echarts.simple.js 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. (function (global, factory) {
  20. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  21. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  22. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.echarts = {}));
  23. }(this, (function (exports) { 'use strict';
  24. /*! *****************************************************************************
  25. Copyright (c) Microsoft Corporation.
  26. Permission to use, copy, modify, and/or distribute this software for any
  27. purpose with or without fee is hereby granted.
  28. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  29. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  30. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  31. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  32. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  33. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  34. PERFORMANCE OF THIS SOFTWARE.
  35. ***************************************************************************** */
  36. /* global Reflect, Promise */
  37. var extendStatics = function(d, b) {
  38. extendStatics = Object.setPrototypeOf ||
  39. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  40. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  41. return extendStatics(d, b);
  42. };
  43. function __extends(d, b) {
  44. if (typeof b !== "function" && b !== null)
  45. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  46. extendStatics(d, b);
  47. function __() { this.constructor = d; }
  48. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  49. }
  50. var Browser = (function () {
  51. function Browser() {
  52. this.firefox = false;
  53. this.ie = false;
  54. this.edge = false;
  55. this.newEdge = false;
  56. this.weChat = false;
  57. }
  58. return Browser;
  59. }());
  60. var Env = (function () {
  61. function Env() {
  62. this.browser = new Browser();
  63. this.node = false;
  64. this.wxa = false;
  65. this.worker = false;
  66. this.svgSupported = false;
  67. this.touchEventsSupported = false;
  68. this.pointerEventsSupported = false;
  69. this.domSupported = false;
  70. this.transformSupported = false;
  71. this.transform3dSupported = false;
  72. this.hasGlobalWindow = typeof window !== 'undefined';
  73. }
  74. return Env;
  75. }());
  76. var env = new Env();
  77. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  78. env.wxa = true;
  79. env.touchEventsSupported = true;
  80. }
  81. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  82. env.worker = true;
  83. }
  84. else if (!env.hasGlobalWindow
  85. || 'Deno' in window
  86. || (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string'
  87. && navigator.userAgent.indexOf('Node.js') > -1)) {
  88. env.node = true;
  89. env.svgSupported = true;
  90. }
  91. else {
  92. detect(navigator.userAgent, env);
  93. }
  94. function detect(ua, env) {
  95. var browser = env.browser;
  96. var firefox = ua.match(/Firefox\/([\d.]+)/);
  97. var ie = ua.match(/MSIE\s([\d.]+)/)
  98. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  99. var edge = ua.match(/Edge?\/([\d.]+)/);
  100. var weChat = (/micromessenger/i).test(ua);
  101. if (firefox) {
  102. browser.firefox = true;
  103. browser.version = firefox[1];
  104. }
  105. if (ie) {
  106. browser.ie = true;
  107. browser.version = ie[1];
  108. }
  109. if (edge) {
  110. browser.edge = true;
  111. browser.version = edge[1];
  112. browser.newEdge = +edge[1].split('.')[0] > 18;
  113. }
  114. if (weChat) {
  115. browser.weChat = true;
  116. }
  117. env.svgSupported = typeof SVGRect !== 'undefined';
  118. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  119. env.pointerEventsSupported = 'onpointerdown' in window
  120. && (browser.edge || (browser.ie && +browser.version >= 11));
  121. var domSupported = env.domSupported = typeof document !== 'undefined';
  122. if (domSupported) {
  123. var style = document.documentElement.style;
  124. env.transform3dSupported = ((browser.ie && 'transition' in style)
  125. || browser.edge
  126. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  127. || 'MozPerspective' in style)
  128. && !('OTransition' in style);
  129. env.transformSupported = env.transform3dSupported
  130. || (browser.ie && +browser.version >= 9);
  131. }
  132. }
  133. var DEFAULT_FONT_SIZE = 12;
  134. var DEFAULT_FONT_FAMILY = 'sans-serif';
  135. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  136. var OFFSET = 20;
  137. var SCALE = 100;
  138. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  139. function getTextWidthMap(mapStr) {
  140. var map = {};
  141. if (typeof JSON === 'undefined') {
  142. return map;
  143. }
  144. for (var i = 0; i < mapStr.length; i++) {
  145. var char = String.fromCharCode(i + 32);
  146. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  147. map[char] = size;
  148. }
  149. return map;
  150. }
  151. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  152. var platformApi = {
  153. createCanvas: function () {
  154. return typeof document !== 'undefined'
  155. && document.createElement('canvas');
  156. },
  157. measureText: (function () {
  158. var _ctx;
  159. var _cachedFont;
  160. return function (text, font) {
  161. if (!_ctx) {
  162. var canvas = platformApi.createCanvas();
  163. _ctx = canvas && canvas.getContext('2d');
  164. }
  165. if (_ctx) {
  166. if (_cachedFont !== font) {
  167. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  168. }
  169. return _ctx.measureText(text);
  170. }
  171. else {
  172. text = text || '';
  173. font = font || DEFAULT_FONT;
  174. var res = /((?:\d+)?\.?\d*)px/.exec(font);
  175. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  176. var width = 0;
  177. if (font.indexOf('mono') >= 0) {
  178. width = fontSize * text.length;
  179. }
  180. else {
  181. for (var i = 0; i < text.length; i++) {
  182. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  183. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  184. }
  185. }
  186. return { width: width };
  187. }
  188. };
  189. })(),
  190. loadImage: function (src, onload, onerror) {
  191. var image = new Image();
  192. image.onload = onload;
  193. image.onerror = onerror;
  194. image.src = src;
  195. return image;
  196. }
  197. };
  198. function setPlatformAPI(newPlatformApis) {
  199. for (var key in platformApi) {
  200. if (newPlatformApis[key]) {
  201. platformApi[key] = newPlatformApis[key];
  202. }
  203. }
  204. }
  205. var BUILTIN_OBJECT = reduce([
  206. 'Function',
  207. 'RegExp',
  208. 'Date',
  209. 'Error',
  210. 'CanvasGradient',
  211. 'CanvasPattern',
  212. 'Image',
  213. 'Canvas'
  214. ], function (obj, val) {
  215. obj['[object ' + val + ']'] = true;
  216. return obj;
  217. }, {});
  218. var TYPED_ARRAY = reduce([
  219. 'Int8',
  220. 'Uint8',
  221. 'Uint8Clamped',
  222. 'Int16',
  223. 'Uint16',
  224. 'Int32',
  225. 'Uint32',
  226. 'Float32',
  227. 'Float64'
  228. ], function (obj, val) {
  229. obj['[object ' + val + 'Array]'] = true;
  230. return obj;
  231. }, {});
  232. var objToString = Object.prototype.toString;
  233. var arrayProto = Array.prototype;
  234. var nativeForEach = arrayProto.forEach;
  235. var nativeFilter = arrayProto.filter;
  236. var nativeSlice = arrayProto.slice;
  237. var nativeMap = arrayProto.map;
  238. var ctorFunction = function () { }.constructor;
  239. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  240. var protoKey = '__proto__';
  241. var idStart = 0x0907;
  242. function guid() {
  243. return idStart++;
  244. }
  245. function logError() {
  246. var args = [];
  247. for (var _i = 0; _i < arguments.length; _i++) {
  248. args[_i] = arguments[_i];
  249. }
  250. if (typeof console !== 'undefined') {
  251. console.error.apply(console, args);
  252. }
  253. }
  254. function clone(source) {
  255. if (source == null || typeof source !== 'object') {
  256. return source;
  257. }
  258. var result = source;
  259. var typeStr = objToString.call(source);
  260. if (typeStr === '[object Array]') {
  261. if (!isPrimitive(source)) {
  262. result = [];
  263. for (var i = 0, len = source.length; i < len; i++) {
  264. result[i] = clone(source[i]);
  265. }
  266. }
  267. }
  268. else if (TYPED_ARRAY[typeStr]) {
  269. if (!isPrimitive(source)) {
  270. var Ctor = source.constructor;
  271. if (Ctor.from) {
  272. result = Ctor.from(source);
  273. }
  274. else {
  275. result = new Ctor(source.length);
  276. for (var i = 0, len = source.length; i < len; i++) {
  277. result[i] = source[i];
  278. }
  279. }
  280. }
  281. }
  282. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  283. result = {};
  284. for (var key in source) {
  285. if (source.hasOwnProperty(key) && key !== protoKey) {
  286. result[key] = clone(source[key]);
  287. }
  288. }
  289. }
  290. return result;
  291. }
  292. function merge(target, source, overwrite) {
  293. if (!isObject(source) || !isObject(target)) {
  294. return overwrite ? clone(source) : target;
  295. }
  296. for (var key in source) {
  297. if (source.hasOwnProperty(key) && key !== protoKey) {
  298. var targetProp = target[key];
  299. var sourceProp = source[key];
  300. if (isObject(sourceProp)
  301. && isObject(targetProp)
  302. && !isArray(sourceProp)
  303. && !isArray(targetProp)
  304. && !isDom(sourceProp)
  305. && !isDom(targetProp)
  306. && !isBuiltInObject(sourceProp)
  307. && !isBuiltInObject(targetProp)
  308. && !isPrimitive(sourceProp)
  309. && !isPrimitive(targetProp)) {
  310. merge(targetProp, sourceProp, overwrite);
  311. }
  312. else if (overwrite || !(key in target)) {
  313. target[key] = clone(source[key]);
  314. }
  315. }
  316. }
  317. return target;
  318. }
  319. function mergeAll(targetAndSources, overwrite) {
  320. var result = targetAndSources[0];
  321. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  322. result = merge(result, targetAndSources[i], overwrite);
  323. }
  324. return result;
  325. }
  326. function extend(target, source) {
  327. if (Object.assign) {
  328. Object.assign(target, source);
  329. }
  330. else {
  331. for (var key in source) {
  332. if (source.hasOwnProperty(key) && key !== protoKey) {
  333. target[key] = source[key];
  334. }
  335. }
  336. }
  337. return target;
  338. }
  339. function defaults(target, source, overlay) {
  340. var keysArr = keys(source);
  341. for (var i = 0, len = keysArr.length; i < len; i++) {
  342. var key = keysArr[i];
  343. if ((overlay ? source[key] != null : target[key] == null)) {
  344. target[key] = source[key];
  345. }
  346. }
  347. return target;
  348. }
  349. var createCanvas = platformApi.createCanvas;
  350. function indexOf(array, value) {
  351. if (array) {
  352. if (array.indexOf) {
  353. return array.indexOf(value);
  354. }
  355. for (var i = 0, len = array.length; i < len; i++) {
  356. if (array[i] === value) {
  357. return i;
  358. }
  359. }
  360. }
  361. return -1;
  362. }
  363. function inherits(clazz, baseClazz) {
  364. var clazzPrototype = clazz.prototype;
  365. function F() { }
  366. F.prototype = baseClazz.prototype;
  367. clazz.prototype = new F();
  368. for (var prop in clazzPrototype) {
  369. if (clazzPrototype.hasOwnProperty(prop)) {
  370. clazz.prototype[prop] = clazzPrototype[prop];
  371. }
  372. }
  373. clazz.prototype.constructor = clazz;
  374. clazz.superClass = baseClazz;
  375. }
  376. function mixin(target, source, override) {
  377. target = 'prototype' in target ? target.prototype : target;
  378. source = 'prototype' in source ? source.prototype : source;
  379. if (Object.getOwnPropertyNames) {
  380. var keyList = Object.getOwnPropertyNames(source);
  381. for (var i = 0; i < keyList.length; i++) {
  382. var key = keyList[i];
  383. if (key !== 'constructor') {
  384. if ((override ? source[key] != null : target[key] == null)) {
  385. target[key] = source[key];
  386. }
  387. }
  388. }
  389. }
  390. else {
  391. defaults(target, source, override);
  392. }
  393. }
  394. function isArrayLike(data) {
  395. if (!data) {
  396. return false;
  397. }
  398. if (typeof data === 'string') {
  399. return false;
  400. }
  401. return typeof data.length === 'number';
  402. }
  403. function each(arr, cb, context) {
  404. if (!(arr && cb)) {
  405. return;
  406. }
  407. if (arr.forEach && arr.forEach === nativeForEach) {
  408. arr.forEach(cb, context);
  409. }
  410. else if (arr.length === +arr.length) {
  411. for (var i = 0, len = arr.length; i < len; i++) {
  412. cb.call(context, arr[i], i, arr);
  413. }
  414. }
  415. else {
  416. for (var key in arr) {
  417. if (arr.hasOwnProperty(key)) {
  418. cb.call(context, arr[key], key, arr);
  419. }
  420. }
  421. }
  422. }
  423. function map(arr, cb, context) {
  424. if (!arr) {
  425. return [];
  426. }
  427. if (!cb) {
  428. return slice(arr);
  429. }
  430. if (arr.map && arr.map === nativeMap) {
  431. return arr.map(cb, context);
  432. }
  433. else {
  434. var result = [];
  435. for (var i = 0, len = arr.length; i < len; i++) {
  436. result.push(cb.call(context, arr[i], i, arr));
  437. }
  438. return result;
  439. }
  440. }
  441. function reduce(arr, cb, memo, context) {
  442. if (!(arr && cb)) {
  443. return;
  444. }
  445. for (var i = 0, len = arr.length; i < len; i++) {
  446. memo = cb.call(context, memo, arr[i], i, arr);
  447. }
  448. return memo;
  449. }
  450. function filter(arr, cb, context) {
  451. if (!arr) {
  452. return [];
  453. }
  454. if (!cb) {
  455. return slice(arr);
  456. }
  457. if (arr.filter && arr.filter === nativeFilter) {
  458. return arr.filter(cb, context);
  459. }
  460. else {
  461. var result = [];
  462. for (var i = 0, len = arr.length; i < len; i++) {
  463. if (cb.call(context, arr[i], i, arr)) {
  464. result.push(arr[i]);
  465. }
  466. }
  467. return result;
  468. }
  469. }
  470. function find(arr, cb, context) {
  471. if (!(arr && cb)) {
  472. return;
  473. }
  474. for (var i = 0, len = arr.length; i < len; i++) {
  475. if (cb.call(context, arr[i], i, arr)) {
  476. return arr[i];
  477. }
  478. }
  479. }
  480. function keys(obj) {
  481. if (!obj) {
  482. return [];
  483. }
  484. if (Object.keys) {
  485. return Object.keys(obj);
  486. }
  487. var keyList = [];
  488. for (var key in obj) {
  489. if (obj.hasOwnProperty(key)) {
  490. keyList.push(key);
  491. }
  492. }
  493. return keyList;
  494. }
  495. function bindPolyfill(func, context) {
  496. var args = [];
  497. for (var _i = 2; _i < arguments.length; _i++) {
  498. args[_i - 2] = arguments[_i];
  499. }
  500. return function () {
  501. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  502. };
  503. }
  504. var bind = (protoFunction && isFunction(protoFunction.bind))
  505. ? protoFunction.call.bind(protoFunction.bind)
  506. : bindPolyfill;
  507. function curry(func) {
  508. var args = [];
  509. for (var _i = 1; _i < arguments.length; _i++) {
  510. args[_i - 1] = arguments[_i];
  511. }
  512. return function () {
  513. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  514. };
  515. }
  516. function isArray(value) {
  517. if (Array.isArray) {
  518. return Array.isArray(value);
  519. }
  520. return objToString.call(value) === '[object Array]';
  521. }
  522. function isFunction(value) {
  523. return typeof value === 'function';
  524. }
  525. function isString(value) {
  526. return typeof value === 'string';
  527. }
  528. function isStringSafe(value) {
  529. return objToString.call(value) === '[object String]';
  530. }
  531. function isNumber(value) {
  532. return typeof value === 'number';
  533. }
  534. function isObject(value) {
  535. var type = typeof value;
  536. return type === 'function' || (!!value && type === 'object');
  537. }
  538. function isBuiltInObject(value) {
  539. return !!BUILTIN_OBJECT[objToString.call(value)];
  540. }
  541. function isTypedArray(value) {
  542. return !!TYPED_ARRAY[objToString.call(value)];
  543. }
  544. function isDom(value) {
  545. return typeof value === 'object'
  546. && typeof value.nodeType === 'number'
  547. && typeof value.ownerDocument === 'object';
  548. }
  549. function isGradientObject(value) {
  550. return value.colorStops != null;
  551. }
  552. function isImagePatternObject(value) {
  553. return value.image != null;
  554. }
  555. function isRegExp(value) {
  556. return objToString.call(value) === '[object RegExp]';
  557. }
  558. function eqNaN(value) {
  559. return value !== value;
  560. }
  561. function retrieve() {
  562. var args = [];
  563. for (var _i = 0; _i < arguments.length; _i++) {
  564. args[_i] = arguments[_i];
  565. }
  566. for (var i = 0, len = args.length; i < len; i++) {
  567. if (args[i] != null) {
  568. return args[i];
  569. }
  570. }
  571. }
  572. function retrieve2(value0, value1) {
  573. return value0 != null
  574. ? value0
  575. : value1;
  576. }
  577. function retrieve3(value0, value1, value2) {
  578. return value0 != null
  579. ? value0
  580. : value1 != null
  581. ? value1
  582. : value2;
  583. }
  584. function slice(arr) {
  585. var args = [];
  586. for (var _i = 1; _i < arguments.length; _i++) {
  587. args[_i - 1] = arguments[_i];
  588. }
  589. return nativeSlice.apply(arr, args);
  590. }
  591. function normalizeCssArray(val) {
  592. if (typeof (val) === 'number') {
  593. return [val, val, val, val];
  594. }
  595. var len = val.length;
  596. if (len === 2) {
  597. return [val[0], val[1], val[0], val[1]];
  598. }
  599. else if (len === 3) {
  600. return [val[0], val[1], val[2], val[1]];
  601. }
  602. return val;
  603. }
  604. function assert(condition, message) {
  605. if (!condition) {
  606. throw new Error(message);
  607. }
  608. }
  609. function trim(str) {
  610. if (str == null) {
  611. return null;
  612. }
  613. else if (typeof str.trim === 'function') {
  614. return str.trim();
  615. }
  616. else {
  617. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  618. }
  619. }
  620. var primitiveKey = '__ec_primitive__';
  621. function setAsPrimitive(obj) {
  622. obj[primitiveKey] = true;
  623. }
  624. function isPrimitive(obj) {
  625. return obj[primitiveKey];
  626. }
  627. var MapPolyfill = (function () {
  628. function MapPolyfill() {
  629. this.data = {};
  630. }
  631. MapPolyfill.prototype["delete"] = function (key) {
  632. var existed = this.has(key);
  633. if (existed) {
  634. delete this.data[key];
  635. }
  636. return existed;
  637. };
  638. MapPolyfill.prototype.has = function (key) {
  639. return this.data.hasOwnProperty(key);
  640. };
  641. MapPolyfill.prototype.get = function (key) {
  642. return this.data[key];
  643. };
  644. MapPolyfill.prototype.set = function (key, value) {
  645. this.data[key] = value;
  646. return this;
  647. };
  648. MapPolyfill.prototype.keys = function () {
  649. return keys(this.data);
  650. };
  651. MapPolyfill.prototype.forEach = function (callback) {
  652. var data = this.data;
  653. for (var key in data) {
  654. if (data.hasOwnProperty(key)) {
  655. callback(data[key], key);
  656. }
  657. }
  658. };
  659. return MapPolyfill;
  660. }());
  661. var isNativeMapSupported = typeof Map === 'function';
  662. function maybeNativeMap() {
  663. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  664. }
  665. var HashMap = (function () {
  666. function HashMap(obj) {
  667. var isArr = isArray(obj);
  668. this.data = maybeNativeMap();
  669. var thisMap = this;
  670. (obj instanceof HashMap)
  671. ? obj.each(visit)
  672. : (obj && each(obj, visit));
  673. function visit(value, key) {
  674. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  675. }
  676. }
  677. HashMap.prototype.hasKey = function (key) {
  678. return this.data.has(key);
  679. };
  680. HashMap.prototype.get = function (key) {
  681. return this.data.get(key);
  682. };
  683. HashMap.prototype.set = function (key, value) {
  684. this.data.set(key, value);
  685. return value;
  686. };
  687. HashMap.prototype.each = function (cb, context) {
  688. this.data.forEach(function (value, key) {
  689. cb.call(context, value, key);
  690. });
  691. };
  692. HashMap.prototype.keys = function () {
  693. var keys = this.data.keys();
  694. return isNativeMapSupported
  695. ? Array.from(keys)
  696. : keys;
  697. };
  698. HashMap.prototype.removeKey = function (key) {
  699. this.data["delete"](key);
  700. };
  701. return HashMap;
  702. }());
  703. function createHashMap(obj) {
  704. return new HashMap(obj);
  705. }
  706. function concatArray(a, b) {
  707. var newArray = new a.constructor(a.length + b.length);
  708. for (var i = 0; i < a.length; i++) {
  709. newArray[i] = a[i];
  710. }
  711. var offset = a.length;
  712. for (var i = 0; i < b.length; i++) {
  713. newArray[i + offset] = b[i];
  714. }
  715. return newArray;
  716. }
  717. function createObject(proto, properties) {
  718. var obj;
  719. if (Object.create) {
  720. obj = Object.create(proto);
  721. }
  722. else {
  723. var StyleCtor = function () { };
  724. StyleCtor.prototype = proto;
  725. obj = new StyleCtor();
  726. }
  727. if (properties) {
  728. extend(obj, properties);
  729. }
  730. return obj;
  731. }
  732. function disableUserSelect(dom) {
  733. var domStyle = dom.style;
  734. domStyle.webkitUserSelect = 'none';
  735. domStyle.userSelect = 'none';
  736. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  737. domStyle['-webkit-touch-callout'] = 'none';
  738. }
  739. function hasOwn(own, prop) {
  740. return own.hasOwnProperty(prop);
  741. }
  742. function noop() { }
  743. var RADIAN_TO_DEGREE = 180 / Math.PI;
  744. var EPSILON = Number.EPSILON || Math.pow(2, -52);
  745. var util = /*#__PURE__*/Object.freeze({
  746. __proto__: null,
  747. guid: guid,
  748. logError: logError,
  749. clone: clone,
  750. merge: merge,
  751. mergeAll: mergeAll,
  752. extend: extend,
  753. defaults: defaults,
  754. createCanvas: createCanvas,
  755. indexOf: indexOf,
  756. inherits: inherits,
  757. mixin: mixin,
  758. isArrayLike: isArrayLike,
  759. each: each,
  760. map: map,
  761. reduce: reduce,
  762. filter: filter,
  763. find: find,
  764. keys: keys,
  765. bind: bind,
  766. curry: curry,
  767. isArray: isArray,
  768. isFunction: isFunction,
  769. isString: isString,
  770. isStringSafe: isStringSafe,
  771. isNumber: isNumber,
  772. isObject: isObject,
  773. isBuiltInObject: isBuiltInObject,
  774. isTypedArray: isTypedArray,
  775. isDom: isDom,
  776. isGradientObject: isGradientObject,
  777. isImagePatternObject: isImagePatternObject,
  778. isRegExp: isRegExp,
  779. eqNaN: eqNaN,
  780. retrieve: retrieve,
  781. retrieve2: retrieve2,
  782. retrieve3: retrieve3,
  783. slice: slice,
  784. normalizeCssArray: normalizeCssArray,
  785. assert: assert,
  786. trim: trim,
  787. setAsPrimitive: setAsPrimitive,
  788. isPrimitive: isPrimitive,
  789. HashMap: HashMap,
  790. createHashMap: createHashMap,
  791. concatArray: concatArray,
  792. createObject: createObject,
  793. disableUserSelect: disableUserSelect,
  794. hasOwn: hasOwn,
  795. noop: noop,
  796. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE,
  797. EPSILON: EPSILON
  798. });
  799. function create(x, y) {
  800. if (x == null) {
  801. x = 0;
  802. }
  803. if (y == null) {
  804. y = 0;
  805. }
  806. return [x, y];
  807. }
  808. function copy(out, v) {
  809. out[0] = v[0];
  810. out[1] = v[1];
  811. return out;
  812. }
  813. function clone$1(v) {
  814. return [v[0], v[1]];
  815. }
  816. function set(out, a, b) {
  817. out[0] = a;
  818. out[1] = b;
  819. return out;
  820. }
  821. function add(out, v1, v2) {
  822. out[0] = v1[0] + v2[0];
  823. out[1] = v1[1] + v2[1];
  824. return out;
  825. }
  826. function scaleAndAdd(out, v1, v2, a) {
  827. out[0] = v1[0] + v2[0] * a;
  828. out[1] = v1[1] + v2[1] * a;
  829. return out;
  830. }
  831. function sub(out, v1, v2) {
  832. out[0] = v1[0] - v2[0];
  833. out[1] = v1[1] - v2[1];
  834. return out;
  835. }
  836. function len(v) {
  837. return Math.sqrt(lenSquare(v));
  838. }
  839. var length = len;
  840. function lenSquare(v) {
  841. return v[0] * v[0] + v[1] * v[1];
  842. }
  843. var lengthSquare = lenSquare;
  844. function mul(out, v1, v2) {
  845. out[0] = v1[0] * v2[0];
  846. out[1] = v1[1] * v2[1];
  847. return out;
  848. }
  849. function div(out, v1, v2) {
  850. out[0] = v1[0] / v2[0];
  851. out[1] = v1[1] / v2[1];
  852. return out;
  853. }
  854. function dot(v1, v2) {
  855. return v1[0] * v2[0] + v1[1] * v2[1];
  856. }
  857. function scale(out, v, s) {
  858. out[0] = v[0] * s;
  859. out[1] = v[1] * s;
  860. return out;
  861. }
  862. function normalize(out, v) {
  863. var d = len(v);
  864. if (d === 0) {
  865. out[0] = 0;
  866. out[1] = 0;
  867. }
  868. else {
  869. out[0] = v[0] / d;
  870. out[1] = v[1] / d;
  871. }
  872. return out;
  873. }
  874. function distance(v1, v2) {
  875. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  876. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  877. }
  878. var dist = distance;
  879. function distanceSquare(v1, v2) {
  880. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  881. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  882. }
  883. var distSquare = distanceSquare;
  884. function negate(out, v) {
  885. out[0] = -v[0];
  886. out[1] = -v[1];
  887. return out;
  888. }
  889. function lerp(out, v1, v2, t) {
  890. out[0] = v1[0] + t * (v2[0] - v1[0]);
  891. out[1] = v1[1] + t * (v2[1] - v1[1]);
  892. return out;
  893. }
  894. function applyTransform(out, v, m) {
  895. var x = v[0];
  896. var y = v[1];
  897. out[0] = m[0] * x + m[2] * y + m[4];
  898. out[1] = m[1] * x + m[3] * y + m[5];
  899. return out;
  900. }
  901. function min(out, v1, v2) {
  902. out[0] = Math.min(v1[0], v2[0]);
  903. out[1] = Math.min(v1[1], v2[1]);
  904. return out;
  905. }
  906. function max(out, v1, v2) {
  907. out[0] = Math.max(v1[0], v2[0]);
  908. out[1] = Math.max(v1[1], v2[1]);
  909. return out;
  910. }
  911. var vector = /*#__PURE__*/Object.freeze({
  912. __proto__: null,
  913. create: create,
  914. copy: copy,
  915. clone: clone$1,
  916. set: set,
  917. add: add,
  918. scaleAndAdd: scaleAndAdd,
  919. sub: sub,
  920. len: len,
  921. length: length,
  922. lenSquare: lenSquare,
  923. lengthSquare: lengthSquare,
  924. mul: mul,
  925. div: div,
  926. dot: dot,
  927. scale: scale,
  928. normalize: normalize,
  929. distance: distance,
  930. dist: dist,
  931. distanceSquare: distanceSquare,
  932. distSquare: distSquare,
  933. negate: negate,
  934. lerp: lerp,
  935. applyTransform: applyTransform,
  936. min: min,
  937. max: max
  938. });
  939. var Param = (function () {
  940. function Param(target, e) {
  941. this.target = target;
  942. this.topTarget = e && e.topTarget;
  943. }
  944. return Param;
  945. }());
  946. var Draggable = (function () {
  947. function Draggable(handler) {
  948. this.handler = handler;
  949. handler.on('mousedown', this._dragStart, this);
  950. handler.on('mousemove', this._drag, this);
  951. handler.on('mouseup', this._dragEnd, this);
  952. }
  953. Draggable.prototype._dragStart = function (e) {
  954. var draggingTarget = e.target;
  955. while (draggingTarget && !draggingTarget.draggable) {
  956. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  957. }
  958. if (draggingTarget) {
  959. this._draggingTarget = draggingTarget;
  960. draggingTarget.dragging = true;
  961. this._x = e.offsetX;
  962. this._y = e.offsetY;
  963. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  964. }
  965. };
  966. Draggable.prototype._drag = function (e) {
  967. var draggingTarget = this._draggingTarget;
  968. if (draggingTarget) {
  969. var x = e.offsetX;
  970. var y = e.offsetY;
  971. var dx = x - this._x;
  972. var dy = y - this._y;
  973. this._x = x;
  974. this._y = y;
  975. draggingTarget.drift(dx, dy, e);
  976. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  977. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  978. var lastDropTarget = this._dropTarget;
  979. this._dropTarget = dropTarget;
  980. if (draggingTarget !== dropTarget) {
  981. if (lastDropTarget && dropTarget !== lastDropTarget) {
  982. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  983. }
  984. if (dropTarget && dropTarget !== lastDropTarget) {
  985. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  986. }
  987. }
  988. }
  989. };
  990. Draggable.prototype._dragEnd = function (e) {
  991. var draggingTarget = this._draggingTarget;
  992. if (draggingTarget) {
  993. draggingTarget.dragging = false;
  994. }
  995. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  996. if (this._dropTarget) {
  997. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  998. }
  999. this._draggingTarget = null;
  1000. this._dropTarget = null;
  1001. };
  1002. return Draggable;
  1003. }());
  1004. var Eventful = (function () {
  1005. function Eventful(eventProcessors) {
  1006. if (eventProcessors) {
  1007. this._$eventProcessor = eventProcessors;
  1008. }
  1009. }
  1010. Eventful.prototype.on = function (event, query, handler, context) {
  1011. if (!this._$handlers) {
  1012. this._$handlers = {};
  1013. }
  1014. var _h = this._$handlers;
  1015. if (typeof query === 'function') {
  1016. context = handler;
  1017. handler = query;
  1018. query = null;
  1019. }
  1020. if (!handler || !event) {
  1021. return this;
  1022. }
  1023. var eventProcessor = this._$eventProcessor;
  1024. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1025. query = eventProcessor.normalizeQuery(query);
  1026. }
  1027. if (!_h[event]) {
  1028. _h[event] = [];
  1029. }
  1030. for (var i = 0; i < _h[event].length; i++) {
  1031. if (_h[event][i].h === handler) {
  1032. return this;
  1033. }
  1034. }
  1035. var wrap = {
  1036. h: handler,
  1037. query: query,
  1038. ctx: (context || this),
  1039. callAtLast: handler.zrEventfulCallAtLast
  1040. };
  1041. var lastIndex = _h[event].length - 1;
  1042. var lastWrap = _h[event][lastIndex];
  1043. (lastWrap && lastWrap.callAtLast)
  1044. ? _h[event].splice(lastIndex, 0, wrap)
  1045. : _h[event].push(wrap);
  1046. return this;
  1047. };
  1048. Eventful.prototype.isSilent = function (eventName) {
  1049. var _h = this._$handlers;
  1050. return !_h || !_h[eventName] || !_h[eventName].length;
  1051. };
  1052. Eventful.prototype.off = function (eventType, handler) {
  1053. var _h = this._$handlers;
  1054. if (!_h) {
  1055. return this;
  1056. }
  1057. if (!eventType) {
  1058. this._$handlers = {};
  1059. return this;
  1060. }
  1061. if (handler) {
  1062. if (_h[eventType]) {
  1063. var newList = [];
  1064. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1065. if (_h[eventType][i].h !== handler) {
  1066. newList.push(_h[eventType][i]);
  1067. }
  1068. }
  1069. _h[eventType] = newList;
  1070. }
  1071. if (_h[eventType] && _h[eventType].length === 0) {
  1072. delete _h[eventType];
  1073. }
  1074. }
  1075. else {
  1076. delete _h[eventType];
  1077. }
  1078. return this;
  1079. };
  1080. Eventful.prototype.trigger = function (eventType) {
  1081. var args = [];
  1082. for (var _i = 1; _i < arguments.length; _i++) {
  1083. args[_i - 1] = arguments[_i];
  1084. }
  1085. if (!this._$handlers) {
  1086. return this;
  1087. }
  1088. var _h = this._$handlers[eventType];
  1089. var eventProcessor = this._$eventProcessor;
  1090. if (_h) {
  1091. var argLen = args.length;
  1092. var len = _h.length;
  1093. for (var i = 0; i < len; i++) {
  1094. var hItem = _h[i];
  1095. if (eventProcessor
  1096. && eventProcessor.filter
  1097. && hItem.query != null
  1098. && !eventProcessor.filter(eventType, hItem.query)) {
  1099. continue;
  1100. }
  1101. switch (argLen) {
  1102. case 0:
  1103. hItem.h.call(hItem.ctx);
  1104. break;
  1105. case 1:
  1106. hItem.h.call(hItem.ctx, args[0]);
  1107. break;
  1108. case 2:
  1109. hItem.h.call(hItem.ctx, args[0], args[1]);
  1110. break;
  1111. default:
  1112. hItem.h.apply(hItem.ctx, args);
  1113. break;
  1114. }
  1115. }
  1116. }
  1117. eventProcessor && eventProcessor.afterTrigger
  1118. && eventProcessor.afterTrigger(eventType);
  1119. return this;
  1120. };
  1121. Eventful.prototype.triggerWithContext = function (type) {
  1122. var args = [];
  1123. for (var _i = 1; _i < arguments.length; _i++) {
  1124. args[_i - 1] = arguments[_i];
  1125. }
  1126. if (!this._$handlers) {
  1127. return this;
  1128. }
  1129. var _h = this._$handlers[type];
  1130. var eventProcessor = this._$eventProcessor;
  1131. if (_h) {
  1132. var argLen = args.length;
  1133. var ctx = args[argLen - 1];
  1134. var len = _h.length;
  1135. for (var i = 0; i < len; i++) {
  1136. var hItem = _h[i];
  1137. if (eventProcessor
  1138. && eventProcessor.filter
  1139. && hItem.query != null
  1140. && !eventProcessor.filter(type, hItem.query)) {
  1141. continue;
  1142. }
  1143. switch (argLen) {
  1144. case 0:
  1145. hItem.h.call(ctx);
  1146. break;
  1147. case 1:
  1148. hItem.h.call(ctx, args[0]);
  1149. break;
  1150. case 2:
  1151. hItem.h.call(ctx, args[0], args[1]);
  1152. break;
  1153. default:
  1154. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1155. break;
  1156. }
  1157. }
  1158. }
  1159. eventProcessor && eventProcessor.afterTrigger
  1160. && eventProcessor.afterTrigger(type);
  1161. return this;
  1162. };
  1163. return Eventful;
  1164. }());
  1165. var LN2 = Math.log(2);
  1166. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1167. var cacheKey = rowMask + '-' + colMask;
  1168. var fullRank = rows.length;
  1169. if (detCache.hasOwnProperty(cacheKey)) {
  1170. return detCache[cacheKey];
  1171. }
  1172. if (rank === 1) {
  1173. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1174. return rows[rowStart][colStart];
  1175. }
  1176. var subRowMask = rowMask | (1 << rowStart);
  1177. var subRowStart = rowStart + 1;
  1178. while (rowMask & (1 << subRowStart)) {
  1179. subRowStart++;
  1180. }
  1181. var sum = 0;
  1182. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1183. var colTag = 1 << j;
  1184. if (!(colTag & colMask)) {
  1185. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1186. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1187. colLocalIdx++;
  1188. }
  1189. }
  1190. detCache[cacheKey] = sum;
  1191. return sum;
  1192. }
  1193. function buildTransformer(src, dest) {
  1194. var mA = [
  1195. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1196. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1197. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1198. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1199. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1200. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1201. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1202. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1203. ];
  1204. var detCache = {};
  1205. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1206. if (det === 0) {
  1207. return;
  1208. }
  1209. var vh = [];
  1210. for (var i = 0; i < 8; i++) {
  1211. for (var j = 0; j < 8; j++) {
  1212. vh[j] == null && (vh[j] = 0);
  1213. vh[j] += ((i + j) % 2 ? -1 : 1)
  1214. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1215. / det * dest[i];
  1216. }
  1217. }
  1218. return function (out, srcPointX, srcPointY) {
  1219. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1220. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1221. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1222. };
  1223. }
  1224. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1225. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1226. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1227. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1228. var markers = prepareCoordMarkers(el, saved);
  1229. var transformer = preparePointerTransformer(markers, saved, inverse);
  1230. if (transformer) {
  1231. transformer(out, inX, inY);
  1232. return true;
  1233. }
  1234. }
  1235. return false;
  1236. }
  1237. function prepareCoordMarkers(el, saved) {
  1238. var markers = saved.markers;
  1239. if (markers) {
  1240. return markers;
  1241. }
  1242. markers = saved.markers = [];
  1243. var propLR = ['left', 'right'];
  1244. var propTB = ['top', 'bottom'];
  1245. for (var i = 0; i < 4; i++) {
  1246. var marker = document.createElement('div');
  1247. var stl = marker.style;
  1248. var idxLR = i % 2;
  1249. var idxTB = (i >> 1) % 2;
  1250. stl.cssText = [
  1251. 'position: absolute',
  1252. 'visibility: hidden',
  1253. 'padding: 0',
  1254. 'margin: 0',
  1255. 'border-width: 0',
  1256. 'user-select: none',
  1257. 'width:0',
  1258. 'height:0',
  1259. propLR[idxLR] + ':0',
  1260. propTB[idxTB] + ':0',
  1261. propLR[1 - idxLR] + ':auto',
  1262. propTB[1 - idxTB] + ':auto',
  1263. ''
  1264. ].join('!important;');
  1265. el.appendChild(marker);
  1266. markers.push(marker);
  1267. }
  1268. saved.clearMarkers = function () {
  1269. each(markers, function (marker) {
  1270. marker.parentNode && marker.parentNode.removeChild(marker);
  1271. });
  1272. };
  1273. return markers;
  1274. }
  1275. function preparePointerTransformer(markers, saved, inverse) {
  1276. var transformerName = inverse ? 'invTrans' : 'trans';
  1277. var transformer = saved[transformerName];
  1278. var oldSrcCoords = saved.srcCoords;
  1279. var srcCoords = [];
  1280. var destCoords = [];
  1281. var oldCoordTheSame = true;
  1282. for (var i = 0; i < 4; i++) {
  1283. var rect = markers[i].getBoundingClientRect();
  1284. var ii = 2 * i;
  1285. var x = rect.left;
  1286. var y = rect.top;
  1287. srcCoords.push(x, y);
  1288. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1289. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1290. }
  1291. return (oldCoordTheSame && transformer)
  1292. ? transformer
  1293. : (saved.srcCoords = srcCoords,
  1294. saved[transformerName] = inverse
  1295. ? buildTransformer(destCoords, srcCoords)
  1296. : buildTransformer(srcCoords, destCoords));
  1297. }
  1298. function isCanvasEl(el) {
  1299. return el.nodeName.toUpperCase() === 'CANVAS';
  1300. }
  1301. var replaceReg = /([&<>"'])/g;
  1302. var replaceMap = {
  1303. '&': '&amp;',
  1304. '<': '&lt;',
  1305. '>': '&gt;',
  1306. '"': '&quot;',
  1307. '\'': '&#39;'
  1308. };
  1309. function encodeHTML(source) {
  1310. return source == null
  1311. ? ''
  1312. : (source + '').replace(replaceReg, function (str, c) {
  1313. return replaceMap[c];
  1314. });
  1315. }
  1316. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1317. var _calcOut = [];
  1318. var firefoxNotSupportOffsetXY = env.browser.firefox
  1319. && +env.browser.version.split('.')[0] < 39;
  1320. function clientToLocal(el, e, out, calculate) {
  1321. out = out || {};
  1322. if (calculate) {
  1323. calculateZrXY(el, e, out);
  1324. }
  1325. else if (firefoxNotSupportOffsetXY
  1326. && e.layerX != null
  1327. && e.layerX !== e.offsetX) {
  1328. out.zrX = e.layerX;
  1329. out.zrY = e.layerY;
  1330. }
  1331. else if (e.offsetX != null) {
  1332. out.zrX = e.offsetX;
  1333. out.zrY = e.offsetY;
  1334. }
  1335. else {
  1336. calculateZrXY(el, e, out);
  1337. }
  1338. return out;
  1339. }
  1340. function calculateZrXY(el, e, out) {
  1341. if (env.domSupported && el.getBoundingClientRect) {
  1342. var ex = e.clientX;
  1343. var ey = e.clientY;
  1344. if (isCanvasEl(el)) {
  1345. var box = el.getBoundingClientRect();
  1346. out.zrX = ex - box.left;
  1347. out.zrY = ey - box.top;
  1348. return;
  1349. }
  1350. else {
  1351. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1352. out.zrX = _calcOut[0];
  1353. out.zrY = _calcOut[1];
  1354. return;
  1355. }
  1356. }
  1357. }
  1358. out.zrX = out.zrY = 0;
  1359. }
  1360. function getNativeEvent(e) {
  1361. return e
  1362. || window.event;
  1363. }
  1364. function normalizeEvent(el, e, calculate) {
  1365. e = getNativeEvent(e);
  1366. if (e.zrX != null) {
  1367. return e;
  1368. }
  1369. var eventType = e.type;
  1370. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1371. if (!isTouch) {
  1372. clientToLocal(el, e, e, calculate);
  1373. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1374. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1375. }
  1376. else {
  1377. var touch = eventType !== 'touchend'
  1378. ? e.targetTouches[0]
  1379. : e.changedTouches[0];
  1380. touch && clientToLocal(el, touch, e, calculate);
  1381. }
  1382. var button = e.button;
  1383. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1384. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1385. }
  1386. return e;
  1387. }
  1388. function getWheelDeltaMayPolyfill(e) {
  1389. var rawWheelDelta = e.wheelDelta;
  1390. if (rawWheelDelta) {
  1391. return rawWheelDelta;
  1392. }
  1393. var deltaX = e.deltaX;
  1394. var deltaY = e.deltaY;
  1395. if (deltaX == null || deltaY == null) {
  1396. return rawWheelDelta;
  1397. }
  1398. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1399. var sign = deltaY > 0 ? -1
  1400. : deltaY < 0 ? 1
  1401. : deltaX > 0 ? -1
  1402. : 1;
  1403. return 3 * delta * sign;
  1404. }
  1405. function addEventListener(el, name, handler, opt) {
  1406. el.addEventListener(name, handler, opt);
  1407. }
  1408. function removeEventListener(el, name, handler, opt) {
  1409. el.removeEventListener(name, handler, opt);
  1410. }
  1411. var stop = function (e) {
  1412. e.preventDefault();
  1413. e.stopPropagation();
  1414. e.cancelBubble = true;
  1415. };
  1416. var GestureMgr = (function () {
  1417. function GestureMgr() {
  1418. this._track = [];
  1419. }
  1420. GestureMgr.prototype.recognize = function (event, target, root) {
  1421. this._doTrack(event, target, root);
  1422. return this._recognize(event);
  1423. };
  1424. GestureMgr.prototype.clear = function () {
  1425. this._track.length = 0;
  1426. return this;
  1427. };
  1428. GestureMgr.prototype._doTrack = function (event, target, root) {
  1429. var touches = event.touches;
  1430. if (!touches) {
  1431. return;
  1432. }
  1433. var trackItem = {
  1434. points: [],
  1435. touches: [],
  1436. target: target,
  1437. event: event
  1438. };
  1439. for (var i = 0, len = touches.length; i < len; i++) {
  1440. var touch = touches[i];
  1441. var pos = clientToLocal(root, touch, {});
  1442. trackItem.points.push([pos.zrX, pos.zrY]);
  1443. trackItem.touches.push(touch);
  1444. }
  1445. this._track.push(trackItem);
  1446. };
  1447. GestureMgr.prototype._recognize = function (event) {
  1448. for (var eventName in recognizers) {
  1449. if (recognizers.hasOwnProperty(eventName)) {
  1450. var gestureInfo = recognizers[eventName](this._track, event);
  1451. if (gestureInfo) {
  1452. return gestureInfo;
  1453. }
  1454. }
  1455. }
  1456. };
  1457. return GestureMgr;
  1458. }());
  1459. function dist$1(pointPair) {
  1460. var dx = pointPair[1][0] - pointPair[0][0];
  1461. var dy = pointPair[1][1] - pointPair[0][1];
  1462. return Math.sqrt(dx * dx + dy * dy);
  1463. }
  1464. function center(pointPair) {
  1465. return [
  1466. (pointPair[0][0] + pointPair[1][0]) / 2,
  1467. (pointPair[0][1] + pointPair[1][1]) / 2
  1468. ];
  1469. }
  1470. var recognizers = {
  1471. pinch: function (tracks, event) {
  1472. var trackLen = tracks.length;
  1473. if (!trackLen) {
  1474. return;
  1475. }
  1476. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1477. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1478. if (pinchPre
  1479. && pinchPre.length > 1
  1480. && pinchEnd
  1481. && pinchEnd.length > 1) {
  1482. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1483. !isFinite(pinchScale) && (pinchScale = 1);
  1484. event.pinchScale = pinchScale;
  1485. var pinchCenter = center(pinchEnd);
  1486. event.pinchX = pinchCenter[0];
  1487. event.pinchY = pinchCenter[1];
  1488. return {
  1489. type: 'pinch',
  1490. target: tracks[0].target,
  1491. event: event
  1492. };
  1493. }
  1494. }
  1495. };
  1496. function create$1() {
  1497. return [1, 0, 0, 1, 0, 0];
  1498. }
  1499. function identity(out) {
  1500. out[0] = 1;
  1501. out[1] = 0;
  1502. out[2] = 0;
  1503. out[3] = 1;
  1504. out[4] = 0;
  1505. out[5] = 0;
  1506. return out;
  1507. }
  1508. function copy$1(out, m) {
  1509. out[0] = m[0];
  1510. out[1] = m[1];
  1511. out[2] = m[2];
  1512. out[3] = m[3];
  1513. out[4] = m[4];
  1514. out[5] = m[5];
  1515. return out;
  1516. }
  1517. function mul$1(out, m1, m2) {
  1518. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1519. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1520. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1521. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1522. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1523. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1524. out[0] = out0;
  1525. out[1] = out1;
  1526. out[2] = out2;
  1527. out[3] = out3;
  1528. out[4] = out4;
  1529. out[5] = out5;
  1530. return out;
  1531. }
  1532. function translate(out, a, v) {
  1533. out[0] = a[0];
  1534. out[1] = a[1];
  1535. out[2] = a[2];
  1536. out[3] = a[3];
  1537. out[4] = a[4] + v[0];
  1538. out[5] = a[5] + v[1];
  1539. return out;
  1540. }
  1541. function rotate(out, a, rad, pivot) {
  1542. if (pivot === void 0) { pivot = [0, 0]; }
  1543. var aa = a[0];
  1544. var ac = a[2];
  1545. var atx = a[4];
  1546. var ab = a[1];
  1547. var ad = a[3];
  1548. var aty = a[5];
  1549. var st = Math.sin(rad);
  1550. var ct = Math.cos(rad);
  1551. out[0] = aa * ct + ab * st;
  1552. out[1] = -aa * st + ab * ct;
  1553. out[2] = ac * ct + ad * st;
  1554. out[3] = -ac * st + ct * ad;
  1555. out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
  1556. out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
  1557. return out;
  1558. }
  1559. function scale$1(out, a, v) {
  1560. var vx = v[0];
  1561. var vy = v[1];
  1562. out[0] = a[0] * vx;
  1563. out[1] = a[1] * vy;
  1564. out[2] = a[2] * vx;
  1565. out[3] = a[3] * vy;
  1566. out[4] = a[4] * vx;
  1567. out[5] = a[5] * vy;
  1568. return out;
  1569. }
  1570. function invert(out, a) {
  1571. var aa = a[0];
  1572. var ac = a[2];
  1573. var atx = a[4];
  1574. var ab = a[1];
  1575. var ad = a[3];
  1576. var aty = a[5];
  1577. var det = aa * ad - ab * ac;
  1578. if (!det) {
  1579. return null;
  1580. }
  1581. det = 1.0 / det;
  1582. out[0] = ad * det;
  1583. out[1] = -ab * det;
  1584. out[2] = -ac * det;
  1585. out[3] = aa * det;
  1586. out[4] = (ac * aty - ad * atx) * det;
  1587. out[5] = (ab * atx - aa * aty) * det;
  1588. return out;
  1589. }
  1590. function clone$2(a) {
  1591. var b = create$1();
  1592. copy$1(b, a);
  1593. return b;
  1594. }
  1595. var matrix = /*#__PURE__*/Object.freeze({
  1596. __proto__: null,
  1597. create: create$1,
  1598. identity: identity,
  1599. copy: copy$1,
  1600. mul: mul$1,
  1601. translate: translate,
  1602. rotate: rotate,
  1603. scale: scale$1,
  1604. invert: invert,
  1605. clone: clone$2
  1606. });
  1607. var Point = (function () {
  1608. function Point(x, y) {
  1609. this.x = x || 0;
  1610. this.y = y || 0;
  1611. }
  1612. Point.prototype.copy = function (other) {
  1613. this.x = other.x;
  1614. this.y = other.y;
  1615. return this;
  1616. };
  1617. Point.prototype.clone = function () {
  1618. return new Point(this.x, this.y);
  1619. };
  1620. Point.prototype.set = function (x, y) {
  1621. this.x = x;
  1622. this.y = y;
  1623. return this;
  1624. };
  1625. Point.prototype.equal = function (other) {
  1626. return other.x === this.x && other.y === this.y;
  1627. };
  1628. Point.prototype.add = function (other) {
  1629. this.x += other.x;
  1630. this.y += other.y;
  1631. return this;
  1632. };
  1633. Point.prototype.scale = function (scalar) {
  1634. this.x *= scalar;
  1635. this.y *= scalar;
  1636. };
  1637. Point.prototype.scaleAndAdd = function (other, scalar) {
  1638. this.x += other.x * scalar;
  1639. this.y += other.y * scalar;
  1640. };
  1641. Point.prototype.sub = function (other) {
  1642. this.x -= other.x;
  1643. this.y -= other.y;
  1644. return this;
  1645. };
  1646. Point.prototype.dot = function (other) {
  1647. return this.x * other.x + this.y * other.y;
  1648. };
  1649. Point.prototype.len = function () {
  1650. return Math.sqrt(this.x * this.x + this.y * this.y);
  1651. };
  1652. Point.prototype.lenSquare = function () {
  1653. return this.x * this.x + this.y * this.y;
  1654. };
  1655. Point.prototype.normalize = function () {
  1656. var len = this.len();
  1657. this.x /= len;
  1658. this.y /= len;
  1659. return this;
  1660. };
  1661. Point.prototype.distance = function (other) {
  1662. var dx = this.x - other.x;
  1663. var dy = this.y - other.y;
  1664. return Math.sqrt(dx * dx + dy * dy);
  1665. };
  1666. Point.prototype.distanceSquare = function (other) {
  1667. var dx = this.x - other.x;
  1668. var dy = this.y - other.y;
  1669. return dx * dx + dy * dy;
  1670. };
  1671. Point.prototype.negate = function () {
  1672. this.x = -this.x;
  1673. this.y = -this.y;
  1674. return this;
  1675. };
  1676. Point.prototype.transform = function (m) {
  1677. if (!m) {
  1678. return;
  1679. }
  1680. var x = this.x;
  1681. var y = this.y;
  1682. this.x = m[0] * x + m[2] * y + m[4];
  1683. this.y = m[1] * x + m[3] * y + m[5];
  1684. return this;
  1685. };
  1686. Point.prototype.toArray = function (out) {
  1687. out[0] = this.x;
  1688. out[1] = this.y;
  1689. return out;
  1690. };
  1691. Point.prototype.fromArray = function (input) {
  1692. this.x = input[0];
  1693. this.y = input[1];
  1694. };
  1695. Point.set = function (p, x, y) {
  1696. p.x = x;
  1697. p.y = y;
  1698. };
  1699. Point.copy = function (p, p2) {
  1700. p.x = p2.x;
  1701. p.y = p2.y;
  1702. };
  1703. Point.len = function (p) {
  1704. return Math.sqrt(p.x * p.x + p.y * p.y);
  1705. };
  1706. Point.lenSquare = function (p) {
  1707. return p.x * p.x + p.y * p.y;
  1708. };
  1709. Point.dot = function (p0, p1) {
  1710. return p0.x * p1.x + p0.y * p1.y;
  1711. };
  1712. Point.add = function (out, p0, p1) {
  1713. out.x = p0.x + p1.x;
  1714. out.y = p0.y + p1.y;
  1715. };
  1716. Point.sub = function (out, p0, p1) {
  1717. out.x = p0.x - p1.x;
  1718. out.y = p0.y - p1.y;
  1719. };
  1720. Point.scale = function (out, p0, scalar) {
  1721. out.x = p0.x * scalar;
  1722. out.y = p0.y * scalar;
  1723. };
  1724. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1725. out.x = p0.x + p1.x * scalar;
  1726. out.y = p0.y + p1.y * scalar;
  1727. };
  1728. Point.lerp = function (out, p0, p1, t) {
  1729. var onet = 1 - t;
  1730. out.x = onet * p0.x + t * p1.x;
  1731. out.y = onet * p0.y + t * p1.y;
  1732. };
  1733. return Point;
  1734. }());
  1735. var mathMin = Math.min;
  1736. var mathMax = Math.max;
  1737. var mathAbs = Math.abs;
  1738. var XY = ['x', 'y'];
  1739. var WH = ['width', 'height'];
  1740. var lt = new Point();
  1741. var rb = new Point();
  1742. var lb = new Point();
  1743. var rt = new Point();
  1744. var _intersectCtx = createIntersectContext();
  1745. var _minTv = _intersectCtx.minTv;
  1746. var _maxTv = _intersectCtx.maxTv;
  1747. var _lenMinMax = [0, 0];
  1748. var BoundingRect = (function () {
  1749. function BoundingRect(x, y, width, height) {
  1750. BoundingRect.set(this, x, y, width, height);
  1751. }
  1752. BoundingRect.set = function (target, x, y, width, height) {
  1753. if (width < 0) {
  1754. x = x + width;
  1755. width = -width;
  1756. }
  1757. if (height < 0) {
  1758. y = y + height;
  1759. height = -height;
  1760. }
  1761. target.x = x;
  1762. target.y = y;
  1763. target.width = width;
  1764. target.height = height;
  1765. return target;
  1766. };
  1767. BoundingRect.prototype.union = function (other) {
  1768. var x = mathMin(other.x, this.x);
  1769. var y = mathMin(other.y, this.y);
  1770. if (isFinite(this.x) && isFinite(this.width)) {
  1771. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1772. }
  1773. else {
  1774. this.width = other.width;
  1775. }
  1776. if (isFinite(this.y) && isFinite(this.height)) {
  1777. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1778. }
  1779. else {
  1780. this.height = other.height;
  1781. }
  1782. this.x = x;
  1783. this.y = y;
  1784. };
  1785. BoundingRect.prototype.applyTransform = function (m) {
  1786. BoundingRect.applyTransform(this, this, m);
  1787. };
  1788. BoundingRect.prototype.calculateTransform = function (b) {
  1789. var a = this;
  1790. var sx = b.width / a.width;
  1791. var sy = b.height / a.height;
  1792. var m = create$1();
  1793. translate(m, m, [-a.x, -a.y]);
  1794. scale$1(m, m, [sx, sy]);
  1795. translate(m, m, [b.x, b.y]);
  1796. return m;
  1797. };
  1798. BoundingRect.prototype.intersect = function (b, mtv, opt) {
  1799. return BoundingRect.intersect(this, b, mtv, opt);
  1800. };
  1801. BoundingRect.intersect = function (a, b, mtv, opt) {
  1802. if (mtv) {
  1803. Point.set(mtv, 0, 0);
  1804. }
  1805. var outIntersectRect = opt && opt.outIntersectRect || null;
  1806. var clamp = opt && opt.clamp;
  1807. if (outIntersectRect) {
  1808. outIntersectRect.x = outIntersectRect.y = outIntersectRect.width = outIntersectRect.height = NaN;
  1809. }
  1810. if (!a || !b) {
  1811. return false;
  1812. }
  1813. if (!(a instanceof BoundingRect)) {
  1814. a = BoundingRect.set(_tmpIntersectA, a.x, a.y, a.width, a.height);
  1815. }
  1816. if (!(b instanceof BoundingRect)) {
  1817. b = BoundingRect.set(_tmpIntersectB, b.x, b.y, b.width, b.height);
  1818. }
  1819. var useMTV = !!mtv;
  1820. _intersectCtx.reset(opt, useMTV);
  1821. var touchThreshold = _intersectCtx.touchThreshold;
  1822. var ax0 = a.x + touchThreshold;
  1823. var ax1 = a.x + a.width - touchThreshold;
  1824. var ay0 = a.y + touchThreshold;
  1825. var ay1 = a.y + a.height - touchThreshold;
  1826. var bx0 = b.x + touchThreshold;
  1827. var bx1 = b.x + b.width - touchThreshold;
  1828. var by0 = b.y + touchThreshold;
  1829. var by1 = b.y + b.height - touchThreshold;
  1830. if (ax0 > ax1 || ay0 > ay1 || bx0 > bx1 || by0 > by1) {
  1831. return false;
  1832. }
  1833. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1834. if (useMTV || outIntersectRect) {
  1835. _lenMinMax[0] = Infinity;
  1836. _lenMinMax[1] = 0;
  1837. intersectOneDim(ax0, ax1, bx0, bx1, 0, useMTV, outIntersectRect, clamp);
  1838. intersectOneDim(ay0, ay1, by0, by1, 1, useMTV, outIntersectRect, clamp);
  1839. if (useMTV) {
  1840. Point.copy(mtv, overlap
  1841. ? (_intersectCtx.useDir ? _intersectCtx.dirMinTv : _minTv)
  1842. : _maxTv);
  1843. }
  1844. }
  1845. return overlap;
  1846. };
  1847. BoundingRect.contain = function (rect, x, y) {
  1848. return x >= rect.x
  1849. && x <= (rect.x + rect.width)
  1850. && y >= rect.y
  1851. && y <= (rect.y + rect.height);
  1852. };
  1853. BoundingRect.prototype.contain = function (x, y) {
  1854. return BoundingRect.contain(this, x, y);
  1855. };
  1856. BoundingRect.prototype.clone = function () {
  1857. return new BoundingRect(this.x, this.y, this.width, this.height);
  1858. };
  1859. BoundingRect.prototype.copy = function (other) {
  1860. BoundingRect.copy(this, other);
  1861. };
  1862. BoundingRect.prototype.plain = function () {
  1863. return {
  1864. x: this.x,
  1865. y: this.y,
  1866. width: this.width,
  1867. height: this.height
  1868. };
  1869. };
  1870. BoundingRect.prototype.isFinite = function () {
  1871. return isFinite(this.x)
  1872. && isFinite(this.y)
  1873. && isFinite(this.width)
  1874. && isFinite(this.height);
  1875. };
  1876. BoundingRect.prototype.isZero = function () {
  1877. return this.width === 0 || this.height === 0;
  1878. };
  1879. BoundingRect.create = function (rect) {
  1880. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1881. };
  1882. BoundingRect.copy = function (target, source) {
  1883. target.x = source.x;
  1884. target.y = source.y;
  1885. target.width = source.width;
  1886. target.height = source.height;
  1887. return target;
  1888. };
  1889. BoundingRect.applyTransform = function (target, source, m) {
  1890. if (!m) {
  1891. if (target !== source) {
  1892. BoundingRect.copy(target, source);
  1893. }
  1894. return;
  1895. }
  1896. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1897. var sx = m[0];
  1898. var sy = m[3];
  1899. var tx = m[4];
  1900. var ty = m[5];
  1901. target.x = source.x * sx + tx;
  1902. target.y = source.y * sy + ty;
  1903. target.width = source.width * sx;
  1904. target.height = source.height * sy;
  1905. if (target.width < 0) {
  1906. target.x += target.width;
  1907. target.width = -target.width;
  1908. }
  1909. if (target.height < 0) {
  1910. target.y += target.height;
  1911. target.height = -target.height;
  1912. }
  1913. return;
  1914. }
  1915. lt.x = lb.x = source.x;
  1916. lt.y = rt.y = source.y;
  1917. rb.x = rt.x = source.x + source.width;
  1918. rb.y = lb.y = source.y + source.height;
  1919. lt.transform(m);
  1920. rt.transform(m);
  1921. rb.transform(m);
  1922. lb.transform(m);
  1923. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1924. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1925. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1926. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1927. target.width = maxX - target.x;
  1928. target.height = maxY - target.y;
  1929. };
  1930. return BoundingRect;
  1931. }());
  1932. var _tmpIntersectA = new BoundingRect(0, 0, 0, 0);
  1933. var _tmpIntersectB = new BoundingRect(0, 0, 0, 0);
  1934. function intersectOneDim(a0, a1, b0, b1, updateDimIdx, useMTV, outIntersectRect, clamp) {
  1935. var d0 = mathAbs(a1 - b0);
  1936. var d1 = mathAbs(b1 - a0);
  1937. var d01min = mathMin(d0, d1);
  1938. var updateDim = XY[updateDimIdx];
  1939. var zeroDim = XY[1 - updateDimIdx];
  1940. var wh = WH[updateDimIdx];
  1941. if (a1 < b0 || b1 < a0) {
  1942. if (d0 < d1) {
  1943. if (useMTV) {
  1944. _maxTv[updateDim] = -d0;
  1945. }
  1946. if (clamp) {
  1947. outIntersectRect[updateDim] = a1;
  1948. outIntersectRect[wh] = 0;
  1949. }
  1950. }
  1951. else {
  1952. if (useMTV) {
  1953. _maxTv[updateDim] = d1;
  1954. }
  1955. if (clamp) {
  1956. outIntersectRect[updateDim] = a0;
  1957. outIntersectRect[wh] = 0;
  1958. }
  1959. }
  1960. }
  1961. else {
  1962. if (outIntersectRect) {
  1963. outIntersectRect[updateDim] = mathMax(a0, b0);
  1964. outIntersectRect[wh] = mathMin(a1, b1) - outIntersectRect[updateDim];
  1965. }
  1966. if (useMTV) {
  1967. if (d01min < _lenMinMax[0] || _intersectCtx.useDir) {
  1968. _lenMinMax[0] = mathMin(d01min, _lenMinMax[0]);
  1969. if (d0 < d1 || !_intersectCtx.bidirectional) {
  1970. _minTv[updateDim] = d0;
  1971. _minTv[zeroDim] = 0;
  1972. if (_intersectCtx.useDir) {
  1973. _intersectCtx.calcDirMTV();
  1974. }
  1975. }
  1976. if (d0 >= d1 || !_intersectCtx.bidirectional) {
  1977. _minTv[updateDim] = -d1;
  1978. _minTv[zeroDim] = 0;
  1979. if (_intersectCtx.useDir) {
  1980. _intersectCtx.calcDirMTV();
  1981. }
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. function createIntersectContext() {
  1988. var _direction = 0;
  1989. var _dirCheckVec = new Point();
  1990. var _dirTmp = new Point();
  1991. var _ctx = {
  1992. minTv: new Point(),
  1993. maxTv: new Point(),
  1994. useDir: false,
  1995. dirMinTv: new Point(),
  1996. touchThreshold: 0,
  1997. bidirectional: true,
  1998. negativeSize: false,
  1999. reset: function (opt, useMTV) {
  2000. _ctx.touchThreshold = 0;
  2001. if (opt && opt.touchThreshold != null) {
  2002. _ctx.touchThreshold = mathMax(0, opt.touchThreshold);
  2003. }
  2004. _ctx.negativeSize = false;
  2005. if (!useMTV) {
  2006. return;
  2007. }
  2008. _ctx.minTv.set(Infinity, Infinity);
  2009. _ctx.maxTv.set(0, 0);
  2010. _ctx.useDir = false;
  2011. if (opt && opt.direction != null) {
  2012. _ctx.useDir = true;
  2013. _ctx.dirMinTv.copy(_ctx.minTv);
  2014. _dirTmp.copy(_ctx.minTv);
  2015. _direction = opt.direction;
  2016. _ctx.bidirectional = opt.bidirectional == null || !!opt.bidirectional;
  2017. if (!_ctx.bidirectional) {
  2018. _dirCheckVec.set(Math.cos(_direction), Math.sin(_direction));
  2019. }
  2020. }
  2021. },
  2022. calcDirMTV: function () {
  2023. var minTv = _ctx.minTv;
  2024. var dirMinTv = _ctx.dirMinTv;
  2025. var squareMag = minTv.y * minTv.y + minTv.x * minTv.x;
  2026. var dirSin = Math.sin(_direction);
  2027. var dirCos = Math.cos(_direction);
  2028. var dotProd = dirSin * minTv.y + dirCos * minTv.x;
  2029. if (nearZero(dotProd)) {
  2030. if (nearZero(minTv.x) && nearZero(minTv.y)) {
  2031. dirMinTv.set(0, 0);
  2032. }
  2033. return;
  2034. }
  2035. _dirTmp.x = squareMag * dirCos / dotProd;
  2036. _dirTmp.y = squareMag * dirSin / dotProd;
  2037. if (nearZero(_dirTmp.x) && nearZero(_dirTmp.y)) {
  2038. dirMinTv.set(0, 0);
  2039. return;
  2040. }
  2041. if ((_ctx.bidirectional
  2042. || _dirCheckVec.dot(_dirTmp) > 0)
  2043. && _dirTmp.len() < dirMinTv.len()) {
  2044. dirMinTv.copy(_dirTmp);
  2045. }
  2046. }
  2047. };
  2048. function nearZero(val) {
  2049. return mathAbs(val) < 1e-10;
  2050. }
  2051. return _ctx;
  2052. }
  2053. var SILENT = 'silent';
  2054. function makeEventPacket(eveType, targetInfo, event) {
  2055. return {
  2056. type: eveType,
  2057. event: event,
  2058. target: targetInfo.target,
  2059. topTarget: targetInfo.topTarget,
  2060. cancelBubble: false,
  2061. offsetX: event.zrX,
  2062. offsetY: event.zrY,
  2063. gestureEvent: event.gestureEvent,
  2064. pinchX: event.pinchX,
  2065. pinchY: event.pinchY,
  2066. pinchScale: event.pinchScale,
  2067. wheelDelta: event.zrDelta,
  2068. zrByTouch: event.zrByTouch,
  2069. which: event.which,
  2070. stop: stopEvent
  2071. };
  2072. }
  2073. function stopEvent() {
  2074. stop(this.event);
  2075. }
  2076. var EmptyProxy = (function (_super) {
  2077. __extends(EmptyProxy, _super);
  2078. function EmptyProxy() {
  2079. var _this = _super !== null && _super.apply(this, arguments) || this;
  2080. _this.handler = null;
  2081. return _this;
  2082. }
  2083. EmptyProxy.prototype.dispose = function () { };
  2084. EmptyProxy.prototype.setCursor = function () { };
  2085. return EmptyProxy;
  2086. }(Eventful));
  2087. var HoveredResult = (function () {
  2088. function HoveredResult(x, y) {
  2089. this.x = x;
  2090. this.y = y;
  2091. }
  2092. return HoveredResult;
  2093. }());
  2094. var handlerNames = [
  2095. 'click', 'dblclick', 'mousewheel', 'mouseout',
  2096. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  2097. ];
  2098. var tmpRect = new BoundingRect(0, 0, 0, 0);
  2099. var Handler = (function (_super) {
  2100. __extends(Handler, _super);
  2101. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  2102. var _this = _super.call(this) || this;
  2103. _this._hovered = new HoveredResult(0, 0);
  2104. _this.storage = storage;
  2105. _this.painter = painter;
  2106. _this.painterRoot = painterRoot;
  2107. _this._pointerSize = pointerSize;
  2108. proxy = proxy || new EmptyProxy();
  2109. _this.proxy = null;
  2110. _this.setHandlerProxy(proxy);
  2111. _this._draggingMgr = new Draggable(_this);
  2112. return _this;
  2113. }
  2114. Handler.prototype.setHandlerProxy = function (proxy) {
  2115. if (this.proxy) {
  2116. this.proxy.dispose();
  2117. }
  2118. if (proxy) {
  2119. each(handlerNames, function (name) {
  2120. proxy.on && proxy.on(name, this[name], this);
  2121. }, this);
  2122. proxy.handler = this;
  2123. }
  2124. this.proxy = proxy;
  2125. };
  2126. Handler.prototype.mousemove = function (event) {
  2127. var x = event.zrX;
  2128. var y = event.zrY;
  2129. var isOutside = isOutsideBoundary(this, x, y);
  2130. var lastHovered = this._hovered;
  2131. var lastHoveredTarget = lastHovered.target;
  2132. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2133. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2134. lastHoveredTarget = lastHovered.target;
  2135. }
  2136. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  2137. var hoveredTarget = hovered.target;
  2138. var proxy = this.proxy;
  2139. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2140. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2141. this.dispatchToElement(lastHovered, 'mouseout', event);
  2142. }
  2143. this.dispatchToElement(hovered, 'mousemove', event);
  2144. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2145. this.dispatchToElement(hovered, 'mouseover', event);
  2146. }
  2147. };
  2148. Handler.prototype.mouseout = function (event) {
  2149. var eventControl = event.zrEventControl;
  2150. if (eventControl !== 'only_globalout') {
  2151. this.dispatchToElement(this._hovered, 'mouseout', event);
  2152. }
  2153. if (eventControl !== 'no_globalout') {
  2154. this.trigger('globalout', { type: 'globalout', event: event });
  2155. }
  2156. };
  2157. Handler.prototype.resize = function () {
  2158. this._hovered = new HoveredResult(0, 0);
  2159. };
  2160. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2161. var handler = this[eventName];
  2162. handler && handler.call(this, eventArgs);
  2163. };
  2164. Handler.prototype.dispose = function () {
  2165. this.proxy.dispose();
  2166. this.storage = null;
  2167. this.proxy = null;
  2168. this.painter = null;
  2169. };
  2170. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2171. var proxy = this.proxy;
  2172. proxy.setCursor && proxy.setCursor(cursorStyle);
  2173. };
  2174. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2175. targetInfo = targetInfo || {};
  2176. var el = targetInfo.target;
  2177. if (el && el.silent) {
  2178. return;
  2179. }
  2180. var eventKey = ('on' + eventName);
  2181. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2182. while (el) {
  2183. el[eventKey]
  2184. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2185. el.trigger(eventName, eventPacket);
  2186. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2187. if (eventPacket.cancelBubble) {
  2188. break;
  2189. }
  2190. }
  2191. if (!eventPacket.cancelBubble) {
  2192. this.trigger(eventName, eventPacket);
  2193. if (this.painter && this.painter.eachOtherLayer) {
  2194. this.painter.eachOtherLayer(function (layer) {
  2195. if (typeof (layer[eventKey]) === 'function') {
  2196. layer[eventKey].call(layer, eventPacket);
  2197. }
  2198. if (layer.trigger) {
  2199. layer.trigger(eventName, eventPacket);
  2200. }
  2201. });
  2202. }
  2203. }
  2204. };
  2205. Handler.prototype.findHover = function (x, y, exclude) {
  2206. var list = this.storage.getDisplayList();
  2207. var out = new HoveredResult(x, y);
  2208. setHoverTarget(list, out, x, y, exclude);
  2209. if (this._pointerSize && !out.target) {
  2210. var candidates = [];
  2211. var pointerSize = this._pointerSize;
  2212. var targetSizeHalf = pointerSize / 2;
  2213. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2214. for (var i = list.length - 1; i >= 0; i--) {
  2215. var el = list[i];
  2216. if (el !== exclude
  2217. && !el.ignore
  2218. && !el.ignoreCoarsePointer
  2219. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2220. tmpRect.copy(el.getBoundingRect());
  2221. if (el.transform) {
  2222. tmpRect.applyTransform(el.transform);
  2223. }
  2224. if (tmpRect.intersect(pointerRect)) {
  2225. candidates.push(el);
  2226. }
  2227. }
  2228. }
  2229. if (candidates.length) {
  2230. var rStep = 4;
  2231. var thetaStep = Math.PI / 12;
  2232. var PI2 = Math.PI * 2;
  2233. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2234. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2235. var x1 = x + r * Math.cos(theta);
  2236. var y1 = y + r * Math.sin(theta);
  2237. setHoverTarget(candidates, out, x1, y1, exclude);
  2238. if (out.target) {
  2239. return out;
  2240. }
  2241. }
  2242. }
  2243. }
  2244. }
  2245. return out;
  2246. };
  2247. Handler.prototype.processGesture = function (event, stage) {
  2248. if (!this._gestureMgr) {
  2249. this._gestureMgr = new GestureMgr();
  2250. }
  2251. var gestureMgr = this._gestureMgr;
  2252. stage === 'start' && gestureMgr.clear();
  2253. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2254. stage === 'end' && gestureMgr.clear();
  2255. if (gestureInfo) {
  2256. var type = gestureInfo.type;
  2257. event.gestureEvent = type;
  2258. var res = new HoveredResult();
  2259. res.target = gestureInfo.target;
  2260. this.dispatchToElement(res, type, gestureInfo.event);
  2261. }
  2262. };
  2263. return Handler;
  2264. }(Eventful));
  2265. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2266. Handler.prototype[name] = function (event) {
  2267. var x = event.zrX;
  2268. var y = event.zrY;
  2269. var isOutside = isOutsideBoundary(this, x, y);
  2270. var hovered;
  2271. var hoveredTarget;
  2272. if (name !== 'mouseup' || !isOutside) {
  2273. hovered = this.findHover(x, y);
  2274. hoveredTarget = hovered.target;
  2275. }
  2276. if (name === 'mousedown') {
  2277. this._downEl = hoveredTarget;
  2278. this._downPoint = [event.zrX, event.zrY];
  2279. this._upEl = hoveredTarget;
  2280. }
  2281. else if (name === 'mouseup') {
  2282. this._upEl = hoveredTarget;
  2283. }
  2284. else if (name === 'click') {
  2285. if (this._downEl !== this._upEl
  2286. || !this._downPoint
  2287. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2288. return;
  2289. }
  2290. this._downPoint = null;
  2291. }
  2292. this.dispatchToElement(hovered, name, event);
  2293. };
  2294. });
  2295. function isHover(displayable, x, y) {
  2296. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2297. var el = displayable;
  2298. var isSilent = void 0;
  2299. var ignoreClip = false;
  2300. while (el) {
  2301. if (el.ignoreClip) {
  2302. ignoreClip = true;
  2303. }
  2304. if (!ignoreClip) {
  2305. var clipPath = el.getClipPath();
  2306. if (clipPath && !clipPath.contain(x, y)) {
  2307. return false;
  2308. }
  2309. }
  2310. if (el.silent) {
  2311. isSilent = true;
  2312. }
  2313. var hostEl = el.__hostTarget;
  2314. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  2315. }
  2316. return isSilent ? SILENT : true;
  2317. }
  2318. return false;
  2319. }
  2320. function setHoverTarget(list, out, x, y, exclude) {
  2321. for (var i = list.length - 1; i >= 0; i--) {
  2322. var el = list[i];
  2323. var hoverCheckResult = void 0;
  2324. if (el !== exclude
  2325. && !el.ignore
  2326. && (hoverCheckResult = isHover(el, x, y))) {
  2327. !out.topTarget && (out.topTarget = el);
  2328. if (hoverCheckResult !== SILENT) {
  2329. out.target = el;
  2330. break;
  2331. }
  2332. }
  2333. }
  2334. }
  2335. function isOutsideBoundary(handlerInstance, x, y) {
  2336. var painter = handlerInstance.painter;
  2337. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2338. }
  2339. var DEFAULT_MIN_MERGE = 32;
  2340. var DEFAULT_MIN_GALLOPING = 7;
  2341. function minRunLength(n) {
  2342. var r = 0;
  2343. while (n >= DEFAULT_MIN_MERGE) {
  2344. r |= n & 1;
  2345. n >>= 1;
  2346. }
  2347. return n + r;
  2348. }
  2349. function makeAscendingRun(array, lo, hi, compare) {
  2350. var runHi = lo + 1;
  2351. if (runHi === hi) {
  2352. return 1;
  2353. }
  2354. if (compare(array[runHi++], array[lo]) < 0) {
  2355. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2356. runHi++;
  2357. }
  2358. reverseRun(array, lo, runHi);
  2359. }
  2360. else {
  2361. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2362. runHi++;
  2363. }
  2364. }
  2365. return runHi - lo;
  2366. }
  2367. function reverseRun(array, lo, hi) {
  2368. hi--;
  2369. while (lo < hi) {
  2370. var t = array[lo];
  2371. array[lo++] = array[hi];
  2372. array[hi--] = t;
  2373. }
  2374. }
  2375. function binaryInsertionSort(array, lo, hi, start, compare) {
  2376. if (start === lo) {
  2377. start++;
  2378. }
  2379. for (; start < hi; start++) {
  2380. var pivot = array[start];
  2381. var left = lo;
  2382. var right = start;
  2383. var mid;
  2384. while (left < right) {
  2385. mid = left + right >>> 1;
  2386. if (compare(pivot, array[mid]) < 0) {
  2387. right = mid;
  2388. }
  2389. else {
  2390. left = mid + 1;
  2391. }
  2392. }
  2393. var n = start - left;
  2394. switch (n) {
  2395. case 3:
  2396. array[left + 3] = array[left + 2];
  2397. case 2:
  2398. array[left + 2] = array[left + 1];
  2399. case 1:
  2400. array[left + 1] = array[left];
  2401. break;
  2402. default:
  2403. while (n > 0) {
  2404. array[left + n] = array[left + n - 1];
  2405. n--;
  2406. }
  2407. }
  2408. array[left] = pivot;
  2409. }
  2410. }
  2411. function gallopLeft(value, array, start, length, hint, compare) {
  2412. var lastOffset = 0;
  2413. var maxOffset = 0;
  2414. var offset = 1;
  2415. if (compare(value, array[start + hint]) > 0) {
  2416. maxOffset = length - hint;
  2417. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2418. lastOffset = offset;
  2419. offset = (offset << 1) + 1;
  2420. if (offset <= 0) {
  2421. offset = maxOffset;
  2422. }
  2423. }
  2424. if (offset > maxOffset) {
  2425. offset = maxOffset;
  2426. }
  2427. lastOffset += hint;
  2428. offset += hint;
  2429. }
  2430. else {
  2431. maxOffset = hint + 1;
  2432. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2433. lastOffset = offset;
  2434. offset = (offset << 1) + 1;
  2435. if (offset <= 0) {
  2436. offset = maxOffset;
  2437. }
  2438. }
  2439. if (offset > maxOffset) {
  2440. offset = maxOffset;
  2441. }
  2442. var tmp = lastOffset;
  2443. lastOffset = hint - offset;
  2444. offset = hint - tmp;
  2445. }
  2446. lastOffset++;
  2447. while (lastOffset < offset) {
  2448. var m = lastOffset + (offset - lastOffset >>> 1);
  2449. if (compare(value, array[start + m]) > 0) {
  2450. lastOffset = m + 1;
  2451. }
  2452. else {
  2453. offset = m;
  2454. }
  2455. }
  2456. return offset;
  2457. }
  2458. function gallopRight(value, array, start, length, hint, compare) {
  2459. var lastOffset = 0;
  2460. var maxOffset = 0;
  2461. var offset = 1;
  2462. if (compare(value, array[start + hint]) < 0) {
  2463. maxOffset = hint + 1;
  2464. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2465. lastOffset = offset;
  2466. offset = (offset << 1) + 1;
  2467. if (offset <= 0) {
  2468. offset = maxOffset;
  2469. }
  2470. }
  2471. if (offset > maxOffset) {
  2472. offset = maxOffset;
  2473. }
  2474. var tmp = lastOffset;
  2475. lastOffset = hint - offset;
  2476. offset = hint - tmp;
  2477. }
  2478. else {
  2479. maxOffset = length - hint;
  2480. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2481. lastOffset = offset;
  2482. offset = (offset << 1) + 1;
  2483. if (offset <= 0) {
  2484. offset = maxOffset;
  2485. }
  2486. }
  2487. if (offset > maxOffset) {
  2488. offset = maxOffset;
  2489. }
  2490. lastOffset += hint;
  2491. offset += hint;
  2492. }
  2493. lastOffset++;
  2494. while (lastOffset < offset) {
  2495. var m = lastOffset + (offset - lastOffset >>> 1);
  2496. if (compare(value, array[start + m]) < 0) {
  2497. offset = m;
  2498. }
  2499. else {
  2500. lastOffset = m + 1;
  2501. }
  2502. }
  2503. return offset;
  2504. }
  2505. function TimSort(array, compare) {
  2506. var minGallop = DEFAULT_MIN_GALLOPING;
  2507. var runStart;
  2508. var runLength;
  2509. var stackSize = 0;
  2510. var tmp = [];
  2511. runStart = [];
  2512. runLength = [];
  2513. function pushRun(_runStart, _runLength) {
  2514. runStart[stackSize] = _runStart;
  2515. runLength[stackSize] = _runLength;
  2516. stackSize += 1;
  2517. }
  2518. function mergeRuns() {
  2519. while (stackSize > 1) {
  2520. var n = stackSize - 2;
  2521. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2522. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2523. if (runLength[n - 1] < runLength[n + 1]) {
  2524. n--;
  2525. }
  2526. }
  2527. else if (runLength[n] > runLength[n + 1]) {
  2528. break;
  2529. }
  2530. mergeAt(n);
  2531. }
  2532. }
  2533. function forceMergeRuns() {
  2534. while (stackSize > 1) {
  2535. var n = stackSize - 2;
  2536. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2537. n--;
  2538. }
  2539. mergeAt(n);
  2540. }
  2541. }
  2542. function mergeAt(i) {
  2543. var start1 = runStart[i];
  2544. var length1 = runLength[i];
  2545. var start2 = runStart[i + 1];
  2546. var length2 = runLength[i + 1];
  2547. runLength[i] = length1 + length2;
  2548. if (i === stackSize - 3) {
  2549. runStart[i + 1] = runStart[i + 2];
  2550. runLength[i + 1] = runLength[i + 2];
  2551. }
  2552. stackSize--;
  2553. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2554. start1 += k;
  2555. length1 -= k;
  2556. if (length1 === 0) {
  2557. return;
  2558. }
  2559. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2560. if (length2 === 0) {
  2561. return;
  2562. }
  2563. if (length1 <= length2) {
  2564. mergeLow(start1, length1, start2, length2);
  2565. }
  2566. else {
  2567. mergeHigh(start1, length1, start2, length2);
  2568. }
  2569. }
  2570. function mergeLow(start1, length1, start2, length2) {
  2571. var i = 0;
  2572. for (i = 0; i < length1; i++) {
  2573. tmp[i] = array[start1 + i];
  2574. }
  2575. var cursor1 = 0;
  2576. var cursor2 = start2;
  2577. var dest = start1;
  2578. array[dest++] = array[cursor2++];
  2579. if (--length2 === 0) {
  2580. for (i = 0; i < length1; i++) {
  2581. array[dest + i] = tmp[cursor1 + i];
  2582. }
  2583. return;
  2584. }
  2585. if (length1 === 1) {
  2586. for (i = 0; i < length2; i++) {
  2587. array[dest + i] = array[cursor2 + i];
  2588. }
  2589. array[dest + length2] = tmp[cursor1];
  2590. return;
  2591. }
  2592. var _minGallop = minGallop;
  2593. var count1;
  2594. var count2;
  2595. var exit;
  2596. while (1) {
  2597. count1 = 0;
  2598. count2 = 0;
  2599. exit = false;
  2600. do {
  2601. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2602. array[dest++] = array[cursor2++];
  2603. count2++;
  2604. count1 = 0;
  2605. if (--length2 === 0) {
  2606. exit = true;
  2607. break;
  2608. }
  2609. }
  2610. else {
  2611. array[dest++] = tmp[cursor1++];
  2612. count1++;
  2613. count2 = 0;
  2614. if (--length1 === 1) {
  2615. exit = true;
  2616. break;
  2617. }
  2618. }
  2619. } while ((count1 | count2) < _minGallop);
  2620. if (exit) {
  2621. break;
  2622. }
  2623. do {
  2624. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2625. if (count1 !== 0) {
  2626. for (i = 0; i < count1; i++) {
  2627. array[dest + i] = tmp[cursor1 + i];
  2628. }
  2629. dest += count1;
  2630. cursor1 += count1;
  2631. length1 -= count1;
  2632. if (length1 <= 1) {
  2633. exit = true;
  2634. break;
  2635. }
  2636. }
  2637. array[dest++] = array[cursor2++];
  2638. if (--length2 === 0) {
  2639. exit = true;
  2640. break;
  2641. }
  2642. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2643. if (count2 !== 0) {
  2644. for (i = 0; i < count2; i++) {
  2645. array[dest + i] = array[cursor2 + i];
  2646. }
  2647. dest += count2;
  2648. cursor2 += count2;
  2649. length2 -= count2;
  2650. if (length2 === 0) {
  2651. exit = true;
  2652. break;
  2653. }
  2654. }
  2655. array[dest++] = tmp[cursor1++];
  2656. if (--length1 === 1) {
  2657. exit = true;
  2658. break;
  2659. }
  2660. _minGallop--;
  2661. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2662. if (exit) {
  2663. break;
  2664. }
  2665. if (_minGallop < 0) {
  2666. _minGallop = 0;
  2667. }
  2668. _minGallop += 2;
  2669. }
  2670. minGallop = _minGallop;
  2671. minGallop < 1 && (minGallop = 1);
  2672. if (length1 === 1) {
  2673. for (i = 0; i < length2; i++) {
  2674. array[dest + i] = array[cursor2 + i];
  2675. }
  2676. array[dest + length2] = tmp[cursor1];
  2677. }
  2678. else if (length1 === 0) {
  2679. throw new Error();
  2680. }
  2681. else {
  2682. for (i = 0; i < length1; i++) {
  2683. array[dest + i] = tmp[cursor1 + i];
  2684. }
  2685. }
  2686. }
  2687. function mergeHigh(start1, length1, start2, length2) {
  2688. var i = 0;
  2689. for (i = 0; i < length2; i++) {
  2690. tmp[i] = array[start2 + i];
  2691. }
  2692. var cursor1 = start1 + length1 - 1;
  2693. var cursor2 = length2 - 1;
  2694. var dest = start2 + length2 - 1;
  2695. var customCursor = 0;
  2696. var customDest = 0;
  2697. array[dest--] = array[cursor1--];
  2698. if (--length1 === 0) {
  2699. customCursor = dest - (length2 - 1);
  2700. for (i = 0; i < length2; i++) {
  2701. array[customCursor + i] = tmp[i];
  2702. }
  2703. return;
  2704. }
  2705. if (length2 === 1) {
  2706. dest -= length1;
  2707. cursor1 -= length1;
  2708. customDest = dest + 1;
  2709. customCursor = cursor1 + 1;
  2710. for (i = length1 - 1; i >= 0; i--) {
  2711. array[customDest + i] = array[customCursor + i];
  2712. }
  2713. array[dest] = tmp[cursor2];
  2714. return;
  2715. }
  2716. var _minGallop = minGallop;
  2717. while (true) {
  2718. var count1 = 0;
  2719. var count2 = 0;
  2720. var exit = false;
  2721. do {
  2722. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2723. array[dest--] = array[cursor1--];
  2724. count1++;
  2725. count2 = 0;
  2726. if (--length1 === 0) {
  2727. exit = true;
  2728. break;
  2729. }
  2730. }
  2731. else {
  2732. array[dest--] = tmp[cursor2--];
  2733. count2++;
  2734. count1 = 0;
  2735. if (--length2 === 1) {
  2736. exit = true;
  2737. break;
  2738. }
  2739. }
  2740. } while ((count1 | count2) < _minGallop);
  2741. if (exit) {
  2742. break;
  2743. }
  2744. do {
  2745. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2746. if (count1 !== 0) {
  2747. dest -= count1;
  2748. cursor1 -= count1;
  2749. length1 -= count1;
  2750. customDest = dest + 1;
  2751. customCursor = cursor1 + 1;
  2752. for (i = count1 - 1; i >= 0; i--) {
  2753. array[customDest + i] = array[customCursor + i];
  2754. }
  2755. if (length1 === 0) {
  2756. exit = true;
  2757. break;
  2758. }
  2759. }
  2760. array[dest--] = tmp[cursor2--];
  2761. if (--length2 === 1) {
  2762. exit = true;
  2763. break;
  2764. }
  2765. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2766. if (count2 !== 0) {
  2767. dest -= count2;
  2768. cursor2 -= count2;
  2769. length2 -= count2;
  2770. customDest = dest + 1;
  2771. customCursor = cursor2 + 1;
  2772. for (i = 0; i < count2; i++) {
  2773. array[customDest + i] = tmp[customCursor + i];
  2774. }
  2775. if (length2 <= 1) {
  2776. exit = true;
  2777. break;
  2778. }
  2779. }
  2780. array[dest--] = array[cursor1--];
  2781. if (--length1 === 0) {
  2782. exit = true;
  2783. break;
  2784. }
  2785. _minGallop--;
  2786. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2787. if (exit) {
  2788. break;
  2789. }
  2790. if (_minGallop < 0) {
  2791. _minGallop = 0;
  2792. }
  2793. _minGallop += 2;
  2794. }
  2795. minGallop = _minGallop;
  2796. if (minGallop < 1) {
  2797. minGallop = 1;
  2798. }
  2799. if (length2 === 1) {
  2800. dest -= length1;
  2801. cursor1 -= length1;
  2802. customDest = dest + 1;
  2803. customCursor = cursor1 + 1;
  2804. for (i = length1 - 1; i >= 0; i--) {
  2805. array[customDest + i] = array[customCursor + i];
  2806. }
  2807. array[dest] = tmp[cursor2];
  2808. }
  2809. else if (length2 === 0) {
  2810. throw new Error();
  2811. }
  2812. else {
  2813. customCursor = dest - (length2 - 1);
  2814. for (i = 0; i < length2; i++) {
  2815. array[customCursor + i] = tmp[i];
  2816. }
  2817. }
  2818. }
  2819. return {
  2820. mergeRuns: mergeRuns,
  2821. forceMergeRuns: forceMergeRuns,
  2822. pushRun: pushRun
  2823. };
  2824. }
  2825. function sort(array, compare, lo, hi) {
  2826. if (!lo) {
  2827. lo = 0;
  2828. }
  2829. if (!hi) {
  2830. hi = array.length;
  2831. }
  2832. var remaining = hi - lo;
  2833. if (remaining < 2) {
  2834. return;
  2835. }
  2836. var runLength = 0;
  2837. if (remaining < DEFAULT_MIN_MERGE) {
  2838. runLength = makeAscendingRun(array, lo, hi, compare);
  2839. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2840. return;
  2841. }
  2842. var ts = TimSort(array, compare);
  2843. var minRun = minRunLength(remaining);
  2844. do {
  2845. runLength = makeAscendingRun(array, lo, hi, compare);
  2846. if (runLength < minRun) {
  2847. var force = remaining;
  2848. if (force > minRun) {
  2849. force = minRun;
  2850. }
  2851. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2852. runLength = force;
  2853. }
  2854. ts.pushRun(lo, runLength);
  2855. ts.mergeRuns();
  2856. remaining -= runLength;
  2857. lo += runLength;
  2858. } while (remaining !== 0);
  2859. ts.forceMergeRuns();
  2860. }
  2861. var REDRAW_BIT = 1;
  2862. var STYLE_CHANGED_BIT = 2;
  2863. var SHAPE_CHANGED_BIT = 4;
  2864. var invalidZErrorLogged = false;
  2865. function logInvalidZError() {
  2866. if (invalidZErrorLogged) {
  2867. return;
  2868. }
  2869. invalidZErrorLogged = true;
  2870. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2871. }
  2872. function shapeCompareFunc(a, b) {
  2873. if (a.zlevel === b.zlevel) {
  2874. if (a.z === b.z) {
  2875. return a.z2 - b.z2;
  2876. }
  2877. return a.z - b.z;
  2878. }
  2879. return a.zlevel - b.zlevel;
  2880. }
  2881. var Storage = (function () {
  2882. function Storage() {
  2883. this._roots = [];
  2884. this._displayList = [];
  2885. this._displayListLen = 0;
  2886. this.displayableSortFunc = shapeCompareFunc;
  2887. }
  2888. Storage.prototype.traverse = function (cb, context) {
  2889. for (var i = 0; i < this._roots.length; i++) {
  2890. this._roots[i].traverse(cb, context);
  2891. }
  2892. };
  2893. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2894. includeIgnore = includeIgnore || false;
  2895. var displayList = this._displayList;
  2896. if (update || !displayList.length) {
  2897. this.updateDisplayList(includeIgnore);
  2898. }
  2899. return displayList;
  2900. };
  2901. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2902. this._displayListLen = 0;
  2903. var roots = this._roots;
  2904. var displayList = this._displayList;
  2905. for (var i = 0, len = roots.length; i < len; i++) {
  2906. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2907. }
  2908. displayList.length = this._displayListLen;
  2909. sort(displayList, shapeCompareFunc);
  2910. };
  2911. Storage.prototype._updateAndAddDisplayable = function (el, parentClipPaths, includeIgnore) {
  2912. if (el.ignore && !includeIgnore) {
  2913. return;
  2914. }
  2915. el.beforeUpdate();
  2916. el.update();
  2917. el.afterUpdate();
  2918. var userSetClipPath = el.getClipPath();
  2919. var parentHasClipPaths = parentClipPaths && parentClipPaths.length;
  2920. var clipPathIdx = 0;
  2921. var thisClipPaths = el.__clipPaths;
  2922. if (!el.ignoreClip
  2923. && (parentHasClipPaths || userSetClipPath)) {
  2924. if (!thisClipPaths) {
  2925. thisClipPaths = el.__clipPaths = [];
  2926. }
  2927. if (parentHasClipPaths) {
  2928. for (var idx = 0; idx < parentClipPaths.length; idx++) {
  2929. thisClipPaths[clipPathIdx++] = parentClipPaths[idx];
  2930. }
  2931. }
  2932. var currentClipPath = userSetClipPath;
  2933. var parentClipPath = el;
  2934. while (currentClipPath) {
  2935. currentClipPath.parent = parentClipPath;
  2936. currentClipPath.updateTransform();
  2937. thisClipPaths[clipPathIdx++] = currentClipPath;
  2938. parentClipPath = currentClipPath;
  2939. currentClipPath = currentClipPath.getClipPath();
  2940. }
  2941. }
  2942. if (thisClipPaths) {
  2943. thisClipPaths.length = clipPathIdx;
  2944. }
  2945. if (el.childrenRef) {
  2946. var children = el.childrenRef();
  2947. for (var i = 0; i < children.length; i++) {
  2948. var child = children[i];
  2949. if (el.__dirty) {
  2950. child.__dirty |= REDRAW_BIT;
  2951. }
  2952. this._updateAndAddDisplayable(child, thisClipPaths, includeIgnore);
  2953. }
  2954. el.__dirty = 0;
  2955. }
  2956. else {
  2957. var disp = el;
  2958. if (isNaN(disp.z)) {
  2959. logInvalidZError();
  2960. disp.z = 0;
  2961. }
  2962. if (isNaN(disp.z2)) {
  2963. logInvalidZError();
  2964. disp.z2 = 0;
  2965. }
  2966. if (isNaN(disp.zlevel)) {
  2967. logInvalidZError();
  2968. disp.zlevel = 0;
  2969. }
  2970. this._displayList[this._displayListLen++] = disp;
  2971. }
  2972. var decalEl = el.getDecalElement && el.getDecalElement();
  2973. if (decalEl) {
  2974. this._updateAndAddDisplayable(decalEl, thisClipPaths, includeIgnore);
  2975. }
  2976. var textGuide = el.getTextGuideLine();
  2977. if (textGuide) {
  2978. this._updateAndAddDisplayable(textGuide, thisClipPaths, includeIgnore);
  2979. }
  2980. var textEl = el.getTextContent();
  2981. if (textEl) {
  2982. this._updateAndAddDisplayable(textEl, thisClipPaths, includeIgnore);
  2983. }
  2984. };
  2985. Storage.prototype.addRoot = function (el) {
  2986. if (el.__zr && el.__zr.storage === this) {
  2987. return;
  2988. }
  2989. this._roots.push(el);
  2990. };
  2991. Storage.prototype.delRoot = function (el) {
  2992. if (el instanceof Array) {
  2993. for (var i = 0, l = el.length; i < l; i++) {
  2994. this.delRoot(el[i]);
  2995. }
  2996. return;
  2997. }
  2998. var idx = indexOf(this._roots, el);
  2999. if (idx >= 0) {
  3000. this._roots.splice(idx, 1);
  3001. }
  3002. };
  3003. Storage.prototype.delAllRoots = function () {
  3004. this._roots = [];
  3005. this._displayList = [];
  3006. this._displayListLen = 0;
  3007. return;
  3008. };
  3009. Storage.prototype.getRoots = function () {
  3010. return this._roots;
  3011. };
  3012. Storage.prototype.dispose = function () {
  3013. this._displayList = null;
  3014. this._roots = null;
  3015. };
  3016. return Storage;
  3017. }());
  3018. var requestAnimationFrame;
  3019. requestAnimationFrame = (env.hasGlobalWindow
  3020. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  3021. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  3022. || window.mozRequestAnimationFrame
  3023. || window.webkitRequestAnimationFrame)) || function (func) {
  3024. return setTimeout(func, 16);
  3025. };
  3026. var requestAnimationFrame$1 = requestAnimationFrame;
  3027. var easingFuncs = {
  3028. linear: function (k) {
  3029. return k;
  3030. },
  3031. quadraticIn: function (k) {
  3032. return k * k;
  3033. },
  3034. quadraticOut: function (k) {
  3035. return k * (2 - k);
  3036. },
  3037. quadraticInOut: function (k) {
  3038. if ((k *= 2) < 1) {
  3039. return 0.5 * k * k;
  3040. }
  3041. return -0.5 * (--k * (k - 2) - 1);
  3042. },
  3043. cubicIn: function (k) {
  3044. return k * k * k;
  3045. },
  3046. cubicOut: function (k) {
  3047. return --k * k * k + 1;
  3048. },
  3049. cubicInOut: function (k) {
  3050. if ((k *= 2) < 1) {
  3051. return 0.5 * k * k * k;
  3052. }
  3053. return 0.5 * ((k -= 2) * k * k + 2);
  3054. },
  3055. quarticIn: function (k) {
  3056. return k * k * k * k;
  3057. },
  3058. quarticOut: function (k) {
  3059. return 1 - (--k * k * k * k);
  3060. },
  3061. quarticInOut: function (k) {
  3062. if ((k *= 2) < 1) {
  3063. return 0.5 * k * k * k * k;
  3064. }
  3065. return -0.5 * ((k -= 2) * k * k * k - 2);
  3066. },
  3067. quinticIn: function (k) {
  3068. return k * k * k * k * k;
  3069. },
  3070. quinticOut: function (k) {
  3071. return --k * k * k * k * k + 1;
  3072. },
  3073. quinticInOut: function (k) {
  3074. if ((k *= 2) < 1) {
  3075. return 0.5 * k * k * k * k * k;
  3076. }
  3077. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  3078. },
  3079. sinusoidalIn: function (k) {
  3080. return 1 - Math.cos(k * Math.PI / 2);
  3081. },
  3082. sinusoidalOut: function (k) {
  3083. return Math.sin(k * Math.PI / 2);
  3084. },
  3085. sinusoidalInOut: function (k) {
  3086. return 0.5 * (1 - Math.cos(Math.PI * k));
  3087. },
  3088. exponentialIn: function (k) {
  3089. return k === 0 ? 0 : Math.pow(1024, k - 1);
  3090. },
  3091. exponentialOut: function (k) {
  3092. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  3093. },
  3094. exponentialInOut: function (k) {
  3095. if (k === 0) {
  3096. return 0;
  3097. }
  3098. if (k === 1) {
  3099. return 1;
  3100. }
  3101. if ((k *= 2) < 1) {
  3102. return 0.5 * Math.pow(1024, k - 1);
  3103. }
  3104. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  3105. },
  3106. circularIn: function (k) {
  3107. return 1 - Math.sqrt(1 - k * k);
  3108. },
  3109. circularOut: function (k) {
  3110. return Math.sqrt(1 - (--k * k));
  3111. },
  3112. circularInOut: function (k) {
  3113. if ((k *= 2) < 1) {
  3114. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  3115. }
  3116. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  3117. },
  3118. elasticIn: function (k) {
  3119. var s;
  3120. var a = 0.1;
  3121. var p = 0.4;
  3122. if (k === 0) {
  3123. return 0;
  3124. }
  3125. if (k === 1) {
  3126. return 1;
  3127. }
  3128. if (!a || a < 1) {
  3129. a = 1;
  3130. s = p / 4;
  3131. }
  3132. else {
  3133. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3134. }
  3135. return -(a * Math.pow(2, 10 * (k -= 1))
  3136. * Math.sin((k - s) * (2 * Math.PI) / p));
  3137. },
  3138. elasticOut: function (k) {
  3139. var s;
  3140. var a = 0.1;
  3141. var p = 0.4;
  3142. if (k === 0) {
  3143. return 0;
  3144. }
  3145. if (k === 1) {
  3146. return 1;
  3147. }
  3148. if (!a || a < 1) {
  3149. a = 1;
  3150. s = p / 4;
  3151. }
  3152. else {
  3153. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3154. }
  3155. return (a * Math.pow(2, -10 * k)
  3156. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3157. },
  3158. elasticInOut: function (k) {
  3159. var s;
  3160. var a = 0.1;
  3161. var p = 0.4;
  3162. if (k === 0) {
  3163. return 0;
  3164. }
  3165. if (k === 1) {
  3166. return 1;
  3167. }
  3168. if (!a || a < 1) {
  3169. a = 1;
  3170. s = p / 4;
  3171. }
  3172. else {
  3173. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3174. }
  3175. if ((k *= 2) < 1) {
  3176. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3177. * Math.sin((k - s) * (2 * Math.PI) / p));
  3178. }
  3179. return a * Math.pow(2, -10 * (k -= 1))
  3180. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3181. },
  3182. backIn: function (k) {
  3183. var s = 1.70158;
  3184. return k * k * ((s + 1) * k - s);
  3185. },
  3186. backOut: function (k) {
  3187. var s = 1.70158;
  3188. return --k * k * ((s + 1) * k + s) + 1;
  3189. },
  3190. backInOut: function (k) {
  3191. var s = 1.70158 * 1.525;
  3192. if ((k *= 2) < 1) {
  3193. return 0.5 * (k * k * ((s + 1) * k - s));
  3194. }
  3195. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3196. },
  3197. bounceIn: function (k) {
  3198. return 1 - easingFuncs.bounceOut(1 - k);
  3199. },
  3200. bounceOut: function (k) {
  3201. if (k < (1 / 2.75)) {
  3202. return 7.5625 * k * k;
  3203. }
  3204. else if (k < (2 / 2.75)) {
  3205. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3206. }
  3207. else if (k < (2.5 / 2.75)) {
  3208. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3209. }
  3210. else {
  3211. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3212. }
  3213. },
  3214. bounceInOut: function (k) {
  3215. if (k < 0.5) {
  3216. return easingFuncs.bounceIn(k * 2) * 0.5;
  3217. }
  3218. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3219. }
  3220. };
  3221. var mathPow = Math.pow;
  3222. var mathSqrt = Math.sqrt;
  3223. var EPSILON$1 = 1e-8;
  3224. var EPSILON_NUMERIC = 1e-4;
  3225. var THREE_SQRT = mathSqrt(3);
  3226. var ONE_THIRD = 1 / 3;
  3227. var _v0 = create();
  3228. var _v1 = create();
  3229. var _v2 = create();
  3230. function isAroundZero(val) {
  3231. return val > -EPSILON$1 && val < EPSILON$1;
  3232. }
  3233. function isNotAroundZero(val) {
  3234. return val > EPSILON$1 || val < -EPSILON$1;
  3235. }
  3236. function cubicAt(p0, p1, p2, p3, t) {
  3237. var onet = 1 - t;
  3238. return onet * onet * (onet * p0 + 3 * t * p1)
  3239. + t * t * (t * p3 + 3 * onet * p2);
  3240. }
  3241. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3242. var onet = 1 - t;
  3243. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3244. + (p3 - p2) * t * t);
  3245. }
  3246. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3247. var a = p3 + 3 * (p1 - p2) - p0;
  3248. var b = 3 * (p2 - p1 * 2 + p0);
  3249. var c = 3 * (p1 - p0);
  3250. var d = p0 - val;
  3251. var A = b * b - 3 * a * c;
  3252. var B = b * c - 9 * a * d;
  3253. var C = c * c - 3 * b * d;
  3254. var n = 0;
  3255. if (isAroundZero(A) && isAroundZero(B)) {
  3256. if (isAroundZero(b)) {
  3257. roots[0] = 0;
  3258. }
  3259. else {
  3260. var t1 = -c / b;
  3261. if (t1 >= 0 && t1 <= 1) {
  3262. roots[n++] = t1;
  3263. }
  3264. }
  3265. }
  3266. else {
  3267. var disc = B * B - 4 * A * C;
  3268. if (isAroundZero(disc)) {
  3269. var K = B / A;
  3270. var t1 = -b / a + K;
  3271. var t2 = -K / 2;
  3272. if (t1 >= 0 && t1 <= 1) {
  3273. roots[n++] = t1;
  3274. }
  3275. if (t2 >= 0 && t2 <= 1) {
  3276. roots[n++] = t2;
  3277. }
  3278. }
  3279. else if (disc > 0) {
  3280. var discSqrt = mathSqrt(disc);
  3281. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3282. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3283. if (Y1 < 0) {
  3284. Y1 = -mathPow(-Y1, ONE_THIRD);
  3285. }
  3286. else {
  3287. Y1 = mathPow(Y1, ONE_THIRD);
  3288. }
  3289. if (Y2 < 0) {
  3290. Y2 = -mathPow(-Y2, ONE_THIRD);
  3291. }
  3292. else {
  3293. Y2 = mathPow(Y2, ONE_THIRD);
  3294. }
  3295. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3296. if (t1 >= 0 && t1 <= 1) {
  3297. roots[n++] = t1;
  3298. }
  3299. }
  3300. else {
  3301. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3302. var theta = Math.acos(T) / 3;
  3303. var ASqrt = mathSqrt(A);
  3304. var tmp = Math.cos(theta);
  3305. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3306. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3307. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3308. if (t1 >= 0 && t1 <= 1) {
  3309. roots[n++] = t1;
  3310. }
  3311. if (t2 >= 0 && t2 <= 1) {
  3312. roots[n++] = t2;
  3313. }
  3314. if (t3 >= 0 && t3 <= 1) {
  3315. roots[n++] = t3;
  3316. }
  3317. }
  3318. }
  3319. return n;
  3320. }
  3321. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3322. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3323. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3324. var c = 3 * p1 - 3 * p0;
  3325. var n = 0;
  3326. if (isAroundZero(a)) {
  3327. if (isNotAroundZero(b)) {
  3328. var t1 = -c / b;
  3329. if (t1 >= 0 && t1 <= 1) {
  3330. extrema[n++] = t1;
  3331. }
  3332. }
  3333. }
  3334. else {
  3335. var disc = b * b - 4 * a * c;
  3336. if (isAroundZero(disc)) {
  3337. extrema[0] = -b / (2 * a);
  3338. }
  3339. else if (disc > 0) {
  3340. var discSqrt = mathSqrt(disc);
  3341. var t1 = (-b + discSqrt) / (2 * a);
  3342. var t2 = (-b - discSqrt) / (2 * a);
  3343. if (t1 >= 0 && t1 <= 1) {
  3344. extrema[n++] = t1;
  3345. }
  3346. if (t2 >= 0 && t2 <= 1) {
  3347. extrema[n++] = t2;
  3348. }
  3349. }
  3350. }
  3351. return n;
  3352. }
  3353. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3354. var p01 = (p1 - p0) * t + p0;
  3355. var p12 = (p2 - p1) * t + p1;
  3356. var p23 = (p3 - p2) * t + p2;
  3357. var p012 = (p12 - p01) * t + p01;
  3358. var p123 = (p23 - p12) * t + p12;
  3359. var p0123 = (p123 - p012) * t + p012;
  3360. out[0] = p0;
  3361. out[1] = p01;
  3362. out[2] = p012;
  3363. out[3] = p0123;
  3364. out[4] = p0123;
  3365. out[5] = p123;
  3366. out[6] = p23;
  3367. out[7] = p3;
  3368. }
  3369. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3370. var t;
  3371. var interval = 0.005;
  3372. var d = Infinity;
  3373. var prev;
  3374. var next;
  3375. var d1;
  3376. var d2;
  3377. _v0[0] = x;
  3378. _v0[1] = y;
  3379. for (var _t = 0; _t < 1; _t += 0.05) {
  3380. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3381. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3382. d1 = distSquare(_v0, _v1);
  3383. if (d1 < d) {
  3384. t = _t;
  3385. d = d1;
  3386. }
  3387. }
  3388. d = Infinity;
  3389. for (var i = 0; i < 32; i++) {
  3390. if (interval < EPSILON_NUMERIC) {
  3391. break;
  3392. }
  3393. prev = t - interval;
  3394. next = t + interval;
  3395. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3396. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3397. d1 = distSquare(_v1, _v0);
  3398. if (prev >= 0 && d1 < d) {
  3399. t = prev;
  3400. d = d1;
  3401. }
  3402. else {
  3403. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3404. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3405. d2 = distSquare(_v2, _v0);
  3406. if (next <= 1 && d2 < d) {
  3407. t = next;
  3408. d = d2;
  3409. }
  3410. else {
  3411. interval *= 0.5;
  3412. }
  3413. }
  3414. }
  3415. if (out) {
  3416. out[0] = cubicAt(x0, x1, x2, x3, t);
  3417. out[1] = cubicAt(y0, y1, y2, y3, t);
  3418. }
  3419. return mathSqrt(d);
  3420. }
  3421. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3422. var px = x0;
  3423. var py = y0;
  3424. var d = 0;
  3425. var step = 1 / iteration;
  3426. for (var i = 1; i <= iteration; i++) {
  3427. var t = i * step;
  3428. var x = cubicAt(x0, x1, x2, x3, t);
  3429. var y = cubicAt(y0, y1, y2, y3, t);
  3430. var dx = x - px;
  3431. var dy = y - py;
  3432. d += Math.sqrt(dx * dx + dy * dy);
  3433. px = x;
  3434. py = y;
  3435. }
  3436. return d;
  3437. }
  3438. function quadraticAt(p0, p1, p2, t) {
  3439. var onet = 1 - t;
  3440. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3441. }
  3442. function quadraticDerivativeAt(p0, p1, p2, t) {
  3443. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3444. }
  3445. function quadraticRootAt(p0, p1, p2, val, roots) {
  3446. var a = p0 - 2 * p1 + p2;
  3447. var b = 2 * (p1 - p0);
  3448. var c = p0 - val;
  3449. var n = 0;
  3450. if (isAroundZero(a)) {
  3451. if (isNotAroundZero(b)) {
  3452. var t1 = -c / b;
  3453. if (t1 >= 0 && t1 <= 1) {
  3454. roots[n++] = t1;
  3455. }
  3456. }
  3457. }
  3458. else {
  3459. var disc = b * b - 4 * a * c;
  3460. if (isAroundZero(disc)) {
  3461. var t1 = -b / (2 * a);
  3462. if (t1 >= 0 && t1 <= 1) {
  3463. roots[n++] = t1;
  3464. }
  3465. }
  3466. else if (disc > 0) {
  3467. var discSqrt = mathSqrt(disc);
  3468. var t1 = (-b + discSqrt) / (2 * a);
  3469. var t2 = (-b - discSqrt) / (2 * a);
  3470. if (t1 >= 0 && t1 <= 1) {
  3471. roots[n++] = t1;
  3472. }
  3473. if (t2 >= 0 && t2 <= 1) {
  3474. roots[n++] = t2;
  3475. }
  3476. }
  3477. }
  3478. return n;
  3479. }
  3480. function quadraticExtremum(p0, p1, p2) {
  3481. var divider = p0 + p2 - 2 * p1;
  3482. if (divider === 0) {
  3483. return 0.5;
  3484. }
  3485. else {
  3486. return (p0 - p1) / divider;
  3487. }
  3488. }
  3489. function quadraticSubdivide(p0, p1, p2, t, out) {
  3490. var p01 = (p1 - p0) * t + p0;
  3491. var p12 = (p2 - p1) * t + p1;
  3492. var p012 = (p12 - p01) * t + p01;
  3493. out[0] = p0;
  3494. out[1] = p01;
  3495. out[2] = p012;
  3496. out[3] = p012;
  3497. out[4] = p12;
  3498. out[5] = p2;
  3499. }
  3500. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3501. var t;
  3502. var interval = 0.005;
  3503. var d = Infinity;
  3504. _v0[0] = x;
  3505. _v0[1] = y;
  3506. for (var _t = 0; _t < 1; _t += 0.05) {
  3507. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3508. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3509. var d1 = distSquare(_v0, _v1);
  3510. if (d1 < d) {
  3511. t = _t;
  3512. d = d1;
  3513. }
  3514. }
  3515. d = Infinity;
  3516. for (var i = 0; i < 32; i++) {
  3517. if (interval < EPSILON_NUMERIC) {
  3518. break;
  3519. }
  3520. var prev = t - interval;
  3521. var next = t + interval;
  3522. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3523. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3524. var d1 = distSquare(_v1, _v0);
  3525. if (prev >= 0 && d1 < d) {
  3526. t = prev;
  3527. d = d1;
  3528. }
  3529. else {
  3530. _v2[0] = quadraticAt(x0, x1, x2, next);
  3531. _v2[1] = quadraticAt(y0, y1, y2, next);
  3532. var d2 = distSquare(_v2, _v0);
  3533. if (next <= 1 && d2 < d) {
  3534. t = next;
  3535. d = d2;
  3536. }
  3537. else {
  3538. interval *= 0.5;
  3539. }
  3540. }
  3541. }
  3542. if (out) {
  3543. out[0] = quadraticAt(x0, x1, x2, t);
  3544. out[1] = quadraticAt(y0, y1, y2, t);
  3545. }
  3546. return mathSqrt(d);
  3547. }
  3548. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3549. var px = x0;
  3550. var py = y0;
  3551. var d = 0;
  3552. var step = 1 / iteration;
  3553. for (var i = 1; i <= iteration; i++) {
  3554. var t = i * step;
  3555. var x = quadraticAt(x0, x1, x2, t);
  3556. var y = quadraticAt(y0, y1, y2, t);
  3557. var dx = x - px;
  3558. var dy = y - py;
  3559. d += Math.sqrt(dx * dx + dy * dy);
  3560. px = x;
  3561. py = y;
  3562. }
  3563. return d;
  3564. }
  3565. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3566. function createCubicEasingFunc(cubicEasingStr) {
  3567. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3568. if (cubic) {
  3569. var points = cubic[1].split(',');
  3570. var a_1 = +trim(points[0]);
  3571. var b_1 = +trim(points[1]);
  3572. var c_1 = +trim(points[2]);
  3573. var d_1 = +trim(points[3]);
  3574. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3575. return;
  3576. }
  3577. var roots_1 = [];
  3578. return function (p) {
  3579. return p <= 0
  3580. ? 0 : p >= 1
  3581. ? 1
  3582. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3583. };
  3584. }
  3585. }
  3586. var Clip = (function () {
  3587. function Clip(opts) {
  3588. this._inited = false;
  3589. this._startTime = 0;
  3590. this._pausedTime = 0;
  3591. this._paused = false;
  3592. this._life = opts.life || 1000;
  3593. this._delay = opts.delay || 0;
  3594. this.loop = opts.loop || false;
  3595. this.onframe = opts.onframe || noop;
  3596. this.ondestroy = opts.ondestroy || noop;
  3597. this.onrestart = opts.onrestart || noop;
  3598. opts.easing && this.setEasing(opts.easing);
  3599. }
  3600. Clip.prototype.step = function (globalTime, deltaTime) {
  3601. if (!this._inited) {
  3602. this._startTime = globalTime + this._delay;
  3603. this._inited = true;
  3604. }
  3605. if (this._paused) {
  3606. this._pausedTime += deltaTime;
  3607. return;
  3608. }
  3609. var life = this._life;
  3610. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3611. var percent = elapsedTime / life;
  3612. if (percent < 0) {
  3613. percent = 0;
  3614. }
  3615. percent = Math.min(percent, 1);
  3616. var easingFunc = this.easingFunc;
  3617. var schedule = easingFunc ? easingFunc(percent) : percent;
  3618. this.onframe(schedule);
  3619. if (percent === 1) {
  3620. if (this.loop) {
  3621. var remainder = elapsedTime % life;
  3622. this._startTime = globalTime - remainder;
  3623. this._pausedTime = 0;
  3624. this.onrestart();
  3625. }
  3626. else {
  3627. return true;
  3628. }
  3629. }
  3630. return false;
  3631. };
  3632. Clip.prototype.pause = function () {
  3633. this._paused = true;
  3634. };
  3635. Clip.prototype.resume = function () {
  3636. this._paused = false;
  3637. };
  3638. Clip.prototype.setEasing = function (easing) {
  3639. this.easing = easing;
  3640. this.easingFunc = isFunction(easing)
  3641. ? easing
  3642. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3643. };
  3644. return Clip;
  3645. }());
  3646. var Entry = (function () {
  3647. function Entry(val) {
  3648. this.value = val;
  3649. }
  3650. return Entry;
  3651. }());
  3652. var LinkedList = (function () {
  3653. function LinkedList() {
  3654. this._len = 0;
  3655. }
  3656. LinkedList.prototype.insert = function (val) {
  3657. var entry = new Entry(val);
  3658. this.insertEntry(entry);
  3659. return entry;
  3660. };
  3661. LinkedList.prototype.insertEntry = function (entry) {
  3662. if (!this.head) {
  3663. this.head = this.tail = entry;
  3664. }
  3665. else {
  3666. this.tail.next = entry;
  3667. entry.prev = this.tail;
  3668. entry.next = null;
  3669. this.tail = entry;
  3670. }
  3671. this._len++;
  3672. };
  3673. LinkedList.prototype.remove = function (entry) {
  3674. var prev = entry.prev;
  3675. var next = entry.next;
  3676. if (prev) {
  3677. prev.next = next;
  3678. }
  3679. else {
  3680. this.head = next;
  3681. }
  3682. if (next) {
  3683. next.prev = prev;
  3684. }
  3685. else {
  3686. this.tail = prev;
  3687. }
  3688. entry.next = entry.prev = null;
  3689. this._len--;
  3690. };
  3691. LinkedList.prototype.len = function () {
  3692. return this._len;
  3693. };
  3694. LinkedList.prototype.clear = function () {
  3695. this.head = this.tail = null;
  3696. this._len = 0;
  3697. };
  3698. return LinkedList;
  3699. }());
  3700. var LRU = (function () {
  3701. function LRU(maxSize) {
  3702. this._list = new LinkedList();
  3703. this._maxSize = 10;
  3704. this._map = {};
  3705. this._maxSize = maxSize;
  3706. }
  3707. LRU.prototype.put = function (key, value) {
  3708. var list = this._list;
  3709. var map = this._map;
  3710. var removed = null;
  3711. if (map[key] == null) {
  3712. var len = list.len();
  3713. var entry = this._lastRemovedEntry;
  3714. if (len >= this._maxSize && len > 0) {
  3715. var leastUsedEntry = list.head;
  3716. list.remove(leastUsedEntry);
  3717. delete map[leastUsedEntry.key];
  3718. removed = leastUsedEntry.value;
  3719. this._lastRemovedEntry = leastUsedEntry;
  3720. }
  3721. if (entry) {
  3722. entry.value = value;
  3723. }
  3724. else {
  3725. entry = new Entry(value);
  3726. }
  3727. entry.key = key;
  3728. list.insertEntry(entry);
  3729. map[key] = entry;
  3730. }
  3731. return removed;
  3732. };
  3733. LRU.prototype.get = function (key) {
  3734. var entry = this._map[key];
  3735. var list = this._list;
  3736. if (entry != null) {
  3737. if (entry !== list.tail) {
  3738. list.remove(entry);
  3739. list.insertEntry(entry);
  3740. }
  3741. return entry.value;
  3742. }
  3743. };
  3744. LRU.prototype.clear = function () {
  3745. this._list.clear();
  3746. this._map = {};
  3747. };
  3748. LRU.prototype.len = function () {
  3749. return this._list.len();
  3750. };
  3751. return LRU;
  3752. }());
  3753. var kCSSColorTable = {
  3754. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3755. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3756. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3757. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3758. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3759. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3760. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3761. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3762. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3763. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3764. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3765. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3766. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3767. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3768. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3769. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3770. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3771. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3772. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3773. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3774. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3775. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3776. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3777. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3778. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3779. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3780. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3781. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3782. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3783. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3784. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3785. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3786. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3787. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3788. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3789. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3790. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3791. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3792. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3793. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3794. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3795. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3796. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3797. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3798. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3799. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3800. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3801. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3802. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3803. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3804. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3805. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3806. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3807. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3808. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3809. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3810. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3811. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3812. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3813. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3814. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3815. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3816. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3817. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3818. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3819. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3820. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3821. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3822. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3823. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3824. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3825. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3826. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3827. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3828. };
  3829. function clampCssByte(i) {
  3830. i = Math.round(i);
  3831. return i < 0 ? 0 : i > 255 ? 255 : i;
  3832. }
  3833. function clampCssAngle(i) {
  3834. i = Math.round(i);
  3835. return i < 0 ? 0 : i > 360 ? 360 : i;
  3836. }
  3837. function clampCssFloat(f) {
  3838. return f < 0 ? 0 : f > 1 ? 1 : f;
  3839. }
  3840. function parseCssInt(val) {
  3841. var str = val;
  3842. if (str.length && str.charAt(str.length - 1) === '%') {
  3843. return clampCssByte(parseFloat(str) / 100 * 255);
  3844. }
  3845. return clampCssByte(parseInt(str, 10));
  3846. }
  3847. function parseCssFloat(val) {
  3848. var str = val;
  3849. if (str.length && str.charAt(str.length - 1) === '%') {
  3850. return clampCssFloat(parseFloat(str) / 100);
  3851. }
  3852. return clampCssFloat(parseFloat(str));
  3853. }
  3854. function cssHueToRgb(m1, m2, h) {
  3855. if (h < 0) {
  3856. h += 1;
  3857. }
  3858. else if (h > 1) {
  3859. h -= 1;
  3860. }
  3861. if (h * 6 < 1) {
  3862. return m1 + (m2 - m1) * h * 6;
  3863. }
  3864. if (h * 2 < 1) {
  3865. return m2;
  3866. }
  3867. if (h * 3 < 2) {
  3868. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3869. }
  3870. return m1;
  3871. }
  3872. function lerpNumber(a, b, p) {
  3873. return a + (b - a) * p;
  3874. }
  3875. function setRgba(out, r, g, b, a) {
  3876. out[0] = r;
  3877. out[1] = g;
  3878. out[2] = b;
  3879. out[3] = a;
  3880. return out;
  3881. }
  3882. function copyRgba(out, a) {
  3883. out[0] = a[0];
  3884. out[1] = a[1];
  3885. out[2] = a[2];
  3886. out[3] = a[3];
  3887. return out;
  3888. }
  3889. var colorCache = new LRU(20);
  3890. var lastRemovedArr = null;
  3891. function putToCache(colorStr, rgbaArr) {
  3892. if (lastRemovedArr) {
  3893. copyRgba(lastRemovedArr, rgbaArr);
  3894. }
  3895. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3896. }
  3897. function parse(colorStr, rgbaArr) {
  3898. if (!colorStr) {
  3899. return;
  3900. }
  3901. rgbaArr = rgbaArr || [];
  3902. var cached = colorCache.get(colorStr);
  3903. if (cached) {
  3904. return copyRgba(rgbaArr, cached);
  3905. }
  3906. colorStr = colorStr + '';
  3907. var str = colorStr.replace(/ /g, '').toLowerCase();
  3908. if (str in kCSSColorTable) {
  3909. copyRgba(rgbaArr, kCSSColorTable[str]);
  3910. putToCache(colorStr, rgbaArr);
  3911. return rgbaArr;
  3912. }
  3913. var strLen = str.length;
  3914. if (str.charAt(0) === '#') {
  3915. if (strLen === 4 || strLen === 5) {
  3916. var iv = parseInt(str.slice(1, 4), 16);
  3917. if (!(iv >= 0 && iv <= 0xfff)) {
  3918. setRgba(rgbaArr, 0, 0, 0, 1);
  3919. return;
  3920. }
  3921. setRgba(rgbaArr, ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8), (iv & 0xf0) | ((iv & 0xf0) >> 4), (iv & 0xf) | ((iv & 0xf) << 4), strLen === 5 ? parseInt(str.slice(4), 16) / 0xf : 1);
  3922. putToCache(colorStr, rgbaArr);
  3923. return rgbaArr;
  3924. }
  3925. else if (strLen === 7 || strLen === 9) {
  3926. var iv = parseInt(str.slice(1, 7), 16);
  3927. if (!(iv >= 0 && iv <= 0xffffff)) {
  3928. setRgba(rgbaArr, 0, 0, 0, 1);
  3929. return;
  3930. }
  3931. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3932. putToCache(colorStr, rgbaArr);
  3933. return rgbaArr;
  3934. }
  3935. return;
  3936. }
  3937. var op = str.indexOf('(');
  3938. var ep = str.indexOf(')');
  3939. if (op !== -1 && ep + 1 === strLen) {
  3940. var fname = str.substr(0, op);
  3941. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3942. var alpha = 1;
  3943. switch (fname) {
  3944. case 'rgba':
  3945. if (params.length !== 4) {
  3946. return params.length === 3
  3947. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3948. : setRgba(rgbaArr, 0, 0, 0, 1);
  3949. }
  3950. alpha = parseCssFloat(params.pop());
  3951. case 'rgb':
  3952. if (params.length >= 3) {
  3953. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3954. putToCache(colorStr, rgbaArr);
  3955. return rgbaArr;
  3956. }
  3957. else {
  3958. setRgba(rgbaArr, 0, 0, 0, 1);
  3959. return;
  3960. }
  3961. case 'hsla':
  3962. if (params.length !== 4) {
  3963. setRgba(rgbaArr, 0, 0, 0, 1);
  3964. return;
  3965. }
  3966. params[3] = parseCssFloat(params[3]);
  3967. hsla2rgba(params, rgbaArr);
  3968. putToCache(colorStr, rgbaArr);
  3969. return rgbaArr;
  3970. case 'hsl':
  3971. if (params.length !== 3) {
  3972. setRgba(rgbaArr, 0, 0, 0, 1);
  3973. return;
  3974. }
  3975. hsla2rgba(params, rgbaArr);
  3976. putToCache(colorStr, rgbaArr);
  3977. return rgbaArr;
  3978. default:
  3979. return;
  3980. }
  3981. }
  3982. setRgba(rgbaArr, 0, 0, 0, 1);
  3983. return;
  3984. }
  3985. function hsla2rgba(hsla, rgba) {
  3986. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3987. var s = parseCssFloat(hsla[1]);
  3988. var l = parseCssFloat(hsla[2]);
  3989. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3990. var m1 = l * 2 - m2;
  3991. rgba = rgba || [];
  3992. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  3993. if (hsla.length === 4) {
  3994. rgba[3] = hsla[3];
  3995. }
  3996. return rgba;
  3997. }
  3998. function rgba2hsla(rgba) {
  3999. if (!rgba) {
  4000. return;
  4001. }
  4002. var R = rgba[0] / 255;
  4003. var G = rgba[1] / 255;
  4004. var B = rgba[2] / 255;
  4005. var vMin = Math.min(R, G, B);
  4006. var vMax = Math.max(R, G, B);
  4007. var delta = vMax - vMin;
  4008. var L = (vMax + vMin) / 2;
  4009. var H;
  4010. var S;
  4011. if (delta === 0) {
  4012. H = 0;
  4013. S = 0;
  4014. }
  4015. else {
  4016. if (L < 0.5) {
  4017. S = delta / (vMax + vMin);
  4018. }
  4019. else {
  4020. S = delta / (2 - vMax - vMin);
  4021. }
  4022. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  4023. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  4024. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  4025. if (R === vMax) {
  4026. H = deltaB - deltaG;
  4027. }
  4028. else if (G === vMax) {
  4029. H = (1 / 3) + deltaR - deltaB;
  4030. }
  4031. else if (B === vMax) {
  4032. H = (2 / 3) + deltaG - deltaR;
  4033. }
  4034. if (H < 0) {
  4035. H += 1;
  4036. }
  4037. if (H > 1) {
  4038. H -= 1;
  4039. }
  4040. }
  4041. var hsla = [H * 360, S, L];
  4042. if (rgba[3] != null) {
  4043. hsla.push(rgba[3]);
  4044. }
  4045. return hsla;
  4046. }
  4047. function lift(color, level) {
  4048. var colorArr = parse(color);
  4049. if (colorArr) {
  4050. for (var i = 0; i < 3; i++) {
  4051. if (level < 0) {
  4052. colorArr[i] = colorArr[i] * (1 - level) | 0;
  4053. }
  4054. else {
  4055. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  4056. }
  4057. if (colorArr[i] > 255) {
  4058. colorArr[i] = 255;
  4059. }
  4060. else if (colorArr[i] < 0) {
  4061. colorArr[i] = 0;
  4062. }
  4063. }
  4064. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  4065. }
  4066. }
  4067. function toHex(color) {
  4068. var colorArr = parse(color);
  4069. if (colorArr) {
  4070. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  4071. }
  4072. }
  4073. function fastLerp(normalizedValue, colors, out) {
  4074. if (!(colors && colors.length)
  4075. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4076. return;
  4077. }
  4078. out = out || [];
  4079. var value = normalizedValue * (colors.length - 1);
  4080. var leftIndex = Math.floor(value);
  4081. var rightIndex = Math.ceil(value);
  4082. var leftColor = colors[leftIndex];
  4083. var rightColor = colors[rightIndex];
  4084. var dv = value - leftIndex;
  4085. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  4086. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  4087. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  4088. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  4089. return out;
  4090. }
  4091. var fastMapToColor = fastLerp;
  4092. function lerp$1(normalizedValue, colors, fullOutput) {
  4093. if (!(colors && colors.length)
  4094. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4095. return;
  4096. }
  4097. var value = normalizedValue * (colors.length - 1);
  4098. var leftIndex = Math.floor(value);
  4099. var rightIndex = Math.ceil(value);
  4100. var leftColor = parse(colors[leftIndex]);
  4101. var rightColor = parse(colors[rightIndex]);
  4102. var dv = value - leftIndex;
  4103. var color = stringify([
  4104. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  4105. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  4106. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  4107. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  4108. ], 'rgba');
  4109. return fullOutput
  4110. ? {
  4111. color: color,
  4112. leftIndex: leftIndex,
  4113. rightIndex: rightIndex,
  4114. value: value
  4115. }
  4116. : color;
  4117. }
  4118. var mapToColor = lerp$1;
  4119. function modifyHSL(color, h, s, l) {
  4120. var colorArr = parse(color);
  4121. if (color) {
  4122. colorArr = rgba2hsla(colorArr);
  4123. h != null && (colorArr[0] = clampCssAngle(isFunction(h) ? h(colorArr[0]) : h));
  4124. s != null && (colorArr[1] = parseCssFloat(isFunction(s) ? s(colorArr[1]) : s));
  4125. l != null && (colorArr[2] = parseCssFloat(isFunction(l) ? l(colorArr[2]) : l));
  4126. return stringify(hsla2rgba(colorArr), 'rgba');
  4127. }
  4128. }
  4129. function modifyAlpha(color, alpha) {
  4130. var colorArr = parse(color);
  4131. if (colorArr && alpha != null) {
  4132. colorArr[3] = clampCssFloat(alpha);
  4133. return stringify(colorArr, 'rgba');
  4134. }
  4135. }
  4136. function stringify(arrColor, type) {
  4137. if (!arrColor || !arrColor.length) {
  4138. return;
  4139. }
  4140. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4141. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4142. colorStr += ',' + arrColor[3];
  4143. }
  4144. return type + '(' + colorStr + ')';
  4145. }
  4146. function lum(color, backgroundLum) {
  4147. var arr = parse(color);
  4148. return arr
  4149. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4150. + (1 - arr[3]) * backgroundLum
  4151. : 0;
  4152. }
  4153. function random() {
  4154. return stringify([
  4155. Math.round(Math.random() * 255),
  4156. Math.round(Math.random() * 255),
  4157. Math.round(Math.random() * 255)
  4158. ], 'rgb');
  4159. }
  4160. var liftedColorCache = new LRU(100);
  4161. function liftColor(color) {
  4162. if (isString(color)) {
  4163. var liftedColor = liftedColorCache.get(color);
  4164. if (!liftedColor) {
  4165. liftedColor = lift(color, -0.1);
  4166. liftedColorCache.put(color, liftedColor);
  4167. }
  4168. return liftedColor;
  4169. }
  4170. else if (isGradientObject(color)) {
  4171. var ret = extend({}, color);
  4172. ret.colorStops = map(color.colorStops, function (stop) { return ({
  4173. offset: stop.offset,
  4174. color: lift(stop.color, -0.1)
  4175. }); });
  4176. return ret;
  4177. }
  4178. return color;
  4179. }
  4180. var color = /*#__PURE__*/Object.freeze({
  4181. __proto__: null,
  4182. parseCssInt: parseCssInt,
  4183. parseCssFloat: parseCssFloat,
  4184. parse: parse,
  4185. lift: lift,
  4186. toHex: toHex,
  4187. fastLerp: fastLerp,
  4188. fastMapToColor: fastMapToColor,
  4189. lerp: lerp$1,
  4190. mapToColor: mapToColor,
  4191. modifyHSL: modifyHSL,
  4192. modifyAlpha: modifyAlpha,
  4193. stringify: stringify,
  4194. lum: lum,
  4195. random: random,
  4196. liftColor: liftColor
  4197. });
  4198. function isLinearGradient(val) {
  4199. return val.type === 'linear';
  4200. }
  4201. function isRadialGradient(val) {
  4202. return val.type === 'radial';
  4203. }
  4204. var arraySlice = Array.prototype.slice;
  4205. function interpolateNumber(p0, p1, percent) {
  4206. return (p1 - p0) * percent + p0;
  4207. }
  4208. function interpolate1DArray(out, p0, p1, percent) {
  4209. var len = p0.length;
  4210. for (var i = 0; i < len; i++) {
  4211. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4212. }
  4213. return out;
  4214. }
  4215. function interpolate2DArray(out, p0, p1, percent) {
  4216. var len = p0.length;
  4217. var len2 = len && p0[0].length;
  4218. for (var i = 0; i < len; i++) {
  4219. if (!out[i]) {
  4220. out[i] = [];
  4221. }
  4222. for (var j = 0; j < len2; j++) {
  4223. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4224. }
  4225. }
  4226. return out;
  4227. }
  4228. function add1DArray(out, p0, p1, sign) {
  4229. var len = p0.length;
  4230. for (var i = 0; i < len; i++) {
  4231. out[i] = p0[i] + p1[i] * sign;
  4232. }
  4233. return out;
  4234. }
  4235. function add2DArray(out, p0, p1, sign) {
  4236. var len = p0.length;
  4237. var len2 = len && p0[0].length;
  4238. for (var i = 0; i < len; i++) {
  4239. if (!out[i]) {
  4240. out[i] = [];
  4241. }
  4242. for (var j = 0; j < len2; j++) {
  4243. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4244. }
  4245. }
  4246. return out;
  4247. }
  4248. function fillColorStops(val0, val1) {
  4249. var len0 = val0.length;
  4250. var len1 = val1.length;
  4251. var shorterArr = len0 > len1 ? val1 : val0;
  4252. var shorterLen = Math.min(len0, len1);
  4253. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4254. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4255. shorterArr.push({
  4256. offset: last.offset,
  4257. color: last.color.slice()
  4258. });
  4259. }
  4260. }
  4261. function fillArray(val0, val1, arrDim) {
  4262. var arr0 = val0;
  4263. var arr1 = val1;
  4264. if (!arr0.push || !arr1.push) {
  4265. return;
  4266. }
  4267. var arr0Len = arr0.length;
  4268. var arr1Len = arr1.length;
  4269. if (arr0Len !== arr1Len) {
  4270. var isPreviousLarger = arr0Len > arr1Len;
  4271. if (isPreviousLarger) {
  4272. arr0.length = arr1Len;
  4273. }
  4274. else {
  4275. for (var i = arr0Len; i < arr1Len; i++) {
  4276. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4277. }
  4278. }
  4279. }
  4280. var len2 = arr0[0] && arr0[0].length;
  4281. for (var i = 0; i < arr0.length; i++) {
  4282. if (arrDim === 1) {
  4283. if (isNaN(arr0[i])) {
  4284. arr0[i] = arr1[i];
  4285. }
  4286. }
  4287. else {
  4288. for (var j = 0; j < len2; j++) {
  4289. if (isNaN(arr0[i][j])) {
  4290. arr0[i][j] = arr1[i][j];
  4291. }
  4292. }
  4293. }
  4294. }
  4295. }
  4296. function cloneValue(value) {
  4297. if (isArrayLike(value)) {
  4298. var len = value.length;
  4299. if (isArrayLike(value[0])) {
  4300. var ret = [];
  4301. for (var i = 0; i < len; i++) {
  4302. ret.push(arraySlice.call(value[i]));
  4303. }
  4304. return ret;
  4305. }
  4306. return arraySlice.call(value);
  4307. }
  4308. return value;
  4309. }
  4310. function rgba2String(rgba) {
  4311. rgba[0] = Math.floor(rgba[0]) || 0;
  4312. rgba[1] = Math.floor(rgba[1]) || 0;
  4313. rgba[2] = Math.floor(rgba[2]) || 0;
  4314. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4315. return 'rgba(' + rgba.join(',') + ')';
  4316. }
  4317. function guessArrayDim(value) {
  4318. return isArrayLike(value && value[0]) ? 2 : 1;
  4319. }
  4320. var VALUE_TYPE_NUMBER = 0;
  4321. var VALUE_TYPE_1D_ARRAY = 1;
  4322. var VALUE_TYPE_2D_ARRAY = 2;
  4323. var VALUE_TYPE_COLOR = 3;
  4324. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4325. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4326. var VALUE_TYPE_UNKOWN = 6;
  4327. function isGradientValueType(valType) {
  4328. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4329. }
  4330. function isArrayValueType(valType) {
  4331. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4332. }
  4333. var tmpRgba = [0, 0, 0, 0];
  4334. var Track = (function () {
  4335. function Track(propName) {
  4336. this.keyframes = [];
  4337. this.discrete = false;
  4338. this._invalid = false;
  4339. this._needsSort = false;
  4340. this._lastFr = 0;
  4341. this._lastFrP = 0;
  4342. this.propName = propName;
  4343. }
  4344. Track.prototype.isFinished = function () {
  4345. return this._finished;
  4346. };
  4347. Track.prototype.setFinished = function () {
  4348. this._finished = true;
  4349. if (this._additiveTrack) {
  4350. this._additiveTrack.setFinished();
  4351. }
  4352. };
  4353. Track.prototype.needsAnimate = function () {
  4354. return this.keyframes.length >= 1;
  4355. };
  4356. Track.prototype.getAdditiveTrack = function () {
  4357. return this._additiveTrack;
  4358. };
  4359. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4360. this._needsSort = true;
  4361. var keyframes = this.keyframes;
  4362. var len = keyframes.length;
  4363. var discrete = false;
  4364. var valType = VALUE_TYPE_UNKOWN;
  4365. var value = rawValue;
  4366. if (isArrayLike(rawValue)) {
  4367. var arrayDim = guessArrayDim(rawValue);
  4368. valType = arrayDim;
  4369. if (arrayDim === 1 && !isNumber(rawValue[0])
  4370. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4371. discrete = true;
  4372. }
  4373. }
  4374. else {
  4375. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4376. valType = VALUE_TYPE_NUMBER;
  4377. }
  4378. else if (isString(rawValue)) {
  4379. if (!isNaN(+rawValue)) {
  4380. valType = VALUE_TYPE_NUMBER;
  4381. }
  4382. else {
  4383. var colorArray = parse(rawValue);
  4384. if (colorArray) {
  4385. value = colorArray;
  4386. valType = VALUE_TYPE_COLOR;
  4387. }
  4388. }
  4389. }
  4390. else if (isGradientObject(rawValue)) {
  4391. var parsedGradient = extend({}, value);
  4392. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4393. offset: colorStop.offset,
  4394. color: parse(colorStop.color)
  4395. }); });
  4396. if (isLinearGradient(rawValue)) {
  4397. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4398. }
  4399. else if (isRadialGradient(rawValue)) {
  4400. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4401. }
  4402. value = parsedGradient;
  4403. }
  4404. }
  4405. if (len === 0) {
  4406. this.valType = valType;
  4407. }
  4408. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4409. discrete = true;
  4410. }
  4411. this.discrete = this.discrete || discrete;
  4412. var kf = {
  4413. time: time,
  4414. value: value,
  4415. rawValue: rawValue,
  4416. percent: 0
  4417. };
  4418. if (easing) {
  4419. kf.easing = easing;
  4420. kf.easingFunc = isFunction(easing)
  4421. ? easing
  4422. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4423. }
  4424. keyframes.push(kf);
  4425. return kf;
  4426. };
  4427. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4428. var kfs = this.keyframes;
  4429. if (this._needsSort) {
  4430. kfs.sort(function (a, b) {
  4431. return a.time - b.time;
  4432. });
  4433. }
  4434. var valType = this.valType;
  4435. var kfsLen = kfs.length;
  4436. var lastKf = kfs[kfsLen - 1];
  4437. var isDiscrete = this.discrete;
  4438. var isArr = isArrayValueType(valType);
  4439. var isGradient = isGradientValueType(valType);
  4440. for (var i = 0; i < kfsLen; i++) {
  4441. var kf = kfs[i];
  4442. var value = kf.value;
  4443. var lastValue = lastKf.value;
  4444. kf.percent = kf.time / maxTime;
  4445. if (!isDiscrete) {
  4446. if (isArr && i !== kfsLen - 1) {
  4447. fillArray(value, lastValue, valType);
  4448. }
  4449. else if (isGradient) {
  4450. fillColorStops(value.colorStops, lastValue.colorStops);
  4451. }
  4452. }
  4453. }
  4454. if (!isDiscrete
  4455. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4456. && additiveTrack
  4457. && this.needsAnimate()
  4458. && additiveTrack.needsAnimate()
  4459. && valType === additiveTrack.valType
  4460. && !additiveTrack._finished) {
  4461. this._additiveTrack = additiveTrack;
  4462. var startValue = kfs[0].value;
  4463. for (var i = 0; i < kfsLen; i++) {
  4464. if (valType === VALUE_TYPE_NUMBER) {
  4465. kfs[i].additiveValue = kfs[i].value - startValue;
  4466. }
  4467. else if (valType === VALUE_TYPE_COLOR) {
  4468. kfs[i].additiveValue =
  4469. add1DArray([], kfs[i].value, startValue, -1);
  4470. }
  4471. else if (isArrayValueType(valType)) {
  4472. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4473. ? add1DArray([], kfs[i].value, startValue, -1)
  4474. : add2DArray([], kfs[i].value, startValue, -1);
  4475. }
  4476. }
  4477. }
  4478. };
  4479. Track.prototype.step = function (target, percent) {
  4480. if (this._finished) {
  4481. return;
  4482. }
  4483. if (this._additiveTrack && this._additiveTrack._finished) {
  4484. this._additiveTrack = null;
  4485. }
  4486. var isAdditive = this._additiveTrack != null;
  4487. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4488. var valType = this.valType;
  4489. var keyframes = this.keyframes;
  4490. var kfsNum = keyframes.length;
  4491. var propName = this.propName;
  4492. var isValueColor = valType === VALUE_TYPE_COLOR;
  4493. var frameIdx;
  4494. var lastFrame = this._lastFr;
  4495. var mathMin = Math.min;
  4496. var frame;
  4497. var nextFrame;
  4498. if (kfsNum === 1) {
  4499. frame = nextFrame = keyframes[0];
  4500. }
  4501. else {
  4502. if (percent < 0) {
  4503. frameIdx = 0;
  4504. }
  4505. else if (percent < this._lastFrP) {
  4506. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4507. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4508. if (keyframes[frameIdx].percent <= percent) {
  4509. break;
  4510. }
  4511. }
  4512. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4513. }
  4514. else {
  4515. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4516. if (keyframes[frameIdx].percent > percent) {
  4517. break;
  4518. }
  4519. }
  4520. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4521. }
  4522. nextFrame = keyframes[frameIdx + 1];
  4523. frame = keyframes[frameIdx];
  4524. }
  4525. if (!(frame && nextFrame)) {
  4526. return;
  4527. }
  4528. this._lastFr = frameIdx;
  4529. this._lastFrP = percent;
  4530. var interval = (nextFrame.percent - frame.percent);
  4531. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4532. if (nextFrame.easingFunc) {
  4533. w = nextFrame.easingFunc(w);
  4534. }
  4535. var targetArr = isAdditive ? this._additiveValue
  4536. : (isValueColor ? tmpRgba : target[propName]);
  4537. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4538. targetArr = this._additiveValue = [];
  4539. }
  4540. if (this.discrete) {
  4541. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4542. }
  4543. else if (isArrayValueType(valType)) {
  4544. valType === VALUE_TYPE_1D_ARRAY
  4545. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4546. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4547. }
  4548. else if (isGradientValueType(valType)) {
  4549. var val = frame[valueKey];
  4550. var nextVal_1 = nextFrame[valueKey];
  4551. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4552. target[propName] = {
  4553. type: isLinearGradient_1 ? 'linear' : 'radial',
  4554. x: interpolateNumber(val.x, nextVal_1.x, w),
  4555. y: interpolateNumber(val.y, nextVal_1.y, w),
  4556. colorStops: map(val.colorStops, function (colorStop, idx) {
  4557. var nextColorStop = nextVal_1.colorStops[idx];
  4558. return {
  4559. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4560. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4561. };
  4562. }),
  4563. global: nextVal_1.global
  4564. };
  4565. if (isLinearGradient_1) {
  4566. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4567. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4568. }
  4569. else {
  4570. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4571. }
  4572. }
  4573. else if (isValueColor) {
  4574. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4575. if (!isAdditive) {
  4576. target[propName] = rgba2String(targetArr);
  4577. }
  4578. }
  4579. else {
  4580. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4581. if (isAdditive) {
  4582. this._additiveValue = value;
  4583. }
  4584. else {
  4585. target[propName] = value;
  4586. }
  4587. }
  4588. if (isAdditive) {
  4589. this._addToTarget(target);
  4590. }
  4591. };
  4592. Track.prototype._addToTarget = function (target) {
  4593. var valType = this.valType;
  4594. var propName = this.propName;
  4595. var additiveValue = this._additiveValue;
  4596. if (valType === VALUE_TYPE_NUMBER) {
  4597. target[propName] = target[propName] + additiveValue;
  4598. }
  4599. else if (valType === VALUE_TYPE_COLOR) {
  4600. parse(target[propName], tmpRgba);
  4601. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4602. target[propName] = rgba2String(tmpRgba);
  4603. }
  4604. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4605. add1DArray(target[propName], target[propName], additiveValue, 1);
  4606. }
  4607. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4608. add2DArray(target[propName], target[propName], additiveValue, 1);
  4609. }
  4610. };
  4611. return Track;
  4612. }());
  4613. var Animator = (function () {
  4614. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4615. this._tracks = {};
  4616. this._trackKeys = [];
  4617. this._maxTime = 0;
  4618. this._started = 0;
  4619. this._clip = null;
  4620. this._target = target;
  4621. this._loop = loop;
  4622. if (loop && additiveTo) {
  4623. logError('Can\' use additive animation on looped animation.');
  4624. return;
  4625. }
  4626. this._additiveAnimators = additiveTo;
  4627. this._allowDiscrete = allowDiscreteAnimation;
  4628. }
  4629. Animator.prototype.getMaxTime = function () {
  4630. return this._maxTime;
  4631. };
  4632. Animator.prototype.getDelay = function () {
  4633. return this._delay;
  4634. };
  4635. Animator.prototype.getLoop = function () {
  4636. return this._loop;
  4637. };
  4638. Animator.prototype.getTarget = function () {
  4639. return this._target;
  4640. };
  4641. Animator.prototype.changeTarget = function (target) {
  4642. this._target = target;
  4643. };
  4644. Animator.prototype.when = function (time, props, easing) {
  4645. return this.whenWithKeys(time, props, keys(props), easing);
  4646. };
  4647. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4648. var tracks = this._tracks;
  4649. for (var i = 0; i < propNames.length; i++) {
  4650. var propName = propNames[i];
  4651. var track = tracks[propName];
  4652. if (!track) {
  4653. track = tracks[propName] = new Track(propName);
  4654. var initialValue = void 0;
  4655. var additiveTrack = this._getAdditiveTrack(propName);
  4656. if (additiveTrack) {
  4657. var addtiveTrackKfs = additiveTrack.keyframes;
  4658. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4659. initialValue = lastFinalKf && lastFinalKf.value;
  4660. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4661. initialValue = rgba2String(initialValue);
  4662. }
  4663. }
  4664. else {
  4665. initialValue = this._target[propName];
  4666. }
  4667. if (initialValue == null) {
  4668. continue;
  4669. }
  4670. if (time > 0) {
  4671. track.addKeyframe(0, cloneValue(initialValue), easing);
  4672. }
  4673. this._trackKeys.push(propName);
  4674. }
  4675. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4676. }
  4677. this._maxTime = Math.max(this._maxTime, time);
  4678. return this;
  4679. };
  4680. Animator.prototype.pause = function () {
  4681. this._clip.pause();
  4682. this._paused = true;
  4683. };
  4684. Animator.prototype.resume = function () {
  4685. this._clip.resume();
  4686. this._paused = false;
  4687. };
  4688. Animator.prototype.isPaused = function () {
  4689. return !!this._paused;
  4690. };
  4691. Animator.prototype.duration = function (duration) {
  4692. this._maxTime = duration;
  4693. this._force = true;
  4694. return this;
  4695. };
  4696. Animator.prototype._doneCallback = function () {
  4697. this._setTracksFinished();
  4698. this._clip = null;
  4699. var doneList = this._doneCbs;
  4700. if (doneList) {
  4701. var len = doneList.length;
  4702. for (var i = 0; i < len; i++) {
  4703. doneList[i].call(this);
  4704. }
  4705. }
  4706. };
  4707. Animator.prototype._abortedCallback = function () {
  4708. this._setTracksFinished();
  4709. var animation = this.animation;
  4710. var abortedList = this._abortedCbs;
  4711. if (animation) {
  4712. animation.removeClip(this._clip);
  4713. }
  4714. this._clip = null;
  4715. if (abortedList) {
  4716. for (var i = 0; i < abortedList.length; i++) {
  4717. abortedList[i].call(this);
  4718. }
  4719. }
  4720. };
  4721. Animator.prototype._setTracksFinished = function () {
  4722. var tracks = this._tracks;
  4723. var tracksKeys = this._trackKeys;
  4724. for (var i = 0; i < tracksKeys.length; i++) {
  4725. tracks[tracksKeys[i]].setFinished();
  4726. }
  4727. };
  4728. Animator.prototype._getAdditiveTrack = function (trackName) {
  4729. var additiveTrack;
  4730. var additiveAnimators = this._additiveAnimators;
  4731. if (additiveAnimators) {
  4732. for (var i = 0; i < additiveAnimators.length; i++) {
  4733. var track = additiveAnimators[i].getTrack(trackName);
  4734. if (track) {
  4735. additiveTrack = track;
  4736. }
  4737. }
  4738. }
  4739. return additiveTrack;
  4740. };
  4741. Animator.prototype.start = function (easing) {
  4742. if (this._started > 0) {
  4743. return;
  4744. }
  4745. this._started = 1;
  4746. var self = this;
  4747. var tracks = [];
  4748. var maxTime = this._maxTime || 0;
  4749. for (var i = 0; i < this._trackKeys.length; i++) {
  4750. var propName = this._trackKeys[i];
  4751. var track = this._tracks[propName];
  4752. var additiveTrack = this._getAdditiveTrack(propName);
  4753. var kfs = track.keyframes;
  4754. var kfsNum = kfs.length;
  4755. track.prepare(maxTime, additiveTrack);
  4756. if (track.needsAnimate()) {
  4757. if (!this._allowDiscrete && track.discrete) {
  4758. var lastKf = kfs[kfsNum - 1];
  4759. if (lastKf) {
  4760. self._target[track.propName] = lastKf.rawValue;
  4761. }
  4762. track.setFinished();
  4763. }
  4764. else {
  4765. tracks.push(track);
  4766. }
  4767. }
  4768. }
  4769. if (tracks.length || this._force) {
  4770. var clip = new Clip({
  4771. life: maxTime,
  4772. loop: this._loop,
  4773. delay: this._delay || 0,
  4774. onframe: function (percent) {
  4775. self._started = 2;
  4776. var additiveAnimators = self._additiveAnimators;
  4777. if (additiveAnimators) {
  4778. var stillHasAdditiveAnimator = false;
  4779. for (var i = 0; i < additiveAnimators.length; i++) {
  4780. if (additiveAnimators[i]._clip) {
  4781. stillHasAdditiveAnimator = true;
  4782. break;
  4783. }
  4784. }
  4785. if (!stillHasAdditiveAnimator) {
  4786. self._additiveAnimators = null;
  4787. }
  4788. }
  4789. for (var i = 0; i < tracks.length; i++) {
  4790. tracks[i].step(self._target, percent);
  4791. }
  4792. var onframeList = self._onframeCbs;
  4793. if (onframeList) {
  4794. for (var i = 0; i < onframeList.length; i++) {
  4795. onframeList[i](self._target, percent);
  4796. }
  4797. }
  4798. },
  4799. ondestroy: function () {
  4800. self._doneCallback();
  4801. }
  4802. });
  4803. this._clip = clip;
  4804. if (this.animation) {
  4805. this.animation.addClip(clip);
  4806. }
  4807. if (easing) {
  4808. clip.setEasing(easing);
  4809. }
  4810. }
  4811. else {
  4812. this._doneCallback();
  4813. }
  4814. return this;
  4815. };
  4816. Animator.prototype.stop = function (forwardToLast) {
  4817. if (!this._clip) {
  4818. return;
  4819. }
  4820. var clip = this._clip;
  4821. if (forwardToLast) {
  4822. clip.onframe(1);
  4823. }
  4824. this._abortedCallback();
  4825. };
  4826. Animator.prototype.delay = function (time) {
  4827. this._delay = time;
  4828. return this;
  4829. };
  4830. Animator.prototype.during = function (cb) {
  4831. if (cb) {
  4832. if (!this._onframeCbs) {
  4833. this._onframeCbs = [];
  4834. }
  4835. this._onframeCbs.push(cb);
  4836. }
  4837. return this;
  4838. };
  4839. Animator.prototype.done = function (cb) {
  4840. if (cb) {
  4841. if (!this._doneCbs) {
  4842. this._doneCbs = [];
  4843. }
  4844. this._doneCbs.push(cb);
  4845. }
  4846. return this;
  4847. };
  4848. Animator.prototype.aborted = function (cb) {
  4849. if (cb) {
  4850. if (!this._abortedCbs) {
  4851. this._abortedCbs = [];
  4852. }
  4853. this._abortedCbs.push(cb);
  4854. }
  4855. return this;
  4856. };
  4857. Animator.prototype.getClip = function () {
  4858. return this._clip;
  4859. };
  4860. Animator.prototype.getTrack = function (propName) {
  4861. return this._tracks[propName];
  4862. };
  4863. Animator.prototype.getTracks = function () {
  4864. var _this = this;
  4865. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4866. };
  4867. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4868. if (!propNames.length || !this._clip) {
  4869. return true;
  4870. }
  4871. var tracks = this._tracks;
  4872. var tracksKeys = this._trackKeys;
  4873. for (var i = 0; i < propNames.length; i++) {
  4874. var track = tracks[propNames[i]];
  4875. if (track && !track.isFinished()) {
  4876. if (forwardToLast) {
  4877. track.step(this._target, 1);
  4878. }
  4879. else if (this._started === 1) {
  4880. track.step(this._target, 0);
  4881. }
  4882. track.setFinished();
  4883. }
  4884. }
  4885. var allAborted = true;
  4886. for (var i = 0; i < tracksKeys.length; i++) {
  4887. if (!tracks[tracksKeys[i]].isFinished()) {
  4888. allAborted = false;
  4889. break;
  4890. }
  4891. }
  4892. if (allAborted) {
  4893. this._abortedCallback();
  4894. }
  4895. return allAborted;
  4896. };
  4897. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4898. if (!target) {
  4899. return;
  4900. }
  4901. trackKeys = trackKeys || this._trackKeys;
  4902. for (var i = 0; i < trackKeys.length; i++) {
  4903. var propName = trackKeys[i];
  4904. var track = this._tracks[propName];
  4905. if (!track || track.isFinished()) {
  4906. continue;
  4907. }
  4908. var kfs = track.keyframes;
  4909. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4910. if (kf) {
  4911. target[propName] = cloneValue(kf.rawValue);
  4912. }
  4913. }
  4914. };
  4915. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4916. trackKeys = trackKeys || keys(finalProps);
  4917. for (var i = 0; i < trackKeys.length; i++) {
  4918. var propName = trackKeys[i];
  4919. var track = this._tracks[propName];
  4920. if (!track) {
  4921. continue;
  4922. }
  4923. var kfs = track.keyframes;
  4924. if (kfs.length > 1) {
  4925. var lastKf = kfs.pop();
  4926. track.addKeyframe(lastKf.time, finalProps[propName]);
  4927. track.prepare(this._maxTime, track.getAdditiveTrack());
  4928. }
  4929. }
  4930. };
  4931. return Animator;
  4932. }());
  4933. function getTime() {
  4934. return new Date().getTime();
  4935. }
  4936. var Animation = (function (_super) {
  4937. __extends(Animation, _super);
  4938. function Animation(opts) {
  4939. var _this = _super.call(this) || this;
  4940. _this._running = false;
  4941. _this._time = 0;
  4942. _this._pausedTime = 0;
  4943. _this._pauseStart = 0;
  4944. _this._paused = false;
  4945. opts = opts || {};
  4946. _this.stage = opts.stage || {};
  4947. return _this;
  4948. }
  4949. Animation.prototype.addClip = function (clip) {
  4950. if (clip.animation) {
  4951. this.removeClip(clip);
  4952. }
  4953. if (!this._head) {
  4954. this._head = this._tail = clip;
  4955. }
  4956. else {
  4957. this._tail.next = clip;
  4958. clip.prev = this._tail;
  4959. clip.next = null;
  4960. this._tail = clip;
  4961. }
  4962. clip.animation = this;
  4963. };
  4964. Animation.prototype.addAnimator = function (animator) {
  4965. animator.animation = this;
  4966. var clip = animator.getClip();
  4967. if (clip) {
  4968. this.addClip(clip);
  4969. }
  4970. };
  4971. Animation.prototype.removeClip = function (clip) {
  4972. if (!clip.animation) {
  4973. return;
  4974. }
  4975. var prev = clip.prev;
  4976. var next = clip.next;
  4977. if (prev) {
  4978. prev.next = next;
  4979. }
  4980. else {
  4981. this._head = next;
  4982. }
  4983. if (next) {
  4984. next.prev = prev;
  4985. }
  4986. else {
  4987. this._tail = prev;
  4988. }
  4989. clip.next = clip.prev = clip.animation = null;
  4990. };
  4991. Animation.prototype.removeAnimator = function (animator) {
  4992. var clip = animator.getClip();
  4993. if (clip) {
  4994. this.removeClip(clip);
  4995. }
  4996. animator.animation = null;
  4997. };
  4998. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4999. var time = getTime() - this._pausedTime;
  5000. var delta = time - this._time;
  5001. var clip = this._head;
  5002. while (clip) {
  5003. var nextClip = clip.next;
  5004. var finished = clip.step(time, delta);
  5005. if (finished) {
  5006. clip.ondestroy();
  5007. this.removeClip(clip);
  5008. clip = nextClip;
  5009. }
  5010. else {
  5011. clip = nextClip;
  5012. }
  5013. }
  5014. this._time = time;
  5015. if (!notTriggerFrameAndStageUpdate) {
  5016. this.trigger('frame', delta);
  5017. this.stage.update && this.stage.update();
  5018. }
  5019. };
  5020. Animation.prototype._startLoop = function () {
  5021. var self = this;
  5022. this._running = true;
  5023. function step() {
  5024. if (self._running) {
  5025. requestAnimationFrame$1(step);
  5026. !self._paused && self.update();
  5027. }
  5028. }
  5029. requestAnimationFrame$1(step);
  5030. };
  5031. Animation.prototype.start = function () {
  5032. if (this._running) {
  5033. return;
  5034. }
  5035. this._time = getTime();
  5036. this._pausedTime = 0;
  5037. this._startLoop();
  5038. };
  5039. Animation.prototype.stop = function () {
  5040. this._running = false;
  5041. };
  5042. Animation.prototype.pause = function () {
  5043. if (!this._paused) {
  5044. this._pauseStart = getTime();
  5045. this._paused = true;
  5046. }
  5047. };
  5048. Animation.prototype.resume = function () {
  5049. if (this._paused) {
  5050. this._pausedTime += getTime() - this._pauseStart;
  5051. this._paused = false;
  5052. }
  5053. };
  5054. Animation.prototype.clear = function () {
  5055. var clip = this._head;
  5056. while (clip) {
  5057. var nextClip = clip.next;
  5058. clip.prev = clip.next = clip.animation = null;
  5059. clip = nextClip;
  5060. }
  5061. this._head = this._tail = null;
  5062. };
  5063. Animation.prototype.isFinished = function () {
  5064. return this._head == null;
  5065. };
  5066. Animation.prototype.animate = function (target, options) {
  5067. options = options || {};
  5068. this.start();
  5069. var animator = new Animator(target, options.loop);
  5070. this.addAnimator(animator);
  5071. return animator;
  5072. };
  5073. return Animation;
  5074. }(Eventful));
  5075. var TOUCH_CLICK_DELAY = 300;
  5076. var globalEventSupported = env.domSupported;
  5077. var localNativeListenerNames = (function () {
  5078. var mouseHandlerNames = [
  5079. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5080. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5081. ];
  5082. var touchHandlerNames = [
  5083. 'touchstart', 'touchend', 'touchmove'
  5084. ];
  5085. var pointerEventNameMap = {
  5086. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5087. };
  5088. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5089. var nm = name.replace('mouse', 'pointer');
  5090. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5091. });
  5092. return {
  5093. mouse: mouseHandlerNames,
  5094. touch: touchHandlerNames,
  5095. pointer: pointerHandlerNames
  5096. };
  5097. })();
  5098. var globalNativeListenerNames = {
  5099. mouse: ['mousemove', 'mouseup'],
  5100. pointer: ['pointermove', 'pointerup']
  5101. };
  5102. var wheelEventSupported = false;
  5103. function isPointerFromTouch(event) {
  5104. var pointerType = event.pointerType;
  5105. return pointerType === 'pen' || pointerType === 'touch';
  5106. }
  5107. function setTouchTimer(scope) {
  5108. scope.touching = true;
  5109. if (scope.touchTimer != null) {
  5110. clearTimeout(scope.touchTimer);
  5111. scope.touchTimer = null;
  5112. }
  5113. scope.touchTimer = setTimeout(function () {
  5114. scope.touching = false;
  5115. scope.touchTimer = null;
  5116. }, 700);
  5117. }
  5118. function markTouch(event) {
  5119. event && (event.zrByTouch = true);
  5120. }
  5121. function normalizeGlobalEvent(instance, event) {
  5122. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5123. }
  5124. function isLocalEl(instance, el) {
  5125. var elTmp = el;
  5126. var isLocal = false;
  5127. while (elTmp && elTmp.nodeType !== 9
  5128. && !(isLocal = elTmp.domBelongToZr
  5129. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5130. elTmp = elTmp.parentNode;
  5131. }
  5132. return isLocal;
  5133. }
  5134. var FakeGlobalEvent = (function () {
  5135. function FakeGlobalEvent(instance, event) {
  5136. this.stopPropagation = noop;
  5137. this.stopImmediatePropagation = noop;
  5138. this.preventDefault = noop;
  5139. this.type = event.type;
  5140. this.target = this.currentTarget = instance.dom;
  5141. this.pointerType = event.pointerType;
  5142. this.clientX = event.clientX;
  5143. this.clientY = event.clientY;
  5144. }
  5145. return FakeGlobalEvent;
  5146. }());
  5147. var localDOMHandlers = {
  5148. mousedown: function (event) {
  5149. event = normalizeEvent(this.dom, event);
  5150. this.__mayPointerCapture = [event.zrX, event.zrY];
  5151. this.trigger('mousedown', event);
  5152. },
  5153. mousemove: function (event) {
  5154. event = normalizeEvent(this.dom, event);
  5155. var downPoint = this.__mayPointerCapture;
  5156. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5157. this.__togglePointerCapture(true);
  5158. }
  5159. this.trigger('mousemove', event);
  5160. },
  5161. mouseup: function (event) {
  5162. event = normalizeEvent(this.dom, event);
  5163. this.__togglePointerCapture(false);
  5164. this.trigger('mouseup', event);
  5165. },
  5166. mouseout: function (event) {
  5167. event = normalizeEvent(this.dom, event);
  5168. var element = event.toElement || event.relatedTarget;
  5169. if (!isLocalEl(this, element)) {
  5170. if (this.__pointerCapturing) {
  5171. event.zrEventControl = 'no_globalout';
  5172. }
  5173. this.trigger('mouseout', event);
  5174. }
  5175. },
  5176. wheel: function (event) {
  5177. wheelEventSupported = true;
  5178. event = normalizeEvent(this.dom, event);
  5179. this.trigger('mousewheel', event);
  5180. },
  5181. mousewheel: function (event) {
  5182. if (wheelEventSupported) {
  5183. return;
  5184. }
  5185. event = normalizeEvent(this.dom, event);
  5186. this.trigger('mousewheel', event);
  5187. },
  5188. touchstart: function (event) {
  5189. event = normalizeEvent(this.dom, event);
  5190. markTouch(event);
  5191. this.__lastTouchMoment = new Date();
  5192. this.handler.processGesture(event, 'start');
  5193. localDOMHandlers.mousemove.call(this, event);
  5194. localDOMHandlers.mousedown.call(this, event);
  5195. },
  5196. touchmove: function (event) {
  5197. event = normalizeEvent(this.dom, event);
  5198. markTouch(event);
  5199. this.handler.processGesture(event, 'change');
  5200. localDOMHandlers.mousemove.call(this, event);
  5201. },
  5202. touchend: function (event) {
  5203. event = normalizeEvent(this.dom, event);
  5204. markTouch(event);
  5205. this.handler.processGesture(event, 'end');
  5206. localDOMHandlers.mouseup.call(this, event);
  5207. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5208. localDOMHandlers.click.call(this, event);
  5209. }
  5210. },
  5211. pointerdown: function (event) {
  5212. localDOMHandlers.mousedown.call(this, event);
  5213. },
  5214. pointermove: function (event) {
  5215. if (!isPointerFromTouch(event)) {
  5216. localDOMHandlers.mousemove.call(this, event);
  5217. }
  5218. },
  5219. pointerup: function (event) {
  5220. localDOMHandlers.mouseup.call(this, event);
  5221. },
  5222. pointerout: function (event) {
  5223. if (!isPointerFromTouch(event)) {
  5224. localDOMHandlers.mouseout.call(this, event);
  5225. }
  5226. }
  5227. };
  5228. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5229. localDOMHandlers[name] = function (event) {
  5230. event = normalizeEvent(this.dom, event);
  5231. this.trigger(name, event);
  5232. };
  5233. });
  5234. var globalDOMHandlers = {
  5235. pointermove: function (event) {
  5236. if (!isPointerFromTouch(event)) {
  5237. globalDOMHandlers.mousemove.call(this, event);
  5238. }
  5239. },
  5240. pointerup: function (event) {
  5241. globalDOMHandlers.mouseup.call(this, event);
  5242. },
  5243. mousemove: function (event) {
  5244. this.trigger('mousemove', event);
  5245. },
  5246. mouseup: function (event) {
  5247. var pointerCaptureReleasing = this.__pointerCapturing;
  5248. this.__togglePointerCapture(false);
  5249. this.trigger('mouseup', event);
  5250. if (pointerCaptureReleasing) {
  5251. event.zrEventControl = 'only_globalout';
  5252. this.trigger('mouseout', event);
  5253. }
  5254. }
  5255. };
  5256. function mountLocalDOMEventListeners(instance, scope) {
  5257. var domHandlers = scope.domHandlers;
  5258. if (env.pointerEventsSupported) {
  5259. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5260. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5261. domHandlers[nativeEventName].call(instance, event);
  5262. });
  5263. });
  5264. }
  5265. else {
  5266. if (env.touchEventsSupported) {
  5267. each(localNativeListenerNames.touch, function (nativeEventName) {
  5268. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5269. domHandlers[nativeEventName].call(instance, event);
  5270. setTouchTimer(scope);
  5271. });
  5272. });
  5273. }
  5274. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5275. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5276. event = getNativeEvent(event);
  5277. if (!scope.touching) {
  5278. domHandlers[nativeEventName].call(instance, event);
  5279. }
  5280. });
  5281. });
  5282. }
  5283. }
  5284. function mountGlobalDOMEventListeners(instance, scope) {
  5285. if (env.pointerEventsSupported) {
  5286. each(globalNativeListenerNames.pointer, mount);
  5287. }
  5288. else if (!env.touchEventsSupported) {
  5289. each(globalNativeListenerNames.mouse, mount);
  5290. }
  5291. function mount(nativeEventName) {
  5292. function nativeEventListener(event) {
  5293. event = getNativeEvent(event);
  5294. if (!isLocalEl(instance, event.target)) {
  5295. event = normalizeGlobalEvent(instance, event);
  5296. scope.domHandlers[nativeEventName].call(instance, event);
  5297. }
  5298. }
  5299. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5300. }
  5301. }
  5302. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5303. scope.mounted[nativeEventName] = listener;
  5304. scope.listenerOpts[nativeEventName] = opt;
  5305. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5306. }
  5307. function unmountDOMEventListeners(scope) {
  5308. var mounted = scope.mounted;
  5309. for (var nativeEventName in mounted) {
  5310. if (mounted.hasOwnProperty(nativeEventName)) {
  5311. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5312. }
  5313. }
  5314. scope.mounted = {};
  5315. }
  5316. var DOMHandlerScope = (function () {
  5317. function DOMHandlerScope(domTarget, domHandlers) {
  5318. this.mounted = {};
  5319. this.listenerOpts = {};
  5320. this.touching = false;
  5321. this.domTarget = domTarget;
  5322. this.domHandlers = domHandlers;
  5323. }
  5324. return DOMHandlerScope;
  5325. }());
  5326. var HandlerDomProxy = (function (_super) {
  5327. __extends(HandlerDomProxy, _super);
  5328. function HandlerDomProxy(dom, painterRoot) {
  5329. var _this = _super.call(this) || this;
  5330. _this.__pointerCapturing = false;
  5331. _this.dom = dom;
  5332. _this.painterRoot = painterRoot;
  5333. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5334. if (globalEventSupported) {
  5335. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5336. }
  5337. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5338. return _this;
  5339. }
  5340. HandlerDomProxy.prototype.dispose = function () {
  5341. unmountDOMEventListeners(this._localHandlerScope);
  5342. if (globalEventSupported) {
  5343. unmountDOMEventListeners(this._globalHandlerScope);
  5344. }
  5345. };
  5346. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5347. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5348. };
  5349. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5350. this.__mayPointerCapture = null;
  5351. if (globalEventSupported
  5352. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5353. this.__pointerCapturing = isPointerCapturing;
  5354. var globalHandlerScope = this._globalHandlerScope;
  5355. isPointerCapturing
  5356. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5357. : unmountDOMEventListeners(globalHandlerScope);
  5358. }
  5359. };
  5360. return HandlerDomProxy;
  5361. }(Eventful));
  5362. var dpr = 1;
  5363. if (env.hasGlobalWindow) {
  5364. dpr = Math.max(window.devicePixelRatio
  5365. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5366. || 1, 1);
  5367. }
  5368. var devicePixelRatio = dpr;
  5369. var DARK_MODE_THRESHOLD = 0.4;
  5370. var DARK_LABEL_COLOR = '#333';
  5371. var LIGHT_LABEL_COLOR = '#ccc';
  5372. var LIGHTER_LABEL_COLOR = '#eee';
  5373. var mIdentity = identity;
  5374. var EPSILON$2 = 5e-5;
  5375. function isNotAroundZero$1(val) {
  5376. return val > EPSILON$2 || val < -EPSILON$2;
  5377. }
  5378. var scaleTmp = [];
  5379. var tmpTransform = [];
  5380. var originTransform = create$1();
  5381. var abs = Math.abs;
  5382. var Transformable = (function () {
  5383. function Transformable() {
  5384. }
  5385. Transformable.prototype.getLocalTransform = function (m) {
  5386. return Transformable.getLocalTransform(this, m);
  5387. };
  5388. Transformable.prototype.setPosition = function (arr) {
  5389. this.x = arr[0];
  5390. this.y = arr[1];
  5391. };
  5392. Transformable.prototype.setScale = function (arr) {
  5393. this.scaleX = arr[0];
  5394. this.scaleY = arr[1];
  5395. };
  5396. Transformable.prototype.setSkew = function (arr) {
  5397. this.skewX = arr[0];
  5398. this.skewY = arr[1];
  5399. };
  5400. Transformable.prototype.setOrigin = function (arr) {
  5401. this.originX = arr[0];
  5402. this.originY = arr[1];
  5403. };
  5404. Transformable.prototype.needLocalTransform = function () {
  5405. return isNotAroundZero$1(this.rotation)
  5406. || isNotAroundZero$1(this.x)
  5407. || isNotAroundZero$1(this.y)
  5408. || isNotAroundZero$1(this.scaleX - 1)
  5409. || isNotAroundZero$1(this.scaleY - 1)
  5410. || isNotAroundZero$1(this.skewX)
  5411. || isNotAroundZero$1(this.skewY);
  5412. };
  5413. Transformable.prototype.updateTransform = function () {
  5414. var parentTransform = this.parent && this.parent.transform;
  5415. var needLocalTransform = this.needLocalTransform();
  5416. var m = this.transform;
  5417. if (!(needLocalTransform || parentTransform)) {
  5418. if (m) {
  5419. mIdentity(m);
  5420. this.invTransform = null;
  5421. }
  5422. return;
  5423. }
  5424. m = m || create$1();
  5425. if (needLocalTransform) {
  5426. this.getLocalTransform(m);
  5427. }
  5428. else {
  5429. mIdentity(m);
  5430. }
  5431. if (parentTransform) {
  5432. if (needLocalTransform) {
  5433. mul$1(m, parentTransform, m);
  5434. }
  5435. else {
  5436. copy$1(m, parentTransform);
  5437. }
  5438. }
  5439. this.transform = m;
  5440. this._resolveGlobalScaleRatio(m);
  5441. };
  5442. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5443. var globalScaleRatio = this.globalScaleRatio;
  5444. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5445. this.getGlobalScale(scaleTmp);
  5446. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5447. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5448. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5449. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5450. m[0] *= sx;
  5451. m[1] *= sx;
  5452. m[2] *= sy;
  5453. m[3] *= sy;
  5454. }
  5455. this.invTransform = this.invTransform || create$1();
  5456. invert(this.invTransform, m);
  5457. };
  5458. Transformable.prototype.getComputedTransform = function () {
  5459. var transformNode = this;
  5460. var ancestors = [];
  5461. while (transformNode) {
  5462. ancestors.push(transformNode);
  5463. transformNode = transformNode.parent;
  5464. }
  5465. while (transformNode = ancestors.pop()) {
  5466. transformNode.updateTransform();
  5467. }
  5468. return this.transform;
  5469. };
  5470. Transformable.prototype.setLocalTransform = function (m) {
  5471. if (!m) {
  5472. return;
  5473. }
  5474. var sx = m[0] * m[0] + m[1] * m[1];
  5475. var sy = m[2] * m[2] + m[3] * m[3];
  5476. var rotation = Math.atan2(m[1], m[0]);
  5477. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5478. sy = Math.sqrt(sy) * Math.cos(shearX);
  5479. sx = Math.sqrt(sx);
  5480. this.skewX = shearX;
  5481. this.skewY = 0;
  5482. this.rotation = -rotation;
  5483. this.x = +m[4];
  5484. this.y = +m[5];
  5485. this.scaleX = sx;
  5486. this.scaleY = sy;
  5487. this.originX = 0;
  5488. this.originY = 0;
  5489. };
  5490. Transformable.prototype.decomposeTransform = function () {
  5491. if (!this.transform) {
  5492. return;
  5493. }
  5494. var parent = this.parent;
  5495. var m = this.transform;
  5496. if (parent && parent.transform) {
  5497. parent.invTransform = parent.invTransform || create$1();
  5498. mul$1(tmpTransform, parent.invTransform, m);
  5499. m = tmpTransform;
  5500. }
  5501. var ox = this.originX;
  5502. var oy = this.originY;
  5503. if (ox || oy) {
  5504. originTransform[4] = ox;
  5505. originTransform[5] = oy;
  5506. mul$1(tmpTransform, m, originTransform);
  5507. tmpTransform[4] -= ox;
  5508. tmpTransform[5] -= oy;
  5509. m = tmpTransform;
  5510. }
  5511. this.setLocalTransform(m);
  5512. };
  5513. Transformable.prototype.getGlobalScale = function (out) {
  5514. var m = this.transform;
  5515. out = out || [];
  5516. if (!m) {
  5517. out[0] = 1;
  5518. out[1] = 1;
  5519. return out;
  5520. }
  5521. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5522. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5523. if (m[0] < 0) {
  5524. out[0] = -out[0];
  5525. }
  5526. if (m[3] < 0) {
  5527. out[1] = -out[1];
  5528. }
  5529. return out;
  5530. };
  5531. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5532. var v2 = [x, y];
  5533. var invTransform = this.invTransform;
  5534. if (invTransform) {
  5535. applyTransform(v2, v2, invTransform);
  5536. }
  5537. return v2;
  5538. };
  5539. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5540. var v2 = [x, y];
  5541. var transform = this.transform;
  5542. if (transform) {
  5543. applyTransform(v2, v2, transform);
  5544. }
  5545. return v2;
  5546. };
  5547. Transformable.prototype.getLineScale = function () {
  5548. var m = this.transform;
  5549. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5550. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5551. : 1;
  5552. };
  5553. Transformable.prototype.copyTransform = function (source) {
  5554. copyTransform(this, source);
  5555. };
  5556. Transformable.getLocalTransform = function (target, m) {
  5557. m = m || [];
  5558. var ox = target.originX || 0;
  5559. var oy = target.originY || 0;
  5560. var sx = target.scaleX;
  5561. var sy = target.scaleY;
  5562. var ax = target.anchorX;
  5563. var ay = target.anchorY;
  5564. var rotation = target.rotation || 0;
  5565. var x = target.x;
  5566. var y = target.y;
  5567. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5568. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5569. if (ox || oy || ax || ay) {
  5570. var dx = ox + ax;
  5571. var dy = oy + ay;
  5572. m[4] = -dx * sx - skewX * dy * sy;
  5573. m[5] = -dy * sy - skewY * dx * sx;
  5574. }
  5575. else {
  5576. m[4] = m[5] = 0;
  5577. }
  5578. m[0] = sx;
  5579. m[3] = sy;
  5580. m[1] = skewY * sx;
  5581. m[2] = skewX * sy;
  5582. rotation && rotate(m, m, rotation);
  5583. m[4] += ox + x;
  5584. m[5] += oy + y;
  5585. return m;
  5586. };
  5587. Transformable.initDefaultProps = (function () {
  5588. var proto = Transformable.prototype;
  5589. proto.scaleX =
  5590. proto.scaleY =
  5591. proto.globalScaleRatio = 1;
  5592. proto.x =
  5593. proto.y =
  5594. proto.originX =
  5595. proto.originY =
  5596. proto.skewX =
  5597. proto.skewY =
  5598. proto.rotation =
  5599. proto.anchorX =
  5600. proto.anchorY = 0;
  5601. })();
  5602. return Transformable;
  5603. }());
  5604. var TRANSFORMABLE_PROPS = [
  5605. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5606. ];
  5607. function copyTransform(target, source) {
  5608. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5609. var propName = TRANSFORMABLE_PROPS[i];
  5610. target[propName] = source[propName];
  5611. }
  5612. }
  5613. function ensureFontMeasureInfo(font) {
  5614. if (!_fontMeasureInfoCache) {
  5615. _fontMeasureInfoCache = new LRU(100);
  5616. }
  5617. font = font || DEFAULT_FONT;
  5618. var measureInfo = _fontMeasureInfoCache.get(font);
  5619. if (!measureInfo) {
  5620. measureInfo = {
  5621. font: font,
  5622. strWidthCache: new LRU(500),
  5623. asciiWidthMap: null,
  5624. asciiWidthMapTried: false,
  5625. stWideCharWidth: platformApi.measureText('国', font).width,
  5626. asciiCharWidth: platformApi.measureText('a', font).width
  5627. };
  5628. _fontMeasureInfoCache.put(font, measureInfo);
  5629. }
  5630. return measureInfo;
  5631. }
  5632. var _fontMeasureInfoCache;
  5633. function tryCreateASCIIWidthMap(font) {
  5634. if (_getASCIIWidthMapLongCount >= GET_ASCII_WIDTH_LONG_COUNT_MAX) {
  5635. return;
  5636. }
  5637. font = font || DEFAULT_FONT;
  5638. var asciiWidthMap = [];
  5639. var start = +(new Date());
  5640. for (var code = 0; code <= 127; code++) {
  5641. asciiWidthMap[code] = platformApi.measureText(String.fromCharCode(code), font).width;
  5642. }
  5643. var cost = +(new Date()) - start;
  5644. if (cost > 16) {
  5645. _getASCIIWidthMapLongCount = GET_ASCII_WIDTH_LONG_COUNT_MAX;
  5646. }
  5647. else if (cost > 2) {
  5648. _getASCIIWidthMapLongCount++;
  5649. }
  5650. return asciiWidthMap;
  5651. }
  5652. var _getASCIIWidthMapLongCount = 0;
  5653. var GET_ASCII_WIDTH_LONG_COUNT_MAX = 5;
  5654. function measureCharWidth(fontMeasureInfo, charCode) {
  5655. if (!fontMeasureInfo.asciiWidthMapTried) {
  5656. fontMeasureInfo.asciiWidthMap = tryCreateASCIIWidthMap(fontMeasureInfo.font);
  5657. fontMeasureInfo.asciiWidthMapTried = true;
  5658. }
  5659. return (0 <= charCode && charCode <= 127)
  5660. ? (fontMeasureInfo.asciiWidthMap != null
  5661. ? fontMeasureInfo.asciiWidthMap[charCode]
  5662. : fontMeasureInfo.asciiCharWidth)
  5663. : fontMeasureInfo.stWideCharWidth;
  5664. }
  5665. function measureWidth(fontMeasureInfo, text) {
  5666. var strWidthCache = fontMeasureInfo.strWidthCache;
  5667. var width = strWidthCache.get(text);
  5668. if (width == null) {
  5669. width = platformApi.measureText(text, fontMeasureInfo.font).width;
  5670. strWidthCache.put(text, width);
  5671. }
  5672. return width;
  5673. }
  5674. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5675. var width = measureWidth(ensureFontMeasureInfo(font), text);
  5676. var height = getLineHeight(font);
  5677. var x = adjustTextX(0, width, textAlign);
  5678. var y = adjustTextY(0, height, textBaseline);
  5679. var rect = new BoundingRect(x, y, width, height);
  5680. return rect;
  5681. }
  5682. function getBoundingRect(text, font, textAlign, textBaseline) {
  5683. var textLines = ((text || '') + '').split('\n');
  5684. var len = textLines.length;
  5685. if (len === 1) {
  5686. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5687. }
  5688. else {
  5689. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5690. for (var i = 0; i < textLines.length; i++) {
  5691. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5692. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5693. }
  5694. return uniondRect;
  5695. }
  5696. }
  5697. function adjustTextX(x, width, textAlign, inverse) {
  5698. if (textAlign === 'right') {
  5699. !inverse ? (x -= width) : (x += width);
  5700. }
  5701. else if (textAlign === 'center') {
  5702. !inverse ? (x -= width / 2) : (x += width / 2);
  5703. }
  5704. return x;
  5705. }
  5706. function adjustTextY(y, height, verticalAlign, inverse) {
  5707. if (verticalAlign === 'middle') {
  5708. !inverse ? (y -= height / 2) : (y += height / 2);
  5709. }
  5710. else if (verticalAlign === 'bottom') {
  5711. !inverse ? (y -= height) : (y += height);
  5712. }
  5713. return y;
  5714. }
  5715. function getLineHeight(font) {
  5716. return ensureFontMeasureInfo(font).stWideCharWidth;
  5717. }
  5718. function parsePercent(value, maxValue) {
  5719. if (typeof value === 'string') {
  5720. if (value.lastIndexOf('%') >= 0) {
  5721. return parseFloat(value) / 100 * maxValue;
  5722. }
  5723. return parseFloat(value);
  5724. }
  5725. return value;
  5726. }
  5727. function calculateTextPosition(out, opts, rect) {
  5728. var textPosition = opts.position || 'inside';
  5729. var distance = opts.distance != null ? opts.distance : 5;
  5730. var height = rect.height;
  5731. var width = rect.width;
  5732. var halfHeight = height / 2;
  5733. var x = rect.x;
  5734. var y = rect.y;
  5735. var textAlign = 'left';
  5736. var textVerticalAlign = 'top';
  5737. if (textPosition instanceof Array) {
  5738. x += parsePercent(textPosition[0], rect.width);
  5739. y += parsePercent(textPosition[1], rect.height);
  5740. textAlign = null;
  5741. textVerticalAlign = null;
  5742. }
  5743. else {
  5744. switch (textPosition) {
  5745. case 'left':
  5746. x -= distance;
  5747. y += halfHeight;
  5748. textAlign = 'right';
  5749. textVerticalAlign = 'middle';
  5750. break;
  5751. case 'right':
  5752. x += distance + width;
  5753. y += halfHeight;
  5754. textVerticalAlign = 'middle';
  5755. break;
  5756. case 'top':
  5757. x += width / 2;
  5758. y -= distance;
  5759. textAlign = 'center';
  5760. textVerticalAlign = 'bottom';
  5761. break;
  5762. case 'bottom':
  5763. x += width / 2;
  5764. y += height + distance;
  5765. textAlign = 'center';
  5766. break;
  5767. case 'inside':
  5768. x += width / 2;
  5769. y += halfHeight;
  5770. textAlign = 'center';
  5771. textVerticalAlign = 'middle';
  5772. break;
  5773. case 'insideLeft':
  5774. x += distance;
  5775. y += halfHeight;
  5776. textVerticalAlign = 'middle';
  5777. break;
  5778. case 'insideRight':
  5779. x += width - distance;
  5780. y += halfHeight;
  5781. textAlign = 'right';
  5782. textVerticalAlign = 'middle';
  5783. break;
  5784. case 'insideTop':
  5785. x += width / 2;
  5786. y += distance;
  5787. textAlign = 'center';
  5788. break;
  5789. case 'insideBottom':
  5790. x += width / 2;
  5791. y += height - distance;
  5792. textAlign = 'center';
  5793. textVerticalAlign = 'bottom';
  5794. break;
  5795. case 'insideTopLeft':
  5796. x += distance;
  5797. y += distance;
  5798. break;
  5799. case 'insideTopRight':
  5800. x += width - distance;
  5801. y += distance;
  5802. textAlign = 'right';
  5803. break;
  5804. case 'insideBottomLeft':
  5805. x += distance;
  5806. y += height - distance;
  5807. textVerticalAlign = 'bottom';
  5808. break;
  5809. case 'insideBottomRight':
  5810. x += width - distance;
  5811. y += height - distance;
  5812. textAlign = 'right';
  5813. textVerticalAlign = 'bottom';
  5814. break;
  5815. }
  5816. }
  5817. out = out || {};
  5818. out.x = x;
  5819. out.y = y;
  5820. out.align = textAlign;
  5821. out.verticalAlign = textVerticalAlign;
  5822. return out;
  5823. }
  5824. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5825. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5826. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5827. obj[key] = true;
  5828. return obj;
  5829. }, { ignore: false });
  5830. var tmpTextPosCalcRes = {};
  5831. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5832. var tmpInnerTextTrans = [];
  5833. var Element = (function () {
  5834. function Element(props) {
  5835. this.id = guid();
  5836. this.animators = [];
  5837. this.currentStates = [];
  5838. this.states = {};
  5839. this._init(props);
  5840. }
  5841. Element.prototype._init = function (props) {
  5842. this.attr(props);
  5843. };
  5844. Element.prototype.drift = function (dx, dy, e) {
  5845. switch (this.draggable) {
  5846. case 'horizontal':
  5847. dy = 0;
  5848. break;
  5849. case 'vertical':
  5850. dx = 0;
  5851. break;
  5852. }
  5853. var m = this.transform;
  5854. if (!m) {
  5855. m = this.transform = [1, 0, 0, 1, 0, 0];
  5856. }
  5857. m[4] += dx;
  5858. m[5] += dy;
  5859. this.decomposeTransform();
  5860. this.markRedraw();
  5861. };
  5862. Element.prototype.beforeUpdate = function () { };
  5863. Element.prototype.afterUpdate = function () { };
  5864. Element.prototype.update = function () {
  5865. this.updateTransform();
  5866. if (this.__dirty) {
  5867. this.updateInnerText();
  5868. }
  5869. };
  5870. Element.prototype.updateInnerText = function (forceUpdate) {
  5871. var textEl = this._textContent;
  5872. if (textEl && (!textEl.ignore || forceUpdate)) {
  5873. if (!this.textConfig) {
  5874. this.textConfig = {};
  5875. }
  5876. var textConfig = this.textConfig;
  5877. var isLocal = textConfig.local;
  5878. var innerTransformable = textEl.innerTransformable;
  5879. var textAlign = void 0;
  5880. var textVerticalAlign = void 0;
  5881. var textStyleChanged = false;
  5882. innerTransformable.parent = isLocal ? this : null;
  5883. var innerOrigin = false;
  5884. innerTransformable.copyTransform(textEl);
  5885. var hasPosition = textConfig.position != null;
  5886. var autoOverflowArea = textConfig.autoOverflowArea;
  5887. var layoutRect = void 0;
  5888. if (autoOverflowArea || hasPosition) {
  5889. layoutRect = tmpBoundingRect;
  5890. if (textConfig.layoutRect) {
  5891. layoutRect.copy(textConfig.layoutRect);
  5892. }
  5893. else {
  5894. layoutRect.copy(this.getBoundingRect());
  5895. }
  5896. if (!isLocal) {
  5897. layoutRect.applyTransform(this.transform);
  5898. }
  5899. }
  5900. if (hasPosition) {
  5901. if (this.calculateTextPosition) {
  5902. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5903. }
  5904. else {
  5905. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5906. }
  5907. innerTransformable.x = tmpTextPosCalcRes.x;
  5908. innerTransformable.y = tmpTextPosCalcRes.y;
  5909. textAlign = tmpTextPosCalcRes.align;
  5910. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5911. var textOrigin = textConfig.origin;
  5912. if (textOrigin && textConfig.rotation != null) {
  5913. var relOriginX = void 0;
  5914. var relOriginY = void 0;
  5915. if (textOrigin === 'center') {
  5916. relOriginX = layoutRect.width * 0.5;
  5917. relOriginY = layoutRect.height * 0.5;
  5918. }
  5919. else {
  5920. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5921. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5922. }
  5923. innerOrigin = true;
  5924. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5925. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5926. }
  5927. }
  5928. if (textConfig.rotation != null) {
  5929. innerTransformable.rotation = textConfig.rotation;
  5930. }
  5931. var textOffset = textConfig.offset;
  5932. if (textOffset) {
  5933. innerTransformable.x += textOffset[0];
  5934. innerTransformable.y += textOffset[1];
  5935. if (!innerOrigin) {
  5936. innerTransformable.originX = -textOffset[0];
  5937. innerTransformable.originY = -textOffset[1];
  5938. }
  5939. }
  5940. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5941. if (autoOverflowArea) {
  5942. var overflowRect = innerTextDefaultStyle.overflowRect =
  5943. innerTextDefaultStyle.overflowRect || new BoundingRect(0, 0, 0, 0);
  5944. innerTransformable.getLocalTransform(tmpInnerTextTrans);
  5945. invert(tmpInnerTextTrans, tmpInnerTextTrans);
  5946. BoundingRect.copy(overflowRect, layoutRect);
  5947. overflowRect.applyTransform(tmpInnerTextTrans);
  5948. }
  5949. else {
  5950. innerTextDefaultStyle.overflowRect = null;
  5951. }
  5952. var isInside = textConfig.inside == null
  5953. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5954. : textConfig.inside;
  5955. var textFill = void 0;
  5956. var textStroke = void 0;
  5957. var autoStroke = void 0;
  5958. if (isInside && this.canBeInsideText()) {
  5959. textFill = textConfig.insideFill;
  5960. textStroke = textConfig.insideStroke;
  5961. if (textFill == null || textFill === 'auto') {
  5962. textFill = this.getInsideTextFill();
  5963. }
  5964. if (textStroke == null || textStroke === 'auto') {
  5965. textStroke = this.getInsideTextStroke(textFill);
  5966. autoStroke = true;
  5967. }
  5968. }
  5969. else {
  5970. textFill = textConfig.outsideFill;
  5971. textStroke = textConfig.outsideStroke;
  5972. if (textFill == null || textFill === 'auto') {
  5973. textFill = this.getOutsideFill();
  5974. }
  5975. if (textStroke == null || textStroke === 'auto') {
  5976. textStroke = this.getOutsideStroke(textFill);
  5977. autoStroke = true;
  5978. }
  5979. }
  5980. textFill = textFill || '#000';
  5981. if (textFill !== innerTextDefaultStyle.fill
  5982. || textStroke !== innerTextDefaultStyle.stroke
  5983. || autoStroke !== innerTextDefaultStyle.autoStroke
  5984. || textAlign !== innerTextDefaultStyle.align
  5985. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5986. textStyleChanged = true;
  5987. innerTextDefaultStyle.fill = textFill;
  5988. innerTextDefaultStyle.stroke = textStroke;
  5989. innerTextDefaultStyle.autoStroke = autoStroke;
  5990. innerTextDefaultStyle.align = textAlign;
  5991. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5992. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5993. }
  5994. textEl.__dirty |= REDRAW_BIT;
  5995. if (textStyleChanged) {
  5996. textEl.dirtyStyle(true);
  5997. }
  5998. }
  5999. };
  6000. Element.prototype.canBeInsideText = function () {
  6001. return true;
  6002. };
  6003. Element.prototype.getInsideTextFill = function () {
  6004. return '#fff';
  6005. };
  6006. Element.prototype.getInsideTextStroke = function (textFill) {
  6007. return '#000';
  6008. };
  6009. Element.prototype.getOutsideFill = function () {
  6010. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  6011. };
  6012. Element.prototype.getOutsideStroke = function (textFill) {
  6013. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  6014. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  6015. if (!colorArr) {
  6016. colorArr = [255, 255, 255, 1];
  6017. }
  6018. var alpha = colorArr[3];
  6019. var isDark = this.__zr.isDarkMode();
  6020. for (var i = 0; i < 3; i++) {
  6021. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  6022. }
  6023. colorArr[3] = 1;
  6024. return stringify(colorArr, 'rgba');
  6025. };
  6026. Element.prototype.traverse = function (cb, context) { };
  6027. Element.prototype.attrKV = function (key, value) {
  6028. if (key === 'textConfig') {
  6029. this.setTextConfig(value);
  6030. }
  6031. else if (key === 'textContent') {
  6032. this.setTextContent(value);
  6033. }
  6034. else if (key === 'clipPath') {
  6035. this.setClipPath(value);
  6036. }
  6037. else if (key === 'extra') {
  6038. this.extra = this.extra || {};
  6039. extend(this.extra, value);
  6040. }
  6041. else {
  6042. this[key] = value;
  6043. }
  6044. };
  6045. Element.prototype.hide = function () {
  6046. this.ignore = true;
  6047. this.markRedraw();
  6048. };
  6049. Element.prototype.show = function () {
  6050. this.ignore = false;
  6051. this.markRedraw();
  6052. };
  6053. Element.prototype.attr = function (keyOrObj, value) {
  6054. if (typeof keyOrObj === 'string') {
  6055. this.attrKV(keyOrObj, value);
  6056. }
  6057. else if (isObject(keyOrObj)) {
  6058. var obj = keyOrObj;
  6059. var keysArr = keys(obj);
  6060. for (var i = 0; i < keysArr.length; i++) {
  6061. var key = keysArr[i];
  6062. this.attrKV(key, keyOrObj[key]);
  6063. }
  6064. }
  6065. this.markRedraw();
  6066. return this;
  6067. };
  6068. Element.prototype.saveCurrentToNormalState = function (toState) {
  6069. this._innerSaveToNormal(toState);
  6070. var normalState = this._normalState;
  6071. for (var i = 0; i < this.animators.length; i++) {
  6072. var animator = this.animators[i];
  6073. var fromStateTransition = animator.__fromStateTransition;
  6074. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  6075. continue;
  6076. }
  6077. var targetName = animator.targetName;
  6078. var target = targetName
  6079. ? normalState[targetName] : normalState;
  6080. animator.saveTo(target);
  6081. }
  6082. };
  6083. Element.prototype._innerSaveToNormal = function (toState) {
  6084. var normalState = this._normalState;
  6085. if (!normalState) {
  6086. normalState = this._normalState = {};
  6087. }
  6088. if (toState.textConfig && !normalState.textConfig) {
  6089. normalState.textConfig = this.textConfig;
  6090. }
  6091. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  6092. };
  6093. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6094. for (var i = 0; i < primaryKeys.length; i++) {
  6095. var key = primaryKeys[i];
  6096. if (toState[key] != null && !(key in normalState)) {
  6097. normalState[key] = this[key];
  6098. }
  6099. }
  6100. };
  6101. Element.prototype.hasState = function () {
  6102. return this.currentStates.length > 0;
  6103. };
  6104. Element.prototype.getState = function (name) {
  6105. return this.states[name];
  6106. };
  6107. Element.prototype.ensureState = function (name) {
  6108. var states = this.states;
  6109. if (!states[name]) {
  6110. states[name] = {};
  6111. }
  6112. return states[name];
  6113. };
  6114. Element.prototype.clearStates = function (noAnimation) {
  6115. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6116. };
  6117. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6118. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6119. var hasStates = this.hasState();
  6120. if (!hasStates && toNormalState) {
  6121. return;
  6122. }
  6123. var currentStates = this.currentStates;
  6124. var animationCfg = this.stateTransition;
  6125. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6126. return;
  6127. }
  6128. var state;
  6129. if (this.stateProxy && !toNormalState) {
  6130. state = this.stateProxy(stateName);
  6131. }
  6132. if (!state) {
  6133. state = (this.states && this.states[stateName]);
  6134. }
  6135. if (!state && !toNormalState) {
  6136. logError("State " + stateName + " not exists.");
  6137. return;
  6138. }
  6139. if (!toNormalState) {
  6140. this.saveCurrentToNormalState(state);
  6141. }
  6142. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6143. if (useHoverLayer) {
  6144. this._toggleHoverLayerFlag(true);
  6145. }
  6146. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6147. var textContent = this._textContent;
  6148. var textGuide = this._textGuide;
  6149. if (textContent) {
  6150. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6151. }
  6152. if (textGuide) {
  6153. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6154. }
  6155. if (toNormalState) {
  6156. this.currentStates = [];
  6157. this._normalState = {};
  6158. }
  6159. else {
  6160. if (!keepCurrentStates) {
  6161. this.currentStates = [stateName];
  6162. }
  6163. else {
  6164. this.currentStates.push(stateName);
  6165. }
  6166. }
  6167. this._updateAnimationTargets();
  6168. this.markRedraw();
  6169. if (!useHoverLayer && this.__inHover) {
  6170. this._toggleHoverLayerFlag(false);
  6171. this.__dirty &= ~REDRAW_BIT;
  6172. }
  6173. return state;
  6174. };
  6175. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6176. if (!states.length) {
  6177. this.clearStates();
  6178. }
  6179. else {
  6180. var stateObjects = [];
  6181. var currentStates = this.currentStates;
  6182. var len = states.length;
  6183. var notChange = len === currentStates.length;
  6184. if (notChange) {
  6185. for (var i = 0; i < len; i++) {
  6186. if (states[i] !== currentStates[i]) {
  6187. notChange = false;
  6188. break;
  6189. }
  6190. }
  6191. }
  6192. if (notChange) {
  6193. return;
  6194. }
  6195. for (var i = 0; i < len; i++) {
  6196. var stateName = states[i];
  6197. var stateObj = void 0;
  6198. if (this.stateProxy) {
  6199. stateObj = this.stateProxy(stateName, states);
  6200. }
  6201. if (!stateObj) {
  6202. stateObj = this.states[stateName];
  6203. }
  6204. if (stateObj) {
  6205. stateObjects.push(stateObj);
  6206. }
  6207. }
  6208. var lastStateObj = stateObjects[len - 1];
  6209. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6210. if (useHoverLayer) {
  6211. this._toggleHoverLayerFlag(true);
  6212. }
  6213. var mergedState = this._mergeStates(stateObjects);
  6214. var animationCfg = this.stateTransition;
  6215. this.saveCurrentToNormalState(mergedState);
  6216. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6217. var textContent = this._textContent;
  6218. var textGuide = this._textGuide;
  6219. if (textContent) {
  6220. textContent.useStates(states, noAnimation, useHoverLayer);
  6221. }
  6222. if (textGuide) {
  6223. textGuide.useStates(states, noAnimation, useHoverLayer);
  6224. }
  6225. this._updateAnimationTargets();
  6226. this.currentStates = states.slice();
  6227. this.markRedraw();
  6228. if (!useHoverLayer && this.__inHover) {
  6229. this._toggleHoverLayerFlag(false);
  6230. this.__dirty &= ~REDRAW_BIT;
  6231. }
  6232. }
  6233. };
  6234. Element.prototype.isSilent = function () {
  6235. var el = this;
  6236. while (el) {
  6237. if (el.silent) {
  6238. return true;
  6239. }
  6240. var hostEl = el.__hostTarget;
  6241. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  6242. }
  6243. return false;
  6244. };
  6245. Element.prototype._updateAnimationTargets = function () {
  6246. for (var i = 0; i < this.animators.length; i++) {
  6247. var animator = this.animators[i];
  6248. if (animator.targetName) {
  6249. animator.changeTarget(this[animator.targetName]);
  6250. }
  6251. }
  6252. };
  6253. Element.prototype.removeState = function (state) {
  6254. var idx = indexOf(this.currentStates, state);
  6255. if (idx >= 0) {
  6256. var currentStates = this.currentStates.slice();
  6257. currentStates.splice(idx, 1);
  6258. this.useStates(currentStates);
  6259. }
  6260. };
  6261. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6262. var currentStates = this.currentStates.slice();
  6263. var idx = indexOf(currentStates, oldState);
  6264. var newStateExists = indexOf(currentStates, newState) >= 0;
  6265. if (idx >= 0) {
  6266. if (!newStateExists) {
  6267. currentStates[idx] = newState;
  6268. }
  6269. else {
  6270. currentStates.splice(idx, 1);
  6271. }
  6272. }
  6273. else if (forceAdd && !newStateExists) {
  6274. currentStates.push(newState);
  6275. }
  6276. this.useStates(currentStates);
  6277. };
  6278. Element.prototype.toggleState = function (state, enable) {
  6279. if (enable) {
  6280. this.useState(state, true);
  6281. }
  6282. else {
  6283. this.removeState(state);
  6284. }
  6285. };
  6286. Element.prototype._mergeStates = function (states) {
  6287. var mergedState = {};
  6288. var mergedTextConfig;
  6289. for (var i = 0; i < states.length; i++) {
  6290. var state = states[i];
  6291. extend(mergedState, state);
  6292. if (state.textConfig) {
  6293. mergedTextConfig = mergedTextConfig || {};
  6294. extend(mergedTextConfig, state.textConfig);
  6295. }
  6296. }
  6297. if (mergedTextConfig) {
  6298. mergedState.textConfig = mergedTextConfig;
  6299. }
  6300. return mergedState;
  6301. };
  6302. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6303. var needsRestoreToNormal = !(state && keepCurrentStates);
  6304. if (state && state.textConfig) {
  6305. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6306. extend(this.textConfig, state.textConfig);
  6307. }
  6308. else if (needsRestoreToNormal) {
  6309. if (normalState.textConfig) {
  6310. this.textConfig = normalState.textConfig;
  6311. }
  6312. }
  6313. var transitionTarget = {};
  6314. var hasTransition = false;
  6315. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6316. var key = PRIMARY_STATES_KEYS[i];
  6317. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6318. if (state && state[key] != null) {
  6319. if (propNeedsTransition) {
  6320. hasTransition = true;
  6321. transitionTarget[key] = state[key];
  6322. }
  6323. else {
  6324. this[key] = state[key];
  6325. }
  6326. }
  6327. else if (needsRestoreToNormal) {
  6328. if (normalState[key] != null) {
  6329. if (propNeedsTransition) {
  6330. hasTransition = true;
  6331. transitionTarget[key] = normalState[key];
  6332. }
  6333. else {
  6334. this[key] = normalState[key];
  6335. }
  6336. }
  6337. }
  6338. }
  6339. if (!transition) {
  6340. for (var i = 0; i < this.animators.length; i++) {
  6341. var animator = this.animators[i];
  6342. var targetName = animator.targetName;
  6343. if (!animator.getLoop()) {
  6344. animator.__changeFinalValue(targetName
  6345. ? (state || normalState)[targetName]
  6346. : (state || normalState));
  6347. }
  6348. }
  6349. }
  6350. if (hasTransition) {
  6351. this._transitionState(stateName, transitionTarget, animationCfg);
  6352. }
  6353. };
  6354. Element.prototype._attachComponent = function (componentEl) {
  6355. if (componentEl.__zr && !componentEl.__hostTarget) {
  6356. if ("development" !== 'production') {
  6357. throw new Error('Text element has been added to zrender.');
  6358. }
  6359. return;
  6360. }
  6361. if (componentEl === this) {
  6362. if ("development" !== 'production') {
  6363. throw new Error('Recursive component attachment.');
  6364. }
  6365. return;
  6366. }
  6367. var zr = this.__zr;
  6368. if (zr) {
  6369. componentEl.addSelfToZr(zr);
  6370. }
  6371. componentEl.__zr = zr;
  6372. componentEl.__hostTarget = this;
  6373. };
  6374. Element.prototype._detachComponent = function (componentEl) {
  6375. if (componentEl.__zr) {
  6376. componentEl.removeSelfFromZr(componentEl.__zr);
  6377. }
  6378. componentEl.__zr = null;
  6379. componentEl.__hostTarget = null;
  6380. };
  6381. Element.prototype.getClipPath = function () {
  6382. return this._clipPath;
  6383. };
  6384. Element.prototype.setClipPath = function (clipPath) {
  6385. if (this._clipPath && this._clipPath !== clipPath) {
  6386. this.removeClipPath();
  6387. }
  6388. this._attachComponent(clipPath);
  6389. this._clipPath = clipPath;
  6390. this.markRedraw();
  6391. };
  6392. Element.prototype.removeClipPath = function () {
  6393. var clipPath = this._clipPath;
  6394. if (clipPath) {
  6395. this._detachComponent(clipPath);
  6396. this._clipPath = null;
  6397. this.markRedraw();
  6398. }
  6399. };
  6400. Element.prototype.getTextContent = function () {
  6401. return this._textContent;
  6402. };
  6403. Element.prototype.setTextContent = function (textEl) {
  6404. var previousTextContent = this._textContent;
  6405. if (previousTextContent === textEl) {
  6406. return;
  6407. }
  6408. if (previousTextContent && previousTextContent !== textEl) {
  6409. this.removeTextContent();
  6410. }
  6411. if ("development" !== 'production') {
  6412. if (textEl.__zr && !textEl.__hostTarget) {
  6413. throw new Error('Text element has been added to zrender.');
  6414. }
  6415. }
  6416. textEl.innerTransformable = new Transformable();
  6417. this._attachComponent(textEl);
  6418. this._textContent = textEl;
  6419. this.markRedraw();
  6420. };
  6421. Element.prototype.setTextConfig = function (cfg) {
  6422. if (!this.textConfig) {
  6423. this.textConfig = {};
  6424. }
  6425. extend(this.textConfig, cfg);
  6426. this.markRedraw();
  6427. };
  6428. Element.prototype.removeTextConfig = function () {
  6429. this.textConfig = null;
  6430. this.markRedraw();
  6431. };
  6432. Element.prototype.removeTextContent = function () {
  6433. var textEl = this._textContent;
  6434. if (textEl) {
  6435. textEl.innerTransformable = null;
  6436. this._detachComponent(textEl);
  6437. this._textContent = null;
  6438. this._innerTextDefaultStyle = null;
  6439. this.markRedraw();
  6440. }
  6441. };
  6442. Element.prototype.getTextGuideLine = function () {
  6443. return this._textGuide;
  6444. };
  6445. Element.prototype.setTextGuideLine = function (guideLine) {
  6446. if (this._textGuide && this._textGuide !== guideLine) {
  6447. this.removeTextGuideLine();
  6448. }
  6449. this._attachComponent(guideLine);
  6450. this._textGuide = guideLine;
  6451. this.markRedraw();
  6452. };
  6453. Element.prototype.removeTextGuideLine = function () {
  6454. var textGuide = this._textGuide;
  6455. if (textGuide) {
  6456. this._detachComponent(textGuide);
  6457. this._textGuide = null;
  6458. this.markRedraw();
  6459. }
  6460. };
  6461. Element.prototype.markRedraw = function () {
  6462. this.__dirty |= REDRAW_BIT;
  6463. var zr = this.__zr;
  6464. if (zr) {
  6465. if (this.__inHover) {
  6466. zr.refreshHover();
  6467. }
  6468. else {
  6469. zr.refresh();
  6470. }
  6471. }
  6472. if (this.__hostTarget) {
  6473. this.__hostTarget.markRedraw();
  6474. }
  6475. };
  6476. Element.prototype.dirty = function () {
  6477. this.markRedraw();
  6478. };
  6479. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6480. this.__inHover = inHover;
  6481. var textContent = this._textContent;
  6482. var textGuide = this._textGuide;
  6483. if (textContent) {
  6484. textContent.__inHover = inHover;
  6485. }
  6486. if (textGuide) {
  6487. textGuide.__inHover = inHover;
  6488. }
  6489. };
  6490. Element.prototype.addSelfToZr = function (zr) {
  6491. if (this.__zr === zr) {
  6492. return;
  6493. }
  6494. this.__zr = zr;
  6495. var animators = this.animators;
  6496. if (animators) {
  6497. for (var i = 0; i < animators.length; i++) {
  6498. zr.animation.addAnimator(animators[i]);
  6499. }
  6500. }
  6501. if (this._clipPath) {
  6502. this._clipPath.addSelfToZr(zr);
  6503. }
  6504. if (this._textContent) {
  6505. this._textContent.addSelfToZr(zr);
  6506. }
  6507. if (this._textGuide) {
  6508. this._textGuide.addSelfToZr(zr);
  6509. }
  6510. };
  6511. Element.prototype.removeSelfFromZr = function (zr) {
  6512. if (!this.__zr) {
  6513. return;
  6514. }
  6515. this.__zr = null;
  6516. var animators = this.animators;
  6517. if (animators) {
  6518. for (var i = 0; i < animators.length; i++) {
  6519. zr.animation.removeAnimator(animators[i]);
  6520. }
  6521. }
  6522. if (this._clipPath) {
  6523. this._clipPath.removeSelfFromZr(zr);
  6524. }
  6525. if (this._textContent) {
  6526. this._textContent.removeSelfFromZr(zr);
  6527. }
  6528. if (this._textGuide) {
  6529. this._textGuide.removeSelfFromZr(zr);
  6530. }
  6531. };
  6532. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6533. var target = key ? this[key] : this;
  6534. if ("development" !== 'production') {
  6535. if (!target) {
  6536. logError('Property "'
  6537. + key
  6538. + '" is not existed in element '
  6539. + this.id);
  6540. return;
  6541. }
  6542. }
  6543. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6544. key && (animator.targetName = key);
  6545. this.addAnimator(animator, key);
  6546. return animator;
  6547. };
  6548. Element.prototype.addAnimator = function (animator, key) {
  6549. var zr = this.__zr;
  6550. var el = this;
  6551. animator.during(function () {
  6552. el.updateDuringAnimation(key);
  6553. }).done(function () {
  6554. var animators = el.animators;
  6555. var idx = indexOf(animators, animator);
  6556. if (idx >= 0) {
  6557. animators.splice(idx, 1);
  6558. }
  6559. });
  6560. this.animators.push(animator);
  6561. if (zr) {
  6562. zr.animation.addAnimator(animator);
  6563. }
  6564. zr && zr.wakeUp();
  6565. };
  6566. Element.prototype.updateDuringAnimation = function (key) {
  6567. this.markRedraw();
  6568. };
  6569. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6570. var animators = this.animators;
  6571. var len = animators.length;
  6572. var leftAnimators = [];
  6573. for (var i = 0; i < len; i++) {
  6574. var animator = animators[i];
  6575. if (!scope || scope === animator.scope) {
  6576. animator.stop(forwardToLast);
  6577. }
  6578. else {
  6579. leftAnimators.push(animator);
  6580. }
  6581. }
  6582. this.animators = leftAnimators;
  6583. return this;
  6584. };
  6585. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6586. animateTo(this, target, cfg, animationProps);
  6587. };
  6588. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6589. animateTo(this, target, cfg, animationProps, true);
  6590. };
  6591. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6592. var animators = animateTo(this, target, cfg, animationProps);
  6593. for (var i = 0; i < animators.length; i++) {
  6594. animators[i].__fromStateTransition = stateName;
  6595. }
  6596. };
  6597. Element.prototype.getBoundingRect = function () {
  6598. return null;
  6599. };
  6600. Element.prototype.getPaintRect = function () {
  6601. return null;
  6602. };
  6603. Element.initDefaultProps = (function () {
  6604. var elProto = Element.prototype;
  6605. elProto.type = 'element';
  6606. elProto.name = '';
  6607. elProto.ignore =
  6608. elProto.silent =
  6609. elProto.ignoreHostSilent =
  6610. elProto.isGroup =
  6611. elProto.draggable =
  6612. elProto.dragging =
  6613. elProto.ignoreClip =
  6614. elProto.__inHover = false;
  6615. elProto.__dirty = REDRAW_BIT;
  6616. var logs = {};
  6617. function logDeprecatedError(key, xKey, yKey) {
  6618. if (!logs[key + xKey + yKey]) {
  6619. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6620. logs[key + xKey + yKey] = true;
  6621. }
  6622. }
  6623. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6624. Object.defineProperty(elProto, key, {
  6625. get: function () {
  6626. if ("development" !== 'production') {
  6627. logDeprecatedError(key, xKey, yKey);
  6628. }
  6629. if (!this[privateKey]) {
  6630. var pos = this[privateKey] = [];
  6631. enhanceArray(this, pos);
  6632. }
  6633. return this[privateKey];
  6634. },
  6635. set: function (pos) {
  6636. if ("development" !== 'production') {
  6637. logDeprecatedError(key, xKey, yKey);
  6638. }
  6639. this[xKey] = pos[0];
  6640. this[yKey] = pos[1];
  6641. this[privateKey] = pos;
  6642. enhanceArray(this, pos);
  6643. }
  6644. });
  6645. function enhanceArray(self, pos) {
  6646. Object.defineProperty(pos, 0, {
  6647. get: function () {
  6648. return self[xKey];
  6649. },
  6650. set: function (val) {
  6651. self[xKey] = val;
  6652. }
  6653. });
  6654. Object.defineProperty(pos, 1, {
  6655. get: function () {
  6656. return self[yKey];
  6657. },
  6658. set: function (val) {
  6659. self[yKey] = val;
  6660. }
  6661. });
  6662. }
  6663. }
  6664. if (Object.defineProperty) {
  6665. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6666. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6667. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6668. }
  6669. })();
  6670. return Element;
  6671. }());
  6672. mixin(Element, Eventful);
  6673. mixin(Element, Transformable);
  6674. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6675. cfg = cfg || {};
  6676. var animators = [];
  6677. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6678. var finishCount = animators.length;
  6679. var doneHappened = false;
  6680. var cfgDone = cfg.done;
  6681. var cfgAborted = cfg.aborted;
  6682. var doneCb = function () {
  6683. doneHappened = true;
  6684. finishCount--;
  6685. if (finishCount <= 0) {
  6686. doneHappened
  6687. ? (cfgDone && cfgDone())
  6688. : (cfgAborted && cfgAborted());
  6689. }
  6690. };
  6691. var abortedCb = function () {
  6692. finishCount--;
  6693. if (finishCount <= 0) {
  6694. doneHappened
  6695. ? (cfgDone && cfgDone())
  6696. : (cfgAborted && cfgAborted());
  6697. }
  6698. };
  6699. if (!finishCount) {
  6700. cfgDone && cfgDone();
  6701. }
  6702. if (animators.length > 0 && cfg.during) {
  6703. animators[0].during(function (target, percent) {
  6704. cfg.during(percent);
  6705. });
  6706. }
  6707. for (var i = 0; i < animators.length; i++) {
  6708. var animator = animators[i];
  6709. if (doneCb) {
  6710. animator.done(doneCb);
  6711. }
  6712. if (abortedCb) {
  6713. animator.aborted(abortedCb);
  6714. }
  6715. if (cfg.force) {
  6716. animator.duration(cfg.duration);
  6717. }
  6718. animator.start(cfg.easing);
  6719. }
  6720. return animators;
  6721. }
  6722. function copyArrShallow(source, target, len) {
  6723. for (var i = 0; i < len; i++) {
  6724. source[i] = target[i];
  6725. }
  6726. }
  6727. function is2DArray(value) {
  6728. return isArrayLike(value[0]);
  6729. }
  6730. function copyValue(target, source, key) {
  6731. if (isArrayLike(source[key])) {
  6732. if (!isArrayLike(target[key])) {
  6733. target[key] = [];
  6734. }
  6735. if (isTypedArray(source[key])) {
  6736. var len = source[key].length;
  6737. if (target[key].length !== len) {
  6738. target[key] = new (source[key].constructor)(len);
  6739. copyArrShallow(target[key], source[key], len);
  6740. }
  6741. }
  6742. else {
  6743. var sourceArr = source[key];
  6744. var targetArr = target[key];
  6745. var len0 = sourceArr.length;
  6746. if (is2DArray(sourceArr)) {
  6747. var len1 = sourceArr[0].length;
  6748. for (var i = 0; i < len0; i++) {
  6749. if (!targetArr[i]) {
  6750. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6751. }
  6752. else {
  6753. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6754. }
  6755. }
  6756. }
  6757. else {
  6758. copyArrShallow(targetArr, sourceArr, len0);
  6759. }
  6760. targetArr.length = sourceArr.length;
  6761. }
  6762. }
  6763. else {
  6764. target[key] = source[key];
  6765. }
  6766. }
  6767. function isValueSame(val1, val2) {
  6768. return val1 === val2
  6769. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6770. }
  6771. function is1DArraySame(arr0, arr1) {
  6772. var len = arr0.length;
  6773. if (len !== arr1.length) {
  6774. return false;
  6775. }
  6776. for (var i = 0; i < len; i++) {
  6777. if (arr0[i] !== arr1[i]) {
  6778. return false;
  6779. }
  6780. }
  6781. return true;
  6782. }
  6783. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6784. var targetKeys = keys(target);
  6785. var duration = cfg.duration;
  6786. var delay = cfg.delay;
  6787. var additive = cfg.additive;
  6788. var setToFinal = cfg.setToFinal;
  6789. var animateAll = !isObject(animationProps);
  6790. var existsAnimators = animatable.animators;
  6791. var animationKeys = [];
  6792. for (var k = 0; k < targetKeys.length; k++) {
  6793. var innerKey = targetKeys[k];
  6794. var targetVal = target[innerKey];
  6795. if (targetVal != null && animateObj[innerKey] != null
  6796. && (animateAll || animationProps[innerKey])) {
  6797. if (isObject(targetVal)
  6798. && !isArrayLike(targetVal)
  6799. && !isGradientObject(targetVal)) {
  6800. if (topKey) {
  6801. if (!reverse) {
  6802. animateObj[innerKey] = targetVal;
  6803. animatable.updateDuringAnimation(topKey);
  6804. }
  6805. continue;
  6806. }
  6807. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6808. }
  6809. else {
  6810. animationKeys.push(innerKey);
  6811. }
  6812. }
  6813. else if (!reverse) {
  6814. animateObj[innerKey] = targetVal;
  6815. animatable.updateDuringAnimation(topKey);
  6816. animationKeys.push(innerKey);
  6817. }
  6818. }
  6819. var keyLen = animationKeys.length;
  6820. if (!additive && keyLen) {
  6821. for (var i = 0; i < existsAnimators.length; i++) {
  6822. var animator = existsAnimators[i];
  6823. if (animator.targetName === topKey) {
  6824. var allAborted = animator.stopTracks(animationKeys);
  6825. if (allAborted) {
  6826. var idx = indexOf(existsAnimators, animator);
  6827. existsAnimators.splice(idx, 1);
  6828. }
  6829. }
  6830. }
  6831. }
  6832. if (!cfg.force) {
  6833. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6834. keyLen = animationKeys.length;
  6835. }
  6836. if (keyLen > 0
  6837. || (cfg.force && !animators.length)) {
  6838. var revertedSource = void 0;
  6839. var reversedTarget = void 0;
  6840. var sourceClone = void 0;
  6841. if (reverse) {
  6842. reversedTarget = {};
  6843. if (setToFinal) {
  6844. revertedSource = {};
  6845. }
  6846. for (var i = 0; i < keyLen; i++) {
  6847. var innerKey = animationKeys[i];
  6848. reversedTarget[innerKey] = animateObj[innerKey];
  6849. if (setToFinal) {
  6850. revertedSource[innerKey] = target[innerKey];
  6851. }
  6852. else {
  6853. animateObj[innerKey] = target[innerKey];
  6854. }
  6855. }
  6856. }
  6857. else if (setToFinal) {
  6858. sourceClone = {};
  6859. for (var i = 0; i < keyLen; i++) {
  6860. var innerKey = animationKeys[i];
  6861. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6862. copyValue(animateObj, target, innerKey);
  6863. }
  6864. }
  6865. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6866. animator.targetName = topKey;
  6867. if (cfg.scope) {
  6868. animator.scope = cfg.scope;
  6869. }
  6870. if (setToFinal && revertedSource) {
  6871. animator.whenWithKeys(0, revertedSource, animationKeys);
  6872. }
  6873. if (sourceClone) {
  6874. animator.whenWithKeys(0, sourceClone, animationKeys);
  6875. }
  6876. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6877. animatable.addAnimator(animator, topKey);
  6878. animators.push(animator);
  6879. }
  6880. }
  6881. var Group = (function (_super) {
  6882. __extends(Group, _super);
  6883. function Group(opts) {
  6884. var _this = _super.call(this) || this;
  6885. _this.isGroup = true;
  6886. _this._children = [];
  6887. _this.attr(opts);
  6888. return _this;
  6889. }
  6890. Group.prototype.childrenRef = function () {
  6891. return this._children;
  6892. };
  6893. Group.prototype.children = function () {
  6894. return this._children.slice();
  6895. };
  6896. Group.prototype.childAt = function (idx) {
  6897. return this._children[idx];
  6898. };
  6899. Group.prototype.childOfName = function (name) {
  6900. var children = this._children;
  6901. for (var i = 0; i < children.length; i++) {
  6902. if (children[i].name === name) {
  6903. return children[i];
  6904. }
  6905. }
  6906. };
  6907. Group.prototype.childCount = function () {
  6908. return this._children.length;
  6909. };
  6910. Group.prototype.add = function (child) {
  6911. if (child) {
  6912. if (child !== this && child.parent !== this) {
  6913. this._children.push(child);
  6914. this._doAdd(child);
  6915. }
  6916. if ("development" !== 'production') {
  6917. if (child.__hostTarget) {
  6918. throw 'This elemenet has been used as an attachment';
  6919. }
  6920. }
  6921. }
  6922. return this;
  6923. };
  6924. Group.prototype.addBefore = function (child, nextSibling) {
  6925. if (child && child !== this && child.parent !== this
  6926. && nextSibling && nextSibling.parent === this) {
  6927. var children = this._children;
  6928. var idx = children.indexOf(nextSibling);
  6929. if (idx >= 0) {
  6930. children.splice(idx, 0, child);
  6931. this._doAdd(child);
  6932. }
  6933. }
  6934. return this;
  6935. };
  6936. Group.prototype.replace = function (oldChild, newChild) {
  6937. var idx = indexOf(this._children, oldChild);
  6938. if (idx >= 0) {
  6939. this.replaceAt(newChild, idx);
  6940. }
  6941. return this;
  6942. };
  6943. Group.prototype.replaceAt = function (child, index) {
  6944. var children = this._children;
  6945. var old = children[index];
  6946. if (child && child !== this && child.parent !== this && child !== old) {
  6947. children[index] = child;
  6948. old.parent = null;
  6949. var zr = this.__zr;
  6950. if (zr) {
  6951. old.removeSelfFromZr(zr);
  6952. }
  6953. this._doAdd(child);
  6954. }
  6955. return this;
  6956. };
  6957. Group.prototype._doAdd = function (child) {
  6958. if (child.parent) {
  6959. child.parent.remove(child);
  6960. }
  6961. child.parent = this;
  6962. var zr = this.__zr;
  6963. if (zr && zr !== child.__zr) {
  6964. child.addSelfToZr(zr);
  6965. }
  6966. zr && zr.refresh();
  6967. };
  6968. Group.prototype.remove = function (child) {
  6969. var zr = this.__zr;
  6970. var children = this._children;
  6971. var idx = indexOf(children, child);
  6972. if (idx < 0) {
  6973. return this;
  6974. }
  6975. children.splice(idx, 1);
  6976. child.parent = null;
  6977. if (zr) {
  6978. child.removeSelfFromZr(zr);
  6979. }
  6980. zr && zr.refresh();
  6981. return this;
  6982. };
  6983. Group.prototype.removeAll = function () {
  6984. var children = this._children;
  6985. var zr = this.__zr;
  6986. for (var i = 0; i < children.length; i++) {
  6987. var child = children[i];
  6988. if (zr) {
  6989. child.removeSelfFromZr(zr);
  6990. }
  6991. child.parent = null;
  6992. }
  6993. children.length = 0;
  6994. return this;
  6995. };
  6996. Group.prototype.eachChild = function (cb, context) {
  6997. var children = this._children;
  6998. for (var i = 0; i < children.length; i++) {
  6999. var child = children[i];
  7000. cb.call(context, child, i);
  7001. }
  7002. return this;
  7003. };
  7004. Group.prototype.traverse = function (cb, context) {
  7005. for (var i = 0; i < this._children.length; i++) {
  7006. var child = this._children[i];
  7007. var stopped = cb.call(context, child);
  7008. if (child.isGroup && !stopped) {
  7009. child.traverse(cb, context);
  7010. }
  7011. }
  7012. return this;
  7013. };
  7014. Group.prototype.addSelfToZr = function (zr) {
  7015. _super.prototype.addSelfToZr.call(this, zr);
  7016. for (var i = 0; i < this._children.length; i++) {
  7017. var child = this._children[i];
  7018. child.addSelfToZr(zr);
  7019. }
  7020. };
  7021. Group.prototype.removeSelfFromZr = function (zr) {
  7022. _super.prototype.removeSelfFromZr.call(this, zr);
  7023. for (var i = 0; i < this._children.length; i++) {
  7024. var child = this._children[i];
  7025. child.removeSelfFromZr(zr);
  7026. }
  7027. };
  7028. Group.prototype.getBoundingRect = function (includeChildren) {
  7029. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7030. var children = includeChildren || this._children;
  7031. var tmpMat = [];
  7032. var rect = null;
  7033. for (var i = 0; i < children.length; i++) {
  7034. var child = children[i];
  7035. if (child.ignore || child.invisible) {
  7036. continue;
  7037. }
  7038. var childRect = child.getBoundingRect();
  7039. var transform = child.getLocalTransform(tmpMat);
  7040. if (transform) {
  7041. BoundingRect.applyTransform(tmpRect, childRect, transform);
  7042. rect = rect || tmpRect.clone();
  7043. rect.union(tmpRect);
  7044. }
  7045. else {
  7046. rect = rect || childRect.clone();
  7047. rect.union(childRect);
  7048. }
  7049. }
  7050. return rect || tmpRect;
  7051. };
  7052. return Group;
  7053. }(Element));
  7054. Group.prototype.type = 'group';
  7055. /*!
  7056. * ZRender, a high performance 2d drawing library.
  7057. *
  7058. * Copyright (c) 2013, Baidu Inc.
  7059. * All rights reserved.
  7060. *
  7061. * LICENSE
  7062. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  7063. */
  7064. var painterCtors = {};
  7065. var instances = {};
  7066. function delInstance(id) {
  7067. delete instances[id];
  7068. }
  7069. function isDarkMode(backgroundColor) {
  7070. if (!backgroundColor) {
  7071. return false;
  7072. }
  7073. if (typeof backgroundColor === 'string') {
  7074. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  7075. }
  7076. else if (backgroundColor.colorStops) {
  7077. var colorStops = backgroundColor.colorStops;
  7078. var totalLum = 0;
  7079. var len = colorStops.length;
  7080. for (var i = 0; i < len; i++) {
  7081. totalLum += lum(colorStops[i].color, 1);
  7082. }
  7083. totalLum /= len;
  7084. return totalLum < DARK_MODE_THRESHOLD;
  7085. }
  7086. return false;
  7087. }
  7088. var ZRender = (function () {
  7089. function ZRender(id, dom, opts) {
  7090. var _this = this;
  7091. this._sleepAfterStill = 10;
  7092. this._stillFrameAccum = 0;
  7093. this._needsRefresh = true;
  7094. this._needsRefreshHover = true;
  7095. this._darkMode = false;
  7096. opts = opts || {};
  7097. this.dom = dom;
  7098. this.id = id;
  7099. var storage = new Storage();
  7100. var rendererType = opts.renderer || 'canvas';
  7101. if (!painterCtors[rendererType]) {
  7102. rendererType = keys(painterCtors)[0];
  7103. }
  7104. if ("development" !== 'production') {
  7105. if (!painterCtors[rendererType]) {
  7106. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  7107. }
  7108. }
  7109. opts.useDirtyRect = opts.useDirtyRect == null
  7110. ? false
  7111. : opts.useDirtyRect;
  7112. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7113. var ssrMode = opts.ssr || painter.ssrOnly;
  7114. this.storage = storage;
  7115. this.painter = painter;
  7116. var handlerProxy = (!env.node && !env.worker && !ssrMode)
  7117. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7118. : null;
  7119. var useCoarsePointer = opts.useCoarsePointer;
  7120. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7121. ? env.touchEventsSupported
  7122. : !!useCoarsePointer;
  7123. var defaultPointerSize = 44;
  7124. var pointerSize;
  7125. if (usePointerSize) {
  7126. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7127. }
  7128. this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize);
  7129. this.animation = new Animation({
  7130. stage: {
  7131. update: ssrMode ? null : function () { return _this._flush(true); }
  7132. }
  7133. });
  7134. if (!ssrMode) {
  7135. this.animation.start();
  7136. }
  7137. }
  7138. ZRender.prototype.add = function (el) {
  7139. if (this._disposed || !el) {
  7140. return;
  7141. }
  7142. this.storage.addRoot(el);
  7143. el.addSelfToZr(this);
  7144. this.refresh();
  7145. };
  7146. ZRender.prototype.remove = function (el) {
  7147. if (this._disposed || !el) {
  7148. return;
  7149. }
  7150. this.storage.delRoot(el);
  7151. el.removeSelfFromZr(this);
  7152. this.refresh();
  7153. };
  7154. ZRender.prototype.configLayer = function (zLevel, config) {
  7155. if (this._disposed) {
  7156. return;
  7157. }
  7158. if (this.painter.configLayer) {
  7159. this.painter.configLayer(zLevel, config);
  7160. }
  7161. this.refresh();
  7162. };
  7163. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7164. if (this._disposed) {
  7165. return;
  7166. }
  7167. if (this.painter.setBackgroundColor) {
  7168. this.painter.setBackgroundColor(backgroundColor);
  7169. }
  7170. this.refresh();
  7171. this._backgroundColor = backgroundColor;
  7172. this._darkMode = isDarkMode(backgroundColor);
  7173. };
  7174. ZRender.prototype.getBackgroundColor = function () {
  7175. return this._backgroundColor;
  7176. };
  7177. ZRender.prototype.setDarkMode = function (darkMode) {
  7178. this._darkMode = darkMode;
  7179. };
  7180. ZRender.prototype.isDarkMode = function () {
  7181. return this._darkMode;
  7182. };
  7183. ZRender.prototype.refreshImmediately = function (fromInside) {
  7184. if (this._disposed) {
  7185. return;
  7186. }
  7187. if (!fromInside) {
  7188. this.animation.update(true);
  7189. }
  7190. this._needsRefresh = false;
  7191. this.painter.refresh();
  7192. this._needsRefresh = false;
  7193. };
  7194. ZRender.prototype.refresh = function () {
  7195. if (this._disposed) {
  7196. return;
  7197. }
  7198. this._needsRefresh = true;
  7199. this.animation.start();
  7200. };
  7201. ZRender.prototype.flush = function () {
  7202. if (this._disposed) {
  7203. return;
  7204. }
  7205. this._flush(false);
  7206. };
  7207. ZRender.prototype._flush = function (fromInside) {
  7208. var triggerRendered;
  7209. var start = getTime();
  7210. if (this._needsRefresh) {
  7211. triggerRendered = true;
  7212. this.refreshImmediately(fromInside);
  7213. }
  7214. if (this._needsRefreshHover) {
  7215. triggerRendered = true;
  7216. this.refreshHoverImmediately();
  7217. }
  7218. var end = getTime();
  7219. if (triggerRendered) {
  7220. this._stillFrameAccum = 0;
  7221. this.trigger('rendered', {
  7222. elapsedTime: end - start
  7223. });
  7224. }
  7225. else if (this._sleepAfterStill > 0) {
  7226. this._stillFrameAccum++;
  7227. if (this._stillFrameAccum > this._sleepAfterStill) {
  7228. this.animation.stop();
  7229. }
  7230. }
  7231. };
  7232. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7233. this._sleepAfterStill = stillFramesCount;
  7234. };
  7235. ZRender.prototype.wakeUp = function () {
  7236. if (this._disposed) {
  7237. return;
  7238. }
  7239. this.animation.start();
  7240. this._stillFrameAccum = 0;
  7241. };
  7242. ZRender.prototype.refreshHover = function () {
  7243. this._needsRefreshHover = true;
  7244. };
  7245. ZRender.prototype.refreshHoverImmediately = function () {
  7246. if (this._disposed) {
  7247. return;
  7248. }
  7249. this._needsRefreshHover = false;
  7250. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7251. this.painter.refreshHover();
  7252. }
  7253. };
  7254. ZRender.prototype.resize = function (opts) {
  7255. if (this._disposed) {
  7256. return;
  7257. }
  7258. opts = opts || {};
  7259. this.painter.resize(opts.width, opts.height);
  7260. this.handler.resize();
  7261. };
  7262. ZRender.prototype.clearAnimation = function () {
  7263. if (this._disposed) {
  7264. return;
  7265. }
  7266. this.animation.clear();
  7267. };
  7268. ZRender.prototype.getWidth = function () {
  7269. if (this._disposed) {
  7270. return;
  7271. }
  7272. return this.painter.getWidth();
  7273. };
  7274. ZRender.prototype.getHeight = function () {
  7275. if (this._disposed) {
  7276. return;
  7277. }
  7278. return this.painter.getHeight();
  7279. };
  7280. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7281. if (this._disposed) {
  7282. return;
  7283. }
  7284. this.handler.setCursorStyle(cursorStyle);
  7285. };
  7286. ZRender.prototype.findHover = function (x, y) {
  7287. if (this._disposed) {
  7288. return;
  7289. }
  7290. return this.handler.findHover(x, y);
  7291. };
  7292. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7293. if (!this._disposed) {
  7294. this.handler.on(eventName, eventHandler, context);
  7295. }
  7296. return this;
  7297. };
  7298. ZRender.prototype.off = function (eventName, eventHandler) {
  7299. if (this._disposed) {
  7300. return;
  7301. }
  7302. this.handler.off(eventName, eventHandler);
  7303. };
  7304. ZRender.prototype.trigger = function (eventName, event) {
  7305. if (this._disposed) {
  7306. return;
  7307. }
  7308. this.handler.trigger(eventName, event);
  7309. };
  7310. ZRender.prototype.clear = function () {
  7311. if (this._disposed) {
  7312. return;
  7313. }
  7314. var roots = this.storage.getRoots();
  7315. for (var i = 0; i < roots.length; i++) {
  7316. if (roots[i] instanceof Group) {
  7317. roots[i].removeSelfFromZr(this);
  7318. }
  7319. }
  7320. this.storage.delAllRoots();
  7321. this.painter.clear();
  7322. };
  7323. ZRender.prototype.dispose = function () {
  7324. if (this._disposed) {
  7325. return;
  7326. }
  7327. this.animation.stop();
  7328. this.clear();
  7329. this.storage.dispose();
  7330. this.painter.dispose();
  7331. this.handler.dispose();
  7332. this.animation =
  7333. this.storage =
  7334. this.painter =
  7335. this.handler = null;
  7336. this._disposed = true;
  7337. delInstance(this.id);
  7338. };
  7339. return ZRender;
  7340. }());
  7341. function init(dom, opts) {
  7342. var zr = new ZRender(guid(), dom, opts);
  7343. instances[zr.id] = zr;
  7344. return zr;
  7345. }
  7346. function dispose(zr) {
  7347. zr.dispose();
  7348. }
  7349. function disposeAll() {
  7350. for (var key in instances) {
  7351. if (instances.hasOwnProperty(key)) {
  7352. instances[key].dispose();
  7353. }
  7354. }
  7355. instances = {};
  7356. }
  7357. function getInstance(id) {
  7358. return instances[id];
  7359. }
  7360. function registerPainter(name, Ctor) {
  7361. painterCtors[name] = Ctor;
  7362. }
  7363. var ssrDataGetter;
  7364. function getElementSSRData(el) {
  7365. if (typeof ssrDataGetter === 'function') {
  7366. return ssrDataGetter(el);
  7367. }
  7368. }
  7369. function registerSSRDataGetter(getter) {
  7370. ssrDataGetter = getter;
  7371. }
  7372. var version = '6.0.0';
  7373. var zrender = /*#__PURE__*/Object.freeze({
  7374. __proto__: null,
  7375. init: init,
  7376. dispose: dispose,
  7377. disposeAll: disposeAll,
  7378. getInstance: getInstance,
  7379. registerPainter: registerPainter,
  7380. getElementSSRData: getElementSSRData,
  7381. registerSSRDataGetter: registerSSRDataGetter,
  7382. version: version
  7383. });
  7384. var RADIAN_EPSILON = 1e-4;
  7385. // Although chrome already enlarge this number to 100 for `toFixed`, but
  7386. // we sill follow the spec for compatibility.
  7387. var ROUND_SUPPORTED_PRECISION_MAX = 20;
  7388. function _trim(str) {
  7389. return str.replace(/^\s+|\s+$/g, '');
  7390. }
  7391. var mathMin$1 = Math.min;
  7392. var mathMax$1 = Math.max;
  7393. var mathAbs$1 = Math.abs;
  7394. /**
  7395. * Linear mapping a value from domain to range
  7396. * @param val
  7397. * @param domain Domain extent domain[0] can be bigger than domain[1]
  7398. * @param range Range extent range[0] can be bigger than range[1]
  7399. * @param clamp Default to be false
  7400. */
  7401. function linearMap(val, domain, range, clamp) {
  7402. var d0 = domain[0];
  7403. var d1 = domain[1];
  7404. var r0 = range[0];
  7405. var r1 = range[1];
  7406. var subDomain = d1 - d0;
  7407. var subRange = r1 - r0;
  7408. if (subDomain === 0) {
  7409. return subRange === 0 ? r0 : (r0 + r1) / 2;
  7410. }
  7411. // Avoid accuracy problem in edge, such as
  7412. // 146.39 - 62.83 === 83.55999999999999.
  7413. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  7414. // It is a little verbose for efficiency considering this method
  7415. // is a hotspot.
  7416. if (clamp) {
  7417. if (subDomain > 0) {
  7418. if (val <= d0) {
  7419. return r0;
  7420. } else if (val >= d1) {
  7421. return r1;
  7422. }
  7423. } else {
  7424. if (val >= d0) {
  7425. return r0;
  7426. } else if (val <= d1) {
  7427. return r1;
  7428. }
  7429. }
  7430. } else {
  7431. if (val === d0) {
  7432. return r0;
  7433. }
  7434. if (val === d1) {
  7435. return r1;
  7436. }
  7437. }
  7438. return (val - d0) / subDomain * subRange + r0;
  7439. }
  7440. /**
  7441. * Preserve the name `parsePercent` for backward compatibility,
  7442. * and it's effectively published as `echarts.number.parsePercent`.
  7443. */
  7444. var parsePercent$1 = parsePositionOption;
  7445. /**
  7446. * @see {parsePositionSizeOption} and also accept a string preset.
  7447. * @see {PositionSizeOption}
  7448. */
  7449. function parsePositionOption(option, percentBase, percentOffset) {
  7450. switch (option) {
  7451. case 'center':
  7452. case 'middle':
  7453. option = '50%';
  7454. break;
  7455. case 'left':
  7456. case 'top':
  7457. option = '0%';
  7458. break;
  7459. case 'right':
  7460. case 'bottom':
  7461. option = '100%';
  7462. break;
  7463. }
  7464. return parsePositionSizeOption(option, percentBase, percentOffset);
  7465. }
  7466. /**
  7467. * Accept number, or numeric stirng (`'123'`), or percentage ('100%'), as x/y/width/height pixel number.
  7468. * If null/undefined or invalid, return NaN.
  7469. * (But allow JS type coercion (`+option`) due to backward compatibility)
  7470. * @see {PositionSizeOption}
  7471. */
  7472. function parsePositionSizeOption(option, percentBase, percentOffset) {
  7473. if (isString(option)) {
  7474. if (_trim(option).match(/%$/)) {
  7475. return parseFloat(option) / 100 * percentBase + (percentOffset || 0);
  7476. }
  7477. return parseFloat(option);
  7478. }
  7479. // Allow flexible input due to backward compatibility.
  7480. return option == null ? NaN : +option;
  7481. }
  7482. function round(x, precision, returnStr) {
  7483. if (precision == null) {
  7484. // FIXME: the default precision should not be provided, since there is no universally adaptable
  7485. // precision. The caller need to input a precision according to the scenarios.
  7486. precision = 10;
  7487. }
  7488. // Avoid range error
  7489. precision = Math.min(Math.max(0, precision), ROUND_SUPPORTED_PRECISION_MAX);
  7490. // PENDING: 1.005.toFixed(2) is '1.00' rather than '1.01'
  7491. x = (+x).toFixed(precision);
  7492. return returnStr ? x : +x;
  7493. }
  7494. /**
  7495. * Inplacd asc sort arr.
  7496. * The input arr will be modified.
  7497. */
  7498. function asc(arr) {
  7499. arr.sort(function (a, b) {
  7500. return a - b;
  7501. });
  7502. return arr;
  7503. }
  7504. /**
  7505. * Get precision.
  7506. */
  7507. function getPrecision(val) {
  7508. val = +val;
  7509. if (isNaN(val)) {
  7510. return 0;
  7511. }
  7512. // It is much faster than methods converting number to string as follows
  7513. // let tmp = val.toString();
  7514. // return tmp.length - 1 - tmp.indexOf('.');
  7515. // especially when precision is low
  7516. // Notice:
  7517. // (1) If the loop count is over about 20, it is slower than `getPrecisionSafe`.
  7518. // (see https://jsbench.me/2vkpcekkvw/1)
  7519. // (2) If the val is less than for example 1e-15, the result may be incorrect.
  7520. // (see test/ut/spec/util/number.test.ts `getPrecision_equal_random`)
  7521. if (val > 1e-14) {
  7522. var e = 1;
  7523. for (var i = 0; i < 15; i++, e *= 10) {
  7524. if (Math.round(val * e) / e === val) {
  7525. return i;
  7526. }
  7527. }
  7528. }
  7529. return getPrecisionSafe(val);
  7530. }
  7531. /**
  7532. * Get precision with slow but safe method
  7533. */
  7534. function getPrecisionSafe(val) {
  7535. // toLowerCase for: '3.4E-12'
  7536. var str = val.toString().toLowerCase();
  7537. // Consider scientific notation: '3.4e-12' '3.4e+12'
  7538. var eIndex = str.indexOf('e');
  7539. var exp = eIndex > 0 ? +str.slice(eIndex + 1) : 0;
  7540. var significandPartLen = eIndex > 0 ? eIndex : str.length;
  7541. var dotIndex = str.indexOf('.');
  7542. var decimalPartLen = dotIndex < 0 ? 0 : significandPartLen - 1 - dotIndex;
  7543. return Math.max(0, decimalPartLen - exp);
  7544. }
  7545. /**
  7546. * Minimal dicernible data precisioin according to a single pixel.
  7547. */
  7548. function getPixelPrecision(dataExtent, pixelExtent) {
  7549. var log = Math.log;
  7550. var LN10 = Math.LN10;
  7551. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  7552. var sizeQuantity = Math.round(log(mathAbs$1(pixelExtent[1] - pixelExtent[0])) / LN10);
  7553. // toFixed() digits argument must be between 0 and 20.
  7554. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  7555. return !isFinite(precision) ? 20 : precision;
  7556. }
  7557. /**
  7558. * Get a data of given precision, assuring the sum of percentages
  7559. * in valueList is 1.
  7560. * The largest remainder method is used.
  7561. * https://en.wikipedia.org/wiki/Largest_remainder_method
  7562. *
  7563. * @param valueList a list of all data
  7564. * @param idx index of the data to be processed in valueList
  7565. * @param precision integer number showing digits of precision
  7566. * @return percent ranging from 0 to 100
  7567. */
  7568. function getPercentWithPrecision(valueList, idx, precision) {
  7569. if (!valueList[idx]) {
  7570. return 0;
  7571. }
  7572. var seats = getPercentSeats(valueList, precision);
  7573. return seats[idx] || 0;
  7574. }
  7575. /**
  7576. * Get a data of given precision, assuring the sum of percentages
  7577. * in valueList is 1.
  7578. * The largest remainder method is used.
  7579. * https://en.wikipedia.org/wiki/Largest_remainder_method
  7580. *
  7581. * @param valueList a list of all data
  7582. * @param precision integer number showing digits of precision
  7583. * @return {Array<number>}
  7584. */
  7585. function getPercentSeats(valueList, precision) {
  7586. var sum = reduce(valueList, function (acc, val) {
  7587. return acc + (isNaN(val) ? 0 : val);
  7588. }, 0);
  7589. if (sum === 0) {
  7590. return [];
  7591. }
  7592. var digits = Math.pow(10, precision);
  7593. var votesPerQuota = map(valueList, function (val) {
  7594. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  7595. });
  7596. var targetSeats = digits * 100;
  7597. var seats = map(votesPerQuota, function (votes) {
  7598. // Assign automatic seats.
  7599. return Math.floor(votes);
  7600. });
  7601. var currentSum = reduce(seats, function (acc, val) {
  7602. return acc + val;
  7603. }, 0);
  7604. var remainder = map(votesPerQuota, function (votes, idx) {
  7605. return votes - seats[idx];
  7606. });
  7607. // Has remainding votes.
  7608. while (currentSum < targetSeats) {
  7609. // Find next largest remainder.
  7610. var max = Number.NEGATIVE_INFINITY;
  7611. var maxId = null;
  7612. for (var i = 0, len = remainder.length; i < len; ++i) {
  7613. if (remainder[i] > max) {
  7614. max = remainder[i];
  7615. maxId = i;
  7616. }
  7617. }
  7618. // Add a vote to max remainder.
  7619. ++seats[maxId];
  7620. remainder[maxId] = 0;
  7621. ++currentSum;
  7622. }
  7623. return map(seats, function (seat) {
  7624. return seat / digits;
  7625. });
  7626. }
  7627. /**
  7628. * Solve the floating point adding problem like 0.1 + 0.2 === 0.30000000000000004
  7629. * See <http://0.30000000000000004.com/>
  7630. */
  7631. function addSafe(val0, val1) {
  7632. var maxPrecision = Math.max(getPrecision(val0), getPrecision(val1));
  7633. // const multiplier = Math.pow(10, maxPrecision);
  7634. // return (Math.round(val0 * multiplier) + Math.round(val1 * multiplier)) / multiplier;
  7635. var sum = val0 + val1;
  7636. // // PENDING: support more?
  7637. return maxPrecision > ROUND_SUPPORTED_PRECISION_MAX ? sum : round(sum, maxPrecision);
  7638. }
  7639. // Number.MAX_SAFE_INTEGER, ie do not support.
  7640. var MAX_SAFE_INTEGER = 9007199254740991;
  7641. /**
  7642. * To 0 - 2 * PI, considering negative radian.
  7643. */
  7644. function remRadian(radian) {
  7645. var pi2 = Math.PI * 2;
  7646. return (radian % pi2 + pi2) % pi2;
  7647. }
  7648. /**
  7649. * @param {type} radian
  7650. * @return {boolean}
  7651. */
  7652. function isRadianAroundZero(val) {
  7653. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  7654. }
  7655. // eslint-disable-next-line
  7656. var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d{1,2})(?::(\d{1,2})(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
  7657. /**
  7658. * @param value valid type: number | string | Date, otherwise return `new Date(NaN)`
  7659. * These values can be accepted:
  7660. * + An instance of Date, represent a time in its own time zone.
  7661. * + Or string in a subset of ISO 8601, only including:
  7662. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  7663. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  7664. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  7665. * all of which will be treated as local time if time zone is not specified
  7666. * (see <https://momentjs.com/>).
  7667. * + Or other string format, including (all of which will be treated as local time):
  7668. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  7669. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  7670. * + a timestamp, which represent a time in UTC.
  7671. * @return date Never be null/undefined. If invalid, return `new Date(NaN)`.
  7672. */
  7673. function parseDate(value) {
  7674. if (value instanceof Date) {
  7675. return value;
  7676. } else if (isString(value)) {
  7677. // Different browsers parse date in different way, so we parse it manually.
  7678. // Some other issues:
  7679. // new Date('1970-01-01') is UTC,
  7680. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  7681. // See issue #3623
  7682. var match = TIME_REG.exec(value);
  7683. if (!match) {
  7684. // return Invalid Date.
  7685. return new Date(NaN);
  7686. }
  7687. // Use local time when no timezone offset is specified.
  7688. if (!match[8]) {
  7689. // match[n] can only be string or undefined.
  7690. // But take care of '12' + 1 => '121'.
  7691. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0);
  7692. }
  7693. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  7694. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  7695. // For example, system timezone is set as "Time Zone: America/Toronto",
  7696. // then these code will get different result:
  7697. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  7698. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  7699. // So we should not use `new Date`, but use `Date.UTC`.
  7700. else {
  7701. var hour = +match[4] || 0;
  7702. if (match[8].toUpperCase() !== 'Z') {
  7703. hour -= +match[8].slice(0, 3);
  7704. }
  7705. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0));
  7706. }
  7707. } else if (value == null) {
  7708. return new Date(NaN);
  7709. }
  7710. return new Date(Math.round(value));
  7711. }
  7712. /**
  7713. * Quantity of a number. e.g. 0.1, 1, 10, 100
  7714. *
  7715. * @param val
  7716. * @return
  7717. */
  7718. function quantity(val) {
  7719. return Math.pow(10, quantityExponent(val));
  7720. }
  7721. /**
  7722. * Exponent of the quantity of a number
  7723. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  7724. *
  7725. * @param val non-negative value
  7726. * @return
  7727. */
  7728. function quantityExponent(val) {
  7729. if (val === 0) {
  7730. return 0;
  7731. }
  7732. var exp = Math.floor(Math.log(val) / Math.LN10);
  7733. /**
  7734. * exp is expected to be the rounded-down result of the base-10 log of val.
  7735. * But due to the precision loss with Math.log(val), we need to restore it
  7736. * using 10^exp to make sure we can get val back from exp. #11249
  7737. */
  7738. if (val / Math.pow(10, exp) >= 10) {
  7739. exp++;
  7740. }
  7741. return exp;
  7742. }
  7743. /**
  7744. * find a “nice” number approximately equal to x. Round the number if round = true,
  7745. * take ceiling if round = false. The primary observation is that the “nicest”
  7746. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  7747. *
  7748. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  7749. *
  7750. * @param val Non-negative value.
  7751. * @param round
  7752. * @return Niced number
  7753. */
  7754. function nice(val, round) {
  7755. var exponent = quantityExponent(val);
  7756. var exp10 = Math.pow(10, exponent);
  7757. var f = val / exp10; // 1 <= f < 10
  7758. var nf;
  7759. if (round) {
  7760. if (f < 1.5) {
  7761. nf = 1;
  7762. } else if (f < 2.5) {
  7763. nf = 2;
  7764. } else if (f < 4) {
  7765. nf = 3;
  7766. } else if (f < 7) {
  7767. nf = 5;
  7768. } else {
  7769. nf = 10;
  7770. }
  7771. } else {
  7772. if (f < 1) {
  7773. nf = 1;
  7774. } else if (f < 2) {
  7775. nf = 2;
  7776. } else if (f < 3) {
  7777. nf = 3;
  7778. } else if (f < 5) {
  7779. nf = 5;
  7780. } else {
  7781. nf = 10;
  7782. }
  7783. }
  7784. val = nf * exp10;
  7785. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  7786. // 20 is the uppper bound of toFixed.
  7787. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  7788. }
  7789. /**
  7790. * This code was copied from "d3.js"
  7791. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  7792. * See the license statement at the head of this file.
  7793. * @param ascArr
  7794. */
  7795. function quantile(ascArr, p) {
  7796. var H = (ascArr.length - 1) * p + 1;
  7797. var h = Math.floor(H);
  7798. var v = +ascArr[h - 1];
  7799. var e = H - h;
  7800. return e ? v + e * (ascArr[h] - v) : v;
  7801. }
  7802. /**
  7803. * Order intervals asc, and split them when overlap.
  7804. * expect(numberUtil.reformIntervals([
  7805. * {interval: [18, 62], close: [1, 1]},
  7806. * {interval: [-Infinity, -70], close: [0, 0]},
  7807. * {interval: [-70, -26], close: [1, 1]},
  7808. * {interval: [-26, 18], close: [1, 1]},
  7809. * {interval: [62, 150], close: [1, 1]},
  7810. * {interval: [106, 150], close: [1, 1]},
  7811. * {interval: [150, Infinity], close: [0, 0]}
  7812. * ])).toEqual([
  7813. * {interval: [-Infinity, -70], close: [0, 0]},
  7814. * {interval: [-70, -26], close: [1, 1]},
  7815. * {interval: [-26, 18], close: [0, 1]},
  7816. * {interval: [18, 62], close: [0, 1]},
  7817. * {interval: [62, 150], close: [0, 1]},
  7818. * {interval: [150, Infinity], close: [0, 0]}
  7819. * ]);
  7820. * @param list, where `close` mean open or close
  7821. * of the interval, and Infinity can be used.
  7822. * @return The origin list, which has been reformed.
  7823. */
  7824. function reformIntervals(list) {
  7825. list.sort(function (a, b) {
  7826. return littleThan(a, b, 0) ? -1 : 1;
  7827. });
  7828. var curr = -Infinity;
  7829. var currClose = 1;
  7830. for (var i = 0; i < list.length;) {
  7831. var interval = list[i].interval;
  7832. var close_1 = list[i].close;
  7833. for (var lg = 0; lg < 2; lg++) {
  7834. if (interval[lg] <= curr) {
  7835. interval[lg] = curr;
  7836. close_1[lg] = !lg ? 1 - currClose : 1;
  7837. }
  7838. curr = interval[lg];
  7839. currClose = close_1[lg];
  7840. }
  7841. if (interval[0] === interval[1] && close_1[0] * close_1[1] !== 1) {
  7842. list.splice(i, 1);
  7843. } else {
  7844. i++;
  7845. }
  7846. }
  7847. return list;
  7848. function littleThan(a, b, lg) {
  7849. return a.interval[lg] < b.interval[lg] || a.interval[lg] === b.interval[lg] && (a.close[lg] - b.close[lg] === (!lg ? 1 : -1) || !lg && littleThan(a, b, 1));
  7850. }
  7851. }
  7852. /**
  7853. * [Numeric is defined as]:
  7854. * `parseFloat(val) == val`
  7855. * For example:
  7856. * numeric:
  7857. * typeof number except NaN, '-123', '123', '2e3', '-2e3', '011', 'Infinity', Infinity,
  7858. * and they rounded by white-spaces or line-terminal like ' -123 \n ' (see es spec)
  7859. * not-numeric:
  7860. * null, undefined, [], {}, true, false, 'NaN', NaN, '123ab',
  7861. * empty string, string with only white-spaces or line-terminal (see es spec),
  7862. * 0x12, '0x12', '-0x12', 012, '012', '-012',
  7863. * non-string, ...
  7864. *
  7865. * @test See full test cases in `test/ut/spec/util/number.js`.
  7866. * @return Must be a typeof number. If not numeric, return NaN.
  7867. */
  7868. function numericToNumber(val) {
  7869. var valFloat = parseFloat(val);
  7870. return valFloat == val // eslint-disable-line eqeqeq
  7871. && (valFloat !== 0 || !isString(val) || val.indexOf('x') <= 0) // For case ' 0x0 '.
  7872. ? valFloat : NaN;
  7873. }
  7874. /**
  7875. * Definition of "numeric": see `numericToNumber`.
  7876. */
  7877. function isNumeric(val) {
  7878. return !isNaN(numericToNumber(val));
  7879. }
  7880. /**
  7881. * Use random base to prevent users hard code depending on
  7882. * this auto generated marker id.
  7883. * @return An positive integer.
  7884. */
  7885. function getRandomIdBase() {
  7886. return Math.round(Math.random() * 9);
  7887. }
  7888. /**
  7889. * Get the greatest common divisor.
  7890. *
  7891. * @param {number} a one number
  7892. * @param {number} b the other number
  7893. */
  7894. function getGreatestCommonDividor(a, b) {
  7895. if (b === 0) {
  7896. return a;
  7897. }
  7898. return getGreatestCommonDividor(b, a % b);
  7899. }
  7900. /**
  7901. * Get the least common multiple.
  7902. *
  7903. * @param {number} a one number
  7904. * @param {number} b the other number
  7905. */
  7906. function getLeastCommonMultiple(a, b) {
  7907. if (a == null) {
  7908. return b;
  7909. }
  7910. if (b == null) {
  7911. return a;
  7912. }
  7913. return a * b / getGreatestCommonDividor(a, b);
  7914. }
  7915. var ECHARTS_PREFIX = '[ECharts] ';
  7916. var storedLogs = {};
  7917. var hasConsole = typeof console !== 'undefined'
  7918. // eslint-disable-next-line
  7919. && console.warn && console.log;
  7920. function outputLog(type, str, onlyOnce) {
  7921. if (hasConsole) {
  7922. if (onlyOnce) {
  7923. if (storedLogs[str]) {
  7924. return;
  7925. }
  7926. storedLogs[str] = true;
  7927. }
  7928. // eslint-disable-next-line
  7929. console[type](ECHARTS_PREFIX + str);
  7930. }
  7931. }
  7932. function log(str, onlyOnce) {
  7933. outputLog('log', str, onlyOnce);
  7934. }
  7935. function warn(str, onlyOnce) {
  7936. outputLog('warn', str, onlyOnce);
  7937. }
  7938. function error(str, onlyOnce) {
  7939. outputLog('error', str, onlyOnce);
  7940. }
  7941. function deprecateLog(str) {
  7942. if ("development" !== 'production') {
  7943. // Not display duplicate message.
  7944. outputLog('warn', 'DEPRECATED: ' + str, true);
  7945. }
  7946. }
  7947. function deprecateReplaceLog(oldOpt, newOpt, scope) {
  7948. if ("development" !== 'production') {
  7949. deprecateLog((scope ? "[" + scope + "]" : '') + (oldOpt + " is deprecated; use " + newOpt + " instead."));
  7950. }
  7951. }
  7952. /**
  7953. * If in __DEV__ environment, get console printable message for users hint.
  7954. * Parameters are separated by ' '.
  7955. * @usage
  7956. * makePrintable('This is an error on', someVar, someObj);
  7957. *
  7958. * @param hintInfo anything about the current execution context to hint users.
  7959. * @throws Error
  7960. */
  7961. function makePrintable() {
  7962. var hintInfo = [];
  7963. for (var _i = 0; _i < arguments.length; _i++) {
  7964. hintInfo[_i] = arguments[_i];
  7965. }
  7966. var msg = '';
  7967. if ("development" !== 'production') {
  7968. // Fuzzy stringify for print.
  7969. // This code only exist in dev environment.
  7970. var makePrintableStringIfPossible_1 = function (val) {
  7971. return val === void 0 ? 'undefined' : val === Infinity ? 'Infinity' : val === -Infinity ? '-Infinity' : eqNaN(val) ? 'NaN' : val instanceof Date ? 'Date(' + val.toISOString() + ')' : isFunction(val) ? 'function () { ... }' : isRegExp(val) ? val + '' : null;
  7972. };
  7973. msg = map(hintInfo, function (arg) {
  7974. if (isString(arg)) {
  7975. // Print without quotation mark for some statement.
  7976. return arg;
  7977. } else {
  7978. var printableStr = makePrintableStringIfPossible_1(arg);
  7979. if (printableStr != null) {
  7980. return printableStr;
  7981. } else if (typeof JSON !== 'undefined' && JSON.stringify) {
  7982. try {
  7983. return JSON.stringify(arg, function (n, val) {
  7984. var printableStr = makePrintableStringIfPossible_1(val);
  7985. return printableStr == null ? val : printableStr;
  7986. });
  7987. // In most cases the info object is small, so do not line break.
  7988. } catch (err) {
  7989. return '?';
  7990. }
  7991. } else {
  7992. return '?';
  7993. }
  7994. }
  7995. }).join(' ');
  7996. }
  7997. return msg;
  7998. }
  7999. /**
  8000. * @throws Error
  8001. */
  8002. function throwError(msg) {
  8003. throw new Error(msg);
  8004. }
  8005. function interpolateNumber$1(p0, p1, percent) {
  8006. return (p1 - p0) * percent + p0;
  8007. }
  8008. /**
  8009. * Make the name displayable. But we should
  8010. * make sure it is not duplicated with user
  8011. * specified name, so use '\0';
  8012. */
  8013. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  8014. var INTERNAL_COMPONENT_ID_PREFIX = '\0_ec_\0';
  8015. /**
  8016. * If value is not array, then translate it to array.
  8017. * @param {*} value
  8018. * @return {Array} [value] or value
  8019. */
  8020. function normalizeToArray(value) {
  8021. return value instanceof Array ? value : value == null ? [] : [value];
  8022. }
  8023. /**
  8024. * Sync default option between normal and emphasis like `position` and `show`
  8025. * In case some one will write code like
  8026. * label: {
  8027. * show: false,
  8028. * position: 'outside',
  8029. * fontSize: 18
  8030. * },
  8031. * emphasis: {
  8032. * label: { show: true }
  8033. * }
  8034. */
  8035. function defaultEmphasis(opt, key, subOpts) {
  8036. // Caution: performance sensitive.
  8037. if (opt) {
  8038. opt[key] = opt[key] || {};
  8039. opt.emphasis = opt.emphasis || {};
  8040. opt.emphasis[key] = opt.emphasis[key] || {};
  8041. // Default emphasis option from normal
  8042. for (var i = 0, len = subOpts.length; i < len; i++) {
  8043. var subOptName = subOpts[i];
  8044. if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
  8045. opt.emphasis[key][subOptName] = opt[key][subOptName];
  8046. }
  8047. }
  8048. }
  8049. }
  8050. var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'];
  8051. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  8052. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  8053. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  8054. // // FIXME: deprecated, check and remove it.
  8055. // 'textStyle'
  8056. // ]);
  8057. /**
  8058. * The method does not ensure performance.
  8059. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  8060. * This helper method retrieves value from data.
  8061. */
  8062. function getDataItemValue(dataItem) {
  8063. return isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
  8064. }
  8065. /**
  8066. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  8067. * This helper method determine if dataItem has extra option besides value
  8068. */
  8069. function isDataItemOption(dataItem) {
  8070. return isObject(dataItem) && !(dataItem instanceof Array);
  8071. // // markLine data can be array
  8072. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  8073. }
  8074. /**
  8075. * Mapping to existings for merge.
  8076. *
  8077. * Mode "normalMege":
  8078. * The mapping result (merge result) will keep the order of the existing
  8079. * component, rather than the order of new option. Because we should ensure
  8080. * some specified index reference (like xAxisIndex) keep work.
  8081. * And in most cases, "merge option" is used to update partial option but not
  8082. * be expected to change the order.
  8083. *
  8084. * Mode "replaceMege":
  8085. * (1) Only the id mapped components will be merged.
  8086. * (2) Other existing components (except internal components) will be removed.
  8087. * (3) Other new options will be used to create new component.
  8088. * (4) The index of the existing components will not be modified.
  8089. * That means their might be "hole" after the removal.
  8090. * The new components are created first at those available index.
  8091. *
  8092. * Mode "replaceAll":
  8093. * This mode try to support that reproduce an echarts instance from another
  8094. * echarts instance (via `getOption`) in some simple cases.
  8095. * In this scenario, the `result` index are exactly the consistent with the `newCmptOptions`,
  8096. * which ensures the component index referring (like `xAxisIndex: ?`) corrent. That is,
  8097. * the "hole" in `newCmptOptions` will also be kept.
  8098. * On the contrary, other modes try best to eliminate holes.
  8099. * PENDING: This is an experimental mode yet.
  8100. *
  8101. * @return See the comment of <MappingResult>.
  8102. */
  8103. function mappingToExists(existings, newCmptOptions, mode) {
  8104. var isNormalMergeMode = mode === 'normalMerge';
  8105. var isReplaceMergeMode = mode === 'replaceMerge';
  8106. var isReplaceAllMode = mode === 'replaceAll';
  8107. existings = existings || [];
  8108. newCmptOptions = (newCmptOptions || []).slice();
  8109. var existingIdIdxMap = createHashMap();
  8110. // Validate id and name on user input option.
  8111. each(newCmptOptions, function (cmptOption, index) {
  8112. if (!isObject(cmptOption)) {
  8113. newCmptOptions[index] = null;
  8114. return;
  8115. }
  8116. if ("development" !== 'production') {
  8117. // There is some legacy case that name is set as `false`.
  8118. // But should work normally rather than throw error.
  8119. if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
  8120. warnInvalidateIdOrName(cmptOption.id);
  8121. }
  8122. if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
  8123. warnInvalidateIdOrName(cmptOption.name);
  8124. }
  8125. }
  8126. });
  8127. var result = prepareResult(existings, existingIdIdxMap, mode);
  8128. if (isNormalMergeMode || isReplaceMergeMode) {
  8129. mappingById(result, existings, existingIdIdxMap, newCmptOptions);
  8130. }
  8131. if (isNormalMergeMode) {
  8132. mappingByName(result, newCmptOptions);
  8133. }
  8134. if (isNormalMergeMode || isReplaceMergeMode) {
  8135. mappingByIndex(result, newCmptOptions, isReplaceMergeMode);
  8136. } else if (isReplaceAllMode) {
  8137. mappingInReplaceAllMode(result, newCmptOptions);
  8138. }
  8139. makeIdAndName(result);
  8140. // The array `result` MUST NOT contain elided items, otherwise the
  8141. // forEach will omit those items and result in incorrect result.
  8142. return result;
  8143. }
  8144. function prepareResult(existings, existingIdIdxMap, mode) {
  8145. var result = [];
  8146. if (mode === 'replaceAll') {
  8147. return result;
  8148. }
  8149. // Do not use native `map` to in case that the array `existings`
  8150. // contains elided items, which will be omitted.
  8151. for (var index = 0; index < existings.length; index++) {
  8152. var existing = existings[index];
  8153. // Because of replaceMerge, `existing` may be null/undefined.
  8154. if (existing && existing.id != null) {
  8155. existingIdIdxMap.set(existing.id, index);
  8156. }
  8157. // For non-internal-componnets:
  8158. // Mode "normalMerge": all existings kept.
  8159. // Mode "replaceMerge": all existing removed unless mapped by id.
  8160. // For internal-components:
  8161. // go with "replaceMerge" approach in both mode.
  8162. result.push({
  8163. existing: mode === 'replaceMerge' || isComponentIdInternal(existing) ? null : existing,
  8164. newOption: null,
  8165. keyInfo: null,
  8166. brandNew: null
  8167. });
  8168. }
  8169. return result;
  8170. }
  8171. function mappingById(result, existings, existingIdIdxMap, newCmptOptions) {
  8172. // Mapping by id if specified.
  8173. each(newCmptOptions, function (cmptOption, index) {
  8174. if (!cmptOption || cmptOption.id == null) {
  8175. return;
  8176. }
  8177. var optionId = makeComparableKey(cmptOption.id);
  8178. var existingIdx = existingIdIdxMap.get(optionId);
  8179. if (existingIdx != null) {
  8180. var resultItem = result[existingIdx];
  8181. assert(!resultItem.newOption, 'Duplicated option on id "' + optionId + '".');
  8182. resultItem.newOption = cmptOption;
  8183. // In both mode, if id matched, new option will be merged to
  8184. // the existings rather than creating new component model.
  8185. resultItem.existing = existings[existingIdx];
  8186. newCmptOptions[index] = null;
  8187. }
  8188. });
  8189. }
  8190. function mappingByName(result, newCmptOptions) {
  8191. // Mapping by name if specified.
  8192. each(newCmptOptions, function (cmptOption, index) {
  8193. if (!cmptOption || cmptOption.name == null) {
  8194. return;
  8195. }
  8196. for (var i = 0; i < result.length; i++) {
  8197. var existing = result[i].existing;
  8198. if (!result[i].newOption // Consider name: two map to one.
  8199. // Can not match when both ids existing but different.
  8200. && existing && (existing.id == null || cmptOption.id == null) && !isComponentIdInternal(cmptOption) && !isComponentIdInternal(existing) && keyExistAndEqual('name', existing, cmptOption)) {
  8201. result[i].newOption = cmptOption;
  8202. newCmptOptions[index] = null;
  8203. return;
  8204. }
  8205. }
  8206. });
  8207. }
  8208. function mappingByIndex(result, newCmptOptions, brandNew) {
  8209. each(newCmptOptions, function (cmptOption) {
  8210. if (!cmptOption) {
  8211. return;
  8212. }
  8213. // Find the first place that not mapped by id and not internal component (consider the "hole").
  8214. var resultItem;
  8215. var nextIdx = 0;
  8216. while (
  8217. // Be `!resultItem` only when `nextIdx >= result.length`.
  8218. (resultItem = result[nextIdx]
  8219. // (1) Existing models that already have id should be able to mapped to. Because
  8220. // after mapping performed, model will always be assigned with an id if user not given.
  8221. // After that all models have id.
  8222. // (2) If new option has id, it can only set to a hole or append to the last. It should
  8223. // not be merged to the existings with different id. Because id should not be overwritten.
  8224. // (3) Name can be overwritten, because axis use name as 'show label text'.
  8225. ) && (resultItem.newOption || isComponentIdInternal(resultItem.existing) ||
  8226. // In mode "replaceMerge", here no not-mapped-non-internal-existing.
  8227. resultItem.existing && cmptOption.id != null && !keyExistAndEqual('id', cmptOption, resultItem.existing))) {
  8228. nextIdx++;
  8229. }
  8230. if (resultItem) {
  8231. resultItem.newOption = cmptOption;
  8232. resultItem.brandNew = brandNew;
  8233. } else {
  8234. result.push({
  8235. newOption: cmptOption,
  8236. brandNew: brandNew,
  8237. existing: null,
  8238. keyInfo: null
  8239. });
  8240. }
  8241. nextIdx++;
  8242. });
  8243. }
  8244. function mappingInReplaceAllMode(result, newCmptOptions) {
  8245. each(newCmptOptions, function (cmptOption) {
  8246. // The feature "reproduce" requires "hole" will also reproduced
  8247. // in case that component index referring are broken.
  8248. result.push({
  8249. newOption: cmptOption,
  8250. brandNew: true,
  8251. existing: null,
  8252. keyInfo: null
  8253. });
  8254. });
  8255. }
  8256. /**
  8257. * Make id and name for mapping result (result of mappingToExists)
  8258. * into `keyInfo` field.
  8259. */
  8260. function makeIdAndName(mapResult) {
  8261. // We use this id to hash component models and view instances
  8262. // in echarts. id can be specified by user, or auto generated.
  8263. // The id generation rule ensures new view instance are able
  8264. // to mapped to old instance when setOption are called in
  8265. // no-merge mode. So we generate model id by name and plus
  8266. // type in view id.
  8267. // name can be duplicated among components, which is convenient
  8268. // to specify multi components (like series) by one name.
  8269. // Ensure that each id is distinct.
  8270. var idMap = createHashMap();
  8271. each(mapResult, function (item) {
  8272. var existing = item.existing;
  8273. existing && idMap.set(existing.id, item);
  8274. });
  8275. each(mapResult, function (item) {
  8276. var opt = item.newOption;
  8277. // Force ensure id not duplicated.
  8278. assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  8279. opt && opt.id != null && idMap.set(opt.id, item);
  8280. !item.keyInfo && (item.keyInfo = {});
  8281. });
  8282. // Make name and id.
  8283. each(mapResult, function (item, index) {
  8284. var existing = item.existing;
  8285. var opt = item.newOption;
  8286. var keyInfo = item.keyInfo;
  8287. if (!isObject(opt)) {
  8288. return;
  8289. }
  8290. // Name can be overwritten. Consider case: axis.name = '20km'.
  8291. // But id generated by name will not be changed, which affect
  8292. // only in that case: setOption with 'not merge mode' and view
  8293. // instance will be recreated, which can be accepted.
  8294. keyInfo.name = opt.name != null ? makeComparableKey(opt.name) : existing ? existing.name
  8295. // Avoid that different series has the same name,
  8296. // because name may be used like in color pallet.
  8297. : DUMMY_COMPONENT_NAME_PREFIX + index;
  8298. if (existing) {
  8299. keyInfo.id = makeComparableKey(existing.id);
  8300. } else if (opt.id != null) {
  8301. keyInfo.id = makeComparableKey(opt.id);
  8302. } else {
  8303. // Consider this situatoin:
  8304. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  8305. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  8306. // Series with the same name between optionA and optionB
  8307. // should be mapped.
  8308. var idNum = 0;
  8309. do {
  8310. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  8311. } while (idMap.get(keyInfo.id));
  8312. }
  8313. idMap.set(keyInfo.id, item);
  8314. });
  8315. }
  8316. function keyExistAndEqual(attr, obj1, obj2) {
  8317. var key1 = convertOptionIdName(obj1[attr], null);
  8318. var key2 = convertOptionIdName(obj2[attr], null);
  8319. // See `MappingExistingItem`. `id` and `name` trade string equals to number.
  8320. return key1 != null && key2 != null && key1 === key2;
  8321. }
  8322. /**
  8323. * @return return null if not exist.
  8324. */
  8325. function makeComparableKey(val) {
  8326. if ("development" !== 'production') {
  8327. if (val == null) {
  8328. throw new Error();
  8329. }
  8330. }
  8331. return convertOptionIdName(val, '');
  8332. }
  8333. function convertOptionIdName(idOrName, defaultValue) {
  8334. if (idOrName == null) {
  8335. return defaultValue;
  8336. }
  8337. return isString(idOrName) ? idOrName : isNumber(idOrName) || isStringSafe(idOrName) ? idOrName + '' : defaultValue;
  8338. }
  8339. function warnInvalidateIdOrName(idOrName) {
  8340. if ("development" !== 'production') {
  8341. warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
  8342. }
  8343. }
  8344. function isValidIdOrName(idOrName) {
  8345. return isStringSafe(idOrName) || isNumeric(idOrName);
  8346. }
  8347. function isNameSpecified(componentModel) {
  8348. var name = componentModel.name;
  8349. // Is specified when `indexOf` get -1 or > 0.
  8350. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  8351. }
  8352. /**
  8353. * @public
  8354. * @param {Object} cmptOption
  8355. * @return {boolean}
  8356. */
  8357. function isComponentIdInternal(cmptOption) {
  8358. return cmptOption && cmptOption.id != null && makeComparableKey(cmptOption.id).indexOf(INTERNAL_COMPONENT_ID_PREFIX) === 0;
  8359. }
  8360. function setComponentTypeToKeyInfo(mappingResult, mainType, componentModelCtor) {
  8361. // Set mainType and complete subType.
  8362. each(mappingResult, function (item) {
  8363. var newOption = item.newOption;
  8364. if (isObject(newOption)) {
  8365. item.keyInfo.mainType = mainType;
  8366. item.keyInfo.subType = determineSubType(mainType, newOption, item.existing, componentModelCtor);
  8367. }
  8368. });
  8369. }
  8370. function determineSubType(mainType, newCmptOption, existComponent, componentModelCtor) {
  8371. var subType = newCmptOption.type ? newCmptOption.type : existComponent ? existComponent.subType
  8372. // Use determineSubType only when there is no existComponent.
  8373. : componentModelCtor.determineSubType(mainType, newCmptOption);
  8374. // tooltip, markline, markpoint may always has no subType
  8375. return subType;
  8376. }
  8377. /**
  8378. * @param payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  8379. * each of which can be Array or primary type.
  8380. * @return dataIndex If not found, return undefined/null.
  8381. */
  8382. function queryDataIndex(data, payload) {
  8383. if (payload.dataIndexInside != null) {
  8384. return payload.dataIndexInside;
  8385. } else if (payload.dataIndex != null) {
  8386. return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
  8387. return data.indexOfRawIndex(value);
  8388. }) : data.indexOfRawIndex(payload.dataIndex);
  8389. } else if (payload.name != null) {
  8390. return isArray(payload.name) ? map(payload.name, function (value) {
  8391. return data.indexOfName(value);
  8392. }) : data.indexOfName(payload.name);
  8393. }
  8394. }
  8395. /**
  8396. * Enable property storage to any host object.
  8397. * Notice: Serialization is not supported.
  8398. *
  8399. * For example:
  8400. * let inner = zrUitl.makeInner();
  8401. *
  8402. * function some1(hostObj) {
  8403. * inner(hostObj).someProperty = 1212;
  8404. * ...
  8405. * }
  8406. * function some2() {
  8407. * let fields = inner(this);
  8408. * fields.someProperty1 = 1212;
  8409. * fields.someProperty2 = 'xx';
  8410. * ...
  8411. * }
  8412. *
  8413. * @return {Function}
  8414. */
  8415. function makeInner() {
  8416. var key = '__ec_inner_' + innerUniqueIndex++;
  8417. return function (hostObj) {
  8418. return hostObj[key] || (hostObj[key] = {});
  8419. };
  8420. }
  8421. var innerUniqueIndex = getRandomIdBase();
  8422. /**
  8423. * The same behavior as `component.getReferringComponents`.
  8424. */
  8425. function parseFinder(ecModel, finderInput, opt) {
  8426. var _a = preParseFinder(finderInput, opt),
  8427. mainTypeSpecified = _a.mainTypeSpecified,
  8428. queryOptionMap = _a.queryOptionMap,
  8429. others = _a.others;
  8430. var result = others;
  8431. var defaultMainType = opt ? opt.defaultMainType : null;
  8432. if (!mainTypeSpecified && defaultMainType) {
  8433. queryOptionMap.set(defaultMainType, {});
  8434. }
  8435. queryOptionMap.each(function (queryOption, mainType) {
  8436. var queryResult = queryReferringComponents(ecModel, mainType, queryOption, {
  8437. useDefault: defaultMainType === mainType,
  8438. enableAll: opt && opt.enableAll != null ? opt.enableAll : true,
  8439. enableNone: opt && opt.enableNone != null ? opt.enableNone : true
  8440. });
  8441. result[mainType + 'Models'] = queryResult.models;
  8442. result[mainType + 'Model'] = queryResult.models[0];
  8443. });
  8444. return result;
  8445. }
  8446. function preParseFinder(finderInput, opt) {
  8447. var finder;
  8448. if (isString(finderInput)) {
  8449. var obj = {};
  8450. obj[finderInput + 'Index'] = 0;
  8451. finder = obj;
  8452. } else {
  8453. finder = finderInput;
  8454. }
  8455. var queryOptionMap = createHashMap();
  8456. var others = {};
  8457. var mainTypeSpecified = false;
  8458. each(finder, function (value, key) {
  8459. // Exclude 'dataIndex' and other illegal keys.
  8460. if (key === 'dataIndex' || key === 'dataIndexInside') {
  8461. others[key] = value;
  8462. return;
  8463. }
  8464. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  8465. var mainType = parsedKey[1];
  8466. var queryType = (parsedKey[2] || '').toLowerCase();
  8467. if (!mainType || !queryType || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
  8468. return;
  8469. }
  8470. mainTypeSpecified = mainTypeSpecified || !!mainType;
  8471. var queryOption = queryOptionMap.get(mainType) || queryOptionMap.set(mainType, {});
  8472. queryOption[queryType] = value;
  8473. });
  8474. return {
  8475. mainTypeSpecified: mainTypeSpecified,
  8476. queryOptionMap: queryOptionMap,
  8477. others: others
  8478. };
  8479. }
  8480. var SINGLE_REFERRING = {
  8481. useDefault: true,
  8482. enableAll: false,
  8483. enableNone: false
  8484. };
  8485. function queryReferringComponents(ecModel, mainType, userOption, opt) {
  8486. opt = opt || SINGLE_REFERRING;
  8487. var indexOption = userOption.index;
  8488. var idOption = userOption.id;
  8489. var nameOption = userOption.name;
  8490. var result = {
  8491. models: null,
  8492. specified: indexOption != null || idOption != null || nameOption != null
  8493. };
  8494. if (!result.specified) {
  8495. // Use the first as default if `useDefault`.
  8496. var firstCmpt = void 0;
  8497. result.models = opt.useDefault && (firstCmpt = ecModel.getComponent(mainType)) ? [firstCmpt] : [];
  8498. return result;
  8499. }
  8500. if (indexOption === 'none' || indexOption === false) {
  8501. if (opt.enableNone) {
  8502. result.models = [];
  8503. return result;
  8504. } else {
  8505. // Do not throw; consider if some component previously does not use this method,
  8506. // and start to use it, need to be fault-tolerant for backward compatibility.
  8507. if ("development" !== 'production') {
  8508. error('`"none"` or `false` is not a valid value on index option.');
  8509. }
  8510. indexOption = -1; // Can not query by index but may still query by id/name if specified.
  8511. }
  8512. }
  8513. // `queryComponents` will return all components if
  8514. // both all of index/id/name are null/undefined.
  8515. if (indexOption === 'all') {
  8516. if (opt.enableAll) {
  8517. indexOption = idOption = nameOption = null;
  8518. } else {
  8519. if ("development" !== 'production') {
  8520. error('`"all"` is not a valid value on index option.');
  8521. }
  8522. indexOption = -1;
  8523. }
  8524. }
  8525. result.models = ecModel.queryComponents({
  8526. mainType: mainType,
  8527. index: indexOption,
  8528. id: idOption,
  8529. name: nameOption
  8530. });
  8531. return result;
  8532. }
  8533. function setAttribute(dom, key, value) {
  8534. dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
  8535. }
  8536. function getAttribute(dom, key) {
  8537. return dom.getAttribute ? dom.getAttribute(key) : dom[key];
  8538. }
  8539. /**
  8540. * Interpolate raw values of a series with percent
  8541. *
  8542. * @param data data
  8543. * @param labelModel label model of the text element
  8544. * @param sourceValue start value. May be null/undefined when init.
  8545. * @param targetValue end value
  8546. * @param percent 0~1 percentage; 0 uses start value while 1 uses end value
  8547. * @return interpolated values
  8548. * If `sourceValue` and `targetValue` are `number`, return `number`.
  8549. * If `sourceValue` and `targetValue` are `string`, return `string`.
  8550. * If `sourceValue` and `targetValue` are `(string | number)[]`, return `(string | number)[]`.
  8551. * Other cases do not supported.
  8552. */
  8553. function interpolateRawValues(data, precision, sourceValue, targetValue, percent) {
  8554. var isAutoPrecision = precision == null || precision === 'auto';
  8555. if (targetValue == null) {
  8556. return targetValue;
  8557. }
  8558. if (isNumber(targetValue)) {
  8559. var value = interpolateNumber$1(sourceValue || 0, targetValue, percent);
  8560. return round(value, isAutoPrecision ? Math.max(getPrecision(sourceValue || 0), getPrecision(targetValue)) : precision);
  8561. } else if (isString(targetValue)) {
  8562. return percent < 1 ? sourceValue : targetValue;
  8563. } else {
  8564. var interpolated = [];
  8565. var leftArr = sourceValue;
  8566. var rightArr = targetValue;
  8567. var length_1 = Math.max(leftArr ? leftArr.length : 0, rightArr.length);
  8568. for (var i = 0; i < length_1; ++i) {
  8569. var info = data.getDimensionInfo(i);
  8570. // Don't interpolate ordinal dims
  8571. if (info && info.type === 'ordinal') {
  8572. // In init, there is no `sourceValue`, but should better not to get undefined result.
  8573. interpolated[i] = (percent < 1 && leftArr ? leftArr : rightArr)[i];
  8574. } else {
  8575. var leftVal = leftArr && leftArr[i] ? leftArr[i] : 0;
  8576. var rightVal = rightArr[i];
  8577. var value = interpolateNumber$1(leftVal, rightVal, percent);
  8578. interpolated[i] = round(value, isAutoPrecision ? Math.max(getPrecision(leftVal), getPrecision(rightVal)) : precision);
  8579. }
  8580. }
  8581. return interpolated;
  8582. }
  8583. }
  8584. var TYPE_DELIMITER = '.';
  8585. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  8586. var IS_EXTENDED_CLASS = '___EC__EXTENDED_CLASS___';
  8587. /**
  8588. * Notice, parseClassType('') should returns {main: '', sub: ''}
  8589. * @public
  8590. */
  8591. function parseClassType(componentType) {
  8592. var ret = {
  8593. main: '',
  8594. sub: ''
  8595. };
  8596. if (componentType) {
  8597. var typeArr = componentType.split(TYPE_DELIMITER);
  8598. ret.main = typeArr[0] || '';
  8599. ret.sub = typeArr[1] || '';
  8600. }
  8601. return ret;
  8602. }
  8603. /**
  8604. * @public
  8605. */
  8606. function checkClassType(componentType) {
  8607. assert(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  8608. }
  8609. function isExtendedClass(clz) {
  8610. return !!(clz && clz[IS_EXTENDED_CLASS]);
  8611. }
  8612. /**
  8613. * Implements `ExtendableConstructor` for `rootClz`.
  8614. *
  8615. * @usage
  8616. * ```ts
  8617. * class Xxx {}
  8618. * type XxxConstructor = typeof Xxx & ExtendableConstructor
  8619. * enableClassExtend(Xxx as XxxConstructor);
  8620. * ```
  8621. */
  8622. function enableClassExtend(rootClz, mandatoryMethods) {
  8623. rootClz.$constructor = rootClz; // FIXME: not necessary?
  8624. rootClz.extend = function (proto) {
  8625. if ("development" !== 'production') {
  8626. each(mandatoryMethods, function (method) {
  8627. if (!proto[method]) {
  8628. console.warn('Method `' + method + '` should be implemented' + (proto.type ? ' in ' + proto.type : '') + '.');
  8629. }
  8630. });
  8631. }
  8632. var superClass = this;
  8633. var ExtendedClass;
  8634. if (isESClass(superClass)) {
  8635. ExtendedClass = /** @class */function (_super) {
  8636. __extends(class_1, _super);
  8637. function class_1() {
  8638. return _super.apply(this, arguments) || this;
  8639. }
  8640. return class_1;
  8641. }(superClass);
  8642. } else {
  8643. // For backward compat, we both support ts class inheritance and this
  8644. // "extend" approach.
  8645. // The constructor should keep the same behavior as ts class inheritance:
  8646. // If this constructor/$constructor is not declared, auto invoke the super
  8647. // constructor.
  8648. // If this constructor/$constructor is declared, it is responsible for
  8649. // calling the super constructor.
  8650. ExtendedClass = function () {
  8651. (proto.$constructor || superClass).apply(this, arguments);
  8652. };
  8653. inherits(ExtendedClass, this);
  8654. }
  8655. extend(ExtendedClass.prototype, proto);
  8656. ExtendedClass[IS_EXTENDED_CLASS] = true;
  8657. ExtendedClass.extend = this.extend;
  8658. ExtendedClass.superCall = superCall;
  8659. ExtendedClass.superApply = superApply;
  8660. ExtendedClass.superClass = superClass;
  8661. return ExtendedClass;
  8662. };
  8663. }
  8664. function isESClass(fn) {
  8665. return isFunction(fn) && /^class\s/.test(Function.prototype.toString.call(fn));
  8666. }
  8667. /**
  8668. * A work around to both support ts extend and this extend mechanism.
  8669. * on sub-class.
  8670. * @usage
  8671. * ```ts
  8672. * class Component { ... }
  8673. * classUtil.enableClassExtend(Component);
  8674. * classUtil.enableClassManagement(Component, {registerWhenExtend: true});
  8675. *
  8676. * class Series extends Component { ... }
  8677. * // Without calling `markExtend`, `registerWhenExtend` will not work.
  8678. * Component.markExtend(Series);
  8679. * ```
  8680. */
  8681. function mountExtend(SubClz, SupperClz) {
  8682. SubClz.extend = SupperClz.extend;
  8683. }
  8684. // A random offset.
  8685. var classBase = Math.round(Math.random() * 10);
  8686. /**
  8687. * Implements `CheckableConstructor` for `target`.
  8688. * Can not use instanceof, consider different scope by
  8689. * cross domain or es module import in ec extensions.
  8690. * Mount a method "isInstance()" to Clz.
  8691. *
  8692. * @usage
  8693. * ```ts
  8694. * class Xxx {}
  8695. * type XxxConstructor = typeof Xxx & CheckableConstructor;
  8696. * enableClassCheck(Xxx as XxxConstructor)
  8697. * ```
  8698. */
  8699. function enableClassCheck(target) {
  8700. var classAttr = ['__\0is_clz', classBase++].join('_');
  8701. target.prototype[classAttr] = true;
  8702. if ("development" !== 'production') {
  8703. assert(!target.isInstance, 'The method "is" can not be defined.');
  8704. }
  8705. target.isInstance = function (obj) {
  8706. return !!(obj && obj[classAttr]);
  8707. };
  8708. }
  8709. // superCall should have class info, which can not be fetched from 'this'.
  8710. // Consider this case:
  8711. // class A has method f,
  8712. // class B inherits class A, overrides method f, f call superApply('f'),
  8713. // class C inherits class B, does not override method f,
  8714. // then when method of class C is called, dead loop occurred.
  8715. function superCall(context, methodName) {
  8716. var args = [];
  8717. for (var _i = 2; _i < arguments.length; _i++) {
  8718. args[_i - 2] = arguments[_i];
  8719. }
  8720. return this.superClass.prototype[methodName].apply(context, args);
  8721. }
  8722. function superApply(context, methodName, args) {
  8723. return this.superClass.prototype[methodName].apply(context, args);
  8724. }
  8725. /**
  8726. * Implements `ClassManager` for `target`
  8727. *
  8728. * @usage
  8729. * ```ts
  8730. * class Xxx {}
  8731. * type XxxConstructor = typeof Xxx & ClassManager
  8732. * enableClassManagement(Xxx as XxxConstructor);
  8733. * ```
  8734. */
  8735. function enableClassManagement(target) {
  8736. /**
  8737. * Component model classes
  8738. * key: componentType,
  8739. * value:
  8740. * componentClass, when componentType is 'a'
  8741. * or Object.<subKey, componentClass>, when componentType is 'a.b'
  8742. */
  8743. var storage = {};
  8744. target.registerClass = function (clz) {
  8745. // `type` should not be a "instance member".
  8746. // If using TS class, should better declared as `static type = 'series.pie'`.
  8747. // otherwise users have to mount `type` on prototype manually.
  8748. // For backward compat and enable instance visit type via `this.type`,
  8749. // we still support fetch `type` from prototype.
  8750. var componentFullType = clz.type || clz.prototype.type;
  8751. if (componentFullType) {
  8752. checkClassType(componentFullType);
  8753. // If only static type declared, we assign it to prototype mandatorily.
  8754. clz.prototype.type = componentFullType;
  8755. var componentTypeInfo = parseClassType(componentFullType);
  8756. if (!componentTypeInfo.sub) {
  8757. if ("development" !== 'production') {
  8758. if (storage[componentTypeInfo.main]) {
  8759. console.warn(componentTypeInfo.main + ' exists.');
  8760. }
  8761. }
  8762. storage[componentTypeInfo.main] = clz;
  8763. } else if (componentTypeInfo.sub !== IS_CONTAINER) {
  8764. var container = makeContainer(componentTypeInfo);
  8765. container[componentTypeInfo.sub] = clz;
  8766. }
  8767. }
  8768. return clz;
  8769. };
  8770. target.getClass = function (mainType, subType, throwWhenNotFound) {
  8771. var clz = storage[mainType];
  8772. if (clz && clz[IS_CONTAINER]) {
  8773. clz = subType ? clz[subType] : null;
  8774. }
  8775. if (throwWhenNotFound && !clz) {
  8776. throw new Error(!subType ? mainType + '.' + 'type should be specified.' : 'Component ' + mainType + '.' + (subType || '') + ' is used but not imported.');
  8777. }
  8778. return clz;
  8779. };
  8780. target.getClassesByMainType = function (componentType) {
  8781. var componentTypeInfo = parseClassType(componentType);
  8782. var result = [];
  8783. var obj = storage[componentTypeInfo.main];
  8784. if (obj && obj[IS_CONTAINER]) {
  8785. each(obj, function (o, type) {
  8786. type !== IS_CONTAINER && result.push(o);
  8787. });
  8788. } else {
  8789. result.push(obj);
  8790. }
  8791. return result;
  8792. };
  8793. target.hasClass = function (componentType) {
  8794. // Just consider componentType.main.
  8795. var componentTypeInfo = parseClassType(componentType);
  8796. return !!storage[componentTypeInfo.main];
  8797. };
  8798. /**
  8799. * @return Like ['aa', 'bb'], but can not be ['aa.xx']
  8800. */
  8801. target.getAllClassMainTypes = function () {
  8802. var types = [];
  8803. each(storage, function (obj, type) {
  8804. types.push(type);
  8805. });
  8806. return types;
  8807. };
  8808. /**
  8809. * If a main type is container and has sub types
  8810. */
  8811. target.hasSubTypes = function (componentType) {
  8812. var componentTypeInfo = parseClassType(componentType);
  8813. var obj = storage[componentTypeInfo.main];
  8814. return obj && obj[IS_CONTAINER];
  8815. };
  8816. function makeContainer(componentTypeInfo) {
  8817. var container = storage[componentTypeInfo.main];
  8818. if (!container || !container[IS_CONTAINER]) {
  8819. container = storage[componentTypeInfo.main] = {};
  8820. container[IS_CONTAINER] = true;
  8821. }
  8822. return container;
  8823. }
  8824. }
  8825. // /**
  8826. // * @param {string|Array.<string>} properties
  8827. // */
  8828. // export function setReadOnly(obj, properties) {
  8829. // FIXME It seems broken in IE8 simulation of IE11
  8830. // if (!zrUtil.isArray(properties)) {
  8831. // properties = properties != null ? [properties] : [];
  8832. // }
  8833. // zrUtil.each(properties, function (prop) {
  8834. // let value = obj[prop];
  8835. // Object.defineProperty
  8836. // && Object.defineProperty(obj, prop, {
  8837. // value: value, writable: false
  8838. // });
  8839. // zrUtil.isArray(obj[prop])
  8840. // && Object.freeze
  8841. // && Object.freeze(obj[prop]);
  8842. // });
  8843. // }
  8844. function makeStyleMapper(properties, ignoreParent) {
  8845. // Normalize
  8846. for (var i = 0; i < properties.length; i++) {
  8847. if (!properties[i][1]) {
  8848. properties[i][1] = properties[i][0];
  8849. }
  8850. }
  8851. ignoreParent = ignoreParent || false;
  8852. return function (model, excludes, includes) {
  8853. var style = {};
  8854. for (var i = 0; i < properties.length; i++) {
  8855. var propName = properties[i][1];
  8856. if (excludes && indexOf(excludes, propName) >= 0 || includes && indexOf(includes, propName) < 0) {
  8857. continue;
  8858. }
  8859. var val = model.getShallow(propName, ignoreParent);
  8860. if (val != null) {
  8861. style[properties[i][0]] = val;
  8862. }
  8863. }
  8864. // TODO Text or image?
  8865. return style;
  8866. };
  8867. }
  8868. var AREA_STYLE_KEY_MAP = [['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor']
  8869. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  8870. // So do not transfer decal directly.
  8871. ];
  8872. var getAreaStyle = makeStyleMapper(AREA_STYLE_KEY_MAP);
  8873. var AreaStyleMixin = /** @class */function () {
  8874. function AreaStyleMixin() {}
  8875. AreaStyleMixin.prototype.getAreaStyle = function (excludes, includes) {
  8876. return getAreaStyle(this, excludes, includes);
  8877. };
  8878. return AreaStyleMixin;
  8879. }();
  8880. var globalImageCache = new LRU(50);
  8881. function findExistImage(newImageOrSrc) {
  8882. if (typeof newImageOrSrc === 'string') {
  8883. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  8884. return cachedImgObj && cachedImgObj.image;
  8885. }
  8886. else {
  8887. return newImageOrSrc;
  8888. }
  8889. }
  8890. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  8891. if (!newImageOrSrc) {
  8892. return image;
  8893. }
  8894. else if (typeof newImageOrSrc === 'string') {
  8895. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  8896. return image;
  8897. }
  8898. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  8899. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  8900. if (cachedImgObj) {
  8901. image = cachedImgObj.image;
  8902. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  8903. }
  8904. else {
  8905. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  8906. image.__zrImageSrc = newImageOrSrc;
  8907. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  8908. image: image,
  8909. pending: [pendingWrap]
  8910. });
  8911. }
  8912. return image;
  8913. }
  8914. else {
  8915. return newImageOrSrc;
  8916. }
  8917. }
  8918. function imageOnLoad() {
  8919. var cachedImgObj = this.__cachedImgObj;
  8920. this.onload = this.onerror = this.__cachedImgObj = null;
  8921. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  8922. var pendingWrap = cachedImgObj.pending[i];
  8923. var cb = pendingWrap.cb;
  8924. cb && cb(this, pendingWrap.cbPayload);
  8925. pendingWrap.hostEl.dirty();
  8926. }
  8927. cachedImgObj.pending.length = 0;
  8928. }
  8929. function isImageReady(image) {
  8930. return image && image.width && image.height;
  8931. }
  8932. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  8933. function truncateText(text, containerWidth, font, ellipsis, options) {
  8934. var out = {};
  8935. truncateText2(out, text, containerWidth, font, ellipsis, options);
  8936. return out.text;
  8937. }
  8938. function truncateText2(out, text, containerWidth, font, ellipsis, options) {
  8939. if (!containerWidth) {
  8940. out.text = '';
  8941. out.isTruncated = false;
  8942. return;
  8943. }
  8944. var textLines = (text + '').split('\n');
  8945. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  8946. var isTruncated = false;
  8947. var truncateOut = {};
  8948. for (var i = 0, len = textLines.length; i < len; i++) {
  8949. truncateSingleLine(truncateOut, textLines[i], options);
  8950. textLines[i] = truncateOut.textLine;
  8951. isTruncated = isTruncated || truncateOut.isTruncated;
  8952. }
  8953. out.text = textLines.join('\n');
  8954. out.isTruncated = isTruncated;
  8955. }
  8956. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  8957. options = options || {};
  8958. var preparedOpts = extend({}, options);
  8959. ellipsis = retrieve2(ellipsis, '...');
  8960. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  8961. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  8962. var fontMeasureInfo = preparedOpts.fontMeasureInfo = ensureFontMeasureInfo(font);
  8963. var ascCharWidth = fontMeasureInfo.asciiCharWidth;
  8964. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  8965. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  8966. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  8967. contentWidth -= ascCharWidth;
  8968. }
  8969. var ellipsisWidth = measureWidth(fontMeasureInfo, ellipsis);
  8970. if (ellipsisWidth > contentWidth) {
  8971. ellipsis = '';
  8972. ellipsisWidth = 0;
  8973. }
  8974. contentWidth = containerWidth - ellipsisWidth;
  8975. preparedOpts.ellipsis = ellipsis;
  8976. preparedOpts.ellipsisWidth = ellipsisWidth;
  8977. preparedOpts.contentWidth = contentWidth;
  8978. preparedOpts.containerWidth = containerWidth;
  8979. return preparedOpts;
  8980. }
  8981. function truncateSingleLine(out, textLine, options) {
  8982. var containerWidth = options.containerWidth;
  8983. var contentWidth = options.contentWidth;
  8984. var fontMeasureInfo = options.fontMeasureInfo;
  8985. if (!containerWidth) {
  8986. out.textLine = '';
  8987. out.isTruncated = false;
  8988. return;
  8989. }
  8990. var lineWidth = measureWidth(fontMeasureInfo, textLine);
  8991. if (lineWidth <= containerWidth) {
  8992. out.textLine = textLine;
  8993. out.isTruncated = false;
  8994. return;
  8995. }
  8996. for (var j = 0;; j++) {
  8997. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  8998. textLine += options.ellipsis;
  8999. break;
  9000. }
  9001. var subLength = j === 0
  9002. ? estimateLength(textLine, contentWidth, fontMeasureInfo)
  9003. : lineWidth > 0
  9004. ? Math.floor(textLine.length * contentWidth / lineWidth)
  9005. : 0;
  9006. textLine = textLine.substr(0, subLength);
  9007. lineWidth = measureWidth(fontMeasureInfo, textLine);
  9008. }
  9009. if (textLine === '') {
  9010. textLine = options.placeholder;
  9011. }
  9012. out.textLine = textLine;
  9013. out.isTruncated = true;
  9014. }
  9015. function estimateLength(text, contentWidth, fontMeasureInfo) {
  9016. var width = 0;
  9017. var i = 0;
  9018. for (var len = text.length; i < len && width < contentWidth; i++) {
  9019. width += measureCharWidth(fontMeasureInfo, text.charCodeAt(i));
  9020. }
  9021. return i;
  9022. }
  9023. function parsePlainText(rawText, style, defaultOuterWidth, defaultOuterHeight) {
  9024. var text = formatText(rawText);
  9025. var overflow = style.overflow;
  9026. var padding = style.padding;
  9027. var paddingH = padding ? padding[1] + padding[3] : 0;
  9028. var paddingV = padding ? padding[0] + padding[2] : 0;
  9029. var font = style.font;
  9030. var truncate = overflow === 'truncate';
  9031. var calculatedLineHeight = getLineHeight(font);
  9032. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  9033. var truncateLineOverflow = style.lineOverflow === 'truncate';
  9034. var isTruncated = false;
  9035. var width = style.width;
  9036. if (width == null && defaultOuterWidth != null) {
  9037. width = defaultOuterWidth - paddingH;
  9038. }
  9039. var height = style.height;
  9040. if (height == null && defaultOuterHeight != null) {
  9041. height = defaultOuterHeight - paddingV;
  9042. }
  9043. var lines;
  9044. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  9045. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  9046. }
  9047. else {
  9048. lines = text ? text.split('\n') : [];
  9049. }
  9050. var contentHeight = lines.length * lineHeight;
  9051. if (height == null) {
  9052. height = contentHeight;
  9053. }
  9054. if (contentHeight > height && truncateLineOverflow) {
  9055. var lineCount = Math.floor(height / lineHeight);
  9056. isTruncated = isTruncated || (lines.length > lineCount);
  9057. lines = lines.slice(0, lineCount);
  9058. contentHeight = lines.length * lineHeight;
  9059. }
  9060. if (text && truncate && width != null) {
  9061. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  9062. minChar: style.truncateMinChar,
  9063. placeholder: style.placeholder
  9064. });
  9065. var singleOut = {};
  9066. for (var i = 0; i < lines.length; i++) {
  9067. truncateSingleLine(singleOut, lines[i], options);
  9068. lines[i] = singleOut.textLine;
  9069. isTruncated = isTruncated || singleOut.isTruncated;
  9070. }
  9071. }
  9072. var outerHeight = height;
  9073. var contentWidth = 0;
  9074. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9075. for (var i = 0; i < lines.length; i++) {
  9076. contentWidth = Math.max(measureWidth(fontMeasureInfo, lines[i]), contentWidth);
  9077. }
  9078. if (width == null) {
  9079. width = contentWidth;
  9080. }
  9081. var outerWidth = width;
  9082. outerHeight += paddingV;
  9083. outerWidth += paddingH;
  9084. return {
  9085. lines: lines,
  9086. height: height,
  9087. outerWidth: outerWidth,
  9088. outerHeight: outerHeight,
  9089. lineHeight: lineHeight,
  9090. calculatedLineHeight: calculatedLineHeight,
  9091. contentWidth: contentWidth,
  9092. contentHeight: contentHeight,
  9093. width: width,
  9094. isTruncated: isTruncated
  9095. };
  9096. }
  9097. var RichTextToken = (function () {
  9098. function RichTextToken() {
  9099. }
  9100. return RichTextToken;
  9101. }());
  9102. var RichTextLine = (function () {
  9103. function RichTextLine(tokens) {
  9104. this.tokens = [];
  9105. if (tokens) {
  9106. this.tokens = tokens;
  9107. }
  9108. }
  9109. return RichTextLine;
  9110. }());
  9111. var RichTextContentBlock = (function () {
  9112. function RichTextContentBlock() {
  9113. this.width = 0;
  9114. this.height = 0;
  9115. this.contentWidth = 0;
  9116. this.contentHeight = 0;
  9117. this.outerWidth = 0;
  9118. this.outerHeight = 0;
  9119. this.lines = [];
  9120. this.isTruncated = false;
  9121. }
  9122. return RichTextContentBlock;
  9123. }());
  9124. function parseRichText(rawText, style, defaultOuterWidth, defaultOuterHeight, topTextAlign) {
  9125. var contentBlock = new RichTextContentBlock();
  9126. var text = formatText(rawText);
  9127. if (!text) {
  9128. return contentBlock;
  9129. }
  9130. var stlPadding = style.padding;
  9131. var stlPaddingH = stlPadding ? stlPadding[1] + stlPadding[3] : 0;
  9132. var stlPaddingV = stlPadding ? stlPadding[0] + stlPadding[2] : 0;
  9133. var topWidth = style.width;
  9134. if (topWidth == null && defaultOuterWidth != null) {
  9135. topWidth = defaultOuterWidth - stlPaddingH;
  9136. }
  9137. var topHeight = style.height;
  9138. if (topHeight == null && defaultOuterHeight != null) {
  9139. topHeight = defaultOuterHeight - stlPaddingV;
  9140. }
  9141. var overflow = style.overflow;
  9142. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  9143. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  9144. : null;
  9145. var lastIndex = STYLE_REG.lastIndex = 0;
  9146. var result;
  9147. while ((result = STYLE_REG.exec(text)) != null) {
  9148. var matchedIndex = result.index;
  9149. if (matchedIndex > lastIndex) {
  9150. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  9151. }
  9152. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  9153. lastIndex = STYLE_REG.lastIndex;
  9154. }
  9155. if (lastIndex < text.length) {
  9156. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  9157. }
  9158. var pendingList = [];
  9159. var calculatedHeight = 0;
  9160. var calculatedWidth = 0;
  9161. var truncate = overflow === 'truncate';
  9162. var truncateLine = style.lineOverflow === 'truncate';
  9163. var tmpTruncateOut = {};
  9164. function finishLine(line, lineWidth, lineHeight) {
  9165. line.width = lineWidth;
  9166. line.lineHeight = lineHeight;
  9167. calculatedHeight += lineHeight;
  9168. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  9169. }
  9170. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  9171. var line = contentBlock.lines[i];
  9172. var lineHeight = 0;
  9173. var lineWidth = 0;
  9174. for (var j = 0; j < line.tokens.length; j++) {
  9175. var token = line.tokens[j];
  9176. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  9177. var textPadding = token.textPadding = tokenStyle.padding;
  9178. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  9179. var font = token.font = tokenStyle.font || style.font;
  9180. token.contentHeight = getLineHeight(font);
  9181. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  9182. token.innerHeight = tokenHeight;
  9183. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  9184. token.height = tokenHeight;
  9185. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  9186. token.align = tokenStyle && tokenStyle.align || topTextAlign;
  9187. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  9188. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  9189. var originalLength = contentBlock.lines.length;
  9190. if (j > 0) {
  9191. line.tokens = line.tokens.slice(0, j);
  9192. finishLine(line, lineWidth, lineHeight);
  9193. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  9194. }
  9195. else {
  9196. contentBlock.lines = contentBlock.lines.slice(0, i);
  9197. }
  9198. contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
  9199. break outer;
  9200. }
  9201. var styleTokenWidth = tokenStyle.width;
  9202. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  9203. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  9204. token.percentWidth = styleTokenWidth;
  9205. pendingList.push(token);
  9206. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9207. }
  9208. else {
  9209. if (tokenWidthNotSpecified) {
  9210. var textBackgroundColor = tokenStyle.backgroundColor;
  9211. var bgImg = textBackgroundColor && textBackgroundColor.image;
  9212. if (bgImg) {
  9213. bgImg = findExistImage(bgImg);
  9214. if (isImageReady(bgImg)) {
  9215. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  9216. }
  9217. }
  9218. }
  9219. var remainTruncWidth = truncate && topWidth != null
  9220. ? topWidth - lineWidth : null;
  9221. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  9222. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  9223. token.text = '';
  9224. token.width = token.contentWidth = 0;
  9225. }
  9226. else {
  9227. truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  9228. token.text = tmpTruncateOut.text;
  9229. contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
  9230. token.width = token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9231. }
  9232. }
  9233. else {
  9234. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9235. }
  9236. }
  9237. token.width += paddingH;
  9238. lineWidth += token.width;
  9239. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  9240. }
  9241. finishLine(line, lineWidth, lineHeight);
  9242. }
  9243. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  9244. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  9245. contentBlock.contentHeight = calculatedHeight;
  9246. contentBlock.contentWidth = calculatedWidth;
  9247. contentBlock.outerWidth += stlPaddingH;
  9248. contentBlock.outerHeight += stlPaddingV;
  9249. for (var i = 0; i < pendingList.length; i++) {
  9250. var token = pendingList[i];
  9251. var percentWidth = token.percentWidth;
  9252. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  9253. }
  9254. return contentBlock;
  9255. }
  9256. function pushTokens(block, str, style, wrapInfo, styleName) {
  9257. var isEmptyStr = str === '';
  9258. var tokenStyle = styleName && style.rich[styleName] || {};
  9259. var lines = block.lines;
  9260. var font = tokenStyle.font || style.font;
  9261. var newLine = false;
  9262. var strLines;
  9263. var linesWidths;
  9264. if (wrapInfo) {
  9265. var tokenPadding = tokenStyle.padding;
  9266. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  9267. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  9268. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  9269. if (lines.length > 0) {
  9270. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  9271. strLines = str.split('\n');
  9272. newLine = true;
  9273. }
  9274. }
  9275. wrapInfo.accumWidth = outerWidth_1;
  9276. }
  9277. else {
  9278. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  9279. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  9280. linesWidths = res.linesWidths;
  9281. strLines = res.lines;
  9282. }
  9283. }
  9284. if (!strLines) {
  9285. strLines = str.split('\n');
  9286. }
  9287. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9288. for (var i = 0; i < strLines.length; i++) {
  9289. var text = strLines[i];
  9290. var token = new RichTextToken();
  9291. token.styleName = styleName;
  9292. token.text = text;
  9293. token.isLineHolder = !text && !isEmptyStr;
  9294. if (typeof tokenStyle.width === 'number') {
  9295. token.width = tokenStyle.width;
  9296. }
  9297. else {
  9298. token.width = linesWidths
  9299. ? linesWidths[i]
  9300. : measureWidth(fontMeasureInfo, text);
  9301. }
  9302. if (!i && !newLine) {
  9303. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  9304. var tokensLen = tokens.length;
  9305. (tokensLen === 1 && tokens[0].isLineHolder)
  9306. ? (tokens[0] = token)
  9307. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  9308. }
  9309. else {
  9310. lines.push(new RichTextLine([token]));
  9311. }
  9312. }
  9313. }
  9314. function isAlphabeticLetter(ch) {
  9315. var code = ch.charCodeAt(0);
  9316. return code >= 0x20 && code <= 0x24F
  9317. || code >= 0x370 && code <= 0x10FF
  9318. || code >= 0x1200 && code <= 0x13FF
  9319. || code >= 0x1E00 && code <= 0x206F;
  9320. }
  9321. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  9322. obj[ch] = true;
  9323. return obj;
  9324. }, {});
  9325. function isWordBreakChar(ch) {
  9326. if (isAlphabeticLetter(ch)) {
  9327. if (breakCharMap[ch]) {
  9328. return true;
  9329. }
  9330. return false;
  9331. }
  9332. return true;
  9333. }
  9334. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  9335. var lines = [];
  9336. var linesWidths = [];
  9337. var line = '';
  9338. var currentWord = '';
  9339. var currentWordWidth = 0;
  9340. var accumWidth = 0;
  9341. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9342. for (var i = 0; i < text.length; i++) {
  9343. var ch = text.charAt(i);
  9344. if (ch === '\n') {
  9345. if (currentWord) {
  9346. line += currentWord;
  9347. accumWidth += currentWordWidth;
  9348. }
  9349. lines.push(line);
  9350. linesWidths.push(accumWidth);
  9351. line = '';
  9352. currentWord = '';
  9353. currentWordWidth = 0;
  9354. accumWidth = 0;
  9355. continue;
  9356. }
  9357. var chWidth = measureCharWidth(fontMeasureInfo, ch.charCodeAt(0));
  9358. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  9359. if (!lines.length
  9360. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  9361. : accumWidth + chWidth > lineWidth) {
  9362. if (!accumWidth) {
  9363. if (inWord) {
  9364. lines.push(currentWord);
  9365. linesWidths.push(currentWordWidth);
  9366. currentWord = ch;
  9367. currentWordWidth = chWidth;
  9368. }
  9369. else {
  9370. lines.push(ch);
  9371. linesWidths.push(chWidth);
  9372. }
  9373. }
  9374. else if (line || currentWord) {
  9375. if (inWord) {
  9376. if (!line) {
  9377. line = currentWord;
  9378. currentWord = '';
  9379. currentWordWidth = 0;
  9380. accumWidth = currentWordWidth;
  9381. }
  9382. lines.push(line);
  9383. linesWidths.push(accumWidth - currentWordWidth);
  9384. currentWord += ch;
  9385. currentWordWidth += chWidth;
  9386. line = '';
  9387. accumWidth = currentWordWidth;
  9388. }
  9389. else {
  9390. if (currentWord) {
  9391. line += currentWord;
  9392. currentWord = '';
  9393. currentWordWidth = 0;
  9394. }
  9395. lines.push(line);
  9396. linesWidths.push(accumWidth);
  9397. line = ch;
  9398. accumWidth = chWidth;
  9399. }
  9400. }
  9401. continue;
  9402. }
  9403. accumWidth += chWidth;
  9404. if (inWord) {
  9405. currentWord += ch;
  9406. currentWordWidth += chWidth;
  9407. }
  9408. else {
  9409. if (currentWord) {
  9410. line += currentWord;
  9411. currentWord = '';
  9412. currentWordWidth = 0;
  9413. }
  9414. line += ch;
  9415. }
  9416. }
  9417. if (currentWord) {
  9418. line += currentWord;
  9419. }
  9420. if (line) {
  9421. lines.push(line);
  9422. linesWidths.push(accumWidth);
  9423. }
  9424. if (lines.length === 1) {
  9425. accumWidth += lastAccumWidth;
  9426. }
  9427. return {
  9428. accumWidth: accumWidth,
  9429. lines: lines,
  9430. linesWidths: linesWidths
  9431. };
  9432. }
  9433. function calcInnerTextOverflowArea(out, overflowRect, baseX, baseY, textAlign, textVerticalAlign) {
  9434. out.baseX = baseX;
  9435. out.baseY = baseY;
  9436. out.outerWidth = out.outerHeight = null;
  9437. if (!overflowRect) {
  9438. return;
  9439. }
  9440. var textWidth = overflowRect.width * 2;
  9441. var textHeight = overflowRect.height * 2;
  9442. BoundingRect.set(tmpCITCTextRect, adjustTextX(baseX, textWidth, textAlign), adjustTextY(baseY, textHeight, textVerticalAlign), textWidth, textHeight);
  9443. BoundingRect.intersect(overflowRect, tmpCITCTextRect, null, tmpCITCIntersectRectOpt);
  9444. var outIntersectRect = tmpCITCIntersectRectOpt.outIntersectRect;
  9445. out.outerWidth = outIntersectRect.width;
  9446. out.outerHeight = outIntersectRect.height;
  9447. out.baseX = adjustTextX(outIntersectRect.x, outIntersectRect.width, textAlign, true);
  9448. out.baseY = adjustTextY(outIntersectRect.y, outIntersectRect.height, textVerticalAlign, true);
  9449. }
  9450. var tmpCITCTextRect = new BoundingRect(0, 0, 0, 0);
  9451. var tmpCITCIntersectRectOpt = { outIntersectRect: {}, clamp: true };
  9452. function formatText(text) {
  9453. return text != null ? (text += '') : (text = '');
  9454. }
  9455. function tSpanCreateBoundingRect(style) {
  9456. var text = formatText(style.text);
  9457. var font = style.font;
  9458. var contentWidth = measureWidth(ensureFontMeasureInfo(font), text);
  9459. var contentHeight = getLineHeight(font);
  9460. return tSpanCreateBoundingRect2(style, contentWidth, contentHeight, null);
  9461. }
  9462. function tSpanCreateBoundingRect2(style, contentWidth, contentHeight, forceLineWidth) {
  9463. var rect = new BoundingRect(adjustTextX(style.x || 0, contentWidth, style.textAlign), adjustTextY(style.y || 0, contentHeight, style.textBaseline), contentWidth, contentHeight);
  9464. var lineWidth = forceLineWidth != null
  9465. ? forceLineWidth
  9466. : (tSpanHasStroke(style) ? style.lineWidth : 0);
  9467. if (lineWidth > 0) {
  9468. rect.x -= lineWidth / 2;
  9469. rect.y -= lineWidth / 2;
  9470. rect.width += lineWidth;
  9471. rect.height += lineWidth;
  9472. }
  9473. return rect;
  9474. }
  9475. function tSpanHasStroke(style) {
  9476. var stroke = style.stroke;
  9477. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  9478. }
  9479. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  9480. var DEFAULT_COMMON_STYLE = {
  9481. shadowBlur: 0,
  9482. shadowOffsetX: 0,
  9483. shadowOffsetY: 0,
  9484. shadowColor: '#000',
  9485. opacity: 1,
  9486. blend: 'source-over'
  9487. };
  9488. var DEFAULT_COMMON_ANIMATION_PROPS = {
  9489. style: {
  9490. shadowBlur: true,
  9491. shadowOffsetX: true,
  9492. shadowOffsetY: true,
  9493. shadowColor: true,
  9494. opacity: true
  9495. }
  9496. };
  9497. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  9498. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  9499. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  9500. var Displayable = (function (_super) {
  9501. __extends(Displayable, _super);
  9502. function Displayable(props) {
  9503. return _super.call(this, props) || this;
  9504. }
  9505. Displayable.prototype._init = function (props) {
  9506. var keysArr = keys(props);
  9507. for (var i = 0; i < keysArr.length; i++) {
  9508. var key = keysArr[i];
  9509. if (key === 'style') {
  9510. this.useStyle(props[key]);
  9511. }
  9512. else {
  9513. _super.prototype.attrKV.call(this, key, props[key]);
  9514. }
  9515. }
  9516. if (!this.style) {
  9517. this.useStyle({});
  9518. }
  9519. };
  9520. Displayable.prototype.beforeBrush = function () { };
  9521. Displayable.prototype.afterBrush = function () { };
  9522. Displayable.prototype.innerBeforeBrush = function () { };
  9523. Displayable.prototype.innerAfterBrush = function () { };
  9524. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  9525. var m = this.transform;
  9526. if (this.ignore
  9527. || this.invisible
  9528. || this.style.opacity === 0
  9529. || (this.culling
  9530. && isDisplayableCulled(this, viewWidth, viewHeight))
  9531. || (m && !m[0] && !m[3])) {
  9532. return false;
  9533. }
  9534. if (considerClipPath && this.__clipPaths && this.__clipPaths.length) {
  9535. for (var i = 0; i < this.__clipPaths.length; ++i) {
  9536. if (this.__clipPaths[i].isZeroArea()) {
  9537. return false;
  9538. }
  9539. }
  9540. }
  9541. if (considerAncestors && this.parent) {
  9542. var parent_1 = this.parent;
  9543. while (parent_1) {
  9544. if (parent_1.ignore) {
  9545. return false;
  9546. }
  9547. parent_1 = parent_1.parent;
  9548. }
  9549. }
  9550. return true;
  9551. };
  9552. Displayable.prototype.contain = function (x, y) {
  9553. return this.rectContain(x, y);
  9554. };
  9555. Displayable.prototype.traverse = function (cb, context) {
  9556. cb.call(context, this);
  9557. };
  9558. Displayable.prototype.rectContain = function (x, y) {
  9559. var coord = this.transformCoordToLocal(x, y);
  9560. var rect = this.getBoundingRect();
  9561. return rect.contain(coord[0], coord[1]);
  9562. };
  9563. Displayable.prototype.getPaintRect = function () {
  9564. var rect = this._paintRect;
  9565. if (!this._paintRect || this.__dirty) {
  9566. var transform = this.transform;
  9567. var elRect = this.getBoundingRect();
  9568. var style = this.style;
  9569. var shadowSize = style.shadowBlur || 0;
  9570. var shadowOffsetX = style.shadowOffsetX || 0;
  9571. var shadowOffsetY = style.shadowOffsetY || 0;
  9572. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  9573. if (transform) {
  9574. BoundingRect.applyTransform(rect, elRect, transform);
  9575. }
  9576. else {
  9577. rect.copy(elRect);
  9578. }
  9579. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  9580. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  9581. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  9582. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  9583. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  9584. }
  9585. var tolerance = this.dirtyRectTolerance;
  9586. if (!rect.isZero()) {
  9587. rect.x = Math.floor(rect.x - tolerance);
  9588. rect.y = Math.floor(rect.y - tolerance);
  9589. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  9590. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  9591. }
  9592. }
  9593. return rect;
  9594. };
  9595. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  9596. if (paintRect) {
  9597. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  9598. this._prevPaintRect.copy(paintRect);
  9599. }
  9600. else {
  9601. this._prevPaintRect = null;
  9602. }
  9603. };
  9604. Displayable.prototype.getPrevPaintRect = function () {
  9605. return this._prevPaintRect;
  9606. };
  9607. Displayable.prototype.animateStyle = function (loop) {
  9608. return this.animate('style', loop);
  9609. };
  9610. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  9611. if (targetKey === 'style') {
  9612. this.dirtyStyle();
  9613. }
  9614. else {
  9615. this.markRedraw();
  9616. }
  9617. };
  9618. Displayable.prototype.attrKV = function (key, value) {
  9619. if (key !== 'style') {
  9620. _super.prototype.attrKV.call(this, key, value);
  9621. }
  9622. else {
  9623. if (!this.style) {
  9624. this.useStyle(value);
  9625. }
  9626. else {
  9627. this.setStyle(value);
  9628. }
  9629. }
  9630. };
  9631. Displayable.prototype.setStyle = function (keyOrObj, value) {
  9632. if (typeof keyOrObj === 'string') {
  9633. this.style[keyOrObj] = value;
  9634. }
  9635. else {
  9636. extend(this.style, keyOrObj);
  9637. }
  9638. this.dirtyStyle();
  9639. return this;
  9640. };
  9641. Displayable.prototype.dirtyStyle = function (notRedraw) {
  9642. if (!notRedraw) {
  9643. this.markRedraw();
  9644. }
  9645. this.__dirty |= STYLE_CHANGED_BIT;
  9646. if (this._rect) {
  9647. this._rect = null;
  9648. }
  9649. };
  9650. Displayable.prototype.dirty = function () {
  9651. this.dirtyStyle();
  9652. };
  9653. Displayable.prototype.styleChanged = function () {
  9654. return !!(this.__dirty & STYLE_CHANGED_BIT);
  9655. };
  9656. Displayable.prototype.styleUpdated = function () {
  9657. this.__dirty &= ~STYLE_CHANGED_BIT;
  9658. };
  9659. Displayable.prototype.createStyle = function (obj) {
  9660. return createObject(DEFAULT_COMMON_STYLE, obj);
  9661. };
  9662. Displayable.prototype.useStyle = function (obj) {
  9663. if (!obj[STYLE_MAGIC_KEY]) {
  9664. obj = this.createStyle(obj);
  9665. }
  9666. if (this.__inHover) {
  9667. this.__hoverStyle = obj;
  9668. }
  9669. else {
  9670. this.style = obj;
  9671. }
  9672. this.dirtyStyle();
  9673. };
  9674. Displayable.prototype.isStyleObject = function (obj) {
  9675. return obj[STYLE_MAGIC_KEY];
  9676. };
  9677. Displayable.prototype._innerSaveToNormal = function (toState) {
  9678. _super.prototype._innerSaveToNormal.call(this, toState);
  9679. var normalState = this._normalState;
  9680. if (toState.style && !normalState.style) {
  9681. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  9682. }
  9683. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  9684. };
  9685. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9686. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9687. var needsRestoreToNormal = !(state && keepCurrentStates);
  9688. var targetStyle;
  9689. if (state && state.style) {
  9690. if (transition) {
  9691. if (keepCurrentStates) {
  9692. targetStyle = state.style;
  9693. }
  9694. else {
  9695. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  9696. this._mergeStyle(targetStyle, state.style);
  9697. }
  9698. }
  9699. else {
  9700. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  9701. this._mergeStyle(targetStyle, state.style);
  9702. }
  9703. }
  9704. else if (needsRestoreToNormal) {
  9705. targetStyle = normalState.style;
  9706. }
  9707. if (targetStyle) {
  9708. if (transition) {
  9709. var sourceStyle = this.style;
  9710. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  9711. if (needsRestoreToNormal) {
  9712. var changedKeys = keys(sourceStyle);
  9713. for (var i = 0; i < changedKeys.length; i++) {
  9714. var key = changedKeys[i];
  9715. if (key in targetStyle) {
  9716. targetStyle[key] = targetStyle[key];
  9717. this.style[key] = sourceStyle[key];
  9718. }
  9719. }
  9720. }
  9721. var targetKeys = keys(targetStyle);
  9722. for (var i = 0; i < targetKeys.length; i++) {
  9723. var key = targetKeys[i];
  9724. this.style[key] = this.style[key];
  9725. }
  9726. this._transitionState(stateName, {
  9727. style: targetStyle
  9728. }, animationCfg, this.getAnimationStyleProps());
  9729. }
  9730. else {
  9731. this.useStyle(targetStyle);
  9732. }
  9733. }
  9734. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  9735. for (var i = 0; i < statesKeys.length; i++) {
  9736. var key = statesKeys[i];
  9737. if (state && state[key] != null) {
  9738. this[key] = state[key];
  9739. }
  9740. else if (needsRestoreToNormal) {
  9741. if (normalState[key] != null) {
  9742. this[key] = normalState[key];
  9743. }
  9744. }
  9745. }
  9746. };
  9747. Displayable.prototype._mergeStates = function (states) {
  9748. var mergedState = _super.prototype._mergeStates.call(this, states);
  9749. var mergedStyle;
  9750. for (var i = 0; i < states.length; i++) {
  9751. var state = states[i];
  9752. if (state.style) {
  9753. mergedStyle = mergedStyle || {};
  9754. this._mergeStyle(mergedStyle, state.style);
  9755. }
  9756. }
  9757. if (mergedStyle) {
  9758. mergedState.style = mergedStyle;
  9759. }
  9760. return mergedState;
  9761. };
  9762. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  9763. extend(targetStyle, sourceStyle);
  9764. return targetStyle;
  9765. };
  9766. Displayable.prototype.getAnimationStyleProps = function () {
  9767. return DEFAULT_COMMON_ANIMATION_PROPS;
  9768. };
  9769. Displayable.initDefaultProps = (function () {
  9770. var dispProto = Displayable.prototype;
  9771. dispProto.type = 'displayable';
  9772. dispProto.invisible = false;
  9773. dispProto.z = 0;
  9774. dispProto.z2 = 0;
  9775. dispProto.zlevel = 0;
  9776. dispProto.culling = false;
  9777. dispProto.cursor = 'pointer';
  9778. dispProto.rectHover = false;
  9779. dispProto.incremental = false;
  9780. dispProto._rect = null;
  9781. dispProto.dirtyRectTolerance = 0;
  9782. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  9783. })();
  9784. return Displayable;
  9785. }(Element));
  9786. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  9787. var viewRect = new BoundingRect(0, 0, 0, 0);
  9788. function isDisplayableCulled(el, width, height) {
  9789. tmpRect$1.copy(el.getBoundingRect());
  9790. if (el.transform) {
  9791. tmpRect$1.applyTransform(el.transform);
  9792. }
  9793. viewRect.width = width;
  9794. viewRect.height = height;
  9795. return !tmpRect$1.intersect(viewRect);
  9796. }
  9797. var mathMin$2 = Math.min;
  9798. var mathMax$2 = Math.max;
  9799. var mathSin = Math.sin;
  9800. var mathCos = Math.cos;
  9801. var PI2 = Math.PI * 2;
  9802. var start = create();
  9803. var end = create();
  9804. var extremity = create();
  9805. function fromLine(x0, y0, x1, y1, min, max) {
  9806. min[0] = mathMin$2(x0, x1);
  9807. min[1] = mathMin$2(y0, y1);
  9808. max[0] = mathMax$2(x0, x1);
  9809. max[1] = mathMax$2(y0, y1);
  9810. }
  9811. var xDim = [];
  9812. var yDim = [];
  9813. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  9814. var cubicExtrema$1 = cubicExtrema;
  9815. var cubicAt$1 = cubicAt;
  9816. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  9817. min[0] = Infinity;
  9818. min[1] = Infinity;
  9819. max[0] = -Infinity;
  9820. max[1] = -Infinity;
  9821. for (var i = 0; i < n; i++) {
  9822. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  9823. min[0] = mathMin$2(x, min[0]);
  9824. max[0] = mathMax$2(x, max[0]);
  9825. }
  9826. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  9827. for (var i = 0; i < n; i++) {
  9828. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  9829. min[1] = mathMin$2(y, min[1]);
  9830. max[1] = mathMax$2(y, max[1]);
  9831. }
  9832. min[0] = mathMin$2(x0, min[0]);
  9833. max[0] = mathMax$2(x0, max[0]);
  9834. min[0] = mathMin$2(x3, min[0]);
  9835. max[0] = mathMax$2(x3, max[0]);
  9836. min[1] = mathMin$2(y0, min[1]);
  9837. max[1] = mathMax$2(y0, max[1]);
  9838. min[1] = mathMin$2(y3, min[1]);
  9839. max[1] = mathMax$2(y3, max[1]);
  9840. }
  9841. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  9842. var quadraticExtremum$1 = quadraticExtremum;
  9843. var quadraticAt$1 = quadraticAt;
  9844. var tx = mathMax$2(mathMin$2(quadraticExtremum$1(x0, x1, x2), 1), 0);
  9845. var ty = mathMax$2(mathMin$2(quadraticExtremum$1(y0, y1, y2), 1), 0);
  9846. var x = quadraticAt$1(x0, x1, x2, tx);
  9847. var y = quadraticAt$1(y0, y1, y2, ty);
  9848. min[0] = mathMin$2(x0, x2, x);
  9849. min[1] = mathMin$2(y0, y2, y);
  9850. max[0] = mathMax$2(x0, x2, x);
  9851. max[1] = mathMax$2(y0, y2, y);
  9852. }
  9853. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  9854. var vec2Min = min;
  9855. var vec2Max = max;
  9856. var diff = Math.abs(startAngle - endAngle);
  9857. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  9858. min$1[0] = x - rx;
  9859. min$1[1] = y - ry;
  9860. max$1[0] = x + rx;
  9861. max$1[1] = y + ry;
  9862. return;
  9863. }
  9864. start[0] = mathCos(startAngle) * rx + x;
  9865. start[1] = mathSin(startAngle) * ry + y;
  9866. end[0] = mathCos(endAngle) * rx + x;
  9867. end[1] = mathSin(endAngle) * ry + y;
  9868. vec2Min(min$1, start, end);
  9869. vec2Max(max$1, start, end);
  9870. startAngle = startAngle % (PI2);
  9871. if (startAngle < 0) {
  9872. startAngle = startAngle + PI2;
  9873. }
  9874. endAngle = endAngle % (PI2);
  9875. if (endAngle < 0) {
  9876. endAngle = endAngle + PI2;
  9877. }
  9878. if (startAngle > endAngle && !anticlockwise) {
  9879. endAngle += PI2;
  9880. }
  9881. else if (startAngle < endAngle && anticlockwise) {
  9882. startAngle += PI2;
  9883. }
  9884. if (anticlockwise) {
  9885. var tmp = endAngle;
  9886. endAngle = startAngle;
  9887. startAngle = tmp;
  9888. }
  9889. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  9890. if (angle > startAngle) {
  9891. extremity[0] = mathCos(angle) * rx + x;
  9892. extremity[1] = mathSin(angle) * ry + y;
  9893. vec2Min(min$1, extremity, min$1);
  9894. vec2Max(max$1, extremity, max$1);
  9895. }
  9896. }
  9897. }
  9898. var CMD = {
  9899. M: 1,
  9900. L: 2,
  9901. C: 3,
  9902. Q: 4,
  9903. A: 5,
  9904. Z: 6,
  9905. R: 7
  9906. };
  9907. var tmpOutX = [];
  9908. var tmpOutY = [];
  9909. var min$1 = [];
  9910. var max$1 = [];
  9911. var min2 = [];
  9912. var max2 = [];
  9913. var mathMin$3 = Math.min;
  9914. var mathMax$3 = Math.max;
  9915. var mathCos$1 = Math.cos;
  9916. var mathSin$1 = Math.sin;
  9917. var mathAbs$2 = Math.abs;
  9918. var PI = Math.PI;
  9919. var PI2$1 = PI * 2;
  9920. var hasTypedArray = typeof Float32Array !== 'undefined';
  9921. var tmpAngles = [];
  9922. function modPI2(radian) {
  9923. var n = Math.round(radian / PI * 1e8) / 1e8;
  9924. return (n % 2) * PI;
  9925. }
  9926. function normalizeArcAngles(angles, anticlockwise) {
  9927. var newStartAngle = modPI2(angles[0]);
  9928. if (newStartAngle < 0) {
  9929. newStartAngle += PI2$1;
  9930. }
  9931. var delta = newStartAngle - angles[0];
  9932. var newEndAngle = angles[1];
  9933. newEndAngle += delta;
  9934. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  9935. newEndAngle = newStartAngle + PI2$1;
  9936. }
  9937. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  9938. newEndAngle = newStartAngle - PI2$1;
  9939. }
  9940. else if (!anticlockwise && newStartAngle > newEndAngle) {
  9941. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  9942. }
  9943. else if (anticlockwise && newStartAngle < newEndAngle) {
  9944. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  9945. }
  9946. angles[0] = newStartAngle;
  9947. angles[1] = newEndAngle;
  9948. }
  9949. var PathProxy = (function () {
  9950. function PathProxy(notSaveData) {
  9951. this.dpr = 1;
  9952. this._xi = 0;
  9953. this._yi = 0;
  9954. this._x0 = 0;
  9955. this._y0 = 0;
  9956. this._len = 0;
  9957. if (notSaveData) {
  9958. this._saveData = false;
  9959. }
  9960. if (this._saveData) {
  9961. this.data = [];
  9962. }
  9963. }
  9964. PathProxy.prototype.increaseVersion = function () {
  9965. this._version++;
  9966. };
  9967. PathProxy.prototype.getVersion = function () {
  9968. return this._version;
  9969. };
  9970. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  9971. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  9972. if (segmentIgnoreThreshold > 0) {
  9973. this._ux = mathAbs$2(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  9974. this._uy = mathAbs$2(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  9975. }
  9976. };
  9977. PathProxy.prototype.setDPR = function (dpr) {
  9978. this.dpr = dpr;
  9979. };
  9980. PathProxy.prototype.setContext = function (ctx) {
  9981. this._ctx = ctx;
  9982. };
  9983. PathProxy.prototype.getContext = function () {
  9984. return this._ctx;
  9985. };
  9986. PathProxy.prototype.beginPath = function () {
  9987. this._ctx && this._ctx.beginPath();
  9988. this.reset();
  9989. return this;
  9990. };
  9991. PathProxy.prototype.reset = function () {
  9992. if (this._saveData) {
  9993. this._len = 0;
  9994. }
  9995. if (this._pathSegLen) {
  9996. this._pathSegLen = null;
  9997. this._pathLen = 0;
  9998. }
  9999. this._version++;
  10000. };
  10001. PathProxy.prototype.moveTo = function (x, y) {
  10002. this._drawPendingPt();
  10003. this.addData(CMD.M, x, y);
  10004. this._ctx && this._ctx.moveTo(x, y);
  10005. this._x0 = x;
  10006. this._y0 = y;
  10007. this._xi = x;
  10008. this._yi = y;
  10009. return this;
  10010. };
  10011. PathProxy.prototype.lineTo = function (x, y) {
  10012. var dx = mathAbs$2(x - this._xi);
  10013. var dy = mathAbs$2(y - this._yi);
  10014. var exceedUnit = dx > this._ux || dy > this._uy;
  10015. this.addData(CMD.L, x, y);
  10016. if (this._ctx && exceedUnit) {
  10017. this._ctx.lineTo(x, y);
  10018. }
  10019. if (exceedUnit) {
  10020. this._xi = x;
  10021. this._yi = y;
  10022. this._pendingPtDist = 0;
  10023. }
  10024. else {
  10025. var d2 = dx * dx + dy * dy;
  10026. if (d2 > this._pendingPtDist) {
  10027. this._pendingPtX = x;
  10028. this._pendingPtY = y;
  10029. this._pendingPtDist = d2;
  10030. }
  10031. }
  10032. return this;
  10033. };
  10034. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  10035. this._drawPendingPt();
  10036. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  10037. if (this._ctx) {
  10038. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10039. }
  10040. this._xi = x3;
  10041. this._yi = y3;
  10042. return this;
  10043. };
  10044. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  10045. this._drawPendingPt();
  10046. this.addData(CMD.Q, x1, y1, x2, y2);
  10047. if (this._ctx) {
  10048. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  10049. }
  10050. this._xi = x2;
  10051. this._yi = y2;
  10052. return this;
  10053. };
  10054. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  10055. this._drawPendingPt();
  10056. tmpAngles[0] = startAngle;
  10057. tmpAngles[1] = endAngle;
  10058. normalizeArcAngles(tmpAngles, anticlockwise);
  10059. startAngle = tmpAngles[0];
  10060. endAngle = tmpAngles[1];
  10061. var delta = endAngle - startAngle;
  10062. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  10063. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10064. this._xi = mathCos$1(endAngle) * r + cx;
  10065. this._yi = mathSin$1(endAngle) * r + cy;
  10066. return this;
  10067. };
  10068. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  10069. this._drawPendingPt();
  10070. if (this._ctx) {
  10071. this._ctx.arcTo(x1, y1, x2, y2, radius);
  10072. }
  10073. return this;
  10074. };
  10075. PathProxy.prototype.rect = function (x, y, w, h) {
  10076. this._drawPendingPt();
  10077. this._ctx && this._ctx.rect(x, y, w, h);
  10078. this.addData(CMD.R, x, y, w, h);
  10079. return this;
  10080. };
  10081. PathProxy.prototype.closePath = function () {
  10082. this._drawPendingPt();
  10083. this.addData(CMD.Z);
  10084. var ctx = this._ctx;
  10085. var x0 = this._x0;
  10086. var y0 = this._y0;
  10087. if (ctx) {
  10088. ctx.closePath();
  10089. }
  10090. this._xi = x0;
  10091. this._yi = y0;
  10092. return this;
  10093. };
  10094. PathProxy.prototype.fill = function (ctx) {
  10095. ctx && ctx.fill();
  10096. this.toStatic();
  10097. };
  10098. PathProxy.prototype.stroke = function (ctx) {
  10099. ctx && ctx.stroke();
  10100. this.toStatic();
  10101. };
  10102. PathProxy.prototype.len = function () {
  10103. return this._len;
  10104. };
  10105. PathProxy.prototype.setData = function (data) {
  10106. if (!this._saveData) {
  10107. return;
  10108. }
  10109. var len = data.length;
  10110. if (!(this.data && this.data.length === len) && hasTypedArray) {
  10111. this.data = new Float32Array(len);
  10112. }
  10113. for (var i = 0; i < len; i++) {
  10114. this.data[i] = data[i];
  10115. }
  10116. this._len = len;
  10117. };
  10118. PathProxy.prototype.appendPath = function (path) {
  10119. if (!this._saveData) {
  10120. return;
  10121. }
  10122. if (!(path instanceof Array)) {
  10123. path = [path];
  10124. }
  10125. var len = path.length;
  10126. var appendSize = 0;
  10127. var offset = this._len;
  10128. for (var i = 0; i < len; i++) {
  10129. appendSize += path[i].len();
  10130. }
  10131. var oldData = this.data;
  10132. if (hasTypedArray && (oldData instanceof Float32Array || !oldData)) {
  10133. this.data = new Float32Array(offset + appendSize);
  10134. if (offset > 0 && oldData) {
  10135. for (var k = 0; k < offset; k++) {
  10136. this.data[k] = oldData[k];
  10137. }
  10138. }
  10139. }
  10140. for (var i = 0; i < len; i++) {
  10141. var appendPathData = path[i].data;
  10142. for (var k = 0; k < appendPathData.length; k++) {
  10143. this.data[offset++] = appendPathData[k];
  10144. }
  10145. }
  10146. this._len = offset;
  10147. };
  10148. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  10149. if (!this._saveData) {
  10150. return;
  10151. }
  10152. var data = this.data;
  10153. if (this._len + arguments.length > data.length) {
  10154. this._expandData();
  10155. data = this.data;
  10156. }
  10157. for (var i = 0; i < arguments.length; i++) {
  10158. data[this._len++] = arguments[i];
  10159. }
  10160. };
  10161. PathProxy.prototype._drawPendingPt = function () {
  10162. if (this._pendingPtDist > 0) {
  10163. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  10164. this._pendingPtDist = 0;
  10165. }
  10166. };
  10167. PathProxy.prototype._expandData = function () {
  10168. if (!(this.data instanceof Array)) {
  10169. var newData = [];
  10170. for (var i = 0; i < this._len; i++) {
  10171. newData[i] = this.data[i];
  10172. }
  10173. this.data = newData;
  10174. }
  10175. };
  10176. PathProxy.prototype.toStatic = function () {
  10177. if (!this._saveData) {
  10178. return;
  10179. }
  10180. this._drawPendingPt();
  10181. var data = this.data;
  10182. if (data instanceof Array) {
  10183. data.length = this._len;
  10184. if (hasTypedArray && this._len > 11) {
  10185. this.data = new Float32Array(data);
  10186. }
  10187. }
  10188. };
  10189. PathProxy.prototype.getBoundingRect = function () {
  10190. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  10191. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  10192. var data = this.data;
  10193. var xi = 0;
  10194. var yi = 0;
  10195. var x0 = 0;
  10196. var y0 = 0;
  10197. var i;
  10198. for (i = 0; i < this._len;) {
  10199. var cmd = data[i++];
  10200. var isFirst = i === 1;
  10201. if (isFirst) {
  10202. xi = data[i];
  10203. yi = data[i + 1];
  10204. x0 = xi;
  10205. y0 = yi;
  10206. }
  10207. switch (cmd) {
  10208. case CMD.M:
  10209. xi = x0 = data[i++];
  10210. yi = y0 = data[i++];
  10211. min2[0] = x0;
  10212. min2[1] = y0;
  10213. max2[0] = x0;
  10214. max2[1] = y0;
  10215. break;
  10216. case CMD.L:
  10217. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  10218. xi = data[i++];
  10219. yi = data[i++];
  10220. break;
  10221. case CMD.C:
  10222. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  10223. xi = data[i++];
  10224. yi = data[i++];
  10225. break;
  10226. case CMD.Q:
  10227. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  10228. xi = data[i++];
  10229. yi = data[i++];
  10230. break;
  10231. case CMD.A:
  10232. var cx = data[i++];
  10233. var cy = data[i++];
  10234. var rx = data[i++];
  10235. var ry = data[i++];
  10236. var startAngle = data[i++];
  10237. var endAngle = data[i++] + startAngle;
  10238. i += 1;
  10239. var anticlockwise = !data[i++];
  10240. if (isFirst) {
  10241. x0 = mathCos$1(startAngle) * rx + cx;
  10242. y0 = mathSin$1(startAngle) * ry + cy;
  10243. }
  10244. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  10245. xi = mathCos$1(endAngle) * rx + cx;
  10246. yi = mathSin$1(endAngle) * ry + cy;
  10247. break;
  10248. case CMD.R:
  10249. x0 = xi = data[i++];
  10250. y0 = yi = data[i++];
  10251. var width = data[i++];
  10252. var height = data[i++];
  10253. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  10254. break;
  10255. case CMD.Z:
  10256. xi = x0;
  10257. yi = y0;
  10258. break;
  10259. }
  10260. min(min$1, min$1, min2);
  10261. max(max$1, max$1, max2);
  10262. }
  10263. if (i === 0) {
  10264. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  10265. }
  10266. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  10267. };
  10268. PathProxy.prototype._calculateLength = function () {
  10269. var data = this.data;
  10270. var len = this._len;
  10271. var ux = this._ux;
  10272. var uy = this._uy;
  10273. var xi = 0;
  10274. var yi = 0;
  10275. var x0 = 0;
  10276. var y0 = 0;
  10277. if (!this._pathSegLen) {
  10278. this._pathSegLen = [];
  10279. }
  10280. var pathSegLen = this._pathSegLen;
  10281. var pathTotalLen = 0;
  10282. var segCount = 0;
  10283. for (var i = 0; i < len;) {
  10284. var cmd = data[i++];
  10285. var isFirst = i === 1;
  10286. if (isFirst) {
  10287. xi = data[i];
  10288. yi = data[i + 1];
  10289. x0 = xi;
  10290. y0 = yi;
  10291. }
  10292. var l = -1;
  10293. switch (cmd) {
  10294. case CMD.M:
  10295. xi = x0 = data[i++];
  10296. yi = y0 = data[i++];
  10297. break;
  10298. case CMD.L: {
  10299. var x2 = data[i++];
  10300. var y2 = data[i++];
  10301. var dx = x2 - xi;
  10302. var dy = y2 - yi;
  10303. if (mathAbs$2(dx) > ux || mathAbs$2(dy) > uy || i === len - 1) {
  10304. l = Math.sqrt(dx * dx + dy * dy);
  10305. xi = x2;
  10306. yi = y2;
  10307. }
  10308. break;
  10309. }
  10310. case CMD.C: {
  10311. var x1 = data[i++];
  10312. var y1 = data[i++];
  10313. var x2 = data[i++];
  10314. var y2 = data[i++];
  10315. var x3 = data[i++];
  10316. var y3 = data[i++];
  10317. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  10318. xi = x3;
  10319. yi = y3;
  10320. break;
  10321. }
  10322. case CMD.Q: {
  10323. var x1 = data[i++];
  10324. var y1 = data[i++];
  10325. var x2 = data[i++];
  10326. var y2 = data[i++];
  10327. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  10328. xi = x2;
  10329. yi = y2;
  10330. break;
  10331. }
  10332. case CMD.A:
  10333. var cx = data[i++];
  10334. var cy = data[i++];
  10335. var rx = data[i++];
  10336. var ry = data[i++];
  10337. var startAngle = data[i++];
  10338. var delta = data[i++];
  10339. var endAngle = delta + startAngle;
  10340. i += 1;
  10341. if (isFirst) {
  10342. x0 = mathCos$1(startAngle) * rx + cx;
  10343. y0 = mathSin$1(startAngle) * ry + cy;
  10344. }
  10345. l = mathMax$3(rx, ry) * mathMin$3(PI2$1, Math.abs(delta));
  10346. xi = mathCos$1(endAngle) * rx + cx;
  10347. yi = mathSin$1(endAngle) * ry + cy;
  10348. break;
  10349. case CMD.R: {
  10350. x0 = xi = data[i++];
  10351. y0 = yi = data[i++];
  10352. var width = data[i++];
  10353. var height = data[i++];
  10354. l = width * 2 + height * 2;
  10355. break;
  10356. }
  10357. case CMD.Z: {
  10358. var dx = x0 - xi;
  10359. var dy = y0 - yi;
  10360. l = Math.sqrt(dx * dx + dy * dy);
  10361. xi = x0;
  10362. yi = y0;
  10363. break;
  10364. }
  10365. }
  10366. if (l >= 0) {
  10367. pathSegLen[segCount++] = l;
  10368. pathTotalLen += l;
  10369. }
  10370. }
  10371. this._pathLen = pathTotalLen;
  10372. return pathTotalLen;
  10373. };
  10374. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  10375. var d = this.data;
  10376. var ux = this._ux;
  10377. var uy = this._uy;
  10378. var len = this._len;
  10379. var x0;
  10380. var y0;
  10381. var xi;
  10382. var yi;
  10383. var x;
  10384. var y;
  10385. var drawPart = percent < 1;
  10386. var pathSegLen;
  10387. var pathTotalLen;
  10388. var accumLength = 0;
  10389. var segCount = 0;
  10390. var displayedLength;
  10391. var pendingPtDist = 0;
  10392. var pendingPtX;
  10393. var pendingPtY;
  10394. if (drawPart) {
  10395. if (!this._pathSegLen) {
  10396. this._calculateLength();
  10397. }
  10398. pathSegLen = this._pathSegLen;
  10399. pathTotalLen = this._pathLen;
  10400. displayedLength = percent * pathTotalLen;
  10401. if (!displayedLength) {
  10402. return;
  10403. }
  10404. }
  10405. lo: for (var i = 0; i < len;) {
  10406. var cmd = d[i++];
  10407. var isFirst = i === 1;
  10408. if (isFirst) {
  10409. xi = d[i];
  10410. yi = d[i + 1];
  10411. x0 = xi;
  10412. y0 = yi;
  10413. }
  10414. if (cmd !== CMD.L && pendingPtDist > 0) {
  10415. ctx.lineTo(pendingPtX, pendingPtY);
  10416. pendingPtDist = 0;
  10417. }
  10418. switch (cmd) {
  10419. case CMD.M:
  10420. x0 = xi = d[i++];
  10421. y0 = yi = d[i++];
  10422. ctx.moveTo(xi, yi);
  10423. break;
  10424. case CMD.L: {
  10425. x = d[i++];
  10426. y = d[i++];
  10427. var dx = mathAbs$2(x - xi);
  10428. var dy = mathAbs$2(y - yi);
  10429. if (dx > ux || dy > uy) {
  10430. if (drawPart) {
  10431. var l = pathSegLen[segCount++];
  10432. if (accumLength + l > displayedLength) {
  10433. var t = (displayedLength - accumLength) / l;
  10434. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  10435. break lo;
  10436. }
  10437. accumLength += l;
  10438. }
  10439. ctx.lineTo(x, y);
  10440. xi = x;
  10441. yi = y;
  10442. pendingPtDist = 0;
  10443. }
  10444. else {
  10445. var d2 = dx * dx + dy * dy;
  10446. if (d2 > pendingPtDist) {
  10447. pendingPtX = x;
  10448. pendingPtY = y;
  10449. pendingPtDist = d2;
  10450. }
  10451. }
  10452. break;
  10453. }
  10454. case CMD.C: {
  10455. var x1 = d[i++];
  10456. var y1 = d[i++];
  10457. var x2 = d[i++];
  10458. var y2 = d[i++];
  10459. var x3 = d[i++];
  10460. var y3 = d[i++];
  10461. if (drawPart) {
  10462. var l = pathSegLen[segCount++];
  10463. if (accumLength + l > displayedLength) {
  10464. var t = (displayedLength - accumLength) / l;
  10465. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  10466. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  10467. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  10468. break lo;
  10469. }
  10470. accumLength += l;
  10471. }
  10472. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10473. xi = x3;
  10474. yi = y3;
  10475. break;
  10476. }
  10477. case CMD.Q: {
  10478. var x1 = d[i++];
  10479. var y1 = d[i++];
  10480. var x2 = d[i++];
  10481. var y2 = d[i++];
  10482. if (drawPart) {
  10483. var l = pathSegLen[segCount++];
  10484. if (accumLength + l > displayedLength) {
  10485. var t = (displayedLength - accumLength) / l;
  10486. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  10487. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  10488. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  10489. break lo;
  10490. }
  10491. accumLength += l;
  10492. }
  10493. ctx.quadraticCurveTo(x1, y1, x2, y2);
  10494. xi = x2;
  10495. yi = y2;
  10496. break;
  10497. }
  10498. case CMD.A:
  10499. var cx = d[i++];
  10500. var cy = d[i++];
  10501. var rx = d[i++];
  10502. var ry = d[i++];
  10503. var startAngle = d[i++];
  10504. var delta = d[i++];
  10505. var psi = d[i++];
  10506. var anticlockwise = !d[i++];
  10507. var r = (rx > ry) ? rx : ry;
  10508. var isEllipse = mathAbs$2(rx - ry) > 1e-3;
  10509. var endAngle = startAngle + delta;
  10510. var breakBuild = false;
  10511. if (drawPart) {
  10512. var l = pathSegLen[segCount++];
  10513. if (accumLength + l > displayedLength) {
  10514. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  10515. breakBuild = true;
  10516. }
  10517. accumLength += l;
  10518. }
  10519. if (isEllipse && ctx.ellipse) {
  10520. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  10521. }
  10522. else {
  10523. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10524. }
  10525. if (breakBuild) {
  10526. break lo;
  10527. }
  10528. if (isFirst) {
  10529. x0 = mathCos$1(startAngle) * rx + cx;
  10530. y0 = mathSin$1(startAngle) * ry + cy;
  10531. }
  10532. xi = mathCos$1(endAngle) * rx + cx;
  10533. yi = mathSin$1(endAngle) * ry + cy;
  10534. break;
  10535. case CMD.R:
  10536. x0 = xi = d[i];
  10537. y0 = yi = d[i + 1];
  10538. x = d[i++];
  10539. y = d[i++];
  10540. var width = d[i++];
  10541. var height = d[i++];
  10542. if (drawPart) {
  10543. var l = pathSegLen[segCount++];
  10544. if (accumLength + l > displayedLength) {
  10545. var d_1 = displayedLength - accumLength;
  10546. ctx.moveTo(x, y);
  10547. ctx.lineTo(x + mathMin$3(d_1, width), y);
  10548. d_1 -= width;
  10549. if (d_1 > 0) {
  10550. ctx.lineTo(x + width, y + mathMin$3(d_1, height));
  10551. }
  10552. d_1 -= height;
  10553. if (d_1 > 0) {
  10554. ctx.lineTo(x + mathMax$3(width - d_1, 0), y + height);
  10555. }
  10556. d_1 -= width;
  10557. if (d_1 > 0) {
  10558. ctx.lineTo(x, y + mathMax$3(height - d_1, 0));
  10559. }
  10560. break lo;
  10561. }
  10562. accumLength += l;
  10563. }
  10564. ctx.rect(x, y, width, height);
  10565. break;
  10566. case CMD.Z:
  10567. if (drawPart) {
  10568. var l = pathSegLen[segCount++];
  10569. if (accumLength + l > displayedLength) {
  10570. var t = (displayedLength - accumLength) / l;
  10571. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  10572. break lo;
  10573. }
  10574. accumLength += l;
  10575. }
  10576. ctx.closePath();
  10577. xi = x0;
  10578. yi = y0;
  10579. }
  10580. }
  10581. };
  10582. PathProxy.prototype.clone = function () {
  10583. var newProxy = new PathProxy();
  10584. var data = this.data;
  10585. newProxy.data = data.slice ? data.slice()
  10586. : Array.prototype.slice.call(data);
  10587. newProxy._len = this._len;
  10588. return newProxy;
  10589. };
  10590. PathProxy.prototype.canSave = function () {
  10591. return !!this._saveData;
  10592. };
  10593. PathProxy.CMD = CMD;
  10594. PathProxy.initDefaultProps = (function () {
  10595. var proto = PathProxy.prototype;
  10596. proto._saveData = true;
  10597. proto._ux = 0;
  10598. proto._uy = 0;
  10599. proto._pendingPtDist = 0;
  10600. proto._version = 0;
  10601. })();
  10602. return PathProxy;
  10603. }());
  10604. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  10605. if (lineWidth === 0) {
  10606. return false;
  10607. }
  10608. var _l = lineWidth;
  10609. var _a = 0;
  10610. var _b = x0;
  10611. if ((y > y0 + _l && y > y1 + _l)
  10612. || (y < y0 - _l && y < y1 - _l)
  10613. || (x > x0 + _l && x > x1 + _l)
  10614. || (x < x0 - _l && x < x1 - _l)) {
  10615. return false;
  10616. }
  10617. if (x0 !== x1) {
  10618. _a = (y0 - y1) / (x0 - x1);
  10619. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  10620. }
  10621. else {
  10622. return Math.abs(x - x0) <= _l / 2;
  10623. }
  10624. var tmp = _a * x - y + _b;
  10625. var _s = tmp * tmp / (_a * _a + 1);
  10626. return _s <= _l / 2 * _l / 2;
  10627. }
  10628. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  10629. if (lineWidth === 0) {
  10630. return false;
  10631. }
  10632. var _l = lineWidth;
  10633. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  10634. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  10635. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  10636. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  10637. return false;
  10638. }
  10639. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  10640. return d <= _l / 2;
  10641. }
  10642. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  10643. if (lineWidth === 0) {
  10644. return false;
  10645. }
  10646. var _l = lineWidth;
  10647. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  10648. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  10649. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  10650. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  10651. return false;
  10652. }
  10653. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  10654. return d <= _l / 2;
  10655. }
  10656. var PI2$2 = Math.PI * 2;
  10657. function normalizeRadian(angle) {
  10658. angle %= PI2$2;
  10659. if (angle < 0) {
  10660. angle += PI2$2;
  10661. }
  10662. return angle;
  10663. }
  10664. var PI2$3 = Math.PI * 2;
  10665. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  10666. if (lineWidth === 0) {
  10667. return false;
  10668. }
  10669. var _l = lineWidth;
  10670. x -= cx;
  10671. y -= cy;
  10672. var d = Math.sqrt(x * x + y * y);
  10673. if ((d - _l > r) || (d + _l < r)) {
  10674. return false;
  10675. }
  10676. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  10677. return true;
  10678. }
  10679. if (anticlockwise) {
  10680. var tmp = startAngle;
  10681. startAngle = normalizeRadian(endAngle);
  10682. endAngle = normalizeRadian(tmp);
  10683. }
  10684. else {
  10685. startAngle = normalizeRadian(startAngle);
  10686. endAngle = normalizeRadian(endAngle);
  10687. }
  10688. if (startAngle > endAngle) {
  10689. endAngle += PI2$3;
  10690. }
  10691. var angle = Math.atan2(y, x);
  10692. if (angle < 0) {
  10693. angle += PI2$3;
  10694. }
  10695. return (angle >= startAngle && angle <= endAngle)
  10696. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  10697. }
  10698. function windingLine(x0, y0, x1, y1, x, y) {
  10699. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  10700. return 0;
  10701. }
  10702. if (y1 === y0) {
  10703. return 0;
  10704. }
  10705. var t = (y - y0) / (y1 - y0);
  10706. var dir = y1 < y0 ? 1 : -1;
  10707. if (t === 1 || t === 0) {
  10708. dir = y1 < y0 ? 0.5 : -0.5;
  10709. }
  10710. var x_ = t * (x1 - x0) + x0;
  10711. return x_ === x ? Infinity : x_ > x ? dir : 0;
  10712. }
  10713. var CMD$1 = PathProxy.CMD;
  10714. var PI2$4 = Math.PI * 2;
  10715. var EPSILON$3 = 1e-4;
  10716. function isAroundEqual(a, b) {
  10717. return Math.abs(a - b) < EPSILON$3;
  10718. }
  10719. var roots = [-1, -1, -1];
  10720. var extrema = [-1, -1];
  10721. function swapExtrema() {
  10722. var tmp = extrema[0];
  10723. extrema[0] = extrema[1];
  10724. extrema[1] = tmp;
  10725. }
  10726. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  10727. if ((y > y0 && y > y1 && y > y2 && y > y3)
  10728. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  10729. return 0;
  10730. }
  10731. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  10732. if (nRoots === 0) {
  10733. return 0;
  10734. }
  10735. else {
  10736. var w = 0;
  10737. var nExtrema = -1;
  10738. var y0_ = void 0;
  10739. var y1_ = void 0;
  10740. for (var i = 0; i < nRoots; i++) {
  10741. var t = roots[i];
  10742. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  10743. var x_ = cubicAt(x0, x1, x2, x3, t);
  10744. if (x_ < x) {
  10745. continue;
  10746. }
  10747. if (nExtrema < 0) {
  10748. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  10749. if (extrema[1] < extrema[0] && nExtrema > 1) {
  10750. swapExtrema();
  10751. }
  10752. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  10753. if (nExtrema > 1) {
  10754. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  10755. }
  10756. }
  10757. if (nExtrema === 2) {
  10758. if (t < extrema[0]) {
  10759. w += y0_ < y0 ? unit : -unit;
  10760. }
  10761. else if (t < extrema[1]) {
  10762. w += y1_ < y0_ ? unit : -unit;
  10763. }
  10764. else {
  10765. w += y3 < y1_ ? unit : -unit;
  10766. }
  10767. }
  10768. else {
  10769. if (t < extrema[0]) {
  10770. w += y0_ < y0 ? unit : -unit;
  10771. }
  10772. else {
  10773. w += y3 < y0_ ? unit : -unit;
  10774. }
  10775. }
  10776. }
  10777. return w;
  10778. }
  10779. }
  10780. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  10781. if ((y > y0 && y > y1 && y > y2)
  10782. || (y < y0 && y < y1 && y < y2)) {
  10783. return 0;
  10784. }
  10785. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  10786. if (nRoots === 0) {
  10787. return 0;
  10788. }
  10789. else {
  10790. var t = quadraticExtremum(y0, y1, y2);
  10791. if (t >= 0 && t <= 1) {
  10792. var w = 0;
  10793. var y_ = quadraticAt(y0, y1, y2, t);
  10794. for (var i = 0; i < nRoots; i++) {
  10795. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  10796. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  10797. if (x_ < x) {
  10798. continue;
  10799. }
  10800. if (roots[i] < t) {
  10801. w += y_ < y0 ? unit : -unit;
  10802. }
  10803. else {
  10804. w += y2 < y_ ? unit : -unit;
  10805. }
  10806. }
  10807. return w;
  10808. }
  10809. else {
  10810. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  10811. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  10812. if (x_ < x) {
  10813. return 0;
  10814. }
  10815. return y2 < y0 ? unit : -unit;
  10816. }
  10817. }
  10818. }
  10819. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  10820. y -= cy;
  10821. if (y > r || y < -r) {
  10822. return 0;
  10823. }
  10824. var tmp = Math.sqrt(r * r - y * y);
  10825. roots[0] = -tmp;
  10826. roots[1] = tmp;
  10827. var dTheta = Math.abs(startAngle - endAngle);
  10828. if (dTheta < 1e-4) {
  10829. return 0;
  10830. }
  10831. if (dTheta >= PI2$4 - 1e-4) {
  10832. startAngle = 0;
  10833. endAngle = PI2$4;
  10834. var dir = anticlockwise ? 1 : -1;
  10835. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  10836. return dir;
  10837. }
  10838. else {
  10839. return 0;
  10840. }
  10841. }
  10842. if (startAngle > endAngle) {
  10843. var tmp_1 = startAngle;
  10844. startAngle = endAngle;
  10845. endAngle = tmp_1;
  10846. }
  10847. if (startAngle < 0) {
  10848. startAngle += PI2$4;
  10849. endAngle += PI2$4;
  10850. }
  10851. var w = 0;
  10852. for (var i = 0; i < 2; i++) {
  10853. var x_ = roots[i];
  10854. if (x_ + cx > x) {
  10855. var angle = Math.atan2(y, x_);
  10856. var dir = anticlockwise ? 1 : -1;
  10857. if (angle < 0) {
  10858. angle = PI2$4 + angle;
  10859. }
  10860. if ((angle >= startAngle && angle <= endAngle)
  10861. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  10862. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  10863. dir = -dir;
  10864. }
  10865. w += dir;
  10866. }
  10867. }
  10868. }
  10869. return w;
  10870. }
  10871. function containPath(path, lineWidth, isStroke, x, y) {
  10872. var data = path.data;
  10873. var len = path.len();
  10874. var w = 0;
  10875. var xi = 0;
  10876. var yi = 0;
  10877. var x0 = 0;
  10878. var y0 = 0;
  10879. var x1;
  10880. var y1;
  10881. for (var i = 0; i < len;) {
  10882. var cmd = data[i++];
  10883. var isFirst = i === 1;
  10884. if (cmd === CMD$1.M && i > 1) {
  10885. if (!isStroke) {
  10886. w += windingLine(xi, yi, x0, y0, x, y);
  10887. }
  10888. }
  10889. if (isFirst) {
  10890. xi = data[i];
  10891. yi = data[i + 1];
  10892. x0 = xi;
  10893. y0 = yi;
  10894. }
  10895. switch (cmd) {
  10896. case CMD$1.M:
  10897. x0 = data[i++];
  10898. y0 = data[i++];
  10899. xi = x0;
  10900. yi = y0;
  10901. break;
  10902. case CMD$1.L:
  10903. if (isStroke) {
  10904. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  10905. return true;
  10906. }
  10907. }
  10908. else {
  10909. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  10910. }
  10911. xi = data[i++];
  10912. yi = data[i++];
  10913. break;
  10914. case CMD$1.C:
  10915. if (isStroke) {
  10916. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  10917. return true;
  10918. }
  10919. }
  10920. else {
  10921. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  10922. }
  10923. xi = data[i++];
  10924. yi = data[i++];
  10925. break;
  10926. case CMD$1.Q:
  10927. if (isStroke) {
  10928. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  10929. return true;
  10930. }
  10931. }
  10932. else {
  10933. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  10934. }
  10935. xi = data[i++];
  10936. yi = data[i++];
  10937. break;
  10938. case CMD$1.A:
  10939. var cx = data[i++];
  10940. var cy = data[i++];
  10941. var rx = data[i++];
  10942. var ry = data[i++];
  10943. var theta = data[i++];
  10944. var dTheta = data[i++];
  10945. i += 1;
  10946. var anticlockwise = !!(1 - data[i++]);
  10947. x1 = Math.cos(theta) * rx + cx;
  10948. y1 = Math.sin(theta) * ry + cy;
  10949. if (!isFirst) {
  10950. w += windingLine(xi, yi, x1, y1, x, y);
  10951. }
  10952. else {
  10953. x0 = x1;
  10954. y0 = y1;
  10955. }
  10956. var _x = (x - cx) * ry / rx + cx;
  10957. if (isStroke) {
  10958. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  10959. return true;
  10960. }
  10961. }
  10962. else {
  10963. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  10964. }
  10965. xi = Math.cos(theta + dTheta) * rx + cx;
  10966. yi = Math.sin(theta + dTheta) * ry + cy;
  10967. break;
  10968. case CMD$1.R:
  10969. x0 = xi = data[i++];
  10970. y0 = yi = data[i++];
  10971. var width = data[i++];
  10972. var height = data[i++];
  10973. x1 = x0 + width;
  10974. y1 = y0 + height;
  10975. if (isStroke) {
  10976. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  10977. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  10978. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  10979. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  10980. return true;
  10981. }
  10982. }
  10983. else {
  10984. w += windingLine(x1, y0, x1, y1, x, y);
  10985. w += windingLine(x0, y1, x0, y0, x, y);
  10986. }
  10987. break;
  10988. case CMD$1.Z:
  10989. if (isStroke) {
  10990. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  10991. return true;
  10992. }
  10993. }
  10994. else {
  10995. w += windingLine(xi, yi, x0, y0, x, y);
  10996. }
  10997. xi = x0;
  10998. yi = y0;
  10999. break;
  11000. }
  11001. }
  11002. if (!isStroke && !isAroundEqual(yi, y0)) {
  11003. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  11004. }
  11005. return w !== 0;
  11006. }
  11007. function contain(pathProxy, x, y) {
  11008. return containPath(pathProxy, 0, false, x, y);
  11009. }
  11010. function containStroke$4(pathProxy, lineWidth, x, y) {
  11011. return containPath(pathProxy, lineWidth, true, x, y);
  11012. }
  11013. var DEFAULT_PATH_STYLE = defaults({
  11014. fill: '#000',
  11015. stroke: null,
  11016. strokePercent: 1,
  11017. fillOpacity: 1,
  11018. strokeOpacity: 1,
  11019. lineDashOffset: 0,
  11020. lineWidth: 1,
  11021. lineCap: 'butt',
  11022. miterLimit: 10,
  11023. strokeNoScale: false,
  11024. strokeFirst: false
  11025. }, DEFAULT_COMMON_STYLE);
  11026. var DEFAULT_PATH_ANIMATION_PROPS = {
  11027. style: defaults({
  11028. fill: true,
  11029. stroke: true,
  11030. strokePercent: true,
  11031. fillOpacity: true,
  11032. strokeOpacity: true,
  11033. lineDashOffset: true,
  11034. lineWidth: true,
  11035. miterLimit: true
  11036. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11037. };
  11038. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  11039. 'culling', 'z', 'z2', 'zlevel', 'parent'
  11040. ]);
  11041. var Path = (function (_super) {
  11042. __extends(Path, _super);
  11043. function Path(opts) {
  11044. return _super.call(this, opts) || this;
  11045. }
  11046. Path.prototype.update = function () {
  11047. var _this = this;
  11048. _super.prototype.update.call(this);
  11049. var style = this.style;
  11050. if (style.decal) {
  11051. var decalEl = this._decalEl = this._decalEl || new Path();
  11052. if (decalEl.buildPath === Path.prototype.buildPath) {
  11053. decalEl.buildPath = function (ctx) {
  11054. _this.buildPath(ctx, _this.shape);
  11055. };
  11056. }
  11057. decalEl.silent = true;
  11058. var decalElStyle = decalEl.style;
  11059. for (var key in style) {
  11060. if (decalElStyle[key] !== style[key]) {
  11061. decalElStyle[key] = style[key];
  11062. }
  11063. }
  11064. decalElStyle.fill = style.fill ? style.decal : null;
  11065. decalElStyle.decal = null;
  11066. decalElStyle.shadowColor = null;
  11067. style.strokeFirst && (decalElStyle.stroke = null);
  11068. for (var i = 0; i < pathCopyParams.length; ++i) {
  11069. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  11070. }
  11071. decalEl.__dirty |= REDRAW_BIT;
  11072. }
  11073. else if (this._decalEl) {
  11074. this._decalEl = null;
  11075. }
  11076. };
  11077. Path.prototype.getDecalElement = function () {
  11078. return this._decalEl;
  11079. };
  11080. Path.prototype._init = function (props) {
  11081. var keysArr = keys(props);
  11082. this.shape = this.getDefaultShape();
  11083. var defaultStyle = this.getDefaultStyle();
  11084. if (defaultStyle) {
  11085. this.useStyle(defaultStyle);
  11086. }
  11087. for (var i = 0; i < keysArr.length; i++) {
  11088. var key = keysArr[i];
  11089. var value = props[key];
  11090. if (key === 'style') {
  11091. if (!this.style) {
  11092. this.useStyle(value);
  11093. }
  11094. else {
  11095. extend(this.style, value);
  11096. }
  11097. }
  11098. else if (key === 'shape') {
  11099. extend(this.shape, value);
  11100. }
  11101. else {
  11102. _super.prototype.attrKV.call(this, key, value);
  11103. }
  11104. }
  11105. if (!this.style) {
  11106. this.useStyle({});
  11107. }
  11108. };
  11109. Path.prototype.getDefaultStyle = function () {
  11110. return null;
  11111. };
  11112. Path.prototype.getDefaultShape = function () {
  11113. return {};
  11114. };
  11115. Path.prototype.canBeInsideText = function () {
  11116. return this.hasFill();
  11117. };
  11118. Path.prototype.getInsideTextFill = function () {
  11119. var pathFill = this.style.fill;
  11120. if (pathFill !== 'none') {
  11121. if (isString(pathFill)) {
  11122. var fillLum = lum(pathFill, 0);
  11123. if (fillLum > 0.5) {
  11124. return DARK_LABEL_COLOR;
  11125. }
  11126. else if (fillLum > 0.2) {
  11127. return LIGHTER_LABEL_COLOR;
  11128. }
  11129. return LIGHT_LABEL_COLOR;
  11130. }
  11131. else if (pathFill) {
  11132. return LIGHT_LABEL_COLOR;
  11133. }
  11134. }
  11135. return DARK_LABEL_COLOR;
  11136. };
  11137. Path.prototype.getInsideTextStroke = function (textFill) {
  11138. var pathFill = this.style.fill;
  11139. if (isString(pathFill)) {
  11140. var zr = this.__zr;
  11141. var isDarkMode = !!(zr && zr.isDarkMode());
  11142. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  11143. if (isDarkMode === isDarkLabel) {
  11144. return pathFill;
  11145. }
  11146. }
  11147. };
  11148. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  11149. Path.prototype.pathUpdated = function () {
  11150. this.__dirty &= ~SHAPE_CHANGED_BIT;
  11151. };
  11152. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  11153. !this.path && this.createPathProxy();
  11154. this.path.beginPath();
  11155. this.buildPath(this.path, this.shape, inBatch);
  11156. return this.path;
  11157. };
  11158. Path.prototype.createPathProxy = function () {
  11159. this.path = new PathProxy(false);
  11160. };
  11161. Path.prototype.hasStroke = function () {
  11162. var style = this.style;
  11163. var stroke = style.stroke;
  11164. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  11165. };
  11166. Path.prototype.hasFill = function () {
  11167. var style = this.style;
  11168. var fill = style.fill;
  11169. return fill != null && fill !== 'none';
  11170. };
  11171. Path.prototype.getBoundingRect = function () {
  11172. var rect = this._rect;
  11173. var style = this.style;
  11174. var needsUpdateRect = !rect;
  11175. if (needsUpdateRect) {
  11176. var firstInvoke = false;
  11177. if (!this.path) {
  11178. firstInvoke = true;
  11179. this.createPathProxy();
  11180. }
  11181. var path = this.path;
  11182. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  11183. path.beginPath();
  11184. this.buildPath(path, this.shape, false);
  11185. this.pathUpdated();
  11186. }
  11187. rect = path.getBoundingRect();
  11188. }
  11189. this._rect = rect;
  11190. if (this.hasStroke() && this.path && this.path.len() > 0) {
  11191. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  11192. if (this.__dirty || needsUpdateRect) {
  11193. rectStroke.copy(rect);
  11194. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  11195. var w = style.lineWidth;
  11196. if (!this.hasFill()) {
  11197. var strokeContainThreshold = this.strokeContainThreshold;
  11198. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  11199. }
  11200. if (lineScale > 1e-10) {
  11201. rectStroke.width += w / lineScale;
  11202. rectStroke.height += w / lineScale;
  11203. rectStroke.x -= w / lineScale / 2;
  11204. rectStroke.y -= w / lineScale / 2;
  11205. }
  11206. }
  11207. return rectStroke;
  11208. }
  11209. return rect;
  11210. };
  11211. Path.prototype.contain = function (x, y) {
  11212. var localPos = this.transformCoordToLocal(x, y);
  11213. var rect = this.getBoundingRect();
  11214. var style = this.style;
  11215. x = localPos[0];
  11216. y = localPos[1];
  11217. if (rect.contain(x, y)) {
  11218. var pathProxy = this.path;
  11219. if (this.hasStroke()) {
  11220. var lineWidth = style.lineWidth;
  11221. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  11222. if (lineScale > 1e-10) {
  11223. if (!this.hasFill()) {
  11224. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  11225. }
  11226. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  11227. return true;
  11228. }
  11229. }
  11230. }
  11231. if (this.hasFill()) {
  11232. return contain(pathProxy, x, y);
  11233. }
  11234. }
  11235. return false;
  11236. };
  11237. Path.prototype.dirtyShape = function () {
  11238. this.__dirty |= SHAPE_CHANGED_BIT;
  11239. if (this._rect) {
  11240. this._rect = null;
  11241. }
  11242. if (this._decalEl) {
  11243. this._decalEl.dirtyShape();
  11244. }
  11245. this.markRedraw();
  11246. };
  11247. Path.prototype.dirty = function () {
  11248. this.dirtyStyle();
  11249. this.dirtyShape();
  11250. };
  11251. Path.prototype.animateShape = function (loop) {
  11252. return this.animate('shape', loop);
  11253. };
  11254. Path.prototype.updateDuringAnimation = function (targetKey) {
  11255. if (targetKey === 'style') {
  11256. this.dirtyStyle();
  11257. }
  11258. else if (targetKey === 'shape') {
  11259. this.dirtyShape();
  11260. }
  11261. else {
  11262. this.markRedraw();
  11263. }
  11264. };
  11265. Path.prototype.attrKV = function (key, value) {
  11266. if (key === 'shape') {
  11267. this.setShape(value);
  11268. }
  11269. else {
  11270. _super.prototype.attrKV.call(this, key, value);
  11271. }
  11272. };
  11273. Path.prototype.setShape = function (keyOrObj, value) {
  11274. var shape = this.shape;
  11275. if (!shape) {
  11276. shape = this.shape = {};
  11277. }
  11278. if (typeof keyOrObj === 'string') {
  11279. shape[keyOrObj] = value;
  11280. }
  11281. else {
  11282. extend(shape, keyOrObj);
  11283. }
  11284. this.dirtyShape();
  11285. return this;
  11286. };
  11287. Path.prototype.shapeChanged = function () {
  11288. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  11289. };
  11290. Path.prototype.createStyle = function (obj) {
  11291. return createObject(DEFAULT_PATH_STYLE, obj);
  11292. };
  11293. Path.prototype._innerSaveToNormal = function (toState) {
  11294. _super.prototype._innerSaveToNormal.call(this, toState);
  11295. var normalState = this._normalState;
  11296. if (toState.shape && !normalState.shape) {
  11297. normalState.shape = extend({}, this.shape);
  11298. }
  11299. };
  11300. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  11301. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  11302. var needsRestoreToNormal = !(state && keepCurrentStates);
  11303. var targetShape;
  11304. if (state && state.shape) {
  11305. if (transition) {
  11306. if (keepCurrentStates) {
  11307. targetShape = state.shape;
  11308. }
  11309. else {
  11310. targetShape = extend({}, normalState.shape);
  11311. extend(targetShape, state.shape);
  11312. }
  11313. }
  11314. else {
  11315. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  11316. extend(targetShape, state.shape);
  11317. }
  11318. }
  11319. else if (needsRestoreToNormal) {
  11320. targetShape = normalState.shape;
  11321. }
  11322. if (targetShape) {
  11323. if (transition) {
  11324. this.shape = extend({}, this.shape);
  11325. var targetShapePrimaryProps = {};
  11326. var shapeKeys = keys(targetShape);
  11327. for (var i = 0; i < shapeKeys.length; i++) {
  11328. var key = shapeKeys[i];
  11329. if (typeof targetShape[key] === 'object') {
  11330. this.shape[key] = targetShape[key];
  11331. }
  11332. else {
  11333. targetShapePrimaryProps[key] = targetShape[key];
  11334. }
  11335. }
  11336. this._transitionState(stateName, {
  11337. shape: targetShapePrimaryProps
  11338. }, animationCfg);
  11339. }
  11340. else {
  11341. this.shape = targetShape;
  11342. this.dirtyShape();
  11343. }
  11344. }
  11345. };
  11346. Path.prototype._mergeStates = function (states) {
  11347. var mergedState = _super.prototype._mergeStates.call(this, states);
  11348. var mergedShape;
  11349. for (var i = 0; i < states.length; i++) {
  11350. var state = states[i];
  11351. if (state.shape) {
  11352. mergedShape = mergedShape || {};
  11353. this._mergeStyle(mergedShape, state.shape);
  11354. }
  11355. }
  11356. if (mergedShape) {
  11357. mergedState.shape = mergedShape;
  11358. }
  11359. return mergedState;
  11360. };
  11361. Path.prototype.getAnimationStyleProps = function () {
  11362. return DEFAULT_PATH_ANIMATION_PROPS;
  11363. };
  11364. Path.prototype.isZeroArea = function () {
  11365. return false;
  11366. };
  11367. Path.extend = function (defaultProps) {
  11368. var Sub = (function (_super) {
  11369. __extends(Sub, _super);
  11370. function Sub(opts) {
  11371. var _this = _super.call(this, opts) || this;
  11372. defaultProps.init && defaultProps.init.call(_this, opts);
  11373. return _this;
  11374. }
  11375. Sub.prototype.getDefaultStyle = function () {
  11376. return clone(defaultProps.style);
  11377. };
  11378. Sub.prototype.getDefaultShape = function () {
  11379. return clone(defaultProps.shape);
  11380. };
  11381. return Sub;
  11382. }(Path));
  11383. for (var key in defaultProps) {
  11384. if (typeof defaultProps[key] === 'function') {
  11385. Sub.prototype[key] = defaultProps[key];
  11386. }
  11387. }
  11388. return Sub;
  11389. };
  11390. Path.initDefaultProps = (function () {
  11391. var pathProto = Path.prototype;
  11392. pathProto.type = 'path';
  11393. pathProto.strokeContainThreshold = 5;
  11394. pathProto.segmentIgnoreThreshold = 0;
  11395. pathProto.subPixelOptimize = false;
  11396. pathProto.autoBatch = false;
  11397. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  11398. })();
  11399. return Path;
  11400. }(Displayable));
  11401. var DEFAULT_TSPAN_STYLE = defaults({
  11402. strokeFirst: true,
  11403. font: DEFAULT_FONT,
  11404. x: 0,
  11405. y: 0,
  11406. textAlign: 'left',
  11407. textBaseline: 'top',
  11408. miterLimit: 2
  11409. }, DEFAULT_PATH_STYLE);
  11410. var TSpan = (function (_super) {
  11411. __extends(TSpan, _super);
  11412. function TSpan() {
  11413. return _super !== null && _super.apply(this, arguments) || this;
  11414. }
  11415. TSpan.prototype.hasStroke = function () {
  11416. return tSpanHasStroke(this.style);
  11417. };
  11418. TSpan.prototype.hasFill = function () {
  11419. var style = this.style;
  11420. var fill = style.fill;
  11421. return fill != null && fill !== 'none';
  11422. };
  11423. TSpan.prototype.createStyle = function (obj) {
  11424. return createObject(DEFAULT_TSPAN_STYLE, obj);
  11425. };
  11426. TSpan.prototype.setBoundingRect = function (rect) {
  11427. this._rect = rect;
  11428. };
  11429. TSpan.prototype.getBoundingRect = function () {
  11430. if (!this._rect) {
  11431. this._rect = tSpanCreateBoundingRect(this.style);
  11432. }
  11433. return this._rect;
  11434. };
  11435. TSpan.initDefaultProps = (function () {
  11436. var tspanProto = TSpan.prototype;
  11437. tspanProto.dirtyRectTolerance = 10;
  11438. })();
  11439. return TSpan;
  11440. }(Displayable));
  11441. TSpan.prototype.type = 'tspan';
  11442. var DEFAULT_IMAGE_STYLE = defaults({
  11443. x: 0,
  11444. y: 0
  11445. }, DEFAULT_COMMON_STYLE);
  11446. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  11447. style: defaults({
  11448. x: true,
  11449. y: true,
  11450. width: true,
  11451. height: true,
  11452. sx: true,
  11453. sy: true,
  11454. sWidth: true,
  11455. sHeight: true
  11456. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11457. };
  11458. function isImageLike(source) {
  11459. return !!(source
  11460. && typeof source !== 'string'
  11461. && source.width && source.height);
  11462. }
  11463. var ZRImage = (function (_super) {
  11464. __extends(ZRImage, _super);
  11465. function ZRImage() {
  11466. return _super !== null && _super.apply(this, arguments) || this;
  11467. }
  11468. ZRImage.prototype.createStyle = function (obj) {
  11469. return createObject(DEFAULT_IMAGE_STYLE, obj);
  11470. };
  11471. ZRImage.prototype._getSize = function (dim) {
  11472. var style = this.style;
  11473. var size = style[dim];
  11474. if (size != null) {
  11475. return size;
  11476. }
  11477. var imageSource = isImageLike(style.image)
  11478. ? style.image : this.__image;
  11479. if (!imageSource) {
  11480. return 0;
  11481. }
  11482. var otherDim = dim === 'width' ? 'height' : 'width';
  11483. var otherDimSize = style[otherDim];
  11484. if (otherDimSize == null) {
  11485. return imageSource[dim];
  11486. }
  11487. else {
  11488. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  11489. }
  11490. };
  11491. ZRImage.prototype.getWidth = function () {
  11492. return this._getSize('width');
  11493. };
  11494. ZRImage.prototype.getHeight = function () {
  11495. return this._getSize('height');
  11496. };
  11497. ZRImage.prototype.getAnimationStyleProps = function () {
  11498. return DEFAULT_IMAGE_ANIMATION_PROPS;
  11499. };
  11500. ZRImage.prototype.getBoundingRect = function () {
  11501. var style = this.style;
  11502. if (!this._rect) {
  11503. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  11504. }
  11505. return this._rect;
  11506. };
  11507. return ZRImage;
  11508. }(Displayable));
  11509. ZRImage.prototype.type = 'image';
  11510. function buildPath(ctx, shape) {
  11511. var x = shape.x;
  11512. var y = shape.y;
  11513. var width = shape.width;
  11514. var height = shape.height;
  11515. var r = shape.r;
  11516. var r1;
  11517. var r2;
  11518. var r3;
  11519. var r4;
  11520. if (width < 0) {
  11521. x = x + width;
  11522. width = -width;
  11523. }
  11524. if (height < 0) {
  11525. y = y + height;
  11526. height = -height;
  11527. }
  11528. if (typeof r === 'number') {
  11529. r1 = r2 = r3 = r4 = r;
  11530. }
  11531. else if (r instanceof Array) {
  11532. if (r.length === 1) {
  11533. r1 = r2 = r3 = r4 = r[0];
  11534. }
  11535. else if (r.length === 2) {
  11536. r1 = r3 = r[0];
  11537. r2 = r4 = r[1];
  11538. }
  11539. else if (r.length === 3) {
  11540. r1 = r[0];
  11541. r2 = r4 = r[1];
  11542. r3 = r[2];
  11543. }
  11544. else {
  11545. r1 = r[0];
  11546. r2 = r[1];
  11547. r3 = r[2];
  11548. r4 = r[3];
  11549. }
  11550. }
  11551. else {
  11552. r1 = r2 = r3 = r4 = 0;
  11553. }
  11554. var total;
  11555. if (r1 + r2 > width) {
  11556. total = r1 + r2;
  11557. r1 *= width / total;
  11558. r2 *= width / total;
  11559. }
  11560. if (r3 + r4 > width) {
  11561. total = r3 + r4;
  11562. r3 *= width / total;
  11563. r4 *= width / total;
  11564. }
  11565. if (r2 + r3 > height) {
  11566. total = r2 + r3;
  11567. r2 *= height / total;
  11568. r3 *= height / total;
  11569. }
  11570. if (r1 + r4 > height) {
  11571. total = r1 + r4;
  11572. r1 *= height / total;
  11573. r4 *= height / total;
  11574. }
  11575. ctx.moveTo(x + r1, y);
  11576. ctx.lineTo(x + width - r2, y);
  11577. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  11578. ctx.lineTo(x + width, y + height - r3);
  11579. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  11580. ctx.lineTo(x + r4, y + height);
  11581. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  11582. ctx.lineTo(x, y + r1);
  11583. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  11584. }
  11585. var round$1 = Math.round;
  11586. function subPixelOptimizeLine(outputShape, inputShape, style) {
  11587. if (!inputShape) {
  11588. return;
  11589. }
  11590. var x1 = inputShape.x1;
  11591. var x2 = inputShape.x2;
  11592. var y1 = inputShape.y1;
  11593. var y2 = inputShape.y2;
  11594. outputShape.x1 = x1;
  11595. outputShape.x2 = x2;
  11596. outputShape.y1 = y1;
  11597. outputShape.y2 = y2;
  11598. var lineWidth = style && style.lineWidth;
  11599. if (!lineWidth) {
  11600. return outputShape;
  11601. }
  11602. if (round$1(x1 * 2) === round$1(x2 * 2)) {
  11603. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  11604. }
  11605. if (round$1(y1 * 2) === round$1(y2 * 2)) {
  11606. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  11607. }
  11608. return outputShape;
  11609. }
  11610. function subPixelOptimizeRect(outputShape, inputShape, style) {
  11611. if (!inputShape) {
  11612. return;
  11613. }
  11614. var originX = inputShape.x;
  11615. var originY = inputShape.y;
  11616. var originWidth = inputShape.width;
  11617. var originHeight = inputShape.height;
  11618. outputShape.x = originX;
  11619. outputShape.y = originY;
  11620. outputShape.width = originWidth;
  11621. outputShape.height = originHeight;
  11622. var lineWidth = style && style.lineWidth;
  11623. if (!lineWidth) {
  11624. return outputShape;
  11625. }
  11626. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  11627. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  11628. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  11629. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  11630. return outputShape;
  11631. }
  11632. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  11633. if (!lineWidth) {
  11634. return position;
  11635. }
  11636. var doubledPosition = round$1(position * 2);
  11637. return (doubledPosition + round$1(lineWidth)) % 2 === 0
  11638. ? doubledPosition / 2
  11639. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  11640. }
  11641. var RectShape = (function () {
  11642. function RectShape() {
  11643. this.x = 0;
  11644. this.y = 0;
  11645. this.width = 0;
  11646. this.height = 0;
  11647. }
  11648. return RectShape;
  11649. }());
  11650. var subPixelOptimizeOutputShape = {};
  11651. var Rect = (function (_super) {
  11652. __extends(Rect, _super);
  11653. function Rect(opts) {
  11654. return _super.call(this, opts) || this;
  11655. }
  11656. Rect.prototype.getDefaultShape = function () {
  11657. return new RectShape();
  11658. };
  11659. Rect.prototype.buildPath = function (ctx, shape) {
  11660. var x;
  11661. var y;
  11662. var width;
  11663. var height;
  11664. if (this.subPixelOptimize) {
  11665. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  11666. x = optimizedShape.x;
  11667. y = optimizedShape.y;
  11668. width = optimizedShape.width;
  11669. height = optimizedShape.height;
  11670. optimizedShape.r = shape.r;
  11671. shape = optimizedShape;
  11672. }
  11673. else {
  11674. x = shape.x;
  11675. y = shape.y;
  11676. width = shape.width;
  11677. height = shape.height;
  11678. }
  11679. if (!shape.r) {
  11680. ctx.rect(x, y, width, height);
  11681. }
  11682. else {
  11683. buildPath(ctx, shape);
  11684. }
  11685. };
  11686. Rect.prototype.isZeroArea = function () {
  11687. return !this.shape.width || !this.shape.height;
  11688. };
  11689. return Rect;
  11690. }(Path));
  11691. Rect.prototype.type = 'rect';
  11692. var DEFAULT_RICH_TEXT_COLOR = {
  11693. fill: '#000'
  11694. };
  11695. var DEFAULT_STROKE_LINE_WIDTH = 2;
  11696. var tmpCITOverflowAreaOut = {};
  11697. var DEFAULT_TEXT_ANIMATION_PROPS = {
  11698. style: defaults({
  11699. fill: true,
  11700. stroke: true,
  11701. fillOpacity: true,
  11702. strokeOpacity: true,
  11703. lineWidth: true,
  11704. fontSize: true,
  11705. lineHeight: true,
  11706. width: true,
  11707. height: true,
  11708. textShadowColor: true,
  11709. textShadowBlur: true,
  11710. textShadowOffsetX: true,
  11711. textShadowOffsetY: true,
  11712. backgroundColor: true,
  11713. padding: true,
  11714. borderColor: true,
  11715. borderWidth: true,
  11716. borderRadius: true
  11717. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11718. };
  11719. var ZRText = (function (_super) {
  11720. __extends(ZRText, _super);
  11721. function ZRText(opts) {
  11722. var _this = _super.call(this) || this;
  11723. _this.type = 'text';
  11724. _this._children = [];
  11725. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  11726. _this.attr(opts);
  11727. return _this;
  11728. }
  11729. ZRText.prototype.childrenRef = function () {
  11730. return this._children;
  11731. };
  11732. ZRText.prototype.update = function () {
  11733. _super.prototype.update.call(this);
  11734. if (this.styleChanged()) {
  11735. this._updateSubTexts();
  11736. }
  11737. for (var i = 0; i < this._children.length; i++) {
  11738. var child = this._children[i];
  11739. child.zlevel = this.zlevel;
  11740. child.z = this.z;
  11741. child.z2 = this.z2;
  11742. child.culling = this.culling;
  11743. child.cursor = this.cursor;
  11744. child.invisible = this.invisible;
  11745. }
  11746. };
  11747. ZRText.prototype.updateTransform = function () {
  11748. var innerTransformable = this.innerTransformable;
  11749. if (innerTransformable) {
  11750. innerTransformable.updateTransform();
  11751. if (innerTransformable.transform) {
  11752. this.transform = innerTransformable.transform;
  11753. }
  11754. }
  11755. else {
  11756. _super.prototype.updateTransform.call(this);
  11757. }
  11758. };
  11759. ZRText.prototype.getLocalTransform = function (m) {
  11760. var innerTransformable = this.innerTransformable;
  11761. return innerTransformable
  11762. ? innerTransformable.getLocalTransform(m)
  11763. : _super.prototype.getLocalTransform.call(this, m);
  11764. };
  11765. ZRText.prototype.getComputedTransform = function () {
  11766. if (this.__hostTarget) {
  11767. this.__hostTarget.getComputedTransform();
  11768. this.__hostTarget.updateInnerText(true);
  11769. }
  11770. return _super.prototype.getComputedTransform.call(this);
  11771. };
  11772. ZRText.prototype._updateSubTexts = function () {
  11773. this._childCursor = 0;
  11774. normalizeTextStyle(this.style);
  11775. this.style.rich
  11776. ? this._updateRichTexts()
  11777. : this._updatePlainTexts();
  11778. this._children.length = this._childCursor;
  11779. this.styleUpdated();
  11780. };
  11781. ZRText.prototype.addSelfToZr = function (zr) {
  11782. _super.prototype.addSelfToZr.call(this, zr);
  11783. for (var i = 0; i < this._children.length; i++) {
  11784. this._children[i].__zr = zr;
  11785. }
  11786. };
  11787. ZRText.prototype.removeSelfFromZr = function (zr) {
  11788. _super.prototype.removeSelfFromZr.call(this, zr);
  11789. for (var i = 0; i < this._children.length; i++) {
  11790. this._children[i].__zr = null;
  11791. }
  11792. };
  11793. ZRText.prototype.getBoundingRect = function () {
  11794. if (this.styleChanged()) {
  11795. this._updateSubTexts();
  11796. }
  11797. if (!this._rect) {
  11798. var tmpRect = new BoundingRect(0, 0, 0, 0);
  11799. var children = this._children;
  11800. var tmpMat = [];
  11801. var rect = null;
  11802. for (var i = 0; i < children.length; i++) {
  11803. var child = children[i];
  11804. var childRect = child.getBoundingRect();
  11805. var transform = child.getLocalTransform(tmpMat);
  11806. if (transform) {
  11807. tmpRect.copy(childRect);
  11808. tmpRect.applyTransform(transform);
  11809. rect = rect || tmpRect.clone();
  11810. rect.union(tmpRect);
  11811. }
  11812. else {
  11813. rect = rect || childRect.clone();
  11814. rect.union(childRect);
  11815. }
  11816. }
  11817. this._rect = rect || tmpRect;
  11818. }
  11819. return this._rect;
  11820. };
  11821. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  11822. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  11823. };
  11824. ZRText.prototype.setTextContent = function (textContent) {
  11825. if ("development" !== 'production') {
  11826. throw new Error('Can\'t attach text on another text');
  11827. }
  11828. };
  11829. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  11830. if (!sourceStyle) {
  11831. return targetStyle;
  11832. }
  11833. var sourceRich = sourceStyle.rich;
  11834. var targetRich = targetStyle.rich || (sourceRich && {});
  11835. extend(targetStyle, sourceStyle);
  11836. if (sourceRich && targetRich) {
  11837. this._mergeRich(targetRich, sourceRich);
  11838. targetStyle.rich = targetRich;
  11839. }
  11840. else if (targetRich) {
  11841. targetStyle.rich = targetRich;
  11842. }
  11843. return targetStyle;
  11844. };
  11845. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  11846. var richNames = keys(sourceRich);
  11847. for (var i = 0; i < richNames.length; i++) {
  11848. var richName = richNames[i];
  11849. targetRich[richName] = targetRich[richName] || {};
  11850. extend(targetRich[richName], sourceRich[richName]);
  11851. }
  11852. };
  11853. ZRText.prototype.getAnimationStyleProps = function () {
  11854. return DEFAULT_TEXT_ANIMATION_PROPS;
  11855. };
  11856. ZRText.prototype._getOrCreateChild = function (Ctor) {
  11857. var child = this._children[this._childCursor];
  11858. if (!child || !(child instanceof Ctor)) {
  11859. child = new Ctor();
  11860. }
  11861. this._children[this._childCursor++] = child;
  11862. child.__zr = this.__zr;
  11863. child.parent = this;
  11864. return child;
  11865. };
  11866. ZRText.prototype._updatePlainTexts = function () {
  11867. var style = this.style;
  11868. var textFont = style.font || DEFAULT_FONT;
  11869. var textPadding = style.padding;
  11870. var defaultStyle = this._defaultStyle;
  11871. var baseX = style.x || 0;
  11872. var baseY = style.y || 0;
  11873. var textAlign = style.align || defaultStyle.align || 'left';
  11874. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  11875. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  11876. baseX = tmpCITOverflowAreaOut.baseX;
  11877. baseY = tmpCITOverflowAreaOut.baseY;
  11878. var text = getStyleText(style);
  11879. var contentBlock = parsePlainText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight);
  11880. var needDrawBg = needDrawBackground(style);
  11881. var bgColorDrawn = !!(style.backgroundColor);
  11882. var outerHeight = contentBlock.outerHeight;
  11883. var outerWidth = contentBlock.outerWidth;
  11884. var textLines = contentBlock.lines;
  11885. var lineHeight = contentBlock.lineHeight;
  11886. this.isTruncated = !!contentBlock.isTruncated;
  11887. var textX = baseX;
  11888. var textY = adjustTextY(baseY, contentBlock.contentHeight, verticalAlign);
  11889. if (needDrawBg || textPadding) {
  11890. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  11891. var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
  11892. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  11893. }
  11894. textY += lineHeight / 2;
  11895. if (textPadding) {
  11896. textX = getTextXForPadding(baseX, textAlign, textPadding);
  11897. if (verticalAlign === 'top') {
  11898. textY += textPadding[0];
  11899. }
  11900. else if (verticalAlign === 'bottom') {
  11901. textY -= textPadding[2];
  11902. }
  11903. }
  11904. var defaultLineWidth = 0;
  11905. var usingDefaultStroke = false;
  11906. var useDefaultFill = false;
  11907. var textFill = getFill('fill' in style
  11908. ? style.fill
  11909. : (useDefaultFill = true, defaultStyle.fill));
  11910. var textStroke = getStroke('stroke' in style
  11911. ? style.stroke
  11912. : (!bgColorDrawn
  11913. && (!defaultStyle.autoStroke || useDefaultFill))
  11914. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  11915. : null);
  11916. var hasShadow = style.textShadowBlur > 0;
  11917. for (var i = 0; i < textLines.length; i++) {
  11918. var el = this._getOrCreateChild(TSpan);
  11919. var subElStyle = el.createStyle();
  11920. el.useStyle(subElStyle);
  11921. subElStyle.text = textLines[i];
  11922. subElStyle.x = textX;
  11923. subElStyle.y = textY;
  11924. if (textAlign) {
  11925. subElStyle.textAlign = textAlign;
  11926. }
  11927. subElStyle.textBaseline = 'middle';
  11928. subElStyle.opacity = style.opacity;
  11929. subElStyle.strokeFirst = true;
  11930. if (hasShadow) {
  11931. subElStyle.shadowBlur = style.textShadowBlur || 0;
  11932. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  11933. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  11934. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  11935. }
  11936. subElStyle.stroke = textStroke;
  11937. subElStyle.fill = textFill;
  11938. if (textStroke) {
  11939. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  11940. subElStyle.lineDash = style.lineDash;
  11941. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  11942. }
  11943. subElStyle.font = textFont;
  11944. setSeparateFont(subElStyle, style);
  11945. textY += lineHeight;
  11946. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, contentBlock.contentWidth, contentBlock.calculatedLineHeight, usingDefaultStroke ? 0 : null));
  11947. }
  11948. };
  11949. ZRText.prototype._updateRichTexts = function () {
  11950. var style = this.style;
  11951. var defaultStyle = this._defaultStyle;
  11952. var textAlign = style.align || defaultStyle.align;
  11953. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  11954. var baseX = style.x || 0;
  11955. var baseY = style.y || 0;
  11956. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  11957. baseX = tmpCITOverflowAreaOut.baseX;
  11958. baseY = tmpCITOverflowAreaOut.baseY;
  11959. var text = getStyleText(style);
  11960. var contentBlock = parseRichText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight, textAlign);
  11961. var contentWidth = contentBlock.width;
  11962. var outerWidth = contentBlock.outerWidth;
  11963. var outerHeight = contentBlock.outerHeight;
  11964. var textPadding = style.padding;
  11965. this.isTruncated = !!contentBlock.isTruncated;
  11966. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  11967. var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
  11968. var xLeft = boxX;
  11969. var lineTop = boxY;
  11970. if (textPadding) {
  11971. xLeft += textPadding[3];
  11972. lineTop += textPadding[0];
  11973. }
  11974. var xRight = xLeft + contentWidth;
  11975. if (needDrawBackground(style)) {
  11976. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  11977. }
  11978. var bgColorDrawn = !!(style.backgroundColor);
  11979. for (var i = 0; i < contentBlock.lines.length; i++) {
  11980. var line = contentBlock.lines[i];
  11981. var tokens = line.tokens;
  11982. var tokenCount = tokens.length;
  11983. var lineHeight = line.lineHeight;
  11984. var remainedWidth = line.width;
  11985. var leftIndex = 0;
  11986. var lineXLeft = xLeft;
  11987. var lineXRight = xRight;
  11988. var rightIndex = tokenCount - 1;
  11989. var token = void 0;
  11990. while (leftIndex < tokenCount
  11991. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  11992. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  11993. remainedWidth -= token.width;
  11994. lineXLeft += token.width;
  11995. leftIndex++;
  11996. }
  11997. while (rightIndex >= 0
  11998. && (token = tokens[rightIndex], token.align === 'right')) {
  11999. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  12000. remainedWidth -= token.width;
  12001. lineXRight -= token.width;
  12002. rightIndex--;
  12003. }
  12004. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  12005. while (leftIndex <= rightIndex) {
  12006. token = tokens[leftIndex];
  12007. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  12008. lineXLeft += token.width;
  12009. leftIndex++;
  12010. }
  12011. lineTop += lineHeight;
  12012. }
  12013. };
  12014. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  12015. var tokenStyle = style.rich[token.styleName] || {};
  12016. tokenStyle.text = token.text;
  12017. var verticalAlign = token.verticalAlign;
  12018. var y = lineTop + lineHeight / 2;
  12019. if (verticalAlign === 'top') {
  12020. y = lineTop + token.height / 2;
  12021. }
  12022. else if (verticalAlign === 'bottom') {
  12023. y = lineTop + lineHeight - token.height / 2;
  12024. }
  12025. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  12026. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  12027. ? x - token.width
  12028. : textAlign === 'center'
  12029. ? x - token.width / 2
  12030. : x, y - token.height / 2, token.width, token.height);
  12031. var bgColorDrawn = !!tokenStyle.backgroundColor;
  12032. var textPadding = token.textPadding;
  12033. if (textPadding) {
  12034. x = getTextXForPadding(x, textAlign, textPadding);
  12035. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  12036. }
  12037. var el = this._getOrCreateChild(TSpan);
  12038. var subElStyle = el.createStyle();
  12039. el.useStyle(subElStyle);
  12040. var defaultStyle = this._defaultStyle;
  12041. var useDefaultFill = false;
  12042. var defaultLineWidth = 0;
  12043. var usingDefaultStroke = false;
  12044. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  12045. : 'fill' in style ? style.fill
  12046. : (useDefaultFill = true, defaultStyle.fill));
  12047. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  12048. : 'stroke' in style ? style.stroke
  12049. : (!bgColorDrawn
  12050. && !parentBgColorDrawn
  12051. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  12052. : null);
  12053. var hasShadow = tokenStyle.textShadowBlur > 0
  12054. || style.textShadowBlur > 0;
  12055. subElStyle.text = token.text;
  12056. subElStyle.x = x;
  12057. subElStyle.y = y;
  12058. if (hasShadow) {
  12059. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  12060. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  12061. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  12062. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  12063. }
  12064. subElStyle.textAlign = textAlign;
  12065. subElStyle.textBaseline = 'middle';
  12066. subElStyle.font = token.font || DEFAULT_FONT;
  12067. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  12068. setSeparateFont(subElStyle, tokenStyle);
  12069. if (textStroke) {
  12070. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  12071. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  12072. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  12073. subElStyle.stroke = textStroke;
  12074. }
  12075. if (textFill) {
  12076. subElStyle.fill = textFill;
  12077. }
  12078. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, token.contentWidth, token.contentHeight, usingDefaultStroke ? 0 : null));
  12079. };
  12080. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  12081. var textBackgroundColor = style.backgroundColor;
  12082. var textBorderWidth = style.borderWidth;
  12083. var textBorderColor = style.borderColor;
  12084. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  12085. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  12086. var textBorderRadius = style.borderRadius;
  12087. var self = this;
  12088. var rectEl;
  12089. var imgEl;
  12090. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  12091. rectEl = this._getOrCreateChild(Rect);
  12092. rectEl.useStyle(rectEl.createStyle());
  12093. rectEl.style.fill = null;
  12094. var rectShape = rectEl.shape;
  12095. rectShape.x = x;
  12096. rectShape.y = y;
  12097. rectShape.width = width;
  12098. rectShape.height = height;
  12099. rectShape.r = textBorderRadius;
  12100. rectEl.dirtyShape();
  12101. }
  12102. if (isPlainOrGradientBg) {
  12103. var rectStyle = rectEl.style;
  12104. rectStyle.fill = textBackgroundColor || null;
  12105. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  12106. }
  12107. else if (isImageBg) {
  12108. imgEl = this._getOrCreateChild(ZRImage);
  12109. imgEl.onload = function () {
  12110. self.dirtyStyle();
  12111. };
  12112. var imgStyle = imgEl.style;
  12113. imgStyle.image = textBackgroundColor.image;
  12114. imgStyle.x = x;
  12115. imgStyle.y = y;
  12116. imgStyle.width = width;
  12117. imgStyle.height = height;
  12118. }
  12119. if (textBorderWidth && textBorderColor) {
  12120. var rectStyle = rectEl.style;
  12121. rectStyle.lineWidth = textBorderWidth;
  12122. rectStyle.stroke = textBorderColor;
  12123. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  12124. rectStyle.lineDash = style.borderDash;
  12125. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  12126. rectEl.strokeContainThreshold = 0;
  12127. if (rectEl.hasFill() && rectEl.hasStroke()) {
  12128. rectStyle.strokeFirst = true;
  12129. rectStyle.lineWidth *= 2;
  12130. }
  12131. }
  12132. var commonStyle = (rectEl || imgEl).style;
  12133. commonStyle.shadowBlur = style.shadowBlur || 0;
  12134. commonStyle.shadowColor = style.shadowColor || 'transparent';
  12135. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  12136. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  12137. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  12138. };
  12139. ZRText.makeFont = function (style) {
  12140. var font = '';
  12141. if (hasSeparateFont(style)) {
  12142. font = [
  12143. style.fontStyle,
  12144. style.fontWeight,
  12145. parseFontSize(style.fontSize),
  12146. style.fontFamily || 'sans-serif'
  12147. ].join(' ');
  12148. }
  12149. return font && trim(font) || style.textFont || style.font;
  12150. };
  12151. return ZRText;
  12152. }(Displayable));
  12153. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  12154. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  12155. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  12156. function parseFontSize(fontSize) {
  12157. if (typeof fontSize === 'string'
  12158. && (fontSize.indexOf('px') !== -1
  12159. || fontSize.indexOf('rem') !== -1
  12160. || fontSize.indexOf('em') !== -1)) {
  12161. return fontSize;
  12162. }
  12163. else if (!isNaN(+fontSize)) {
  12164. return fontSize + 'px';
  12165. }
  12166. else {
  12167. return DEFAULT_FONT_SIZE + 'px';
  12168. }
  12169. }
  12170. function setSeparateFont(targetStyle, sourceStyle) {
  12171. for (var i = 0; i < FONT_PARTS.length; i++) {
  12172. var fontProp = FONT_PARTS[i];
  12173. var val = sourceStyle[fontProp];
  12174. if (val != null) {
  12175. targetStyle[fontProp] = val;
  12176. }
  12177. }
  12178. }
  12179. function hasSeparateFont(style) {
  12180. return style.fontSize != null || style.fontFamily || style.fontWeight;
  12181. }
  12182. function normalizeTextStyle(style) {
  12183. normalizeStyle(style);
  12184. each(style.rich, normalizeStyle);
  12185. return style;
  12186. }
  12187. function normalizeStyle(style) {
  12188. if (style) {
  12189. style.font = ZRText.makeFont(style);
  12190. var textAlign = style.align;
  12191. textAlign === 'middle' && (textAlign = 'center');
  12192. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  12193. var verticalAlign = style.verticalAlign;
  12194. verticalAlign === 'center' && (verticalAlign = 'middle');
  12195. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  12196. var textPadding = style.padding;
  12197. if (textPadding) {
  12198. style.padding = normalizeCssArray(style.padding);
  12199. }
  12200. }
  12201. }
  12202. function getStroke(stroke, lineWidth) {
  12203. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  12204. ? null
  12205. : (stroke.image || stroke.colorStops)
  12206. ? '#000'
  12207. : stroke;
  12208. }
  12209. function getFill(fill) {
  12210. return (fill == null || fill === 'none')
  12211. ? null
  12212. : (fill.image || fill.colorStops)
  12213. ? '#000'
  12214. : fill;
  12215. }
  12216. function getTextXForPadding(x, textAlign, textPadding) {
  12217. return textAlign === 'right'
  12218. ? (x - textPadding[1])
  12219. : textAlign === 'center'
  12220. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  12221. : (x + textPadding[3]);
  12222. }
  12223. function getStyleText(style) {
  12224. var text = style.text;
  12225. text != null && (text += '');
  12226. return text;
  12227. }
  12228. function needDrawBackground(style) {
  12229. return !!(style.backgroundColor
  12230. || style.lineHeight
  12231. || (style.borderWidth && style.borderColor));
  12232. }
  12233. var getECData = makeInner();
  12234. var setCommonECData = function (seriesIndex, dataType, dataIdx, el) {
  12235. if (el) {
  12236. var ecData = getECData(el);
  12237. // Add data index and series index for indexing the data by element
  12238. // Useful in tooltip
  12239. ecData.dataIndex = dataIdx;
  12240. ecData.dataType = dataType;
  12241. ecData.seriesIndex = seriesIndex;
  12242. ecData.ssrType = 'chart';
  12243. // TODO: not store dataIndex on children.
  12244. if (el.type === 'group') {
  12245. el.traverse(function (child) {
  12246. var childECData = getECData(child);
  12247. childECData.seriesIndex = seriesIndex;
  12248. childECData.dataIndex = dataIdx;
  12249. childECData.dataType = dataType;
  12250. childECData.ssrType = 'chart';
  12251. });
  12252. }
  12253. }
  12254. };
  12255. // Reserve 0 as default.
  12256. var _highlightNextDigit = 1;
  12257. var _highlightKeyMap = {};
  12258. var getSavedStates = makeInner();
  12259. var getComponentStates = makeInner();
  12260. var HOVER_STATE_NORMAL = 0;
  12261. var HOVER_STATE_BLUR = 1;
  12262. var HOVER_STATE_EMPHASIS = 2;
  12263. var SPECIAL_STATES = ['emphasis', 'blur', 'select'];
  12264. var DISPLAY_STATES = ['normal', 'emphasis', 'blur', 'select'];
  12265. var Z2_EMPHASIS_LIFT = 10;
  12266. var Z2_SELECT_LIFT = 9;
  12267. var HIGHLIGHT_ACTION_TYPE = 'highlight';
  12268. var DOWNPLAY_ACTION_TYPE = 'downplay';
  12269. var SELECT_ACTION_TYPE = 'select';
  12270. var UNSELECT_ACTION_TYPE = 'unselect';
  12271. var TOGGLE_SELECT_ACTION_TYPE = 'toggleSelect';
  12272. var SELECT_CHANGED_EVENT_TYPE = 'selectchanged';
  12273. function hasFillOrStroke(fillOrStroke) {
  12274. return fillOrStroke != null && fillOrStroke !== 'none';
  12275. }
  12276. function doChangeHoverState(el, stateName, hoverStateEnum) {
  12277. if (el.onHoverStateChange && (el.hoverState || 0) !== hoverStateEnum) {
  12278. el.onHoverStateChange(stateName);
  12279. }
  12280. el.hoverState = hoverStateEnum;
  12281. }
  12282. function singleEnterEmphasis(el) {
  12283. // Only mark the flag.
  12284. // States will be applied in the echarts.ts in next frame.
  12285. doChangeHoverState(el, 'emphasis', HOVER_STATE_EMPHASIS);
  12286. }
  12287. function singleLeaveEmphasis(el) {
  12288. // Only mark the flag.
  12289. // States will be applied in the echarts.ts in next frame.
  12290. if (el.hoverState === HOVER_STATE_EMPHASIS) {
  12291. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  12292. }
  12293. }
  12294. function singleEnterBlur(el) {
  12295. doChangeHoverState(el, 'blur', HOVER_STATE_BLUR);
  12296. }
  12297. function singleLeaveBlur(el) {
  12298. if (el.hoverState === HOVER_STATE_BLUR) {
  12299. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  12300. }
  12301. }
  12302. function singleEnterSelect(el) {
  12303. el.selected = true;
  12304. }
  12305. function singleLeaveSelect(el) {
  12306. el.selected = false;
  12307. }
  12308. function updateElementState(el, updater, commonParam) {
  12309. updater(el, commonParam);
  12310. }
  12311. function traverseUpdateState(el, updater, commonParam) {
  12312. updateElementState(el, updater, commonParam);
  12313. el.isGroup && el.traverse(function (child) {
  12314. updateElementState(child, updater, commonParam);
  12315. });
  12316. }
  12317. function setStatesFlag(el, stateName) {
  12318. switch (stateName) {
  12319. case 'emphasis':
  12320. el.hoverState = HOVER_STATE_EMPHASIS;
  12321. break;
  12322. case 'normal':
  12323. el.hoverState = HOVER_STATE_NORMAL;
  12324. break;
  12325. case 'blur':
  12326. el.hoverState = HOVER_STATE_BLUR;
  12327. break;
  12328. case 'select':
  12329. el.selected = true;
  12330. }
  12331. }
  12332. function getFromStateStyle(el, props, toStateName, defaultValue) {
  12333. var style = el.style;
  12334. var fromState = {};
  12335. for (var i = 0; i < props.length; i++) {
  12336. var propName = props[i];
  12337. var val = style[propName];
  12338. fromState[propName] = val == null ? defaultValue && defaultValue[propName] : val;
  12339. }
  12340. for (var i = 0; i < el.animators.length; i++) {
  12341. var animator = el.animators[i];
  12342. if (animator.__fromStateTransition
  12343. // Don't consider the animation to emphasis state.
  12344. && animator.__fromStateTransition.indexOf(toStateName) < 0 && animator.targetName === 'style') {
  12345. animator.saveTo(fromState, props);
  12346. }
  12347. }
  12348. return fromState;
  12349. }
  12350. function createEmphasisDefaultState(el, stateName, targetStates, state) {
  12351. var hasSelect = targetStates && indexOf(targetStates, 'select') >= 0;
  12352. var cloned = false;
  12353. if (el instanceof Path) {
  12354. var store = getSavedStates(el);
  12355. var fromFill = hasSelect ? store.selectFill || store.normalFill : store.normalFill;
  12356. var fromStroke = hasSelect ? store.selectStroke || store.normalStroke : store.normalStroke;
  12357. if (hasFillOrStroke(fromFill) || hasFillOrStroke(fromStroke)) {
  12358. state = state || {};
  12359. var emphasisStyle = state.style || {};
  12360. // inherit case
  12361. if (emphasisStyle.fill === 'inherit') {
  12362. cloned = true;
  12363. state = extend({}, state);
  12364. emphasisStyle = extend({}, emphasisStyle);
  12365. emphasisStyle.fill = fromFill;
  12366. }
  12367. // Apply default color lift
  12368. else if (!hasFillOrStroke(emphasisStyle.fill) && hasFillOrStroke(fromFill)) {
  12369. cloned = true;
  12370. // Not modify the original value.
  12371. state = extend({}, state);
  12372. emphasisStyle = extend({}, emphasisStyle);
  12373. // Already being applied 'emphasis'. DON'T lift color multiple times.
  12374. emphasisStyle.fill = liftColor(fromFill);
  12375. }
  12376. // Not highlight stroke if fill has been highlighted.
  12377. else if (!hasFillOrStroke(emphasisStyle.stroke) && hasFillOrStroke(fromStroke)) {
  12378. if (!cloned) {
  12379. state = extend({}, state);
  12380. emphasisStyle = extend({}, emphasisStyle);
  12381. }
  12382. emphasisStyle.stroke = liftColor(fromStroke);
  12383. }
  12384. state.style = emphasisStyle;
  12385. }
  12386. }
  12387. if (state) {
  12388. // TODO Share with textContent?
  12389. if (state.z2 == null) {
  12390. if (!cloned) {
  12391. state = extend({}, state);
  12392. }
  12393. var z2EmphasisLift = el.z2EmphasisLift;
  12394. state.z2 = el.z2 + (z2EmphasisLift != null ? z2EmphasisLift : Z2_EMPHASIS_LIFT);
  12395. }
  12396. }
  12397. return state;
  12398. }
  12399. function createSelectDefaultState(el, stateName, state) {
  12400. // const hasSelect = indexOf(el.currentStates, stateName) >= 0;
  12401. if (state) {
  12402. // TODO Share with textContent?
  12403. if (state.z2 == null) {
  12404. state = extend({}, state);
  12405. var z2SelectLift = el.z2SelectLift;
  12406. state.z2 = el.z2 + (z2SelectLift != null ? z2SelectLift : Z2_SELECT_LIFT);
  12407. }
  12408. }
  12409. return state;
  12410. }
  12411. function createBlurDefaultState(el, stateName, state) {
  12412. var hasBlur = indexOf(el.currentStates, stateName) >= 0;
  12413. var currentOpacity = el.style.opacity;
  12414. var fromState = !hasBlur ? getFromStateStyle(el, ['opacity'], stateName, {
  12415. opacity: 1
  12416. }) : null;
  12417. state = state || {};
  12418. var blurStyle = state.style || {};
  12419. if (blurStyle.opacity == null) {
  12420. // clone state
  12421. state = extend({}, state);
  12422. blurStyle = extend({
  12423. // Already being applied 'emphasis'. DON'T mul opacity multiple times.
  12424. opacity: hasBlur ? currentOpacity : fromState.opacity * 0.1
  12425. }, blurStyle);
  12426. state.style = blurStyle;
  12427. }
  12428. return state;
  12429. }
  12430. function elementStateProxy(stateName, targetStates) {
  12431. var state = this.states[stateName];
  12432. if (this.style) {
  12433. if (stateName === 'emphasis') {
  12434. return createEmphasisDefaultState(this, stateName, targetStates, state);
  12435. } else if (stateName === 'blur') {
  12436. return createBlurDefaultState(this, stateName, state);
  12437. } else if (stateName === 'select') {
  12438. return createSelectDefaultState(this, stateName, state);
  12439. }
  12440. }
  12441. return state;
  12442. }
  12443. /**
  12444. * Set hover style (namely "emphasis style") of element.
  12445. * @param el Should not be `zrender/graphic/Group`.
  12446. * @param focus 'self' | 'selfInSeries' | 'series'
  12447. */
  12448. function setDefaultStateProxy(el) {
  12449. el.stateProxy = elementStateProxy;
  12450. var textContent = el.getTextContent();
  12451. var textGuide = el.getTextGuideLine();
  12452. if (textContent) {
  12453. textContent.stateProxy = elementStateProxy;
  12454. }
  12455. if (textGuide) {
  12456. textGuide.stateProxy = elementStateProxy;
  12457. }
  12458. }
  12459. function enterEmphasisWhenMouseOver(el, e) {
  12460. !shouldSilent(el, e)
  12461. // "emphasis" event highlight has higher priority than mouse highlight.
  12462. && !el.__highByOuter && traverseUpdateState(el, singleEnterEmphasis);
  12463. }
  12464. function leaveEmphasisWhenMouseOut(el, e) {
  12465. !shouldSilent(el, e)
  12466. // "emphasis" event highlight has higher priority than mouse highlight.
  12467. && !el.__highByOuter && traverseUpdateState(el, singleLeaveEmphasis);
  12468. }
  12469. function enterEmphasis(el, highlightDigit) {
  12470. el.__highByOuter |= 1 << (highlightDigit || 0);
  12471. traverseUpdateState(el, singleEnterEmphasis);
  12472. }
  12473. function leaveEmphasis(el, highlightDigit) {
  12474. !(el.__highByOuter &= ~(1 << (highlightDigit || 0))) && traverseUpdateState(el, singleLeaveEmphasis);
  12475. }
  12476. function enterBlur(el) {
  12477. traverseUpdateState(el, singleEnterBlur);
  12478. }
  12479. function leaveBlur(el) {
  12480. traverseUpdateState(el, singleLeaveBlur);
  12481. }
  12482. function enterSelect(el) {
  12483. traverseUpdateState(el, singleEnterSelect);
  12484. }
  12485. function leaveSelect(el) {
  12486. traverseUpdateState(el, singleLeaveSelect);
  12487. }
  12488. function shouldSilent(el, e) {
  12489. return el.__highDownSilentOnTouch && e.zrByTouch;
  12490. }
  12491. function allLeaveBlur(api) {
  12492. var model = api.getModel();
  12493. var leaveBlurredSeries = [];
  12494. var allComponentViews = [];
  12495. model.eachComponent(function (componentType, componentModel) {
  12496. var componentStates = getComponentStates(componentModel);
  12497. var isSeries = componentType === 'series';
  12498. var view = isSeries ? api.getViewOfSeriesModel(componentModel) : api.getViewOfComponentModel(componentModel);
  12499. !isSeries && allComponentViews.push(view);
  12500. if (componentStates.isBlured) {
  12501. // Leave blur anyway
  12502. view.group.traverse(function (child) {
  12503. singleLeaveBlur(child);
  12504. });
  12505. isSeries && leaveBlurredSeries.push(componentModel);
  12506. }
  12507. componentStates.isBlured = false;
  12508. });
  12509. each(allComponentViews, function (view) {
  12510. if (view && view.toggleBlurSeries) {
  12511. view.toggleBlurSeries(leaveBlurredSeries, false, model);
  12512. }
  12513. });
  12514. }
  12515. function blurSeries(targetSeriesIndex, focus, blurScope, api) {
  12516. var ecModel = api.getModel();
  12517. blurScope = blurScope || 'coordinateSystem';
  12518. function leaveBlurOfIndices(data, dataIndices) {
  12519. for (var i = 0; i < dataIndices.length; i++) {
  12520. var itemEl = data.getItemGraphicEl(dataIndices[i]);
  12521. itemEl && leaveBlur(itemEl);
  12522. }
  12523. }
  12524. if (targetSeriesIndex == null) {
  12525. return;
  12526. }
  12527. if (!focus || focus === 'none') {
  12528. return;
  12529. }
  12530. var targetSeriesModel = ecModel.getSeriesByIndex(targetSeriesIndex);
  12531. var targetCoordSys = targetSeriesModel.coordinateSystem;
  12532. if (targetCoordSys && targetCoordSys.master) {
  12533. targetCoordSys = targetCoordSys.master;
  12534. }
  12535. var blurredSeries = [];
  12536. ecModel.eachSeries(function (seriesModel) {
  12537. var sameSeries = targetSeriesModel === seriesModel;
  12538. var coordSys = seriesModel.coordinateSystem;
  12539. if (coordSys && coordSys.master) {
  12540. coordSys = coordSys.master;
  12541. }
  12542. var sameCoordSys = coordSys && targetCoordSys ? coordSys === targetCoordSys : sameSeries; // If there is no coordinate system. use sameSeries instead.
  12543. if (!(
  12544. // Not blur other series if blurScope series
  12545. blurScope === 'series' && !sameSeries
  12546. // Not blur other coordinate system if blurScope is coordinateSystem
  12547. || blurScope === 'coordinateSystem' && !sameCoordSys
  12548. // Not blur self series if focus is series.
  12549. || focus === 'series' && sameSeries
  12550. // TODO blurScope: coordinate system
  12551. )) {
  12552. var view = api.getViewOfSeriesModel(seriesModel);
  12553. view.group.traverse(function (child) {
  12554. // For the elements that have been triggered by other components,
  12555. // and are still required to be highlighted,
  12556. // because the current is directly forced to blur the element,
  12557. // it will cause the focus self to be unable to highlight, so skip the blur of this element.
  12558. if (child.__highByOuter && sameSeries && focus === 'self') {
  12559. return;
  12560. }
  12561. singleEnterBlur(child);
  12562. });
  12563. if (isArrayLike(focus)) {
  12564. leaveBlurOfIndices(seriesModel.getData(), focus);
  12565. } else if (isObject(focus)) {
  12566. var dataTypes = keys(focus);
  12567. for (var d = 0; d < dataTypes.length; d++) {
  12568. leaveBlurOfIndices(seriesModel.getData(dataTypes[d]), focus[dataTypes[d]]);
  12569. }
  12570. }
  12571. blurredSeries.push(seriesModel);
  12572. getComponentStates(seriesModel).isBlured = true;
  12573. }
  12574. });
  12575. ecModel.eachComponent(function (componentType, componentModel) {
  12576. if (componentType === 'series') {
  12577. return;
  12578. }
  12579. var view = api.getViewOfComponentModel(componentModel);
  12580. if (view && view.toggleBlurSeries) {
  12581. view.toggleBlurSeries(blurredSeries, true, ecModel);
  12582. }
  12583. });
  12584. }
  12585. function blurComponent(componentMainType, componentIndex, api) {
  12586. if (componentMainType == null || componentIndex == null) {
  12587. return;
  12588. }
  12589. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12590. if (!componentModel) {
  12591. return;
  12592. }
  12593. getComponentStates(componentModel).isBlured = true;
  12594. var view = api.getViewOfComponentModel(componentModel);
  12595. if (!view || !view.focusBlurEnabled) {
  12596. return;
  12597. }
  12598. view.group.traverse(function (child) {
  12599. singleEnterBlur(child);
  12600. });
  12601. }
  12602. function blurSeriesFromHighlightPayload(seriesModel, payload, api) {
  12603. var seriesIndex = seriesModel.seriesIndex;
  12604. var data = seriesModel.getData(payload.dataType);
  12605. if (!data) {
  12606. if ("development" !== 'production') {
  12607. error("Unknown dataType " + payload.dataType);
  12608. }
  12609. return;
  12610. }
  12611. var dataIndex = queryDataIndex(data, payload);
  12612. // Pick the first one if there is multiple/none exists.
  12613. dataIndex = (isArray(dataIndex) ? dataIndex[0] : dataIndex) || 0;
  12614. var el = data.getItemGraphicEl(dataIndex);
  12615. if (!el) {
  12616. var count = data.count();
  12617. var current = 0;
  12618. // If data on dataIndex is NaN.
  12619. while (!el && current < count) {
  12620. el = data.getItemGraphicEl(current++);
  12621. }
  12622. }
  12623. if (el) {
  12624. var ecData = getECData(el);
  12625. blurSeries(seriesIndex, ecData.focus, ecData.blurScope, api);
  12626. } else {
  12627. // If there is no element put on the data. Try getting it from raw option
  12628. // TODO Should put it on seriesModel?
  12629. var focus_1 = seriesModel.get(['emphasis', 'focus']);
  12630. var blurScope = seriesModel.get(['emphasis', 'blurScope']);
  12631. if (focus_1 != null) {
  12632. blurSeries(seriesIndex, focus_1, blurScope, api);
  12633. }
  12634. }
  12635. }
  12636. function findComponentHighDownDispatchers(componentMainType, componentIndex, name, api) {
  12637. var ret = {
  12638. focusSelf: false,
  12639. dispatchers: null
  12640. };
  12641. if (componentMainType == null || componentMainType === 'series' || componentIndex == null || name == null) {
  12642. return ret;
  12643. }
  12644. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12645. if (!componentModel) {
  12646. return ret;
  12647. }
  12648. var view = api.getViewOfComponentModel(componentModel);
  12649. if (!view || !view.findHighDownDispatchers) {
  12650. return ret;
  12651. }
  12652. var dispatchers = view.findHighDownDispatchers(name);
  12653. // At presnet, the component (like Geo) only blur inside itself.
  12654. // So we do not use `blurScope` in component.
  12655. var focusSelf;
  12656. for (var i = 0; i < dispatchers.length; i++) {
  12657. if ("development" !== 'production' && !isHighDownDispatcher(dispatchers[i])) {
  12658. error('param should be highDownDispatcher');
  12659. }
  12660. if (getECData(dispatchers[i]).focus === 'self') {
  12661. focusSelf = true;
  12662. break;
  12663. }
  12664. }
  12665. return {
  12666. focusSelf: focusSelf,
  12667. dispatchers: dispatchers
  12668. };
  12669. }
  12670. function handleGlobalMouseOverForHighDown(dispatcher, e, api) {
  12671. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12672. error('param should be highDownDispatcher');
  12673. }
  12674. var ecData = getECData(dispatcher);
  12675. var _a = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api),
  12676. dispatchers = _a.dispatchers,
  12677. focusSelf = _a.focusSelf;
  12678. // If `findHighDownDispatchers` is supported on the component,
  12679. // highlight/downplay elements with the same name.
  12680. if (dispatchers) {
  12681. if (focusSelf) {
  12682. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12683. }
  12684. each(dispatchers, function (dispatcher) {
  12685. return enterEmphasisWhenMouseOver(dispatcher, e);
  12686. });
  12687. } else {
  12688. // Try blur all in the related series. Then emphasis the hoverred.
  12689. // TODO. progressive mode.
  12690. blurSeries(ecData.seriesIndex, ecData.focus, ecData.blurScope, api);
  12691. if (ecData.focus === 'self') {
  12692. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12693. }
  12694. // Other than series, component that not support `findHighDownDispatcher` will
  12695. // also use it. But in this case, highlight/downplay are only supported in
  12696. // mouse hover but not in dispatchAction.
  12697. enterEmphasisWhenMouseOver(dispatcher, e);
  12698. }
  12699. }
  12700. function handleGlobalMouseOutForHighDown(dispatcher, e, api) {
  12701. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12702. error('param should be highDownDispatcher');
  12703. }
  12704. allLeaveBlur(api);
  12705. var ecData = getECData(dispatcher);
  12706. var dispatchers = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api).dispatchers;
  12707. if (dispatchers) {
  12708. each(dispatchers, function (dispatcher) {
  12709. return leaveEmphasisWhenMouseOut(dispatcher, e);
  12710. });
  12711. } else {
  12712. leaveEmphasisWhenMouseOut(dispatcher, e);
  12713. }
  12714. }
  12715. function toggleSelectionFromPayload(seriesModel, payload, api) {
  12716. if (!isSelectChangePayload(payload)) {
  12717. return;
  12718. }
  12719. var dataType = payload.dataType;
  12720. var data = seriesModel.getData(dataType);
  12721. var dataIndex = queryDataIndex(data, payload);
  12722. if (!isArray(dataIndex)) {
  12723. dataIndex = [dataIndex];
  12724. }
  12725. seriesModel[payload.type === TOGGLE_SELECT_ACTION_TYPE ? 'toggleSelect' : payload.type === SELECT_ACTION_TYPE ? 'select' : 'unselect'](dataIndex, dataType);
  12726. }
  12727. function updateSeriesElementSelection(seriesModel) {
  12728. var allData = seriesModel.getAllData();
  12729. each(allData, function (_a) {
  12730. var data = _a.data,
  12731. type = _a.type;
  12732. data.eachItemGraphicEl(function (el, idx) {
  12733. seriesModel.isSelected(idx, type) ? enterSelect(el) : leaveSelect(el);
  12734. });
  12735. });
  12736. }
  12737. function getAllSelectedIndices(ecModel) {
  12738. var ret = [];
  12739. ecModel.eachSeries(function (seriesModel) {
  12740. var allData = seriesModel.getAllData();
  12741. each(allData, function (_a) {
  12742. var data = _a.data,
  12743. type = _a.type;
  12744. var dataIndices = seriesModel.getSelectedDataIndices();
  12745. if (dataIndices.length > 0) {
  12746. var item = {
  12747. dataIndex: dataIndices,
  12748. seriesIndex: seriesModel.seriesIndex
  12749. };
  12750. if (type != null) {
  12751. item.dataType = type;
  12752. }
  12753. ret.push(item);
  12754. }
  12755. });
  12756. });
  12757. return ret;
  12758. }
  12759. /**
  12760. * Enable the function that mouseover will trigger the emphasis state.
  12761. *
  12762. * NOTE:
  12763. * This function should be used on the element with dataIndex, seriesIndex.
  12764. *
  12765. */
  12766. function enableHoverEmphasis(el, focus, blurScope) {
  12767. setAsHighDownDispatcher(el, true);
  12768. traverseUpdateState(el, setDefaultStateProxy);
  12769. enableHoverFocus(el, focus, blurScope);
  12770. }
  12771. function disableHoverEmphasis(el) {
  12772. setAsHighDownDispatcher(el, false);
  12773. }
  12774. function toggleHoverEmphasis(el, focus, blurScope, isDisabled) {
  12775. isDisabled ? disableHoverEmphasis(el) : enableHoverEmphasis(el, focus, blurScope);
  12776. }
  12777. function enableHoverFocus(el, focus, blurScope) {
  12778. var ecData = getECData(el);
  12779. if (focus != null) {
  12780. // TODO dataIndex may be set after this function. This check is not useful.
  12781. // if (ecData.dataIndex == null) {
  12782. // if (__DEV__) {
  12783. // console.warn('focus can only been set on element with dataIndex');
  12784. // }
  12785. // }
  12786. // else {
  12787. ecData.focus = focus;
  12788. ecData.blurScope = blurScope;
  12789. // }
  12790. } else if (ecData.focus) {
  12791. ecData.focus = null;
  12792. }
  12793. }
  12794. var OTHER_STATES = ['emphasis', 'blur', 'select'];
  12795. var defaultStyleGetterMap = {
  12796. itemStyle: 'getItemStyle',
  12797. lineStyle: 'getLineStyle',
  12798. areaStyle: 'getAreaStyle'
  12799. };
  12800. /**
  12801. * Set emphasis/blur/selected states of element.
  12802. */
  12803. function setStatesStylesFromModel(el, itemModel, styleType,
  12804. // default itemStyle
  12805. getter) {
  12806. styleType = styleType || 'itemStyle';
  12807. for (var i = 0; i < OTHER_STATES.length; i++) {
  12808. var stateName = OTHER_STATES[i];
  12809. var model = itemModel.getModel([stateName, styleType]);
  12810. var state = el.ensureState(stateName);
  12811. // Let it throw error if getterType is not found.
  12812. state.style = getter ? getter(model) : model[defaultStyleGetterMap[styleType]]();
  12813. }
  12814. }
  12815. /**
  12816. *
  12817. * Set element as highlight / downplay dispatcher.
  12818. * It will be checked when element received mouseover event or from highlight action.
  12819. * It's in change of all highlight/downplay behavior of it's children.
  12820. *
  12821. * @param el
  12822. * @param el.highDownSilentOnTouch
  12823. * In touch device, mouseover event will be trigger on touchstart event
  12824. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  12825. * conveniently use hoverStyle when tap on touch screen without additional
  12826. * code for compatibility.
  12827. * But if the chart/component has select feature, which usually also use
  12828. * hoverStyle, there might be conflict between 'select-highlight' and
  12829. * 'hover-highlight' especially when roam is enabled (see geo for example).
  12830. * In this case, `highDownSilentOnTouch` should be used to disable
  12831. * hover-highlight on touch device.
  12832. * @param asDispatcher If `false`, do not set as "highDownDispatcher".
  12833. */
  12834. function setAsHighDownDispatcher(el, asDispatcher) {
  12835. var disable = asDispatcher === false;
  12836. var extendedEl = el;
  12837. // Make `highDownSilentOnTouch` and `onStateChange` only work after
  12838. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  12839. if (el.highDownSilentOnTouch) {
  12840. extendedEl.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  12841. }
  12842. // Simple optimize, since this method might be
  12843. // called for each elements of a group in some cases.
  12844. if (!disable || extendedEl.__highDownDispatcher) {
  12845. // Emphasis, normal can be triggered manually by API or other components like hover link.
  12846. // el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);
  12847. // Also keep previous record.
  12848. extendedEl.__highByOuter = extendedEl.__highByOuter || 0;
  12849. extendedEl.__highDownDispatcher = !disable;
  12850. }
  12851. }
  12852. function isHighDownDispatcher(el) {
  12853. return !!(el && el.__highDownDispatcher);
  12854. }
  12855. /**
  12856. * Support highlight/downplay record on each elements.
  12857. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  12858. * user triggered highlight/downplay should not conflict.
  12859. * Only all of the highlightDigit cleared, return to normal.
  12860. * @param {string} highlightKey
  12861. * @return {number} highlightDigit
  12862. */
  12863. function getHighlightDigit(highlightKey) {
  12864. var highlightDigit = _highlightKeyMap[highlightKey];
  12865. if (highlightDigit == null && _highlightNextDigit <= 32) {
  12866. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  12867. }
  12868. return highlightDigit;
  12869. }
  12870. function isSelectChangePayload(payload) {
  12871. var payloadType = payload.type;
  12872. return payloadType === SELECT_ACTION_TYPE || payloadType === UNSELECT_ACTION_TYPE || payloadType === TOGGLE_SELECT_ACTION_TYPE;
  12873. }
  12874. function isHighDownPayload(payload) {
  12875. var payloadType = payload.type;
  12876. return payloadType === HIGHLIGHT_ACTION_TYPE || payloadType === DOWNPLAY_ACTION_TYPE;
  12877. }
  12878. function savePathStates(el) {
  12879. var store = getSavedStates(el);
  12880. store.normalFill = el.style.fill;
  12881. store.normalStroke = el.style.stroke;
  12882. var selectState = el.states.select || {};
  12883. store.selectFill = selectState.style && selectState.style.fill || null;
  12884. store.selectStroke = selectState.style && selectState.style.stroke || null;
  12885. }
  12886. var CMD$2 = PathProxy.CMD;
  12887. var points = [[], [], []];
  12888. var mathSqrt$1 = Math.sqrt;
  12889. var mathAtan2 = Math.atan2;
  12890. function transformPath(path, m) {
  12891. if (!m) {
  12892. return;
  12893. }
  12894. var data = path.data;
  12895. var len = path.len();
  12896. var cmd;
  12897. var nPoint;
  12898. var i;
  12899. var j;
  12900. var k;
  12901. var p;
  12902. var M = CMD$2.M;
  12903. var C = CMD$2.C;
  12904. var L = CMD$2.L;
  12905. var R = CMD$2.R;
  12906. var A = CMD$2.A;
  12907. var Q = CMD$2.Q;
  12908. for (i = 0, j = 0; i < len;) {
  12909. cmd = data[i++];
  12910. j = i;
  12911. nPoint = 0;
  12912. switch (cmd) {
  12913. case M:
  12914. nPoint = 1;
  12915. break;
  12916. case L:
  12917. nPoint = 1;
  12918. break;
  12919. case C:
  12920. nPoint = 3;
  12921. break;
  12922. case Q:
  12923. nPoint = 2;
  12924. break;
  12925. case A:
  12926. var x = m[4];
  12927. var y = m[5];
  12928. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  12929. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  12930. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  12931. data[i] *= sx;
  12932. data[i++] += x;
  12933. data[i] *= sy;
  12934. data[i++] += y;
  12935. data[i++] *= sx;
  12936. data[i++] *= sy;
  12937. data[i++] += angle;
  12938. data[i++] += angle;
  12939. i += 2;
  12940. j = i;
  12941. break;
  12942. case R:
  12943. p[0] = data[i++];
  12944. p[1] = data[i++];
  12945. applyTransform(p, p, m);
  12946. data[j++] = p[0];
  12947. data[j++] = p[1];
  12948. p[0] += data[i++];
  12949. p[1] += data[i++];
  12950. applyTransform(p, p, m);
  12951. data[j++] = p[0];
  12952. data[j++] = p[1];
  12953. }
  12954. for (k = 0; k < nPoint; k++) {
  12955. var p_1 = points[k];
  12956. p_1[0] = data[i++];
  12957. p_1[1] = data[i++];
  12958. applyTransform(p_1, p_1, m);
  12959. data[j++] = p_1[0];
  12960. data[j++] = p_1[1];
  12961. }
  12962. }
  12963. path.increaseVersion();
  12964. }
  12965. var mathSqrt$2 = Math.sqrt;
  12966. var mathSin$2 = Math.sin;
  12967. var mathCos$2 = Math.cos;
  12968. var PI$1 = Math.PI;
  12969. function vMag(v) {
  12970. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12971. }
  12972. function vRatio(u, v) {
  12973. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12974. }
  12975. function vAngle(u, v) {
  12976. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  12977. * Math.acos(vRatio(u, v));
  12978. }
  12979. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12980. var psi = psiDeg * (PI$1 / 180.0);
  12981. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  12982. + mathSin$2(psi) * (y1 - y2) / 2.0;
  12983. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  12984. + mathCos$2(psi) * (y1 - y2) / 2.0;
  12985. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  12986. if (lambda > 1) {
  12987. rx *= mathSqrt$2(lambda);
  12988. ry *= mathSqrt$2(lambda);
  12989. }
  12990. var f = (fa === fs ? -1 : 1)
  12991. * mathSqrt$2((((rx * rx) * (ry * ry))
  12992. - ((rx * rx) * (yp * yp))
  12993. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  12994. + (ry * ry) * (xp * xp))) || 0;
  12995. var cxp = f * rx * yp / ry;
  12996. var cyp = f * -ry * xp / rx;
  12997. var cx = (x1 + x2) / 2.0
  12998. + mathCos$2(psi) * cxp
  12999. - mathSin$2(psi) * cyp;
  13000. var cy = (y1 + y2) / 2.0
  13001. + mathSin$2(psi) * cxp
  13002. + mathCos$2(psi) * cyp;
  13003. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  13004. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  13005. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  13006. var dTheta = vAngle(u, v);
  13007. if (vRatio(u, v) <= -1) {
  13008. dTheta = PI$1;
  13009. }
  13010. if (vRatio(u, v) >= 1) {
  13011. dTheta = 0;
  13012. }
  13013. if (dTheta < 0) {
  13014. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  13015. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  13016. }
  13017. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  13018. }
  13019. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  13020. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  13021. function createPathProxyFromString(data) {
  13022. var path = new PathProxy();
  13023. if (!data) {
  13024. return path;
  13025. }
  13026. var cpx = 0;
  13027. var cpy = 0;
  13028. var subpathX = cpx;
  13029. var subpathY = cpy;
  13030. var prevCmd;
  13031. var CMD = PathProxy.CMD;
  13032. var cmdList = data.match(commandReg);
  13033. if (!cmdList) {
  13034. return path;
  13035. }
  13036. for (var l = 0; l < cmdList.length; l++) {
  13037. var cmdText = cmdList[l];
  13038. var cmdStr = cmdText.charAt(0);
  13039. var cmd = void 0;
  13040. var p = cmdText.match(numberReg) || [];
  13041. var pLen = p.length;
  13042. for (var i = 0; i < pLen; i++) {
  13043. p[i] = parseFloat(p[i]);
  13044. }
  13045. var off = 0;
  13046. while (off < pLen) {
  13047. var ctlPtx = void 0;
  13048. var ctlPty = void 0;
  13049. var rx = void 0;
  13050. var ry = void 0;
  13051. var psi = void 0;
  13052. var fa = void 0;
  13053. var fs = void 0;
  13054. var x1 = cpx;
  13055. var y1 = cpy;
  13056. var len = void 0;
  13057. var pathData = void 0;
  13058. switch (cmdStr) {
  13059. case 'l':
  13060. cpx += p[off++];
  13061. cpy += p[off++];
  13062. cmd = CMD.L;
  13063. path.addData(cmd, cpx, cpy);
  13064. break;
  13065. case 'L':
  13066. cpx = p[off++];
  13067. cpy = p[off++];
  13068. cmd = CMD.L;
  13069. path.addData(cmd, cpx, cpy);
  13070. break;
  13071. case 'm':
  13072. cpx += p[off++];
  13073. cpy += p[off++];
  13074. cmd = CMD.M;
  13075. path.addData(cmd, cpx, cpy);
  13076. subpathX = cpx;
  13077. subpathY = cpy;
  13078. cmdStr = 'l';
  13079. break;
  13080. case 'M':
  13081. cpx = p[off++];
  13082. cpy = p[off++];
  13083. cmd = CMD.M;
  13084. path.addData(cmd, cpx, cpy);
  13085. subpathX = cpx;
  13086. subpathY = cpy;
  13087. cmdStr = 'L';
  13088. break;
  13089. case 'h':
  13090. cpx += p[off++];
  13091. cmd = CMD.L;
  13092. path.addData(cmd, cpx, cpy);
  13093. break;
  13094. case 'H':
  13095. cpx = p[off++];
  13096. cmd = CMD.L;
  13097. path.addData(cmd, cpx, cpy);
  13098. break;
  13099. case 'v':
  13100. cpy += p[off++];
  13101. cmd = CMD.L;
  13102. path.addData(cmd, cpx, cpy);
  13103. break;
  13104. case 'V':
  13105. cpy = p[off++];
  13106. cmd = CMD.L;
  13107. path.addData(cmd, cpx, cpy);
  13108. break;
  13109. case 'C':
  13110. cmd = CMD.C;
  13111. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  13112. cpx = p[off - 2];
  13113. cpy = p[off - 1];
  13114. break;
  13115. case 'c':
  13116. cmd = CMD.C;
  13117. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  13118. cpx += p[off - 2];
  13119. cpy += p[off - 1];
  13120. break;
  13121. case 'S':
  13122. ctlPtx = cpx;
  13123. ctlPty = cpy;
  13124. len = path.len();
  13125. pathData = path.data;
  13126. if (prevCmd === CMD.C) {
  13127. ctlPtx += cpx - pathData[len - 4];
  13128. ctlPty += cpy - pathData[len - 3];
  13129. }
  13130. cmd = CMD.C;
  13131. x1 = p[off++];
  13132. y1 = p[off++];
  13133. cpx = p[off++];
  13134. cpy = p[off++];
  13135. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13136. break;
  13137. case 's':
  13138. ctlPtx = cpx;
  13139. ctlPty = cpy;
  13140. len = path.len();
  13141. pathData = path.data;
  13142. if (prevCmd === CMD.C) {
  13143. ctlPtx += cpx - pathData[len - 4];
  13144. ctlPty += cpy - pathData[len - 3];
  13145. }
  13146. cmd = CMD.C;
  13147. x1 = cpx + p[off++];
  13148. y1 = cpy + p[off++];
  13149. cpx += p[off++];
  13150. cpy += p[off++];
  13151. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13152. break;
  13153. case 'Q':
  13154. x1 = p[off++];
  13155. y1 = p[off++];
  13156. cpx = p[off++];
  13157. cpy = p[off++];
  13158. cmd = CMD.Q;
  13159. path.addData(cmd, x1, y1, cpx, cpy);
  13160. break;
  13161. case 'q':
  13162. x1 = p[off++] + cpx;
  13163. y1 = p[off++] + cpy;
  13164. cpx += p[off++];
  13165. cpy += p[off++];
  13166. cmd = CMD.Q;
  13167. path.addData(cmd, x1, y1, cpx, cpy);
  13168. break;
  13169. case 'T':
  13170. ctlPtx = cpx;
  13171. ctlPty = cpy;
  13172. len = path.len();
  13173. pathData = path.data;
  13174. if (prevCmd === CMD.Q) {
  13175. ctlPtx += cpx - pathData[len - 4];
  13176. ctlPty += cpy - pathData[len - 3];
  13177. }
  13178. cpx = p[off++];
  13179. cpy = p[off++];
  13180. cmd = CMD.Q;
  13181. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13182. break;
  13183. case 't':
  13184. ctlPtx = cpx;
  13185. ctlPty = cpy;
  13186. len = path.len();
  13187. pathData = path.data;
  13188. if (prevCmd === CMD.Q) {
  13189. ctlPtx += cpx - pathData[len - 4];
  13190. ctlPty += cpy - pathData[len - 3];
  13191. }
  13192. cpx += p[off++];
  13193. cpy += p[off++];
  13194. cmd = CMD.Q;
  13195. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13196. break;
  13197. case 'A':
  13198. rx = p[off++];
  13199. ry = p[off++];
  13200. psi = p[off++];
  13201. fa = p[off++];
  13202. fs = p[off++];
  13203. x1 = cpx, y1 = cpy;
  13204. cpx = p[off++];
  13205. cpy = p[off++];
  13206. cmd = CMD.A;
  13207. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  13208. break;
  13209. case 'a':
  13210. rx = p[off++];
  13211. ry = p[off++];
  13212. psi = p[off++];
  13213. fa = p[off++];
  13214. fs = p[off++];
  13215. x1 = cpx, y1 = cpy;
  13216. cpx += p[off++];
  13217. cpy += p[off++];
  13218. cmd = CMD.A;
  13219. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  13220. break;
  13221. }
  13222. }
  13223. if (cmdStr === 'z' || cmdStr === 'Z') {
  13224. cmd = CMD.Z;
  13225. path.addData(cmd);
  13226. cpx = subpathX;
  13227. cpy = subpathY;
  13228. }
  13229. prevCmd = cmd;
  13230. }
  13231. path.toStatic();
  13232. return path;
  13233. }
  13234. var SVGPath = (function (_super) {
  13235. __extends(SVGPath, _super);
  13236. function SVGPath() {
  13237. return _super !== null && _super.apply(this, arguments) || this;
  13238. }
  13239. SVGPath.prototype.applyTransform = function (m) { };
  13240. return SVGPath;
  13241. }(Path));
  13242. function isPathProxy(path) {
  13243. return path.setData != null;
  13244. }
  13245. function createPathOptions(str, opts) {
  13246. var pathProxy = createPathProxyFromString(str);
  13247. var innerOpts = extend({}, opts);
  13248. innerOpts.buildPath = function (path) {
  13249. var beProxy = isPathProxy(path);
  13250. if (beProxy && path.canSave()) {
  13251. path.appendPath(pathProxy);
  13252. var ctx = path.getContext();
  13253. if (ctx) {
  13254. path.rebuildPath(ctx, 1);
  13255. }
  13256. }
  13257. else {
  13258. var ctx = beProxy ? path.getContext() : path;
  13259. if (ctx) {
  13260. pathProxy.rebuildPath(ctx, 1);
  13261. }
  13262. }
  13263. };
  13264. innerOpts.applyTransform = function (m) {
  13265. transformPath(pathProxy, m);
  13266. this.dirtyShape();
  13267. };
  13268. return innerOpts;
  13269. }
  13270. function createFromString(str, opts) {
  13271. return new SVGPath(createPathOptions(str, opts));
  13272. }
  13273. function extendFromString(str, defaultOpts) {
  13274. var innerOpts = createPathOptions(str, defaultOpts);
  13275. var Sub = (function (_super) {
  13276. __extends(Sub, _super);
  13277. function Sub(opts) {
  13278. var _this = _super.call(this, opts) || this;
  13279. _this.applyTransform = innerOpts.applyTransform;
  13280. _this.buildPath = innerOpts.buildPath;
  13281. return _this;
  13282. }
  13283. return Sub;
  13284. }(SVGPath));
  13285. return Sub;
  13286. }
  13287. function mergePath(pathEls, opts) {
  13288. var pathList = [];
  13289. var len = pathEls.length;
  13290. for (var i = 0; i < len; i++) {
  13291. var pathEl = pathEls[i];
  13292. pathList.push(pathEl.getUpdatedPathProxy(true));
  13293. }
  13294. var pathBundle = new Path(opts);
  13295. pathBundle.createPathProxy();
  13296. pathBundle.buildPath = function (path) {
  13297. if (isPathProxy(path)) {
  13298. path.appendPath(pathList);
  13299. var ctx = path.getContext();
  13300. if (ctx) {
  13301. path.rebuildPath(ctx, 1);
  13302. }
  13303. }
  13304. };
  13305. return pathBundle;
  13306. }
  13307. var CircleShape = (function () {
  13308. function CircleShape() {
  13309. this.cx = 0;
  13310. this.cy = 0;
  13311. this.r = 0;
  13312. }
  13313. return CircleShape;
  13314. }());
  13315. var Circle = (function (_super) {
  13316. __extends(Circle, _super);
  13317. function Circle(opts) {
  13318. return _super.call(this, opts) || this;
  13319. }
  13320. Circle.prototype.getDefaultShape = function () {
  13321. return new CircleShape();
  13322. };
  13323. Circle.prototype.buildPath = function (ctx, shape) {
  13324. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13325. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  13326. };
  13327. return Circle;
  13328. }(Path));
  13329. Circle.prototype.type = 'circle';
  13330. var EllipseShape = (function () {
  13331. function EllipseShape() {
  13332. this.cx = 0;
  13333. this.cy = 0;
  13334. this.rx = 0;
  13335. this.ry = 0;
  13336. }
  13337. return EllipseShape;
  13338. }());
  13339. var Ellipse = (function (_super) {
  13340. __extends(Ellipse, _super);
  13341. function Ellipse(opts) {
  13342. return _super.call(this, opts) || this;
  13343. }
  13344. Ellipse.prototype.getDefaultShape = function () {
  13345. return new EllipseShape();
  13346. };
  13347. Ellipse.prototype.buildPath = function (ctx, shape) {
  13348. var k = 0.5522848;
  13349. var x = shape.cx;
  13350. var y = shape.cy;
  13351. var a = shape.rx;
  13352. var b = shape.ry;
  13353. var ox = a * k;
  13354. var oy = b * k;
  13355. ctx.moveTo(x - a, y);
  13356. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  13357. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  13358. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  13359. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  13360. ctx.closePath();
  13361. };
  13362. return Ellipse;
  13363. }(Path));
  13364. Ellipse.prototype.type = 'ellipse';
  13365. var PI$2 = Math.PI;
  13366. var PI2$5 = PI$2 * 2;
  13367. var mathSin$3 = Math.sin;
  13368. var mathCos$3 = Math.cos;
  13369. var mathACos = Math.acos;
  13370. var mathATan2 = Math.atan2;
  13371. var mathAbs$3 = Math.abs;
  13372. var mathSqrt$3 = Math.sqrt;
  13373. var mathMax$4 = Math.max;
  13374. var mathMin$4 = Math.min;
  13375. var e = 1e-4;
  13376. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  13377. var dx10 = x1 - x0;
  13378. var dy10 = y1 - y0;
  13379. var dx32 = x3 - x2;
  13380. var dy32 = y3 - y2;
  13381. var t = dy32 * dx10 - dx32 * dy10;
  13382. if (t * t < e) {
  13383. return;
  13384. }
  13385. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  13386. return [x0 + t * dx10, y0 + t * dy10];
  13387. }
  13388. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  13389. var x01 = x0 - x1;
  13390. var y01 = y0 - y1;
  13391. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  13392. var ox = lo * y01;
  13393. var oy = -lo * x01;
  13394. var x11 = x0 + ox;
  13395. var y11 = y0 + oy;
  13396. var x10 = x1 + ox;
  13397. var y10 = y1 + oy;
  13398. var x00 = (x11 + x10) / 2;
  13399. var y00 = (y11 + y10) / 2;
  13400. var dx = x10 - x11;
  13401. var dy = y10 - y11;
  13402. var d2 = dx * dx + dy * dy;
  13403. var r = radius - cr;
  13404. var s = x11 * y10 - x10 * y11;
  13405. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$4(0, r * r * d2 - s * s));
  13406. var cx0 = (s * dy - dx * d) / d2;
  13407. var cy0 = (-s * dx - dy * d) / d2;
  13408. var cx1 = (s * dy + dx * d) / d2;
  13409. var cy1 = (-s * dx + dy * d) / d2;
  13410. var dx0 = cx0 - x00;
  13411. var dy0 = cy0 - y00;
  13412. var dx1 = cx1 - x00;
  13413. var dy1 = cy1 - y00;
  13414. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  13415. cx0 = cx1;
  13416. cy0 = cy1;
  13417. }
  13418. return {
  13419. cx: cx0,
  13420. cy: cy0,
  13421. x0: -ox,
  13422. y0: -oy,
  13423. x1: cx0 * (radius / r - 1),
  13424. y1: cy0 * (radius / r - 1)
  13425. };
  13426. }
  13427. function normalizeCornerRadius(cr) {
  13428. var arr;
  13429. if (isArray(cr)) {
  13430. var len = cr.length;
  13431. if (!len) {
  13432. return cr;
  13433. }
  13434. if (len === 1) {
  13435. arr = [cr[0], cr[0], 0, 0];
  13436. }
  13437. else if (len === 2) {
  13438. arr = [cr[0], cr[0], cr[1], cr[1]];
  13439. }
  13440. else if (len === 3) {
  13441. arr = cr.concat(cr[2]);
  13442. }
  13443. else {
  13444. arr = cr;
  13445. }
  13446. }
  13447. else {
  13448. arr = [cr, cr, cr, cr];
  13449. }
  13450. return arr;
  13451. }
  13452. function buildPath$1(ctx, shape) {
  13453. var _a;
  13454. var radius = mathMax$4(shape.r, 0);
  13455. var innerRadius = mathMax$4(shape.r0 || 0, 0);
  13456. var hasRadius = radius > 0;
  13457. var hasInnerRadius = innerRadius > 0;
  13458. if (!hasRadius && !hasInnerRadius) {
  13459. return;
  13460. }
  13461. if (!hasRadius) {
  13462. radius = innerRadius;
  13463. innerRadius = 0;
  13464. }
  13465. if (innerRadius > radius) {
  13466. var tmp = radius;
  13467. radius = innerRadius;
  13468. innerRadius = tmp;
  13469. }
  13470. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  13471. if (isNaN(startAngle) || isNaN(endAngle)) {
  13472. return;
  13473. }
  13474. var cx = shape.cx, cy = shape.cy;
  13475. var clockwise = !!shape.clockwise;
  13476. var arc = mathAbs$3(endAngle - startAngle);
  13477. var mod = arc > PI2$5 && arc % PI2$5;
  13478. mod > e && (arc = mod);
  13479. if (!(radius > e)) {
  13480. ctx.moveTo(cx, cy);
  13481. }
  13482. else if (arc > PI2$5 - e) {
  13483. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  13484. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  13485. if (innerRadius > e) {
  13486. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  13487. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  13488. }
  13489. }
  13490. else {
  13491. var icrStart = void 0;
  13492. var icrEnd = void 0;
  13493. var ocrStart = void 0;
  13494. var ocrEnd = void 0;
  13495. var ocrs = void 0;
  13496. var ocre = void 0;
  13497. var icrs = void 0;
  13498. var icre = void 0;
  13499. var ocrMax = void 0;
  13500. var icrMax = void 0;
  13501. var limitedOcrMax = void 0;
  13502. var limitedIcrMax = void 0;
  13503. var xre = void 0;
  13504. var yre = void 0;
  13505. var xirs = void 0;
  13506. var yirs = void 0;
  13507. var xrs = radius * mathCos$3(startAngle);
  13508. var yrs = radius * mathSin$3(startAngle);
  13509. var xire = innerRadius * mathCos$3(endAngle);
  13510. var yire = innerRadius * mathSin$3(endAngle);
  13511. var hasArc = arc > e;
  13512. if (hasArc) {
  13513. var cornerRadius = shape.cornerRadius;
  13514. if (cornerRadius) {
  13515. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  13516. }
  13517. var halfRd = mathAbs$3(radius - innerRadius) / 2;
  13518. ocrs = mathMin$4(halfRd, ocrStart);
  13519. ocre = mathMin$4(halfRd, ocrEnd);
  13520. icrs = mathMin$4(halfRd, icrStart);
  13521. icre = mathMin$4(halfRd, icrEnd);
  13522. limitedOcrMax = ocrMax = mathMax$4(ocrs, ocre);
  13523. limitedIcrMax = icrMax = mathMax$4(icrs, icre);
  13524. if (ocrMax > e || icrMax > e) {
  13525. xre = radius * mathCos$3(endAngle);
  13526. yre = radius * mathSin$3(endAngle);
  13527. xirs = innerRadius * mathCos$3(startAngle);
  13528. yirs = innerRadius * mathSin$3(startAngle);
  13529. if (arc < PI$2) {
  13530. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  13531. if (it_1) {
  13532. var x0 = xrs - it_1[0];
  13533. var y0 = yrs - it_1[1];
  13534. var x1 = xre - it_1[0];
  13535. var y1 = yre - it_1[1];
  13536. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  13537. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  13538. limitedOcrMax = mathMin$4(ocrMax, (radius - b) / (a + 1));
  13539. limitedIcrMax = mathMin$4(icrMax, (innerRadius - b) / (a - 1));
  13540. }
  13541. }
  13542. }
  13543. }
  13544. if (!hasArc) {
  13545. ctx.moveTo(cx + xrs, cy + yrs);
  13546. }
  13547. else if (limitedOcrMax > e) {
  13548. var crStart = mathMin$4(ocrStart, limitedOcrMax);
  13549. var crEnd = mathMin$4(ocrEnd, limitedOcrMax);
  13550. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  13551. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  13552. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  13553. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  13554. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13555. }
  13556. else {
  13557. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  13558. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  13559. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13560. }
  13561. }
  13562. else {
  13563. ctx.moveTo(cx + xrs, cy + yrs);
  13564. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  13565. }
  13566. if (!(innerRadius > e) || !hasArc) {
  13567. ctx.lineTo(cx + xire, cy + yire);
  13568. }
  13569. else if (limitedIcrMax > e) {
  13570. var crStart = mathMin$4(icrStart, limitedIcrMax);
  13571. var crEnd = mathMin$4(icrEnd, limitedIcrMax);
  13572. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  13573. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  13574. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  13575. if (limitedIcrMax < icrMax && crStart === crEnd) {
  13576. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13577. }
  13578. else {
  13579. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  13580. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  13581. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13582. }
  13583. }
  13584. else {
  13585. ctx.lineTo(cx + xire, cy + yire);
  13586. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  13587. }
  13588. }
  13589. ctx.closePath();
  13590. }
  13591. var SectorShape = (function () {
  13592. function SectorShape() {
  13593. this.cx = 0;
  13594. this.cy = 0;
  13595. this.r0 = 0;
  13596. this.r = 0;
  13597. this.startAngle = 0;
  13598. this.endAngle = Math.PI * 2;
  13599. this.clockwise = true;
  13600. this.cornerRadius = 0;
  13601. }
  13602. return SectorShape;
  13603. }());
  13604. var Sector = (function (_super) {
  13605. __extends(Sector, _super);
  13606. function Sector(opts) {
  13607. return _super.call(this, opts) || this;
  13608. }
  13609. Sector.prototype.getDefaultShape = function () {
  13610. return new SectorShape();
  13611. };
  13612. Sector.prototype.buildPath = function (ctx, shape) {
  13613. buildPath$1(ctx, shape);
  13614. };
  13615. Sector.prototype.isZeroArea = function () {
  13616. return this.shape.startAngle === this.shape.endAngle
  13617. || this.shape.r === this.shape.r0;
  13618. };
  13619. return Sector;
  13620. }(Path));
  13621. Sector.prototype.type = 'sector';
  13622. var RingShape = (function () {
  13623. function RingShape() {
  13624. this.cx = 0;
  13625. this.cy = 0;
  13626. this.r = 0;
  13627. this.r0 = 0;
  13628. }
  13629. return RingShape;
  13630. }());
  13631. var Ring = (function (_super) {
  13632. __extends(Ring, _super);
  13633. function Ring(opts) {
  13634. return _super.call(this, opts) || this;
  13635. }
  13636. Ring.prototype.getDefaultShape = function () {
  13637. return new RingShape();
  13638. };
  13639. Ring.prototype.buildPath = function (ctx, shape) {
  13640. var x = shape.cx;
  13641. var y = shape.cy;
  13642. var PI2 = Math.PI * 2;
  13643. ctx.moveTo(x + shape.r, y);
  13644. ctx.arc(x, y, shape.r, 0, PI2, false);
  13645. ctx.moveTo(x + shape.r0, y);
  13646. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13647. };
  13648. return Ring;
  13649. }(Path));
  13650. Ring.prototype.type = 'ring';
  13651. function smoothBezier(points, smooth, isLoop, constraint) {
  13652. var cps = [];
  13653. var v = [];
  13654. var v1 = [];
  13655. var v2 = [];
  13656. var prevPoint;
  13657. var nextPoint;
  13658. var min$1;
  13659. var max$1;
  13660. if (constraint) {
  13661. min$1 = [Infinity, Infinity];
  13662. max$1 = [-Infinity, -Infinity];
  13663. for (var i = 0, len = points.length; i < len; i++) {
  13664. min(min$1, min$1, points[i]);
  13665. max(max$1, max$1, points[i]);
  13666. }
  13667. min(min$1, min$1, constraint[0]);
  13668. max(max$1, max$1, constraint[1]);
  13669. }
  13670. for (var i = 0, len = points.length; i < len; i++) {
  13671. var point = points[i];
  13672. if (isLoop) {
  13673. prevPoint = points[i ? i - 1 : len - 1];
  13674. nextPoint = points[(i + 1) % len];
  13675. }
  13676. else {
  13677. if (i === 0 || i === len - 1) {
  13678. cps.push(clone$1(points[i]));
  13679. continue;
  13680. }
  13681. else {
  13682. prevPoint = points[i - 1];
  13683. nextPoint = points[i + 1];
  13684. }
  13685. }
  13686. sub(v, nextPoint, prevPoint);
  13687. scale(v, v, smooth);
  13688. var d0 = distance(point, prevPoint);
  13689. var d1 = distance(point, nextPoint);
  13690. var sum = d0 + d1;
  13691. if (sum !== 0) {
  13692. d0 /= sum;
  13693. d1 /= sum;
  13694. }
  13695. scale(v1, v, -d0);
  13696. scale(v2, v, d1);
  13697. var cp0 = add([], point, v1);
  13698. var cp1 = add([], point, v2);
  13699. if (constraint) {
  13700. max(cp0, cp0, min$1);
  13701. min(cp0, cp0, max$1);
  13702. max(cp1, cp1, min$1);
  13703. min(cp1, cp1, max$1);
  13704. }
  13705. cps.push(cp0);
  13706. cps.push(cp1);
  13707. }
  13708. if (isLoop) {
  13709. cps.push(cps.shift());
  13710. }
  13711. return cps;
  13712. }
  13713. function buildPath$2(ctx, shape, closePath) {
  13714. var smooth = shape.smooth;
  13715. var points = shape.points;
  13716. if (points && points.length >= 2) {
  13717. if (smooth) {
  13718. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  13719. ctx.moveTo(points[0][0], points[0][1]);
  13720. var len = points.length;
  13721. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13722. var cp1 = controlPoints[i * 2];
  13723. var cp2 = controlPoints[i * 2 + 1];
  13724. var p = points[(i + 1) % len];
  13725. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  13726. }
  13727. }
  13728. else {
  13729. ctx.moveTo(points[0][0], points[0][1]);
  13730. for (var i = 1, l = points.length; i < l; i++) {
  13731. ctx.lineTo(points[i][0], points[i][1]);
  13732. }
  13733. }
  13734. closePath && ctx.closePath();
  13735. }
  13736. }
  13737. var PolygonShape = (function () {
  13738. function PolygonShape() {
  13739. this.points = null;
  13740. this.smooth = 0;
  13741. this.smoothConstraint = null;
  13742. }
  13743. return PolygonShape;
  13744. }());
  13745. var Polygon = (function (_super) {
  13746. __extends(Polygon, _super);
  13747. function Polygon(opts) {
  13748. return _super.call(this, opts) || this;
  13749. }
  13750. Polygon.prototype.getDefaultShape = function () {
  13751. return new PolygonShape();
  13752. };
  13753. Polygon.prototype.buildPath = function (ctx, shape) {
  13754. buildPath$2(ctx, shape, true);
  13755. };
  13756. return Polygon;
  13757. }(Path));
  13758. Polygon.prototype.type = 'polygon';
  13759. var PolylineShape = (function () {
  13760. function PolylineShape() {
  13761. this.points = null;
  13762. this.percent = 1;
  13763. this.smooth = 0;
  13764. this.smoothConstraint = null;
  13765. }
  13766. return PolylineShape;
  13767. }());
  13768. var Polyline = (function (_super) {
  13769. __extends(Polyline, _super);
  13770. function Polyline(opts) {
  13771. return _super.call(this, opts) || this;
  13772. }
  13773. Polyline.prototype.getDefaultStyle = function () {
  13774. return {
  13775. stroke: '#000',
  13776. fill: null
  13777. };
  13778. };
  13779. Polyline.prototype.getDefaultShape = function () {
  13780. return new PolylineShape();
  13781. };
  13782. Polyline.prototype.buildPath = function (ctx, shape) {
  13783. buildPath$2(ctx, shape, false);
  13784. };
  13785. return Polyline;
  13786. }(Path));
  13787. Polyline.prototype.type = 'polyline';
  13788. var subPixelOptimizeOutputShape$1 = {};
  13789. var LineShape = (function () {
  13790. function LineShape() {
  13791. this.x1 = 0;
  13792. this.y1 = 0;
  13793. this.x2 = 0;
  13794. this.y2 = 0;
  13795. this.percent = 1;
  13796. }
  13797. return LineShape;
  13798. }());
  13799. var Line = (function (_super) {
  13800. __extends(Line, _super);
  13801. function Line(opts) {
  13802. return _super.call(this, opts) || this;
  13803. }
  13804. Line.prototype.getDefaultStyle = function () {
  13805. return {
  13806. stroke: '#000',
  13807. fill: null
  13808. };
  13809. };
  13810. Line.prototype.getDefaultShape = function () {
  13811. return new LineShape();
  13812. };
  13813. Line.prototype.buildPath = function (ctx, shape) {
  13814. var x1;
  13815. var y1;
  13816. var x2;
  13817. var y2;
  13818. if (this.subPixelOptimize) {
  13819. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  13820. x1 = optimizedShape.x1;
  13821. y1 = optimizedShape.y1;
  13822. x2 = optimizedShape.x2;
  13823. y2 = optimizedShape.y2;
  13824. }
  13825. else {
  13826. x1 = shape.x1;
  13827. y1 = shape.y1;
  13828. x2 = shape.x2;
  13829. y2 = shape.y2;
  13830. }
  13831. var percent = shape.percent;
  13832. if (percent === 0) {
  13833. return;
  13834. }
  13835. ctx.moveTo(x1, y1);
  13836. if (percent < 1) {
  13837. x2 = x1 * (1 - percent) + x2 * percent;
  13838. y2 = y1 * (1 - percent) + y2 * percent;
  13839. }
  13840. ctx.lineTo(x2, y2);
  13841. };
  13842. Line.prototype.pointAt = function (p) {
  13843. var shape = this.shape;
  13844. return [
  13845. shape.x1 * (1 - p) + shape.x2 * p,
  13846. shape.y1 * (1 - p) + shape.y2 * p
  13847. ];
  13848. };
  13849. return Line;
  13850. }(Path));
  13851. Line.prototype.type = 'line';
  13852. var out = [];
  13853. var BezierCurveShape = (function () {
  13854. function BezierCurveShape() {
  13855. this.x1 = 0;
  13856. this.y1 = 0;
  13857. this.x2 = 0;
  13858. this.y2 = 0;
  13859. this.cpx1 = 0;
  13860. this.cpy1 = 0;
  13861. this.percent = 1;
  13862. }
  13863. return BezierCurveShape;
  13864. }());
  13865. function someVectorAt(shape, t, isTangent) {
  13866. var cpx2 = shape.cpx2;
  13867. var cpy2 = shape.cpy2;
  13868. if (cpx2 != null || cpy2 != null) {
  13869. return [
  13870. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13871. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13872. ];
  13873. }
  13874. else {
  13875. return [
  13876. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13877. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13878. ];
  13879. }
  13880. }
  13881. var BezierCurve = (function (_super) {
  13882. __extends(BezierCurve, _super);
  13883. function BezierCurve(opts) {
  13884. return _super.call(this, opts) || this;
  13885. }
  13886. BezierCurve.prototype.getDefaultStyle = function () {
  13887. return {
  13888. stroke: '#000',
  13889. fill: null
  13890. };
  13891. };
  13892. BezierCurve.prototype.getDefaultShape = function () {
  13893. return new BezierCurveShape();
  13894. };
  13895. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13896. var x1 = shape.x1;
  13897. var y1 = shape.y1;
  13898. var x2 = shape.x2;
  13899. var y2 = shape.y2;
  13900. var cpx1 = shape.cpx1;
  13901. var cpy1 = shape.cpy1;
  13902. var cpx2 = shape.cpx2;
  13903. var cpy2 = shape.cpy2;
  13904. var percent = shape.percent;
  13905. if (percent === 0) {
  13906. return;
  13907. }
  13908. ctx.moveTo(x1, y1);
  13909. if (cpx2 == null || cpy2 == null) {
  13910. if (percent < 1) {
  13911. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13912. cpx1 = out[1];
  13913. x2 = out[2];
  13914. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13915. cpy1 = out[1];
  13916. y2 = out[2];
  13917. }
  13918. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13919. }
  13920. else {
  13921. if (percent < 1) {
  13922. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13923. cpx1 = out[1];
  13924. cpx2 = out[2];
  13925. x2 = out[3];
  13926. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13927. cpy1 = out[1];
  13928. cpy2 = out[2];
  13929. y2 = out[3];
  13930. }
  13931. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13932. }
  13933. };
  13934. BezierCurve.prototype.pointAt = function (t) {
  13935. return someVectorAt(this.shape, t, false);
  13936. };
  13937. BezierCurve.prototype.tangentAt = function (t) {
  13938. var p = someVectorAt(this.shape, t, true);
  13939. return normalize(p, p);
  13940. };
  13941. return BezierCurve;
  13942. }(Path));
  13943. BezierCurve.prototype.type = 'bezier-curve';
  13944. var ArcShape = (function () {
  13945. function ArcShape() {
  13946. this.cx = 0;
  13947. this.cy = 0;
  13948. this.r = 0;
  13949. this.startAngle = 0;
  13950. this.endAngle = Math.PI * 2;
  13951. this.clockwise = true;
  13952. }
  13953. return ArcShape;
  13954. }());
  13955. var Arc = (function (_super) {
  13956. __extends(Arc, _super);
  13957. function Arc(opts) {
  13958. return _super.call(this, opts) || this;
  13959. }
  13960. Arc.prototype.getDefaultStyle = function () {
  13961. return {
  13962. stroke: '#000',
  13963. fill: null
  13964. };
  13965. };
  13966. Arc.prototype.getDefaultShape = function () {
  13967. return new ArcShape();
  13968. };
  13969. Arc.prototype.buildPath = function (ctx, shape) {
  13970. var x = shape.cx;
  13971. var y = shape.cy;
  13972. var r = Math.max(shape.r, 0);
  13973. var startAngle = shape.startAngle;
  13974. var endAngle = shape.endAngle;
  13975. var clockwise = shape.clockwise;
  13976. var unitX = Math.cos(startAngle);
  13977. var unitY = Math.sin(startAngle);
  13978. ctx.moveTo(unitX * r + x, unitY * r + y);
  13979. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13980. };
  13981. return Arc;
  13982. }(Path));
  13983. Arc.prototype.type = 'arc';
  13984. var CompoundPath = (function (_super) {
  13985. __extends(CompoundPath, _super);
  13986. function CompoundPath() {
  13987. var _this = _super !== null && _super.apply(this, arguments) || this;
  13988. _this.type = 'compound';
  13989. return _this;
  13990. }
  13991. CompoundPath.prototype._updatePathDirty = function () {
  13992. var paths = this.shape.paths;
  13993. var dirtyPath = this.shapeChanged();
  13994. for (var i = 0; i < paths.length; i++) {
  13995. dirtyPath = dirtyPath || paths[i].shapeChanged();
  13996. }
  13997. if (dirtyPath) {
  13998. this.dirtyShape();
  13999. }
  14000. };
  14001. CompoundPath.prototype.beforeBrush = function () {
  14002. this._updatePathDirty();
  14003. var paths = this.shape.paths || [];
  14004. var scale = this.getGlobalScale();
  14005. for (var i = 0; i < paths.length; i++) {
  14006. if (!paths[i].path) {
  14007. paths[i].createPathProxy();
  14008. }
  14009. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  14010. }
  14011. };
  14012. CompoundPath.prototype.buildPath = function (ctx, shape) {
  14013. var paths = shape.paths || [];
  14014. for (var i = 0; i < paths.length; i++) {
  14015. paths[i].buildPath(ctx, paths[i].shape, true);
  14016. }
  14017. };
  14018. CompoundPath.prototype.afterBrush = function () {
  14019. var paths = this.shape.paths || [];
  14020. for (var i = 0; i < paths.length; i++) {
  14021. paths[i].pathUpdated();
  14022. }
  14023. };
  14024. CompoundPath.prototype.getBoundingRect = function () {
  14025. this._updatePathDirty.call(this);
  14026. return Path.prototype.getBoundingRect.call(this);
  14027. };
  14028. return CompoundPath;
  14029. }(Path));
  14030. var Gradient = (function () {
  14031. function Gradient(colorStops) {
  14032. this.colorStops = colorStops || [];
  14033. }
  14034. Gradient.prototype.addColorStop = function (offset, color) {
  14035. this.colorStops.push({
  14036. offset: offset,
  14037. color: color
  14038. });
  14039. };
  14040. return Gradient;
  14041. }());
  14042. var LinearGradient = (function (_super) {
  14043. __extends(LinearGradient, _super);
  14044. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  14045. var _this = _super.call(this, colorStops) || this;
  14046. _this.x = x == null ? 0 : x;
  14047. _this.y = y == null ? 0 : y;
  14048. _this.x2 = x2 == null ? 1 : x2;
  14049. _this.y2 = y2 == null ? 0 : y2;
  14050. _this.type = 'linear';
  14051. _this.global = globalCoord || false;
  14052. return _this;
  14053. }
  14054. return LinearGradient;
  14055. }(Gradient));
  14056. var RadialGradient = (function (_super) {
  14057. __extends(RadialGradient, _super);
  14058. function RadialGradient(x, y, r, colorStops, globalCoord) {
  14059. var _this = _super.call(this, colorStops) || this;
  14060. _this.x = x == null ? 0.5 : x;
  14061. _this.y = y == null ? 0.5 : y;
  14062. _this.r = r == null ? 0.5 : r;
  14063. _this.type = 'radial';
  14064. _this.global = globalCoord || false;
  14065. return _this;
  14066. }
  14067. return RadialGradient;
  14068. }(Gradient));
  14069. var mathMin$5 = Math.min;
  14070. var mathMax$5 = Math.max;
  14071. var mathAbs$4 = Math.abs;
  14072. var _extent = [0, 0];
  14073. var _extent2 = [0, 0];
  14074. var _intersectCtx$1 = createIntersectContext();
  14075. var _minTv$1 = _intersectCtx$1.minTv;
  14076. var _maxTv$1 = _intersectCtx$1.maxTv;
  14077. var OrientedBoundingRect = (function () {
  14078. function OrientedBoundingRect(rect, transform) {
  14079. this._corners = [];
  14080. this._axes = [];
  14081. this._origin = [0, 0];
  14082. for (var i = 0; i < 4; i++) {
  14083. this._corners[i] = new Point();
  14084. }
  14085. for (var i = 0; i < 2; i++) {
  14086. this._axes[i] = new Point();
  14087. }
  14088. if (rect) {
  14089. this.fromBoundingRect(rect, transform);
  14090. }
  14091. }
  14092. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  14093. var corners = this._corners;
  14094. var axes = this._axes;
  14095. var x = rect.x;
  14096. var y = rect.y;
  14097. var x2 = x + rect.width;
  14098. var y2 = y + rect.height;
  14099. corners[0].set(x, y);
  14100. corners[1].set(x2, y);
  14101. corners[2].set(x2, y2);
  14102. corners[3].set(x, y2);
  14103. if (transform) {
  14104. for (var i = 0; i < 4; i++) {
  14105. corners[i].transform(transform);
  14106. }
  14107. }
  14108. Point.sub(axes[0], corners[1], corners[0]);
  14109. Point.sub(axes[1], corners[3], corners[0]);
  14110. axes[0].normalize();
  14111. axes[1].normalize();
  14112. for (var i = 0; i < 2; i++) {
  14113. this._origin[i] = axes[i].dot(corners[0]);
  14114. }
  14115. };
  14116. OrientedBoundingRect.prototype.intersect = function (other, mtv, opt) {
  14117. var overlapped = true;
  14118. var noMtv = !mtv;
  14119. if (mtv) {
  14120. Point.set(mtv, 0, 0);
  14121. }
  14122. _intersectCtx$1.reset(opt, !noMtv);
  14123. if (!this._intersectCheckOneSide(this, other, noMtv, 1)) {
  14124. overlapped = false;
  14125. if (noMtv) {
  14126. return overlapped;
  14127. }
  14128. }
  14129. if (!this._intersectCheckOneSide(other, this, noMtv, -1)) {
  14130. overlapped = false;
  14131. if (noMtv) {
  14132. return overlapped;
  14133. }
  14134. }
  14135. if (!noMtv && !_intersectCtx$1.negativeSize) {
  14136. Point.copy(mtv, overlapped
  14137. ? (_intersectCtx$1.useDir ? _intersectCtx$1.dirMinTv : _minTv$1)
  14138. : _maxTv$1);
  14139. }
  14140. return overlapped;
  14141. };
  14142. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, noMtv, inverse) {
  14143. var overlapped = true;
  14144. for (var i = 0; i < 2; i++) {
  14145. var axis = self._axes[i];
  14146. self._getProjMinMaxOnAxis(i, self._corners, _extent);
  14147. self._getProjMinMaxOnAxis(i, other._corners, _extent2);
  14148. if (_intersectCtx$1.negativeSize || _extent[1] < _extent2[0] || _extent[0] > _extent2[1]) {
  14149. overlapped = false;
  14150. if (_intersectCtx$1.negativeSize || noMtv) {
  14151. return overlapped;
  14152. }
  14153. var dist0 = mathAbs$4(_extent2[0] - _extent[1]);
  14154. var dist1 = mathAbs$4(_extent[0] - _extent2[1]);
  14155. if (mathMin$5(dist0, dist1) > _maxTv$1.len()) {
  14156. if (dist0 < dist1) {
  14157. Point.scale(_maxTv$1, axis, -dist0 * inverse);
  14158. }
  14159. else {
  14160. Point.scale(_maxTv$1, axis, dist1 * inverse);
  14161. }
  14162. }
  14163. }
  14164. else if (!noMtv) {
  14165. var dist0 = mathAbs$4(_extent2[0] - _extent[1]);
  14166. var dist1 = mathAbs$4(_extent[0] - _extent2[1]);
  14167. if (_intersectCtx$1.useDir || mathMin$5(dist0, dist1) < _minTv$1.len()) {
  14168. if (dist0 < dist1 || !_intersectCtx$1.bidirectional) {
  14169. Point.scale(_minTv$1, axis, dist0 * inverse);
  14170. if (_intersectCtx$1.useDir) {
  14171. _intersectCtx$1.calcDirMTV();
  14172. }
  14173. }
  14174. if (dist0 >= dist1 || !_intersectCtx$1.bidirectional) {
  14175. Point.scale(_minTv$1, axis, -dist1 * inverse);
  14176. if (_intersectCtx$1.useDir) {
  14177. _intersectCtx$1.calcDirMTV();
  14178. }
  14179. }
  14180. }
  14181. }
  14182. }
  14183. return overlapped;
  14184. };
  14185. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  14186. var axis = this._axes[dim];
  14187. var origin = this._origin;
  14188. var proj = corners[0].dot(axis) + origin[dim];
  14189. var min = proj;
  14190. var max = proj;
  14191. for (var i = 1; i < corners.length; i++) {
  14192. var proj_1 = corners[i].dot(axis) + origin[dim];
  14193. min = mathMin$5(proj_1, min);
  14194. max = mathMax$5(proj_1, max);
  14195. }
  14196. out[0] = min + _intersectCtx$1.touchThreshold;
  14197. out[1] = max - _intersectCtx$1.touchThreshold;
  14198. _intersectCtx$1.negativeSize = out[1] < out[0];
  14199. };
  14200. return OrientedBoundingRect;
  14201. }());
  14202. var m = [];
  14203. var IncrementalDisplayable = (function (_super) {
  14204. __extends(IncrementalDisplayable, _super);
  14205. function IncrementalDisplayable() {
  14206. var _this = _super !== null && _super.apply(this, arguments) || this;
  14207. _this.notClear = true;
  14208. _this.incremental = true;
  14209. _this._displayables = [];
  14210. _this._temporaryDisplayables = [];
  14211. _this._cursor = 0;
  14212. return _this;
  14213. }
  14214. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  14215. cb.call(context, this);
  14216. };
  14217. IncrementalDisplayable.prototype.useStyle = function () {
  14218. this.style = {};
  14219. };
  14220. IncrementalDisplayable.prototype.getCursor = function () {
  14221. return this._cursor;
  14222. };
  14223. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  14224. this._cursor = this._displayables.length;
  14225. };
  14226. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  14227. this._displayables = [];
  14228. this._temporaryDisplayables = [];
  14229. this._cursor = 0;
  14230. this.markRedraw();
  14231. this.notClear = false;
  14232. };
  14233. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  14234. this._temporaryDisplayables = [];
  14235. };
  14236. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  14237. if (notPersistent) {
  14238. this._temporaryDisplayables.push(displayable);
  14239. }
  14240. else {
  14241. this._displayables.push(displayable);
  14242. }
  14243. this.markRedraw();
  14244. };
  14245. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  14246. notPersistent = notPersistent || false;
  14247. for (var i = 0; i < displayables.length; i++) {
  14248. this.addDisplayable(displayables[i], notPersistent);
  14249. }
  14250. };
  14251. IncrementalDisplayable.prototype.getDisplayables = function () {
  14252. return this._displayables;
  14253. };
  14254. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  14255. return this._temporaryDisplayables;
  14256. };
  14257. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  14258. for (var i = this._cursor; i < this._displayables.length; i++) {
  14259. cb && cb(this._displayables[i]);
  14260. }
  14261. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14262. cb && cb(this._temporaryDisplayables[i]);
  14263. }
  14264. };
  14265. IncrementalDisplayable.prototype.update = function () {
  14266. this.updateTransform();
  14267. for (var i = this._cursor; i < this._displayables.length; i++) {
  14268. var displayable = this._displayables[i];
  14269. displayable.parent = this;
  14270. displayable.update();
  14271. displayable.parent = null;
  14272. }
  14273. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14274. var displayable = this._temporaryDisplayables[i];
  14275. displayable.parent = this;
  14276. displayable.update();
  14277. displayable.parent = null;
  14278. }
  14279. };
  14280. IncrementalDisplayable.prototype.getBoundingRect = function () {
  14281. if (!this._rect) {
  14282. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  14283. for (var i = 0; i < this._displayables.length; i++) {
  14284. var displayable = this._displayables[i];
  14285. var childRect = displayable.getBoundingRect().clone();
  14286. if (displayable.needLocalTransform()) {
  14287. childRect.applyTransform(displayable.getLocalTransform(m));
  14288. }
  14289. rect.union(childRect);
  14290. }
  14291. this._rect = rect;
  14292. }
  14293. return this._rect;
  14294. };
  14295. IncrementalDisplayable.prototype.contain = function (x, y) {
  14296. var localPos = this.transformCoordToLocal(x, y);
  14297. var rect = this.getBoundingRect();
  14298. if (rect.contain(localPos[0], localPos[1])) {
  14299. for (var i = 0; i < this._displayables.length; i++) {
  14300. var displayable = this._displayables[i];
  14301. if (displayable.contain(x, y)) {
  14302. return true;
  14303. }
  14304. }
  14305. }
  14306. return false;
  14307. };
  14308. return IncrementalDisplayable;
  14309. }(Displayable));
  14310. // Stored properties for further transition.
  14311. var transitionStore = makeInner();
  14312. /**
  14313. * Return null if animation is disabled.
  14314. */
  14315. function getAnimationConfig(animationType, animatableModel, dataIndex,
  14316. // Extra opts can override the option in animatable model.
  14317. extraOpts,
  14318. // TODO It's only for pictorial bar now.
  14319. extraDelayParams) {
  14320. var animationPayload;
  14321. // Check if there is global animation configuration from dataZoom/resize can override the config in option.
  14322. // If animation is enabled. Will use this animation config in payload.
  14323. // If animation is disabled. Just ignore it.
  14324. if (animatableModel && animatableModel.ecModel) {
  14325. var updatePayload = animatableModel.ecModel.getUpdatePayload();
  14326. animationPayload = updatePayload && updatePayload.animation;
  14327. }
  14328. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  14329. var isUpdate = animationType === 'update';
  14330. if (animationEnabled) {
  14331. var duration = void 0;
  14332. var easing = void 0;
  14333. var delay = void 0;
  14334. if (extraOpts) {
  14335. duration = retrieve2(extraOpts.duration, 200);
  14336. easing = retrieve2(extraOpts.easing, 'cubicOut');
  14337. delay = 0;
  14338. } else {
  14339. duration = animatableModel.getShallow(isUpdate ? 'animationDurationUpdate' : 'animationDuration');
  14340. easing = animatableModel.getShallow(isUpdate ? 'animationEasingUpdate' : 'animationEasing');
  14341. delay = animatableModel.getShallow(isUpdate ? 'animationDelayUpdate' : 'animationDelay');
  14342. }
  14343. // animation from payload has highest priority.
  14344. if (animationPayload) {
  14345. animationPayload.duration != null && (duration = animationPayload.duration);
  14346. animationPayload.easing != null && (easing = animationPayload.easing);
  14347. animationPayload.delay != null && (delay = animationPayload.delay);
  14348. }
  14349. if (isFunction(delay)) {
  14350. delay = delay(dataIndex, extraDelayParams);
  14351. }
  14352. if (isFunction(duration)) {
  14353. duration = duration(dataIndex);
  14354. }
  14355. var config = {
  14356. duration: duration || 0,
  14357. delay: delay,
  14358. easing: easing
  14359. };
  14360. return config;
  14361. } else {
  14362. return null;
  14363. }
  14364. }
  14365. function animateOrSetProps(animationType, el, props, animatableModel, dataIndex, cb, during) {
  14366. var isFrom = false;
  14367. var removeOpt;
  14368. if (isFunction(dataIndex)) {
  14369. during = cb;
  14370. cb = dataIndex;
  14371. dataIndex = null;
  14372. } else if (isObject(dataIndex)) {
  14373. cb = dataIndex.cb;
  14374. during = dataIndex.during;
  14375. isFrom = dataIndex.isFrom;
  14376. removeOpt = dataIndex.removeOpt;
  14377. dataIndex = dataIndex.dataIndex;
  14378. }
  14379. var isRemove = animationType === 'leave';
  14380. if (!isRemove) {
  14381. // Must stop the remove animation.
  14382. el.stopAnimation('leave');
  14383. }
  14384. var animationConfig = getAnimationConfig(animationType, animatableModel, dataIndex, isRemove ? removeOpt || {} : null, animatableModel && animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  14385. if (animationConfig && animationConfig.duration > 0) {
  14386. var duration = animationConfig.duration;
  14387. var animationDelay = animationConfig.delay;
  14388. var animationEasing = animationConfig.easing;
  14389. var animateConfig = {
  14390. duration: duration,
  14391. delay: animationDelay || 0,
  14392. easing: animationEasing,
  14393. done: cb,
  14394. force: !!cb || !!during,
  14395. // Set to final state in update/init animation.
  14396. // So the post processing based on the path shape can be done correctly.
  14397. setToFinal: !isRemove,
  14398. scope: animationType,
  14399. during: during
  14400. };
  14401. isFrom ? el.animateFrom(props, animateConfig) : el.animateTo(props, animateConfig);
  14402. } else {
  14403. el.stopAnimation();
  14404. // If `isFrom`, the props is the "from" props.
  14405. !isFrom && el.attr(props);
  14406. // Call during at least once.
  14407. during && during(1);
  14408. cb && cb();
  14409. }
  14410. }
  14411. /**
  14412. * Update graphic element properties with or without animation according to the
  14413. * configuration in series.
  14414. *
  14415. * Caution: this method will stop previous animation.
  14416. * So do not use this method to one element twice before
  14417. * animation starts, unless you know what you are doing.
  14418. * @example
  14419. * graphic.updateProps(el, {
  14420. * position: [100, 100]
  14421. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  14422. * // Or
  14423. * graphic.updateProps(el, {
  14424. * position: [100, 100]
  14425. * }, seriesModel, function () { console.log('Animation done!'); });
  14426. */
  14427. function updateProps(el, props,
  14428. // TODO: TYPE AnimatableModel
  14429. animatableModel, dataIndex, cb, during) {
  14430. animateOrSetProps('update', el, props, animatableModel, dataIndex, cb, during);
  14431. }
  14432. /**
  14433. * Init graphic element properties with or without animation according to the
  14434. * configuration in series.
  14435. *
  14436. * Caution: this method will stop previous animation.
  14437. * So do not use this method to one element twice before
  14438. * animation starts, unless you know what you are doing.
  14439. */
  14440. function initProps(el, props, animatableModel, dataIndex, cb, during) {
  14441. animateOrSetProps('enter', el, props, animatableModel, dataIndex, cb, during);
  14442. }
  14443. /**
  14444. * If element is removed.
  14445. * It can determine if element is having remove animation.
  14446. */
  14447. function isElementRemoved(el) {
  14448. if (!el.__zr) {
  14449. return true;
  14450. }
  14451. for (var i = 0; i < el.animators.length; i++) {
  14452. var animator = el.animators[i];
  14453. if (animator.scope === 'leave') {
  14454. return true;
  14455. }
  14456. }
  14457. return false;
  14458. }
  14459. /**
  14460. * Remove graphic element
  14461. */
  14462. function removeElement(el, props, animatableModel, dataIndex, cb, during) {
  14463. // Don't do remove animation twice.
  14464. if (isElementRemoved(el)) {
  14465. return;
  14466. }
  14467. animateOrSetProps('leave', el, props, animatableModel, dataIndex, cb, during);
  14468. }
  14469. function fadeOutDisplayable(el, animatableModel, dataIndex, done) {
  14470. el.removeTextContent();
  14471. el.removeTextGuideLine();
  14472. removeElement(el, {
  14473. style: {
  14474. opacity: 0
  14475. }
  14476. }, animatableModel, dataIndex, done);
  14477. }
  14478. function removeElementWithFadeOut(el, animatableModel, dataIndex) {
  14479. function doRemove() {
  14480. el.parent && el.parent.remove(el);
  14481. }
  14482. // Hide label and labelLine first
  14483. // TODO Also use fade out animation?
  14484. if (!el.isGroup) {
  14485. fadeOutDisplayable(el, animatableModel, dataIndex, doRemove);
  14486. } else {
  14487. el.traverse(function (disp) {
  14488. if (!disp.isGroup) {
  14489. // Can invoke doRemove multiple times.
  14490. fadeOutDisplayable(disp, animatableModel, dataIndex, doRemove);
  14491. }
  14492. });
  14493. }
  14494. }
  14495. /**
  14496. * Save old style for style transition in universalTransition module.
  14497. * It's used when element will be reused in each render.
  14498. * For chart like map, heatmap, which will always create new element.
  14499. * We don't need to save this because universalTransition can get old style from the old element
  14500. */
  14501. function saveOldStyle(el) {
  14502. transitionStore(el).oldStyle = el.style;
  14503. }
  14504. var _customShapeMap = {};
  14505. var XY$1 = ['x', 'y'];
  14506. var WH$1 = ['width', 'height'];
  14507. /**
  14508. * Extend shape with parameters
  14509. */
  14510. function extendShape(opts) {
  14511. return Path.extend(opts);
  14512. }
  14513. var extendPathFromString = extendFromString;
  14514. /**
  14515. * Extend path
  14516. */
  14517. function extendPath(pathData, opts) {
  14518. return extendPathFromString(pathData, opts);
  14519. }
  14520. /**
  14521. * Register a user defined shape.
  14522. * The shape class can be fetched by `getShapeClass`
  14523. * This method will overwrite the registered shapes, including
  14524. * the registered built-in shapes, if using the same `name`.
  14525. * The shape can be used in `custom series` and
  14526. * `graphic component` by declaring `{type: name}`.
  14527. *
  14528. * @param name
  14529. * @param ShapeClass Can be generated by `extendShape`.
  14530. */
  14531. function registerShape(name, ShapeClass) {
  14532. _customShapeMap[name] = ShapeClass;
  14533. }
  14534. /**
  14535. * Find shape class registered by `registerShape`. Usually used in
  14536. * fetching user defined shape.
  14537. *
  14538. * [Caution]:
  14539. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  14540. * to use user registered shapes.
  14541. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  14542. * `registerShape` by default. That enables users to get both built-in
  14543. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  14544. * the built-in shapes by using names like 'circle', 'rect' via calling
  14545. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  14546. * in case that it is overwritten by users, except that some features, like
  14547. * `custom series`, `graphic component`, do it deliberately.
  14548. *
  14549. * (2) In the features like `custom series`, `graphic component`, the user input
  14550. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  14551. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  14552. * are reserved names, that is, if some user registers a shape named `'image'`,
  14553. * the shape will not be used. If we intending to add some more reserved names
  14554. * in feature, that might bring break changes (disable some existing user shape
  14555. * names). But that case probably rarely happens. So we don't make more mechanism
  14556. * to resolve this issue here.
  14557. *
  14558. * @param name
  14559. * @return The shape class. If not found, return nothing.
  14560. */
  14561. function getShapeClass(name) {
  14562. if (_customShapeMap.hasOwnProperty(name)) {
  14563. return _customShapeMap[name];
  14564. }
  14565. }
  14566. /**
  14567. * Create a path element from path data string
  14568. * @param pathData
  14569. * @param opts
  14570. * @param rect
  14571. * @param layout 'center' or 'cover' default to be cover
  14572. */
  14573. function makePath(pathData, opts, rect, layout) {
  14574. var path = createFromString(pathData, opts);
  14575. if (rect) {
  14576. if (layout === 'center') {
  14577. rect = centerGraphic(rect, path.getBoundingRect());
  14578. }
  14579. resizePath(path, rect);
  14580. }
  14581. return path;
  14582. }
  14583. /**
  14584. * Create a image element from image url
  14585. * @param imageUrl image url
  14586. * @param opts options
  14587. * @param rect constrain rect
  14588. * @param layout 'center' or 'cover'. Default to be 'cover'
  14589. */
  14590. function makeImage(imageUrl, rect, layout) {
  14591. var zrImg = new ZRImage({
  14592. style: {
  14593. image: imageUrl,
  14594. x: rect.x,
  14595. y: rect.y,
  14596. width: rect.width,
  14597. height: rect.height
  14598. },
  14599. onload: function (img) {
  14600. if (layout === 'center') {
  14601. var boundingRect = {
  14602. width: img.width,
  14603. height: img.height
  14604. };
  14605. zrImg.setStyle(centerGraphic(rect, boundingRect));
  14606. }
  14607. }
  14608. });
  14609. return zrImg;
  14610. }
  14611. /**
  14612. * Get position of centered element in bounding box.
  14613. *
  14614. * @param rect element local bounding box
  14615. * @param boundingRect constraint bounding box
  14616. * @return element position containing x, y, width, and height
  14617. */
  14618. function centerGraphic(rect, boundingRect) {
  14619. // Set rect to center, keep width / height ratio.
  14620. var aspect = boundingRect.width / boundingRect.height;
  14621. var width = rect.height * aspect;
  14622. var height;
  14623. if (width <= rect.width) {
  14624. height = rect.height;
  14625. } else {
  14626. width = rect.width;
  14627. height = width / aspect;
  14628. }
  14629. var cx = rect.x + rect.width / 2;
  14630. var cy = rect.y + rect.height / 2;
  14631. return {
  14632. x: cx - width / 2,
  14633. y: cy - height / 2,
  14634. width: width,
  14635. height: height
  14636. };
  14637. }
  14638. var mergePath$1 = mergePath;
  14639. /**
  14640. * Resize a path to fit the rect
  14641. * @param path
  14642. * @param rect
  14643. */
  14644. function resizePath(path, rect) {
  14645. if (!path.applyTransform) {
  14646. return;
  14647. }
  14648. var pathRect = path.getBoundingRect();
  14649. var m = pathRect.calculateTransform(rect);
  14650. path.applyTransform(m);
  14651. }
  14652. /**
  14653. * Sub pixel optimize line for canvas
  14654. */
  14655. function subPixelOptimizeLine$1(shape, lineWidth) {
  14656. subPixelOptimizeLine(shape, shape, {
  14657. lineWidth: lineWidth
  14658. });
  14659. return shape;
  14660. }
  14661. /**
  14662. * Get transform matrix of target (param target),
  14663. * in coordinate of its ancestor (param ancestor)
  14664. *
  14665. * @param target
  14666. * @param [ancestor]
  14667. */
  14668. function getTransform(target, ancestor) {
  14669. var mat = identity([]);
  14670. while (target && target !== ancestor) {
  14671. mul$1(mat, target.getLocalTransform(), mat);
  14672. target = target.parent;
  14673. }
  14674. return mat;
  14675. }
  14676. function isNotGroup(el) {
  14677. return !el.isGroup;
  14678. }
  14679. function isPath(el) {
  14680. return el.shape != null;
  14681. }
  14682. /**
  14683. * Apply group transition animation from g1 to g2.
  14684. * If no animatableModel, no animation.
  14685. */
  14686. function groupTransition(g1, g2, animatableModel) {
  14687. if (!g1 || !g2) {
  14688. return;
  14689. }
  14690. function getElMap(g) {
  14691. var elMap = {};
  14692. g.traverse(function (el) {
  14693. if (isNotGroup(el) && el.anid) {
  14694. elMap[el.anid] = el;
  14695. }
  14696. });
  14697. return elMap;
  14698. }
  14699. function getAnimatableProps(el) {
  14700. var obj = {
  14701. x: el.x,
  14702. y: el.y,
  14703. rotation: el.rotation
  14704. };
  14705. if (isPath(el)) {
  14706. obj.shape = clone(el.shape);
  14707. }
  14708. return obj;
  14709. }
  14710. var elMap1 = getElMap(g1);
  14711. g2.traverse(function (el) {
  14712. if (isNotGroup(el) && el.anid) {
  14713. var oldEl = elMap1[el.anid];
  14714. if (oldEl) {
  14715. var newProp = getAnimatableProps(el);
  14716. el.attr(getAnimatableProps(oldEl));
  14717. updateProps(el, newProp, animatableModel, getECData(el).dataIndex);
  14718. }
  14719. }
  14720. });
  14721. }
  14722. function clipPointsByRect(points, rect) {
  14723. // FIXME: This way might be incorrect when graphic clipped by a corner
  14724. // and when element has a border.
  14725. return map(points, function (point) {
  14726. var x = point[0];
  14727. x = mathMax$1(x, rect.x);
  14728. x = mathMin$1(x, rect.x + rect.width);
  14729. var y = point[1];
  14730. y = mathMax$1(y, rect.y);
  14731. y = mathMin$1(y, rect.y + rect.height);
  14732. return [x, y];
  14733. });
  14734. }
  14735. /**
  14736. * Return a new clipped rect. If rect size are negative, return undefined.
  14737. */
  14738. function clipRectByRect(targetRect, rect) {
  14739. var x = mathMax$1(targetRect.x, rect.x);
  14740. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  14741. var y = mathMax$1(targetRect.y, rect.y);
  14742. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  14743. // If the total rect is cliped, nothing, including the border,
  14744. // should be painted. So return undefined.
  14745. if (x2 >= x && y2 >= y) {
  14746. return {
  14747. x: x,
  14748. y: y,
  14749. width: x2 - x,
  14750. height: y2 - y
  14751. };
  14752. }
  14753. }
  14754. function createIcon(iconStr,
  14755. // Support 'image://' or 'path://' or direct svg path.
  14756. opt, rect) {
  14757. var innerOpts = extend({
  14758. rectHover: true
  14759. }, opt);
  14760. var style = innerOpts.style = {
  14761. strokeNoScale: true
  14762. };
  14763. rect = rect || {
  14764. x: -1,
  14765. y: -1,
  14766. width: 2,
  14767. height: 2
  14768. };
  14769. if (iconStr) {
  14770. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), defaults(style, rect), new ZRImage(innerOpts)) : makePath(iconStr.replace('path://', ''), innerOpts, rect, 'center');
  14771. }
  14772. }
  14773. /**
  14774. * NOTE:
  14775. * A negative-width/height rect (due to negative margins) is not supported;
  14776. * it will be clampped to zero width/height.
  14777. * Although negative-width/height rects can be defined reasonably following the
  14778. * similar sense in CSS, but they are rarely used, hard to understand and complicated.
  14779. *
  14780. * @param rect Assume its width/height >= 0 if existing.
  14781. * x/y/width/height is allowed to be NaN,
  14782. * for the case that only x/width or y/height is intended to be computed.
  14783. * @param delta
  14784. * If be `number[]`, should be `[top, right, bottom, left]`,
  14785. * which can be used in padding or margin case.
  14786. * @see `normalizeCssArray` in `util/format.ts`
  14787. * If be `number`, it means [delta, delta, delta, delta],
  14788. * which can be used in lineWidth (borderWith) case,
  14789. * [NOTICE]: commonly pass lineWidth / 2, following the convention that border is
  14790. * half inside half outside of the rect.
  14791. * @param shrinkOrExpand
  14792. * `true` - shrink if `delta[i]` is positive, commmonly used in `padding` case.
  14793. * `false` - expand if `delta[i]` is positive, commmonly used in `margin` case. (default)
  14794. * @param noNegative
  14795. * `true` - negative `delta[i]` will be clampped to 0.
  14796. * `false` - No clamp to `delta`. (default).
  14797. * @return The input `rect`.
  14798. */
  14799. function expandOrShrinkRect(rect, delta, shrinkOrExpand, noNegative, minSize // by default [0, 0].
  14800. ) {
  14801. if (delta == null) {
  14802. return rect;
  14803. } else if (isNumber(delta)) {
  14804. _tmpExpandRectDelta[0] = _tmpExpandRectDelta[1] = _tmpExpandRectDelta[2] = _tmpExpandRectDelta[3] = delta;
  14805. } else {
  14806. if ("development" !== 'production') {
  14807. assert(delta.length === 4);
  14808. }
  14809. _tmpExpandRectDelta[0] = delta[0];
  14810. _tmpExpandRectDelta[1] = delta[1];
  14811. _tmpExpandRectDelta[2] = delta[2];
  14812. _tmpExpandRectDelta[3] = delta[3];
  14813. }
  14814. if (noNegative) {
  14815. _tmpExpandRectDelta[0] = mathMax$1(0, _tmpExpandRectDelta[0]);
  14816. _tmpExpandRectDelta[1] = mathMax$1(0, _tmpExpandRectDelta[1]);
  14817. _tmpExpandRectDelta[2] = mathMax$1(0, _tmpExpandRectDelta[2]);
  14818. _tmpExpandRectDelta[3] = mathMax$1(0, _tmpExpandRectDelta[3]);
  14819. }
  14820. if (shrinkOrExpand) {
  14821. _tmpExpandRectDelta[0] = -_tmpExpandRectDelta[0];
  14822. _tmpExpandRectDelta[1] = -_tmpExpandRectDelta[1];
  14823. _tmpExpandRectDelta[2] = -_tmpExpandRectDelta[2];
  14824. _tmpExpandRectDelta[3] = -_tmpExpandRectDelta[3];
  14825. }
  14826. expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'x', 'width', 3, 1, minSize && minSize[0] || 0);
  14827. expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'y', 'height', 0, 2, minSize && minSize[1] || 0);
  14828. return rect;
  14829. }
  14830. var _tmpExpandRectDelta = [0, 0, 0, 0];
  14831. function expandRectOnOneDimension(rect, delta, xy, wh, ltIdx, rbIdx, minSize) {
  14832. var deltaSum = delta[rbIdx] + delta[ltIdx];
  14833. var oldSize = rect[wh];
  14834. rect[wh] += deltaSum;
  14835. minSize = mathMax$1(0, mathMin$1(minSize, oldSize));
  14836. if (rect[wh] < minSize) {
  14837. rect[wh] = minSize;
  14838. // Try to make the position of the zero rect reasonable in most visual cases.
  14839. rect[xy] += delta[ltIdx] >= 0 ? -delta[ltIdx] : delta[rbIdx] >= 0 ? oldSize + delta[rbIdx] : mathAbs$1(deltaSum) > 1e-8 ? (oldSize - minSize) * delta[ltIdx] / deltaSum : 0;
  14840. } else {
  14841. rect[xy] -= delta[ltIdx];
  14842. }
  14843. }
  14844. function setTooltipConfig(opt) {
  14845. var itemTooltipOption = opt.itemTooltipOption;
  14846. var componentModel = opt.componentModel;
  14847. var itemName = opt.itemName;
  14848. var itemTooltipOptionObj = isString(itemTooltipOption) ? {
  14849. formatter: itemTooltipOption
  14850. } : itemTooltipOption;
  14851. var mainType = componentModel.mainType;
  14852. var componentIndex = componentModel.componentIndex;
  14853. var formatterParams = {
  14854. componentType: mainType,
  14855. name: itemName,
  14856. $vars: ['name']
  14857. };
  14858. formatterParams[mainType + 'Index'] = componentIndex;
  14859. var formatterParamsExtra = opt.formatterParamsExtra;
  14860. if (formatterParamsExtra) {
  14861. each(keys(formatterParamsExtra), function (key) {
  14862. if (!hasOwn(formatterParams, key)) {
  14863. formatterParams[key] = formatterParamsExtra[key];
  14864. formatterParams.$vars.push(key);
  14865. }
  14866. });
  14867. }
  14868. var ecData = getECData(opt.el);
  14869. ecData.componentMainType = mainType;
  14870. ecData.componentIndex = componentIndex;
  14871. ecData.tooltipConfig = {
  14872. name: itemName,
  14873. option: defaults({
  14874. content: itemName,
  14875. encodeHTMLContent: true,
  14876. formatterParams: formatterParams
  14877. }, itemTooltipOptionObj)
  14878. };
  14879. }
  14880. function traverseElement(el, cb) {
  14881. var stopped;
  14882. // TODO
  14883. // Polyfill for fixing zrender group traverse don't visit it's root issue.
  14884. if (el.isGroup) {
  14885. stopped = cb(el);
  14886. }
  14887. if (!stopped) {
  14888. el.traverse(cb);
  14889. }
  14890. }
  14891. function traverseElements(els, cb) {
  14892. if (els) {
  14893. if (isArray(els)) {
  14894. for (var i = 0; i < els.length; i++) {
  14895. traverseElement(els[i], cb);
  14896. }
  14897. } else {
  14898. traverseElement(els, cb);
  14899. }
  14900. }
  14901. }
  14902. /**
  14903. * After a boundingRect applying a `transform`, whether to be still parallel screen X and Y.
  14904. */
  14905. function isBoundingRectAxisAligned(transform) {
  14906. return !transform || mathAbs$1(transform[1]) < AXIS_ALIGN_EPSILON && mathAbs$1(transform[2]) < AXIS_ALIGN_EPSILON || mathAbs$1(transform[0]) < AXIS_ALIGN_EPSILON && mathAbs$1(transform[3]) < AXIS_ALIGN_EPSILON;
  14907. }
  14908. var AXIS_ALIGN_EPSILON = 1e-5;
  14909. /**
  14910. * Create or copy to the existing bounding rect to avoid modifying `source`.
  14911. *
  14912. * @usage
  14913. * out.rect = ensureCopyRect(out.rect, sourceRect);
  14914. */
  14915. function ensureCopyRect(target, source) {
  14916. return target ? BoundingRect.copy(target, source) : source.clone();
  14917. }
  14918. /**
  14919. * Create or copy to the existing transform to avoid modifying `source`.
  14920. *
  14921. * [CAUTION]: transform is `NullUndefined` if no transform, following convention of zrender,
  14922. * and enable to bypass some unnecessary calculation, since in most cases there is no transform.
  14923. *
  14924. * @usage
  14925. * out.transform = ensureCopyTransform(out.transform, sourceTransform);
  14926. */
  14927. function ensureCopyTransform(target, source) {
  14928. return source ? copy$1(target || create$1(), source) : undefined;
  14929. }
  14930. function retrieveZInfo(model) {
  14931. return {
  14932. z: model.get('z') || 0,
  14933. zlevel: model.get('zlevel') || 0
  14934. };
  14935. }
  14936. function traverseUpdateZ(el, z, zlevel) {
  14937. doUpdateZ(el, z, zlevel, -Infinity);
  14938. }
  14939. function doUpdateZ(el, z, zlevel,
  14940. // FIXME: Ideally all the labels should be above all the glyphs by default,
  14941. // e.g. in graph, edge labels should be above node elements.
  14942. // Currently impl does not guarantee that.
  14943. maxZ2) {
  14944. // `ignoreModelZ` is used to intentionally lift elements to cover other elements,
  14945. // where maxZ2 (for label.z2) should also not be counted for its parents.
  14946. if (el.ignoreModelZ) {
  14947. return maxZ2;
  14948. }
  14949. // Group may also have textContent
  14950. var label = el.getTextContent();
  14951. var labelLine = el.getTextGuideLine();
  14952. var isGroup = el.isGroup;
  14953. if (isGroup) {
  14954. // set z & zlevel of children elements of Group
  14955. var children = el.childrenRef();
  14956. for (var i = 0; i < children.length; i++) {
  14957. maxZ2 = mathMax$1(doUpdateZ(children[i], z, zlevel, maxZ2), maxZ2);
  14958. }
  14959. } else {
  14960. // not Group
  14961. el.z = z;
  14962. el.zlevel = zlevel;
  14963. maxZ2 = mathMax$1(el.z2 || 0, maxZ2);
  14964. }
  14965. // always set z and zlevel if label/labelLine exists
  14966. if (label) {
  14967. label.z = z;
  14968. label.zlevel = zlevel;
  14969. // lift z2 of text content
  14970. // TODO if el.emphasis.z2 is spcefied, what about textContent.
  14971. isFinite(maxZ2) && (label.z2 = maxZ2 + 2);
  14972. }
  14973. if (labelLine) {
  14974. var textGuideLineConfig = el.textGuideLineConfig;
  14975. labelLine.z = z;
  14976. labelLine.zlevel = zlevel;
  14977. isFinite(maxZ2) && (labelLine.z2 = maxZ2 + (textGuideLineConfig && textGuideLineConfig.showAbove ? 1 : -1));
  14978. }
  14979. return maxZ2;
  14980. }
  14981. // Register built-in shapes. These shapes might be overwritten
  14982. // by users, although we do not recommend that.
  14983. registerShape('circle', Circle);
  14984. registerShape('ellipse', Ellipse);
  14985. registerShape('sector', Sector);
  14986. registerShape('ring', Ring);
  14987. registerShape('polygon', Polygon);
  14988. registerShape('polyline', Polyline);
  14989. registerShape('rect', Rect);
  14990. registerShape('line', Line);
  14991. registerShape('bezierCurve', BezierCurve);
  14992. registerShape('arc', Arc);
  14993. var EMPTY_OBJ = {};
  14994. function setLabelText(label, labelTexts) {
  14995. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  14996. var stateName = SPECIAL_STATES[i];
  14997. var text = labelTexts[stateName];
  14998. var state = label.ensureState(stateName);
  14999. state.style = state.style || {};
  15000. state.style.text = text;
  15001. }
  15002. var oldStates = label.currentStates.slice();
  15003. label.clearStates(true);
  15004. label.setStyle({
  15005. text: labelTexts.normal
  15006. });
  15007. label.useStates(oldStates, true);
  15008. }
  15009. function getLabelText(opt, stateModels, interpolatedValue) {
  15010. var labelFetcher = opt.labelFetcher;
  15011. var labelDataIndex = opt.labelDataIndex;
  15012. var labelDimIndex = opt.labelDimIndex;
  15013. var normalModel = stateModels.normal;
  15014. var baseText;
  15015. if (labelFetcher) {
  15016. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, normalModel && normalModel.get('formatter'), interpolatedValue != null ? {
  15017. interpolatedValue: interpolatedValue
  15018. } : null);
  15019. }
  15020. if (baseText == null) {
  15021. baseText = isFunction(opt.defaultText) ? opt.defaultText(labelDataIndex, opt, interpolatedValue) : opt.defaultText;
  15022. }
  15023. var statesText = {
  15024. normal: baseText
  15025. };
  15026. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15027. var stateName = SPECIAL_STATES[i];
  15028. var stateModel = stateModels[stateName];
  15029. statesText[stateName] = retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, stateName, null, labelDimIndex, stateModel && stateModel.get('formatter')) : null, baseText);
  15030. }
  15031. return statesText;
  15032. }
  15033. function setLabelStyle(targetEl, labelStatesModels, opt, stateSpecified
  15034. // TODO specified position?
  15035. ) {
  15036. opt = opt || EMPTY_OBJ;
  15037. var isSetOnText = targetEl instanceof ZRText;
  15038. var needsCreateText = false;
  15039. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  15040. var stateModel = labelStatesModels[DISPLAY_STATES[i]];
  15041. if (stateModel && stateModel.getShallow('show')) {
  15042. needsCreateText = true;
  15043. break;
  15044. }
  15045. }
  15046. var textContent = isSetOnText ? targetEl : targetEl.getTextContent();
  15047. if (needsCreateText) {
  15048. if (!isSetOnText) {
  15049. // Reuse the previous
  15050. if (!textContent) {
  15051. textContent = new ZRText();
  15052. targetEl.setTextContent(textContent);
  15053. }
  15054. // Use same state proxy
  15055. if (targetEl.stateProxy) {
  15056. textContent.stateProxy = targetEl.stateProxy;
  15057. }
  15058. }
  15059. var labelStatesTexts = getLabelText(opt, labelStatesModels);
  15060. var normalModel = labelStatesModels.normal;
  15061. var showNormal = !!normalModel.getShallow('show');
  15062. var normalStyle = createTextStyle(normalModel, stateSpecified && stateSpecified.normal, opt, false, !isSetOnText);
  15063. normalStyle.text = labelStatesTexts.normal;
  15064. if (!isSetOnText) {
  15065. // Always create new
  15066. targetEl.setTextConfig(createTextConfig(normalModel, opt, false));
  15067. }
  15068. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15069. var stateName = SPECIAL_STATES[i];
  15070. var stateModel = labelStatesModels[stateName];
  15071. if (stateModel) {
  15072. var stateObj = textContent.ensureState(stateName);
  15073. var stateShow = !!retrieve2(stateModel.getShallow('show'), showNormal);
  15074. if (stateShow !== showNormal) {
  15075. stateObj.ignore = !stateShow;
  15076. }
  15077. stateObj.style = createTextStyle(stateModel, stateSpecified && stateSpecified[stateName], opt, true, !isSetOnText);
  15078. stateObj.style.text = labelStatesTexts[stateName];
  15079. if (!isSetOnText) {
  15080. var targetElEmphasisState = targetEl.ensureState(stateName);
  15081. targetElEmphasisState.textConfig = createTextConfig(stateModel, opt, true);
  15082. }
  15083. }
  15084. }
  15085. // PENDING: if there is many requirements that emphasis position
  15086. // need to be different from normal position, we might consider
  15087. // auto silent is those cases.
  15088. textContent.silent = !!normalModel.getShallow('silent');
  15089. // Keep x and y
  15090. if (textContent.style.x != null) {
  15091. normalStyle.x = textContent.style.x;
  15092. }
  15093. if (textContent.style.y != null) {
  15094. normalStyle.y = textContent.style.y;
  15095. }
  15096. textContent.ignore = !showNormal;
  15097. // Always create new style.
  15098. textContent.useStyle(normalStyle);
  15099. textContent.dirty();
  15100. if (opt.enableTextSetter) {
  15101. labelInner(textContent).setLabelText = function (interpolatedValue) {
  15102. var labelStatesTexts = getLabelText(opt, labelStatesModels, interpolatedValue);
  15103. setLabelText(textContent, labelStatesTexts);
  15104. };
  15105. }
  15106. } else if (textContent) {
  15107. // Not display rich text.
  15108. textContent.ignore = true;
  15109. }
  15110. targetEl.dirty();
  15111. }
  15112. function getLabelStatesModels(itemModel, labelName) {
  15113. labelName = labelName || 'label';
  15114. var statesModels = {
  15115. normal: itemModel.getModel(labelName)
  15116. };
  15117. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15118. var stateName = SPECIAL_STATES[i];
  15119. statesModels[stateName] = itemModel.getModel([stateName, labelName]);
  15120. }
  15121. return statesModels;
  15122. }
  15123. /**
  15124. * Set basic textStyle properties.
  15125. */
  15126. function createTextStyle(textStyleModel, specifiedTextStyle,
  15127. // Fixed style in the code. Can't be set by model.
  15128. opt, isNotNormal, isAttached // If text is attached on an element. If so, auto color will handling in zrender.
  15129. ) {
  15130. var textStyle = {};
  15131. setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached);
  15132. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  15133. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15134. return textStyle;
  15135. }
  15136. function createTextConfig(textStyleModel, opt, isNotNormal) {
  15137. opt = opt || {};
  15138. var textConfig = {};
  15139. var labelPosition;
  15140. var labelRotate = textStyleModel.getShallow('rotate');
  15141. var labelDistance = retrieve2(textStyleModel.getShallow('distance'), isNotNormal ? null : 5);
  15142. var labelOffset = textStyleModel.getShallow('offset');
  15143. labelPosition = textStyleModel.getShallow('position') || (isNotNormal ? null : 'inside');
  15144. // 'outside' is not a valid zr textPostion value, but used
  15145. // in bar series, and magic type should be considered.
  15146. labelPosition === 'outside' && (labelPosition = opt.defaultOutsidePosition || 'top');
  15147. if (labelPosition != null) {
  15148. textConfig.position = labelPosition;
  15149. }
  15150. if (labelOffset != null) {
  15151. textConfig.offset = labelOffset;
  15152. }
  15153. if (labelRotate != null) {
  15154. labelRotate *= Math.PI / 180;
  15155. textConfig.rotation = labelRotate;
  15156. }
  15157. if (labelDistance != null) {
  15158. textConfig.distance = labelDistance;
  15159. }
  15160. // fill and auto is determined by the color of path fill if it's not specified by developers.
  15161. textConfig.outsideFill = textStyleModel.get('color') === 'inherit' ? opt.inheritColor || null : 'auto';
  15162. if (opt.autoOverflowArea != null) {
  15163. textConfig.autoOverflowArea = opt.autoOverflowArea;
  15164. }
  15165. if (opt.layoutRect != null) {
  15166. textConfig.layoutRect = opt.layoutRect;
  15167. }
  15168. return textConfig;
  15169. }
  15170. /**
  15171. * The uniform entry of set text style, that is, retrieve style definitions
  15172. * from `model` and set to `textStyle` object.
  15173. *
  15174. * Never in merge mode, but in overwrite mode, that is, all of the text style
  15175. * properties will be set. (Consider the states of normal and emphasis and
  15176. * default value can be adopted, merge would make the logic too complicated
  15177. * to manage.)
  15178. */
  15179. function setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached) {
  15180. // Consider there will be abnormal when merge hover style to normal style if given default value.
  15181. opt = opt || EMPTY_OBJ;
  15182. var ecModel = textStyleModel.ecModel;
  15183. var globalTextStyle = ecModel && ecModel.option.textStyle;
  15184. // Consider case:
  15185. // {
  15186. // data: [{
  15187. // value: 12,
  15188. // label: {
  15189. // rich: {
  15190. // // no 'a' here but using parent 'a'.
  15191. // }
  15192. // }
  15193. // }],
  15194. // rich: {
  15195. // a: { ... }
  15196. // }
  15197. // }
  15198. var richItemNames = getRichItemNames(textStyleModel);
  15199. var richResult;
  15200. if (richItemNames) {
  15201. richResult = {};
  15202. var richInheritPlainLabelOptionName = 'richInheritPlainLabel';
  15203. var richInheritPlainLabel = retrieve2(textStyleModel.get(richInheritPlainLabelOptionName), ecModel ? ecModel.get(richInheritPlainLabelOptionName) : undefined);
  15204. for (var name_1 in richItemNames) {
  15205. if (richItemNames.hasOwnProperty(name_1)) {
  15206. // Cascade is supported in rich.
  15207. var richTextStyle = textStyleModel.getModel(['rich', name_1]);
  15208. // In rich, never `disableBox`.
  15209. // consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  15210. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  15211. // That might confuses users. So probably we should put `textStyleModel` as the
  15212. // root ancestor of the `richTextStyle`. But that would be a break change.
  15213. // Since v6, the rich style inherits plain label by default
  15214. // but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
  15215. setTokenTextStyle(richResult[name_1] = {}, richTextStyle, globalTextStyle, textStyleModel, richInheritPlainLabel, opt, isNotNormal, isAttached, false, true);
  15216. }
  15217. }
  15218. }
  15219. if (richResult) {
  15220. textStyle.rich = richResult;
  15221. }
  15222. var overflow = textStyleModel.get('overflow');
  15223. if (overflow) {
  15224. textStyle.overflow = overflow;
  15225. }
  15226. var lineOverflow = textStyleModel.get('lineOverflow');
  15227. if (lineOverflow) {
  15228. textStyle.lineOverflow = lineOverflow;
  15229. }
  15230. var labelTextStyle = textStyle;
  15231. // `minMargin` has a higher precedence than `textMargin`, because `textMargin` is allowed
  15232. // to be set in `defaultOption`.
  15233. var minMargin = textStyleModel.get('minMargin');
  15234. if (minMargin != null) {
  15235. // `minMargin` only support number value.
  15236. minMargin = !isNumber(minMargin) ? 0 : minMargin / 2;
  15237. labelTextStyle.margin = [minMargin, minMargin, minMargin, minMargin];
  15238. labelTextStyle.__marginType = LabelMarginType.minMargin;
  15239. } else {
  15240. var textMargin = textStyleModel.get('textMargin');
  15241. if (textMargin != null) {
  15242. labelTextStyle.margin = normalizeCssArray(textMargin);
  15243. labelTextStyle.__marginType = LabelMarginType.textMargin;
  15244. }
  15245. }
  15246. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, null, null, opt, isNotNormal, isAttached, true, false);
  15247. }
  15248. // Consider case:
  15249. // {
  15250. // data: [{
  15251. // value: 12,
  15252. // label: {
  15253. // rich: {
  15254. // // no 'a' here but using parent 'a'.
  15255. // }
  15256. // }
  15257. // }],
  15258. // rich: {
  15259. // a: { ... }
  15260. // }
  15261. // }
  15262. // TODO TextStyleModel
  15263. function getRichItemNames(textStyleModel) {
  15264. // Use object to remove duplicated names.
  15265. var richItemNameMap;
  15266. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  15267. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  15268. if (rich) {
  15269. richItemNameMap = richItemNameMap || {};
  15270. var richKeys = keys(rich);
  15271. for (var i = 0; i < richKeys.length; i++) {
  15272. var richKey = richKeys[i];
  15273. richItemNameMap[richKey] = 1;
  15274. }
  15275. }
  15276. textStyleModel = textStyleModel.parentModel;
  15277. }
  15278. return richItemNameMap;
  15279. }
  15280. var TEXT_PROPS_WITH_GLOBAL = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'];
  15281. var TEXT_PROPS_SELF = ['align', 'lineHeight', 'width', 'height', 'tag', 'verticalAlign', 'ellipsis'];
  15282. var TEXT_PROPS_BOX = ['padding', 'borderWidth', 'borderRadius', 'borderDashOffset', 'backgroundColor', 'borderColor', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  15283. function setTokenTextStyle(textStyle,
  15284. // FIXME: check/refactor for ellipsis handling of rich text.
  15285. textStyleModel, globalTextStyle, plainTextModel, richInheritPlainLabel, opt, isNotNormal, isAttached, isBlock, inRich) {
  15286. // In merge mode, default value should not be given.
  15287. globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
  15288. var inheritColor = opt && opt.inheritColor;
  15289. var fillColor = textStyleModel.getShallow('color');
  15290. var strokeColor = textStyleModel.getShallow('textBorderColor');
  15291. var opacity = retrieve2(textStyleModel.getShallow('opacity'), globalTextStyle.opacity);
  15292. if (fillColor === 'inherit' || fillColor === 'auto') {
  15293. if ("development" !== 'production') {
  15294. if (fillColor === 'auto') {
  15295. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  15296. }
  15297. }
  15298. if (inheritColor) {
  15299. fillColor = inheritColor;
  15300. } else {
  15301. fillColor = null;
  15302. }
  15303. }
  15304. if (strokeColor === 'inherit' || strokeColor === 'auto') {
  15305. if ("development" !== 'production') {
  15306. if (strokeColor === 'auto') {
  15307. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  15308. }
  15309. }
  15310. if (inheritColor) {
  15311. strokeColor = inheritColor;
  15312. } else {
  15313. strokeColor = null;
  15314. }
  15315. }
  15316. if (!isAttached) {
  15317. // Only use default global textStyle.color if text is individual.
  15318. // Otherwise it will use the strategy of attached text color because text may be on a path.
  15319. fillColor = fillColor || globalTextStyle.color;
  15320. strokeColor = strokeColor || globalTextStyle.textBorderColor;
  15321. }
  15322. if (fillColor != null) {
  15323. // Might not be a string, e.g, it's a function in axisLabel case; but assume that it will
  15324. // be erased by a correct value outside.
  15325. textStyle.fill = fillColor;
  15326. }
  15327. if (strokeColor != null) {
  15328. textStyle.stroke = strokeColor;
  15329. }
  15330. var textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  15331. if (textBorderWidth != null) {
  15332. textStyle.lineWidth = textBorderWidth;
  15333. }
  15334. var textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
  15335. if (textBorderType != null) {
  15336. textStyle.lineDash = textBorderType;
  15337. }
  15338. var textBorderDashOffset = retrieve2(textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset);
  15339. if (textBorderDashOffset != null) {
  15340. textStyle.lineDashOffset = textBorderDashOffset;
  15341. }
  15342. if (!isNotNormal && opacity == null && !inRich) {
  15343. opacity = opt && opt.defaultOpacity;
  15344. }
  15345. if (opacity != null) {
  15346. textStyle.opacity = opacity;
  15347. }
  15348. // TODO
  15349. if (!isNotNormal && !isAttached) {
  15350. // Set default finally.
  15351. if (textStyle.fill == null && opt.inheritColor) {
  15352. textStyle.fill = opt.inheritColor;
  15353. }
  15354. }
  15355. // Do not use `getFont` here, because merge should be supported, where
  15356. // part of these properties may be changed in emphasis style, and the
  15357. // others should remain their original value got from normal style.
  15358. for (var i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
  15359. var key = TEXT_PROPS_WITH_GLOBAL[i];
  15360. // props width, height, padding, margin, tag, backgroundColor, borderColor,
  15361. // borderWidth, borderRadius, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY
  15362. // may inappropriate to inherit from plainTextStyle.
  15363. // And if some props is specified in default options, users may have to reset them one by one.
  15364. // Therefore, we only allow these props to inherit from plainTextStyle.
  15365. // `richInheritPlainLabel` is switch for backward compatibility
  15366. var val = richInheritPlainLabel !== false && plainTextModel ? retrieve3(textStyleModel.getShallow(key), plainTextModel.getShallow(key), globalTextStyle[key]) : retrieve2(textStyleModel.getShallow(key), globalTextStyle[key]);
  15367. if (val != null) {
  15368. textStyle[key] = val;
  15369. }
  15370. }
  15371. for (var i = 0; i < TEXT_PROPS_SELF.length; i++) {
  15372. var key = TEXT_PROPS_SELF[i];
  15373. var val = textStyleModel.getShallow(key);
  15374. if (val != null) {
  15375. textStyle[key] = val;
  15376. }
  15377. }
  15378. if (textStyle.verticalAlign == null) {
  15379. var baseline = textStyleModel.getShallow('baseline');
  15380. if (baseline != null) {
  15381. textStyle.verticalAlign = baseline;
  15382. }
  15383. }
  15384. if (!isBlock || !opt.disableBox) {
  15385. for (var i = 0; i < TEXT_PROPS_BOX.length; i++) {
  15386. var key = TEXT_PROPS_BOX[i];
  15387. var val = textStyleModel.getShallow(key);
  15388. if (val != null) {
  15389. textStyle[key] = val;
  15390. }
  15391. }
  15392. var borderType = textStyleModel.getShallow('borderType');
  15393. if (borderType != null) {
  15394. textStyle.borderDash = borderType;
  15395. }
  15396. if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
  15397. if ("development" !== 'production') {
  15398. if (textStyle.backgroundColor === 'auto') {
  15399. deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\'');
  15400. }
  15401. }
  15402. textStyle.backgroundColor = inheritColor;
  15403. }
  15404. if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) {
  15405. if ("development" !== 'production') {
  15406. if (textStyle.borderColor === 'auto') {
  15407. deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\'');
  15408. }
  15409. }
  15410. textStyle.borderColor = inheritColor;
  15411. }
  15412. }
  15413. }
  15414. function getFont(opt, ecModel) {
  15415. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  15416. return trim([
  15417. // FIXME in node-canvas fontWeight is before fontStyle
  15418. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '', opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '', (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px', opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'].join(' '));
  15419. }
  15420. var labelInner = makeInner();
  15421. function setLabelValueAnimation(label, labelStatesModels, value, getDefaultText) {
  15422. if (!label) {
  15423. return;
  15424. }
  15425. var obj = labelInner(label);
  15426. obj.prevValue = obj.value;
  15427. obj.value = value;
  15428. var normalLabelModel = labelStatesModels.normal;
  15429. obj.valueAnimation = normalLabelModel.get('valueAnimation');
  15430. if (obj.valueAnimation) {
  15431. obj.precision = normalLabelModel.get('precision');
  15432. obj.defaultInterpolatedText = getDefaultText;
  15433. obj.statesModels = labelStatesModels;
  15434. }
  15435. }
  15436. /**
  15437. * PENDING: Temporary impl. unify them?
  15438. * @see {LabelCommonOption['textMargin']}
  15439. * @see {LabelCommonOption['minMargin']}
  15440. */
  15441. var LabelMarginType = {
  15442. minMargin: 1,
  15443. textMargin: 2
  15444. };
  15445. var PATH_COLOR = ['textStyle', 'color'];
  15446. var textStyleParams = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'padding', 'lineHeight', 'rich', 'width', 'height', 'overflow'];
  15447. // TODO Performance improvement?
  15448. var tmpText = new ZRText();
  15449. var TextStyleMixin = /** @class */function () {
  15450. function TextStyleMixin() {}
  15451. /**
  15452. * Get color property or get color from option.textStyle.color
  15453. */
  15454. // TODO Callback
  15455. TextStyleMixin.prototype.getTextColor = function (isEmphasis) {
  15456. var ecModel = this.ecModel;
  15457. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  15458. };
  15459. /**
  15460. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15461. * @return {string}
  15462. */
  15463. TextStyleMixin.prototype.getFont = function () {
  15464. return getFont({
  15465. fontStyle: this.getShallow('fontStyle'),
  15466. fontWeight: this.getShallow('fontWeight'),
  15467. fontSize: this.getShallow('fontSize'),
  15468. fontFamily: this.getShallow('fontFamily')
  15469. }, this.ecModel);
  15470. };
  15471. TextStyleMixin.prototype.getTextRect = function (text) {
  15472. var style = {
  15473. text: text,
  15474. verticalAlign: this.getShallow('verticalAlign') || this.getShallow('baseline')
  15475. };
  15476. for (var i = 0; i < textStyleParams.length; i++) {
  15477. style[textStyleParams[i]] = this.getShallow(textStyleParams[i]);
  15478. }
  15479. tmpText.useStyle(style);
  15480. tmpText.update();
  15481. return tmpText.getBoundingRect();
  15482. };
  15483. return TextStyleMixin;
  15484. }();
  15485. var LINE_STYLE_KEY_MAP = [['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['lineDash', 'type'], ['lineDashOffset', 'dashOffset'], ['lineCap', 'cap'], ['lineJoin', 'join'], ['miterLimit']
  15486. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  15487. // So do not transfer decal directly.
  15488. ];
  15489. var getLineStyle = makeStyleMapper(LINE_STYLE_KEY_MAP);
  15490. var LineStyleMixin = /** @class */function () {
  15491. function LineStyleMixin() {}
  15492. LineStyleMixin.prototype.getLineStyle = function (excludes) {
  15493. return getLineStyle(this, excludes);
  15494. };
  15495. return LineStyleMixin;
  15496. }();
  15497. var ITEM_STYLE_KEY_MAP = [['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['lineDash', 'borderType'], ['lineDashOffset', 'borderDashOffset'], ['lineCap', 'borderCap'], ['lineJoin', 'borderJoin'], ['miterLimit', 'borderMiterLimit']
  15498. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  15499. // So do not transfer decal directly.
  15500. ];
  15501. var getItemStyle = makeStyleMapper(ITEM_STYLE_KEY_MAP);
  15502. var ItemStyleMixin = /** @class */function () {
  15503. function ItemStyleMixin() {}
  15504. ItemStyleMixin.prototype.getItemStyle = function (excludes, includes) {
  15505. return getItemStyle(this, excludes, includes);
  15506. };
  15507. return ItemStyleMixin;
  15508. }();
  15509. var Model = /** @class */function () {
  15510. function Model(option, parentModel, ecModel) {
  15511. this.parentModel = parentModel;
  15512. this.ecModel = ecModel;
  15513. this.option = option;
  15514. // Simple optimization
  15515. // if (this.init) {
  15516. // if (arguments.length <= 4) {
  15517. // this.init(option, parentModel, ecModel, extraOpt);
  15518. // }
  15519. // else {
  15520. // this.init.apply(this, arguments);
  15521. // }
  15522. // }
  15523. }
  15524. Model.prototype.init = function (option, parentModel, ecModel) {
  15525. var rest = [];
  15526. for (var _i = 3; _i < arguments.length; _i++) {
  15527. rest[_i - 3] = arguments[_i];
  15528. }
  15529. };
  15530. /**
  15531. * Merge the input option to me.
  15532. */
  15533. Model.prototype.mergeOption = function (option, ecModel) {
  15534. merge(this.option, option, true);
  15535. };
  15536. // `path` can be 'a.b.c', so the return value type have to be `ModelOption`
  15537. // TODO: TYPE strict key check?
  15538. // get(path: string | string[], ignoreParent?: boolean): ModelOption;
  15539. Model.prototype.get = function (path, ignoreParent) {
  15540. if (path == null) {
  15541. return this.option;
  15542. }
  15543. return this._doGet(this.parsePath(path), !ignoreParent && this.parentModel);
  15544. };
  15545. Model.prototype.getShallow = function (key, ignoreParent) {
  15546. var option = this.option;
  15547. var val = option == null ? option : option[key];
  15548. if (val == null && !ignoreParent) {
  15549. var parentModel = this.parentModel;
  15550. if (parentModel) {
  15551. // FIXME:TS do not know how to make it works
  15552. val = parentModel.getShallow(key);
  15553. }
  15554. }
  15555. return val;
  15556. };
  15557. // `path` can be 'a.b.c', so the return value type have to be `Model<ModelOption>`
  15558. // getModel(path: string | string[], parentModel?: Model): Model;
  15559. // TODO 'a.b.c' is deprecated
  15560. Model.prototype.getModel = function (path, parentModel) {
  15561. var hasPath = path != null;
  15562. var pathFinal = hasPath ? this.parsePath(path) : null;
  15563. var obj = hasPath ? this._doGet(pathFinal) : this.option;
  15564. parentModel = parentModel || this.parentModel && this.parentModel.getModel(this.resolveParentPath(pathFinal));
  15565. return new Model(obj, parentModel, this.ecModel);
  15566. };
  15567. /**
  15568. * If model has option
  15569. */
  15570. Model.prototype.isEmpty = function () {
  15571. return this.option == null;
  15572. };
  15573. Model.prototype.restoreData = function () {};
  15574. // Pending
  15575. Model.prototype.clone = function () {
  15576. var Ctor = this.constructor;
  15577. return new Ctor(clone(this.option));
  15578. };
  15579. // setReadOnly(properties): void {
  15580. // clazzUtil.setReadOnly(this, properties);
  15581. // }
  15582. // If path is null/undefined, return null/undefined.
  15583. Model.prototype.parsePath = function (path) {
  15584. if (typeof path === 'string') {
  15585. return path.split('.');
  15586. }
  15587. return path;
  15588. };
  15589. // Resolve path for parent. Perhaps useful when parent use a different property.
  15590. // Default to be a identity resolver.
  15591. // Can be modified to a different resolver.
  15592. Model.prototype.resolveParentPath = function (path) {
  15593. return path;
  15594. };
  15595. // FIXME:TS check whether put this method here
  15596. Model.prototype.isAnimationEnabled = function () {
  15597. if (!env.node && this.option) {
  15598. if (this.option.animation != null) {
  15599. return !!this.option.animation;
  15600. } else if (this.parentModel) {
  15601. return this.parentModel.isAnimationEnabled();
  15602. }
  15603. }
  15604. };
  15605. Model.prototype._doGet = function (pathArr, parentModel) {
  15606. var obj = this.option;
  15607. if (!pathArr) {
  15608. return obj;
  15609. }
  15610. for (var i = 0; i < pathArr.length; i++) {
  15611. // Ignore empty
  15612. if (!pathArr[i]) {
  15613. continue;
  15614. }
  15615. // obj could be number/string/... (like 0)
  15616. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  15617. if (obj == null) {
  15618. break;
  15619. }
  15620. }
  15621. if (obj == null && parentModel) {
  15622. obj = parentModel._doGet(this.resolveParentPath(pathArr), parentModel.parentModel);
  15623. }
  15624. return obj;
  15625. };
  15626. return Model;
  15627. }();
  15628. // Enable Model.extend.
  15629. enableClassExtend(Model);
  15630. enableClassCheck(Model);
  15631. mixin(Model, LineStyleMixin);
  15632. mixin(Model, ItemStyleMixin);
  15633. mixin(Model, AreaStyleMixin);
  15634. mixin(Model, TextStyleMixin);
  15635. // A random offset
  15636. var base = Math.round(Math.random() * 10);
  15637. /**
  15638. * @public
  15639. * @param {string} type
  15640. * @return {string}
  15641. */
  15642. function getUID(type) {
  15643. // Considering the case of crossing js context,
  15644. // use Math.random to make id as unique as possible.
  15645. return [type || '', base++].join('_');
  15646. }
  15647. /**
  15648. * Implements `SubTypeDefaulterManager` for `target`.
  15649. */
  15650. function enableSubTypeDefaulter(target) {
  15651. var subTypeDefaulters = {};
  15652. target.registerSubTypeDefaulter = function (componentType, defaulter) {
  15653. var componentTypeInfo = parseClassType(componentType);
  15654. subTypeDefaulters[componentTypeInfo.main] = defaulter;
  15655. };
  15656. target.determineSubType = function (componentType, option) {
  15657. var type = option.type;
  15658. if (!type) {
  15659. var componentTypeMain = parseClassType(componentType).main;
  15660. if (target.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15661. type = subTypeDefaulters[componentTypeMain](option);
  15662. }
  15663. }
  15664. return type;
  15665. };
  15666. }
  15667. /**
  15668. * Implements `TopologicalTravelable<any>` for `entity`.
  15669. *
  15670. * Topological travel on Activity Network (Activity On Vertices).
  15671. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15672. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15673. * If there is circular dependencey, Error will be thrown.
  15674. */
  15675. function enableTopologicalTravel(entity, dependencyGetter) {
  15676. /**
  15677. * @param targetNameList Target Component type list.
  15678. * Can be ['aa', 'bb', 'aa.xx']
  15679. * @param fullNameList By which we can build dependency graph.
  15680. * @param callback Params: componentType, dependencies.
  15681. * @param context Scope of callback.
  15682. */
  15683. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15684. if (!targetNameList.length) {
  15685. return;
  15686. }
  15687. var result = makeDepndencyGraph(fullNameList);
  15688. var graph = result.graph;
  15689. var noEntryList = result.noEntryList;
  15690. var targetNameSet = {};
  15691. each(targetNameList, function (name) {
  15692. targetNameSet[name] = true;
  15693. });
  15694. while (noEntryList.length) {
  15695. var currComponentType = noEntryList.pop();
  15696. var currVertex = graph[currComponentType];
  15697. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15698. if (isInTargetNameSet) {
  15699. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15700. delete targetNameSet[currComponentType];
  15701. }
  15702. each(currVertex.successor, isInTargetNameSet ? removeEdgeAndAdd : removeEdge);
  15703. }
  15704. each(targetNameSet, function () {
  15705. var errMsg = '';
  15706. if ("development" !== 'production') {
  15707. errMsg = makePrintable('Circular dependency may exists: ', targetNameSet, targetNameList, fullNameList);
  15708. }
  15709. throw new Error(errMsg);
  15710. });
  15711. function removeEdge(succComponentType) {
  15712. graph[succComponentType].entryCount--;
  15713. if (graph[succComponentType].entryCount === 0) {
  15714. noEntryList.push(succComponentType);
  15715. }
  15716. }
  15717. // Consider this case: legend depends on series, and we call
  15718. // chart.setOption({series: [...]}), where only series is in option.
  15719. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15720. // not be called, but only sereis.mergeOption is called. Thus legend
  15721. // have no chance to update its local record about series (like which
  15722. // name of series is available in legend).
  15723. function removeEdgeAndAdd(succComponentType) {
  15724. targetNameSet[succComponentType] = true;
  15725. removeEdge(succComponentType);
  15726. }
  15727. };
  15728. function makeDepndencyGraph(fullNameList) {
  15729. var graph = {};
  15730. var noEntryList = [];
  15731. each(fullNameList, function (name) {
  15732. var thisItem = createDependencyGraphItem(graph, name);
  15733. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15734. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15735. thisItem.entryCount = availableDeps.length;
  15736. if (thisItem.entryCount === 0) {
  15737. noEntryList.push(name);
  15738. }
  15739. each(availableDeps, function (dependentName) {
  15740. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15741. thisItem.predecessor.push(dependentName);
  15742. }
  15743. var thatItem = createDependencyGraphItem(graph, dependentName);
  15744. if (indexOf(thatItem.successor, dependentName) < 0) {
  15745. thatItem.successor.push(name);
  15746. }
  15747. });
  15748. });
  15749. return {
  15750. graph: graph,
  15751. noEntryList: noEntryList
  15752. };
  15753. }
  15754. function createDependencyGraphItem(graph, name) {
  15755. if (!graph[name]) {
  15756. graph[name] = {
  15757. predecessor: [],
  15758. successor: []
  15759. };
  15760. }
  15761. return graph[name];
  15762. }
  15763. function getAvailableDependencies(originalDeps, fullNameList) {
  15764. var availableDeps = [];
  15765. each(originalDeps, function (dep) {
  15766. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15767. });
  15768. return availableDeps;
  15769. }
  15770. }
  15771. function inheritDefaultOption(superOption, subOption) {
  15772. // See also `model/Component.ts#getDefaultOption`
  15773. return merge(merge({}, superOption, true), subOption, true);
  15774. }
  15775. /*
  15776. * Licensed to the Apache Software Foundation (ASF) under one
  15777. * or more contributor license agreements. See the NOTICE file
  15778. * distributed with this work for additional information
  15779. * regarding copyright ownership. The ASF licenses this file
  15780. * to you under the Apache License, Version 2.0 (the
  15781. * "License"); you may not use this file except in compliance
  15782. * with the License. You may obtain a copy of the License at
  15783. *
  15784. * http://www.apache.org/licenses/LICENSE-2.0
  15785. *
  15786. * Unless required by applicable law or agreed to in writing,
  15787. * software distributed under the License is distributed on an
  15788. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15789. * KIND, either express or implied. See the License for the
  15790. * specific language governing permissions and limitations
  15791. * under the License.
  15792. */
  15793. /**
  15794. * AUTO-GENERATED FILE. DO NOT MODIFY.
  15795. */
  15796. /*
  15797. * Licensed to the Apache Software Foundation (ASF) under one
  15798. * or more contributor license agreements. See the NOTICE file
  15799. * distributed with this work for additional information
  15800. * regarding copyright ownership. The ASF licenses this file
  15801. * to you under the Apache License, Version 2.0 (the
  15802. * "License"); you may not use this file except in compliance
  15803. * with the License. You may obtain a copy of the License at
  15804. *
  15805. * http://www.apache.org/licenses/LICENSE-2.0
  15806. *
  15807. * Unless required by applicable law or agreed to in writing,
  15808. * software distributed under the License is distributed on an
  15809. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15810. * KIND, either express or implied. See the License for the
  15811. * specific language governing permissions and limitations
  15812. * under the License.
  15813. */
  15814. /**
  15815. * Language: English.
  15816. */
  15817. var langEN = {
  15818. time: {
  15819. month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  15820. monthAbbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  15821. dayOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  15822. dayOfWeekAbbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  15823. },
  15824. legend: {
  15825. selector: {
  15826. all: 'All',
  15827. inverse: 'Inv'
  15828. }
  15829. },
  15830. toolbox: {
  15831. brush: {
  15832. title: {
  15833. rect: 'Box Select',
  15834. polygon: 'Lasso Select',
  15835. lineX: 'Horizontally Select',
  15836. lineY: 'Vertically Select',
  15837. keep: 'Keep Selections',
  15838. clear: 'Clear Selections'
  15839. }
  15840. },
  15841. dataView: {
  15842. title: 'Data View',
  15843. lang: ['Data View', 'Close', 'Refresh']
  15844. },
  15845. dataZoom: {
  15846. title: {
  15847. zoom: 'Zoom',
  15848. back: 'Zoom Reset'
  15849. }
  15850. },
  15851. magicType: {
  15852. title: {
  15853. line: 'Switch to Line Chart',
  15854. bar: 'Switch to Bar Chart',
  15855. stack: 'Stack',
  15856. tiled: 'Tile'
  15857. }
  15858. },
  15859. restore: {
  15860. title: 'Restore'
  15861. },
  15862. saveAsImage: {
  15863. title: 'Save as Image',
  15864. lang: ['Right Click to Save Image']
  15865. }
  15866. },
  15867. series: {
  15868. typeNames: {
  15869. pie: 'Pie chart',
  15870. bar: 'Bar chart',
  15871. line: 'Line chart',
  15872. scatter: 'Scatter plot',
  15873. effectScatter: 'Ripple scatter plot',
  15874. radar: 'Radar chart',
  15875. tree: 'Tree',
  15876. treemap: 'Treemap',
  15877. boxplot: 'Boxplot',
  15878. candlestick: 'Candlestick',
  15879. k: 'K line chart',
  15880. heatmap: 'Heat map',
  15881. map: 'Map',
  15882. parallel: 'Parallel coordinate map',
  15883. lines: 'Line graph',
  15884. graph: 'Relationship graph',
  15885. sankey: 'Sankey diagram',
  15886. funnel: 'Funnel chart',
  15887. gauge: 'Gauge',
  15888. pictorialBar: 'Pictorial bar',
  15889. themeRiver: 'Theme River Map',
  15890. sunburst: 'Sunburst',
  15891. custom: 'Custom chart',
  15892. chart: 'Chart'
  15893. }
  15894. },
  15895. aria: {
  15896. general: {
  15897. withTitle: 'This is a chart about "{title}"',
  15898. withoutTitle: 'This is a chart'
  15899. },
  15900. series: {
  15901. single: {
  15902. prefix: '',
  15903. withName: ' with type {seriesType} named {seriesName}.',
  15904. withoutName: ' with type {seriesType}.'
  15905. },
  15906. multiple: {
  15907. prefix: '. It consists of {seriesCount} series count.',
  15908. withName: ' The {seriesId} series is a {seriesType} representing {seriesName}.',
  15909. withoutName: ' The {seriesId} series is a {seriesType}.',
  15910. separator: {
  15911. middle: '',
  15912. end: ''
  15913. }
  15914. }
  15915. },
  15916. data: {
  15917. allData: 'The data is as follows: ',
  15918. partialData: 'The first {displayCnt} items are: ',
  15919. withName: 'the data for {name} is {value}',
  15920. withoutName: '{value}',
  15921. separator: {
  15922. middle: ', ',
  15923. end: '. '
  15924. }
  15925. }
  15926. }
  15927. };
  15928. /*
  15929. * Licensed to the Apache Software Foundation (ASF) under one
  15930. * or more contributor license agreements. See the NOTICE file
  15931. * distributed with this work for additional information
  15932. * regarding copyright ownership. The ASF licenses this file
  15933. * to you under the Apache License, Version 2.0 (the
  15934. * "License"); you may not use this file except in compliance
  15935. * with the License. You may obtain a copy of the License at
  15936. *
  15937. * http://www.apache.org/licenses/LICENSE-2.0
  15938. *
  15939. * Unless required by applicable law or agreed to in writing,
  15940. * software distributed under the License is distributed on an
  15941. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15942. * KIND, either express or implied. See the License for the
  15943. * specific language governing permissions and limitations
  15944. * under the License.
  15945. */
  15946. /**
  15947. * AUTO-GENERATED FILE. DO NOT MODIFY.
  15948. */
  15949. /*
  15950. * Licensed to the Apache Software Foundation (ASF) under one
  15951. * or more contributor license agreements. See the NOTICE file
  15952. * distributed with this work for additional information
  15953. * regarding copyright ownership. The ASF licenses this file
  15954. * to you under the Apache License, Version 2.0 (the
  15955. * "License"); you may not use this file except in compliance
  15956. * with the License. You may obtain a copy of the License at
  15957. *
  15958. * http://www.apache.org/licenses/LICENSE-2.0
  15959. *
  15960. * Unless required by applicable law or agreed to in writing,
  15961. * software distributed under the License is distributed on an
  15962. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15963. * KIND, either express or implied. See the License for the
  15964. * specific language governing permissions and limitations
  15965. * under the License.
  15966. */
  15967. var langZH = {
  15968. time: {
  15969. month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  15970. monthAbbr: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  15971. dayOfWeek: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  15972. dayOfWeekAbbr: ['日', '一', '二', '三', '四', '五', '六']
  15973. },
  15974. legend: {
  15975. selector: {
  15976. all: '全选',
  15977. inverse: '反选'
  15978. }
  15979. },
  15980. toolbox: {
  15981. brush: {
  15982. title: {
  15983. rect: '矩形选择',
  15984. polygon: '圈选',
  15985. lineX: '横向选择',
  15986. lineY: '纵向选择',
  15987. keep: '保持选择',
  15988. clear: '清除选择'
  15989. }
  15990. },
  15991. dataView: {
  15992. title: '数据视图',
  15993. lang: ['数据视图', '关闭', '刷新']
  15994. },
  15995. dataZoom: {
  15996. title: {
  15997. zoom: '区域缩放',
  15998. back: '区域缩放还原'
  15999. }
  16000. },
  16001. magicType: {
  16002. title: {
  16003. line: '切换为折线图',
  16004. bar: '切换为柱状图',
  16005. stack: '切换为堆叠',
  16006. tiled: '切换为平铺'
  16007. }
  16008. },
  16009. restore: {
  16010. title: '还原'
  16011. },
  16012. saveAsImage: {
  16013. title: '保存为图片',
  16014. lang: ['右键另存为图片']
  16015. }
  16016. },
  16017. series: {
  16018. typeNames: {
  16019. pie: '饼图',
  16020. bar: '柱状图',
  16021. line: '折线图',
  16022. scatter: '散点图',
  16023. effectScatter: '涟漪散点图',
  16024. radar: '雷达图',
  16025. tree: '树图',
  16026. treemap: '矩形树图',
  16027. boxplot: '箱型图',
  16028. candlestick: 'K线图',
  16029. k: 'K线图',
  16030. heatmap: '热力图',
  16031. map: '地图',
  16032. parallel: '平行坐标图',
  16033. lines: '线图',
  16034. graph: '关系图',
  16035. sankey: '桑基图',
  16036. funnel: '漏斗图',
  16037. gauge: '仪表盘图',
  16038. pictorialBar: '象形柱图',
  16039. themeRiver: '主题河流图',
  16040. sunburst: '旭日图',
  16041. custom: '自定义图表',
  16042. chart: '图表'
  16043. }
  16044. },
  16045. aria: {
  16046. general: {
  16047. withTitle: '这是一个关于“{title}”的图表。',
  16048. withoutTitle: '这是一个图表,'
  16049. },
  16050. series: {
  16051. single: {
  16052. prefix: '',
  16053. withName: '图表类型是{seriesType},表示{seriesName}。',
  16054. withoutName: '图表类型是{seriesType}。'
  16055. },
  16056. multiple: {
  16057. prefix: '它由{seriesCount}个图表系列组成。',
  16058. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  16059. withoutName: '第{seriesId}个系列是一个{seriesType},',
  16060. separator: {
  16061. middle: ';',
  16062. end: '。'
  16063. }
  16064. }
  16065. },
  16066. data: {
  16067. allData: '其数据是——',
  16068. partialData: '其中,前{displayCnt}项是——',
  16069. withName: '{name}的数据是{value}',
  16070. withoutName: '{value}',
  16071. separator: {
  16072. middle: ',',
  16073. end: ''
  16074. }
  16075. }
  16076. }
  16077. };
  16078. var LOCALE_ZH = 'ZH';
  16079. var LOCALE_EN = 'EN';
  16080. var DEFAULT_LOCALE = LOCALE_EN;
  16081. var localeStorage = {};
  16082. var localeModels = {};
  16083. var SYSTEM_LANG = !env.domSupported ? DEFAULT_LOCALE : function () {
  16084. var langStr = (/* eslint-disable-next-line */
  16085. document.documentElement.lang || navigator.language || navigator.browserLanguage || DEFAULT_LOCALE).toUpperCase();
  16086. return langStr.indexOf(LOCALE_ZH) > -1 ? LOCALE_ZH : DEFAULT_LOCALE;
  16087. }();
  16088. function registerLocale(locale, localeObj) {
  16089. locale = locale.toUpperCase();
  16090. localeModels[locale] = new Model(localeObj);
  16091. localeStorage[locale] = localeObj;
  16092. }
  16093. // export function getLocale(locale: string) {
  16094. // return localeStorage[locale];
  16095. // }
  16096. function createLocaleObject(locale) {
  16097. if (isString(locale)) {
  16098. var localeObj = localeStorage[locale.toUpperCase()] || {};
  16099. if (locale === LOCALE_ZH || locale === LOCALE_EN) {
  16100. return clone(localeObj);
  16101. } else {
  16102. return merge(clone(localeObj), clone(localeStorage[DEFAULT_LOCALE]), false);
  16103. }
  16104. } else {
  16105. return merge(clone(locale), clone(localeStorage[DEFAULT_LOCALE]), false);
  16106. }
  16107. }
  16108. function getLocaleModel(lang) {
  16109. return localeModels[lang];
  16110. }
  16111. function getDefaultLocaleModel() {
  16112. return localeModels[DEFAULT_LOCALE];
  16113. }
  16114. // Default locale
  16115. registerLocale(LOCALE_EN, langEN);
  16116. registerLocale(LOCALE_ZH, langZH);
  16117. var _impl = null;
  16118. function getScaleBreakHelper() {
  16119. return _impl;
  16120. }
  16121. var ONE_SECOND = 1000;
  16122. var ONE_MINUTE = ONE_SECOND * 60;
  16123. var ONE_HOUR = ONE_MINUTE * 60;
  16124. var ONE_DAY = ONE_HOUR * 24;
  16125. var ONE_YEAR = ONE_DAY * 365;
  16126. var primaryTimeUnitFormatterMatchers = {
  16127. year: /({yyyy}|{yy})/,
  16128. month: /({MMMM}|{MMM}|{MM}|{M})/,
  16129. day: /({dd}|{d})/,
  16130. hour: /({HH}|{H}|{hh}|{h})/,
  16131. minute: /({mm}|{m})/,
  16132. second: /({ss}|{s})/,
  16133. millisecond: /({SSS}|{S})/
  16134. };
  16135. var defaultFormatterSeed = {
  16136. year: '{yyyy}',
  16137. month: '{MMM}',
  16138. day: '{d}',
  16139. hour: '{HH}:{mm}',
  16140. minute: '{HH}:{mm}',
  16141. second: '{HH}:{mm}:{ss}',
  16142. millisecond: '{HH}:{mm}:{ss} {SSS}'
  16143. };
  16144. var defaultFullFormatter = '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss} {SSS}';
  16145. var fullDayFormatter = '{yyyy}-{MM}-{dd}';
  16146. var fullLeveledFormatter = {
  16147. year: '{yyyy}',
  16148. month: '{yyyy}-{MM}',
  16149. day: fullDayFormatter,
  16150. hour: fullDayFormatter + ' ' + defaultFormatterSeed.hour,
  16151. minute: fullDayFormatter + ' ' + defaultFormatterSeed.minute,
  16152. second: fullDayFormatter + ' ' + defaultFormatterSeed.second,
  16153. millisecond: defaultFullFormatter
  16154. };
  16155. // Order must be ensured from big to small.
  16156. var primaryTimeUnits = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
  16157. var timeUnits = ['year', 'half-year', 'quarter', 'month', 'week', 'half-week', 'day', 'half-day', 'quarter-day', 'hour', 'minute', 'second', 'millisecond'];
  16158. function parseTimeAxisLabelFormatter(formatter) {
  16159. // Keep the logic the same with function `leveledFormat`.
  16160. return !isString(formatter) && !isFunction(formatter) ? parseTimeAxisLabelFormatterDictionary(formatter) : formatter;
  16161. }
  16162. /**
  16163. * The final generated dictionary is like:
  16164. * generated_dict = {
  16165. * year: {
  16166. * year: ['{yyyy}', ...<higher_levels_if_any>]
  16167. * },
  16168. * month: {
  16169. * year: ['{yyyy} {MMM}', ...<higher_levels_if_any>],
  16170. * month: ['{MMM}', ...<higher_levels_if_any>]
  16171. * },
  16172. * day: {
  16173. * year: ['{yyyy} {MMM} {d}', ...<higher_levels_if_any>],
  16174. * month: ['{MMM} {d}', ...<higher_levels_if_any>],
  16175. * day: ['{d}', ...<higher_levels_if_any>]
  16176. * },
  16177. * ...
  16178. * }
  16179. *
  16180. * In echarts option, users can specify the entire dictionary or typically just:
  16181. * {formatter: {
  16182. * year: '{yyyy}', // Or an array of leveled templates: `['{yyyy}', '{bold1|{yyyy}}', ...]`,
  16183. * // corresponding to `[level0, level1, level2, ...]`.
  16184. * month: '{MMM}',
  16185. * day: '{d}',
  16186. * hour: '{HH}:{mm}',
  16187. * second: '{HH}:{mm}',
  16188. * ...
  16189. * }}
  16190. * If any time unit is not specified in echarts option, the default template is used,
  16191. * such as `['{yyyy}', {primary|{yyyy}']`.
  16192. *
  16193. * The `tick.level` is only used to read string from each array, meaning the style type.
  16194. *
  16195. * Let `lowerUnit = getUnitFromValue(tick.value)`.
  16196. * The non-break axis ticks only use `generated_dict[lowerUnit][lowerUnit][level]`.
  16197. * The break axis ticks may use `generated_dict[lowerUnit][upperUnit][level]`, because:
  16198. * Consider the case: the non-break ticks are `16th, 23th, Feb, 7th, ...`, where `Feb` is in the break
  16199. * range and pruned by breaks, and the break ends might be in lower time unit than day. e.g., break start
  16200. * is `Jan 25th 18:00`(in unit `hour`) and break end is `Feb 6th 18:30` (in unit `minute`). Thus the break
  16201. * label prefers `Jan 25th 18:00` and `Feb 6th 18:30` rather than only `18:00` and `18:30`, otherwise it
  16202. * causes misleading.
  16203. * In this case, the tick of the break start and end will both be:
  16204. * `{level: 1, lowerTimeUnit: 'minute', upperTimeUnit: 'month'}`
  16205. * And get the final template by `generated_dict[lowerTimeUnit][upperTimeUnit][level]`.
  16206. * Note that the time unit can not be calculated directly by a single tick value, since the two breaks have
  16207. * to be at the same time unit to avoid awkward appearance. i.e., `Jan 25th 18:00` is in the time unit "hour"
  16208. * but we need it to be "minute", following `Feb 6th 18:30`.
  16209. */
  16210. function parseTimeAxisLabelFormatterDictionary(dictOption) {
  16211. dictOption = dictOption || {};
  16212. var dict = {};
  16213. // Currently if any template is specified by user, it may contain rich text tag,
  16214. // such as `'{my_bold|{YYYY}}'`, thus we do add highlight style to it.
  16215. // (Note that nested tag (`'{some|{some2|xxx}}'`) in rich text is not supported yet.)
  16216. var canAddHighlight = true;
  16217. each(primaryTimeUnits, function (lowestUnit) {
  16218. canAddHighlight && (canAddHighlight = dictOption[lowestUnit] == null);
  16219. });
  16220. each(primaryTimeUnits, function (lowestUnit, lowestUnitIdx) {
  16221. var upperDictOption = dictOption[lowestUnit];
  16222. dict[lowestUnit] = {};
  16223. var lowerTpl = null;
  16224. for (var upperUnitIdx = lowestUnitIdx; upperUnitIdx >= 0; upperUnitIdx--) {
  16225. var upperUnit = primaryTimeUnits[upperUnitIdx];
  16226. var upperDictItemOption = isObject(upperDictOption) && !isArray(upperDictOption) ? upperDictOption[upperUnit] : upperDictOption;
  16227. var tplArr = void 0;
  16228. if (isArray(upperDictItemOption)) {
  16229. tplArr = upperDictItemOption.slice();
  16230. lowerTpl = tplArr[0] || '';
  16231. } else if (isString(upperDictItemOption)) {
  16232. lowerTpl = upperDictItemOption;
  16233. tplArr = [lowerTpl];
  16234. } else {
  16235. if (lowerTpl == null) {
  16236. lowerTpl = defaultFormatterSeed[lowestUnit];
  16237. }
  16238. // Generate the dict by the rule as follows:
  16239. // If the user specify (or by default):
  16240. // {formatter: {
  16241. // year: '{yyyy}',
  16242. // month: '{MMM}',
  16243. // day: '{d}',
  16244. // ...
  16245. // }}
  16246. // Concat them to make the final dictionary:
  16247. // {formatter: {
  16248. // year: {year: ['{yyyy}']},
  16249. // month: {year: ['{yyyy} {MMM}'], month: ['{MMM}']},
  16250. // day: {year: ['{yyyy} {MMM} {d}'], month: ['{MMM} {d}'], day: ['{d}']}
  16251. // ...
  16252. // }}
  16253. // And then add `{primary|...}` to each array if from default template.
  16254. // This strategy is convinient for user configurating and works for most cases.
  16255. // If bad cases encountered, users can specify the entire dictionary themselves
  16256. // instead of going through this logic.
  16257. else if (!primaryTimeUnitFormatterMatchers[upperUnit].test(lowerTpl)) {
  16258. lowerTpl = dict[upperUnit][upperUnit][0] + " " + lowerTpl;
  16259. }
  16260. tplArr = [lowerTpl];
  16261. if (canAddHighlight) {
  16262. tplArr[1] = "{primary|" + lowerTpl + "}";
  16263. }
  16264. }
  16265. dict[lowestUnit][upperUnit] = tplArr;
  16266. }
  16267. });
  16268. return dict;
  16269. }
  16270. function pad(str, len) {
  16271. str += '';
  16272. return '0000'.substr(0, len - str.length) + str;
  16273. }
  16274. function getPrimaryTimeUnit(timeUnit) {
  16275. switch (timeUnit) {
  16276. case 'half-year':
  16277. case 'quarter':
  16278. return 'month';
  16279. case 'week':
  16280. case 'half-week':
  16281. return 'day';
  16282. case 'half-day':
  16283. case 'quarter-day':
  16284. return 'hour';
  16285. default:
  16286. // year, minutes, second, milliseconds
  16287. return timeUnit;
  16288. }
  16289. }
  16290. function isPrimaryTimeUnit(timeUnit) {
  16291. return timeUnit === getPrimaryTimeUnit(timeUnit);
  16292. }
  16293. function getDefaultFormatPrecisionOfInterval(timeUnit) {
  16294. switch (timeUnit) {
  16295. case 'year':
  16296. case 'month':
  16297. return 'day';
  16298. case 'millisecond':
  16299. return 'millisecond';
  16300. default:
  16301. // Also for day, hour, minute, second
  16302. return 'second';
  16303. }
  16304. }
  16305. function format(
  16306. // Note: The result based on `isUTC` are totally different, which can not be just simply
  16307. // substituted by the result without `isUTC`. So we make the param `isUTC` mandatory.
  16308. time, template, isUTC, lang) {
  16309. var date = parseDate(time);
  16310. var y = date[fullYearGetterName(isUTC)]();
  16311. var M = date[monthGetterName(isUTC)]() + 1;
  16312. var q = Math.floor((M - 1) / 3) + 1;
  16313. var d = date[dateGetterName(isUTC)]();
  16314. var e = date['get' + (isUTC ? 'UTC' : '') + 'Day']();
  16315. var H = date[hoursGetterName(isUTC)]();
  16316. var h = (H - 1) % 12 + 1;
  16317. var m = date[minutesGetterName(isUTC)]();
  16318. var s = date[secondsGetterName(isUTC)]();
  16319. var S = date[millisecondsGetterName(isUTC)]();
  16320. var a = H >= 12 ? 'pm' : 'am';
  16321. var A = a.toUpperCase();
  16322. var localeModel = lang instanceof Model ? lang : getLocaleModel(lang || SYSTEM_LANG) || getDefaultLocaleModel();
  16323. var timeModel = localeModel.getModel('time');
  16324. var month = timeModel.get('month');
  16325. var monthAbbr = timeModel.get('monthAbbr');
  16326. var dayOfWeek = timeModel.get('dayOfWeek');
  16327. var dayOfWeekAbbr = timeModel.get('dayOfWeekAbbr');
  16328. return (template || '').replace(/{a}/g, a + '').replace(/{A}/g, A + '').replace(/{yyyy}/g, y + '').replace(/{yy}/g, pad(y % 100 + '', 2)).replace(/{Q}/g, q + '').replace(/{MMMM}/g, month[M - 1]).replace(/{MMM}/g, monthAbbr[M - 1]).replace(/{MM}/g, pad(M, 2)).replace(/{M}/g, M + '').replace(/{dd}/g, pad(d, 2)).replace(/{d}/g, d + '').replace(/{eeee}/g, dayOfWeek[e]).replace(/{ee}/g, dayOfWeekAbbr[e]).replace(/{e}/g, e + '').replace(/{HH}/g, pad(H, 2)).replace(/{H}/g, H + '').replace(/{hh}/g, pad(h + '', 2)).replace(/{h}/g, h + '').replace(/{mm}/g, pad(m, 2)).replace(/{m}/g, m + '').replace(/{ss}/g, pad(s, 2)).replace(/{s}/g, s + '').replace(/{SSS}/g, pad(S, 3)).replace(/{S}/g, S + '');
  16329. }
  16330. function leveledFormat(tick, idx, formatter, lang, isUTC) {
  16331. var template = null;
  16332. if (isString(formatter)) {
  16333. // Single formatter for all units at all levels
  16334. template = formatter;
  16335. } else if (isFunction(formatter)) {
  16336. var extra = {
  16337. time: tick.time,
  16338. level: tick.time.level
  16339. };
  16340. var scaleBreakHelper = getScaleBreakHelper();
  16341. if (scaleBreakHelper) {
  16342. scaleBreakHelper.makeAxisLabelFormatterParamBreak(extra, tick["break"]);
  16343. }
  16344. template = formatter(tick.value, idx, extra);
  16345. } else {
  16346. var tickTime = tick.time;
  16347. if (tickTime) {
  16348. var leveledTplArr = formatter[tickTime.lowerTimeUnit][tickTime.upperTimeUnit];
  16349. template = leveledTplArr[Math.min(tickTime.level, leveledTplArr.length - 1)] || '';
  16350. } else {
  16351. // tick may be from customTicks or timeline therefore no tick.time.
  16352. var unit = getUnitFromValue(tick.value, isUTC);
  16353. template = formatter[unit][unit][0];
  16354. }
  16355. }
  16356. return format(new Date(tick.value), template, isUTC, lang);
  16357. }
  16358. function getUnitFromValue(value, isUTC) {
  16359. var date = parseDate(value);
  16360. var M = date[monthGetterName(isUTC)]() + 1;
  16361. var d = date[dateGetterName(isUTC)]();
  16362. var h = date[hoursGetterName(isUTC)]();
  16363. var m = date[minutesGetterName(isUTC)]();
  16364. var s = date[secondsGetterName(isUTC)]();
  16365. var S = date[millisecondsGetterName(isUTC)]();
  16366. var isSecond = S === 0;
  16367. var isMinute = isSecond && s === 0;
  16368. var isHour = isMinute && m === 0;
  16369. var isDay = isHour && h === 0;
  16370. var isMonth = isDay && d === 1;
  16371. var isYear = isMonth && M === 1;
  16372. if (isYear) {
  16373. return 'year';
  16374. } else if (isMonth) {
  16375. return 'month';
  16376. } else if (isDay) {
  16377. return 'day';
  16378. } else if (isHour) {
  16379. return 'hour';
  16380. } else if (isMinute) {
  16381. return 'minute';
  16382. } else if (isSecond) {
  16383. return 'second';
  16384. } else {
  16385. return 'millisecond';
  16386. }
  16387. }
  16388. // export function getUnitValue(
  16389. // value: number | Date,
  16390. // unit: TimeUnit,
  16391. // isUTC: boolean
  16392. // ) : number {
  16393. // const date = zrUtil.isNumber(value)
  16394. // ? numberUtil.parseDate(value)
  16395. // : value;
  16396. // unit = unit || getUnitFromValue(value, isUTC);
  16397. // switch (unit) {
  16398. // case 'year':
  16399. // return date[fullYearGetterName(isUTC)]();
  16400. // case 'half-year':
  16401. // return date[monthGetterName(isUTC)]() >= 6 ? 1 : 0;
  16402. // case 'quarter':
  16403. // return Math.floor((date[monthGetterName(isUTC)]() + 1) / 4);
  16404. // case 'month':
  16405. // return date[monthGetterName(isUTC)]();
  16406. // case 'day':
  16407. // return date[dateGetterName(isUTC)]();
  16408. // case 'half-day':
  16409. // return date[hoursGetterName(isUTC)]() / 24;
  16410. // case 'hour':
  16411. // return date[hoursGetterName(isUTC)]();
  16412. // case 'minute':
  16413. // return date[minutesGetterName(isUTC)]();
  16414. // case 'second':
  16415. // return date[secondsGetterName(isUTC)]();
  16416. // case 'millisecond':
  16417. // return date[millisecondsGetterName(isUTC)]();
  16418. // }
  16419. // }
  16420. /**
  16421. * e.g.,
  16422. * If timeUnit is 'year', return the Jan 1st 00:00:00 000 of that year.
  16423. * If timeUnit is 'day', return the 00:00:00 000 of that day.
  16424. *
  16425. * @return The input date.
  16426. */
  16427. function roundTime(date, timeUnit, isUTC) {
  16428. switch (timeUnit) {
  16429. case 'year':
  16430. date[monthSetterName(isUTC)](0);
  16431. case 'month':
  16432. date[dateSetterName(isUTC)](1);
  16433. case 'day':
  16434. date[hoursSetterName(isUTC)](0);
  16435. case 'hour':
  16436. date[minutesSetterName(isUTC)](0);
  16437. case 'minute':
  16438. date[secondsSetterName(isUTC)](0);
  16439. case 'second':
  16440. date[millisecondsSetterName(isUTC)](0);
  16441. }
  16442. return date;
  16443. }
  16444. function fullYearGetterName(isUTC) {
  16445. return isUTC ? 'getUTCFullYear' : 'getFullYear';
  16446. }
  16447. function monthGetterName(isUTC) {
  16448. return isUTC ? 'getUTCMonth' : 'getMonth';
  16449. }
  16450. function dateGetterName(isUTC) {
  16451. return isUTC ? 'getUTCDate' : 'getDate';
  16452. }
  16453. function hoursGetterName(isUTC) {
  16454. return isUTC ? 'getUTCHours' : 'getHours';
  16455. }
  16456. function minutesGetterName(isUTC) {
  16457. return isUTC ? 'getUTCMinutes' : 'getMinutes';
  16458. }
  16459. function secondsGetterName(isUTC) {
  16460. return isUTC ? 'getUTCSeconds' : 'getSeconds';
  16461. }
  16462. function millisecondsGetterName(isUTC) {
  16463. return isUTC ? 'getUTCMilliseconds' : 'getMilliseconds';
  16464. }
  16465. function fullYearSetterName(isUTC) {
  16466. return isUTC ? 'setUTCFullYear' : 'setFullYear';
  16467. }
  16468. function monthSetterName(isUTC) {
  16469. return isUTC ? 'setUTCMonth' : 'setMonth';
  16470. }
  16471. function dateSetterName(isUTC) {
  16472. return isUTC ? 'setUTCDate' : 'setDate';
  16473. }
  16474. function hoursSetterName(isUTC) {
  16475. return isUTC ? 'setUTCHours' : 'setHours';
  16476. }
  16477. function minutesSetterName(isUTC) {
  16478. return isUTC ? 'setUTCMinutes' : 'setMinutes';
  16479. }
  16480. function secondsSetterName(isUTC) {
  16481. return isUTC ? 'setUTCSeconds' : 'setSeconds';
  16482. }
  16483. function millisecondsSetterName(isUTC) {
  16484. return isUTC ? 'setUTCMilliseconds' : 'setMilliseconds';
  16485. }
  16486. function getTextRect(text, font, align, verticalAlign, padding, rich, truncate, lineHeight) {
  16487. var textEl = new ZRText({
  16488. style: {
  16489. text: text,
  16490. font: font,
  16491. align: align,
  16492. verticalAlign: verticalAlign,
  16493. padding: padding,
  16494. rich: rich,
  16495. overflow: truncate ? 'truncate' : null,
  16496. lineHeight: lineHeight
  16497. }
  16498. });
  16499. return textEl.getBoundingRect();
  16500. }
  16501. /**
  16502. * Add a comma each three digit.
  16503. */
  16504. function addCommas(x) {
  16505. if (!isNumeric(x)) {
  16506. return isString(x) ? x : '-';
  16507. }
  16508. var parts = (x + '').split('.');
  16509. return parts[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (parts.length > 1 ? '.' + parts[1] : '');
  16510. }
  16511. function toCamelCase(str, upperCaseFirst) {
  16512. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  16513. return group1.toUpperCase();
  16514. });
  16515. if (upperCaseFirst && str) {
  16516. str = str.charAt(0).toUpperCase() + str.slice(1);
  16517. }
  16518. return str;
  16519. }
  16520. var normalizeCssArray$1 = normalizeCssArray;
  16521. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  16522. var wrapVar = function (varName, seriesIdx) {
  16523. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  16524. };
  16525. /**
  16526. * Template formatter
  16527. * @param {Array.<Object>|Object} paramsList
  16528. */
  16529. function formatTpl(tpl, paramsList, encode) {
  16530. if (!isArray(paramsList)) {
  16531. paramsList = [paramsList];
  16532. }
  16533. var seriesLen = paramsList.length;
  16534. if (!seriesLen) {
  16535. return '';
  16536. }
  16537. var $vars = paramsList[0].$vars || [];
  16538. for (var i = 0; i < $vars.length; i++) {
  16539. var alias = TPL_VAR_ALIAS[i];
  16540. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16541. }
  16542. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16543. for (var k = 0; k < $vars.length; k++) {
  16544. var val = paramsList[seriesIdx][$vars[k]];
  16545. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  16546. }
  16547. }
  16548. return tpl;
  16549. }
  16550. function getTooltipMarker(inOpt, extraCssText) {
  16551. var opt = isString(inOpt) ? {
  16552. color: inOpt,
  16553. extraCssText: extraCssText
  16554. } : inOpt || {};
  16555. var color = opt.color;
  16556. var type = opt.type;
  16557. extraCssText = opt.extraCssText;
  16558. var renderMode = opt.renderMode || 'html';
  16559. if (!color) {
  16560. return '';
  16561. }
  16562. if (renderMode === 'html') {
  16563. return type === 'subItem' ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;' + 'border-radius:4px;width:4px;height:4px;background-color:'
  16564. // Only support string
  16565. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>' : '<span style="display:inline-block;margin-right:4px;' + 'border-radius:10px;width:10px;height:10px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  16566. } else {
  16567. // Should better not to auto generate style name by auto-increment number here.
  16568. // Because this util is usually called in tooltip formatter, which is probably
  16569. // called repeatedly when mouse move and the auto-increment number increases fast.
  16570. // Users can make their own style name by theirselves, make it unique and readable.
  16571. var markerId = opt.markerId || 'markerX';
  16572. return {
  16573. renderMode: renderMode,
  16574. content: '{' + markerId + '|} ',
  16575. style: type === 'subItem' ? {
  16576. width: 4,
  16577. height: 4,
  16578. borderRadius: 2,
  16579. backgroundColor: color
  16580. } : {
  16581. width: 10,
  16582. height: 10,
  16583. borderRadius: 5,
  16584. backgroundColor: color
  16585. }
  16586. };
  16587. }
  16588. }
  16589. /**
  16590. * @deprecated Use `time/format` instead.
  16591. * ISO Date format
  16592. * @param {string} tpl
  16593. * @param {number} value
  16594. * @param {boolean} [isUTC=false] Default in local time.
  16595. * see `module:echarts/scale/Time`
  16596. * and `module:echarts/util/number#parseDate`.
  16597. * @inner
  16598. */
  16599. function formatTime(tpl, value, isUTC) {
  16600. if ("development" !== 'production') {
  16601. deprecateReplaceLog('echarts.format.formatTime', 'echarts.time.format');
  16602. }
  16603. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  16604. tpl = 'MM-dd\nyyyy';
  16605. }
  16606. var date = parseDate(value);
  16607. var getUTC = isUTC ? 'getUTC' : 'get';
  16608. var y = date[getUTC + 'FullYear']();
  16609. var M = date[getUTC + 'Month']() + 1;
  16610. var d = date[getUTC + 'Date']();
  16611. var h = date[getUTC + 'Hours']();
  16612. var m = date[getUTC + 'Minutes']();
  16613. var s = date[getUTC + 'Seconds']();
  16614. var S = date[getUTC + 'Milliseconds']();
  16615. tpl = tpl.replace('MM', pad(M, 2)).replace('M', M).replace('yyyy', y).replace('yy', pad(y % 100 + '', 2)).replace('dd', pad(d, 2)).replace('d', d).replace('hh', pad(h, 2)).replace('h', h).replace('mm', pad(m, 2)).replace('m', m).replace('ss', pad(s, 2)).replace('s', s).replace('SSS', pad(S, 3));
  16616. return tpl;
  16617. }
  16618. /**
  16619. * Capital first
  16620. * @param {string} str
  16621. * @return {string}
  16622. */
  16623. function capitalFirst(str) {
  16624. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  16625. }
  16626. /**
  16627. * @return Never be null/undefined.
  16628. */
  16629. function convertToColorString(color, defaultColor) {
  16630. defaultColor = defaultColor || 'transparent';
  16631. return isString(color) ? color : isObject(color) ? color.colorStops && (color.colorStops[0] || {}).color || defaultColor : defaultColor;
  16632. }
  16633. /**
  16634. * FIXME:
  16635. * `nonSeriesBoxCoordSysCreators` and `_nonSeriesBoxMasterList` are hardcoded implementations.
  16636. * Regarding "coord sys layout based on another coord sys", currently we only exprimentally support one level
  16637. * dpendency, such as, "grid(cartesian)s can be laid out based on matrix/calendar coord sys."
  16638. * But a comprehensive implementation may need to support:
  16639. * - Recursive dependencies. e.g., a matrix coord sys lays out based on another matrix coord sys.
  16640. * That requires in the implementation `create` and `update` of coord sys are called by a dependency graph.
  16641. * (@see enableTopologicalTravel in `util/component.ts`)
  16642. */
  16643. var nonSeriesBoxCoordSysCreators = {};
  16644. var normalCoordSysCreators = {};
  16645. var CoordinateSystemManager = /** @class */function () {
  16646. function CoordinateSystemManager() {
  16647. this._normalMasterList = [];
  16648. this._nonSeriesBoxMasterList = [];
  16649. }
  16650. /**
  16651. * Typically,
  16652. * - in `create`, a coord sys lays out based on a given rect;
  16653. * - in `update`, update the pixel and data extent of there axes (if any) based on processed `series.data`.
  16654. * After that, a coord sys can serve (typically by `dataToPoint`/`dataToLayout`/`pointToData`).
  16655. * If the coordinate system do not lay out based on `series.data`, `update` is not needed.
  16656. */
  16657. CoordinateSystemManager.prototype.create = function (ecModel, api) {
  16658. this._nonSeriesBoxMasterList = dealCreate(nonSeriesBoxCoordSysCreators, true);
  16659. this._normalMasterList = dealCreate(normalCoordSysCreators, false);
  16660. function dealCreate(creatorMap, canBeNonSeriesBox) {
  16661. var coordinateSystems = [];
  16662. each(creatorMap, function (creator, type) {
  16663. var list = creator.create(ecModel, api);
  16664. coordinateSystems = coordinateSystems.concat(list || []);
  16665. if ("development" !== 'production') {
  16666. if (canBeNonSeriesBox) {
  16667. // Disallow `update` is a brutal way to ensure `_nonSeriesBoxMasterList`s are ready to
  16668. // serve after `create`. But if `update` has to be involved in `_nonSeriesBoxMasterList`
  16669. // for some future case, more complicated mechanisms need to be introduced.
  16670. each(list, function (master) {
  16671. return assert(!master.update);
  16672. });
  16673. }
  16674. }
  16675. });
  16676. return coordinateSystems;
  16677. }
  16678. };
  16679. /**
  16680. * @see CoordinateSystem['create']
  16681. */
  16682. CoordinateSystemManager.prototype.update = function (ecModel, api) {
  16683. each(this._normalMasterList, function (coordSys) {
  16684. coordSys.update && coordSys.update(ecModel, api);
  16685. });
  16686. };
  16687. CoordinateSystemManager.prototype.getCoordinateSystems = function () {
  16688. return this._normalMasterList.concat(this._nonSeriesBoxMasterList);
  16689. };
  16690. CoordinateSystemManager.register = function (type, creator) {
  16691. if (type === 'matrix' || type === 'calendar') {
  16692. // FIXME: hardcode, @see nonSeriesBoxCoordSysCreators
  16693. nonSeriesBoxCoordSysCreators[type] = creator;
  16694. return;
  16695. }
  16696. normalCoordSysCreators[type] = creator;
  16697. };
  16698. CoordinateSystemManager.get = function (type) {
  16699. return normalCoordSysCreators[type] || nonSeriesBoxCoordSysCreators[type];
  16700. };
  16701. return CoordinateSystemManager;
  16702. }();
  16703. function canBeNonSeriesBoxCoordSys(coordSysType) {
  16704. return !!nonSeriesBoxCoordSysCreators[coordSysType];
  16705. }
  16706. var BoxCoordinateSystemCoordFrom = {
  16707. // By default fetch coord from `model.get('coord')`.
  16708. coord: 1,
  16709. // Some model/series, such as pie, is allowed to also get coord from `model.get('center')`,
  16710. // if cannot get from `model.get('coord')`. But historically pie use `center` option, but
  16711. // geo use `layoutCenter` option to specify layout center; they are not able to be unified.
  16712. // Therefor it is not recommended.
  16713. coord2: 2
  16714. };
  16715. /**
  16716. * @see_also `createBoxLayoutReference`
  16717. * @see_also `injectCoordSysByOption`
  16718. */
  16719. function registerLayOutOnCoordSysUsage(opt) {
  16720. if ("development" !== 'production') {
  16721. assert(!coordSysUseMap.get(opt.fullType));
  16722. }
  16723. coordSysUseMap.set(opt.fullType, {
  16724. getCoord2: undefined
  16725. }).getCoord2 = opt.getCoord2;
  16726. }
  16727. var coordSysUseMap = createHashMap();
  16728. /**
  16729. * @return Be an object, but never be NullUndefined.
  16730. */
  16731. function getCoordForBoxCoordSys(model) {
  16732. var coord = model.getShallow('coord', true);
  16733. var from = BoxCoordinateSystemCoordFrom.coord;
  16734. if (coord == null) {
  16735. var store = coordSysUseMap.get(model.type);
  16736. if (store && store.getCoord2) {
  16737. from = BoxCoordinateSystemCoordFrom.coord2;
  16738. coord = store.getCoord2(model);
  16739. }
  16740. }
  16741. return {
  16742. coord: coord,
  16743. from: from
  16744. };
  16745. }
  16746. /**
  16747. * - "dataCoordSys": each data item is laid out based on a coord sys.
  16748. * - "boxCoordSys": the overall bounding rect or anchor point is calculated based on a coord sys.
  16749. * e.g.,
  16750. * grid rect (cartesian rect) is calculate based on matrix/calendar coord sys;
  16751. * pie center is calculated based on calendar/cartesian;
  16752. *
  16753. * The default value (if not declared in option `coordinateSystemUsage`):
  16754. * For series, use `dataCoordSys`, since this is the most case and backward compatible.
  16755. * For non-series components, use `boxCoordSys`, since `dataCoordSys` is not applicable.
  16756. */
  16757. var CoordinateSystemUsageKind = {
  16758. none: 0,
  16759. dataCoordSys: 1,
  16760. boxCoordSys: 2
  16761. };
  16762. function decideCoordSysUsageKind(
  16763. // Component or series
  16764. model, printError) {
  16765. // For backward compat, still not use `true` in model.get.
  16766. var coordSysType = model.getShallow('coordinateSystem');
  16767. var coordSysUsageOption = model.getShallow('coordinateSystemUsage', true);
  16768. var isDeclaredExplicitly = coordSysUsageOption != null;
  16769. var kind = CoordinateSystemUsageKind.none;
  16770. if (coordSysType) {
  16771. var isSeries = model.mainType === 'series';
  16772. if (coordSysUsageOption == null) {
  16773. coordSysUsageOption = isSeries ? 'data' : 'box';
  16774. }
  16775. if (coordSysUsageOption === 'data') {
  16776. kind = CoordinateSystemUsageKind.dataCoordSys;
  16777. if (!isSeries) {
  16778. if ("development" !== 'production') {
  16779. if (isDeclaredExplicitly && printError) {
  16780. error('coordinateSystemUsage "data" is not supported in non-series components.');
  16781. }
  16782. }
  16783. kind = CoordinateSystemUsageKind.none;
  16784. }
  16785. } else if (coordSysUsageOption === 'box') {
  16786. kind = CoordinateSystemUsageKind.boxCoordSys;
  16787. if (!isSeries && !canBeNonSeriesBoxCoordSys(coordSysType)) {
  16788. if ("development" !== 'production') {
  16789. if (isDeclaredExplicitly && printError) {
  16790. error("coordinateSystem \"" + coordSysType + "\" cannot be used" + (" as coordinateSystemUsage \"box\" for \"" + model.type + "\" yet."));
  16791. }
  16792. }
  16793. kind = CoordinateSystemUsageKind.none;
  16794. }
  16795. }
  16796. }
  16797. return {
  16798. coordSysType: coordSysType,
  16799. kind: kind
  16800. };
  16801. }
  16802. /**
  16803. * These cases are considered:
  16804. * (A) Most series can use only "dataCoordSys", but "boxCoordSys" is not applicable:
  16805. * - e.g., series.heatmap, series.line, series.bar, series.scatter, ...
  16806. * (B) Some series and most components can use only "boxCoordSys", but "dataCoordSys" is not applicable:
  16807. * - e.g., series.pie, series.funnel, ...
  16808. * - e.g., grid, polar, geo, title, ...
  16809. * (C) Several series can use both "boxCoordSys" and "dataCoordSys", even at the same time:
  16810. * - e.g., series.graph, series.map
  16811. * - If graph or map series use a "boxCoordSys", it creates a internal "dataCoordSys" to lay out its data.
  16812. * - Graph series can use matrix coord sys as either the "dataCoordSys" (each item layout on one cell)
  16813. * or "boxCoordSys" (the entire series are layout within one cell).
  16814. * - To achieve this effect,
  16815. * `series.coordinateSystemUsage: 'box'` needs to be specified explicitly.
  16816. *
  16817. * Check these echarts option settings:
  16818. * - If `series: {type: 'bar'}`:
  16819. * dataCoordSys: "cartesian2d", boxCoordSys: "none".
  16820. * (since `coordinateSystem: 'cartesian2d'` is the default option in bar.)
  16821. * - If `grid: {coordinateSystem: 'matrix'}`
  16822. * dataCoordSys: "none", boxCoordSys: "matrix".
  16823. * - If `series: {type: 'pie', coordinateSystem: 'matrix'}`:
  16824. * dataCoordSys: "none", boxCoordSys: "matrix".
  16825. * (since `coordinateSystemUsage: 'box'` is the default option in pie.)
  16826. * - If `series: {type: 'graph', coordinateSystem: 'matrix'}`:
  16827. * dataCoordSys: "matrix", boxCoordSys: "none"
  16828. * - If `series: {type: 'graph', coordinateSystem: 'matrix', coordinateSystemUsage: 'box'}`:
  16829. * dataCoordSys: "an internal view", boxCoordSys: "the internal view is laid out on a matrix"
  16830. * - If `series: {type: 'map'}`:
  16831. * dataCoordSys: "a internal geo", boxCoordSys: "none"
  16832. * - If `series: {type: 'map', coordinateSystem: 'geo', geoIndex: 0}`:
  16833. * dataCoordSys: "a geo", boxCoordSys: "none"
  16834. * - If `series: {type: 'map', coordinateSystem: 'matrix'}`:
  16835. * not_applicable
  16836. * - If `series: {type: 'map', coordinateSystem: 'matrix', coordinateSystemUsage: 'box'}`:
  16837. * dataCoordSys: "an internal geo", boxCoordSys: "the internal geo is laid out on a matrix"
  16838. *
  16839. * @usage
  16840. * For case (A) & (B),
  16841. * call `injectCoordSysByOption({coordSysType: 'aaa', ...})` once for each series/components.
  16842. * For case (C),
  16843. * call `injectCoordSysByOption({coordSysType: 'aaa', ...})` once for each series/components,
  16844. * and then call `injectCoordSysByOption({coordSysType: 'bbb', ..., isDefaultDataCoordSys: true})`
  16845. * once for each series/components.
  16846. *
  16847. * @return Whether injected.
  16848. */
  16849. function injectCoordSysByOption(opt) {
  16850. var targetModel = opt.targetModel,
  16851. coordSysType = opt.coordSysType,
  16852. coordSysProvider = opt.coordSysProvider,
  16853. isDefaultDataCoordSys = opt.isDefaultDataCoordSys,
  16854. allowNotFound = opt.allowNotFound;
  16855. if ("development" !== 'production') {
  16856. assert(!!coordSysType);
  16857. }
  16858. var _a = decideCoordSysUsageKind(targetModel, true),
  16859. kind = _a.kind,
  16860. declaredType = _a.coordSysType;
  16861. if (isDefaultDataCoordSys && kind !== CoordinateSystemUsageKind.dataCoordSys) {
  16862. // If both dataCoordSys and boxCoordSys declared in one model.
  16863. // There is the only case in series-graph, and no other cases yet.
  16864. kind = CoordinateSystemUsageKind.dataCoordSys;
  16865. declaredType = coordSysType;
  16866. }
  16867. if (kind === CoordinateSystemUsageKind.none || declaredType !== coordSysType) {
  16868. return false;
  16869. }
  16870. var coordSys = coordSysProvider(coordSysType, targetModel);
  16871. if (!coordSys) {
  16872. if ("development" !== 'production') {
  16873. if (!allowNotFound) {
  16874. error(coordSysType + " cannot be found for" + (" " + targetModel.type + " (index: " + targetModel.componentIndex + ")."));
  16875. }
  16876. }
  16877. return false;
  16878. }
  16879. if (kind === CoordinateSystemUsageKind.dataCoordSys) {
  16880. if ("development" !== 'production') {
  16881. assert(targetModel.mainType === 'series');
  16882. }
  16883. targetModel.coordinateSystem = coordSys;
  16884. } else {
  16885. // kind === 'boxCoordSys'
  16886. targetModel.boxCoordinateSystem = coordSys;
  16887. }
  16888. return true;
  16889. }
  16890. var each$1 = each;
  16891. /**
  16892. * @public
  16893. */
  16894. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  16895. /**
  16896. * @public
  16897. */
  16898. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  16899. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  16900. var x = 0;
  16901. var y = 0;
  16902. if (maxWidth == null) {
  16903. maxWidth = Infinity;
  16904. }
  16905. if (maxHeight == null) {
  16906. maxHeight = Infinity;
  16907. }
  16908. var currentLineMaxSize = 0;
  16909. group.eachChild(function (child, idx) {
  16910. var rect = child.getBoundingRect();
  16911. var nextChild = group.childAt(idx + 1);
  16912. var nextChildRect = nextChild && nextChild.getBoundingRect();
  16913. var nextX;
  16914. var nextY;
  16915. if (orient === 'horizontal') {
  16916. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  16917. nextX = x + moveX;
  16918. // Wrap when width exceeds maxWidth or meet a `newline` group
  16919. // FIXME compare before adding gap?
  16920. if (nextX > maxWidth || child.newline) {
  16921. x = 0;
  16922. nextX = moveX;
  16923. y += currentLineMaxSize + gap;
  16924. currentLineMaxSize = rect.height;
  16925. } else {
  16926. // FIXME: consider rect.y is not `0`?
  16927. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  16928. }
  16929. } else {
  16930. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  16931. nextY = y + moveY;
  16932. // Wrap when width exceeds maxHeight or meet a `newline` group
  16933. if (nextY > maxHeight || child.newline) {
  16934. x += currentLineMaxSize + gap;
  16935. y = 0;
  16936. nextY = moveY;
  16937. currentLineMaxSize = rect.width;
  16938. } else {
  16939. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  16940. }
  16941. }
  16942. if (child.newline) {
  16943. return;
  16944. }
  16945. child.x = x;
  16946. child.y = y;
  16947. child.markRedraw();
  16948. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  16949. });
  16950. }
  16951. /**
  16952. * VBox layouting
  16953. * @param {module:zrender/graphic/Group} group
  16954. * @param {number} gap
  16955. * @param {number} [width=Infinity]
  16956. * @param {number} [height=Infinity]
  16957. */
  16958. var vbox = curry(boxLayout, 'vertical');
  16959. /**
  16960. * HBox layouting
  16961. * @param {module:zrender/graphic/Group} group
  16962. * @param {number} gap
  16963. * @param {number} [width=Infinity]
  16964. * @param {number} [height=Infinity]
  16965. */
  16966. var hbox = curry(boxLayout, 'horizontal');
  16967. function getBoxLayoutParams(boxLayoutModel, ignoreParent) {
  16968. return {
  16969. left: boxLayoutModel.getShallow('left', ignoreParent),
  16970. top: boxLayoutModel.getShallow('top', ignoreParent),
  16971. right: boxLayoutModel.getShallow('right', ignoreParent),
  16972. bottom: boxLayoutModel.getShallow('bottom', ignoreParent),
  16973. width: boxLayoutModel.getShallow('width', ignoreParent),
  16974. height: boxLayoutModel.getShallow('height', ignoreParent)
  16975. };
  16976. }
  16977. function getViewRectAndCenterForCircleLayout(seriesModel, api) {
  16978. var layoutRef = createBoxLayoutReference(seriesModel, api, {
  16979. enableLayoutOnlyByCenter: true
  16980. });
  16981. var boxLayoutParams = seriesModel.getBoxLayoutParams();
  16982. var viewRect;
  16983. var center;
  16984. if (layoutRef.type === BoxLayoutReferenceType.point) {
  16985. center = layoutRef.refPoint;
  16986. // `viewRect` is required in `pie/labelLayout.ts`.
  16987. viewRect = getLayoutRect(boxLayoutParams, {
  16988. width: api.getWidth(),
  16989. height: api.getHeight()
  16990. });
  16991. } else {
  16992. // layoutRef.type === layout.BoxLayoutReferenceType.rect
  16993. var centerOption = seriesModel.get('center');
  16994. var centerOptionArr = isArray(centerOption) ? centerOption : [centerOption, centerOption];
  16995. viewRect = getLayoutRect(boxLayoutParams, layoutRef.refContainer);
  16996. center = layoutRef.boxCoordFrom === BoxCoordinateSystemCoordFrom.coord2 ? layoutRef.refPoint // option `series.center` has been used as coord.
  16997. : [parsePercent$1(centerOptionArr[0], viewRect.width) + viewRect.x, parsePercent$1(centerOptionArr[1], viewRect.height) + viewRect.y];
  16998. }
  16999. return {
  17000. viewRect: viewRect,
  17001. center: center
  17002. };
  17003. }
  17004. function getCircleLayout(seriesModel, api) {
  17005. // center can be string or number when coordinateSystem is specified
  17006. var _a = getViewRectAndCenterForCircleLayout(seriesModel, api),
  17007. viewRect = _a.viewRect,
  17008. center = _a.center;
  17009. var radius = seriesModel.get('radius');
  17010. if (!isArray(radius)) {
  17011. radius = [0, radius];
  17012. }
  17013. var width = parsePercent$1(viewRect.width, api.getWidth());
  17014. var height = parsePercent$1(viewRect.height, api.getHeight());
  17015. var size = Math.min(width, height);
  17016. var r0 = parsePercent$1(radius[0], size / 2);
  17017. var r = parsePercent$1(radius[1], size / 2);
  17018. return {
  17019. cx: center[0],
  17020. cy: center[1],
  17021. r0: r0,
  17022. r: r,
  17023. viewRect: viewRect
  17024. };
  17025. }
  17026. /**
  17027. * Parse position info.
  17028. */
  17029. function getLayoutRect(positionInfo, containerRect,
  17030. // This is the space from the `containerRect` to the returned bounding rect.
  17031. // Commonly used in option `legend.padding`, `timeline.padding`, `title.padding`,
  17032. // `visualMap.padding`, ...
  17033. // [NOTICE]:
  17034. // It's named `margin`, because it's the space that outside the bounding rect. But from
  17035. // the perspective of the the caller, it's commonly used as the `padding` of a component,
  17036. // because conventionally background color covers this space.
  17037. // [BEHAVIOR]:
  17038. // - If width/height is specified, `margin` does not effect them.
  17039. // - Otherwise, they are calculated based on the rect that `containerRect` shrinked by `margin`.
  17040. // - left/right/top/bottom are based on the rect that `containerRect` shrinked by `margin`.
  17041. margin) {
  17042. margin = normalizeCssArray$1(margin || 0);
  17043. var containerWidth = containerRect.width;
  17044. var containerHeight = containerRect.height;
  17045. var left = parsePercent$1(positionInfo.left, containerWidth);
  17046. var top = parsePercent$1(positionInfo.top, containerHeight);
  17047. var right = parsePercent$1(positionInfo.right, containerWidth);
  17048. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  17049. var width = parsePercent$1(positionInfo.width, containerWidth);
  17050. var height = parsePercent$1(positionInfo.height, containerHeight);
  17051. var verticalMargin = margin[2] + margin[0];
  17052. var horizontalMargin = margin[1] + margin[3];
  17053. var aspect = positionInfo.aspect;
  17054. // If width is not specified, calculate width from left and right
  17055. if (isNaN(width)) {
  17056. width = containerWidth - right - horizontalMargin - left;
  17057. }
  17058. if (isNaN(height)) {
  17059. height = containerHeight - bottom - verticalMargin - top;
  17060. }
  17061. if (aspect != null) {
  17062. // If width and height are not given
  17063. // 1. Graph should not exceeds the container
  17064. // 2. Aspect must be keeped
  17065. // 3. Graph should take the space as more as possible
  17066. // FIXME
  17067. // Margin is not considered, because there is no case that both
  17068. // using margin and aspect so far.
  17069. if (isNaN(width) && isNaN(height)) {
  17070. // PENDING: if only `left` or `right` is defined, perhaps it's more preferable to
  17071. // calculate size based on `containerWidth - left` or `containerWidth - left` here,
  17072. // but for backward compatibility we do not change it.
  17073. if (aspect > containerWidth / containerHeight) {
  17074. width = containerWidth * 0.8;
  17075. } else {
  17076. height = containerHeight * 0.8;
  17077. }
  17078. }
  17079. // Calculate width or height with given aspect
  17080. if (isNaN(width)) {
  17081. width = aspect * height;
  17082. }
  17083. if (isNaN(height)) {
  17084. height = width / aspect;
  17085. }
  17086. }
  17087. // If left is not specified, calculate left from right and width
  17088. if (isNaN(left)) {
  17089. left = containerWidth - right - width - horizontalMargin;
  17090. }
  17091. if (isNaN(top)) {
  17092. top = containerHeight - bottom - height - verticalMargin;
  17093. }
  17094. // Align left and top
  17095. switch (positionInfo.left || positionInfo.right) {
  17096. case 'center':
  17097. left = containerWidth / 2 - width / 2 - margin[3];
  17098. break;
  17099. case 'right':
  17100. left = containerWidth - width - horizontalMargin;
  17101. break;
  17102. }
  17103. switch (positionInfo.top || positionInfo.bottom) {
  17104. case 'middle':
  17105. case 'center':
  17106. top = containerHeight / 2 - height / 2 - margin[0];
  17107. break;
  17108. case 'bottom':
  17109. top = containerHeight - height - verticalMargin;
  17110. break;
  17111. }
  17112. // If something is wrong and left, top, width, height are calculated as NaN
  17113. left = left || 0;
  17114. top = top || 0;
  17115. if (isNaN(width)) {
  17116. // Width may be NaN if only one value is given except width
  17117. width = containerWidth - horizontalMargin - left - (right || 0);
  17118. }
  17119. if (isNaN(height)) {
  17120. // Height may be NaN if only one value is given except height
  17121. height = containerHeight - verticalMargin - top - (bottom || 0);
  17122. }
  17123. var rect = new BoundingRect((containerRect.x || 0) + left + margin[3], (containerRect.y || 0) + top + margin[0], width, height);
  17124. rect.margin = margin;
  17125. return rect;
  17126. }
  17127. var BoxLayoutReferenceType = {
  17128. rect: 1,
  17129. point: 2
  17130. };
  17131. /**
  17132. * Uniformly calculate layout reference (rect or center) based on either:
  17133. * - viewport:
  17134. * - Get `refContainer` as `{x: 0, y: 0, width: api.getWidth(), height: api.getHeight()}`
  17135. * - coordinate system, which can serve in several ways:
  17136. * - Use `dataToPoint` to get the `refPoint`, such as, in cartesian2d coord sys.
  17137. * - Use `dataToLayout` to get the `refContainer`, such as, in matrix coord sys.
  17138. */
  17139. function createBoxLayoutReference(model, api, opt) {
  17140. var refContainer;
  17141. var refPoint;
  17142. var layoutRefType;
  17143. var boxCoordSys = model.boxCoordinateSystem;
  17144. var boxCoordFrom;
  17145. if (boxCoordSys) {
  17146. var _a = getCoordForBoxCoordSys(model),
  17147. coord = _a.coord,
  17148. from = _a.from;
  17149. // Do not use `clamp` in `dataToLayout` and `dataToPoint`, because:
  17150. // 1. Should support overflow (such as, by dataZoom), where NaN should be in the result.
  17151. // 2. Be consistent with the way used in `series.data`
  17152. if (boxCoordSys.dataToLayout) {
  17153. layoutRefType = BoxLayoutReferenceType.rect;
  17154. boxCoordFrom = from;
  17155. var result = boxCoordSys.dataToLayout(coord);
  17156. refContainer = result.contentRect || result.rect;
  17157. } else if (opt && opt.enableLayoutOnlyByCenter && boxCoordSys.dataToPoint) {
  17158. layoutRefType = BoxLayoutReferenceType.point;
  17159. boxCoordFrom = from;
  17160. refPoint = boxCoordSys.dataToPoint(coord);
  17161. } else {
  17162. if ("development" !== 'production') {
  17163. error(model.type + "[" + model.componentIndex + "]" + (" layout based on " + boxCoordSys.type + " is not supported."));
  17164. }
  17165. }
  17166. }
  17167. if (layoutRefType == null) {
  17168. layoutRefType = BoxLayoutReferenceType.rect;
  17169. }
  17170. if (layoutRefType === BoxLayoutReferenceType.rect) {
  17171. if (!refContainer) {
  17172. refContainer = {
  17173. x: 0,
  17174. y: 0,
  17175. width: api.getWidth(),
  17176. height: api.getHeight()
  17177. };
  17178. }
  17179. refPoint = [refContainer.x + refContainer.width / 2, refContainer.y + refContainer.height / 2];
  17180. }
  17181. return {
  17182. type: layoutRefType,
  17183. refContainer: refContainer,
  17184. refPoint: refPoint,
  17185. boxCoordFrom: boxCoordFrom
  17186. };
  17187. }
  17188. function fetchLayoutMode(ins) {
  17189. var layoutMode = ins.layoutMode || ins.constructor.layoutMode;
  17190. return isObject(layoutMode) ? layoutMode : layoutMode ? {
  17191. type: layoutMode
  17192. } : null;
  17193. }
  17194. /**
  17195. * Consider Case:
  17196. * When default option has {left: 0, width: 100}, and we set {right: 0}
  17197. * through setOption or media query, using normal zrUtil.merge will cause
  17198. * {right: 0} does not take effect.
  17199. *
  17200. * @example
  17201. * ComponentModel.extend({
  17202. * init: function () {
  17203. * ...
  17204. * let inputPositionParams = layout.getLayoutParams(option);
  17205. * this.mergeOption(inputPositionParams);
  17206. * },
  17207. * mergeOption: function (newOption) {
  17208. * newOption && zrUtil.merge(thisOption, newOption, true);
  17209. * layout.mergeLayoutParam(thisOption, newOption);
  17210. * }
  17211. * });
  17212. *
  17213. * @param targetOption
  17214. * @param newOption
  17215. * @param opt
  17216. */
  17217. function mergeLayoutParam(targetOption, newOption, opt) {
  17218. var ignoreSize = opt && opt.ignoreSize;
  17219. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  17220. var hResult = merge(HV_NAMES[0], 0);
  17221. var vResult = merge(HV_NAMES[1], 1);
  17222. copy(HV_NAMES[0], targetOption, hResult);
  17223. copy(HV_NAMES[1], targetOption, vResult);
  17224. function merge(names, hvIdx) {
  17225. var newParams = {};
  17226. var newValueCount = 0;
  17227. var merged = {};
  17228. var mergedValueCount = 0;
  17229. var enoughParamNumber = 2;
  17230. each$1(names, function (name) {
  17231. merged[name] = targetOption[name];
  17232. });
  17233. each$1(names, function (name) {
  17234. // Consider case: newOption.width is null, which is
  17235. // set by user for removing width setting.
  17236. hasOwn(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  17237. hasValue(newParams, name) && newValueCount++;
  17238. hasValue(merged, name) && mergedValueCount++;
  17239. });
  17240. if (ignoreSize[hvIdx]) {
  17241. // Only one of left/right is premitted to exist.
  17242. if (hasValue(newOption, names[1])) {
  17243. merged[names[2]] = null;
  17244. } else if (hasValue(newOption, names[2])) {
  17245. merged[names[1]] = null;
  17246. }
  17247. return merged;
  17248. }
  17249. // Case: newOption: {width: ..., right: ...},
  17250. // or targetOption: {right: ...} and newOption: {width: ...},
  17251. // There is no conflict when merged only has params count
  17252. // little than enoughParamNumber.
  17253. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  17254. return merged;
  17255. }
  17256. // Case: newOption: {width: ..., right: ...},
  17257. // Than we can make sure user only want those two, and ignore
  17258. // all origin params in targetOption.
  17259. else if (newValueCount >= enoughParamNumber) {
  17260. return newParams;
  17261. } else {
  17262. // Chose another param from targetOption by priority.
  17263. for (var i = 0; i < names.length; i++) {
  17264. var name_1 = names[i];
  17265. if (!hasOwn(newParams, name_1) && hasOwn(targetOption, name_1)) {
  17266. newParams[name_1] = targetOption[name_1];
  17267. break;
  17268. }
  17269. }
  17270. return newParams;
  17271. }
  17272. }
  17273. function hasValue(obj, name) {
  17274. return obj[name] != null && obj[name] !== 'auto';
  17275. }
  17276. function copy(names, target, source) {
  17277. each$1(names, function (name) {
  17278. target[name] = source[name];
  17279. });
  17280. }
  17281. }
  17282. /**
  17283. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17284. */
  17285. function getLayoutParams(source) {
  17286. return copyLayoutParams({}, source);
  17287. }
  17288. /**
  17289. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17290. * @param {Object} source
  17291. * @return {Object} Result contains those props.
  17292. */
  17293. function copyLayoutParams(target, source) {
  17294. source && target && each$1(LOCATION_PARAMS, function (name) {
  17295. hasOwn(source, name) && (target[name] = source[name]);
  17296. });
  17297. return target;
  17298. }
  17299. var inner = makeInner();
  17300. var ComponentModel = /** @class */function (_super) {
  17301. __extends(ComponentModel, _super);
  17302. function ComponentModel(option, parentModel, ecModel) {
  17303. var _this = _super.call(this, option, parentModel, ecModel) || this;
  17304. _this.uid = getUID('ec_cpt_model');
  17305. return _this;
  17306. }
  17307. ComponentModel.prototype.init = function (option, parentModel, ecModel) {
  17308. this.mergeDefaultAndTheme(option, ecModel);
  17309. };
  17310. ComponentModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  17311. var layoutMode = fetchLayoutMode(this);
  17312. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  17313. var themeModel = ecModel.getTheme();
  17314. merge(option, themeModel.get(this.mainType));
  17315. merge(option, this.getDefaultOption());
  17316. if (layoutMode) {
  17317. mergeLayoutParam(option, inputPositionParams, layoutMode);
  17318. }
  17319. };
  17320. ComponentModel.prototype.mergeOption = function (option, ecModel) {
  17321. merge(this.option, option, true);
  17322. var layoutMode = fetchLayoutMode(this);
  17323. if (layoutMode) {
  17324. mergeLayoutParam(this.option, option, layoutMode);
  17325. }
  17326. };
  17327. /**
  17328. * Called immediately after `init` or `mergeOption` of this instance called.
  17329. */
  17330. ComponentModel.prototype.optionUpdated = function (newCptOption, isInit) {};
  17331. /**
  17332. * [How to declare defaultOption]:
  17333. *
  17334. * (A) If using class declaration in typescript (since echarts 5):
  17335. * ```ts
  17336. * import {ComponentOption} from '../model/option.js';
  17337. * export interface XxxOption extends ComponentOption {
  17338. * aaa: number
  17339. * }
  17340. * export class XxxModel extends Component {
  17341. * static type = 'xxx';
  17342. * static defaultOption: XxxOption = {
  17343. * aaa: 123
  17344. * }
  17345. * }
  17346. * Component.registerClass(XxxModel);
  17347. * ```
  17348. * ```ts
  17349. * import {inheritDefaultOption} from '../util/component.js';
  17350. * import {XxxModel, XxxOption} from './XxxModel.js';
  17351. * export interface XxxSubOption extends XxxOption {
  17352. * bbb: number
  17353. * }
  17354. * class XxxSubModel extends XxxModel {
  17355. * static defaultOption: XxxSubOption = inheritDefaultOption(XxxModel.defaultOption, {
  17356. * bbb: 456
  17357. * })
  17358. * fn() {
  17359. * let opt = this.getDefaultOption();
  17360. * // opt is {aaa: 123, bbb: 456}
  17361. * }
  17362. * }
  17363. * ```
  17364. *
  17365. * (B) If using class extend (previous approach in echarts 3 & 4):
  17366. * ```js
  17367. * let XxxComponent = Component.extend({
  17368. * defaultOption: {
  17369. * xx: 123
  17370. * }
  17371. * })
  17372. * ```
  17373. * ```js
  17374. * let XxxSubComponent = XxxComponent.extend({
  17375. * defaultOption: {
  17376. * yy: 456
  17377. * },
  17378. * fn: function () {
  17379. * let opt = this.getDefaultOption();
  17380. * // opt is {xx: 123, yy: 456}
  17381. * }
  17382. * })
  17383. * ```
  17384. */
  17385. ComponentModel.prototype.getDefaultOption = function () {
  17386. var ctor = this.constructor;
  17387. if (!isExtendedClass(ctor)) {
  17388. // When using ES class declaration, defaultOption must be declared as static.
  17389. // And manually inherit the defaultOption from its parent class if needed, such as,
  17390. // ```ts
  17391. // static defaultOption = inheritDefaultOption(ParentModel.defaultOption, {...});
  17392. // ```
  17393. return ctor.defaultOption;
  17394. }
  17395. // FIXME: remove this approach?
  17396. // Legacy: auto merge defaultOption from ancestor classes if using ParentClass.extend(subProto)
  17397. var fields = inner(this);
  17398. if (!fields.defaultOption) {
  17399. var optList = [];
  17400. var clz = ctor;
  17401. while (clz) {
  17402. var opt = clz.prototype.defaultOption;
  17403. opt && optList.push(opt);
  17404. clz = clz.superClass;
  17405. }
  17406. var defaultOption = {};
  17407. for (var i = optList.length - 1; i >= 0; i--) {
  17408. defaultOption = merge(defaultOption, optList[i], true);
  17409. }
  17410. fields.defaultOption = defaultOption;
  17411. }
  17412. return fields.defaultOption;
  17413. };
  17414. /**
  17415. * Notice: always force to input param `useDefault` in case that forget to consider it.
  17416. * The same behavior as `modelUtil.parseFinder`.
  17417. *
  17418. * @param useDefault In many cases like series refer axis and axis refer grid,
  17419. * If axis index / axis id not specified, use the first target as default.
  17420. * In other cases like dataZoom refer axis, if not specified, measn no refer.
  17421. */
  17422. ComponentModel.prototype.getReferringComponents = function (mainType, opt) {
  17423. var indexKey = mainType + 'Index';
  17424. var idKey = mainType + 'Id';
  17425. return queryReferringComponents(this.ecModel, mainType, {
  17426. index: this.get(indexKey, true),
  17427. id: this.get(idKey, true)
  17428. }, opt);
  17429. };
  17430. ComponentModel.prototype.getBoxLayoutParams = function () {
  17431. // Consider itself having box layout configs.
  17432. // For backward compatibility, by default do not `ignoreParent`.
  17433. return getBoxLayoutParams(this, false);
  17434. };
  17435. /**
  17436. * Get key for zlevel.
  17437. * If developers don't configure zlevel. We will assign zlevel to series based on the key.
  17438. * For example, lines with trail effect and progressive series will in an individual zlevel.
  17439. */
  17440. ComponentModel.prototype.getZLevelKey = function () {
  17441. return '';
  17442. };
  17443. ComponentModel.prototype.setZLevel = function (zlevel) {
  17444. this.option.zlevel = zlevel;
  17445. };
  17446. ComponentModel.protoInitialize = function () {
  17447. var proto = ComponentModel.prototype;
  17448. proto.type = 'component';
  17449. proto.id = '';
  17450. proto.name = '';
  17451. proto.mainType = '';
  17452. proto.subType = '';
  17453. proto.componentIndex = 0;
  17454. }();
  17455. return ComponentModel;
  17456. }(Model);
  17457. mountExtend(ComponentModel, Model);
  17458. enableClassManagement(ComponentModel);
  17459. enableSubTypeDefaulter(ComponentModel);
  17460. enableTopologicalTravel(ComponentModel, getDependencies);
  17461. function getDependencies(componentType) {
  17462. var deps = [];
  17463. each(ComponentModel.getClassesByMainType(componentType), function (clz) {
  17464. deps = deps.concat(clz.dependencies || clz.prototype.dependencies || []);
  17465. });
  17466. // Ensure main type.
  17467. deps = map(deps, function (type) {
  17468. return parseClassType(type).main;
  17469. });
  17470. // Hack dataset for convenience.
  17471. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  17472. deps.unshift('dataset');
  17473. }
  17474. return deps;
  17475. }
  17476. var tokens = {
  17477. color: {},
  17478. darkColor: {},
  17479. size: {}
  17480. };
  17481. var color$1 = tokens.color = {
  17482. theme: ['#5070dd', '#b6d634', '#505372', '#ff994d', '#0ca8df', '#ffd10a', '#fb628b', '#785db0', '#3fbe95'],
  17483. neutral00: '#fff',
  17484. neutral05: '#f4f7fd',
  17485. neutral10: '#e8ebf0',
  17486. neutral15: '#dbdee4',
  17487. neutral20: '#cfd2d7',
  17488. neutral25: '#c3c5cb',
  17489. neutral30: '#b7b9be',
  17490. neutral35: '#aaacb2',
  17491. neutral40: '#9ea0a5',
  17492. neutral45: '#929399',
  17493. neutral50: '#86878c',
  17494. neutral55: '#797b7f',
  17495. neutral60: '#6d6e73',
  17496. neutral65: '#616266',
  17497. neutral70: '#54555a',
  17498. neutral75: '#48494d',
  17499. neutral80: '#3c3c41',
  17500. neutral85: '#303034',
  17501. neutral90: '#232328',
  17502. neutral95: '#17171b',
  17503. neutral99: '#000',
  17504. accent05: '#eff1f9',
  17505. accent10: '#e0e4f2',
  17506. accent15: '#d0d6ec',
  17507. accent20: '#c0c9e6',
  17508. accent25: '#b1bbdf',
  17509. accent30: '#a1aed9',
  17510. accent35: '#91a0d3',
  17511. accent40: '#8292cc',
  17512. accent45: '#7285c6',
  17513. accent50: '#6578ba',
  17514. accent55: '#5c6da9',
  17515. accent60: '#536298',
  17516. accent65: '#4a5787',
  17517. accent70: '#404c76',
  17518. accent75: '#374165',
  17519. accent80: '#2e3654',
  17520. accent85: '#252b43',
  17521. accent90: '#1b2032',
  17522. accent95: '#121521',
  17523. transparent: 'rgba(0,0,0,0)',
  17524. highlight: 'rgba(255,231,130,0.8)'
  17525. };
  17526. extend(color$1, {
  17527. primary: color$1.neutral80,
  17528. secondary: color$1.neutral70,
  17529. tertiary: color$1.neutral60,
  17530. quaternary: color$1.neutral50,
  17531. disabled: color$1.neutral20,
  17532. border: color$1.neutral30,
  17533. borderTint: color$1.neutral20,
  17534. borderShade: color$1.neutral40,
  17535. background: color$1.neutral05,
  17536. backgroundTint: 'rgba(234,237,245,0.5)',
  17537. backgroundTransparent: 'rgba(255,255,255,0)',
  17538. backgroundShade: color$1.neutral10,
  17539. shadow: 'rgba(0,0,0,0.2)',
  17540. shadowTint: 'rgba(129,130,136,0.2)',
  17541. axisLine: color$1.neutral70,
  17542. axisLineTint: color$1.neutral40,
  17543. axisTick: color$1.neutral70,
  17544. axisTickMinor: color$1.neutral60,
  17545. axisLabel: color$1.neutral70,
  17546. axisSplitLine: color$1.neutral15,
  17547. axisMinorSplitLine: color$1.neutral05
  17548. });
  17549. for (var key in color$1) {
  17550. if (color$1.hasOwnProperty(key)) {
  17551. var hex = color$1[key];
  17552. if (key === 'theme') {
  17553. // Don't modify theme colors.
  17554. tokens.darkColor.theme = color$1.theme.slice();
  17555. } else if (key === 'highlight') {
  17556. tokens.darkColor.highlight = 'rgba(255,231,130,0.4)';
  17557. } else if (key.indexOf('accent') === 0) {
  17558. // Desaturate and lighten accent colors.
  17559. tokens.darkColor[key] = modifyHSL(hex, null, function (s) {
  17560. return s * 0.5;
  17561. }, function (l) {
  17562. return Math.min(1, 1.3 - l);
  17563. });
  17564. } else {
  17565. tokens.darkColor[key] = modifyHSL(hex, null, function (s) {
  17566. return s * 0.9;
  17567. }, function (l) {
  17568. return 1 - Math.pow(l, 1.5);
  17569. });
  17570. }
  17571. }
  17572. }
  17573. tokens.size = {
  17574. xxs: 2,
  17575. xs: 5,
  17576. s: 10,
  17577. m: 15,
  17578. l: 20,
  17579. xl: 30,
  17580. xxl: 40,
  17581. xxxl: 50
  17582. };
  17583. var platform = '';
  17584. // Navigator not exists in node
  17585. if (typeof navigator !== 'undefined') {
  17586. /* global navigator */
  17587. platform = navigator.platform || '';
  17588. }
  17589. var decalColor = 'rgba(0, 0, 0, 0.2)';
  17590. var themeColor = tokens.color.theme[0];
  17591. var lightThemeColor = modifyHSL(themeColor, null, null, 0.9);
  17592. var globalDefault = {
  17593. darkMode: 'auto',
  17594. // backgroundColor: 'rgba(0,0,0,0)',
  17595. colorBy: 'series',
  17596. color: tokens.color.theme,
  17597. gradientColor: [lightThemeColor, themeColor],
  17598. aria: {
  17599. decal: {
  17600. decals: [{
  17601. color: decalColor,
  17602. dashArrayX: [1, 0],
  17603. dashArrayY: [2, 5],
  17604. symbolSize: 1,
  17605. rotation: Math.PI / 6
  17606. }, {
  17607. color: decalColor,
  17608. symbol: 'circle',
  17609. dashArrayX: [[8, 8], [0, 8, 8, 0]],
  17610. dashArrayY: [6, 0],
  17611. symbolSize: 0.8
  17612. }, {
  17613. color: decalColor,
  17614. dashArrayX: [1, 0],
  17615. dashArrayY: [4, 3],
  17616. rotation: -Math.PI / 4
  17617. }, {
  17618. color: decalColor,
  17619. dashArrayX: [[6, 6], [0, 6, 6, 0]],
  17620. dashArrayY: [6, 0]
  17621. }, {
  17622. color: decalColor,
  17623. dashArrayX: [[1, 0], [1, 6]],
  17624. dashArrayY: [1, 0, 6, 0],
  17625. rotation: Math.PI / 4
  17626. }, {
  17627. color: decalColor,
  17628. symbol: 'triangle',
  17629. dashArrayX: [[9, 9], [0, 9, 9, 0]],
  17630. dashArrayY: [7, 2],
  17631. symbolSize: 0.75
  17632. }]
  17633. }
  17634. },
  17635. // If xAxis and yAxis declared, grid is created by default.
  17636. // grid: {},
  17637. textStyle: {
  17638. // color: '#000',
  17639. // decoration: 'none',
  17640. // PENDING
  17641. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  17642. // fontFamily: 'Arial, Verdana, sans-serif',
  17643. fontSize: 12,
  17644. fontStyle: 'normal',
  17645. fontWeight: 'normal'
  17646. },
  17647. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  17648. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  17649. // Default is source-over
  17650. blendMode: null,
  17651. stateAnimation: {
  17652. duration: 300,
  17653. easing: 'cubicOut'
  17654. },
  17655. animation: 'auto',
  17656. animationDuration: 1000,
  17657. animationDurationUpdate: 500,
  17658. animationEasing: 'cubicInOut',
  17659. animationEasingUpdate: 'cubicInOut',
  17660. animationThreshold: 2000,
  17661. // Configuration for progressive/incremental rendering
  17662. progressiveThreshold: 3000,
  17663. progressive: 400,
  17664. // Threshold of if use single hover layer to optimize.
  17665. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  17666. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  17667. // which is unexpected.
  17668. // see example <echarts/test/heatmap-large.html>.
  17669. hoverLayerThreshold: 3000,
  17670. // See: module:echarts/scale/Time
  17671. useUTC: false
  17672. };
  17673. var VISUAL_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'itemGroupId', 'itemChildGroupId', 'seriesName']);
  17674. var SOURCE_FORMAT_ORIGINAL = 'original';
  17675. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  17676. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  17677. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  17678. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  17679. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  17680. var SERIES_LAYOUT_BY_COLUMN = 'column';
  17681. var SERIES_LAYOUT_BY_ROW = 'row';
  17682. // The result of `guessOrdinal`.
  17683. var BE_ORDINAL = {
  17684. Must: 1,
  17685. Might: 2,
  17686. Not: 3 // Other cases
  17687. };
  17688. var innerGlobalModel = makeInner();
  17689. /**
  17690. * MUST be called before mergeOption of all series.
  17691. */
  17692. function resetSourceDefaulter(ecModel) {
  17693. // `datasetMap` is used to make default encode.
  17694. innerGlobalModel(ecModel).datasetMap = createHashMap();
  17695. }
  17696. /**
  17697. * [The strategy of the arrengment of data dimensions for dataset]:
  17698. * "value way": all axes are non-category axes. So series one by one take
  17699. * several (the number is coordSysDims.length) dimensions from dataset.
  17700. * The result of data arrengment of data dimensions like:
  17701. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  17702. * "category way": at least one axis is category axis. So the the first data
  17703. * dimension is always mapped to the first category axis and shared by
  17704. * all of the series. The other data dimensions are taken by series like
  17705. * "value way" does.
  17706. * The result of data arrengment of data dimensions like:
  17707. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  17708. *
  17709. * @return encode Never be `null/undefined`.
  17710. */
  17711. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  17712. var encode = {};
  17713. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel);
  17714. // Currently only make default when using dataset, util more reqirements occur.
  17715. if (!datasetModel || !coordDimensions) {
  17716. return encode;
  17717. }
  17718. var encodeItemName = [];
  17719. var encodeSeriesName = [];
  17720. var ecModel = seriesModel.ecModel;
  17721. var datasetMap = innerGlobalModel(ecModel).datasetMap;
  17722. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  17723. var baseCategoryDimIndex;
  17724. var categoryWayValueDimStart;
  17725. coordDimensions = coordDimensions.slice();
  17726. each(coordDimensions, function (coordDimInfoLoose, coordDimIdx) {
  17727. var coordDimInfo = isObject(coordDimInfoLoose) ? coordDimInfoLoose : coordDimensions[coordDimIdx] = {
  17728. name: coordDimInfoLoose
  17729. };
  17730. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  17731. baseCategoryDimIndex = coordDimIdx;
  17732. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimInfo);
  17733. }
  17734. encode[coordDimInfo.name] = [];
  17735. });
  17736. var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
  17737. categoryWayDim: categoryWayValueDimStart,
  17738. valueWayDim: 0
  17739. });
  17740. // TODO
  17741. // Auto detect first time axis and do arrangement.
  17742. each(coordDimensions, function (coordDimInfo, coordDimIdx) {
  17743. var coordDimName = coordDimInfo.name;
  17744. var count = getDataDimCountOnCoordDim(coordDimInfo);
  17745. // In value way.
  17746. if (baseCategoryDimIndex == null) {
  17747. var start = datasetRecord.valueWayDim;
  17748. pushDim(encode[coordDimName], start, count);
  17749. pushDim(encodeSeriesName, start, count);
  17750. datasetRecord.valueWayDim += count;
  17751. // ??? TODO give a better default series name rule?
  17752. // especially when encode x y specified.
  17753. // consider: when multiple series share one dimension
  17754. // category axis, series name should better use
  17755. // the other dimension name. On the other hand, use
  17756. // both dimensions name.
  17757. }
  17758. // In category way, the first category axis.
  17759. else if (baseCategoryDimIndex === coordDimIdx) {
  17760. pushDim(encode[coordDimName], 0, count);
  17761. pushDim(encodeItemName, 0, count);
  17762. }
  17763. // In category way, the other axis.
  17764. else {
  17765. var start = datasetRecord.categoryWayDim;
  17766. pushDim(encode[coordDimName], start, count);
  17767. pushDim(encodeSeriesName, start, count);
  17768. datasetRecord.categoryWayDim += count;
  17769. }
  17770. });
  17771. function pushDim(dimIdxArr, idxFrom, idxCount) {
  17772. for (var i = 0; i < idxCount; i++) {
  17773. dimIdxArr.push(idxFrom + i);
  17774. }
  17775. }
  17776. function getDataDimCountOnCoordDim(coordDimInfo) {
  17777. var dimsDef = coordDimInfo.dimsDef;
  17778. return dimsDef ? dimsDef.length : 1;
  17779. }
  17780. encodeItemName.length && (encode.itemName = encodeItemName);
  17781. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  17782. return encode;
  17783. }
  17784. /**
  17785. * Work for data like [{name: ..., value: ...}, ...].
  17786. *
  17787. * @return encode Never be `null/undefined`.
  17788. */
  17789. function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
  17790. var encode = {};
  17791. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel);
  17792. // Currently only make default when using dataset, util more reqirements occur.
  17793. if (!datasetModel) {
  17794. return encode;
  17795. }
  17796. var sourceFormat = source.sourceFormat;
  17797. var dimensionsDefine = source.dimensionsDefine;
  17798. var potentialNameDimIndex;
  17799. if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17800. each(dimensionsDefine, function (dim, idx) {
  17801. if ((isObject(dim) ? dim.name : dim) === 'name') {
  17802. potentialNameDimIndex = idx;
  17803. }
  17804. });
  17805. }
  17806. var idxResult = function () {
  17807. var idxRes0 = {};
  17808. var idxRes1 = {};
  17809. var guessRecords = [];
  17810. // 5 is an experience value.
  17811. for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
  17812. var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i);
  17813. guessRecords.push(guessResult);
  17814. var isPureNumber = guessResult === BE_ORDINAL.Not;
  17815. // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
  17816. // and then find a name dim with the priority:
  17817. // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
  17818. if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
  17819. idxRes0.v = i;
  17820. }
  17821. if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) {
  17822. idxRes0.n = i;
  17823. }
  17824. if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
  17825. return idxRes0;
  17826. }
  17827. // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
  17828. // find the first BE_ORDINAL.Might as the value dim,
  17829. // and then find a name dim with the priority:
  17830. // "other dim" > "the value dim itself".
  17831. // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
  17832. // treated as number.
  17833. if (!isPureNumber) {
  17834. if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
  17835. idxRes1.v = i;
  17836. }
  17837. if (idxRes1.n == null || idxRes1.n === idxRes1.v) {
  17838. idxRes1.n = i;
  17839. }
  17840. }
  17841. }
  17842. function fulfilled(idxResult) {
  17843. return idxResult.v != null && idxResult.n != null;
  17844. }
  17845. return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
  17846. }();
  17847. if (idxResult) {
  17848. encode.value = [idxResult.v];
  17849. // `potentialNameDimIndex` has highest priority.
  17850. var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n;
  17851. // By default, label uses itemName in charts.
  17852. // So we don't set encodeLabel here.
  17853. encode.itemName = [nameDimIndex];
  17854. encode.seriesName = [nameDimIndex];
  17855. }
  17856. return encode;
  17857. }
  17858. /**
  17859. * @return If return null/undefined, indicate that should not use datasetModel.
  17860. */
  17861. function querySeriesUpstreamDatasetModel(seriesModel) {
  17862. // Caution: consider the scenario:
  17863. // A dataset is declared and a series is not expected to use the dataset,
  17864. // and at the beginning `setOption({series: { noData })` (just prepare other
  17865. // option but no data), then `setOption({series: {data: [...]}); In this case,
  17866. // the user should set an empty array to avoid that dataset is used by default.
  17867. var thisData = seriesModel.get('data', true);
  17868. if (!thisData) {
  17869. return queryReferringComponents(seriesModel.ecModel, 'dataset', {
  17870. index: seriesModel.get('datasetIndex', true),
  17871. id: seriesModel.get('datasetId', true)
  17872. }, SINGLE_REFERRING).models[0];
  17873. }
  17874. }
  17875. /**
  17876. * @return Always return an array event empty.
  17877. */
  17878. function queryDatasetUpstreamDatasetModels(datasetModel) {
  17879. // Only these attributes declared, we by default reference to `datasetIndex: 0`.
  17880. // Otherwise, no reference.
  17881. if (!datasetModel.get('transform', true) && !datasetModel.get('fromTransformResult', true)) {
  17882. return [];
  17883. }
  17884. return queryReferringComponents(datasetModel.ecModel, 'dataset', {
  17885. index: datasetModel.get('fromDatasetIndex', true),
  17886. id: datasetModel.get('fromDatasetId', true)
  17887. }, SINGLE_REFERRING).models;
  17888. }
  17889. /**
  17890. * The rule should not be complex, otherwise user might not
  17891. * be able to known where the data is wrong.
  17892. * The code is ugly, but how to make it neat?
  17893. */
  17894. function guessOrdinal(source, dimIndex) {
  17895. return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
  17896. }
  17897. // dimIndex may be overflow source data.
  17898. // return {BE_ORDINAL}
  17899. function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
  17900. var result;
  17901. // Experience value.
  17902. var maxLoop = 5;
  17903. if (isTypedArray(data)) {
  17904. return BE_ORDINAL.Not;
  17905. }
  17906. // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  17907. // always exists in source.
  17908. var dimName;
  17909. var dimType;
  17910. if (dimensionsDefine) {
  17911. var dimDefItem = dimensionsDefine[dimIndex];
  17912. if (isObject(dimDefItem)) {
  17913. dimName = dimDefItem.name;
  17914. dimType = dimDefItem.type;
  17915. } else if (isString(dimDefItem)) {
  17916. dimName = dimDefItem;
  17917. }
  17918. }
  17919. if (dimType != null) {
  17920. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  17921. }
  17922. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17923. var dataArrayRows = data;
  17924. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  17925. var sample = dataArrayRows[dimIndex];
  17926. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  17927. if ((result = detectValue(sample[startIndex + i])) != null) {
  17928. return result;
  17929. }
  17930. }
  17931. } else {
  17932. for (var i = 0; i < dataArrayRows.length && i < maxLoop; i++) {
  17933. var row = dataArrayRows[startIndex + i];
  17934. if (row && (result = detectValue(row[dimIndex])) != null) {
  17935. return result;
  17936. }
  17937. }
  17938. }
  17939. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17940. var dataObjectRows = data;
  17941. if (!dimName) {
  17942. return BE_ORDINAL.Not;
  17943. }
  17944. for (var i = 0; i < dataObjectRows.length && i < maxLoop; i++) {
  17945. var item = dataObjectRows[i];
  17946. if (item && (result = detectValue(item[dimName])) != null) {
  17947. return result;
  17948. }
  17949. }
  17950. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17951. var dataKeyedColumns = data;
  17952. if (!dimName) {
  17953. return BE_ORDINAL.Not;
  17954. }
  17955. var sample = dataKeyedColumns[dimName];
  17956. if (!sample || isTypedArray(sample)) {
  17957. return BE_ORDINAL.Not;
  17958. }
  17959. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  17960. if ((result = detectValue(sample[i])) != null) {
  17961. return result;
  17962. }
  17963. }
  17964. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17965. var dataOriginal = data;
  17966. for (var i = 0; i < dataOriginal.length && i < maxLoop; i++) {
  17967. var item = dataOriginal[i];
  17968. var val = getDataItemValue(item);
  17969. if (!isArray(val)) {
  17970. return BE_ORDINAL.Not;
  17971. }
  17972. if ((result = detectValue(val[dimIndex])) != null) {
  17973. return result;
  17974. }
  17975. }
  17976. }
  17977. function detectValue(val) {
  17978. var beStr = isString(val);
  17979. // Consider usage convenience, '1', '2' will be treated as "number".
  17980. // `Number('')` (or any whitespace) is `0`.
  17981. if (val != null && Number.isFinite(Number(val)) && val !== '') {
  17982. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  17983. } else if (beStr && val !== '-') {
  17984. return BE_ORDINAL.Must;
  17985. }
  17986. }
  17987. return BE_ORDINAL.Not;
  17988. }
  17989. var internalOptionCreatorMap = createHashMap();
  17990. function concatInternalOptions(ecModel, mainType, newCmptOptionList) {
  17991. var internalOptionCreator = internalOptionCreatorMap.get(mainType);
  17992. if (!internalOptionCreator) {
  17993. return newCmptOptionList;
  17994. }
  17995. var internalOptions = internalOptionCreator(ecModel);
  17996. if (!internalOptions) {
  17997. return newCmptOptionList;
  17998. }
  17999. if ("development" !== 'production') {
  18000. for (var i = 0; i < internalOptions.length; i++) {
  18001. assert(isComponentIdInternal(internalOptions[i]));
  18002. }
  18003. }
  18004. return newCmptOptionList.concat(internalOptions);
  18005. }
  18006. var innerColor = makeInner();
  18007. var innerDecal = makeInner();
  18008. var PaletteMixin = /** @class */function () {
  18009. function PaletteMixin() {}
  18010. PaletteMixin.prototype.getColorFromPalette = function (name, scope, requestNum) {
  18011. var defaultPalette = normalizeToArray(this.get('color', true));
  18012. var layeredPalette = this.get('colorLayer', true);
  18013. return getFromPalette(this, innerColor, defaultPalette, layeredPalette, name, scope, requestNum);
  18014. };
  18015. PaletteMixin.prototype.clearColorPalette = function () {
  18016. clearPalette(this, innerColor);
  18017. };
  18018. return PaletteMixin;
  18019. }();
  18020. function getDecalFromPalette(ecModel, name, scope, requestNum) {
  18021. var defaultDecals = normalizeToArray(ecModel.get(['aria', 'decal', 'decals']));
  18022. return getFromPalette(ecModel, innerDecal, defaultDecals, null, name, scope, requestNum);
  18023. }
  18024. function getNearestPalette(palettes, requestColorNum) {
  18025. var paletteNum = palettes.length;
  18026. // TODO palettes must be in order
  18027. for (var i = 0; i < paletteNum; i++) {
  18028. if (palettes[i].length > requestColorNum) {
  18029. return palettes[i];
  18030. }
  18031. }
  18032. return palettes[paletteNum - 1];
  18033. }
  18034. /**
  18035. * @param name MUST NOT be null/undefined. Otherwise call this function
  18036. * twise with the same parameters will get different result.
  18037. * @param scope default this.
  18038. * @return Can be null/undefined
  18039. */
  18040. function getFromPalette(that, inner, defaultPalette, layeredPalette, name, scope, requestNum) {
  18041. scope = scope || that;
  18042. var scopeFields = inner(scope);
  18043. var paletteIdx = scopeFields.paletteIdx || 0;
  18044. var paletteNameMap = scopeFields.paletteNameMap = scopeFields.paletteNameMap || {};
  18045. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  18046. if (paletteNameMap.hasOwnProperty(name)) {
  18047. return paletteNameMap[name];
  18048. }
  18049. var palette = requestNum == null || !layeredPalette ? defaultPalette : getNearestPalette(layeredPalette, requestNum);
  18050. // In case can't find in layered color palette.
  18051. palette = palette || defaultPalette;
  18052. if (!palette || !palette.length) {
  18053. return;
  18054. }
  18055. var pickedPaletteItem = palette[paletteIdx];
  18056. if (name) {
  18057. paletteNameMap[name] = pickedPaletteItem;
  18058. }
  18059. scopeFields.paletteIdx = (paletteIdx + 1) % palette.length;
  18060. return pickedPaletteItem;
  18061. }
  18062. function clearPalette(that, inner) {
  18063. inner(that).paletteIdx = 0;
  18064. inner(that).paletteNameMap = {};
  18065. }
  18066. // -----------------------
  18067. // Internal method names:
  18068. // -----------------------
  18069. var reCreateSeriesIndices;
  18070. var assertSeriesInitialized;
  18071. var initBase;
  18072. var OPTION_INNER_KEY = '\0_ec_inner';
  18073. var OPTION_INNER_VALUE = 1;
  18074. var BUITIN_COMPONENTS_MAP = {
  18075. grid: 'GridComponent',
  18076. polar: 'PolarComponent',
  18077. geo: 'GeoComponent',
  18078. singleAxis: 'SingleAxisComponent',
  18079. parallel: 'ParallelComponent',
  18080. calendar: 'CalendarComponent',
  18081. matrix: 'MatrixComponent',
  18082. graphic: 'GraphicComponent',
  18083. toolbox: 'ToolboxComponent',
  18084. tooltip: 'TooltipComponent',
  18085. axisPointer: 'AxisPointerComponent',
  18086. brush: 'BrushComponent',
  18087. title: 'TitleComponent',
  18088. timeline: 'TimelineComponent',
  18089. markPoint: 'MarkPointComponent',
  18090. markLine: 'MarkLineComponent',
  18091. markArea: 'MarkAreaComponent',
  18092. legend: 'LegendComponent',
  18093. dataZoom: 'DataZoomComponent',
  18094. visualMap: 'VisualMapComponent',
  18095. // aria: 'AriaComponent',
  18096. // dataset: 'DatasetComponent',
  18097. // Dependencies
  18098. xAxis: 'GridComponent',
  18099. yAxis: 'GridComponent',
  18100. angleAxis: 'PolarComponent',
  18101. radiusAxis: 'PolarComponent'
  18102. };
  18103. var BUILTIN_CHARTS_MAP = {
  18104. line: 'LineChart',
  18105. bar: 'BarChart',
  18106. pie: 'PieChart',
  18107. scatter: 'ScatterChart',
  18108. radar: 'RadarChart',
  18109. map: 'MapChart',
  18110. tree: 'TreeChart',
  18111. treemap: 'TreemapChart',
  18112. graph: 'GraphChart',
  18113. chord: 'ChordChart',
  18114. gauge: 'GaugeChart',
  18115. funnel: 'FunnelChart',
  18116. parallel: 'ParallelChart',
  18117. sankey: 'SankeyChart',
  18118. boxplot: 'BoxplotChart',
  18119. candlestick: 'CandlestickChart',
  18120. effectScatter: 'EffectScatterChart',
  18121. lines: 'LinesChart',
  18122. heatmap: 'HeatmapChart',
  18123. pictorialBar: 'PictorialBarChart',
  18124. themeRiver: 'ThemeRiverChart',
  18125. sunburst: 'SunburstChart',
  18126. custom: 'CustomChart'
  18127. };
  18128. var componetsMissingLogPrinted = {};
  18129. function checkMissingComponents(option) {
  18130. each(option, function (componentOption, mainType) {
  18131. if (!ComponentModel.hasClass(mainType)) {
  18132. var componentImportName = BUITIN_COMPONENTS_MAP[mainType];
  18133. if (componentImportName && !componetsMissingLogPrinted[componentImportName]) {
  18134. error("Component " + mainType + " is used but not imported.\nimport { " + componentImportName + " } from 'echarts/components';\necharts.use([" + componentImportName + "]);");
  18135. componetsMissingLogPrinted[componentImportName] = true;
  18136. }
  18137. }
  18138. });
  18139. }
  18140. var GlobalModel = /** @class */function (_super) {
  18141. __extends(GlobalModel, _super);
  18142. function GlobalModel() {
  18143. return _super !== null && _super.apply(this, arguments) || this;
  18144. }
  18145. GlobalModel.prototype.init = function (option, parentModel, ecModel, theme, locale, optionManager) {
  18146. theme = theme || {};
  18147. this.option = null; // Mark as not initialized.
  18148. this._theme = new Model(theme);
  18149. this._locale = new Model(locale);
  18150. this._optionManager = optionManager;
  18151. };
  18152. GlobalModel.prototype.setOption = function (option, opts, optionPreprocessorFuncs) {
  18153. if ("development" !== 'production') {
  18154. assert(option != null, 'option is null/undefined');
  18155. assert(option[OPTION_INNER_KEY] !== OPTION_INNER_VALUE, 'please use chart.getOption()');
  18156. }
  18157. var innerOpt = normalizeSetOptionInput(opts);
  18158. this._optionManager.setOption(option, optionPreprocessorFuncs, innerOpt);
  18159. this._resetOption(null, innerOpt);
  18160. };
  18161. /**
  18162. * @param type null/undefined: reset all.
  18163. * 'recreate': force recreate all.
  18164. * 'timeline': only reset timeline option
  18165. * 'media': only reset media query option
  18166. * @return Whether option changed.
  18167. */
  18168. GlobalModel.prototype.resetOption = function (type, opt) {
  18169. return this._resetOption(type, normalizeSetOptionInput(opt));
  18170. };
  18171. GlobalModel.prototype._resetOption = function (type, opt) {
  18172. var optionChanged = false;
  18173. var optionManager = this._optionManager;
  18174. if (!type || type === 'recreate') {
  18175. var baseOption = optionManager.mountOption(type === 'recreate');
  18176. if ("development" !== 'production') {
  18177. checkMissingComponents(baseOption);
  18178. }
  18179. if (!this.option || type === 'recreate') {
  18180. initBase(this, baseOption);
  18181. } else {
  18182. this.restoreData();
  18183. this._mergeOption(baseOption, opt);
  18184. }
  18185. optionChanged = true;
  18186. }
  18187. if (type === 'timeline' || type === 'media') {
  18188. this.restoreData();
  18189. }
  18190. // By design, if `setOption(option2)` at the second time, and `option2` is a `ECUnitOption`,
  18191. // it should better not have the same props with `MediaUnit['option']`.
  18192. // Because either `option2` or `MediaUnit['option']` will be always merged to "current option"
  18193. // rather than original "baseOption". If they both override a prop, the result might be
  18194. // unexpected when media state changed after `setOption` called.
  18195. // If we really need to modify a props in each `MediaUnit['option']`, use the full version
  18196. // (`{baseOption, media}`) in `setOption`.
  18197. // For `timeline`, the case is the same.
  18198. if (!type || type === 'recreate' || type === 'timeline') {
  18199. var timelineOption = optionManager.getTimelineOption(this);
  18200. if (timelineOption) {
  18201. optionChanged = true;
  18202. this._mergeOption(timelineOption, opt);
  18203. }
  18204. }
  18205. if (!type || type === 'recreate' || type === 'media') {
  18206. var mediaOptions = optionManager.getMediaOption(this);
  18207. if (mediaOptions.length) {
  18208. each(mediaOptions, function (mediaOption) {
  18209. optionChanged = true;
  18210. this._mergeOption(mediaOption, opt);
  18211. }, this);
  18212. }
  18213. }
  18214. return optionChanged;
  18215. };
  18216. GlobalModel.prototype.mergeOption = function (option) {
  18217. this._mergeOption(option, null);
  18218. };
  18219. GlobalModel.prototype._mergeOption = function (newOption, opt) {
  18220. var option = this.option;
  18221. var componentsMap = this._componentsMap;
  18222. var componentsCount = this._componentsCount;
  18223. var newCmptTypes = [];
  18224. var newCmptTypeMap = createHashMap();
  18225. var replaceMergeMainTypeMap = opt && opt.replaceMergeMainTypeMap;
  18226. resetSourceDefaulter(this);
  18227. // If no component class, merge directly.
  18228. // For example: color, animaiton options, etc.
  18229. each(newOption, function (componentOption, mainType) {
  18230. if (componentOption == null) {
  18231. return;
  18232. }
  18233. if (!ComponentModel.hasClass(mainType)) {
  18234. // globalSettingTask.dirty();
  18235. option[mainType] = option[mainType] == null ? clone(componentOption) : merge(option[mainType], componentOption, true);
  18236. } else if (mainType) {
  18237. newCmptTypes.push(mainType);
  18238. newCmptTypeMap.set(mainType, true);
  18239. }
  18240. });
  18241. if (replaceMergeMainTypeMap) {
  18242. // If there is a mainType `xxx` in `replaceMerge` but not declared in option,
  18243. // we trade it as it is declared in option as `{xxx: []}`. Because:
  18244. // (1) for normal merge, `{xxx: null/undefined}` are the same meaning as `{xxx: []}`.
  18245. // (2) some preprocessor may convert some of `{xxx: null/undefined}` to `{xxx: []}`.
  18246. replaceMergeMainTypeMap.each(function (val, mainTypeInReplaceMerge) {
  18247. if (ComponentModel.hasClass(mainTypeInReplaceMerge) && !newCmptTypeMap.get(mainTypeInReplaceMerge)) {
  18248. newCmptTypes.push(mainTypeInReplaceMerge);
  18249. newCmptTypeMap.set(mainTypeInReplaceMerge, true);
  18250. }
  18251. });
  18252. }
  18253. ComponentModel.topologicalTravel(newCmptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this);
  18254. function visitComponent(mainType) {
  18255. var newCmptOptionList = concatInternalOptions(this, mainType, normalizeToArray(newOption[mainType]));
  18256. var oldCmptList = componentsMap.get(mainType);
  18257. var mergeMode =
  18258. // `!oldCmptList` means init. See the comment in `mappingToExists`
  18259. !oldCmptList ? 'replaceAll' : replaceMergeMainTypeMap && replaceMergeMainTypeMap.get(mainType) ? 'replaceMerge' : 'normalMerge';
  18260. var mappingResult = mappingToExists(oldCmptList, newCmptOptionList, mergeMode);
  18261. // Set mainType and complete subType.
  18262. setComponentTypeToKeyInfo(mappingResult, mainType, ComponentModel);
  18263. // Empty it before the travel, in order to prevent `this._componentsMap`
  18264. // from being used in the `init`/`mergeOption`/`optionUpdated` of some
  18265. // components, which is probably incorrect logic.
  18266. option[mainType] = null;
  18267. componentsMap.set(mainType, null);
  18268. componentsCount.set(mainType, 0);
  18269. var optionsByMainType = [];
  18270. var cmptsByMainType = [];
  18271. var cmptsCountByMainType = 0;
  18272. var tooltipExists;
  18273. var tooltipWarningLogged;
  18274. each(mappingResult, function (resultItem, index) {
  18275. var componentModel = resultItem.existing;
  18276. var newCmptOption = resultItem.newOption;
  18277. if (!newCmptOption) {
  18278. if (componentModel) {
  18279. // Consider where is no new option and should be merged using {},
  18280. // see removeEdgeAndAdd in topologicalTravel and
  18281. // ComponentModel.getAllClassMainTypes.
  18282. componentModel.mergeOption({}, this);
  18283. componentModel.optionUpdated({}, false);
  18284. }
  18285. // If no both `resultItem.exist` and `resultItem.option`,
  18286. // either it is in `replaceMerge` and not matched by any id,
  18287. // or it has been removed in previous `replaceMerge` and left a "hole" in this component index.
  18288. } else {
  18289. var isSeriesType = mainType === 'series';
  18290. var ComponentModelClass = ComponentModel.getClass(mainType, resultItem.keyInfo.subType, !isSeriesType // Give a more detailed warn later if series don't exists
  18291. );
  18292. if (!ComponentModelClass) {
  18293. if ("development" !== 'production') {
  18294. var subType = resultItem.keyInfo.subType;
  18295. var seriesImportName = BUILTIN_CHARTS_MAP[subType];
  18296. if (!componetsMissingLogPrinted[subType]) {
  18297. componetsMissingLogPrinted[subType] = true;
  18298. if (seriesImportName) {
  18299. error("Series " + subType + " is used but not imported.\nimport { " + seriesImportName + " } from 'echarts/charts';\necharts.use([" + seriesImportName + "]);");
  18300. } else {
  18301. error("Unknown series " + subType);
  18302. }
  18303. }
  18304. }
  18305. return;
  18306. }
  18307. // TODO Before multiple tooltips get supported, we do this check to avoid unexpected exception.
  18308. if (mainType === 'tooltip') {
  18309. if (tooltipExists) {
  18310. if ("development" !== 'production') {
  18311. if (!tooltipWarningLogged) {
  18312. warn('Currently only one tooltip component is allowed.');
  18313. tooltipWarningLogged = true;
  18314. }
  18315. }
  18316. return;
  18317. }
  18318. tooltipExists = true;
  18319. }
  18320. if (componentModel && componentModel.constructor === ComponentModelClass) {
  18321. componentModel.name = resultItem.keyInfo.name;
  18322. // componentModel.settingTask && componentModel.settingTask.dirty();
  18323. componentModel.mergeOption(newCmptOption, this);
  18324. componentModel.optionUpdated(newCmptOption, false);
  18325. } else {
  18326. // PENDING Global as parent ?
  18327. var extraOpt = extend({
  18328. componentIndex: index
  18329. }, resultItem.keyInfo);
  18330. componentModel = new ComponentModelClass(newCmptOption, this, this, extraOpt);
  18331. // Assign `keyInfo`
  18332. extend(componentModel, extraOpt);
  18333. if (resultItem.brandNew) {
  18334. componentModel.__requireNewView = true;
  18335. }
  18336. componentModel.init(newCmptOption, this, this);
  18337. // Call optionUpdated after init.
  18338. // newCmptOption has been used as componentModel.option
  18339. // and may be merged with theme and default, so pass null
  18340. // to avoid confusion.
  18341. componentModel.optionUpdated(null, true);
  18342. }
  18343. }
  18344. if (componentModel) {
  18345. optionsByMainType.push(componentModel.option);
  18346. cmptsByMainType.push(componentModel);
  18347. cmptsCountByMainType++;
  18348. } else {
  18349. // Always do assign to avoid elided item in array.
  18350. optionsByMainType.push(void 0);
  18351. cmptsByMainType.push(void 0);
  18352. }
  18353. }, this);
  18354. option[mainType] = optionsByMainType;
  18355. componentsMap.set(mainType, cmptsByMainType);
  18356. componentsCount.set(mainType, cmptsCountByMainType);
  18357. // Backup series for filtering.
  18358. if (mainType === 'series') {
  18359. reCreateSeriesIndices(this);
  18360. }
  18361. }
  18362. // If no series declared, ensure `_seriesIndices` initialized.
  18363. if (!this._seriesIndices) {
  18364. reCreateSeriesIndices(this);
  18365. }
  18366. };
  18367. /**
  18368. * Get option for output (cloned option and inner info removed)
  18369. */
  18370. GlobalModel.prototype.getOption = function () {
  18371. var option = clone(this.option);
  18372. each(option, function (optInMainType, mainType) {
  18373. if (ComponentModel.hasClass(mainType)) {
  18374. var opts = normalizeToArray(optInMainType);
  18375. // Inner cmpts need to be removed.
  18376. // Inner cmpts might not be at last since ec5.0, but still
  18377. // compatible for users: if inner cmpt at last, splice the returned array.
  18378. var realLen = opts.length;
  18379. var metNonInner = false;
  18380. for (var i = realLen - 1; i >= 0; i--) {
  18381. // Remove options with inner id.
  18382. if (opts[i] && !isComponentIdInternal(opts[i])) {
  18383. metNonInner = true;
  18384. } else {
  18385. opts[i] = null;
  18386. !metNonInner && realLen--;
  18387. }
  18388. }
  18389. opts.length = realLen;
  18390. option[mainType] = opts;
  18391. }
  18392. });
  18393. delete option[OPTION_INNER_KEY];
  18394. return option;
  18395. };
  18396. GlobalModel.prototype.setTheme = function (theme) {
  18397. this._theme = new Model(theme);
  18398. this._resetOption('recreate', null);
  18399. };
  18400. GlobalModel.prototype.getTheme = function () {
  18401. return this._theme;
  18402. };
  18403. GlobalModel.prototype.getLocaleModel = function () {
  18404. return this._locale;
  18405. };
  18406. GlobalModel.prototype.setUpdatePayload = function (payload) {
  18407. this._payload = payload;
  18408. };
  18409. GlobalModel.prototype.getUpdatePayload = function () {
  18410. return this._payload;
  18411. };
  18412. /**
  18413. * @param idx If not specified, return the first one.
  18414. */
  18415. GlobalModel.prototype.getComponent = function (mainType, idx) {
  18416. var list = this._componentsMap.get(mainType);
  18417. if (list) {
  18418. var cmpt = list[idx || 0];
  18419. if (cmpt) {
  18420. return cmpt;
  18421. } else if (idx == null) {
  18422. for (var i = 0; i < list.length; i++) {
  18423. if (list[i]) {
  18424. return list[i];
  18425. }
  18426. }
  18427. }
  18428. }
  18429. };
  18430. /**
  18431. * @return Never be null/undefined.
  18432. */
  18433. GlobalModel.prototype.queryComponents = function (condition) {
  18434. var mainType = condition.mainType;
  18435. if (!mainType) {
  18436. return [];
  18437. }
  18438. var index = condition.index;
  18439. var id = condition.id;
  18440. var name = condition.name;
  18441. var cmpts = this._componentsMap.get(mainType);
  18442. if (!cmpts || !cmpts.length) {
  18443. return [];
  18444. }
  18445. var result;
  18446. if (index != null) {
  18447. result = [];
  18448. each(normalizeToArray(index), function (idx) {
  18449. cmpts[idx] && result.push(cmpts[idx]);
  18450. });
  18451. } else if (id != null) {
  18452. result = queryByIdOrName('id', id, cmpts);
  18453. } else if (name != null) {
  18454. result = queryByIdOrName('name', name, cmpts);
  18455. } else {
  18456. // Return all non-empty components in that mainType
  18457. result = filter(cmpts, function (cmpt) {
  18458. return !!cmpt;
  18459. });
  18460. }
  18461. return filterBySubType(result, condition);
  18462. };
  18463. /**
  18464. * The interface is different from queryComponents,
  18465. * which is convenient for inner usage.
  18466. *
  18467. * @usage
  18468. * let result = findComponents(
  18469. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  18470. * );
  18471. * let result = findComponents(
  18472. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  18473. * );
  18474. * let result = findComponents(
  18475. * {mainType: 'series',
  18476. * filter: function (model, index) {...}}
  18477. * );
  18478. * // result like [component0, componnet1, ...]
  18479. */
  18480. GlobalModel.prototype.findComponents = function (condition) {
  18481. var query = condition.query;
  18482. var mainType = condition.mainType;
  18483. var queryCond = getQueryCond(query);
  18484. var result = queryCond ? this.queryComponents(queryCond)
  18485. // Retrieve all non-empty components.
  18486. : filter(this._componentsMap.get(mainType), function (cmpt) {
  18487. return !!cmpt;
  18488. });
  18489. return doFilter(filterBySubType(result, condition));
  18490. function getQueryCond(q) {
  18491. var indexAttr = mainType + 'Index';
  18492. var idAttr = mainType + 'Id';
  18493. var nameAttr = mainType + 'Name';
  18494. return q && (q[indexAttr] != null || q[idAttr] != null || q[nameAttr] != null) ? {
  18495. mainType: mainType,
  18496. // subType will be filtered finally.
  18497. index: q[indexAttr],
  18498. id: q[idAttr],
  18499. name: q[nameAttr]
  18500. } : null;
  18501. }
  18502. function doFilter(res) {
  18503. return condition.filter ? filter(res, condition.filter) : res;
  18504. }
  18505. };
  18506. GlobalModel.prototype.eachComponent = function (mainType, cb, context) {
  18507. var componentsMap = this._componentsMap;
  18508. if (isFunction(mainType)) {
  18509. var ctxForAll_1 = cb;
  18510. var cbForAll_1 = mainType;
  18511. componentsMap.each(function (cmpts, componentType) {
  18512. for (var i = 0; cmpts && i < cmpts.length; i++) {
  18513. var cmpt = cmpts[i];
  18514. cmpt && cbForAll_1.call(ctxForAll_1, componentType, cmpt, cmpt.componentIndex);
  18515. }
  18516. });
  18517. } else {
  18518. var cmpts = isString(mainType) ? componentsMap.get(mainType) : isObject(mainType) ? this.findComponents(mainType) : null;
  18519. for (var i = 0; cmpts && i < cmpts.length; i++) {
  18520. var cmpt = cmpts[i];
  18521. cmpt && cb.call(context, cmpt, cmpt.componentIndex);
  18522. }
  18523. }
  18524. };
  18525. /**
  18526. * Get series list before filtered by name.
  18527. */
  18528. GlobalModel.prototype.getSeriesByName = function (name) {
  18529. var nameStr = convertOptionIdName(name, null);
  18530. return filter(this._componentsMap.get('series'), function (oneSeries) {
  18531. return !!oneSeries && nameStr != null && oneSeries.name === nameStr;
  18532. });
  18533. };
  18534. /**
  18535. * Get series list before filtered by index.
  18536. */
  18537. GlobalModel.prototype.getSeriesByIndex = function (seriesIndex) {
  18538. return this._componentsMap.get('series')[seriesIndex];
  18539. };
  18540. /**
  18541. * Get series list before filtered by type.
  18542. * FIXME: rename to getRawSeriesByType?
  18543. */
  18544. GlobalModel.prototype.getSeriesByType = function (subType) {
  18545. return filter(this._componentsMap.get('series'), function (oneSeries) {
  18546. return !!oneSeries && oneSeries.subType === subType;
  18547. });
  18548. };
  18549. /**
  18550. * Get all series before filtered.
  18551. */
  18552. GlobalModel.prototype.getSeries = function () {
  18553. return filter(this._componentsMap.get('series'), function (oneSeries) {
  18554. return !!oneSeries;
  18555. });
  18556. };
  18557. /**
  18558. * Count series before filtered.
  18559. */
  18560. GlobalModel.prototype.getSeriesCount = function () {
  18561. return this._componentsCount.get('series');
  18562. };
  18563. /**
  18564. * After filtering, series may be different
  18565. * from raw series.
  18566. */
  18567. GlobalModel.prototype.eachSeries = function (cb, context) {
  18568. assertSeriesInitialized(this);
  18569. each(this._seriesIndices, function (rawSeriesIndex) {
  18570. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18571. cb.call(context, series, rawSeriesIndex);
  18572. }, this);
  18573. };
  18574. /**
  18575. * Iterate raw series before filtered.
  18576. *
  18577. * @param {Function} cb
  18578. * @param {*} context
  18579. */
  18580. GlobalModel.prototype.eachRawSeries = function (cb, context) {
  18581. each(this._componentsMap.get('series'), function (series) {
  18582. series && cb.call(context, series, series.componentIndex);
  18583. });
  18584. };
  18585. /**
  18586. * After filtering, series may be different.
  18587. * from raw series.
  18588. */
  18589. GlobalModel.prototype.eachSeriesByType = function (subType, cb, context) {
  18590. assertSeriesInitialized(this);
  18591. each(this._seriesIndices, function (rawSeriesIndex) {
  18592. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18593. if (series.subType === subType) {
  18594. cb.call(context, series, rawSeriesIndex);
  18595. }
  18596. }, this);
  18597. };
  18598. /**
  18599. * Iterate raw series before filtered of given type.
  18600. */
  18601. GlobalModel.prototype.eachRawSeriesByType = function (subType, cb, context) {
  18602. return each(this.getSeriesByType(subType), cb, context);
  18603. };
  18604. GlobalModel.prototype.isSeriesFiltered = function (seriesModel) {
  18605. assertSeriesInitialized(this);
  18606. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  18607. };
  18608. GlobalModel.prototype.getCurrentSeriesIndices = function () {
  18609. return (this._seriesIndices || []).slice();
  18610. };
  18611. GlobalModel.prototype.filterSeries = function (cb, context) {
  18612. assertSeriesInitialized(this);
  18613. var newSeriesIndices = [];
  18614. each(this._seriesIndices, function (seriesRawIdx) {
  18615. var series = this._componentsMap.get('series')[seriesRawIdx];
  18616. cb.call(context, series, seriesRawIdx) && newSeriesIndices.push(seriesRawIdx);
  18617. }, this);
  18618. this._seriesIndices = newSeriesIndices;
  18619. this._seriesIndicesMap = createHashMap(newSeriesIndices);
  18620. };
  18621. GlobalModel.prototype.restoreData = function (payload) {
  18622. reCreateSeriesIndices(this);
  18623. var componentsMap = this._componentsMap;
  18624. var componentTypes = [];
  18625. componentsMap.each(function (components, componentType) {
  18626. if (ComponentModel.hasClass(componentType)) {
  18627. componentTypes.push(componentType);
  18628. }
  18629. });
  18630. ComponentModel.topologicalTravel(componentTypes, ComponentModel.getAllClassMainTypes(), function (componentType) {
  18631. each(componentsMap.get(componentType), function (component) {
  18632. if (component && (componentType !== 'series' || !isNotTargetSeries(component, payload))) {
  18633. component.restoreData();
  18634. }
  18635. });
  18636. });
  18637. };
  18638. GlobalModel.internalField = function () {
  18639. reCreateSeriesIndices = function (ecModel) {
  18640. var seriesIndices = ecModel._seriesIndices = [];
  18641. each(ecModel._componentsMap.get('series'), function (series) {
  18642. // series may have been removed by `replaceMerge`.
  18643. series && seriesIndices.push(series.componentIndex);
  18644. });
  18645. ecModel._seriesIndicesMap = createHashMap(seriesIndices);
  18646. };
  18647. assertSeriesInitialized = function (ecModel) {
  18648. // Components that use _seriesIndices should depends on series component,
  18649. // which make sure that their initialization is after series.
  18650. if ("development" !== 'production') {
  18651. if (!ecModel._seriesIndices) {
  18652. throw new Error('Option should contains series.');
  18653. }
  18654. }
  18655. };
  18656. initBase = function (ecModel, baseOption) {
  18657. // Using OPTION_INNER_KEY to mark that this option cannot be used outside,
  18658. // i.e. `chart.setOption(chart.getModel().option);` is forbidden.
  18659. ecModel.option = {};
  18660. ecModel.option[OPTION_INNER_KEY] = OPTION_INNER_VALUE;
  18661. // Init with series: [], in case of calling findSeries method
  18662. // before series initialized.
  18663. ecModel._componentsMap = createHashMap({
  18664. series: []
  18665. });
  18666. ecModel._componentsCount = createHashMap();
  18667. // If user spefied `option.aria`, aria will be enable. This detection should be
  18668. // performed before theme and globalDefault merge.
  18669. var airaOption = baseOption.aria;
  18670. if (isObject(airaOption) && airaOption.enabled == null) {
  18671. airaOption.enabled = true;
  18672. }
  18673. mergeTheme(baseOption, ecModel._theme.option);
  18674. // TODO Needs clone when merging to the unexisted property
  18675. merge(baseOption, globalDefault, false);
  18676. ecModel._mergeOption(baseOption, null);
  18677. };
  18678. }();
  18679. return GlobalModel;
  18680. }(Model);
  18681. function isNotTargetSeries(seriesModel, payload) {
  18682. if (payload) {
  18683. var index = payload.seriesIndex;
  18684. var id = payload.seriesId;
  18685. var name_1 = payload.seriesName;
  18686. return index != null && seriesModel.componentIndex !== index || id != null && seriesModel.id !== id || name_1 != null && seriesModel.name !== name_1;
  18687. }
  18688. }
  18689. function mergeTheme(option, theme) {
  18690. // PENDING
  18691. // NOT use `colorLayer` in theme if option has `color`
  18692. var notMergeColorLayer = option.color && !option.colorLayer;
  18693. each(theme, function (themeItem, name) {
  18694. if (name === 'colorLayer' && notMergeColorLayer || name === 'color' && option.color) {
  18695. return;
  18696. }
  18697. // If it is component model mainType, the model handles that merge later.
  18698. // otherwise, merge them here.
  18699. if (!ComponentModel.hasClass(name)) {
  18700. if (typeof themeItem === 'object') {
  18701. option[name] = !option[name] ? clone(themeItem) : merge(option[name], themeItem, false);
  18702. } else {
  18703. if (option[name] == null) {
  18704. option[name] = themeItem;
  18705. }
  18706. }
  18707. }
  18708. });
  18709. }
  18710. function queryByIdOrName(attr, idOrName, cmpts) {
  18711. // Here is a break from echarts4: string and number are
  18712. // treated as equal.
  18713. if (isArray(idOrName)) {
  18714. var keyMap_1 = createHashMap();
  18715. each(idOrName, function (idOrNameItem) {
  18716. if (idOrNameItem != null) {
  18717. var idName = convertOptionIdName(idOrNameItem, null);
  18718. idName != null && keyMap_1.set(idOrNameItem, true);
  18719. }
  18720. });
  18721. return filter(cmpts, function (cmpt) {
  18722. return cmpt && keyMap_1.get(cmpt[attr]);
  18723. });
  18724. } else {
  18725. var idName_1 = convertOptionIdName(idOrName, null);
  18726. return filter(cmpts, function (cmpt) {
  18727. return cmpt && idName_1 != null && cmpt[attr] === idName_1;
  18728. });
  18729. }
  18730. }
  18731. function filterBySubType(components, condition) {
  18732. // Using hasOwnProperty for restrict. Consider
  18733. // subType is undefined in user payload.
  18734. return condition.hasOwnProperty('subType') ? filter(components, function (cmpt) {
  18735. return cmpt && cmpt.subType === condition.subType;
  18736. }) : components;
  18737. }
  18738. function normalizeSetOptionInput(opts) {
  18739. var replaceMergeMainTypeMap = createHashMap();
  18740. opts && each(normalizeToArray(opts.replaceMerge), function (mainType) {
  18741. if ("development" !== 'production') {
  18742. assert(ComponentModel.hasClass(mainType), '"' + mainType + '" is not valid component main type in "replaceMerge"');
  18743. }
  18744. replaceMergeMainTypeMap.set(mainType, true);
  18745. });
  18746. return {
  18747. replaceMergeMainTypeMap: replaceMergeMainTypeMap
  18748. };
  18749. }
  18750. mixin(GlobalModel, PaletteMixin);
  18751. var availableMethods = ['getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isSSR', 'isDisposed', 'on', 'off', 'getDataURL', 'getConnectedDataURL',
  18752. // 'getModel',
  18753. 'getOption',
  18754. // 'getViewOfComponentModel',
  18755. // 'getViewOfSeriesModel',
  18756. 'getId', 'updateLabelLayout'];
  18757. var ExtensionAPI = /** @class */function () {
  18758. function ExtensionAPI(ecInstance) {
  18759. each(availableMethods, function (methodName) {
  18760. this[methodName] = bind(ecInstance[methodName], ecInstance);
  18761. }, this);
  18762. }
  18763. return ExtensionAPI;
  18764. }();
  18765. var QUERY_REG = /^(min|max)?(.+)$/;
  18766. // Key: mainType
  18767. // type FakeComponentsMap = HashMap<(MappingExistingItem & { subType: string })[]>;
  18768. /**
  18769. * TERM EXPLANATIONS:
  18770. * See `ECOption` and `ECUnitOption` in `src/util/types.ts`.
  18771. */
  18772. var OptionManager = /** @class */function () {
  18773. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  18774. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  18775. // rawOption cloned and backuped when timeline changed, which does no
  18776. // good to performance. What's more, that both timeline and setOption
  18777. // method supply 'notMerge' brings complex and some problems.
  18778. // Consider this case:
  18779. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  18780. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  18781. function OptionManager(api) {
  18782. this._timelineOptions = [];
  18783. this._mediaList = [];
  18784. /**
  18785. * -1, means default.
  18786. * empty means no media.
  18787. */
  18788. this._currentMediaIndices = [];
  18789. this._api = api;
  18790. }
  18791. OptionManager.prototype.setOption = function (rawOption, optionPreprocessorFuncs, opt) {
  18792. if (rawOption) {
  18793. // That set dat primitive is dangerous if user reuse the data when setOption again.
  18794. each(normalizeToArray(rawOption.series), function (series) {
  18795. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  18796. });
  18797. each(normalizeToArray(rawOption.dataset), function (dataset) {
  18798. dataset && dataset.source && isTypedArray(dataset.source) && setAsPrimitive(dataset.source);
  18799. });
  18800. }
  18801. // Caution: some series modify option data, if do not clone,
  18802. // it should ensure that the repeat modify correctly
  18803. // (create a new object when modify itself).
  18804. rawOption = clone(rawOption);
  18805. // FIXME
  18806. // If some property is set in timeline options or media option but
  18807. // not set in baseOption, a warning should be given.
  18808. var optionBackup = this._optionBackup;
  18809. var newParsedOption = parseRawOption(rawOption, optionPreprocessorFuncs, !optionBackup);
  18810. this._newBaseOption = newParsedOption.baseOption;
  18811. // For setOption at second time (using merge mode);
  18812. if (optionBackup) {
  18813. // FIXME
  18814. // the restore merge solution is essentially incorrect.
  18815. // the mapping can not be 100% consistent with ecModel, which probably brings
  18816. // potential bug!
  18817. // The first merge is delayed, because in most cases, users do not call `setOption` twice.
  18818. // let fakeCmptsMap = this._fakeCmptsMap;
  18819. // if (!fakeCmptsMap) {
  18820. // fakeCmptsMap = this._fakeCmptsMap = createHashMap();
  18821. // mergeToBackupOption(fakeCmptsMap, null, optionBackup.baseOption, null);
  18822. // }
  18823. // mergeToBackupOption(
  18824. // fakeCmptsMap, optionBackup.baseOption, newParsedOption.baseOption, opt
  18825. // );
  18826. // For simplicity, timeline options and media options do not support merge,
  18827. // that is, if you `setOption` twice and both has timeline options, the latter
  18828. // timeline options will not be merged to the former, but just substitute them.
  18829. if (newParsedOption.timelineOptions.length) {
  18830. optionBackup.timelineOptions = newParsedOption.timelineOptions;
  18831. }
  18832. if (newParsedOption.mediaList.length) {
  18833. optionBackup.mediaList = newParsedOption.mediaList;
  18834. }
  18835. if (newParsedOption.mediaDefault) {
  18836. optionBackup.mediaDefault = newParsedOption.mediaDefault;
  18837. }
  18838. } else {
  18839. this._optionBackup = newParsedOption;
  18840. }
  18841. };
  18842. OptionManager.prototype.mountOption = function (isRecreate) {
  18843. var optionBackup = this._optionBackup;
  18844. this._timelineOptions = optionBackup.timelineOptions;
  18845. this._mediaList = optionBackup.mediaList;
  18846. this._mediaDefault = optionBackup.mediaDefault;
  18847. this._currentMediaIndices = [];
  18848. return clone(isRecreate
  18849. // this._optionBackup.baseOption, which is created at the first `setOption`
  18850. // called, and is merged into every new option by inner method `mergeToBackupOption`
  18851. // each time `setOption` called, can be only used in `isRecreate`, because
  18852. // its reliability is under suspicion. In other cases option merge is
  18853. // performed by `model.mergeOption`.
  18854. ? optionBackup.baseOption : this._newBaseOption);
  18855. };
  18856. OptionManager.prototype.getTimelineOption = function (ecModel) {
  18857. var option;
  18858. var timelineOptions = this._timelineOptions;
  18859. if (timelineOptions.length) {
  18860. // getTimelineOption can only be called after ecModel inited,
  18861. // so we can get currentIndex from timelineModel.
  18862. var timelineModel = ecModel.getComponent('timeline');
  18863. if (timelineModel) {
  18864. option = clone(
  18865. // FIXME:TS as TimelineModel or quivlant interface
  18866. timelineOptions[timelineModel.getCurrentIndex()]);
  18867. }
  18868. }
  18869. return option;
  18870. };
  18871. OptionManager.prototype.getMediaOption = function (ecModel) {
  18872. var ecWidth = this._api.getWidth();
  18873. var ecHeight = this._api.getHeight();
  18874. var mediaList = this._mediaList;
  18875. var mediaDefault = this._mediaDefault;
  18876. var indices = [];
  18877. var result = [];
  18878. // No media defined.
  18879. if (!mediaList.length && !mediaDefault) {
  18880. return result;
  18881. }
  18882. // Multi media may be applied, the latter defined media has higher priority.
  18883. for (var i = 0, len = mediaList.length; i < len; i++) {
  18884. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  18885. indices.push(i);
  18886. }
  18887. }
  18888. // FIXME
  18889. // Whether mediaDefault should force users to provide? Otherwise
  18890. // the change by media query can not be recorvered.
  18891. if (!indices.length && mediaDefault) {
  18892. indices = [-1];
  18893. }
  18894. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  18895. result = map(indices, function (index) {
  18896. return clone(index === -1 ? mediaDefault.option : mediaList[index].option);
  18897. });
  18898. }
  18899. // Otherwise return nothing.
  18900. this._currentMediaIndices = indices;
  18901. return result;
  18902. };
  18903. return OptionManager;
  18904. }();
  18905. /**
  18906. * [RAW_OPTION_PATTERNS]
  18907. * (Note: "series: []" represents all other props in `ECUnitOption`)
  18908. *
  18909. * (1) No prop "baseOption" declared:
  18910. * Root option is used as "baseOption" (except prop "options" and "media").
  18911. * ```js
  18912. * option = {
  18913. * series: [],
  18914. * timeline: {},
  18915. * options: [],
  18916. * };
  18917. * option = {
  18918. * series: [],
  18919. * media: {},
  18920. * };
  18921. * option = {
  18922. * series: [],
  18923. * timeline: {},
  18924. * options: [],
  18925. * media: {},
  18926. * }
  18927. * ```
  18928. *
  18929. * (2) Prop "baseOption" declared:
  18930. * If "baseOption" declared, `ECUnitOption` props can only be declared
  18931. * inside "baseOption" except prop "timeline" (compat ec2).
  18932. * ```js
  18933. * option = {
  18934. * baseOption: {
  18935. * timeline: {},
  18936. * series: [],
  18937. * },
  18938. * options: []
  18939. * };
  18940. * option = {
  18941. * baseOption: {
  18942. * series: [],
  18943. * },
  18944. * media: []
  18945. * };
  18946. * option = {
  18947. * baseOption: {
  18948. * timeline: {},
  18949. * series: [],
  18950. * },
  18951. * options: []
  18952. * media: []
  18953. * };
  18954. * option = {
  18955. * // ec3 compat ec2: allow (only) `timeline` declared
  18956. * // outside baseOption. Keep this setting for compat.
  18957. * timeline: {},
  18958. * baseOption: {
  18959. * series: [],
  18960. * },
  18961. * options: [],
  18962. * media: []
  18963. * };
  18964. * ```
  18965. */
  18966. function parseRawOption(
  18967. // `rawOption` May be modified
  18968. rawOption, optionPreprocessorFuncs, isNew) {
  18969. var mediaList = [];
  18970. var mediaDefault;
  18971. var baseOption;
  18972. var declaredBaseOption = rawOption.baseOption;
  18973. // Compatible with ec2, [RAW_OPTION_PATTERNS] above.
  18974. var timelineOnRoot = rawOption.timeline;
  18975. var timelineOptionsOnRoot = rawOption.options;
  18976. var mediaOnRoot = rawOption.media;
  18977. var hasMedia = !!rawOption.media;
  18978. var hasTimeline = !!(timelineOptionsOnRoot || timelineOnRoot || declaredBaseOption && declaredBaseOption.timeline);
  18979. if (declaredBaseOption) {
  18980. baseOption = declaredBaseOption;
  18981. // For merge option.
  18982. if (!baseOption.timeline) {
  18983. baseOption.timeline = timelineOnRoot;
  18984. }
  18985. }
  18986. // For convenience, enable to use the root option as the `baseOption`:
  18987. // `{ ...normalOptionProps, media: [{ ... }, { ... }] }`
  18988. else {
  18989. if (hasTimeline || hasMedia) {
  18990. rawOption.options = rawOption.media = null;
  18991. }
  18992. baseOption = rawOption;
  18993. }
  18994. if (hasMedia) {
  18995. if (isArray(mediaOnRoot)) {
  18996. each(mediaOnRoot, function (singleMedia) {
  18997. if ("development" !== 'production') {
  18998. // Real case of wrong config.
  18999. if (singleMedia && !singleMedia.option && isObject(singleMedia.query) && isObject(singleMedia.query.option)) {
  19000. error('Illegal media option. Must be like { media: [ { query: {}, option: {} } ] }');
  19001. }
  19002. }
  19003. if (singleMedia && singleMedia.option) {
  19004. if (singleMedia.query) {
  19005. mediaList.push(singleMedia);
  19006. } else if (!mediaDefault) {
  19007. // Use the first media default.
  19008. mediaDefault = singleMedia;
  19009. }
  19010. }
  19011. });
  19012. } else {
  19013. if ("development" !== 'production') {
  19014. // Real case of wrong config.
  19015. error('Illegal media option. Must be an array. Like { media: [ {...}, {...} ] }');
  19016. }
  19017. }
  19018. }
  19019. doPreprocess(baseOption);
  19020. each(timelineOptionsOnRoot, function (option) {
  19021. return doPreprocess(option);
  19022. });
  19023. each(mediaList, function (media) {
  19024. return doPreprocess(media.option);
  19025. });
  19026. function doPreprocess(option) {
  19027. each(optionPreprocessorFuncs, function (preProcess) {
  19028. preProcess(option, isNew);
  19029. });
  19030. }
  19031. return {
  19032. baseOption: baseOption,
  19033. timelineOptions: timelineOptionsOnRoot || [],
  19034. mediaDefault: mediaDefault,
  19035. mediaList: mediaList
  19036. };
  19037. }
  19038. /**
  19039. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  19040. * Support: width, height, aspectRatio
  19041. * Can use max or min as prefix.
  19042. */
  19043. function applyMediaQuery(query, ecWidth, ecHeight) {
  19044. var realMap = {
  19045. width: ecWidth,
  19046. height: ecHeight,
  19047. aspectratio: ecWidth / ecHeight // lower case for convenience.
  19048. };
  19049. var applicable = true;
  19050. each(query, function (value, attr) {
  19051. var matched = attr.match(QUERY_REG);
  19052. if (!matched || !matched[1] || !matched[2]) {
  19053. return;
  19054. }
  19055. var operator = matched[1];
  19056. var realAttr = matched[2].toLowerCase();
  19057. if (!compare(realMap[realAttr], value, operator)) {
  19058. applicable = false;
  19059. }
  19060. });
  19061. return applicable;
  19062. }
  19063. function compare(real, expect, operator) {
  19064. if (operator === 'min') {
  19065. return real >= expect;
  19066. } else if (operator === 'max') {
  19067. return real <= expect;
  19068. } else {
  19069. // Equals
  19070. return real === expect;
  19071. }
  19072. }
  19073. function indicesEquals(indices1, indices2) {
  19074. // indices is always order by asc and has only finite number.
  19075. return indices1.join(',') === indices2.join(',');
  19076. }
  19077. var each$2 = each;
  19078. var isObject$1 = isObject;
  19079. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  19080. function compatEC2ItemStyle(opt) {
  19081. var itemStyleOpt = opt && opt.itemStyle;
  19082. if (!itemStyleOpt) {
  19083. return;
  19084. }
  19085. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  19086. var styleName = POSSIBLE_STYLES[i];
  19087. var normalItemStyleOpt = itemStyleOpt.normal;
  19088. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  19089. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  19090. if ("development" !== 'production') {
  19091. deprecateReplaceLog("itemStyle.normal." + styleName, styleName);
  19092. }
  19093. opt[styleName] = opt[styleName] || {};
  19094. if (!opt[styleName].normal) {
  19095. opt[styleName].normal = normalItemStyleOpt[styleName];
  19096. } else {
  19097. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  19098. }
  19099. normalItemStyleOpt[styleName] = null;
  19100. }
  19101. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  19102. if ("development" !== 'production') {
  19103. deprecateReplaceLog("itemStyle.emphasis." + styleName, "emphasis." + styleName);
  19104. }
  19105. opt[styleName] = opt[styleName] || {};
  19106. if (!opt[styleName].emphasis) {
  19107. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  19108. } else {
  19109. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  19110. }
  19111. emphasisItemStyleOpt[styleName] = null;
  19112. }
  19113. }
  19114. }
  19115. function convertNormalEmphasis(opt, optType, useExtend) {
  19116. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  19117. var normalOpt = opt[optType].normal;
  19118. var emphasisOpt = opt[optType].emphasis;
  19119. if (normalOpt) {
  19120. if ("development" !== 'production') {
  19121. // eslint-disable-next-line max-len
  19122. deprecateLog("'normal' hierarchy in " + optType + " has been removed since 4.0. All style properties are configured in " + optType + " directly now.");
  19123. }
  19124. // Timeline controlStyle has other properties besides normal and emphasis
  19125. if (useExtend) {
  19126. opt[optType].normal = opt[optType].emphasis = null;
  19127. defaults(opt[optType], normalOpt);
  19128. } else {
  19129. opt[optType] = normalOpt;
  19130. }
  19131. }
  19132. if (emphasisOpt) {
  19133. if ("development" !== 'production') {
  19134. deprecateLog(optType + ".emphasis has been changed to emphasis." + optType + " since 4.0");
  19135. }
  19136. opt.emphasis = opt.emphasis || {};
  19137. opt.emphasis[optType] = emphasisOpt;
  19138. // Also compat the case user mix the style and focus together in ec3 style
  19139. // for example: { itemStyle: { normal: {}, emphasis: {focus, shadowBlur} } }
  19140. if (emphasisOpt.focus) {
  19141. opt.emphasis.focus = emphasisOpt.focus;
  19142. }
  19143. if (emphasisOpt.blurScope) {
  19144. opt.emphasis.blurScope = emphasisOpt.blurScope;
  19145. }
  19146. }
  19147. }
  19148. }
  19149. function removeEC3NormalStatus(opt) {
  19150. convertNormalEmphasis(opt, 'itemStyle');
  19151. convertNormalEmphasis(opt, 'lineStyle');
  19152. convertNormalEmphasis(opt, 'areaStyle');
  19153. convertNormalEmphasis(opt, 'label');
  19154. convertNormalEmphasis(opt, 'labelLine');
  19155. // treemap
  19156. convertNormalEmphasis(opt, 'upperLabel');
  19157. // graph
  19158. convertNormalEmphasis(opt, 'edgeLabel');
  19159. }
  19160. function compatTextStyle(opt, propName) {
  19161. // Check whether is not object (string\null\undefined ...)
  19162. var labelOptSingle = isObject$1(opt) && opt[propName];
  19163. var textStyle = isObject$1(labelOptSingle) && labelOptSingle.textStyle;
  19164. if (textStyle) {
  19165. if ("development" !== 'production') {
  19166. // eslint-disable-next-line max-len
  19167. deprecateLog("textStyle hierarchy in " + propName + " has been removed since 4.0. All textStyle properties are configured in " + propName + " directly now.");
  19168. }
  19169. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  19170. var textPropName = TEXT_STYLE_OPTIONS[i];
  19171. if (textStyle.hasOwnProperty(textPropName)) {
  19172. labelOptSingle[textPropName] = textStyle[textPropName];
  19173. }
  19174. }
  19175. }
  19176. }
  19177. function compatEC3CommonStyles(opt) {
  19178. if (opt) {
  19179. removeEC3NormalStatus(opt);
  19180. compatTextStyle(opt, 'label');
  19181. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  19182. }
  19183. }
  19184. function processSeries(seriesOpt) {
  19185. if (!isObject$1(seriesOpt)) {
  19186. return;
  19187. }
  19188. compatEC2ItemStyle(seriesOpt);
  19189. removeEC3NormalStatus(seriesOpt);
  19190. compatTextStyle(seriesOpt, 'label');
  19191. // treemap
  19192. compatTextStyle(seriesOpt, 'upperLabel');
  19193. // graph
  19194. compatTextStyle(seriesOpt, 'edgeLabel');
  19195. if (seriesOpt.emphasis) {
  19196. compatTextStyle(seriesOpt.emphasis, 'label');
  19197. // treemap
  19198. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  19199. // graph
  19200. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  19201. }
  19202. var markPoint = seriesOpt.markPoint;
  19203. if (markPoint) {
  19204. compatEC2ItemStyle(markPoint);
  19205. compatEC3CommonStyles(markPoint);
  19206. }
  19207. var markLine = seriesOpt.markLine;
  19208. if (markLine) {
  19209. compatEC2ItemStyle(markLine);
  19210. compatEC3CommonStyles(markLine);
  19211. }
  19212. var markArea = seriesOpt.markArea;
  19213. if (markArea) {
  19214. compatEC3CommonStyles(markArea);
  19215. }
  19216. var data = seriesOpt.data;
  19217. // Break with ec3: if `setOption` again, there may be no `type` in option,
  19218. // then the backward compat based on option type will not be performed.
  19219. if (seriesOpt.type === 'graph') {
  19220. data = data || seriesOpt.nodes;
  19221. var edgeData = seriesOpt.links || seriesOpt.edges;
  19222. if (edgeData && !isTypedArray(edgeData)) {
  19223. for (var i = 0; i < edgeData.length; i++) {
  19224. compatEC3CommonStyles(edgeData[i]);
  19225. }
  19226. }
  19227. each(seriesOpt.categories, function (opt) {
  19228. removeEC3NormalStatus(opt);
  19229. });
  19230. }
  19231. if (data && !isTypedArray(data)) {
  19232. for (var i = 0; i < data.length; i++) {
  19233. compatEC3CommonStyles(data[i]);
  19234. }
  19235. }
  19236. // mark point data
  19237. markPoint = seriesOpt.markPoint;
  19238. if (markPoint && markPoint.data) {
  19239. var mpData = markPoint.data;
  19240. for (var i = 0; i < mpData.length; i++) {
  19241. compatEC3CommonStyles(mpData[i]);
  19242. }
  19243. }
  19244. // mark line data
  19245. markLine = seriesOpt.markLine;
  19246. if (markLine && markLine.data) {
  19247. var mlData = markLine.data;
  19248. for (var i = 0; i < mlData.length; i++) {
  19249. if (isArray(mlData[i])) {
  19250. compatEC3CommonStyles(mlData[i][0]);
  19251. compatEC3CommonStyles(mlData[i][1]);
  19252. } else {
  19253. compatEC3CommonStyles(mlData[i]);
  19254. }
  19255. }
  19256. }
  19257. // Series
  19258. if (seriesOpt.type === 'gauge') {
  19259. compatTextStyle(seriesOpt, 'axisLabel');
  19260. compatTextStyle(seriesOpt, 'title');
  19261. compatTextStyle(seriesOpt, 'detail');
  19262. } else if (seriesOpt.type === 'treemap') {
  19263. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  19264. each(seriesOpt.levels, function (opt) {
  19265. removeEC3NormalStatus(opt);
  19266. });
  19267. } else if (seriesOpt.type === 'tree') {
  19268. removeEC3NormalStatus(seriesOpt.leaves);
  19269. }
  19270. // sunburst starts from ec4, so it does not need to compat levels.
  19271. }
  19272. function toArr(o) {
  19273. return isArray(o) ? o : o ? [o] : [];
  19274. }
  19275. function toObj(o) {
  19276. return (isArray(o) ? o[0] : o) || {};
  19277. }
  19278. function globalCompatStyle(option, isTheme) {
  19279. each$2(toArr(option.series), function (seriesOpt) {
  19280. isObject$1(seriesOpt) && processSeries(seriesOpt);
  19281. });
  19282. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  19283. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  19284. each$2(axes, function (axisName) {
  19285. each$2(toArr(option[axisName]), function (axisOpt) {
  19286. if (axisOpt) {
  19287. compatTextStyle(axisOpt, 'axisLabel');
  19288. compatTextStyle(axisOpt.axisPointer, 'label');
  19289. }
  19290. });
  19291. });
  19292. each$2(toArr(option.parallel), function (parallelOpt) {
  19293. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  19294. compatTextStyle(parallelAxisDefault, 'axisLabel');
  19295. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  19296. });
  19297. each$2(toArr(option.calendar), function (calendarOpt) {
  19298. convertNormalEmphasis(calendarOpt, 'itemStyle');
  19299. compatTextStyle(calendarOpt, 'dayLabel');
  19300. compatTextStyle(calendarOpt, 'monthLabel');
  19301. compatTextStyle(calendarOpt, 'yearLabel');
  19302. });
  19303. // radar.name.textStyle
  19304. each$2(toArr(option.radar), function (radarOpt) {
  19305. compatTextStyle(radarOpt, 'name');
  19306. // Use axisName instead of name because component has name property
  19307. if (radarOpt.name && radarOpt.axisName == null) {
  19308. radarOpt.axisName = radarOpt.name;
  19309. delete radarOpt.name;
  19310. if ("development" !== 'production') {
  19311. deprecateLog('name property in radar component has been changed to axisName');
  19312. }
  19313. }
  19314. if (radarOpt.nameGap != null && radarOpt.axisNameGap == null) {
  19315. radarOpt.axisNameGap = radarOpt.nameGap;
  19316. delete radarOpt.nameGap;
  19317. if ("development" !== 'production') {
  19318. deprecateLog('nameGap property in radar component has been changed to axisNameGap');
  19319. }
  19320. }
  19321. if ("development" !== 'production') {
  19322. each$2(radarOpt.indicator, function (indicatorOpt) {
  19323. if (indicatorOpt.text) {
  19324. deprecateReplaceLog('text', 'name', 'radar.indicator');
  19325. }
  19326. });
  19327. }
  19328. });
  19329. each$2(toArr(option.geo), function (geoOpt) {
  19330. if (isObject$1(geoOpt)) {
  19331. compatEC3CommonStyles(geoOpt);
  19332. each$2(toArr(geoOpt.regions), function (regionObj) {
  19333. compatEC3CommonStyles(regionObj);
  19334. });
  19335. }
  19336. });
  19337. each$2(toArr(option.timeline), function (timelineOpt) {
  19338. compatEC3CommonStyles(timelineOpt);
  19339. convertNormalEmphasis(timelineOpt, 'label');
  19340. convertNormalEmphasis(timelineOpt, 'itemStyle');
  19341. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  19342. var data = timelineOpt.data;
  19343. isArray(data) && each(data, function (item) {
  19344. if (isObject(item)) {
  19345. convertNormalEmphasis(item, 'label');
  19346. convertNormalEmphasis(item, 'itemStyle');
  19347. }
  19348. });
  19349. });
  19350. each$2(toArr(option.toolbox), function (toolboxOpt) {
  19351. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  19352. each$2(toolboxOpt.feature, function (featureOpt) {
  19353. convertNormalEmphasis(featureOpt, 'iconStyle');
  19354. });
  19355. });
  19356. compatTextStyle(toObj(option.axisPointer), 'label');
  19357. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  19358. // Clean logs
  19359. // storedLogs = {};
  19360. }
  19361. function get(opt, path) {
  19362. var pathArr = path.split(',');
  19363. var obj = opt;
  19364. for (var i = 0; i < pathArr.length; i++) {
  19365. obj = obj && obj[pathArr[i]];
  19366. if (obj == null) {
  19367. break;
  19368. }
  19369. }
  19370. return obj;
  19371. }
  19372. function set$1(opt, path, val, overwrite) {
  19373. var pathArr = path.split(',');
  19374. var obj = opt;
  19375. var key;
  19376. var i = 0;
  19377. for (; i < pathArr.length - 1; i++) {
  19378. key = pathArr[i];
  19379. if (obj[key] == null) {
  19380. obj[key] = {};
  19381. }
  19382. obj = obj[key];
  19383. }
  19384. if (overwrite || obj[pathArr[i]] == null) {
  19385. obj[pathArr[i]] = val;
  19386. }
  19387. }
  19388. function compatLayoutProperties(option) {
  19389. option && each(LAYOUT_PROPERTIES, function (prop) {
  19390. if (prop[0] in option && !(prop[1] in option)) {
  19391. option[prop[1]] = option[prop[0]];
  19392. }
  19393. });
  19394. }
  19395. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  19396. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  19397. var BAR_ITEM_STYLE_MAP = [['borderRadius', 'barBorderRadius'], ['borderColor', 'barBorderColor'], ['borderWidth', 'barBorderWidth']];
  19398. function compatBarItemStyle(option) {
  19399. var itemStyle = option && option.itemStyle;
  19400. if (itemStyle) {
  19401. for (var i = 0; i < BAR_ITEM_STYLE_MAP.length; i++) {
  19402. var oldName = BAR_ITEM_STYLE_MAP[i][1];
  19403. var newName = BAR_ITEM_STYLE_MAP[i][0];
  19404. if (itemStyle[oldName] != null) {
  19405. itemStyle[newName] = itemStyle[oldName];
  19406. if ("development" !== 'production') {
  19407. deprecateReplaceLog(oldName, newName);
  19408. }
  19409. }
  19410. }
  19411. }
  19412. }
  19413. function compatPieLabel(option) {
  19414. if (!option) {
  19415. return;
  19416. }
  19417. if (option.alignTo === 'edge' && option.margin != null && option.edgeDistance == null) {
  19418. if ("development" !== 'production') {
  19419. deprecateReplaceLog('label.margin', 'label.edgeDistance', 'pie');
  19420. }
  19421. option.edgeDistance = option.margin;
  19422. }
  19423. }
  19424. function compatSunburstState(option) {
  19425. if (!option) {
  19426. return;
  19427. }
  19428. if (option.downplay && !option.blur) {
  19429. option.blur = option.downplay;
  19430. if ("development" !== 'production') {
  19431. deprecateReplaceLog('downplay', 'blur', 'sunburst');
  19432. }
  19433. }
  19434. }
  19435. function compatGraphFocus(option) {
  19436. if (!option) {
  19437. return;
  19438. }
  19439. if (option.focusNodeAdjacency != null) {
  19440. option.emphasis = option.emphasis || {};
  19441. if (option.emphasis.focus == null) {
  19442. if ("development" !== 'production') {
  19443. deprecateReplaceLog('focusNodeAdjacency', 'emphasis: { focus: \'adjacency\'}', 'graph/sankey');
  19444. }
  19445. option.emphasis.focus = 'adjacency';
  19446. }
  19447. }
  19448. }
  19449. function traverseTree(data, cb) {
  19450. if (data) {
  19451. for (var i = 0; i < data.length; i++) {
  19452. cb(data[i]);
  19453. data[i] && traverseTree(data[i].children, cb);
  19454. }
  19455. }
  19456. }
  19457. function globalBackwardCompat(option, isTheme) {
  19458. globalCompatStyle(option, isTheme);
  19459. // Make sure series array for model initialization.
  19460. option.series = normalizeToArray(option.series);
  19461. each(option.series, function (seriesOpt) {
  19462. if (!isObject(seriesOpt)) {
  19463. return;
  19464. }
  19465. var seriesType = seriesOpt.type;
  19466. if (seriesType === 'line') {
  19467. if (seriesOpt.clipOverflow != null) {
  19468. seriesOpt.clip = seriesOpt.clipOverflow;
  19469. if ("development" !== 'production') {
  19470. deprecateReplaceLog('clipOverflow', 'clip', 'line');
  19471. }
  19472. }
  19473. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  19474. if (seriesOpt.clockWise != null) {
  19475. seriesOpt.clockwise = seriesOpt.clockWise;
  19476. if ("development" !== 'production') {
  19477. deprecateReplaceLog('clockWise', 'clockwise');
  19478. }
  19479. }
  19480. compatPieLabel(seriesOpt.label);
  19481. var data = seriesOpt.data;
  19482. if (data && !isTypedArray(data)) {
  19483. for (var i = 0; i < data.length; i++) {
  19484. compatPieLabel(data[i]);
  19485. }
  19486. }
  19487. if (seriesOpt.hoverOffset != null) {
  19488. seriesOpt.emphasis = seriesOpt.emphasis || {};
  19489. if (seriesOpt.emphasis.scaleSize = null) {
  19490. if ("development" !== 'production') {
  19491. deprecateReplaceLog('hoverOffset', 'emphasis.scaleSize');
  19492. }
  19493. seriesOpt.emphasis.scaleSize = seriesOpt.hoverOffset;
  19494. }
  19495. }
  19496. } else if (seriesType === 'gauge') {
  19497. var pointerColor = get(seriesOpt, 'pointer.color');
  19498. pointerColor != null && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  19499. } else if (seriesType === 'bar') {
  19500. compatBarItemStyle(seriesOpt);
  19501. compatBarItemStyle(seriesOpt.backgroundStyle);
  19502. compatBarItemStyle(seriesOpt.emphasis);
  19503. var data = seriesOpt.data;
  19504. if (data && !isTypedArray(data)) {
  19505. for (var i = 0; i < data.length; i++) {
  19506. if (typeof data[i] === 'object') {
  19507. compatBarItemStyle(data[i]);
  19508. compatBarItemStyle(data[i] && data[i].emphasis);
  19509. }
  19510. }
  19511. }
  19512. } else if (seriesType === 'sunburst') {
  19513. var highlightPolicy = seriesOpt.highlightPolicy;
  19514. if (highlightPolicy) {
  19515. seriesOpt.emphasis = seriesOpt.emphasis || {};
  19516. if (!seriesOpt.emphasis.focus) {
  19517. seriesOpt.emphasis.focus = highlightPolicy;
  19518. if ("development" !== 'production') {
  19519. deprecateReplaceLog('highlightPolicy', 'emphasis.focus', 'sunburst');
  19520. }
  19521. }
  19522. }
  19523. compatSunburstState(seriesOpt);
  19524. traverseTree(seriesOpt.data, compatSunburstState);
  19525. } else if (seriesType === 'graph' || seriesType === 'sankey') {
  19526. compatGraphFocus(seriesOpt);
  19527. // TODO nodes, edges?
  19528. } else if (seriesType === 'map') {
  19529. if (seriesOpt.mapType && !seriesOpt.map) {
  19530. if ("development" !== 'production') {
  19531. deprecateReplaceLog('mapType', 'map', 'map');
  19532. }
  19533. seriesOpt.map = seriesOpt.mapType;
  19534. }
  19535. if (seriesOpt.mapLocation) {
  19536. if ("development" !== 'production') {
  19537. deprecateLog('`mapLocation` is not used anymore.');
  19538. }
  19539. defaults(seriesOpt, seriesOpt.mapLocation);
  19540. }
  19541. }
  19542. if (seriesOpt.hoverAnimation != null) {
  19543. seriesOpt.emphasis = seriesOpt.emphasis || {};
  19544. if (seriesOpt.emphasis && seriesOpt.emphasis.scale == null) {
  19545. if ("development" !== 'production') {
  19546. deprecateReplaceLog('hoverAnimation', 'emphasis.scale');
  19547. }
  19548. seriesOpt.emphasis.scale = seriesOpt.hoverAnimation;
  19549. }
  19550. }
  19551. compatLayoutProperties(seriesOpt);
  19552. });
  19553. // dataRange has changed to visualMap
  19554. if (option.dataRange) {
  19555. option.visualMap = option.dataRange;
  19556. }
  19557. each(COMPATITABLE_COMPONENTS, function (componentName) {
  19558. var options = option[componentName];
  19559. if (options) {
  19560. if (!isArray(options)) {
  19561. options = [options];
  19562. }
  19563. each(options, function (option) {
  19564. compatLayoutProperties(option);
  19565. });
  19566. }
  19567. });
  19568. }
  19569. // (1) [Caution]: the logic is correct based on the premises:
  19570. // data processing stage is blocked in stream.
  19571. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  19572. // (2) Only register once when import repeatedly.
  19573. // Should be executed after series is filtered and before stack calculation.
  19574. function dataStack(ecModel) {
  19575. var stackInfoMap = createHashMap();
  19576. ecModel.eachSeries(function (seriesModel) {
  19577. var stack = seriesModel.get('stack');
  19578. // Compatible: when `stack` is set as '', do not stack.
  19579. if (stack) {
  19580. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  19581. var data = seriesModel.getData();
  19582. var stackInfo = {
  19583. // Used for calculate axis extent automatically.
  19584. // TODO: Type getCalculationInfo return more specific type?
  19585. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  19586. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  19587. stackedDimension: data.getCalculationInfo('stackedDimension'),
  19588. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  19589. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  19590. data: data,
  19591. seriesModel: seriesModel
  19592. };
  19593. // If stacked on axis that do not support data stack.
  19594. if (!stackInfo.stackedDimension || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)) {
  19595. return;
  19596. }
  19597. stackInfoList.push(stackInfo);
  19598. }
  19599. });
  19600. // Process each stack group
  19601. stackInfoMap.each(function (stackInfoList) {
  19602. if (stackInfoList.length === 0) {
  19603. return;
  19604. }
  19605. // Check if stack order needs to be reversed
  19606. var firstSeries = stackInfoList[0].seriesModel;
  19607. var stackOrder = firstSeries.get('stackOrder') || 'seriesAsc';
  19608. if (stackOrder === 'seriesDesc') {
  19609. stackInfoList.reverse();
  19610. }
  19611. // Set stackedOnSeries for each series in the final order
  19612. each(stackInfoList, function (stackInfo, index) {
  19613. stackInfo.data.setCalculationInfo('stackedOnSeries', index > 0 ? stackInfoList[index - 1].seriesModel : null);
  19614. });
  19615. // Calculate stack values
  19616. calculateStack(stackInfoList);
  19617. });
  19618. }
  19619. function calculateStack(stackInfoList) {
  19620. each(stackInfoList, function (targetStackInfo, idxInStack) {
  19621. var resultVal = [];
  19622. var resultNaN = [NaN, NaN];
  19623. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  19624. var targetData = targetStackInfo.data;
  19625. var isStackedByIndex = targetStackInfo.isStackedByIndex;
  19626. var stackStrategy = targetStackInfo.seriesModel.get('stackStrategy') || 'samesign';
  19627. // Should not write on raw data, because stack series model list changes
  19628. // depending on legend selection.
  19629. targetData.modify(dims, function (v0, v1, dataIndex) {
  19630. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);
  19631. // Consider `connectNulls` of line area, if value is NaN, stackedOver
  19632. // should also be NaN, to draw a appropriate belt area.
  19633. if (isNaN(sum)) {
  19634. return resultNaN;
  19635. }
  19636. var byValue;
  19637. var stackedDataRawIndex;
  19638. if (isStackedByIndex) {
  19639. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  19640. } else {
  19641. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  19642. }
  19643. // If stackOver is NaN, chart view will render point on value start.
  19644. var stackedOver = NaN;
  19645. for (var j = idxInStack - 1; j >= 0; j--) {
  19646. var stackInfo = stackInfoList[j];
  19647. // Has been optimized by inverted indices on `stackedByDimension`.
  19648. if (!isStackedByIndex) {
  19649. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  19650. }
  19651. if (stackedDataRawIndex >= 0) {
  19652. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
  19653. // Considering positive stack, negative stack and empty data
  19654. if (stackStrategy === 'all' // single stack group
  19655. || stackStrategy === 'positive' && val > 0 || stackStrategy === 'negative' && val < 0 || stackStrategy === 'samesign' && sum >= 0 && val > 0 // All positive stack
  19656. || stackStrategy === 'samesign' && sum <= 0 && val < 0 // All negative stack
  19657. ) {
  19658. // The sum has to be very small to be affected by the
  19659. // floating arithmetic problem. An incorrect result will probably
  19660. // cause axis min/max to be filtered incorrectly.
  19661. sum = addSafe(sum, val);
  19662. stackedOver = val;
  19663. break;
  19664. }
  19665. }
  19666. }
  19667. resultVal[0] = sum;
  19668. resultVal[1] = stackedOver;
  19669. return resultVal;
  19670. });
  19671. });
  19672. }
  19673. // @inner
  19674. var SourceImpl = /** @class */function () {
  19675. function SourceImpl(fields) {
  19676. this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
  19677. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  19678. // Visit config
  19679. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  19680. this.startIndex = fields.startIndex || 0;
  19681. this.dimensionsDetectedCount = fields.dimensionsDetectedCount;
  19682. this.metaRawOption = fields.metaRawOption;
  19683. var dimensionsDefine = this.dimensionsDefine = fields.dimensionsDefine;
  19684. if (dimensionsDefine) {
  19685. for (var i = 0; i < dimensionsDefine.length; i++) {
  19686. var dim = dimensionsDefine[i];
  19687. if (dim.type == null) {
  19688. if (guessOrdinal(this, i) === BE_ORDINAL.Must) {
  19689. dim.type = 'ordinal';
  19690. }
  19691. }
  19692. }
  19693. }
  19694. }
  19695. return SourceImpl;
  19696. }();
  19697. function isSourceInstance(val) {
  19698. return val instanceof SourceImpl;
  19699. }
  19700. /**
  19701. * Create a source from option.
  19702. * NOTE: Created source is immutable. Don't change any properties in it.
  19703. */
  19704. function createSource(sourceData, thisMetaRawOption,
  19705. // can be null. If not provided, auto detect it from `sourceData`.
  19706. sourceFormat) {
  19707. sourceFormat = sourceFormat || detectSourceFormat(sourceData);
  19708. var seriesLayoutBy = thisMetaRawOption.seriesLayoutBy;
  19709. var determined = determineSourceDimensions(sourceData, sourceFormat, seriesLayoutBy, thisMetaRawOption.sourceHeader, thisMetaRawOption.dimensions);
  19710. var source = new SourceImpl({
  19711. data: sourceData,
  19712. sourceFormat: sourceFormat,
  19713. seriesLayoutBy: seriesLayoutBy,
  19714. dimensionsDefine: determined.dimensionsDefine,
  19715. startIndex: determined.startIndex,
  19716. dimensionsDetectedCount: determined.dimensionsDetectedCount,
  19717. metaRawOption: clone(thisMetaRawOption)
  19718. });
  19719. return source;
  19720. }
  19721. /**
  19722. * Wrap original series data for some compatibility cases.
  19723. */
  19724. function createSourceFromSeriesDataOption(data) {
  19725. return new SourceImpl({
  19726. data: data,
  19727. sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL
  19728. });
  19729. }
  19730. /**
  19731. * Clone source but excludes source data.
  19732. */
  19733. function cloneSourceShallow(source) {
  19734. return new SourceImpl({
  19735. data: source.data,
  19736. sourceFormat: source.sourceFormat,
  19737. seriesLayoutBy: source.seriesLayoutBy,
  19738. dimensionsDefine: clone(source.dimensionsDefine),
  19739. startIndex: source.startIndex,
  19740. dimensionsDetectedCount: source.dimensionsDetectedCount
  19741. });
  19742. }
  19743. /**
  19744. * Note: An empty array will be detected as `SOURCE_FORMAT_ARRAY_ROWS`.
  19745. */
  19746. function detectSourceFormat(data) {
  19747. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  19748. if (isTypedArray(data)) {
  19749. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  19750. } else if (isArray(data)) {
  19751. // FIXME Whether tolerate null in top level array?
  19752. if (data.length === 0) {
  19753. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  19754. }
  19755. for (var i = 0, len = data.length; i < len; i++) {
  19756. var item = data[i];
  19757. if (item == null) {
  19758. continue;
  19759. } else if (isArray(item) || isTypedArray(item)) {
  19760. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  19761. break;
  19762. } else if (isObject(item)) {
  19763. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  19764. break;
  19765. }
  19766. }
  19767. } else if (isObject(data)) {
  19768. for (var key in data) {
  19769. if (hasOwn(data, key) && isArrayLike(data[key])) {
  19770. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  19771. break;
  19772. }
  19773. }
  19774. }
  19775. return sourceFormat;
  19776. }
  19777. /**
  19778. * Determine the source definitions from data standalone dimensions definitions
  19779. * are not specified.
  19780. */
  19781. function determineSourceDimensions(data, sourceFormat, seriesLayoutBy, sourceHeader,
  19782. // standalone raw dimensions definition, like:
  19783. // {
  19784. // dimensions: ['aa', 'bb', { name: 'cc', type: 'time' }]
  19785. // }
  19786. // in `dataset` or `series`
  19787. dimensionsDefine) {
  19788. var dimensionsDetectedCount;
  19789. var startIndex;
  19790. // PENDING: Could data be null/undefined here?
  19791. // currently, if `dataset.source` not specified, error thrown.
  19792. // if `series.data` not specified, nothing rendered without error thrown.
  19793. // Should test these cases.
  19794. if (!data) {
  19795. return {
  19796. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  19797. startIndex: startIndex,
  19798. dimensionsDetectedCount: dimensionsDetectedCount
  19799. };
  19800. }
  19801. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  19802. var dataArrayRows = data;
  19803. // Rule: Most of the first line are string: it is header.
  19804. // Caution: consider a line with 5 string and 1 number,
  19805. // it still can not be sure it is a head, because the
  19806. // 5 string may be 5 values of category columns.
  19807. if (sourceHeader === 'auto' || sourceHeader == null) {
  19808. arrayRowsTravelFirst(function (val) {
  19809. // '-' is regarded as null/undefined.
  19810. if (val != null && val !== '-') {
  19811. if (isString(val)) {
  19812. startIndex == null && (startIndex = 1);
  19813. } else {
  19814. startIndex = 0;
  19815. }
  19816. }
  19817. // 10 is an experience number, avoid long loop.
  19818. }, seriesLayoutBy, dataArrayRows, 10);
  19819. } else {
  19820. startIndex = isNumber(sourceHeader) ? sourceHeader : sourceHeader ? 1 : 0;
  19821. }
  19822. if (!dimensionsDefine && startIndex === 1) {
  19823. dimensionsDefine = [];
  19824. arrayRowsTravelFirst(function (val, index) {
  19825. dimensionsDefine[index] = val != null ? val + '' : '';
  19826. }, seriesLayoutBy, dataArrayRows, Infinity);
  19827. }
  19828. dimensionsDetectedCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? dataArrayRows.length : dataArrayRows[0] ? dataArrayRows[0].length : null;
  19829. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  19830. if (!dimensionsDefine) {
  19831. dimensionsDefine = objectRowsCollectDimensions(data);
  19832. }
  19833. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  19834. if (!dimensionsDefine) {
  19835. dimensionsDefine = [];
  19836. each(data, function (colArr, key) {
  19837. dimensionsDefine.push(key);
  19838. });
  19839. }
  19840. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  19841. var value0 = getDataItemValue(data[0]);
  19842. dimensionsDetectedCount = isArray(value0) && value0.length || 1;
  19843. } else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  19844. if ("development" !== 'production') {
  19845. assert(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  19846. }
  19847. }
  19848. return {
  19849. startIndex: startIndex,
  19850. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  19851. dimensionsDetectedCount: dimensionsDetectedCount
  19852. };
  19853. }
  19854. function objectRowsCollectDimensions(data) {
  19855. var firstIndex = 0;
  19856. var obj;
  19857. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  19858. if (obj) {
  19859. return keys(obj);
  19860. }
  19861. }
  19862. // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  19863. // which is reasonable. But dimension name is duplicated.
  19864. // Returns undefined or an array contains only object without null/undefined or string.
  19865. function normalizeDimensionsOption(dimensionsDefine) {
  19866. if (!dimensionsDefine) {
  19867. // The meaning of null/undefined is different from empty array.
  19868. return;
  19869. }
  19870. var nameMap = createHashMap();
  19871. return map(dimensionsDefine, function (rawItem, index) {
  19872. rawItem = isObject(rawItem) ? rawItem : {
  19873. name: rawItem
  19874. };
  19875. // Other fields will be discarded.
  19876. var item = {
  19877. name: rawItem.name,
  19878. displayName: rawItem.displayName,
  19879. type: rawItem.type
  19880. };
  19881. // User can set null in dimensions.
  19882. // We don't auto specify name, otherwise a given name may
  19883. // cause it to be referred unexpectedly.
  19884. if (item.name == null) {
  19885. return item;
  19886. }
  19887. // Also consider number form like 2012.
  19888. item.name += '';
  19889. // User may also specify displayName.
  19890. // displayName will always exists except user not
  19891. // specified or dim name is not specified or detected.
  19892. // (A auto generated dim name will not be used as
  19893. // displayName).
  19894. if (item.displayName == null) {
  19895. item.displayName = item.name;
  19896. }
  19897. var exist = nameMap.get(item.name);
  19898. if (!exist) {
  19899. nameMap.set(item.name, {
  19900. count: 1
  19901. });
  19902. } else {
  19903. item.name += '-' + exist.count++;
  19904. }
  19905. return item;
  19906. });
  19907. }
  19908. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  19909. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  19910. for (var i = 0; i < data.length && i < maxLoop; i++) {
  19911. cb(data[i] ? data[i][0] : null, i);
  19912. }
  19913. } else {
  19914. var value0 = data[0] || [];
  19915. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  19916. cb(value0[i], i);
  19917. }
  19918. }
  19919. }
  19920. function shouldRetrieveDataByName(source) {
  19921. var sourceFormat = source.sourceFormat;
  19922. return sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS;
  19923. }
  19924. /*
  19925. * Licensed to the Apache Software Foundation (ASF) under one
  19926. * or more contributor license agreements. See the NOTICE file
  19927. * distributed with this work for additional information
  19928. * regarding copyright ownership. The ASF licenses this file
  19929. * to you under the Apache License, Version 2.0 (the
  19930. * "License"); you may not use this file except in compliance
  19931. * with the License. You may obtain a copy of the License at
  19932. *
  19933. * http://www.apache.org/licenses/LICENSE-2.0
  19934. *
  19935. * Unless required by applicable law or agreed to in writing,
  19936. * software distributed under the License is distributed on an
  19937. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19938. * KIND, either express or implied. See the License for the
  19939. * specific language governing permissions and limitations
  19940. * under the License.
  19941. */
  19942. /**
  19943. * AUTO-GENERATED FILE. DO NOT MODIFY.
  19944. */
  19945. /*
  19946. * Licensed to the Apache Software Foundation (ASF) under one
  19947. * or more contributor license agreements. See the NOTICE file
  19948. * distributed with this work for additional information
  19949. * regarding copyright ownership. The ASF licenses this file
  19950. * to you under the Apache License, Version 2.0 (the
  19951. * "License"); you may not use this file except in compliance
  19952. * with the License. You may obtain a copy of the License at
  19953. *
  19954. * http://www.apache.org/licenses/LICENSE-2.0
  19955. *
  19956. * Unless required by applicable law or agreed to in writing,
  19957. * software distributed under the License is distributed on an
  19958. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19959. * KIND, either express or implied. See the License for the
  19960. * specific language governing permissions and limitations
  19961. * under the License.
  19962. */
  19963. var _a, _b, _c, _d;
  19964. var providerMethods;
  19965. var mountMethods;
  19966. /**
  19967. * If normal array used, mutable chunk size is supported.
  19968. * If typed array used, chunk size must be fixed.
  19969. */
  19970. var DefaultDataProvider = /** @class */function () {
  19971. function DefaultDataProvider(sourceParam, dimSize) {
  19972. // let source: Source;
  19973. var source = !isSourceInstance(sourceParam) ? createSourceFromSeriesDataOption(sourceParam) : sourceParam;
  19974. // declare source is Source;
  19975. this._source = source;
  19976. var data = this._data = source.data;
  19977. var sourceFormat = source.sourceFormat;
  19978. var seriesLayoutBy = source.seriesLayoutBy;
  19979. // Typed array. TODO IE10+?
  19980. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  19981. if ("development" !== 'production') {
  19982. if (dimSize == null) {
  19983. throw new Error('Typed array data must specify dimension size');
  19984. }
  19985. }
  19986. this._offset = 0;
  19987. this._dimSize = dimSize;
  19988. this._data = data;
  19989. }
  19990. if ("development" !== 'production') {
  19991. var validator = rawSourceDataValidatorMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  19992. validator && validator(data, source.dimensionsDefine);
  19993. }
  19994. mountMethods(this, data, source);
  19995. }
  19996. DefaultDataProvider.prototype.getSource = function () {
  19997. return this._source;
  19998. };
  19999. DefaultDataProvider.prototype.count = function () {
  20000. return 0;
  20001. };
  20002. DefaultDataProvider.prototype.getItem = function (idx, out) {
  20003. return;
  20004. };
  20005. DefaultDataProvider.prototype.appendData = function (newData) {};
  20006. DefaultDataProvider.prototype.clean = function () {};
  20007. DefaultDataProvider.protoInitialize = function () {
  20008. // PENDING: To avoid potential incompat (e.g., prototype
  20009. // is visited somewhere), still init them on prototype.
  20010. var proto = DefaultDataProvider.prototype;
  20011. proto.pure = false;
  20012. proto.persistent = true;
  20013. }();
  20014. DefaultDataProvider.internalField = function () {
  20015. var _a;
  20016. mountMethods = function (provider, data, source) {
  20017. var sourceFormat = source.sourceFormat;
  20018. var seriesLayoutBy = source.seriesLayoutBy;
  20019. var startIndex = source.startIndex;
  20020. var dimsDef = source.dimensionsDefine;
  20021. var methods = providerMethods[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20022. if ("development" !== 'production') {
  20023. assert(methods, 'Invalide sourceFormat: ' + sourceFormat);
  20024. }
  20025. extend(provider, methods);
  20026. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20027. provider.getItem = getItemForTypedArray;
  20028. provider.count = countForTypedArray;
  20029. provider.fillStorage = fillStorageForTypedArray;
  20030. } else {
  20031. var rawItemGetter = getRawSourceItemGetter(sourceFormat, seriesLayoutBy);
  20032. provider.getItem = bind(rawItemGetter, null, data, startIndex, dimsDef);
  20033. var rawCounter = getRawSourceDataCounter(sourceFormat, seriesLayoutBy);
  20034. provider.count = bind(rawCounter, null, data, startIndex, dimsDef);
  20035. }
  20036. };
  20037. var getItemForTypedArray = function (idx, out) {
  20038. idx = idx - this._offset;
  20039. out = out || [];
  20040. var data = this._data;
  20041. var dimSize = this._dimSize;
  20042. var offset = dimSize * idx;
  20043. for (var i = 0; i < dimSize; i++) {
  20044. out[i] = data[offset + i];
  20045. }
  20046. return out;
  20047. };
  20048. var fillStorageForTypedArray = function (start, end, storage, extent) {
  20049. var data = this._data;
  20050. var dimSize = this._dimSize;
  20051. for (var dim = 0; dim < dimSize; dim++) {
  20052. var dimExtent = extent[dim];
  20053. var min = dimExtent[0] == null ? Infinity : dimExtent[0];
  20054. var max = dimExtent[1] == null ? -Infinity : dimExtent[1];
  20055. var count = end - start;
  20056. var arr = storage[dim];
  20057. for (var i = 0; i < count; i++) {
  20058. // appendData with TypedArray will always do replace in provider.
  20059. var val = data[i * dimSize + dim];
  20060. arr[start + i] = val;
  20061. val < min && (min = val);
  20062. val > max && (max = val);
  20063. }
  20064. dimExtent[0] = min;
  20065. dimExtent[1] = max;
  20066. }
  20067. };
  20068. var countForTypedArray = function () {
  20069. return this._data ? this._data.length / this._dimSize : 0;
  20070. };
  20071. providerMethods = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = {
  20072. pure: true,
  20073. appendData: appendDataSimply
  20074. }, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = {
  20075. pure: true,
  20076. appendData: function () {
  20077. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  20078. }
  20079. }, _a[SOURCE_FORMAT_OBJECT_ROWS] = {
  20080. pure: true,
  20081. appendData: appendDataSimply
  20082. }, _a[SOURCE_FORMAT_KEYED_COLUMNS] = {
  20083. pure: true,
  20084. appendData: function (newData) {
  20085. var data = this._data;
  20086. each(newData, function (newCol, key) {
  20087. var oldCol = data[key] || (data[key] = []);
  20088. for (var i = 0; i < (newCol || []).length; i++) {
  20089. oldCol.push(newCol[i]);
  20090. }
  20091. });
  20092. }
  20093. }, _a[SOURCE_FORMAT_ORIGINAL] = {
  20094. appendData: appendDataSimply
  20095. }, _a[SOURCE_FORMAT_TYPED_ARRAY] = {
  20096. persistent: false,
  20097. pure: true,
  20098. appendData: function (newData) {
  20099. if ("development" !== 'production') {
  20100. assert(isTypedArray(newData), 'Added data must be TypedArray if data in initialization is TypedArray');
  20101. }
  20102. this._data = newData;
  20103. },
  20104. // Clean self if data is already used.
  20105. clean: function () {
  20106. // PENDING
  20107. this._offset += this.count();
  20108. this._data = null;
  20109. }
  20110. }, _a);
  20111. function appendDataSimply(newData) {
  20112. for (var i = 0; i < newData.length; i++) {
  20113. this._data.push(newData[i]);
  20114. }
  20115. }
  20116. }();
  20117. return DefaultDataProvider;
  20118. }();
  20119. var validateSimply = function (rawData) {
  20120. if (!isArray(rawData)) {
  20121. error('series.data or dataset.source must be an array.');
  20122. }
  20123. };
  20124. /**
  20125. * Only run in dev mode - hint users for debug.
  20126. */
  20127. var rawSourceDataValidatorMap = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = validateSimply, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = validateSimply, _a[SOURCE_FORMAT_OBJECT_ROWS] = validateSimply, _a[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, dimsDef) {
  20128. for (var i = 0; i < dimsDef.length; i++) {
  20129. var dimName = dimsDef[i].name;
  20130. if (dimName == null) {
  20131. error('dimension name must not be null/undefined.');
  20132. }
  20133. }
  20134. }, _a[SOURCE_FORMAT_ORIGINAL] = validateSimply, _a);
  20135. var getItemSimply = function (rawData, startIndex, dimsDef, idx) {
  20136. return rawData[idx];
  20137. };
  20138. var rawSourceItemGetterMap = (_b = {}, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef, idx) {
  20139. return rawData[idx + startIndex];
  20140. }, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef, idx, out) {
  20141. idx += startIndex;
  20142. var item = out || [];
  20143. var data = rawData;
  20144. for (var i = 0; i < data.length; i++) {
  20145. var row = data[i];
  20146. item[i] = row ? row[idx] : null;
  20147. }
  20148. return item;
  20149. }, _b[SOURCE_FORMAT_OBJECT_ROWS] = getItemSimply, _b[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef, idx, out) {
  20150. var item = out || [];
  20151. for (var i = 0; i < dimsDef.length; i++) {
  20152. var dimName = dimsDef[i].name;
  20153. var col = dimName != null ? rawData[dimName] : null;
  20154. item[i] = col ? col[idx] : null;
  20155. }
  20156. return item;
  20157. }, _b[SOURCE_FORMAT_ORIGINAL] = getItemSimply, _b);
  20158. function getRawSourceItemGetter(sourceFormat, seriesLayoutBy) {
  20159. var method = rawSourceItemGetterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20160. if ("development" !== 'production') {
  20161. assert(method, 'Do not support get item on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  20162. }
  20163. return method;
  20164. }
  20165. var countSimply = function (rawData, startIndex, dimsDef) {
  20166. return rawData.length;
  20167. };
  20168. var rawSourceDataCounterMap = (_c = {}, _c[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef) {
  20169. return Math.max(0, rawData.length - startIndex);
  20170. }, _c[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef) {
  20171. var row = rawData[0];
  20172. return row ? Math.max(0, row.length - startIndex) : 0;
  20173. }, _c[SOURCE_FORMAT_OBJECT_ROWS] = countSimply, _c[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef) {
  20174. var dimName = dimsDef[0].name;
  20175. var col = dimName != null ? rawData[dimName] : null;
  20176. return col ? col.length : 0;
  20177. }, _c[SOURCE_FORMAT_ORIGINAL] = countSimply, _c);
  20178. function getRawSourceDataCounter(sourceFormat, seriesLayoutBy) {
  20179. var method = rawSourceDataCounterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20180. if ("development" !== 'production') {
  20181. assert(method, 'Do not support count on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  20182. }
  20183. return method;
  20184. }
  20185. var getRawValueSimply = function (dataItem, dimIndex, property) {
  20186. return dataItem[dimIndex];
  20187. };
  20188. var rawSourceValueGetterMap = (_d = {}, _d[SOURCE_FORMAT_ARRAY_ROWS] = getRawValueSimply, _d[SOURCE_FORMAT_OBJECT_ROWS] = function (dataItem, dimIndex, property) {
  20189. return dataItem[property];
  20190. }, _d[SOURCE_FORMAT_KEYED_COLUMNS] = getRawValueSimply, _d[SOURCE_FORMAT_ORIGINAL] = function (dataItem, dimIndex, property) {
  20191. // FIXME: In some case (markpoint in geo (geo-map.html)),
  20192. // dataItem is {coord: [...]}
  20193. var value = getDataItemValue(dataItem);
  20194. return !(value instanceof Array) ? value : value[dimIndex];
  20195. }, _d[SOURCE_FORMAT_TYPED_ARRAY] = getRawValueSimply, _d);
  20196. function getRawSourceValueGetter(sourceFormat) {
  20197. var method = rawSourceValueGetterMap[sourceFormat];
  20198. if ("development" !== 'production') {
  20199. assert(method, 'Do not support get value on "' + sourceFormat + '".');
  20200. }
  20201. return method;
  20202. }
  20203. function getMethodMapKey(sourceFormat, seriesLayoutBy) {
  20204. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + seriesLayoutBy : sourceFormat;
  20205. }
  20206. // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  20207. // Consider persistent.
  20208. // Caution: why use raw value to display on label or tooltip?
  20209. // A reason is to avoid format. For example time value we do not know
  20210. // how to format is expected. More over, if stack is used, calculated
  20211. // value may be 0.91000000001, which have brings trouble to display.
  20212. // TODO: consider how to treat null/undefined/NaN when display?
  20213. function retrieveRawValue(data, dataIndex,
  20214. // If dimIndex is null/undefined, return OptionDataItem.
  20215. // Otherwise, return OptionDataValue.
  20216. dim) {
  20217. if (!data) {
  20218. return;
  20219. }
  20220. // Consider data may be not persistent.
  20221. var dataItem = data.getRawDataItem(dataIndex);
  20222. if (dataItem == null) {
  20223. return;
  20224. }
  20225. var store = data.getStore();
  20226. var sourceFormat = store.getSource().sourceFormat;
  20227. if (dim != null) {
  20228. var dimIndex = data.getDimensionIndex(dim);
  20229. var property = store.getDimensionProperty(dimIndex);
  20230. return getRawSourceValueGetter(sourceFormat)(dataItem, dimIndex, property);
  20231. } else {
  20232. var result = dataItem;
  20233. if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  20234. result = getDataItemValue(dataItem);
  20235. }
  20236. return result;
  20237. }
  20238. }
  20239. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  20240. var DataFormatMixin = /** @class */function () {
  20241. function DataFormatMixin() {}
  20242. /**
  20243. * Get params for formatter
  20244. */
  20245. DataFormatMixin.prototype.getDataParams = function (dataIndex, dataType) {
  20246. var data = this.getData(dataType);
  20247. var rawValue = this.getRawValue(dataIndex, dataType);
  20248. var rawDataIndex = data.getRawIndex(dataIndex);
  20249. var name = data.getName(dataIndex);
  20250. var itemOpt = data.getRawDataItem(dataIndex);
  20251. var style = data.getItemVisual(dataIndex, 'style');
  20252. var color = style && style[data.getItemVisual(dataIndex, 'drawType') || 'fill'];
  20253. var borderColor = style && style.stroke;
  20254. var mainType = this.mainType;
  20255. var isSeries = mainType === 'series';
  20256. var userOutput = data.userOutput && data.userOutput.get();
  20257. return {
  20258. componentType: mainType,
  20259. componentSubType: this.subType,
  20260. componentIndex: this.componentIndex,
  20261. seriesType: isSeries ? this.subType : null,
  20262. seriesIndex: this.seriesIndex,
  20263. seriesId: isSeries ? this.id : null,
  20264. seriesName: isSeries ? this.name : null,
  20265. name: name,
  20266. dataIndex: rawDataIndex,
  20267. data: itemOpt,
  20268. dataType: dataType,
  20269. value: rawValue,
  20270. color: color,
  20271. borderColor: borderColor,
  20272. dimensionNames: userOutput ? userOutput.fullDimensions : null,
  20273. encode: userOutput ? userOutput.encode : null,
  20274. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  20275. $vars: ['seriesName', 'name', 'value']
  20276. };
  20277. };
  20278. /**
  20279. * Format label
  20280. * @param dataIndex
  20281. * @param status 'normal' by default
  20282. * @param dataType
  20283. * @param labelDimIndex Only used in some chart that
  20284. * use formatter in different dimensions, like radar.
  20285. * @param formatter Formatter given outside.
  20286. * @return return null/undefined if no formatter
  20287. */
  20288. DataFormatMixin.prototype.getFormattedLabel = function (dataIndex, status, dataType, labelDimIndex, formatter, extendParams) {
  20289. status = status || 'normal';
  20290. var data = this.getData(dataType);
  20291. var params = this.getDataParams(dataIndex, dataType);
  20292. if (extendParams) {
  20293. params.value = extendParams.interpolatedValue;
  20294. }
  20295. if (labelDimIndex != null && isArray(params.value)) {
  20296. params.value = params.value[labelDimIndex];
  20297. }
  20298. if (!formatter) {
  20299. var itemModel = data.getItemModel(dataIndex);
  20300. // @ts-ignore
  20301. formatter = itemModel.get(status === 'normal' ? ['label', 'formatter'] : [status, 'label', 'formatter']);
  20302. }
  20303. if (isFunction(formatter)) {
  20304. params.status = status;
  20305. params.dimensionIndex = labelDimIndex;
  20306. return formatter(params);
  20307. } else if (isString(formatter)) {
  20308. var str = formatTpl(formatter, params);
  20309. // Support 'aaa{@[3]}bbb{@product}ccc'.
  20310. // Do not support '}' in dim name util have to.
  20311. return str.replace(DIMENSION_LABEL_REG, function (origin, dimStr) {
  20312. var len = dimStr.length;
  20313. var dimLoose = dimStr;
  20314. if (dimLoose.charAt(0) === '[' && dimLoose.charAt(len - 1) === ']') {
  20315. dimLoose = +dimLoose.slice(1, len - 1); // Also support: '[]' => 0
  20316. if ("development" !== 'production') {
  20317. if (isNaN(dimLoose)) {
  20318. error("Invalide label formatter: @" + dimStr + ", only support @[0], @[1], @[2], ...");
  20319. }
  20320. }
  20321. }
  20322. var val = retrieveRawValue(data, dataIndex, dimLoose);
  20323. if (extendParams && isArray(extendParams.interpolatedValue)) {
  20324. var dimIndex = data.getDimensionIndex(dimLoose);
  20325. if (dimIndex >= 0) {
  20326. val = extendParams.interpolatedValue[dimIndex];
  20327. }
  20328. }
  20329. return val != null ? val + '' : '';
  20330. });
  20331. }
  20332. };
  20333. /**
  20334. * Get raw value in option
  20335. */
  20336. DataFormatMixin.prototype.getRawValue = function (idx, dataType) {
  20337. return retrieveRawValue(this.getData(dataType), idx);
  20338. };
  20339. /**
  20340. * Should be implemented.
  20341. * @param {number} dataIndex
  20342. * @param {boolean} [multipleSeries=false]
  20343. * @param {string} [dataType]
  20344. */
  20345. DataFormatMixin.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  20346. // Empty function
  20347. return;
  20348. };
  20349. return DataFormatMixin;
  20350. }();
  20351. /**
  20352. * @param {Object} define
  20353. * @return See the return of `createTask`.
  20354. */
  20355. function createTask(define) {
  20356. return new Task(define);
  20357. }
  20358. var Task = /** @class */function () {
  20359. function Task(define) {
  20360. define = define || {};
  20361. this._reset = define.reset;
  20362. this._plan = define.plan;
  20363. this._count = define.count;
  20364. this._onDirty = define.onDirty;
  20365. this._dirty = true;
  20366. }
  20367. /**
  20368. * @param step Specified step.
  20369. * @param skip Skip customer perform call.
  20370. * @param modBy Sampling window size.
  20371. * @param modDataCount Sampling count.
  20372. * @return whether unfinished.
  20373. */
  20374. Task.prototype.perform = function (performArgs) {
  20375. var upTask = this._upstream;
  20376. var skip = performArgs && performArgs.skip;
  20377. // TODO some refactor.
  20378. // Pull data. Must pull data each time, because context.data
  20379. // may be updated by Series.setData.
  20380. if (this._dirty && upTask) {
  20381. var context = this.context;
  20382. context.data = context.outputData = upTask.context.outputData;
  20383. }
  20384. if (this.__pipeline) {
  20385. this.__pipeline.currentTask = this;
  20386. }
  20387. var planResult;
  20388. if (this._plan && !skip) {
  20389. planResult = this._plan(this.context);
  20390. }
  20391. // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  20392. // elements uniformed distributed when progress, especially when moving or zooming.
  20393. var lastModBy = normalizeModBy(this._modBy);
  20394. var lastModDataCount = this._modDataCount || 0;
  20395. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  20396. var modDataCount = performArgs && performArgs.modDataCount || 0;
  20397. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  20398. planResult = 'reset';
  20399. }
  20400. function normalizeModBy(val) {
  20401. !(val >= 1) && (val = 1); // jshint ignore:line
  20402. return val;
  20403. }
  20404. var forceFirstProgress;
  20405. if (this._dirty || planResult === 'reset') {
  20406. this._dirty = false;
  20407. forceFirstProgress = this._doReset(skip);
  20408. }
  20409. this._modBy = modBy;
  20410. this._modDataCount = modDataCount;
  20411. var step = performArgs && performArgs.step;
  20412. if (upTask) {
  20413. if ("development" !== 'production') {
  20414. assert(upTask._outputDueEnd != null);
  20415. }
  20416. this._dueEnd = upTask._outputDueEnd;
  20417. }
  20418. // DataTask or overallTask
  20419. else {
  20420. if ("development" !== 'production') {
  20421. assert(!this._progress || this._count);
  20422. }
  20423. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  20424. }
  20425. // Note: Stubs, that its host overall task let it has progress, has progress.
  20426. // If no progress, pass index from upstream to downstream each time plan called.
  20427. if (this._progress) {
  20428. var start = this._dueIndex;
  20429. var end = Math.min(step != null ? this._dueIndex + step : Infinity, this._dueEnd);
  20430. if (!skip && (forceFirstProgress || start < end)) {
  20431. var progress = this._progress;
  20432. if (isArray(progress)) {
  20433. for (var i = 0; i < progress.length; i++) {
  20434. this._doProgress(progress[i], start, end, modBy, modDataCount);
  20435. }
  20436. } else {
  20437. this._doProgress(progress, start, end, modBy, modDataCount);
  20438. }
  20439. }
  20440. this._dueIndex = end;
  20441. // If no `outputDueEnd`, assume that output data and
  20442. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  20443. var outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : end;
  20444. if ("development" !== 'production') {
  20445. // ??? Can not rollback.
  20446. assert(outputDueEnd >= this._outputDueEnd);
  20447. }
  20448. this._outputDueEnd = outputDueEnd;
  20449. } else {
  20450. // (1) Some overall task has no progress.
  20451. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  20452. // This should always be performed so it can be passed to downstream.
  20453. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : this._dueEnd;
  20454. }
  20455. return this.unfinished();
  20456. };
  20457. Task.prototype.dirty = function () {
  20458. this._dirty = true;
  20459. this._onDirty && this._onDirty(this.context);
  20460. };
  20461. Task.prototype._doProgress = function (progress, start, end, modBy, modDataCount) {
  20462. iterator.reset(start, end, modBy, modDataCount);
  20463. this._callingProgress = progress;
  20464. this._callingProgress({
  20465. start: start,
  20466. end: end,
  20467. count: end - start,
  20468. next: iterator.next
  20469. }, this.context);
  20470. };
  20471. Task.prototype._doReset = function (skip) {
  20472. this._dueIndex = this._outputDueEnd = this._dueEnd = 0;
  20473. this._settedOutputEnd = null;
  20474. var progress;
  20475. var forceFirstProgress;
  20476. if (!skip && this._reset) {
  20477. progress = this._reset(this.context);
  20478. if (progress && progress.progress) {
  20479. forceFirstProgress = progress.forceFirstProgress;
  20480. progress = progress.progress;
  20481. }
  20482. // To simplify no progress checking, array must has item.
  20483. if (isArray(progress) && !progress.length) {
  20484. progress = null;
  20485. }
  20486. }
  20487. this._progress = progress;
  20488. this._modBy = this._modDataCount = null;
  20489. var downstream = this._downstream;
  20490. downstream && downstream.dirty();
  20491. return forceFirstProgress;
  20492. };
  20493. Task.prototype.unfinished = function () {
  20494. return this._progress && this._dueIndex < this._dueEnd;
  20495. };
  20496. /**
  20497. * @param downTask The downstream task.
  20498. * @return The downstream task.
  20499. */
  20500. Task.prototype.pipe = function (downTask) {
  20501. if ("development" !== 'production') {
  20502. assert(downTask && !downTask._disposed && downTask !== this);
  20503. }
  20504. // If already downstream, do not dirty downTask.
  20505. if (this._downstream !== downTask || this._dirty) {
  20506. this._downstream = downTask;
  20507. downTask._upstream = this;
  20508. downTask.dirty();
  20509. }
  20510. };
  20511. Task.prototype.dispose = function () {
  20512. if (this._disposed) {
  20513. return;
  20514. }
  20515. this._upstream && (this._upstream._downstream = null);
  20516. this._downstream && (this._downstream._upstream = null);
  20517. this._dirty = false;
  20518. this._disposed = true;
  20519. };
  20520. Task.prototype.getUpstream = function () {
  20521. return this._upstream;
  20522. };
  20523. Task.prototype.getDownstream = function () {
  20524. return this._downstream;
  20525. };
  20526. Task.prototype.setOutputEnd = function (end) {
  20527. // This only happens in dataTask, dataZoom, map, currently.
  20528. // where dataZoom do not set end each time, but only set
  20529. // when reset. So we should record the set end, in case
  20530. // that the stub of dataZoom perform again and earse the
  20531. // set end by upstream.
  20532. this._outputDueEnd = this._settedOutputEnd = end;
  20533. };
  20534. return Task;
  20535. }();
  20536. var iterator = function () {
  20537. var end;
  20538. var current;
  20539. var modBy;
  20540. var modDataCount;
  20541. var winCount;
  20542. var it = {
  20543. reset: function (s, e, sStep, sCount) {
  20544. current = s;
  20545. end = e;
  20546. modBy = sStep;
  20547. modDataCount = sCount;
  20548. winCount = Math.ceil(modDataCount / modBy);
  20549. it.next = modBy > 1 && modDataCount > 0 ? modNext : sequentialNext;
  20550. }
  20551. };
  20552. return it;
  20553. function sequentialNext() {
  20554. return current < end ? current++ : null;
  20555. }
  20556. function modNext() {
  20557. var dataIndex = current % winCount * modBy + Math.ceil(current / winCount);
  20558. var result = current >= end ? null : dataIndex < modDataCount ? dataIndex
  20559. // If modDataCount is smaller than data.count() (consider `appendData` case),
  20560. // Use normal linear rendering mode.
  20561. : current;
  20562. current++;
  20563. return result;
  20564. }
  20565. }();
  20566. // -----------------------------------------------------------------------------
  20567. // For stream debug (Should be commented out after used!)
  20568. // @usage: printTask(this, 'begin');
  20569. // @usage: printTask(this, null, {someExtraProp});
  20570. // @usage: Use `__idxInPipeline` as conditional breakpiont.
  20571. //
  20572. // window.printTask = function (task: any, prefix: string, extra: { [key: string]: unknown }): void {
  20573. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  20574. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  20575. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  20576. // let props = [];
  20577. // if (task.__pipeline) {
  20578. // let val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  20579. // props.push({text: '__idxInPipeline/total', value: val});
  20580. // } else {
  20581. // let stubCount = 0;
  20582. // task.agentStubMap.each(() => stubCount++);
  20583. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  20584. // }
  20585. // props.push({text: 'uid', value: task.uidDebug});
  20586. // if (task.__pipeline) {
  20587. // props.push({text: 'pipelineId', value: task.__pipeline.id});
  20588. // task.agent && props.push(
  20589. // {text: 'stubFor', value: task.agent.uidDebug}
  20590. // );
  20591. // }
  20592. // props.push(
  20593. // {text: 'dirty', value: task._dirty},
  20594. // {text: 'dueIndex', value: task._dueIndex},
  20595. // {text: 'dueEnd', value: task._dueEnd},
  20596. // {text: 'outputDueEnd', value: task._outputDueEnd}
  20597. // );
  20598. // if (extra) {
  20599. // Object.keys(extra).forEach(key => {
  20600. // props.push({text: key, value: extra[key]});
  20601. // });
  20602. // }
  20603. // let args = ['color: blue'];
  20604. // let msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  20605. // args.push('color: green', 'color: red'),
  20606. // `${item.text}: %c${item.value}`
  20607. // )).join('%c, ');
  20608. // console.log.apply(console, [msg].concat(args));
  20609. // // console.log(this);
  20610. // };
  20611. // window.printPipeline = function (task: any, prefix: string) {
  20612. // const pipeline = task.__pipeline;
  20613. // let currTask = pipeline.head;
  20614. // while (currTask) {
  20615. // window.printTask(currTask, prefix);
  20616. // currTask = currTask._downstream;
  20617. // }
  20618. // };
  20619. // window.showChain = function (chainHeadTask) {
  20620. // var chain = [];
  20621. // var task = chainHeadTask;
  20622. // while (task) {
  20623. // chain.push({
  20624. // task: task,
  20625. // up: task._upstream,
  20626. // down: task._downstream,
  20627. // idxInPipeline: task.__idxInPipeline
  20628. // });
  20629. // task = task._downstream;
  20630. // }
  20631. // return chain;
  20632. // };
  20633. // window.findTaskInChain = function (task, chainHeadTask) {
  20634. // let chain = window.showChain(chainHeadTask);
  20635. // let result = [];
  20636. // for (let i = 0; i < chain.length; i++) {
  20637. // let chainItem = chain[i];
  20638. // if (chainItem.task === task) {
  20639. // result.push(i);
  20640. // }
  20641. // }
  20642. // return result;
  20643. // };
  20644. // window.printChainAEachInChainB = function (chainHeadTaskA, chainHeadTaskB) {
  20645. // let chainA = window.showChain(chainHeadTaskA);
  20646. // for (let i = 0; i < chainA.length; i++) {
  20647. // console.log('chainAIdx:', i, 'inChainB:', window.findTaskInChain(chainA[i].task, chainHeadTaskB));
  20648. // }
  20649. // };
  20650. /**
  20651. * Convert raw the value in to inner value in List.
  20652. *
  20653. * [Performance sensitive]
  20654. *
  20655. * [Caution]: this is the key logic of user value parser.
  20656. * For backward compatibility, do not modify it until you have to!
  20657. */
  20658. function parseDataValue(value,
  20659. // For high performance, do not omit the second param.
  20660. opt) {
  20661. // Performance sensitive.
  20662. var dimType = opt && opt.type;
  20663. if (dimType === 'ordinal') {
  20664. // If given value is a category string
  20665. return value;
  20666. }
  20667. if (dimType === 'time'
  20668. // spead up when using timestamp
  20669. && !isNumber(value) && value != null && value !== '-') {
  20670. value = +parseDate(value);
  20671. }
  20672. // dimType defaults 'number'.
  20673. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  20674. // parse to NaN.
  20675. // number-like string (like ' 123 ') can be converted to a number.
  20676. // where null/undefined or other string will be converted to NaN.
  20677. return value == null || value === '' ? NaN
  20678. // If string (like '-'), using '+' parse to NaN
  20679. // If object, also parse to NaN
  20680. : Number(value);
  20681. }
  20682. var valueParserMap = createHashMap({
  20683. 'number': function (val) {
  20684. // Do not use `numericToNumber` here. We have `numericToNumber` by default.
  20685. // Here the number parser can have loose rule:
  20686. // enable to cut suffix: "120px" => 120, "14%" => 14.
  20687. return parseFloat(val);
  20688. },
  20689. 'time': function (val) {
  20690. // return timestamp.
  20691. return +parseDate(val);
  20692. },
  20693. 'trim': function (val) {
  20694. return isString(val) ? trim(val) : val;
  20695. }
  20696. });
  20697. /**
  20698. * TODO: disable writable.
  20699. * This structure will be exposed to users.
  20700. */
  20701. var ExternalSource = /** @class */function () {
  20702. function ExternalSource() {}
  20703. ExternalSource.prototype.getRawData = function () {
  20704. // Only built-in transform available.
  20705. throw new Error('not supported');
  20706. };
  20707. ExternalSource.prototype.getRawDataItem = function (dataIndex) {
  20708. // Only built-in transform available.
  20709. throw new Error('not supported');
  20710. };
  20711. ExternalSource.prototype.cloneRawData = function () {
  20712. return;
  20713. };
  20714. /**
  20715. * @return If dimension not found, return null/undefined.
  20716. */
  20717. ExternalSource.prototype.getDimensionInfo = function (dim) {
  20718. return;
  20719. };
  20720. /**
  20721. * dimensions defined if and only if either:
  20722. * (a) dataset.dimensions are declared.
  20723. * (b) dataset data include dimensions definitions in data (detected or via specified `sourceHeader`).
  20724. * If dimensions are defined, `dimensionInfoAll` is corresponding to
  20725. * the defined dimensions.
  20726. * Otherwise, `dimensionInfoAll` is determined by data columns.
  20727. * @return Always return an array (even empty array).
  20728. */
  20729. ExternalSource.prototype.cloneAllDimensionInfo = function () {
  20730. return;
  20731. };
  20732. ExternalSource.prototype.count = function () {
  20733. return;
  20734. };
  20735. /**
  20736. * Only support by dimension index.
  20737. * No need to support by dimension name in transform function,
  20738. * because transform function is not case-specific, no need to use name literally.
  20739. */
  20740. ExternalSource.prototype.retrieveValue = function (dataIndex, dimIndex) {
  20741. return;
  20742. };
  20743. ExternalSource.prototype.retrieveValueFromItem = function (dataItem, dimIndex) {
  20744. return;
  20745. };
  20746. ExternalSource.prototype.convertValue = function (rawVal, dimInfo) {
  20747. return parseDataValue(rawVal, dimInfo);
  20748. };
  20749. return ExternalSource;
  20750. }();
  20751. function createExternalSource(internalSource, externalTransform) {
  20752. var extSource = new ExternalSource();
  20753. var data = internalSource.data;
  20754. var sourceFormat = extSource.sourceFormat = internalSource.sourceFormat;
  20755. var sourceHeaderCount = internalSource.startIndex;
  20756. var errMsg = '';
  20757. if (internalSource.seriesLayoutBy !== SERIES_LAYOUT_BY_COLUMN) {
  20758. // For the logic simplicity in transformer, only 'culumn' is
  20759. // supported in data transform. Otherwise, the `dimensionsDefine`
  20760. // might be detected by 'row', which probably confuses users.
  20761. if ("development" !== 'production') {
  20762. errMsg = '`seriesLayoutBy` of upstream dataset can only be "column" in data transform.';
  20763. }
  20764. throwError(errMsg);
  20765. }
  20766. // [MEMO]
  20767. // Create a new dimensions structure for exposing.
  20768. // Do not expose all dimension info to users directly.
  20769. // Because the dimension is probably auto detected from data and not might reliable.
  20770. // Should not lead the transformers to think that is reliable and return it.
  20771. // See [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  20772. var dimensions = [];
  20773. var dimsByName = {};
  20774. var dimsDef = internalSource.dimensionsDefine;
  20775. if (dimsDef) {
  20776. each(dimsDef, function (dimDef, idx) {
  20777. var name = dimDef.name;
  20778. var dimDefExt = {
  20779. index: idx,
  20780. name: name,
  20781. displayName: dimDef.displayName
  20782. };
  20783. dimensions.push(dimDefExt);
  20784. // Users probably do not specify dimension name. For simplicity, data transform
  20785. // does not generate dimension name.
  20786. if (name != null) {
  20787. // Dimension name should not be duplicated.
  20788. // For simplicity, data transform forbids name duplication, do not generate
  20789. // new name like module `completeDimensions.ts` did, but just tell users.
  20790. var errMsg_1 = '';
  20791. if (hasOwn(dimsByName, name)) {
  20792. if ("development" !== 'production') {
  20793. errMsg_1 = 'dimension name "' + name + '" duplicated.';
  20794. }
  20795. throwError(errMsg_1);
  20796. }
  20797. dimsByName[name] = dimDefExt;
  20798. }
  20799. });
  20800. }
  20801. // If dimension definitions are not defined and can not be detected.
  20802. // e.g., pure data `[[11, 22], ...]`.
  20803. else {
  20804. for (var i = 0; i < internalSource.dimensionsDetectedCount || 0; i++) {
  20805. // Do not generete name or anything others. The consequence process in
  20806. // `transform` or `series` probably have there own name generation strategry.
  20807. dimensions.push({
  20808. index: i
  20809. });
  20810. }
  20811. }
  20812. // Implement public methods:
  20813. var rawItemGetter = getRawSourceItemGetter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  20814. if (externalTransform.__isBuiltIn) {
  20815. extSource.getRawDataItem = function (dataIndex) {
  20816. return rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  20817. };
  20818. extSource.getRawData = bind(getRawData, null, internalSource);
  20819. }
  20820. extSource.cloneRawData = bind(cloneRawData, null, internalSource);
  20821. var rawCounter = getRawSourceDataCounter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  20822. extSource.count = bind(rawCounter, null, data, sourceHeaderCount, dimensions);
  20823. var rawValueGetter = getRawSourceValueGetter(sourceFormat);
  20824. extSource.retrieveValue = function (dataIndex, dimIndex) {
  20825. var rawItem = rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  20826. return retrieveValueFromItem(rawItem, dimIndex);
  20827. };
  20828. var retrieveValueFromItem = extSource.retrieveValueFromItem = function (dataItem, dimIndex) {
  20829. if (dataItem == null) {
  20830. return;
  20831. }
  20832. var dimDef = dimensions[dimIndex];
  20833. // When `dimIndex` is `null`, `rawValueGetter` return the whole item.
  20834. if (dimDef) {
  20835. return rawValueGetter(dataItem, dimIndex, dimDef.name);
  20836. }
  20837. };
  20838. extSource.getDimensionInfo = bind(getDimensionInfo, null, dimensions, dimsByName);
  20839. extSource.cloneAllDimensionInfo = bind(cloneAllDimensionInfo, null, dimensions);
  20840. return extSource;
  20841. }
  20842. function getRawData(upstream) {
  20843. var sourceFormat = upstream.sourceFormat;
  20844. if (!isSupportedSourceFormat(sourceFormat)) {
  20845. var errMsg = '';
  20846. if ("development" !== 'production') {
  20847. errMsg = '`getRawData` is not supported in source format ' + sourceFormat;
  20848. }
  20849. throwError(errMsg);
  20850. }
  20851. return upstream.data;
  20852. }
  20853. function cloneRawData(upstream) {
  20854. var sourceFormat = upstream.sourceFormat;
  20855. var data = upstream.data;
  20856. if (!isSupportedSourceFormat(sourceFormat)) {
  20857. var errMsg = '';
  20858. if ("development" !== 'production') {
  20859. errMsg = '`cloneRawData` is not supported in source format ' + sourceFormat;
  20860. }
  20861. throwError(errMsg);
  20862. }
  20863. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  20864. var result = [];
  20865. for (var i = 0, len = data.length; i < len; i++) {
  20866. // Not strictly clone for performance
  20867. result.push(data[i].slice());
  20868. }
  20869. return result;
  20870. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  20871. var result = [];
  20872. for (var i = 0, len = data.length; i < len; i++) {
  20873. // Not strictly clone for performance
  20874. result.push(extend({}, data[i]));
  20875. }
  20876. return result;
  20877. }
  20878. }
  20879. function getDimensionInfo(dimensions, dimsByName, dim) {
  20880. if (dim == null) {
  20881. return;
  20882. }
  20883. // Keep the same logic as `List::getDimension` did.
  20884. if (isNumber(dim)
  20885. // If being a number-like string but not being defined a dimension name.
  20886. || !isNaN(dim) && !hasOwn(dimsByName, dim)) {
  20887. return dimensions[dim];
  20888. } else if (hasOwn(dimsByName, dim)) {
  20889. return dimsByName[dim];
  20890. }
  20891. }
  20892. function cloneAllDimensionInfo(dimensions) {
  20893. return clone(dimensions);
  20894. }
  20895. var externalTransformMap = createHashMap();
  20896. function registerExternalTransform(externalTransform) {
  20897. externalTransform = clone(externalTransform);
  20898. var type = externalTransform.type;
  20899. var errMsg = '';
  20900. if (!type) {
  20901. if ("development" !== 'production') {
  20902. errMsg = 'Must have a `type` when `registerTransform`.';
  20903. }
  20904. throwError(errMsg);
  20905. }
  20906. var typeParsed = type.split(':');
  20907. if (typeParsed.length !== 2) {
  20908. if ("development" !== 'production') {
  20909. errMsg = 'Name must include namespace like "ns:regression".';
  20910. }
  20911. throwError(errMsg);
  20912. }
  20913. // Namespace 'echarts:xxx' is official namespace, where the transforms should
  20914. // be called directly via 'xxx' rather than 'echarts:xxx'.
  20915. var isBuiltIn = false;
  20916. if (typeParsed[0] === 'echarts') {
  20917. type = typeParsed[1];
  20918. isBuiltIn = true;
  20919. }
  20920. externalTransform.__isBuiltIn = isBuiltIn;
  20921. externalTransformMap.set(type, externalTransform);
  20922. }
  20923. function applyDataTransform(rawTransOption, sourceList, infoForPrint) {
  20924. var pipedTransOption = normalizeToArray(rawTransOption);
  20925. var pipeLen = pipedTransOption.length;
  20926. var errMsg = '';
  20927. if (!pipeLen) {
  20928. if ("development" !== 'production') {
  20929. errMsg = 'If `transform` declared, it should at least contain one transform.';
  20930. }
  20931. throwError(errMsg);
  20932. }
  20933. for (var i = 0, len = pipeLen; i < len; i++) {
  20934. var transOption = pipedTransOption[i];
  20935. sourceList = applySingleDataTransform(transOption, sourceList, infoForPrint, pipeLen === 1 ? null : i);
  20936. // piped transform only support single input, except the fist one.
  20937. // piped transform only support single output, except the last one.
  20938. if (i !== len - 1) {
  20939. sourceList.length = Math.max(sourceList.length, 1);
  20940. }
  20941. }
  20942. return sourceList;
  20943. }
  20944. function applySingleDataTransform(transOption, upSourceList, infoForPrint,
  20945. // If `pipeIndex` is null/undefined, no piped transform.
  20946. pipeIndex) {
  20947. var errMsg = '';
  20948. if (!upSourceList.length) {
  20949. if ("development" !== 'production') {
  20950. errMsg = 'Must have at least one upstream dataset.';
  20951. }
  20952. throwError(errMsg);
  20953. }
  20954. if (!isObject(transOption)) {
  20955. if ("development" !== 'production') {
  20956. errMsg = 'transform declaration must be an object rather than ' + typeof transOption + '.';
  20957. }
  20958. throwError(errMsg);
  20959. }
  20960. var transType = transOption.type;
  20961. var externalTransform = externalTransformMap.get(transType);
  20962. if (!externalTransform) {
  20963. if ("development" !== 'production') {
  20964. errMsg = 'Can not find transform on type "' + transType + '".';
  20965. }
  20966. throwError(errMsg);
  20967. }
  20968. // Prepare source
  20969. var extUpSourceList = map(upSourceList, function (upSource) {
  20970. return createExternalSource(upSource, externalTransform);
  20971. });
  20972. var resultList = normalizeToArray(externalTransform.transform({
  20973. upstream: extUpSourceList[0],
  20974. upstreamList: extUpSourceList,
  20975. config: clone(transOption.config)
  20976. }));
  20977. if ("development" !== 'production') {
  20978. if (transOption.print) {
  20979. var printStrArr = map(resultList, function (extSource) {
  20980. var pipeIndexStr = pipeIndex != null ? ' === pipe index: ' + pipeIndex : '';
  20981. return ['=== dataset index: ' + infoForPrint.datasetIndex + pipeIndexStr + ' ===', '- transform result data:', makePrintable(extSource.data), '- transform result dimensions:', makePrintable(extSource.dimensions)].join('\n');
  20982. }).join('\n');
  20983. log(printStrArr);
  20984. }
  20985. }
  20986. return map(resultList, function (result, resultIndex) {
  20987. var errMsg = '';
  20988. if (!isObject(result)) {
  20989. if ("development" !== 'production') {
  20990. errMsg = 'A transform should not return some empty results.';
  20991. }
  20992. throwError(errMsg);
  20993. }
  20994. if (!result.data) {
  20995. if ("development" !== 'production') {
  20996. errMsg = 'Transform result data should be not be null or undefined';
  20997. }
  20998. throwError(errMsg);
  20999. }
  21000. var sourceFormat = detectSourceFormat(result.data);
  21001. if (!isSupportedSourceFormat(sourceFormat)) {
  21002. if ("development" !== 'production') {
  21003. errMsg = 'Transform result data should be array rows or object rows.';
  21004. }
  21005. throwError(errMsg);
  21006. }
  21007. var resultMetaRawOption;
  21008. var firstUpSource = upSourceList[0];
  21009. /**
  21010. * Intuitively, the end users known the content of the original `dataset.source`,
  21011. * calucating the transform result in mind.
  21012. * Suppose the original `dataset.source` is:
  21013. * ```js
  21014. * [
  21015. * ['product', '2012', '2013', '2014', '2015'],
  21016. * ['AAA', 41.1, 30.4, 65.1, 53.3],
  21017. * ['BBB', 86.5, 92.1, 85.7, 83.1],
  21018. * ['CCC', 24.1, 67.2, 79.5, 86.4]
  21019. * ]
  21020. * ```
  21021. * The dimension info have to be detected from the source data.
  21022. * Some of the transformers (like filter, sort) will follow the dimension info
  21023. * of upstream, while others use new dimensions (like aggregate).
  21024. * Transformer can output a field `dimensions` to define the its own output dimensions.
  21025. * We also allow transformers to ignore the output `dimensions` field, and
  21026. * inherit the upstream dimensions definition. It can reduce the burden of handling
  21027. * dimensions in transformers.
  21028. *
  21029. * See also [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  21030. */
  21031. if (firstUpSource && resultIndex === 0
  21032. // If transformer returns `dimensions`, it means that the transformer has different
  21033. // dimensions definitions. We do not inherit anything from upstream.
  21034. && !result.dimensions) {
  21035. var startIndex = firstUpSource.startIndex;
  21036. // We copy the header of upstream to the result, because:
  21037. // (1) The returned data always does not contain header line and can not be used
  21038. // as dimension-detection. In this case we can not use "detected dimensions" of
  21039. // upstream directly, because it might be detected based on different `seriesLayoutBy`.
  21040. // (2) We should support that the series read the upstream source in `seriesLayoutBy: 'row'`.
  21041. // So the original detected header should be add to the result, otherwise they can not be read.
  21042. if (startIndex) {
  21043. result.data = firstUpSource.data.slice(0, startIndex).concat(result.data);
  21044. }
  21045. resultMetaRawOption = {
  21046. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  21047. sourceHeader: startIndex,
  21048. dimensions: firstUpSource.metaRawOption.dimensions
  21049. };
  21050. } else {
  21051. resultMetaRawOption = {
  21052. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  21053. sourceHeader: 0,
  21054. dimensions: result.dimensions
  21055. };
  21056. }
  21057. return createSource(result.data, resultMetaRawOption, null);
  21058. });
  21059. }
  21060. function isSupportedSourceFormat(sourceFormat) {
  21061. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS || sourceFormat === SOURCE_FORMAT_OBJECT_ROWS;
  21062. }
  21063. var UNDEFINED = 'undefined';
  21064. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  21065. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  21066. // different from the Ctor of typed array.
  21067. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  21068. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  21069. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  21070. var CtorFloat64Array = typeof Float64Array === UNDEFINED ? Array : Float64Array;
  21071. /**
  21072. * Multi dimensional data store
  21073. */
  21074. var dataCtors = {
  21075. 'float': CtorFloat64Array,
  21076. 'int': CtorInt32Array,
  21077. // Ordinal data type can be string or int
  21078. 'ordinal': Array,
  21079. 'number': Array,
  21080. 'time': CtorFloat64Array
  21081. };
  21082. var defaultDimValueGetters;
  21083. function getIndicesCtor(rawCount) {
  21084. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  21085. return rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  21086. }
  21087. function getInitialExtent() {
  21088. return [Infinity, -Infinity];
  21089. }
  21090. function cloneChunk(originalChunk) {
  21091. var Ctor = originalChunk.constructor;
  21092. // Only shallow clone is enough when Array.
  21093. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  21094. }
  21095. function prepareStore(store, dimIdx, dimType, end, append) {
  21096. var DataCtor = dataCtors[dimType || 'float'];
  21097. if (append) {
  21098. var oldStore = store[dimIdx];
  21099. var oldLen = oldStore && oldStore.length;
  21100. if (!(oldLen === end)) {
  21101. var newStore = new DataCtor(end);
  21102. // The cost of the copy is probably inconsiderable
  21103. // within the initial chunkSize.
  21104. for (var j = 0; j < oldLen; j++) {
  21105. newStore[j] = oldStore[j];
  21106. }
  21107. store[dimIdx] = newStore;
  21108. }
  21109. } else {
  21110. store[dimIdx] = new DataCtor(end);
  21111. }
  21112. }
  21113. /**
  21114. * Basically, DataStore API keep immutable.
  21115. */
  21116. var DataStore = /** @class */function () {
  21117. function DataStore() {
  21118. this._chunks = [];
  21119. // It will not be calculated until needed.
  21120. this._rawExtent = [];
  21121. this._extent = [];
  21122. this._count = 0;
  21123. this._rawCount = 0;
  21124. this._calcDimNameToIdx = createHashMap();
  21125. }
  21126. /**
  21127. * Initialize from data
  21128. */
  21129. DataStore.prototype.initData = function (provider, inputDimensions, dimValueGetter) {
  21130. if ("development" !== 'production') {
  21131. assert(isFunction(provider.getItem) && isFunction(provider.count), 'Invalid data provider.');
  21132. }
  21133. this._provider = provider;
  21134. // Clear
  21135. this._chunks = [];
  21136. this._indices = null;
  21137. this.getRawIndex = this._getRawIdxIdentity;
  21138. var source = provider.getSource();
  21139. var defaultGetter = this.defaultDimValueGetter = defaultDimValueGetters[source.sourceFormat];
  21140. // Default dim value getter
  21141. this._dimValueGetter = dimValueGetter || defaultGetter;
  21142. // Reset raw extent.
  21143. this._rawExtent = [];
  21144. var willRetrieveDataByName = shouldRetrieveDataByName(source);
  21145. this._dimensions = map(inputDimensions, function (dim) {
  21146. if ("development" !== 'production') {
  21147. if (willRetrieveDataByName) {
  21148. assert(dim.property != null);
  21149. }
  21150. }
  21151. return {
  21152. // Only pick these two props. Not leak other properties like orderMeta.
  21153. type: dim.type,
  21154. property: dim.property
  21155. };
  21156. });
  21157. this._initDataFromProvider(0, provider.count());
  21158. };
  21159. DataStore.prototype.getProvider = function () {
  21160. return this._provider;
  21161. };
  21162. /**
  21163. * Caution: even when a `source` instance owned by a series, the created data store
  21164. * may still be shared by different sereis (the source hash does not use all `source`
  21165. * props, see `sourceManager`). In this case, the `source` props that are not used in
  21166. * hash (like `source.dimensionDefine`) probably only belongs to a certain series and
  21167. * thus should not be fetch here.
  21168. */
  21169. DataStore.prototype.getSource = function () {
  21170. return this._provider.getSource();
  21171. };
  21172. /**
  21173. * @caution Only used in dataStack.
  21174. */
  21175. DataStore.prototype.ensureCalculationDimension = function (dimName, type) {
  21176. var calcDimNameToIdx = this._calcDimNameToIdx;
  21177. var dimensions = this._dimensions;
  21178. var calcDimIdx = calcDimNameToIdx.get(dimName);
  21179. if (calcDimIdx != null) {
  21180. if (dimensions[calcDimIdx].type === type) {
  21181. return calcDimIdx;
  21182. }
  21183. } else {
  21184. calcDimIdx = dimensions.length;
  21185. }
  21186. dimensions[calcDimIdx] = {
  21187. type: type
  21188. };
  21189. calcDimNameToIdx.set(dimName, calcDimIdx);
  21190. this._chunks[calcDimIdx] = new dataCtors[type || 'float'](this._rawCount);
  21191. this._rawExtent[calcDimIdx] = getInitialExtent();
  21192. return calcDimIdx;
  21193. };
  21194. DataStore.prototype.collectOrdinalMeta = function (dimIdx, ordinalMeta) {
  21195. var chunk = this._chunks[dimIdx];
  21196. var dim = this._dimensions[dimIdx];
  21197. var rawExtents = this._rawExtent;
  21198. var offset = dim.ordinalOffset || 0;
  21199. var len = chunk.length;
  21200. if (offset === 0) {
  21201. // We need to reset the rawExtent if collect is from start.
  21202. // Because this dimension may be guessed as number and calcuating a wrong extent.
  21203. rawExtents[dimIdx] = getInitialExtent();
  21204. }
  21205. var dimRawExtent = rawExtents[dimIdx];
  21206. // Parse from previous data offset. len may be changed after appendData
  21207. for (var i = offset; i < len; i++) {
  21208. var val = chunk[i] = ordinalMeta.parseAndCollect(chunk[i]);
  21209. if (!isNaN(val)) {
  21210. dimRawExtent[0] = Math.min(val, dimRawExtent[0]);
  21211. dimRawExtent[1] = Math.max(val, dimRawExtent[1]);
  21212. }
  21213. }
  21214. dim.ordinalMeta = ordinalMeta;
  21215. dim.ordinalOffset = len;
  21216. dim.type = 'ordinal'; // Force to be ordinal
  21217. };
  21218. DataStore.prototype.getOrdinalMeta = function (dimIdx) {
  21219. var dimInfo = this._dimensions[dimIdx];
  21220. var ordinalMeta = dimInfo.ordinalMeta;
  21221. return ordinalMeta;
  21222. };
  21223. DataStore.prototype.getDimensionProperty = function (dimIndex) {
  21224. var item = this._dimensions[dimIndex];
  21225. return item && item.property;
  21226. };
  21227. /**
  21228. * Caution: Can be only called on raw data (before `this._indices` created).
  21229. */
  21230. DataStore.prototype.appendData = function (data) {
  21231. if ("development" !== 'production') {
  21232. assert(!this._indices, 'appendData can only be called on raw data.');
  21233. }
  21234. var provider = this._provider;
  21235. var start = this.count();
  21236. provider.appendData(data);
  21237. var end = provider.count();
  21238. if (!provider.persistent) {
  21239. end += start;
  21240. }
  21241. if (start < end) {
  21242. this._initDataFromProvider(start, end, true);
  21243. }
  21244. return [start, end];
  21245. };
  21246. DataStore.prototype.appendValues = function (values, minFillLen) {
  21247. var chunks = this._chunks;
  21248. var dimensions = this._dimensions;
  21249. var dimLen = dimensions.length;
  21250. var rawExtent = this._rawExtent;
  21251. var start = this.count();
  21252. var end = start + Math.max(values.length, minFillLen || 0);
  21253. for (var i = 0; i < dimLen; i++) {
  21254. var dim = dimensions[i];
  21255. prepareStore(chunks, i, dim.type, end, true);
  21256. }
  21257. var emptyDataItem = [];
  21258. for (var idx = start; idx < end; idx++) {
  21259. var sourceIdx = idx - start;
  21260. // Store the data by dimensions
  21261. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  21262. var dim = dimensions[dimIdx];
  21263. var val = defaultDimValueGetters.arrayRows.call(this, values[sourceIdx] || emptyDataItem, dim.property, sourceIdx, dimIdx);
  21264. chunks[dimIdx][idx] = val;
  21265. var dimRawExtent = rawExtent[dimIdx];
  21266. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  21267. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  21268. }
  21269. }
  21270. this._rawCount = this._count = end;
  21271. return {
  21272. start: start,
  21273. end: end
  21274. };
  21275. };
  21276. DataStore.prototype._initDataFromProvider = function (start, end, append) {
  21277. var provider = this._provider;
  21278. var chunks = this._chunks;
  21279. var dimensions = this._dimensions;
  21280. var dimLen = dimensions.length;
  21281. var rawExtent = this._rawExtent;
  21282. var dimNames = map(dimensions, function (dim) {
  21283. return dim.property;
  21284. });
  21285. for (var i = 0; i < dimLen; i++) {
  21286. var dim = dimensions[i];
  21287. if (!rawExtent[i]) {
  21288. rawExtent[i] = getInitialExtent();
  21289. }
  21290. prepareStore(chunks, i, dim.type, end, append);
  21291. }
  21292. if (provider.fillStorage) {
  21293. provider.fillStorage(start, end, chunks, rawExtent);
  21294. } else {
  21295. var dataItem = [];
  21296. for (var idx = start; idx < end; idx++) {
  21297. // NOTICE: Try not to write things into dataItem
  21298. dataItem = provider.getItem(idx, dataItem);
  21299. // Each data item is value
  21300. // [1, 2]
  21301. // 2
  21302. // Bar chart, line chart which uses category axis
  21303. // only gives the 'y' value. 'x' value is the indices of category
  21304. // Use a tempValue to normalize the value to be a (x, y) value
  21305. // Store the data by dimensions
  21306. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  21307. var dimStorage = chunks[dimIdx];
  21308. // PENDING NULL is empty or zero
  21309. var val = this._dimValueGetter(dataItem, dimNames[dimIdx], idx, dimIdx);
  21310. dimStorage[idx] = val;
  21311. var dimRawExtent = rawExtent[dimIdx];
  21312. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  21313. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  21314. }
  21315. }
  21316. }
  21317. if (!provider.persistent && provider.clean) {
  21318. // Clean unused data if data source is typed array.
  21319. provider.clean();
  21320. }
  21321. this._rawCount = this._count = end;
  21322. // Reset data extent
  21323. this._extent = [];
  21324. };
  21325. DataStore.prototype.count = function () {
  21326. return this._count;
  21327. };
  21328. /**
  21329. * Get value. Return NaN if idx is out of range.
  21330. */
  21331. DataStore.prototype.get = function (dim, idx) {
  21332. if (!(idx >= 0 && idx < this._count)) {
  21333. return NaN;
  21334. }
  21335. var dimStore = this._chunks[dim];
  21336. return dimStore ? dimStore[this.getRawIndex(idx)] : NaN;
  21337. };
  21338. DataStore.prototype.getValues = function (dimensions, idx) {
  21339. var values = [];
  21340. var dimArr = [];
  21341. if (idx == null) {
  21342. idx = dimensions;
  21343. // TODO get all from store?
  21344. dimensions = [];
  21345. // All dimensions
  21346. for (var i = 0; i < this._dimensions.length; i++) {
  21347. dimArr.push(i);
  21348. }
  21349. } else {
  21350. dimArr = dimensions;
  21351. }
  21352. for (var i = 0, len = dimArr.length; i < len; i++) {
  21353. values.push(this.get(dimArr[i], idx));
  21354. }
  21355. return values;
  21356. };
  21357. /**
  21358. * @param dim concrete dim
  21359. */
  21360. DataStore.prototype.getByRawIndex = function (dim, rawIdx) {
  21361. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  21362. return NaN;
  21363. }
  21364. var dimStore = this._chunks[dim];
  21365. return dimStore ? dimStore[rawIdx] : NaN;
  21366. };
  21367. /**
  21368. * Get sum of data in one dimension
  21369. */
  21370. DataStore.prototype.getSum = function (dim) {
  21371. var dimData = this._chunks[dim];
  21372. var sum = 0;
  21373. if (dimData) {
  21374. for (var i = 0, len = this.count(); i < len; i++) {
  21375. var value = this.get(dim, i);
  21376. if (!isNaN(value)) {
  21377. sum += value;
  21378. }
  21379. }
  21380. }
  21381. return sum;
  21382. };
  21383. /**
  21384. * Get median of data in one dimension
  21385. */
  21386. DataStore.prototype.getMedian = function (dim) {
  21387. var dimDataArray = [];
  21388. // map all data of one dimension
  21389. this.each([dim], function (val) {
  21390. if (!isNaN(val)) {
  21391. dimDataArray.push(val);
  21392. }
  21393. });
  21394. // TODO
  21395. // Use quick select?
  21396. var sortedDimDataArray = dimDataArray.sort(function (a, b) {
  21397. return a - b;
  21398. });
  21399. var len = this.count();
  21400. // calculate median
  21401. return len === 0 ? 0 : len % 2 === 1 ? sortedDimDataArray[(len - 1) / 2] : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  21402. };
  21403. /**
  21404. * Retrieve the index with given raw data index.
  21405. */
  21406. DataStore.prototype.indexOfRawIndex = function (rawIndex) {
  21407. if (rawIndex >= this._rawCount || rawIndex < 0) {
  21408. return -1;
  21409. }
  21410. if (!this._indices) {
  21411. return rawIndex;
  21412. }
  21413. // Indices are ascending
  21414. var indices = this._indices;
  21415. // If rawIndex === dataIndex
  21416. var rawDataIndex = indices[rawIndex];
  21417. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  21418. return rawIndex;
  21419. }
  21420. var left = 0;
  21421. var right = this._count - 1;
  21422. while (left <= right) {
  21423. var mid = (left + right) / 2 | 0;
  21424. if (indices[mid] < rawIndex) {
  21425. left = mid + 1;
  21426. } else if (indices[mid] > rawIndex) {
  21427. right = mid - 1;
  21428. } else {
  21429. return mid;
  21430. }
  21431. }
  21432. return -1;
  21433. };
  21434. DataStore.prototype.getIndices = function () {
  21435. var newIndices;
  21436. var indices = this._indices;
  21437. if (indices) {
  21438. var Ctor = indices.constructor;
  21439. var thisCount = this._count;
  21440. // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  21441. if (Ctor === Array) {
  21442. newIndices = new Ctor(thisCount);
  21443. for (var i = 0; i < thisCount; i++) {
  21444. newIndices[i] = indices[i];
  21445. }
  21446. } else {
  21447. newIndices = new Ctor(indices.buffer, 0, thisCount);
  21448. }
  21449. } else {
  21450. var Ctor = getIndicesCtor(this._rawCount);
  21451. newIndices = new Ctor(this.count());
  21452. for (var i = 0; i < newIndices.length; i++) {
  21453. newIndices[i] = i;
  21454. }
  21455. }
  21456. return newIndices;
  21457. };
  21458. /**
  21459. * Data filter.
  21460. */
  21461. DataStore.prototype.filter = function (dims, cb) {
  21462. if (!this._count) {
  21463. return this;
  21464. }
  21465. var newStore = this.clone();
  21466. var count = newStore.count();
  21467. var Ctor = getIndicesCtor(newStore._rawCount);
  21468. var newIndices = new Ctor(count);
  21469. var value = [];
  21470. var dimSize = dims.length;
  21471. var offset = 0;
  21472. var dim0 = dims[0];
  21473. var chunks = newStore._chunks;
  21474. for (var i = 0; i < count; i++) {
  21475. var keep = void 0;
  21476. var rawIdx = newStore.getRawIndex(i);
  21477. // Simple optimization
  21478. if (dimSize === 0) {
  21479. keep = cb(i);
  21480. } else if (dimSize === 1) {
  21481. var val = chunks[dim0][rawIdx];
  21482. keep = cb(val, i);
  21483. } else {
  21484. var k = 0;
  21485. for (; k < dimSize; k++) {
  21486. value[k] = chunks[dims[k]][rawIdx];
  21487. }
  21488. value[k] = i;
  21489. keep = cb.apply(null, value);
  21490. }
  21491. if (keep) {
  21492. newIndices[offset++] = rawIdx;
  21493. }
  21494. }
  21495. // Set indices after filtered.
  21496. if (offset < count) {
  21497. newStore._indices = newIndices;
  21498. }
  21499. newStore._count = offset;
  21500. // Reset data extent
  21501. newStore._extent = [];
  21502. newStore._updateGetRawIdx();
  21503. return newStore;
  21504. };
  21505. /**
  21506. * Select data in range. (For optimization of filter)
  21507. * (Manually inline code, support 5 million data filtering in data zoom.)
  21508. */
  21509. DataStore.prototype.selectRange = function (range) {
  21510. var newStore = this.clone();
  21511. var len = newStore._count;
  21512. if (!len) {
  21513. return this;
  21514. }
  21515. var dims = keys(range);
  21516. var dimSize = dims.length;
  21517. if (!dimSize) {
  21518. return this;
  21519. }
  21520. var originalCount = newStore.count();
  21521. var Ctor = getIndicesCtor(newStore._rawCount);
  21522. var newIndices = new Ctor(originalCount);
  21523. var offset = 0;
  21524. var dim0 = dims[0];
  21525. var min = range[dim0][0];
  21526. var max = range[dim0][1];
  21527. var storeArr = newStore._chunks;
  21528. var quickFinished = false;
  21529. if (!newStore._indices) {
  21530. // Extreme optimization for common case. About 2x faster in chrome.
  21531. var idx = 0;
  21532. if (dimSize === 1) {
  21533. var dimStorage = storeArr[dims[0]];
  21534. for (var i = 0; i < len; i++) {
  21535. var val = dimStorage[i];
  21536. // NaN will not be filtered. Consider the case, in line chart, empty
  21537. // value indicates the line should be broken. But for the case like
  21538. // scatter plot, a data item with empty value will not be rendered,
  21539. // but the axis extent may be effected if some other dim of the data
  21540. // item has value. Fortunately it is not a significant negative effect.
  21541. if (val >= min && val <= max || isNaN(val)) {
  21542. newIndices[offset++] = idx;
  21543. }
  21544. idx++;
  21545. }
  21546. quickFinished = true;
  21547. } else if (dimSize === 2) {
  21548. var dimStorage = storeArr[dims[0]];
  21549. var dimStorage2 = storeArr[dims[1]];
  21550. var min2 = range[dims[1]][0];
  21551. var max2 = range[dims[1]][1];
  21552. for (var i = 0; i < len; i++) {
  21553. var val = dimStorage[i];
  21554. var val2 = dimStorage2[i];
  21555. // Do not filter NaN, see comment above.
  21556. if ((val >= min && val <= max || isNaN(val)) && (val2 >= min2 && val2 <= max2 || isNaN(val2))) {
  21557. newIndices[offset++] = idx;
  21558. }
  21559. idx++;
  21560. }
  21561. quickFinished = true;
  21562. }
  21563. }
  21564. if (!quickFinished) {
  21565. if (dimSize === 1) {
  21566. for (var i = 0; i < originalCount; i++) {
  21567. var rawIndex = newStore.getRawIndex(i);
  21568. var val = storeArr[dims[0]][rawIndex];
  21569. // Do not filter NaN, see comment above.
  21570. if (val >= min && val <= max || isNaN(val)) {
  21571. newIndices[offset++] = rawIndex;
  21572. }
  21573. }
  21574. } else {
  21575. for (var i = 0; i < originalCount; i++) {
  21576. var keep = true;
  21577. var rawIndex = newStore.getRawIndex(i);
  21578. for (var k = 0; k < dimSize; k++) {
  21579. var dimk = dims[k];
  21580. var val = storeArr[dimk][rawIndex];
  21581. // Do not filter NaN, see comment above.
  21582. if (val < range[dimk][0] || val > range[dimk][1]) {
  21583. keep = false;
  21584. }
  21585. }
  21586. if (keep) {
  21587. newIndices[offset++] = newStore.getRawIndex(i);
  21588. }
  21589. }
  21590. }
  21591. }
  21592. // Set indices after filtered.
  21593. if (offset < originalCount) {
  21594. newStore._indices = newIndices;
  21595. }
  21596. newStore._count = offset;
  21597. // Reset data extent
  21598. newStore._extent = [];
  21599. newStore._updateGetRawIdx();
  21600. return newStore;
  21601. };
  21602. // /**
  21603. // * Data mapping to a plain array
  21604. // */
  21605. // mapArray(dims: DimensionIndex[], cb: MapArrayCb): any[] {
  21606. // const result: any[] = [];
  21607. // this.each(dims, function () {
  21608. // result.push(cb && (cb as MapArrayCb).apply(null, arguments));
  21609. // });
  21610. // return result;
  21611. // }
  21612. /**
  21613. * Data mapping to a new List with given dimensions
  21614. */
  21615. DataStore.prototype.map = function (dims, cb) {
  21616. // TODO only clone picked chunks.
  21617. var target = this.clone(dims);
  21618. this._updateDims(target, dims, cb);
  21619. return target;
  21620. };
  21621. /**
  21622. * @caution Danger!! Only used in dataStack.
  21623. */
  21624. DataStore.prototype.modify = function (dims, cb) {
  21625. this._updateDims(this, dims, cb);
  21626. };
  21627. DataStore.prototype._updateDims = function (target, dims, cb) {
  21628. var targetChunks = target._chunks;
  21629. var tmpRetValue = [];
  21630. var dimSize = dims.length;
  21631. var dataCount = target.count();
  21632. var values = [];
  21633. var rawExtent = target._rawExtent;
  21634. for (var i = 0; i < dims.length; i++) {
  21635. rawExtent[dims[i]] = getInitialExtent();
  21636. }
  21637. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  21638. var rawIndex = target.getRawIndex(dataIndex);
  21639. for (var k = 0; k < dimSize; k++) {
  21640. values[k] = targetChunks[dims[k]][rawIndex];
  21641. }
  21642. values[dimSize] = dataIndex;
  21643. var retValue = cb && cb.apply(null, values);
  21644. if (retValue != null) {
  21645. // a number or string (in oridinal dimension)?
  21646. if (typeof retValue !== 'object') {
  21647. tmpRetValue[0] = retValue;
  21648. retValue = tmpRetValue;
  21649. }
  21650. for (var i = 0; i < retValue.length; i++) {
  21651. var dim = dims[i];
  21652. var val = retValue[i];
  21653. var rawExtentOnDim = rawExtent[dim];
  21654. var dimStore = targetChunks[dim];
  21655. if (dimStore) {
  21656. dimStore[rawIndex] = val;
  21657. }
  21658. if (val < rawExtentOnDim[0]) {
  21659. rawExtentOnDim[0] = val;
  21660. }
  21661. if (val > rawExtentOnDim[1]) {
  21662. rawExtentOnDim[1] = val;
  21663. }
  21664. }
  21665. }
  21666. }
  21667. };
  21668. /**
  21669. * Large data down sampling using largest-triangle-three-buckets
  21670. * @param {string} valueDimension
  21671. * @param {number} targetCount
  21672. */
  21673. DataStore.prototype.lttbDownSample = function (valueDimension, rate) {
  21674. var target = this.clone([valueDimension], true);
  21675. var targetStorage = target._chunks;
  21676. var dimStore = targetStorage[valueDimension];
  21677. var len = this.count();
  21678. var sampledIndex = 0;
  21679. var frameSize = Math.floor(1 / rate);
  21680. var currentRawIndex = this.getRawIndex(0);
  21681. var maxArea;
  21682. var area;
  21683. var nextRawIndex;
  21684. var newIndices = new (getIndicesCtor(this._rawCount))(Math.min((Math.ceil(len / frameSize) + 2) * 2, len));
  21685. // First frame use the first data.
  21686. newIndices[sampledIndex++] = currentRawIndex;
  21687. for (var i = 1; i < len - 1; i += frameSize) {
  21688. var nextFrameStart = Math.min(i + frameSize, len - 1);
  21689. var nextFrameEnd = Math.min(i + frameSize * 2, len);
  21690. var avgX = (nextFrameEnd + nextFrameStart) / 2;
  21691. var avgY = 0;
  21692. for (var idx = nextFrameStart; idx < nextFrameEnd; idx++) {
  21693. var rawIndex = this.getRawIndex(idx);
  21694. var y = dimStore[rawIndex];
  21695. if (isNaN(y)) {
  21696. continue;
  21697. }
  21698. avgY += y;
  21699. }
  21700. avgY /= nextFrameEnd - nextFrameStart;
  21701. var frameStart = i;
  21702. var frameEnd = Math.min(i + frameSize, len);
  21703. var pointAX = i - 1;
  21704. var pointAY = dimStore[currentRawIndex];
  21705. maxArea = -1;
  21706. nextRawIndex = frameStart;
  21707. var firstNaNIndex = -1;
  21708. var countNaN = 0;
  21709. // Find a point from current frame that construct a triangle with largest area with previous selected point
  21710. // And the average of next frame.
  21711. for (var idx = frameStart; idx < frameEnd; idx++) {
  21712. var rawIndex = this.getRawIndex(idx);
  21713. var y = dimStore[rawIndex];
  21714. if (isNaN(y)) {
  21715. countNaN++;
  21716. if (firstNaNIndex < 0) {
  21717. firstNaNIndex = rawIndex;
  21718. }
  21719. continue;
  21720. }
  21721. // Calculate triangle area over three buckets
  21722. area = Math.abs((pointAX - avgX) * (y - pointAY) - (pointAX - idx) * (avgY - pointAY));
  21723. if (area > maxArea) {
  21724. maxArea = area;
  21725. nextRawIndex = rawIndex; // Next a is this b
  21726. }
  21727. }
  21728. if (countNaN > 0 && countNaN < frameEnd - frameStart) {
  21729. // Append first NaN point in every bucket.
  21730. // It is necessary to ensure the correct order of indices.
  21731. newIndices[sampledIndex++] = Math.min(firstNaNIndex, nextRawIndex);
  21732. nextRawIndex = Math.max(firstNaNIndex, nextRawIndex);
  21733. }
  21734. newIndices[sampledIndex++] = nextRawIndex;
  21735. currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
  21736. }
  21737. // First frame use the last data.
  21738. newIndices[sampledIndex++] = this.getRawIndex(len - 1);
  21739. target._count = sampledIndex;
  21740. target._indices = newIndices;
  21741. target.getRawIndex = this._getRawIdx;
  21742. return target;
  21743. };
  21744. /**
  21745. * Large data down sampling using min-max
  21746. * @param {string} valueDimension
  21747. * @param {number} rate
  21748. */
  21749. DataStore.prototype.minmaxDownSample = function (valueDimension, rate) {
  21750. var target = this.clone([valueDimension], true);
  21751. var targetStorage = target._chunks;
  21752. var frameSize = Math.floor(1 / rate);
  21753. var dimStore = targetStorage[valueDimension];
  21754. var len = this.count();
  21755. // Each frame results in 2 data points, one for min and one for max
  21756. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize) * 2);
  21757. var offset = 0;
  21758. for (var i = 0; i < len; i += frameSize) {
  21759. var minIndex = i;
  21760. var minValue = dimStore[this.getRawIndex(minIndex)];
  21761. var maxIndex = i;
  21762. var maxValue = dimStore[this.getRawIndex(maxIndex)];
  21763. var thisFrameSize = frameSize;
  21764. // Handle final smaller frame
  21765. if (i + frameSize > len) {
  21766. thisFrameSize = len - i;
  21767. }
  21768. // Determine min and max within the current frame
  21769. for (var k = 0; k < thisFrameSize; k++) {
  21770. var rawIndex = this.getRawIndex(i + k);
  21771. var value = dimStore[rawIndex];
  21772. if (value < minValue) {
  21773. minValue = value;
  21774. minIndex = i + k;
  21775. }
  21776. if (value > maxValue) {
  21777. maxValue = value;
  21778. maxIndex = i + k;
  21779. }
  21780. }
  21781. var rawMinIndex = this.getRawIndex(minIndex);
  21782. var rawMaxIndex = this.getRawIndex(maxIndex);
  21783. // Set the order of the min and max values, based on their ordering in the frame
  21784. if (minIndex < maxIndex) {
  21785. newIndices[offset++] = rawMinIndex;
  21786. newIndices[offset++] = rawMaxIndex;
  21787. } else {
  21788. newIndices[offset++] = rawMaxIndex;
  21789. newIndices[offset++] = rawMinIndex;
  21790. }
  21791. }
  21792. target._count = offset;
  21793. target._indices = newIndices;
  21794. target._updateGetRawIdx();
  21795. return target;
  21796. };
  21797. /**
  21798. * Large data down sampling on given dimension
  21799. * @param sampleIndex Sample index for name and id
  21800. */
  21801. DataStore.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  21802. var target = this.clone([dimension], true);
  21803. var targetStorage = target._chunks;
  21804. var frameValues = [];
  21805. var frameSize = Math.floor(1 / rate);
  21806. var dimStore = targetStorage[dimension];
  21807. var len = this.count();
  21808. var rawExtentOnDim = target._rawExtent[dimension] = getInitialExtent();
  21809. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize));
  21810. var offset = 0;
  21811. for (var i = 0; i < len; i += frameSize) {
  21812. // Last frame
  21813. if (frameSize > len - i) {
  21814. frameSize = len - i;
  21815. frameValues.length = frameSize;
  21816. }
  21817. for (var k = 0; k < frameSize; k++) {
  21818. var dataIdx = this.getRawIndex(i + k);
  21819. frameValues[k] = dimStore[dataIdx];
  21820. }
  21821. var value = sampleValue(frameValues);
  21822. var sampleFrameIdx = this.getRawIndex(Math.min(i + sampleIndex(frameValues, value) || 0, len - 1));
  21823. // Only write value on the filtered data
  21824. dimStore[sampleFrameIdx] = value;
  21825. if (value < rawExtentOnDim[0]) {
  21826. rawExtentOnDim[0] = value;
  21827. }
  21828. if (value > rawExtentOnDim[1]) {
  21829. rawExtentOnDim[1] = value;
  21830. }
  21831. newIndices[offset++] = sampleFrameIdx;
  21832. }
  21833. target._count = offset;
  21834. target._indices = newIndices;
  21835. target._updateGetRawIdx();
  21836. return target;
  21837. };
  21838. /**
  21839. * Data iteration
  21840. * @param ctx default this
  21841. * @example
  21842. * list.each('x', function (x, idx) {});
  21843. * list.each(['x', 'y'], function (x, y, idx) {});
  21844. * list.each(function (idx) {})
  21845. */
  21846. DataStore.prototype.each = function (dims, cb) {
  21847. if (!this._count) {
  21848. return;
  21849. }
  21850. var dimSize = dims.length;
  21851. var chunks = this._chunks;
  21852. for (var i = 0, len = this.count(); i < len; i++) {
  21853. var rawIdx = this.getRawIndex(i);
  21854. // Simple optimization
  21855. switch (dimSize) {
  21856. case 0:
  21857. cb(i);
  21858. break;
  21859. case 1:
  21860. cb(chunks[dims[0]][rawIdx], i);
  21861. break;
  21862. case 2:
  21863. cb(chunks[dims[0]][rawIdx], chunks[dims[1]][rawIdx], i);
  21864. break;
  21865. default:
  21866. var k = 0;
  21867. var value = [];
  21868. for (; k < dimSize; k++) {
  21869. value[k] = chunks[dims[k]][rawIdx];
  21870. }
  21871. // Index
  21872. value[k] = i;
  21873. cb.apply(null, value);
  21874. }
  21875. }
  21876. };
  21877. /**
  21878. * Get extent of data in one dimension
  21879. */
  21880. DataStore.prototype.getDataExtent = function (dim) {
  21881. // Make sure use concrete dim as cache name.
  21882. var dimData = this._chunks[dim];
  21883. var initialExtent = getInitialExtent();
  21884. if (!dimData) {
  21885. return initialExtent;
  21886. }
  21887. // Make more strict checkings to ensure hitting cache.
  21888. var currEnd = this.count();
  21889. // Consider the most cases when using data zoom, `getDataExtent`
  21890. // happened before filtering. We cache raw extent, which is not
  21891. // necessary to be cleared and recalculated when restore data.
  21892. var useRaw = !this._indices;
  21893. var dimExtent;
  21894. if (useRaw) {
  21895. return this._rawExtent[dim].slice();
  21896. }
  21897. dimExtent = this._extent[dim];
  21898. if (dimExtent) {
  21899. return dimExtent.slice();
  21900. }
  21901. dimExtent = initialExtent;
  21902. var min = dimExtent[0];
  21903. var max = dimExtent[1];
  21904. for (var i = 0; i < currEnd; i++) {
  21905. var rawIdx = this.getRawIndex(i);
  21906. var value = dimData[rawIdx];
  21907. value < min && (min = value);
  21908. value > max && (max = value);
  21909. }
  21910. dimExtent = [min, max];
  21911. this._extent[dim] = dimExtent;
  21912. return dimExtent;
  21913. };
  21914. /**
  21915. * Get raw data item
  21916. */
  21917. DataStore.prototype.getRawDataItem = function (idx) {
  21918. var rawIdx = this.getRawIndex(idx);
  21919. if (!this._provider.persistent) {
  21920. var val = [];
  21921. var chunks = this._chunks;
  21922. for (var i = 0; i < chunks.length; i++) {
  21923. val.push(chunks[i][rawIdx]);
  21924. }
  21925. return val;
  21926. } else {
  21927. return this._provider.getItem(rawIdx);
  21928. }
  21929. };
  21930. /**
  21931. * Clone shallow.
  21932. *
  21933. * @param clonedDims Determine which dims to clone. Will share the data if not specified.
  21934. */
  21935. DataStore.prototype.clone = function (clonedDims, ignoreIndices) {
  21936. var target = new DataStore();
  21937. var chunks = this._chunks;
  21938. var clonedDimsMap = clonedDims && reduce(clonedDims, function (obj, dimIdx) {
  21939. obj[dimIdx] = true;
  21940. return obj;
  21941. }, {});
  21942. if (clonedDimsMap) {
  21943. for (var i = 0; i < chunks.length; i++) {
  21944. // Not clone if dim is not picked.
  21945. target._chunks[i] = !clonedDimsMap[i] ? chunks[i] : cloneChunk(chunks[i]);
  21946. }
  21947. } else {
  21948. target._chunks = chunks;
  21949. }
  21950. this._copyCommonProps(target);
  21951. if (!ignoreIndices) {
  21952. target._indices = this._cloneIndices();
  21953. }
  21954. target._updateGetRawIdx();
  21955. return target;
  21956. };
  21957. DataStore.prototype._copyCommonProps = function (target) {
  21958. target._count = this._count;
  21959. target._rawCount = this._rawCount;
  21960. target._provider = this._provider;
  21961. target._dimensions = this._dimensions;
  21962. target._extent = clone(this._extent);
  21963. target._rawExtent = clone(this._rawExtent);
  21964. };
  21965. DataStore.prototype._cloneIndices = function () {
  21966. if (this._indices) {
  21967. var Ctor = this._indices.constructor;
  21968. var indices = void 0;
  21969. if (Ctor === Array) {
  21970. var thisCount = this._indices.length;
  21971. indices = new Ctor(thisCount);
  21972. for (var i = 0; i < thisCount; i++) {
  21973. indices[i] = this._indices[i];
  21974. }
  21975. } else {
  21976. indices = new Ctor(this._indices);
  21977. }
  21978. return indices;
  21979. }
  21980. return null;
  21981. };
  21982. DataStore.prototype._getRawIdxIdentity = function (idx) {
  21983. return idx;
  21984. };
  21985. DataStore.prototype._getRawIdx = function (idx) {
  21986. if (idx < this._count && idx >= 0) {
  21987. return this._indices[idx];
  21988. }
  21989. return -1;
  21990. };
  21991. DataStore.prototype._updateGetRawIdx = function () {
  21992. this.getRawIndex = this._indices ? this._getRawIdx : this._getRawIdxIdentity;
  21993. };
  21994. DataStore.internalField = function () {
  21995. function getDimValueSimply(dataItem, property, dataIndex, dimIndex) {
  21996. return parseDataValue(dataItem[dimIndex], this._dimensions[dimIndex]);
  21997. }
  21998. defaultDimValueGetters = {
  21999. arrayRows: getDimValueSimply,
  22000. objectRows: function (dataItem, property, dataIndex, dimIndex) {
  22001. return parseDataValue(dataItem[property], this._dimensions[dimIndex]);
  22002. },
  22003. keyedColumns: getDimValueSimply,
  22004. original: function (dataItem, property, dataIndex, dimIndex) {
  22005. // Performance sensitive, do not use modelUtil.getDataItemValue.
  22006. // If dataItem is an plain object with no value field, the let `value`
  22007. // will be assigned with the object, but it will be tread correctly
  22008. // in the `convertValue`.
  22009. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  22010. return parseDataValue(value instanceof Array ? value[dimIndex]
  22011. // If value is a single number or something else not array.
  22012. : value, this._dimensions[dimIndex]);
  22013. },
  22014. typedArray: function (dataItem, property, dataIndex, dimIndex) {
  22015. return dataItem[dimIndex];
  22016. }
  22017. };
  22018. }();
  22019. return DataStore;
  22020. }();
  22021. /**
  22022. * [REQUIREMENT_MEMO]:
  22023. * (0) `metaRawOption` means `dimensions`/`sourceHeader`/`seriesLayoutBy` in raw option.
  22024. * (1) Keep support the feature: `metaRawOption` can be specified both on `series` and
  22025. * `root-dataset`. Them on `series` has higher priority.
  22026. * (2) Do not support to set `metaRawOption` on a `non-root-dataset`, because it might
  22027. * confuse users: whether those props indicate how to visit the upstream source or visit
  22028. * the transform result source, and some transforms has nothing to do with these props,
  22029. * and some transforms might have multiple upstream.
  22030. * (3) Transforms should specify `metaRawOption` in each output, just like they can be
  22031. * declared in `root-dataset`.
  22032. * (4) At present only support visit source in `SERIES_LAYOUT_BY_COLUMN` in transforms.
  22033. * That is for reducing complexity in transforms.
  22034. * PENDING: Whether to provide transposition transform?
  22035. *
  22036. * [IMPLEMENTAION_MEMO]:
  22037. * "sourceVisitConfig" are calculated from `metaRawOption` and `data`.
  22038. * They will not be calculated until `source` is about to be visited (to prevent from
  22039. * duplicate calcuation). `source` is visited only in series and input to transforms.
  22040. *
  22041. * [DIMENSION_INHERIT_RULE]:
  22042. * By default the dimensions are inherited from ancestors, unless a transform return
  22043. * a new dimensions definition.
  22044. * Consider the case:
  22045. * ```js
  22046. * dataset: [{
  22047. * source: [ ['Product', 'Sales', 'Prise'], ['Cookies', 321, 44.21], ...]
  22048. * }, {
  22049. * transform: { type: 'filter', ... }
  22050. * }]
  22051. * dataset: [{
  22052. * dimension: ['Product', 'Sales', 'Prise'],
  22053. * source: [ ['Cookies', 321, 44.21], ...]
  22054. * }, {
  22055. * transform: { type: 'filter', ... }
  22056. * }]
  22057. * ```
  22058. * The two types of option should have the same behavior after transform.
  22059. *
  22060. *
  22061. * [SCENARIO]:
  22062. * (1) Provide source data directly:
  22063. * ```js
  22064. * series: {
  22065. * encode: {...},
  22066. * dimensions: [...]
  22067. * seriesLayoutBy: 'row',
  22068. * data: [[...]]
  22069. * }
  22070. * ```
  22071. * (2) Series refer to dataset.
  22072. * ```js
  22073. * series: [{
  22074. * encode: {...}
  22075. * // Ignore datasetIndex means `datasetIndex: 0`
  22076. * // and the dimensions defination in dataset is used
  22077. * }, {
  22078. * encode: {...},
  22079. * seriesLayoutBy: 'column',
  22080. * datasetIndex: 1
  22081. * }]
  22082. * ```
  22083. * (3) dataset transform
  22084. * ```js
  22085. * dataset: [{
  22086. * source: [...]
  22087. * }, {
  22088. * source: [...]
  22089. * }, {
  22090. * // By default from 0.
  22091. * transform: { type: 'filter', config: {...} }
  22092. * }, {
  22093. * // Piped.
  22094. * transform: [
  22095. * { type: 'filter', config: {...} },
  22096. * { type: 'sort', config: {...} }
  22097. * ]
  22098. * }, {
  22099. * id: 'regressionData',
  22100. * fromDatasetIndex: 1,
  22101. * // Third-party transform
  22102. * transform: { type: 'ecStat:regression', config: {...} }
  22103. * }, {
  22104. * // retrieve the extra result.
  22105. * id: 'regressionFormula',
  22106. * fromDatasetId: 'regressionData',
  22107. * fromTransformResult: 1
  22108. * }]
  22109. * ```
  22110. */
  22111. var SourceManager = /** @class */function () {
  22112. function SourceManager(sourceHost) {
  22113. // Cached source. Do not repeat calculating if not dirty.
  22114. this._sourceList = [];
  22115. this._storeList = [];
  22116. // version sign of each upstream source manager.
  22117. this._upstreamSignList = [];
  22118. this._versionSignBase = 0;
  22119. this._dirty = true;
  22120. this._sourceHost = sourceHost;
  22121. }
  22122. /**
  22123. * Mark dirty.
  22124. */
  22125. SourceManager.prototype.dirty = function () {
  22126. this._setLocalSource([], []);
  22127. this._storeList = [];
  22128. this._dirty = true;
  22129. };
  22130. SourceManager.prototype._setLocalSource = function (sourceList, upstreamSignList) {
  22131. this._sourceList = sourceList;
  22132. this._upstreamSignList = upstreamSignList;
  22133. this._versionSignBase++;
  22134. if (this._versionSignBase > 9e10) {
  22135. this._versionSignBase = 0;
  22136. }
  22137. };
  22138. /**
  22139. * For detecting whether the upstream source is dirty, so that
  22140. * the local cached source (in `_sourceList`) should be discarded.
  22141. */
  22142. SourceManager.prototype._getVersionSign = function () {
  22143. return this._sourceHost.uid + '_' + this._versionSignBase;
  22144. };
  22145. /**
  22146. * Always return a source instance. Otherwise throw error.
  22147. */
  22148. SourceManager.prototype.prepareSource = function () {
  22149. // For the case that call `setOption` multiple time but no data changed,
  22150. // cache the result source to prevent from repeating transform.
  22151. if (this._isDirty()) {
  22152. this._createSource();
  22153. this._dirty = false;
  22154. }
  22155. };
  22156. SourceManager.prototype._createSource = function () {
  22157. this._setLocalSource([], []);
  22158. var sourceHost = this._sourceHost;
  22159. var upSourceMgrList = this._getUpstreamSourceManagers();
  22160. var hasUpstream = !!upSourceMgrList.length;
  22161. var resultSourceList;
  22162. var upstreamSignList;
  22163. if (isSeries(sourceHost)) {
  22164. var seriesModel = sourceHost;
  22165. var data = void 0;
  22166. var sourceFormat = void 0;
  22167. var upSource = void 0;
  22168. // Has upstream dataset
  22169. if (hasUpstream) {
  22170. var upSourceMgr = upSourceMgrList[0];
  22171. upSourceMgr.prepareSource();
  22172. upSource = upSourceMgr.getSource();
  22173. data = upSource.data;
  22174. sourceFormat = upSource.sourceFormat;
  22175. upstreamSignList = [upSourceMgr._getVersionSign()];
  22176. }
  22177. // Series data is from own.
  22178. else {
  22179. data = seriesModel.get('data', true);
  22180. sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  22181. upstreamSignList = [];
  22182. }
  22183. // See [REQUIREMENT_MEMO], merge settings on series and parent dataset if it is root.
  22184. var newMetaRawOption = this._getSourceMetaRawOption() || {};
  22185. var upMetaRawOption = upSource && upSource.metaRawOption || {};
  22186. var seriesLayoutBy = retrieve2(newMetaRawOption.seriesLayoutBy, upMetaRawOption.seriesLayoutBy) || null;
  22187. var sourceHeader = retrieve2(newMetaRawOption.sourceHeader, upMetaRawOption.sourceHeader);
  22188. // Note here we should not use `upSource.dimensionsDefine`. Consider the case:
  22189. // `upSource.dimensionsDefine` is detected by `seriesLayoutBy: 'column'`,
  22190. // but series need `seriesLayoutBy: 'row'`.
  22191. var dimensions = retrieve2(newMetaRawOption.dimensions, upMetaRawOption.dimensions);
  22192. // We share source with dataset as much as possible
  22193. // to avoid extra memory cost of high dimensional data.
  22194. var needsCreateSource = seriesLayoutBy !== upMetaRawOption.seriesLayoutBy || !!sourceHeader !== !!upMetaRawOption.sourceHeader || dimensions;
  22195. resultSourceList = needsCreateSource ? [createSource(data, {
  22196. seriesLayoutBy: seriesLayoutBy,
  22197. sourceHeader: sourceHeader,
  22198. dimensions: dimensions
  22199. }, sourceFormat)] : [];
  22200. } else {
  22201. var datasetModel = sourceHost;
  22202. // Has upstream dataset.
  22203. if (hasUpstream) {
  22204. var result = this._applyTransform(upSourceMgrList);
  22205. resultSourceList = result.sourceList;
  22206. upstreamSignList = result.upstreamSignList;
  22207. }
  22208. // Is root dataset.
  22209. else {
  22210. var sourceData = datasetModel.get('source', true);
  22211. resultSourceList = [createSource(sourceData, this._getSourceMetaRawOption(), null)];
  22212. upstreamSignList = [];
  22213. }
  22214. }
  22215. if ("development" !== 'production') {
  22216. assert(resultSourceList && upstreamSignList);
  22217. }
  22218. this._setLocalSource(resultSourceList, upstreamSignList);
  22219. };
  22220. SourceManager.prototype._applyTransform = function (upMgrList) {
  22221. var datasetModel = this._sourceHost;
  22222. var transformOption = datasetModel.get('transform', true);
  22223. var fromTransformResult = datasetModel.get('fromTransformResult', true);
  22224. if ("development" !== 'production') {
  22225. assert(fromTransformResult != null || transformOption != null);
  22226. }
  22227. if (fromTransformResult != null) {
  22228. var errMsg = '';
  22229. if (upMgrList.length !== 1) {
  22230. if ("development" !== 'production') {
  22231. errMsg = 'When using `fromTransformResult`, there should be only one upstream dataset';
  22232. }
  22233. doThrow(errMsg);
  22234. }
  22235. }
  22236. var sourceList;
  22237. var upSourceList = [];
  22238. var upstreamSignList = [];
  22239. each(upMgrList, function (upMgr) {
  22240. upMgr.prepareSource();
  22241. var upSource = upMgr.getSource(fromTransformResult || 0);
  22242. var errMsg = '';
  22243. if (fromTransformResult != null && !upSource) {
  22244. if ("development" !== 'production') {
  22245. errMsg = 'Can not retrieve result by `fromTransformResult`: ' + fromTransformResult;
  22246. }
  22247. doThrow(errMsg);
  22248. }
  22249. upSourceList.push(upSource);
  22250. upstreamSignList.push(upMgr._getVersionSign());
  22251. });
  22252. if (transformOption) {
  22253. sourceList = applyDataTransform(transformOption, upSourceList, {
  22254. datasetIndex: datasetModel.componentIndex
  22255. });
  22256. } else if (fromTransformResult != null) {
  22257. sourceList = [cloneSourceShallow(upSourceList[0])];
  22258. }
  22259. return {
  22260. sourceList: sourceList,
  22261. upstreamSignList: upstreamSignList
  22262. };
  22263. };
  22264. SourceManager.prototype._isDirty = function () {
  22265. if (this._dirty) {
  22266. return true;
  22267. }
  22268. // All sourceList is from the some upstream.
  22269. var upSourceMgrList = this._getUpstreamSourceManagers();
  22270. for (var i = 0; i < upSourceMgrList.length; i++) {
  22271. var upSrcMgr = upSourceMgrList[i];
  22272. if (
  22273. // Consider the case that there is ancestor diry, call it recursively.
  22274. // The performance is probably not an issue because usually the chain is not long.
  22275. upSrcMgr._isDirty() || this._upstreamSignList[i] !== upSrcMgr._getVersionSign()) {
  22276. return true;
  22277. }
  22278. }
  22279. };
  22280. /**
  22281. * @param sourceIndex By default 0, means "main source".
  22282. * In most cases there is only one source.
  22283. */
  22284. SourceManager.prototype.getSource = function (sourceIndex) {
  22285. sourceIndex = sourceIndex || 0;
  22286. var source = this._sourceList[sourceIndex];
  22287. if (!source) {
  22288. // Series may share source instance with dataset.
  22289. var upSourceMgrList = this._getUpstreamSourceManagers();
  22290. return upSourceMgrList[0] && upSourceMgrList[0].getSource(sourceIndex);
  22291. }
  22292. return source;
  22293. };
  22294. /**
  22295. *
  22296. * Get a data store which can be shared across series.
  22297. * Only available for series.
  22298. *
  22299. * @param seriesDimRequest Dimensions that are generated in series.
  22300. * Should have been sorted by `storeDimIndex` asc.
  22301. */
  22302. SourceManager.prototype.getSharedDataStore = function (seriesDimRequest) {
  22303. if ("development" !== 'production') {
  22304. assert(isSeries(this._sourceHost), 'Can only call getDataStore on series source manager.');
  22305. }
  22306. var schema = seriesDimRequest.makeStoreSchema();
  22307. return this._innerGetDataStore(schema.dimensions, seriesDimRequest.source, schema.hash);
  22308. };
  22309. SourceManager.prototype._innerGetDataStore = function (storeDims, seriesSource, sourceReadKey) {
  22310. // TODO Can use other sourceIndex?
  22311. var sourceIndex = 0;
  22312. var storeList = this._storeList;
  22313. var cachedStoreMap = storeList[sourceIndex];
  22314. if (!cachedStoreMap) {
  22315. cachedStoreMap = storeList[sourceIndex] = {};
  22316. }
  22317. var cachedStore = cachedStoreMap[sourceReadKey];
  22318. if (!cachedStore) {
  22319. var upSourceMgr = this._getUpstreamSourceManagers()[0];
  22320. if (isSeries(this._sourceHost) && upSourceMgr) {
  22321. cachedStore = upSourceMgr._innerGetDataStore(storeDims, seriesSource, sourceReadKey);
  22322. } else {
  22323. cachedStore = new DataStore();
  22324. // Always create store from source of series.
  22325. cachedStore.initData(new DefaultDataProvider(seriesSource, storeDims.length), storeDims);
  22326. }
  22327. cachedStoreMap[sourceReadKey] = cachedStore;
  22328. }
  22329. return cachedStore;
  22330. };
  22331. /**
  22332. * PENDING: Is it fast enough?
  22333. * If no upstream, return empty array.
  22334. */
  22335. SourceManager.prototype._getUpstreamSourceManagers = function () {
  22336. // Always get the relationship from the raw option.
  22337. // Do not cache the link of the dependency graph, so that
  22338. // there is no need to update them when change happens.
  22339. var sourceHost = this._sourceHost;
  22340. if (isSeries(sourceHost)) {
  22341. var datasetModel = querySeriesUpstreamDatasetModel(sourceHost);
  22342. return !datasetModel ? [] : [datasetModel.getSourceManager()];
  22343. } else {
  22344. return map(queryDatasetUpstreamDatasetModels(sourceHost), function (datasetModel) {
  22345. return datasetModel.getSourceManager();
  22346. });
  22347. }
  22348. };
  22349. SourceManager.prototype._getSourceMetaRawOption = function () {
  22350. var sourceHost = this._sourceHost;
  22351. var seriesLayoutBy;
  22352. var sourceHeader;
  22353. var dimensions;
  22354. if (isSeries(sourceHost)) {
  22355. seriesLayoutBy = sourceHost.get('seriesLayoutBy', true);
  22356. sourceHeader = sourceHost.get('sourceHeader', true);
  22357. dimensions = sourceHost.get('dimensions', true);
  22358. }
  22359. // See [REQUIREMENT_MEMO], `non-root-dataset` do not support them.
  22360. else if (!this._getUpstreamSourceManagers().length) {
  22361. var model = sourceHost;
  22362. seriesLayoutBy = model.get('seriesLayoutBy', true);
  22363. sourceHeader = model.get('sourceHeader', true);
  22364. dimensions = model.get('dimensions', true);
  22365. }
  22366. return {
  22367. seriesLayoutBy: seriesLayoutBy,
  22368. sourceHeader: sourceHeader,
  22369. dimensions: dimensions
  22370. };
  22371. };
  22372. return SourceManager;
  22373. }();
  22374. // Call this method after `super.init` and `super.mergeOption` to
  22375. // disable the transform merge, but do not disable transform clone from rawOption.
  22376. function disableTransformOptionMerge(datasetModel) {
  22377. var transformOption = datasetModel.option.transform;
  22378. transformOption && setAsPrimitive(datasetModel.option.transform);
  22379. }
  22380. function isSeries(sourceHost) {
  22381. // Avoid circular dependency with Series.ts
  22382. return sourceHost.mainType === 'series';
  22383. }
  22384. function doThrow(errMsg) {
  22385. throw new Error(errMsg);
  22386. }
  22387. // eslint-disable-next-line max-len
  22388. function createTooltipMarkup(type, option) {
  22389. option.type = type;
  22390. return option;
  22391. }
  22392. function retrieveVisualColorForTooltipMarker(series, dataIndex) {
  22393. var style = series.getData().getItemVisual(dataIndex, 'style');
  22394. var color = style[series.visualDrawType];
  22395. return convertToColorString(color);
  22396. }
  22397. function defaultSeriesFormatTooltip(opt) {
  22398. var series = opt.series;
  22399. var dataIndex = opt.dataIndex;
  22400. var multipleSeries = opt.multipleSeries;
  22401. var data = series.getData();
  22402. var tooltipDims = data.mapDimensionsAll('defaultedTooltip');
  22403. var tooltipDimLen = tooltipDims.length;
  22404. var value = series.getRawValue(dataIndex);
  22405. var isValueArr = isArray(value);
  22406. var markerColor = retrieveVisualColorForTooltipMarker(series, dataIndex);
  22407. // Complicated rule for pretty tooltip.
  22408. var inlineValue;
  22409. var inlineValueType;
  22410. var subBlocks;
  22411. var sortParam;
  22412. if (tooltipDimLen > 1 || isValueArr && !tooltipDimLen) {
  22413. var formatArrResult = formatTooltipArrayValue(value, series, dataIndex, tooltipDims, markerColor);
  22414. inlineValue = formatArrResult.inlineValues;
  22415. inlineValueType = formatArrResult.inlineValueTypes;
  22416. subBlocks = formatArrResult.blocks;
  22417. // Only support tooltip sort by the first inline value. It's enough in most cases.
  22418. sortParam = formatArrResult.inlineValues[0];
  22419. } else if (tooltipDimLen) {
  22420. var dimInfo = data.getDimensionInfo(tooltipDims[0]);
  22421. sortParam = inlineValue = retrieveRawValue(data, dataIndex, tooltipDims[0]);
  22422. inlineValueType = dimInfo.type;
  22423. } else {
  22424. sortParam = inlineValue = isValueArr ? value[0] : value;
  22425. }
  22426. // Do not show generated series name. It might not be readable.
  22427. var seriesNameSpecified = isNameSpecified(series);
  22428. var seriesName = seriesNameSpecified && series.name || '';
  22429. var itemName = data.getName(dataIndex);
  22430. var inlineName = multipleSeries ? seriesName : itemName;
  22431. return createTooltipMarkup('section', {
  22432. header: seriesName,
  22433. // When series name is not specified, do not show a header line with only '-'.
  22434. // This case always happens in tooltip.trigger: 'item'.
  22435. noHeader: multipleSeries || !seriesNameSpecified,
  22436. sortParam: sortParam,
  22437. blocks: [createTooltipMarkup('nameValue', {
  22438. markerType: 'item',
  22439. markerColor: markerColor,
  22440. // Do not mix display seriesName and itemName in one tooltip,
  22441. // which might confuses users.
  22442. name: inlineName,
  22443. // name dimension might be auto assigned, where the name might
  22444. // be not readable. So we check trim here.
  22445. noName: !trim(inlineName),
  22446. value: inlineValue,
  22447. valueType: inlineValueType,
  22448. dataIndex: dataIndex
  22449. })].concat(subBlocks || [])
  22450. });
  22451. }
  22452. function formatTooltipArrayValue(value, series, dataIndex, tooltipDims, colorStr) {
  22453. // check: category-no-encode-has-axis-data in dataset.html
  22454. var data = series.getData();
  22455. var isValueMultipleLine = reduce(value, function (isValueMultipleLine, val, idx) {
  22456. var dimItem = data.getDimensionInfo(idx);
  22457. return isValueMultipleLine = isValueMultipleLine || dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  22458. }, false);
  22459. var inlineValues = [];
  22460. var inlineValueTypes = [];
  22461. var blocks = [];
  22462. tooltipDims.length ? each(tooltipDims, function (dim) {
  22463. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  22464. })
  22465. // By default, all dims is used on tooltip.
  22466. : each(value, setEachItem);
  22467. function setEachItem(val, dim) {
  22468. var dimInfo = data.getDimensionInfo(dim);
  22469. // If `dimInfo.tooltip` is not set, show tooltip.
  22470. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  22471. return;
  22472. }
  22473. if (isValueMultipleLine) {
  22474. blocks.push(createTooltipMarkup('nameValue', {
  22475. markerType: 'subItem',
  22476. markerColor: colorStr,
  22477. name: dimInfo.displayName,
  22478. value: val,
  22479. valueType: dimInfo.type
  22480. }));
  22481. } else {
  22482. inlineValues.push(val);
  22483. inlineValueTypes.push(dimInfo.type);
  22484. }
  22485. }
  22486. return {
  22487. inlineValues: inlineValues,
  22488. inlineValueTypes: inlineValueTypes,
  22489. blocks: blocks
  22490. };
  22491. }
  22492. var inner$1 = makeInner();
  22493. function getSelectionKey(data, dataIndex) {
  22494. return data.getName(dataIndex) || data.getId(dataIndex);
  22495. }
  22496. var SERIES_UNIVERSAL_TRANSITION_PROP = '__universalTransitionEnabled';
  22497. var SeriesModel = /** @class */function (_super) {
  22498. __extends(SeriesModel, _super);
  22499. function SeriesModel() {
  22500. // [Caution]: Because this class or desecendants can be used as `XXX.extend(subProto)`,
  22501. // the class members must not be initialized in constructor or declaration place.
  22502. // Otherwise there is bad case:
  22503. // class A {xxx = 1;}
  22504. // enableClassExtend(A);
  22505. // class B extends A {}
  22506. // var C = B.extend({xxx: 5});
  22507. // var c = new C();
  22508. // console.log(c.xxx); // expect 5 but always 1.
  22509. var _this = _super !== null && _super.apply(this, arguments) || this;
  22510. // ---------------------------------------
  22511. // Props about data selection
  22512. // ---------------------------------------
  22513. _this._selectedDataIndicesMap = {};
  22514. return _this;
  22515. }
  22516. SeriesModel.prototype.init = function (option, parentModel, ecModel) {
  22517. this.seriesIndex = this.componentIndex;
  22518. this.dataTask = createTask({
  22519. count: dataTaskCount,
  22520. reset: dataTaskReset
  22521. });
  22522. this.dataTask.context = {
  22523. model: this
  22524. };
  22525. this.mergeDefaultAndTheme(option, ecModel);
  22526. var sourceManager = inner$1(this).sourceManager = new SourceManager(this);
  22527. sourceManager.prepareSource();
  22528. var data = this.getInitialData(option, ecModel);
  22529. wrapData(data, this);
  22530. this.dataTask.context.data = data;
  22531. if ("development" !== 'production') {
  22532. assert(data, 'getInitialData returned invalid data.');
  22533. }
  22534. inner$1(this).dataBeforeProcessed = data;
  22535. // If we reverse the order (make data firstly, and then make
  22536. // dataBeforeProcessed by cloneShallow), cloneShallow will
  22537. // cause data.graph.data !== data when using
  22538. // module:echarts/data/Graph or module:echarts/data/Tree.
  22539. // See module:echarts/data/helper/linkSeriesData
  22540. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  22541. // init or merge stage, because the data can be restored. So we do not `restoreData`
  22542. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  22543. // Call `seriesModel.getRawData()` instead.
  22544. // this.restoreData();
  22545. autoSeriesName(this);
  22546. this._initSelectedMapFromData(data);
  22547. };
  22548. /**
  22549. * Util for merge default and theme to option
  22550. */
  22551. SeriesModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  22552. var layoutMode = fetchLayoutMode(this);
  22553. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  22554. // Backward compat: using subType on theme.
  22555. // But if name duplicate between series subType
  22556. // (for example: parallel) add component mainType,
  22557. // add suffix 'Series'.
  22558. var themeSubType = this.subType;
  22559. if (ComponentModel.hasClass(themeSubType)) {
  22560. themeSubType += 'Series';
  22561. }
  22562. merge(option, ecModel.getTheme().get(this.subType));
  22563. merge(option, this.getDefaultOption());
  22564. // Default label emphasis `show`
  22565. defaultEmphasis(option, 'label', ['show']);
  22566. this.fillDataTextStyle(option.data);
  22567. if (layoutMode) {
  22568. mergeLayoutParam(option, inputPositionParams, layoutMode);
  22569. }
  22570. };
  22571. SeriesModel.prototype.mergeOption = function (newSeriesOption, ecModel) {
  22572. // this.settingTask.dirty();
  22573. newSeriesOption = merge(this.option, newSeriesOption, true);
  22574. this.fillDataTextStyle(newSeriesOption.data);
  22575. var layoutMode = fetchLayoutMode(this);
  22576. if (layoutMode) {
  22577. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  22578. }
  22579. var sourceManager = inner$1(this).sourceManager;
  22580. sourceManager.dirty();
  22581. sourceManager.prepareSource();
  22582. var data = this.getInitialData(newSeriesOption, ecModel);
  22583. wrapData(data, this);
  22584. this.dataTask.dirty();
  22585. this.dataTask.context.data = data;
  22586. inner$1(this).dataBeforeProcessed = data;
  22587. autoSeriesName(this);
  22588. this._initSelectedMapFromData(data);
  22589. };
  22590. SeriesModel.prototype.fillDataTextStyle = function (data) {
  22591. // Default data label emphasis `show`
  22592. // FIXME Tree structure data ?
  22593. // FIXME Performance ?
  22594. if (data && !isTypedArray(data)) {
  22595. var props = ['show'];
  22596. for (var i = 0; i < data.length; i++) {
  22597. if (data[i] && data[i].label) {
  22598. defaultEmphasis(data[i], 'label', props);
  22599. }
  22600. }
  22601. }
  22602. };
  22603. /**
  22604. * Init a data structure from data related option in series
  22605. * Must be overridden.
  22606. */
  22607. SeriesModel.prototype.getInitialData = function (option, ecModel) {
  22608. return;
  22609. };
  22610. /**
  22611. * Append data to list
  22612. */
  22613. SeriesModel.prototype.appendData = function (params) {
  22614. // FIXME ???
  22615. // (1) If data from dataset, forbidden append.
  22616. // (2) support append data of dataset.
  22617. var data = this.getRawData();
  22618. data.appendData(params.data);
  22619. };
  22620. /**
  22621. * Consider some method like `filter`, `map` need make new data,
  22622. * We should make sure that `seriesModel.getData()` get correct
  22623. * data in the stream procedure. So we fetch data from upstream
  22624. * each time `task.perform` called.
  22625. */
  22626. SeriesModel.prototype.getData = function (dataType) {
  22627. var task = getCurrentTask(this);
  22628. if (task) {
  22629. var data = task.context.data;
  22630. return dataType == null || !data.getLinkedData ? data : data.getLinkedData(dataType);
  22631. } else {
  22632. // When series is not alive (that may happen when click toolbox
  22633. // restore or setOption with not merge mode), series data may
  22634. // be still need to judge animation or something when graphic
  22635. // elements want to know whether fade out.
  22636. return inner$1(this).data;
  22637. }
  22638. };
  22639. SeriesModel.prototype.getAllData = function () {
  22640. var mainData = this.getData();
  22641. return mainData && mainData.getLinkedDataAll ? mainData.getLinkedDataAll() : [{
  22642. data: mainData
  22643. }];
  22644. };
  22645. SeriesModel.prototype.setData = function (data) {
  22646. var task = getCurrentTask(this);
  22647. if (task) {
  22648. var context = task.context;
  22649. // Consider case: filter, data sample.
  22650. // FIXME:TS never used, so comment it
  22651. // if (context.data !== data && task.modifyOutputEnd) {
  22652. // task.setOutputEnd(data.count());
  22653. // }
  22654. context.outputData = data;
  22655. // Caution: setData should update context.data,
  22656. // Because getData may be called multiply in a
  22657. // single stage and expect to get the data just
  22658. // set. (For example, AxisProxy, x y both call
  22659. // getData and setDate sequentially).
  22660. // So the context.data should be fetched from
  22661. // upstream each time when a stage starts to be
  22662. // performed.
  22663. if (task !== this.dataTask) {
  22664. context.data = data;
  22665. }
  22666. }
  22667. inner$1(this).data = data;
  22668. };
  22669. SeriesModel.prototype.getEncode = function () {
  22670. var encode = this.get('encode', true);
  22671. if (encode) {
  22672. return createHashMap(encode);
  22673. }
  22674. };
  22675. SeriesModel.prototype.getSourceManager = function () {
  22676. return inner$1(this).sourceManager;
  22677. };
  22678. SeriesModel.prototype.getSource = function () {
  22679. return this.getSourceManager().getSource();
  22680. };
  22681. /**
  22682. * Get data before processed
  22683. */
  22684. SeriesModel.prototype.getRawData = function () {
  22685. return inner$1(this).dataBeforeProcessed;
  22686. };
  22687. SeriesModel.prototype.getColorBy = function () {
  22688. var colorBy = this.get('colorBy');
  22689. return colorBy || 'series';
  22690. };
  22691. SeriesModel.prototype.isColorBySeries = function () {
  22692. return this.getColorBy() === 'series';
  22693. };
  22694. /**
  22695. * Get base axis if has coordinate system and has axis.
  22696. * By default use coordSys.getBaseAxis();
  22697. * Can be overridden for some chart.
  22698. * @return {type} description
  22699. */
  22700. SeriesModel.prototype.getBaseAxis = function () {
  22701. var coordSys = this.coordinateSystem;
  22702. // @ts-ignore
  22703. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  22704. };
  22705. /**
  22706. * Retrieve the index of nearest value in the view coordinate.
  22707. * Data position is compared with each axis's dataToCoord.
  22708. *
  22709. * @param axisDim axis dimension
  22710. * @param dim data dimension
  22711. * @param value
  22712. * @param [maxDistance=Infinity] The maximum distance in view coordinate space
  22713. * @return If and only if multiple indices has
  22714. * the same value, they are put to the result.
  22715. */
  22716. SeriesModel.prototype.indicesOfNearest = function (axisDim, dim, value, maxDistance) {
  22717. var data = this.getData();
  22718. var coordSys = this.coordinateSystem;
  22719. var axis = coordSys && coordSys.getAxis(axisDim);
  22720. if (!coordSys || !axis) {
  22721. return [];
  22722. }
  22723. var targetCoord = axis.dataToCoord(value);
  22724. if (maxDistance == null) {
  22725. maxDistance = Infinity;
  22726. }
  22727. var nearestIndices = [];
  22728. var minDist = Infinity;
  22729. var minDiff = -1;
  22730. var nearestIndicesLen = 0;
  22731. data.each(dim, function (dimValue, idx) {
  22732. var dataCoord = axis.dataToCoord(dimValue);
  22733. var diff = targetCoord - dataCoord;
  22734. var dist = Math.abs(diff);
  22735. if (dist <= maxDistance) {
  22736. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  22737. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  22738. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  22739. // So we choose the one that `diff >= 0` in this case.
  22740. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  22741. // should be push to `nearestIndices`.
  22742. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  22743. minDist = dist;
  22744. minDiff = diff;
  22745. nearestIndicesLen = 0;
  22746. }
  22747. if (diff === minDiff) {
  22748. nearestIndices[nearestIndicesLen++] = idx;
  22749. }
  22750. }
  22751. });
  22752. nearestIndices.length = nearestIndicesLen;
  22753. return nearestIndices;
  22754. };
  22755. /**
  22756. * Default tooltip formatter
  22757. *
  22758. * @param dataIndex
  22759. * @param multipleSeries
  22760. * @param dataType
  22761. * @param renderMode valid values: 'html'(by default) and 'richText'.
  22762. * 'html' is used for rendering tooltip in extra DOM form, and the result
  22763. * string is used as DOM HTML content.
  22764. * 'richText' is used for rendering tooltip in rich text form, for those where
  22765. * DOM operation is not supported.
  22766. * @return formatted tooltip with `html` and `markers`
  22767. * Notice: The override method can also return string
  22768. */
  22769. SeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  22770. return defaultSeriesFormatTooltip({
  22771. series: this,
  22772. dataIndex: dataIndex,
  22773. multipleSeries: multipleSeries
  22774. });
  22775. };
  22776. SeriesModel.prototype.isAnimationEnabled = function () {
  22777. var ecModel = this.ecModel;
  22778. // Disable animation if using echarts in node but not give ssr flag.
  22779. // In ssr mode, renderToString will generate svg with css animation.
  22780. if (env.node && !(ecModel && ecModel.ssr)) {
  22781. return false;
  22782. }
  22783. var animationEnabled = this.getShallow('animation');
  22784. if (animationEnabled) {
  22785. if (this.getData().count() > this.getShallow('animationThreshold')) {
  22786. animationEnabled = false;
  22787. }
  22788. }
  22789. return !!animationEnabled;
  22790. };
  22791. SeriesModel.prototype.restoreData = function () {
  22792. this.dataTask.dirty();
  22793. };
  22794. SeriesModel.prototype.getColorFromPalette = function (name, scope, requestColorNum) {
  22795. var ecModel = this.ecModel;
  22796. // PENDING
  22797. var color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
  22798. if (!color) {
  22799. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  22800. }
  22801. return color;
  22802. };
  22803. /**
  22804. * Use `data.mapDimensionsAll(coordDim)` instead.
  22805. * @deprecated
  22806. */
  22807. SeriesModel.prototype.coordDimToDataDim = function (coordDim) {
  22808. return this.getRawData().mapDimensionsAll(coordDim);
  22809. };
  22810. /**
  22811. * Get progressive rendering count each step
  22812. */
  22813. SeriesModel.prototype.getProgressive = function () {
  22814. return this.get('progressive');
  22815. };
  22816. /**
  22817. * Get progressive rendering count each step
  22818. */
  22819. SeriesModel.prototype.getProgressiveThreshold = function () {
  22820. return this.get('progressiveThreshold');
  22821. };
  22822. // PENGING If selectedMode is null ?
  22823. SeriesModel.prototype.select = function (innerDataIndices, dataType) {
  22824. this._innerSelect(this.getData(dataType), innerDataIndices);
  22825. };
  22826. SeriesModel.prototype.unselect = function (innerDataIndices, dataType) {
  22827. var selectedMap = this.option.selectedMap;
  22828. if (!selectedMap) {
  22829. return;
  22830. }
  22831. var selectedMode = this.option.selectedMode;
  22832. var data = this.getData(dataType);
  22833. if (selectedMode === 'series' || selectedMap === 'all') {
  22834. this.option.selectedMap = {};
  22835. this._selectedDataIndicesMap = {};
  22836. return;
  22837. }
  22838. for (var i = 0; i < innerDataIndices.length; i++) {
  22839. var dataIndex = innerDataIndices[i];
  22840. var nameOrId = getSelectionKey(data, dataIndex);
  22841. selectedMap[nameOrId] = false;
  22842. this._selectedDataIndicesMap[nameOrId] = -1;
  22843. }
  22844. };
  22845. SeriesModel.prototype.toggleSelect = function (innerDataIndices, dataType) {
  22846. var tmpArr = [];
  22847. for (var i = 0; i < innerDataIndices.length; i++) {
  22848. tmpArr[0] = innerDataIndices[i];
  22849. this.isSelected(innerDataIndices[i], dataType) ? this.unselect(tmpArr, dataType) : this.select(tmpArr, dataType);
  22850. }
  22851. };
  22852. SeriesModel.prototype.getSelectedDataIndices = function () {
  22853. if (this.option.selectedMap === 'all') {
  22854. return [].slice.call(this.getData().getIndices());
  22855. }
  22856. var selectedDataIndicesMap = this._selectedDataIndicesMap;
  22857. var nameOrIds = keys(selectedDataIndicesMap);
  22858. var dataIndices = [];
  22859. for (var i = 0; i < nameOrIds.length; i++) {
  22860. var dataIndex = selectedDataIndicesMap[nameOrIds[i]];
  22861. if (dataIndex >= 0) {
  22862. dataIndices.push(dataIndex);
  22863. }
  22864. }
  22865. return dataIndices;
  22866. };
  22867. SeriesModel.prototype.isSelected = function (dataIndex, dataType) {
  22868. var selectedMap = this.option.selectedMap;
  22869. if (!selectedMap) {
  22870. return false;
  22871. }
  22872. var data = this.getData(dataType);
  22873. return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)]) && !data.getItemModel(dataIndex).get(['select', 'disabled']);
  22874. };
  22875. SeriesModel.prototype.isUniversalTransitionEnabled = function () {
  22876. if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  22877. return true;
  22878. }
  22879. var universalTransitionOpt = this.option.universalTransition;
  22880. // Quick reject
  22881. if (!universalTransitionOpt) {
  22882. return false;
  22883. }
  22884. if (universalTransitionOpt === true) {
  22885. return true;
  22886. }
  22887. // Can be simply 'universalTransition: true'
  22888. return universalTransitionOpt && universalTransitionOpt.enabled;
  22889. };
  22890. SeriesModel.prototype._innerSelect = function (data, innerDataIndices) {
  22891. var _a, _b;
  22892. var option = this.option;
  22893. var selectedMode = option.selectedMode;
  22894. var len = innerDataIndices.length;
  22895. if (!selectedMode || !len) {
  22896. return;
  22897. }
  22898. if (selectedMode === 'series') {
  22899. option.selectedMap = 'all';
  22900. } else if (selectedMode === 'multiple') {
  22901. if (!isObject(option.selectedMap)) {
  22902. option.selectedMap = {};
  22903. }
  22904. var selectedMap = option.selectedMap;
  22905. for (var i = 0; i < len; i++) {
  22906. var dataIndex = innerDataIndices[i];
  22907. // TODO different types of data share same object.
  22908. var nameOrId = getSelectionKey(data, dataIndex);
  22909. selectedMap[nameOrId] = true;
  22910. this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
  22911. }
  22912. } else if (selectedMode === 'single' || selectedMode === true) {
  22913. var lastDataIndex = innerDataIndices[len - 1];
  22914. var nameOrId = getSelectionKey(data, lastDataIndex);
  22915. option.selectedMap = (_a = {}, _a[nameOrId] = true, _a);
  22916. this._selectedDataIndicesMap = (_b = {}, _b[nameOrId] = data.getRawIndex(lastDataIndex), _b);
  22917. }
  22918. };
  22919. SeriesModel.prototype._initSelectedMapFromData = function (data) {
  22920. // Ignore select info in data if selectedMap exists.
  22921. // NOTE It's only for legacy usage. edge data is not supported.
  22922. if (this.option.selectedMap) {
  22923. return;
  22924. }
  22925. var dataIndices = [];
  22926. if (data.hasItemOption) {
  22927. data.each(function (idx) {
  22928. var rawItem = data.getRawDataItem(idx);
  22929. if (rawItem && rawItem.selected) {
  22930. dataIndices.push(idx);
  22931. }
  22932. });
  22933. }
  22934. if (dataIndices.length > 0) {
  22935. this._innerSelect(data, dataIndices);
  22936. }
  22937. };
  22938. // /**
  22939. // * @see {module:echarts/stream/Scheduler}
  22940. // */
  22941. // abstract pipeTask: null
  22942. SeriesModel.registerClass = function (clz) {
  22943. return ComponentModel.registerClass(clz);
  22944. };
  22945. SeriesModel.protoInitialize = function () {
  22946. var proto = SeriesModel.prototype;
  22947. proto.type = 'series.__base__';
  22948. proto.seriesIndex = 0;
  22949. proto.ignoreStyleOnData = false;
  22950. proto.hasSymbolVisual = false;
  22951. proto.defaultSymbol = 'circle';
  22952. // Make sure the values can be accessed!
  22953. proto.visualStyleAccessPath = 'itemStyle';
  22954. proto.visualDrawType = 'fill';
  22955. }();
  22956. return SeriesModel;
  22957. }(ComponentModel);
  22958. mixin(SeriesModel, DataFormatMixin);
  22959. mixin(SeriesModel, PaletteMixin);
  22960. mountExtend(SeriesModel, ComponentModel);
  22961. /**
  22962. * MUST be called after `prepareSource` called
  22963. * Here we need to make auto series, especially for auto legend. But we
  22964. * do not modify series.name in option to avoid side effects.
  22965. */
  22966. function autoSeriesName(seriesModel) {
  22967. // User specified name has higher priority, otherwise it may cause
  22968. // series can not be queried unexpectedly.
  22969. var name = seriesModel.name;
  22970. if (!isNameSpecified(seriesModel)) {
  22971. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  22972. }
  22973. }
  22974. function getSeriesAutoName(seriesModel) {
  22975. var data = seriesModel.getRawData();
  22976. var dataDims = data.mapDimensionsAll('seriesName');
  22977. var nameArr = [];
  22978. each(dataDims, function (dataDim) {
  22979. var dimInfo = data.getDimensionInfo(dataDim);
  22980. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  22981. });
  22982. return nameArr.join(' ');
  22983. }
  22984. function dataTaskCount(context) {
  22985. return context.model.getRawData().count();
  22986. }
  22987. function dataTaskReset(context) {
  22988. var seriesModel = context.model;
  22989. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  22990. return dataTaskProgress;
  22991. }
  22992. function dataTaskProgress(param, context) {
  22993. // Avoid repeat cloneShallow when data just created in reset.
  22994. if (context.outputData && param.end > context.outputData.count()) {
  22995. context.model.getRawData().cloneShallow(context.outputData);
  22996. }
  22997. }
  22998. // TODO refactor
  22999. function wrapData(data, seriesModel) {
  23000. each(concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
  23001. data.wrapMethod(methodName, curry(onDataChange, seriesModel));
  23002. });
  23003. }
  23004. function onDataChange(seriesModel, newList) {
  23005. var task = getCurrentTask(seriesModel);
  23006. if (task) {
  23007. // Consider case: filter, selectRange
  23008. task.setOutputEnd((newList || this).count());
  23009. }
  23010. return newList;
  23011. }
  23012. function getCurrentTask(seriesModel) {
  23013. var scheduler = (seriesModel.ecModel || {}).scheduler;
  23014. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  23015. if (pipeline) {
  23016. // When pipline finished, the currrentTask keep the last
  23017. // task (renderTask).
  23018. var task = pipeline.currentTask;
  23019. if (task) {
  23020. var agentStubMap = task.agentStubMap;
  23021. if (agentStubMap) {
  23022. task = agentStubMap.get(seriesModel.uid);
  23023. }
  23024. }
  23025. return task;
  23026. }
  23027. }
  23028. var ComponentView = /** @class */function () {
  23029. function ComponentView() {
  23030. this.group = new Group();
  23031. this.uid = getUID('viewComponent');
  23032. }
  23033. ComponentView.prototype.init = function (ecModel, api) {};
  23034. ComponentView.prototype.render = function (model, ecModel, api, payload) {};
  23035. ComponentView.prototype.dispose = function (ecModel, api) {};
  23036. ComponentView.prototype.updateView = function (model, ecModel, api, payload) {
  23037. // Do nothing;
  23038. };
  23039. ComponentView.prototype.updateLayout = function (model, ecModel, api, payload) {
  23040. // Do nothing;
  23041. };
  23042. ComponentView.prototype.updateVisual = function (model, ecModel, api, payload) {
  23043. // Do nothing;
  23044. };
  23045. /**
  23046. * Hook for toggle blur target series.
  23047. * Can be used in marker for blur or leave blur the markers
  23048. */
  23049. ComponentView.prototype.toggleBlurSeries = function (seriesModels, isBlur, ecModel) {
  23050. // Do nothing;
  23051. };
  23052. /**
  23053. * Traverse the new rendered elements.
  23054. *
  23055. * It will traverse the new added element in progressive rendering.
  23056. * And traverse all in normal rendering.
  23057. */
  23058. ComponentView.prototype.eachRendered = function (cb) {
  23059. var group = this.group;
  23060. if (group) {
  23061. group.traverse(cb);
  23062. }
  23063. };
  23064. return ComponentView;
  23065. }();
  23066. enableClassExtend(ComponentView);
  23067. enableClassManagement(ComponentView);
  23068. /**
  23069. * @return {string} If large mode changed, return string 'reset';
  23070. */
  23071. function createRenderPlanner() {
  23072. var inner = makeInner();
  23073. return function (seriesModel) {
  23074. var fields = inner(seriesModel);
  23075. var pipelineContext = seriesModel.pipelineContext;
  23076. var originalLarge = !!fields.large;
  23077. var originalProgressive = !!fields.progressiveRender;
  23078. // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  23079. // exists. See #11611 . Probably we need to modify this structure, see the comment
  23080. // on `performRawSeries` in `Schedular.js`.
  23081. var large = fields.large = !!(pipelineContext && pipelineContext.large);
  23082. var progressive = fields.progressiveRender = !!(pipelineContext && pipelineContext.progressiveRender);
  23083. return !!(originalLarge !== large || originalProgressive !== progressive) && 'reset';
  23084. };
  23085. }
  23086. var inner$2 = makeInner();
  23087. var renderPlanner = createRenderPlanner();
  23088. var ChartView = /** @class */function () {
  23089. function ChartView() {
  23090. this.group = new Group();
  23091. this.uid = getUID('viewChart');
  23092. this.renderTask = createTask({
  23093. plan: renderTaskPlan,
  23094. reset: renderTaskReset
  23095. });
  23096. this.renderTask.context = {
  23097. view: this
  23098. };
  23099. }
  23100. ChartView.prototype.init = function (ecModel, api) {};
  23101. ChartView.prototype.render = function (seriesModel, ecModel, api, payload) {
  23102. if ("development" !== 'production') {
  23103. throw new Error('render method must been implemented');
  23104. }
  23105. };
  23106. /**
  23107. * Highlight series or specified data item.
  23108. */
  23109. ChartView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  23110. var data = seriesModel.getData(payload && payload.dataType);
  23111. if (!data) {
  23112. if ("development" !== 'production') {
  23113. error("Unknown dataType " + payload.dataType);
  23114. }
  23115. return;
  23116. }
  23117. toggleHighlight(data, payload, 'emphasis');
  23118. };
  23119. /**
  23120. * Downplay series or specified data item.
  23121. */
  23122. ChartView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  23123. var data = seriesModel.getData(payload && payload.dataType);
  23124. if (!data) {
  23125. if ("development" !== 'production') {
  23126. error("Unknown dataType " + payload.dataType);
  23127. }
  23128. return;
  23129. }
  23130. toggleHighlight(data, payload, 'normal');
  23131. };
  23132. /**
  23133. * Remove self.
  23134. */
  23135. ChartView.prototype.remove = function (ecModel, api) {
  23136. this.group.removeAll();
  23137. };
  23138. /**
  23139. * Dispose self.
  23140. */
  23141. ChartView.prototype.dispose = function (ecModel, api) {};
  23142. ChartView.prototype.updateView = function (seriesModel, ecModel, api, payload) {
  23143. this.render(seriesModel, ecModel, api, payload);
  23144. };
  23145. // FIXME never used?
  23146. ChartView.prototype.updateLayout = function (seriesModel, ecModel, api, payload) {
  23147. this.render(seriesModel, ecModel, api, payload);
  23148. };
  23149. // FIXME never used?
  23150. ChartView.prototype.updateVisual = function (seriesModel, ecModel, api, payload) {
  23151. this.render(seriesModel, ecModel, api, payload);
  23152. };
  23153. /**
  23154. * Traverse the new rendered elements.
  23155. *
  23156. * It will traverse the new added element in progressive rendering.
  23157. * And traverse all in normal rendering.
  23158. */
  23159. ChartView.prototype.eachRendered = function (cb) {
  23160. traverseElements(this.group, cb);
  23161. };
  23162. ChartView.markUpdateMethod = function (payload, methodName) {
  23163. inner$2(payload).updateMethod = methodName;
  23164. };
  23165. ChartView.protoInitialize = function () {
  23166. var proto = ChartView.prototype;
  23167. proto.type = 'chart';
  23168. }();
  23169. return ChartView;
  23170. }();
  23171. /**
  23172. * Set state of single element
  23173. */
  23174. function elSetState(el, state, highlightDigit) {
  23175. if (el && isHighDownDispatcher(el)) {
  23176. (state === 'emphasis' ? enterEmphasis : leaveEmphasis)(el, highlightDigit);
  23177. }
  23178. }
  23179. function toggleHighlight(data, payload, state) {
  23180. var dataIndex = queryDataIndex(data, payload);
  23181. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  23182. if (dataIndex != null) {
  23183. each(normalizeToArray(dataIndex), function (dataIdx) {
  23184. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  23185. });
  23186. } else {
  23187. data.eachItemGraphicEl(function (el) {
  23188. elSetState(el, state, highlightDigit);
  23189. });
  23190. }
  23191. }
  23192. enableClassExtend(ChartView, ['dispose']);
  23193. enableClassManagement(ChartView);
  23194. function renderTaskPlan(context) {
  23195. return renderPlanner(context.model);
  23196. }
  23197. function renderTaskReset(context) {
  23198. var seriesModel = context.model;
  23199. var ecModel = context.ecModel;
  23200. var api = context.api;
  23201. var payload = context.payload;
  23202. // FIXME: remove updateView updateVisual
  23203. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  23204. var view = context.view;
  23205. var updateMethod = payload && inner$2(payload).updateMethod;
  23206. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod
  23207. // `appendData` is also supported when data amount
  23208. // is less than progressive threshold.
  23209. : 'render';
  23210. if (methodName !== 'render') {
  23211. view[methodName](seriesModel, ecModel, api, payload);
  23212. }
  23213. return progressMethodMap[methodName];
  23214. }
  23215. var progressMethodMap = {
  23216. incrementalPrepareRender: {
  23217. progress: function (params, context) {
  23218. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  23219. }
  23220. },
  23221. render: {
  23222. // Put view.render in `progress` to support appendData. But in this case
  23223. // view.render should not be called in reset, otherwise it will be called
  23224. // twise. Use `forceFirstProgress` to make sure that view.render is called
  23225. // in any cases.
  23226. forceFirstProgress: true,
  23227. progress: function (params, context) {
  23228. context.view.render(context.model, context.ecModel, context.api, context.payload);
  23229. }
  23230. }
  23231. };
  23232. /**
  23233. * @public
  23234. * @param {(Function)} fn
  23235. * @param {number} [delay=0] Unit: ms.
  23236. * @param {boolean} [debounce=false]
  23237. * true: If call interval less than `delay`, only the last call works.
  23238. * false: If call interval less than `delay, call works on fixed rate.
  23239. * @return {(Function)} throttled fn.
  23240. */
  23241. function throttle(fn, delay, debounce) {
  23242. var currCall;
  23243. var lastCall = 0;
  23244. var lastExec = 0;
  23245. var timer = null;
  23246. var diff;
  23247. var scope;
  23248. var args;
  23249. var debounceNextCall;
  23250. delay = delay || 0;
  23251. function exec() {
  23252. lastExec = new Date().getTime();
  23253. timer = null;
  23254. fn.apply(scope, args || []);
  23255. }
  23256. var cb = function () {
  23257. var cbArgs = [];
  23258. for (var _i = 0; _i < arguments.length; _i++) {
  23259. cbArgs[_i] = arguments[_i];
  23260. }
  23261. currCall = new Date().getTime();
  23262. scope = this;
  23263. args = cbArgs;
  23264. var thisDelay = debounceNextCall || delay;
  23265. var thisDebounce = debounceNextCall || debounce;
  23266. debounceNextCall = null;
  23267. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  23268. clearTimeout(timer);
  23269. // Here we should make sure that: the `exec` SHOULD NOT be called later
  23270. // than a new call of `cb`, that is, preserving the command order. Consider
  23271. // calculating "scale rate" when roaming as an example. When a call of `cb`
  23272. // happens, either the `exec` is called dierectly, or the call is delayed.
  23273. // But the delayed call should never be later than next call of `cb`. Under
  23274. // this assurance, we can simply update view state each time `dispatchAction`
  23275. // triggered by user roaming, but not need to add extra code to avoid the
  23276. // state being "rolled-back".
  23277. if (thisDebounce) {
  23278. timer = setTimeout(exec, thisDelay);
  23279. } else {
  23280. if (diff >= 0) {
  23281. exec();
  23282. } else {
  23283. timer = setTimeout(exec, -diff);
  23284. }
  23285. }
  23286. lastCall = currCall;
  23287. };
  23288. /**
  23289. * Clear throttle.
  23290. * @public
  23291. */
  23292. cb.clear = function () {
  23293. if (timer) {
  23294. clearTimeout(timer);
  23295. timer = null;
  23296. }
  23297. };
  23298. /**
  23299. * Enable debounce once.
  23300. */
  23301. cb.debounceNextCall = function (debounceDelay) {
  23302. debounceNextCall = debounceDelay;
  23303. };
  23304. return cb;
  23305. }
  23306. var inner$3 = makeInner();
  23307. var defaultStyleMappers = {
  23308. itemStyle: makeStyleMapper(ITEM_STYLE_KEY_MAP, true),
  23309. lineStyle: makeStyleMapper(LINE_STYLE_KEY_MAP, true)
  23310. };
  23311. var defaultColorKey = {
  23312. lineStyle: 'stroke',
  23313. itemStyle: 'fill'
  23314. };
  23315. function getStyleMapper(seriesModel, stylePath) {
  23316. var styleMapper = seriesModel.visualStyleMapper || defaultStyleMappers[stylePath];
  23317. if (!styleMapper) {
  23318. console.warn("Unknown style type '" + stylePath + "'.");
  23319. return defaultStyleMappers.itemStyle;
  23320. }
  23321. return styleMapper;
  23322. }
  23323. function getDefaultColorKey(seriesModel, stylePath) {
  23324. // return defaultColorKey[stylePath] ||
  23325. var colorKey = seriesModel.visualDrawType || defaultColorKey[stylePath];
  23326. if (!colorKey) {
  23327. console.warn("Unknown style type '" + stylePath + "'.");
  23328. return 'fill';
  23329. }
  23330. return colorKey;
  23331. }
  23332. var seriesStyleTask = {
  23333. createOnAllSeries: true,
  23334. performRawSeries: true,
  23335. reset: function (seriesModel, ecModel) {
  23336. var data = seriesModel.getData();
  23337. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  23338. // Set in itemStyle
  23339. var styleModel = seriesModel.getModel(stylePath);
  23340. var getStyle = getStyleMapper(seriesModel, stylePath);
  23341. var globalStyle = getStyle(styleModel);
  23342. var decalOption = styleModel.getShallow('decal');
  23343. if (decalOption) {
  23344. data.setVisual('decal', decalOption);
  23345. decalOption.dirty = true;
  23346. }
  23347. // TODO
  23348. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  23349. var color = globalStyle[colorKey];
  23350. // TODO style callback
  23351. var colorCallback = isFunction(color) ? color : null;
  23352. var hasAutoColor = globalStyle.fill === 'auto' || globalStyle.stroke === 'auto';
  23353. // Get from color palette by default.
  23354. if (!globalStyle[colorKey] || colorCallback || hasAutoColor) {
  23355. // Note: If some series has color specified (e.g., by itemStyle.color), we DO NOT
  23356. // make it effect palette. Because some scenarios users need to make some series
  23357. // transparent or as background, which should better not effect the palette.
  23358. var colorPalette = seriesModel.getColorFromPalette(
  23359. // TODO series count changed.
  23360. seriesModel.name, null, ecModel.getSeriesCount());
  23361. if (!globalStyle[colorKey]) {
  23362. globalStyle[colorKey] = colorPalette;
  23363. data.setVisual('colorFromPalette', true);
  23364. }
  23365. globalStyle.fill = globalStyle.fill === 'auto' || isFunction(globalStyle.fill) ? colorPalette : globalStyle.fill;
  23366. globalStyle.stroke = globalStyle.stroke === 'auto' || isFunction(globalStyle.stroke) ? colorPalette : globalStyle.stroke;
  23367. }
  23368. data.setVisual('style', globalStyle);
  23369. data.setVisual('drawType', colorKey);
  23370. // Only visible series has each data be visual encoded
  23371. if (!ecModel.isSeriesFiltered(seriesModel) && colorCallback) {
  23372. data.setVisual('colorFromPalette', false);
  23373. return {
  23374. dataEach: function (data, idx) {
  23375. var dataParams = seriesModel.getDataParams(idx);
  23376. var itemStyle = extend({}, globalStyle);
  23377. itemStyle[colorKey] = colorCallback(dataParams);
  23378. data.setItemVisual(idx, 'style', itemStyle);
  23379. }
  23380. };
  23381. }
  23382. }
  23383. };
  23384. var sharedModel = new Model();
  23385. var dataStyleTask = {
  23386. createOnAllSeries: true,
  23387. performRawSeries: true,
  23388. reset: function (seriesModel, ecModel) {
  23389. if (seriesModel.ignoreStyleOnData || ecModel.isSeriesFiltered(seriesModel)) {
  23390. return;
  23391. }
  23392. var data = seriesModel.getData();
  23393. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  23394. // Set in itemStyle
  23395. var getStyle = getStyleMapper(seriesModel, stylePath);
  23396. var colorKey = data.getVisual('drawType');
  23397. return {
  23398. dataEach: data.hasItemOption ? function (data, idx) {
  23399. // Not use getItemModel for performance considuration
  23400. var rawItem = data.getRawDataItem(idx);
  23401. if (rawItem && rawItem[stylePath]) {
  23402. sharedModel.option = rawItem[stylePath];
  23403. var style = getStyle(sharedModel);
  23404. var existsStyle = data.ensureUniqueItemVisual(idx, 'style');
  23405. extend(existsStyle, style);
  23406. if (sharedModel.option.decal) {
  23407. data.setItemVisual(idx, 'decal', sharedModel.option.decal);
  23408. sharedModel.option.decal.dirty = true;
  23409. }
  23410. if (colorKey in style) {
  23411. data.setItemVisual(idx, 'colorFromPalette', false);
  23412. }
  23413. }
  23414. } : null
  23415. };
  23416. }
  23417. };
  23418. // Pick color from palette for the data which has not been set with color yet.
  23419. // Note: do not support stream rendering. No such cases yet.
  23420. var dataColorPaletteTask = {
  23421. performRawSeries: true,
  23422. overallReset: function (ecModel) {
  23423. // Each type of series uses one scope.
  23424. // Pie and funnel are using different scopes.
  23425. var paletteScopeGroupByType = createHashMap();
  23426. ecModel.eachSeries(function (seriesModel) {
  23427. var colorBy = seriesModel.getColorBy();
  23428. if (seriesModel.isColorBySeries()) {
  23429. return;
  23430. }
  23431. var key = seriesModel.type + '-' + colorBy;
  23432. var colorScope = paletteScopeGroupByType.get(key);
  23433. if (!colorScope) {
  23434. colorScope = {};
  23435. paletteScopeGroupByType.set(key, colorScope);
  23436. }
  23437. inner$3(seriesModel).scope = colorScope;
  23438. });
  23439. ecModel.eachSeries(function (seriesModel) {
  23440. if (seriesModel.isColorBySeries() || ecModel.isSeriesFiltered(seriesModel)) {
  23441. return;
  23442. }
  23443. var dataAll = seriesModel.getRawData();
  23444. var idxMap = {};
  23445. var data = seriesModel.getData();
  23446. var colorScope = inner$3(seriesModel).scope;
  23447. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  23448. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  23449. data.each(function (idx) {
  23450. var rawIdx = data.getRawIndex(idx);
  23451. idxMap[rawIdx] = idx;
  23452. });
  23453. // Iterate on data before filtered. To make sure color from palette can be
  23454. // Consistent when toggling legend.
  23455. dataAll.each(function (rawIdx) {
  23456. var idx = idxMap[rawIdx];
  23457. var fromPalette = data.getItemVisual(idx, 'colorFromPalette');
  23458. // Get color from palette for each data only when the color is inherited from series color, which is
  23459. // also picked from color palette. So following situation is not in the case:
  23460. // 1. series.itemStyle.color is set
  23461. // 2. color is encoded by visualMap
  23462. if (fromPalette) {
  23463. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  23464. var name_1 = dataAll.getName(rawIdx) || rawIdx + '';
  23465. var dataCount = dataAll.count();
  23466. itemStyle[colorKey] = seriesModel.getColorFromPalette(name_1, colorScope, dataCount);
  23467. }
  23468. });
  23469. });
  23470. }
  23471. };
  23472. var PI$3 = Math.PI;
  23473. /**
  23474. * @param {module:echarts/ExtensionAPI} api
  23475. * @param {Object} [opts]
  23476. * @param {string} [opts.text]
  23477. * @param {string} [opts.color]
  23478. * @param {string} [opts.textColor]
  23479. * @return {module:zrender/Element}
  23480. */
  23481. function defaultLoading(api, opts) {
  23482. opts = opts || {};
  23483. defaults(opts, {
  23484. text: 'loading',
  23485. textColor: tokens.color.primary,
  23486. fontSize: 12,
  23487. fontWeight: 'normal',
  23488. fontStyle: 'normal',
  23489. fontFamily: 'sans-serif',
  23490. maskColor: 'rgba(255,255,255,0.8)',
  23491. showSpinner: true,
  23492. color: tokens.color.theme[0],
  23493. spinnerRadius: 10,
  23494. lineWidth: 5,
  23495. zlevel: 0
  23496. });
  23497. var group = new Group();
  23498. var mask = new Rect({
  23499. style: {
  23500. fill: opts.maskColor
  23501. },
  23502. zlevel: opts.zlevel,
  23503. z: 10000
  23504. });
  23505. group.add(mask);
  23506. var textContent = new ZRText({
  23507. style: {
  23508. text: opts.text,
  23509. fill: opts.textColor,
  23510. fontSize: opts.fontSize,
  23511. fontWeight: opts.fontWeight,
  23512. fontStyle: opts.fontStyle,
  23513. fontFamily: opts.fontFamily
  23514. },
  23515. zlevel: opts.zlevel,
  23516. z: 10001
  23517. });
  23518. var labelRect = new Rect({
  23519. style: {
  23520. fill: 'none'
  23521. },
  23522. textContent: textContent,
  23523. textConfig: {
  23524. position: 'right',
  23525. distance: 10
  23526. },
  23527. zlevel: opts.zlevel,
  23528. z: 10001
  23529. });
  23530. group.add(labelRect);
  23531. var arc;
  23532. if (opts.showSpinner) {
  23533. arc = new Arc({
  23534. shape: {
  23535. startAngle: -PI$3 / 2,
  23536. endAngle: -PI$3 / 2 + 0.1,
  23537. r: opts.spinnerRadius
  23538. },
  23539. style: {
  23540. stroke: opts.color,
  23541. lineCap: 'round',
  23542. lineWidth: opts.lineWidth
  23543. },
  23544. zlevel: opts.zlevel,
  23545. z: 10001
  23546. });
  23547. arc.animateShape(true).when(1000, {
  23548. endAngle: PI$3 * 3 / 2
  23549. }).start('circularInOut');
  23550. arc.animateShape(true).when(1000, {
  23551. startAngle: PI$3 * 3 / 2
  23552. }).delay(300).start('circularInOut');
  23553. group.add(arc);
  23554. }
  23555. // Inject resize
  23556. group.resize = function () {
  23557. var textWidth = textContent.getBoundingRect().width;
  23558. var r = opts.showSpinner ? opts.spinnerRadius : 0;
  23559. // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  23560. // textDistance needs to be calculated when both animation and text exist
  23561. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 - (opts.showSpinner && textWidth ? 0 : 5 + textWidth / 2)
  23562. // only show the text
  23563. + (opts.showSpinner ? 0 : textWidth / 2)
  23564. // only show the spinner
  23565. + (textWidth ? 0 : r);
  23566. var cy = api.getHeight() / 2;
  23567. opts.showSpinner && arc.setShape({
  23568. cx: cx,
  23569. cy: cy
  23570. });
  23571. labelRect.setShape({
  23572. x: cx - r,
  23573. y: cy - r,
  23574. width: r * 2,
  23575. height: r * 2
  23576. });
  23577. mask.setShape({
  23578. x: 0,
  23579. y: 0,
  23580. width: api.getWidth(),
  23581. height: api.getHeight()
  23582. });
  23583. };
  23584. group.resize();
  23585. return group;
  23586. }
  23587. var Scheduler = /** @class */function () {
  23588. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  23589. // key: handlerUID
  23590. this._stageTaskMap = createHashMap();
  23591. this.ecInstance = ecInstance;
  23592. this.api = api;
  23593. // Fix current processors in case that in some rear cases that
  23594. // processors might be registered after echarts instance created.
  23595. // Register processors incrementally for a echarts instance is
  23596. // not supported by this stream architecture.
  23597. dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  23598. visualHandlers = this._visualHandlers = visualHandlers.slice();
  23599. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  23600. }
  23601. Scheduler.prototype.restoreData = function (ecModel, payload) {
  23602. // TODO: Only restore needed series and components, but not all components.
  23603. // Currently `restoreData` of all of the series and component will be called.
  23604. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  23605. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  23606. // and some components like coordinate system, axes, dataZoom, visualMap only
  23607. // need their target series refresh.
  23608. // (1) If we are implementing this feature some day, we should consider these cases:
  23609. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  23610. // on the settings of `dataZoom`), it should be re-performed if the component
  23611. // is modified by `setOption`.
  23612. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  23613. // it should be re-performed when the result array of `getTargetSeries` changed.
  23614. // We use `dependencies` to cover these issues.
  23615. // (3) How to update target series when coordinate system related components modified.
  23616. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  23617. // and this case all of the tasks will be set as dirty.
  23618. ecModel.restoreData(payload);
  23619. // Theoretically an overall task not only depends on each of its target series, but also
  23620. // depends on all of the series.
  23621. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  23622. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  23623. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  23624. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  23625. // probably cause state chaos (consider `dataZoomProcessor`).
  23626. this._stageTaskMap.each(function (taskRecord) {
  23627. var overallTask = taskRecord.overallTask;
  23628. overallTask && overallTask.dirty();
  23629. });
  23630. };
  23631. // If seriesModel provided, incremental threshold is check by series data.
  23632. Scheduler.prototype.getPerformArgs = function (task, isBlock) {
  23633. // For overall task
  23634. if (!task.__pipeline) {
  23635. return;
  23636. }
  23637. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  23638. var pCtx = pipeline.context;
  23639. var incremental = !isBlock && pipeline.progressiveEnabled && (!pCtx || pCtx.progressiveRender) && task.__idxInPipeline > pipeline.blockIndex;
  23640. var step = incremental ? pipeline.step : null;
  23641. var modDataCount = pCtx && pCtx.modDataCount;
  23642. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  23643. return {
  23644. step: step,
  23645. modBy: modBy,
  23646. modDataCount: modDataCount
  23647. };
  23648. };
  23649. Scheduler.prototype.getPipeline = function (pipelineId) {
  23650. return this._pipelineMap.get(pipelineId);
  23651. };
  23652. /**
  23653. * Current, progressive rendering starts from visual and layout.
  23654. * Always detect render mode in the same stage, avoiding that incorrect
  23655. * detection caused by data filtering.
  23656. * Caution:
  23657. * `updateStreamModes` use `seriesModel.getData()`.
  23658. */
  23659. Scheduler.prototype.updateStreamModes = function (seriesModel, view) {
  23660. var pipeline = this._pipelineMap.get(seriesModel.uid);
  23661. var data = seriesModel.getData();
  23662. var dataLen = data.count();
  23663. // `progressiveRender` means that can render progressively in each
  23664. // animation frame. Note that some types of series do not provide
  23665. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  23666. // use the term `incremental` but not `progressive` to describe the
  23667. // case that `chart.appendData`.
  23668. var progressiveRender = pipeline.progressiveEnabled && view.incrementalPrepareRender && dataLen >= pipeline.threshold;
  23669. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');
  23670. // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  23671. // see `test/candlestick-large3.html`
  23672. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  23673. seriesModel.pipelineContext = pipeline.context = {
  23674. progressiveRender: progressiveRender,
  23675. modDataCount: modDataCount,
  23676. large: large
  23677. };
  23678. };
  23679. Scheduler.prototype.restorePipelines = function (ecModel) {
  23680. var scheduler = this;
  23681. var pipelineMap = scheduler._pipelineMap = createHashMap();
  23682. ecModel.eachSeries(function (seriesModel) {
  23683. var progressive = seriesModel.getProgressive();
  23684. var pipelineId = seriesModel.uid;
  23685. pipelineMap.set(pipelineId, {
  23686. id: pipelineId,
  23687. head: null,
  23688. tail: null,
  23689. threshold: seriesModel.getProgressiveThreshold(),
  23690. progressiveEnabled: progressive && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  23691. blockIndex: -1,
  23692. step: Math.round(progressive || 700),
  23693. count: 0
  23694. });
  23695. scheduler._pipe(seriesModel, seriesModel.dataTask);
  23696. });
  23697. };
  23698. Scheduler.prototype.prepareStageTasks = function () {
  23699. var stageTaskMap = this._stageTaskMap;
  23700. var ecModel = this.api.getModel();
  23701. var api = this.api;
  23702. each(this._allHandlers, function (handler) {
  23703. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, {});
  23704. var errMsg = '';
  23705. if ("development" !== 'production') {
  23706. // Currently do not need to support to sepecify them both.
  23707. errMsg = '"reset" and "overallReset" must not be both specified.';
  23708. }
  23709. assert(!(handler.reset && handler.overallReset), errMsg);
  23710. handler.reset && this._createSeriesStageTask(handler, record, ecModel, api);
  23711. handler.overallReset && this._createOverallStageTask(handler, record, ecModel, api);
  23712. }, this);
  23713. };
  23714. Scheduler.prototype.prepareView = function (view, model, ecModel, api) {
  23715. var renderTask = view.renderTask;
  23716. var context = renderTask.context;
  23717. context.model = model;
  23718. context.ecModel = ecModel;
  23719. context.api = api;
  23720. renderTask.__block = !view.incrementalPrepareRender;
  23721. this._pipe(model, renderTask);
  23722. };
  23723. Scheduler.prototype.performDataProcessorTasks = function (ecModel, payload) {
  23724. // If we do not use `block` here, it should be considered when to update modes.
  23725. this._performStageTasks(this._dataProcessorHandlers, ecModel, payload, {
  23726. block: true
  23727. });
  23728. };
  23729. Scheduler.prototype.performVisualTasks = function (ecModel, payload, opt) {
  23730. this._performStageTasks(this._visualHandlers, ecModel, payload, opt);
  23731. };
  23732. Scheduler.prototype._performStageTasks = function (stageHandlers, ecModel, payload, opt) {
  23733. opt = opt || {};
  23734. var unfinished = false;
  23735. var scheduler = this;
  23736. each(stageHandlers, function (stageHandler, idx) {
  23737. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  23738. return;
  23739. }
  23740. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  23741. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  23742. var overallTask = stageHandlerRecord.overallTask;
  23743. if (overallTask) {
  23744. var overallNeedDirty_1;
  23745. var agentStubMap = overallTask.agentStubMap;
  23746. agentStubMap.each(function (stub) {
  23747. if (needSetDirty(opt, stub)) {
  23748. stub.dirty();
  23749. overallNeedDirty_1 = true;
  23750. }
  23751. });
  23752. overallNeedDirty_1 && overallTask.dirty();
  23753. scheduler.updatePayload(overallTask, payload);
  23754. var performArgs_1 = scheduler.getPerformArgs(overallTask, opt.block);
  23755. // Execute stubs firstly, which may set the overall task dirty,
  23756. // then execute the overall task. And stub will call seriesModel.setData,
  23757. // which ensures that in the overallTask seriesModel.getData() will not
  23758. // return incorrect data.
  23759. agentStubMap.each(function (stub) {
  23760. stub.perform(performArgs_1);
  23761. });
  23762. if (overallTask.perform(performArgs_1)) {
  23763. unfinished = true;
  23764. }
  23765. } else if (seriesTaskMap) {
  23766. seriesTaskMap.each(function (task, pipelineId) {
  23767. if (needSetDirty(opt, task)) {
  23768. task.dirty();
  23769. }
  23770. var performArgs = scheduler.getPerformArgs(task, opt.block);
  23771. // FIXME
  23772. // if intending to declare `performRawSeries` in handlers, only
  23773. // stream-independent (specifically, data item independent) operations can be
  23774. // performed. Because if a series is filtered, most of the tasks will not
  23775. // be performed. A stream-dependent operation probably cause wrong biz logic.
  23776. // Perhaps we should not provide a separate callback for this case instead
  23777. // of providing the config `performRawSeries`. The stream-dependent operations
  23778. // and stream-independent operations should better not be mixed.
  23779. performArgs.skip = !stageHandler.performRawSeries && ecModel.isSeriesFiltered(task.context.model);
  23780. scheduler.updatePayload(task, payload);
  23781. if (task.perform(performArgs)) {
  23782. unfinished = true;
  23783. }
  23784. });
  23785. }
  23786. });
  23787. function needSetDirty(opt, task) {
  23788. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  23789. }
  23790. this.unfinished = unfinished || this.unfinished;
  23791. };
  23792. Scheduler.prototype.performSeriesTasks = function (ecModel) {
  23793. var unfinished;
  23794. ecModel.eachSeries(function (seriesModel) {
  23795. // Progress to the end for dataInit and dataRestore.
  23796. unfinished = seriesModel.dataTask.perform() || unfinished;
  23797. });
  23798. this.unfinished = unfinished || this.unfinished;
  23799. };
  23800. Scheduler.prototype.plan = function () {
  23801. // Travel pipelines, check block.
  23802. this._pipelineMap.each(function (pipeline) {
  23803. var task = pipeline.tail;
  23804. do {
  23805. if (task.__block) {
  23806. pipeline.blockIndex = task.__idxInPipeline;
  23807. break;
  23808. }
  23809. task = task.getUpstream();
  23810. } while (task);
  23811. });
  23812. };
  23813. Scheduler.prototype.updatePayload = function (task, payload) {
  23814. payload !== 'remain' && (task.context.payload = payload);
  23815. };
  23816. Scheduler.prototype._createSeriesStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  23817. var scheduler = this;
  23818. var oldSeriesTaskMap = stageHandlerRecord.seriesTaskMap;
  23819. // The count of stages are totally about only several dozen, so
  23820. // do not need to reuse the map.
  23821. var newSeriesTaskMap = stageHandlerRecord.seriesTaskMap = createHashMap();
  23822. var seriesType = stageHandler.seriesType;
  23823. var getTargetSeries = stageHandler.getTargetSeries;
  23824. // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  23825. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  23826. // it works but it may cause other irrelevant charts blocked.
  23827. if (stageHandler.createOnAllSeries) {
  23828. ecModel.eachRawSeries(create);
  23829. } else if (seriesType) {
  23830. ecModel.eachRawSeriesByType(seriesType, create);
  23831. } else if (getTargetSeries) {
  23832. getTargetSeries(ecModel, api).each(create);
  23833. }
  23834. function create(seriesModel) {
  23835. var pipelineId = seriesModel.uid;
  23836. // Init tasks for each seriesModel only once.
  23837. // Reuse original task instance.
  23838. var task = newSeriesTaskMap.set(pipelineId, oldSeriesTaskMap && oldSeriesTaskMap.get(pipelineId) || createTask({
  23839. plan: seriesTaskPlan,
  23840. reset: seriesTaskReset,
  23841. count: seriesTaskCount
  23842. }));
  23843. task.context = {
  23844. model: seriesModel,
  23845. ecModel: ecModel,
  23846. api: api,
  23847. // PENDING: `useClearVisual` not used?
  23848. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  23849. plan: stageHandler.plan,
  23850. reset: stageHandler.reset,
  23851. scheduler: scheduler
  23852. };
  23853. scheduler._pipe(seriesModel, task);
  23854. }
  23855. };
  23856. Scheduler.prototype._createOverallStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  23857. var scheduler = this;
  23858. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask
  23859. // For overall task, the function only be called on reset stage.
  23860. || createTask({
  23861. reset: overallTaskReset
  23862. });
  23863. overallTask.context = {
  23864. ecModel: ecModel,
  23865. api: api,
  23866. overallReset: stageHandler.overallReset,
  23867. scheduler: scheduler
  23868. };
  23869. var oldAgentStubMap = overallTask.agentStubMap;
  23870. // The count of stages are totally about only several dozen, so
  23871. // do not need to reuse the map.
  23872. var newAgentStubMap = overallTask.agentStubMap = createHashMap();
  23873. var seriesType = stageHandler.seriesType;
  23874. var getTargetSeries = stageHandler.getTargetSeries;
  23875. var overallProgress = true;
  23876. var shouldOverallTaskDirty = false;
  23877. // FIXME:TS never used, so comment it
  23878. // let modifyOutputEnd = stageHandler.modifyOutputEnd;
  23879. // An overall task with seriesType detected or has `getTargetSeries`, we add
  23880. // stub in each pipelines, it will set the overall task dirty when the pipeline
  23881. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  23882. // we set the pipeline block.
  23883. var errMsg = '';
  23884. if ("development" !== 'production') {
  23885. errMsg = '"createOnAllSeries" is not supported for "overallReset", ' + 'because it will block all streams.';
  23886. }
  23887. assert(!stageHandler.createOnAllSeries, errMsg);
  23888. if (seriesType) {
  23889. ecModel.eachRawSeriesByType(seriesType, createStub);
  23890. } else if (getTargetSeries) {
  23891. getTargetSeries(ecModel, api).each(createStub);
  23892. }
  23893. // Otherwise, (usually it is legacy case), the overall task will only be
  23894. // executed when upstream is dirty. Otherwise the progressive rendering of all
  23895. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  23896. // dirty info from upstream.
  23897. else {
  23898. overallProgress = false;
  23899. each(ecModel.getSeries(), createStub);
  23900. }
  23901. function createStub(seriesModel) {
  23902. var pipelineId = seriesModel.uid;
  23903. var stub = newAgentStubMap.set(pipelineId, oldAgentStubMap && oldAgentStubMap.get(pipelineId) || (
  23904. // When the result of `getTargetSeries` changed, the overallTask
  23905. // should be set as dirty and re-performed.
  23906. shouldOverallTaskDirty = true, createTask({
  23907. reset: stubReset,
  23908. onDirty: stubOnDirty
  23909. })));
  23910. stub.context = {
  23911. model: seriesModel,
  23912. overallProgress: overallProgress
  23913. // FIXME:TS never used, so comment it
  23914. // modifyOutputEnd: modifyOutputEnd
  23915. };
  23916. stub.agent = overallTask;
  23917. stub.__block = overallProgress;
  23918. scheduler._pipe(seriesModel, stub);
  23919. }
  23920. if (shouldOverallTaskDirty) {
  23921. overallTask.dirty();
  23922. }
  23923. };
  23924. Scheduler.prototype._pipe = function (seriesModel, task) {
  23925. var pipelineId = seriesModel.uid;
  23926. var pipeline = this._pipelineMap.get(pipelineId);
  23927. !pipeline.head && (pipeline.head = task);
  23928. pipeline.tail && pipeline.tail.pipe(task);
  23929. pipeline.tail = task;
  23930. task.__idxInPipeline = pipeline.count++;
  23931. task.__pipeline = pipeline;
  23932. };
  23933. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  23934. if (isFunction(stageHandler)) {
  23935. stageHandler = {
  23936. overallReset: stageHandler,
  23937. seriesType: detectSeriseType(stageHandler)
  23938. };
  23939. }
  23940. stageHandler.uid = getUID('stageHandler');
  23941. visualType && (stageHandler.visualType = visualType);
  23942. return stageHandler;
  23943. };
  23944. return Scheduler;
  23945. }();
  23946. function overallTaskReset(context) {
  23947. context.overallReset(context.ecModel, context.api, context.payload);
  23948. }
  23949. function stubReset(context) {
  23950. return context.overallProgress && stubProgress;
  23951. }
  23952. function stubProgress() {
  23953. this.agent.dirty();
  23954. this.getDownstream().dirty();
  23955. }
  23956. function stubOnDirty() {
  23957. this.agent && this.agent.dirty();
  23958. }
  23959. function seriesTaskPlan(context) {
  23960. return context.plan ? context.plan(context.model, context.ecModel, context.api, context.payload) : null;
  23961. }
  23962. function seriesTaskReset(context) {
  23963. if (context.useClearVisual) {
  23964. context.data.clearAllVisual();
  23965. }
  23966. var resetDefines = context.resetDefines = normalizeToArray(context.reset(context.model, context.ecModel, context.api, context.payload));
  23967. return resetDefines.length > 1 ? map(resetDefines, function (v, idx) {
  23968. return makeSeriesTaskProgress(idx);
  23969. }) : singleSeriesTaskProgress;
  23970. }
  23971. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  23972. function makeSeriesTaskProgress(resetDefineIdx) {
  23973. return function (params, context) {
  23974. var data = context.data;
  23975. var resetDefine = context.resetDefines[resetDefineIdx];
  23976. if (resetDefine && resetDefine.dataEach) {
  23977. for (var i = params.start; i < params.end; i++) {
  23978. resetDefine.dataEach(data, i);
  23979. }
  23980. } else if (resetDefine && resetDefine.progress) {
  23981. resetDefine.progress(params, data);
  23982. }
  23983. };
  23984. }
  23985. function seriesTaskCount(context) {
  23986. return context.data.count();
  23987. }
  23988. /**
  23989. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  23990. * To ensure that they can work normally, they should work in block mode, that is,
  23991. * they should not be started util the previous tasks finished. So they cause the
  23992. * progressive rendering disabled. We try to detect the series type, to narrow down
  23993. * the block range to only the series type they concern, but not all series.
  23994. */
  23995. function detectSeriseType(legacyFunc) {
  23996. seriesType = null;
  23997. try {
  23998. // Assume there is no async when calling `eachSeriesByType`.
  23999. legacyFunc(ecModelMock, apiMock);
  24000. } catch (e) {}
  24001. return seriesType;
  24002. }
  24003. var ecModelMock = {};
  24004. var apiMock = {};
  24005. var seriesType;
  24006. mockMethods(ecModelMock, GlobalModel);
  24007. mockMethods(apiMock, ExtensionAPI);
  24008. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  24009. seriesType = type;
  24010. };
  24011. ecModelMock.eachComponent = function (cond) {
  24012. if (cond.mainType === 'series' && cond.subType) {
  24013. seriesType = cond.subType;
  24014. }
  24015. };
  24016. function mockMethods(target, Clz) {
  24017. /* eslint-disable */
  24018. for (var name_1 in Clz.prototype) {
  24019. // Do not use hasOwnProperty
  24020. target[name_1] = noop;
  24021. }
  24022. /* eslint-enable */
  24023. }
  24024. var color$2 = tokens.darkColor;
  24025. var backgroundColor = color$2.background;
  24026. var axisCommon = function () {
  24027. return {
  24028. axisLine: {
  24029. lineStyle: {
  24030. color: color$2.axisLine
  24031. }
  24032. },
  24033. splitLine: {
  24034. lineStyle: {
  24035. color: color$2.axisSplitLine
  24036. }
  24037. },
  24038. splitArea: {
  24039. areaStyle: {
  24040. color: [color$2.backgroundTint, color$2.backgroundTransparent]
  24041. }
  24042. },
  24043. minorSplitLine: {
  24044. lineStyle: {
  24045. color: color$2.axisMinorSplitLine
  24046. }
  24047. },
  24048. axisLabel: {
  24049. color: color$2.axisLabel
  24050. },
  24051. axisName: {}
  24052. };
  24053. };
  24054. var matrixAxis = {
  24055. label: {
  24056. color: color$2.secondary
  24057. },
  24058. itemStyle: {
  24059. borderColor: color$2.borderTint
  24060. },
  24061. dividerLineStyle: {
  24062. color: color$2.border
  24063. }
  24064. };
  24065. var theme = {
  24066. darkMode: true,
  24067. color: color$2.theme,
  24068. backgroundColor: backgroundColor,
  24069. axisPointer: {
  24070. lineStyle: {
  24071. color: color$2.border
  24072. },
  24073. crossStyle: {
  24074. color: color$2.borderShade
  24075. },
  24076. label: {
  24077. color: color$2.tertiary
  24078. }
  24079. },
  24080. legend: {
  24081. textStyle: {
  24082. color: color$2.secondary
  24083. },
  24084. pageTextStyle: {
  24085. color: color$2.tertiary
  24086. }
  24087. },
  24088. textStyle: {
  24089. color: color$2.secondary
  24090. },
  24091. title: {
  24092. textStyle: {
  24093. color: color$2.primary
  24094. },
  24095. subtextStyle: {
  24096. color: color$2.quaternary
  24097. }
  24098. },
  24099. toolbox: {
  24100. iconStyle: {
  24101. borderColor: color$2.accent50
  24102. }
  24103. },
  24104. tooltip: {
  24105. backgroundColor: color$2.neutral20,
  24106. defaultBorderColor: color$2.border,
  24107. textStyle: {
  24108. color: color$2.tertiary
  24109. }
  24110. },
  24111. dataZoom: {
  24112. borderColor: color$2.accent10,
  24113. textStyle: {
  24114. color: color$2.tertiary
  24115. },
  24116. brushStyle: {
  24117. color: color$2.backgroundTint
  24118. },
  24119. handleStyle: {
  24120. color: color$2.neutral00,
  24121. borderColor: color$2.accent20
  24122. },
  24123. moveHandleStyle: {
  24124. color: color$2.accent40
  24125. },
  24126. emphasis: {
  24127. handleStyle: {
  24128. borderColor: color$2.accent50
  24129. }
  24130. },
  24131. dataBackground: {
  24132. lineStyle: {
  24133. color: color$2.accent30
  24134. },
  24135. areaStyle: {
  24136. color: color$2.accent20
  24137. }
  24138. },
  24139. selectedDataBackground: {
  24140. lineStyle: {
  24141. color: color$2.accent50
  24142. },
  24143. areaStyle: {
  24144. color: color$2.accent30
  24145. }
  24146. }
  24147. },
  24148. visualMap: {
  24149. textStyle: {
  24150. color: color$2.secondary
  24151. },
  24152. handleStyle: {
  24153. borderColor: color$2.neutral30
  24154. }
  24155. },
  24156. timeline: {
  24157. lineStyle: {
  24158. color: color$2.accent10
  24159. },
  24160. label: {
  24161. color: color$2.tertiary
  24162. },
  24163. controlStyle: {
  24164. color: color$2.accent30,
  24165. borderColor: color$2.accent30
  24166. }
  24167. },
  24168. calendar: {
  24169. itemStyle: {
  24170. color: color$2.neutral00,
  24171. borderColor: color$2.neutral20
  24172. },
  24173. dayLabel: {
  24174. color: color$2.tertiary
  24175. },
  24176. monthLabel: {
  24177. color: color$2.secondary
  24178. },
  24179. yearLabel: {
  24180. color: color$2.secondary
  24181. }
  24182. },
  24183. matrix: {
  24184. x: matrixAxis,
  24185. y: matrixAxis,
  24186. backgroundColor: {
  24187. borderColor: color$2.axisLine
  24188. },
  24189. body: {
  24190. itemStyle: {
  24191. borderColor: color$2.borderTint
  24192. }
  24193. }
  24194. },
  24195. timeAxis: axisCommon(),
  24196. logAxis: axisCommon(),
  24197. valueAxis: axisCommon(),
  24198. categoryAxis: axisCommon(),
  24199. line: {
  24200. symbol: 'circle'
  24201. },
  24202. graph: {
  24203. color: color$2.theme
  24204. },
  24205. gauge: {
  24206. title: {
  24207. color: color$2.secondary
  24208. },
  24209. axisLine: {
  24210. lineStyle: {
  24211. color: [[1, color$2.neutral05]]
  24212. }
  24213. },
  24214. axisLabel: {
  24215. color: color$2.axisLabel
  24216. },
  24217. detail: {
  24218. color: color$2.primary
  24219. }
  24220. },
  24221. candlestick: {
  24222. itemStyle: {
  24223. color: '#f64e56',
  24224. color0: '#54ea92',
  24225. borderColor: '#f64e56',
  24226. borderColor0: '#54ea92'
  24227. // borderColor: '#ca2824',
  24228. // borderColor0: '#09a443'
  24229. }
  24230. },
  24231. funnel: {
  24232. itemStyle: {
  24233. borderColor: color$2.background
  24234. }
  24235. },
  24236. radar: function () {
  24237. var radar = axisCommon();
  24238. radar.axisName = {
  24239. color: color$2.axisLabel
  24240. };
  24241. radar.axisLine.lineStyle.color = color$2.neutral20;
  24242. return radar;
  24243. }(),
  24244. treemap: {
  24245. breadcrumb: {
  24246. itemStyle: {
  24247. color: color$2.neutral20,
  24248. textStyle: {
  24249. color: color$2.secondary
  24250. }
  24251. },
  24252. emphasis: {
  24253. itemStyle: {
  24254. color: color$2.neutral30
  24255. }
  24256. }
  24257. }
  24258. },
  24259. sunburst: {
  24260. itemStyle: {
  24261. borderColor: color$2.background
  24262. }
  24263. },
  24264. map: {
  24265. itemStyle: {
  24266. borderColor: color$2.border,
  24267. areaColor: color$2.neutral10
  24268. },
  24269. label: {
  24270. color: color$2.tertiary
  24271. },
  24272. emphasis: {
  24273. label: {
  24274. color: color$2.primary
  24275. },
  24276. itemStyle: {
  24277. areaColor: color$2.highlight
  24278. }
  24279. },
  24280. select: {
  24281. label: {
  24282. color: color$2.primary
  24283. },
  24284. itemStyle: {
  24285. areaColor: color$2.highlight
  24286. }
  24287. }
  24288. },
  24289. geo: {
  24290. itemStyle: {
  24291. borderColor: color$2.border,
  24292. areaColor: color$2.neutral10
  24293. },
  24294. emphasis: {
  24295. label: {
  24296. color: color$2.primary
  24297. },
  24298. itemStyle: {
  24299. areaColor: color$2.highlight
  24300. }
  24301. },
  24302. select: {
  24303. label: {
  24304. color: color$2.primary
  24305. },
  24306. itemStyle: {
  24307. color: color$2.highlight
  24308. }
  24309. }
  24310. }
  24311. };
  24312. theme.categoryAxis.splitLine.show = false;
  24313. /**
  24314. * Usage of query:
  24315. * `chart.on('click', query, handler);`
  24316. * The `query` can be:
  24317. * + The component type query string, only `mainType` or `mainType.subType`,
  24318. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  24319. * + The component query object, like:
  24320. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  24321. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  24322. * + The data query object, like:
  24323. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  24324. * + The other query object (cmponent customized query), like:
  24325. * `{element: 'some'}` (only available in custom series).
  24326. *
  24327. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  24328. * same as there is no such prop in the `query` object.
  24329. */
  24330. var ECEventProcessor = /** @class */function () {
  24331. function ECEventProcessor() {}
  24332. ECEventProcessor.prototype.normalizeQuery = function (query) {
  24333. var cptQuery = {};
  24334. var dataQuery = {};
  24335. var otherQuery = {};
  24336. // `query` is `mainType` or `mainType.subType` of component.
  24337. if (isString(query)) {
  24338. var condCptType = parseClassType(query);
  24339. // `.main` and `.sub` may be ''.
  24340. cptQuery.mainType = condCptType.main || null;
  24341. cptQuery.subType = condCptType.sub || null;
  24342. }
  24343. // `query` is an object, convert to {mainType, index, name, id}.
  24344. else {
  24345. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  24346. // can not be used in `compomentModel.filterForExposedEvent`.
  24347. var suffixes_1 = ['Index', 'Name', 'Id'];
  24348. var dataKeys_1 = {
  24349. name: 1,
  24350. dataIndex: 1,
  24351. dataType: 1
  24352. };
  24353. each(query, function (val, key) {
  24354. var reserved = false;
  24355. for (var i = 0; i < suffixes_1.length; i++) {
  24356. var propSuffix = suffixes_1[i];
  24357. var suffixPos = key.lastIndexOf(propSuffix);
  24358. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  24359. var mainType = key.slice(0, suffixPos);
  24360. // Consider `dataIndex`.
  24361. if (mainType !== 'data') {
  24362. cptQuery.mainType = mainType;
  24363. cptQuery[propSuffix.toLowerCase()] = val;
  24364. reserved = true;
  24365. }
  24366. }
  24367. }
  24368. if (dataKeys_1.hasOwnProperty(key)) {
  24369. dataQuery[key] = val;
  24370. reserved = true;
  24371. }
  24372. if (!reserved) {
  24373. otherQuery[key] = val;
  24374. }
  24375. });
  24376. }
  24377. return {
  24378. cptQuery: cptQuery,
  24379. dataQuery: dataQuery,
  24380. otherQuery: otherQuery
  24381. };
  24382. };
  24383. ECEventProcessor.prototype.filter = function (eventType, query) {
  24384. // They should be assigned before each trigger call.
  24385. var eventInfo = this.eventInfo;
  24386. if (!eventInfo) {
  24387. return true;
  24388. }
  24389. var targetEl = eventInfo.targetEl;
  24390. var packedEvent = eventInfo.packedEvent;
  24391. var model = eventInfo.model;
  24392. var view = eventInfo.view;
  24393. // For event like 'globalout'.
  24394. if (!model || !view) {
  24395. return true;
  24396. }
  24397. var cptQuery = query.cptQuery;
  24398. var dataQuery = query.dataQuery;
  24399. return check(cptQuery, model, 'mainType') && check(cptQuery, model, 'subType') && check(cptQuery, model, 'index', 'componentIndex') && check(cptQuery, model, 'name') && check(cptQuery, model, 'id') && check(dataQuery, packedEvent, 'name') && check(dataQuery, packedEvent, 'dataIndex') && check(dataQuery, packedEvent, 'dataType') && (!view.filterForExposedEvent || view.filterForExposedEvent(eventType, query.otherQuery, targetEl, packedEvent));
  24400. function check(query, host, prop, propOnHost) {
  24401. return query[prop] == null || host[propOnHost || prop] === query[prop];
  24402. }
  24403. };
  24404. ECEventProcessor.prototype.afterTrigger = function () {
  24405. // Make sure the eventInfo won't be used in next trigger.
  24406. this.eventInfo = null;
  24407. };
  24408. return ECEventProcessor;
  24409. }();
  24410. var SYMBOL_PROPS_WITH_CB = ['symbol', 'symbolSize', 'symbolRotate', 'symbolOffset'];
  24411. var SYMBOL_PROPS = SYMBOL_PROPS_WITH_CB.concat(['symbolKeepAspect']);
  24412. // Encoding visual for all series include which is filtered for legend drawing
  24413. var seriesSymbolTask = {
  24414. createOnAllSeries: true,
  24415. // For legend.
  24416. performRawSeries: true,
  24417. reset: function (seriesModel, ecModel) {
  24418. var data = seriesModel.getData();
  24419. if (seriesModel.legendIcon) {
  24420. data.setVisual('legendIcon', seriesModel.legendIcon);
  24421. }
  24422. if (!seriesModel.hasSymbolVisual) {
  24423. return;
  24424. }
  24425. var symbolOptions = {};
  24426. var symbolOptionsCb = {};
  24427. var hasCallback = false;
  24428. for (var i = 0; i < SYMBOL_PROPS_WITH_CB.length; i++) {
  24429. var symbolPropName = SYMBOL_PROPS_WITH_CB[i];
  24430. var val = seriesModel.get(symbolPropName);
  24431. if (isFunction(val)) {
  24432. hasCallback = true;
  24433. symbolOptionsCb[symbolPropName] = val;
  24434. } else {
  24435. symbolOptions[symbolPropName] = val;
  24436. }
  24437. }
  24438. symbolOptions.symbol = symbolOptions.symbol || seriesModel.defaultSymbol;
  24439. data.setVisual(extend({
  24440. legendIcon: seriesModel.legendIcon || symbolOptions.symbol,
  24441. symbolKeepAspect: seriesModel.get('symbolKeepAspect')
  24442. }, symbolOptions));
  24443. // Only visible series has each data be visual encoded
  24444. if (ecModel.isSeriesFiltered(seriesModel)) {
  24445. return;
  24446. }
  24447. var symbolPropsCb = keys(symbolOptionsCb);
  24448. function dataEach(data, idx) {
  24449. var rawValue = seriesModel.getRawValue(idx);
  24450. var params = seriesModel.getDataParams(idx);
  24451. for (var i = 0; i < symbolPropsCb.length; i++) {
  24452. var symbolPropName = symbolPropsCb[i];
  24453. data.setItemVisual(idx, symbolPropName, symbolOptionsCb[symbolPropName](rawValue, params));
  24454. }
  24455. }
  24456. return {
  24457. dataEach: hasCallback ? dataEach : null
  24458. };
  24459. }
  24460. };
  24461. var dataSymbolTask = {
  24462. createOnAllSeries: true,
  24463. // For legend.
  24464. performRawSeries: true,
  24465. reset: function (seriesModel, ecModel) {
  24466. if (!seriesModel.hasSymbolVisual) {
  24467. return;
  24468. }
  24469. // Only visible series has each data be visual encoded
  24470. if (ecModel.isSeriesFiltered(seriesModel)) {
  24471. return;
  24472. }
  24473. var data = seriesModel.getData();
  24474. function dataEach(data, idx) {
  24475. var itemModel = data.getItemModel(idx);
  24476. for (var i = 0; i < SYMBOL_PROPS.length; i++) {
  24477. var symbolPropName = SYMBOL_PROPS[i];
  24478. var val = itemModel.getShallow(symbolPropName, true);
  24479. if (val != null) {
  24480. data.setItemVisual(idx, symbolPropName, val);
  24481. }
  24482. }
  24483. }
  24484. return {
  24485. dataEach: data.hasItemOption ? dataEach : null
  24486. };
  24487. }
  24488. };
  24489. /*
  24490. * Licensed to the Apache Software Foundation (ASF) under one
  24491. * or more contributor license agreements. See the NOTICE file
  24492. * distributed with this work for additional information
  24493. * regarding copyright ownership. The ASF licenses this file
  24494. * to you under the Apache License, Version 2.0 (the
  24495. * "License"); you may not use this file except in compliance
  24496. * with the License. You may obtain a copy of the License at
  24497. *
  24498. * http://www.apache.org/licenses/LICENSE-2.0
  24499. *
  24500. * Unless required by applicable law or agreed to in writing,
  24501. * software distributed under the License is distributed on an
  24502. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24503. * KIND, either express or implied. See the License for the
  24504. * specific language governing permissions and limitations
  24505. * under the License.
  24506. */
  24507. /**
  24508. * AUTO-GENERATED FILE. DO NOT MODIFY.
  24509. */
  24510. /*
  24511. * Licensed to the Apache Software Foundation (ASF) under one
  24512. * or more contributor license agreements. See the NOTICE file
  24513. * distributed with this work for additional information
  24514. * regarding copyright ownership. The ASF licenses this file
  24515. * to you under the Apache License, Version 2.0 (the
  24516. * "License"); you may not use this file except in compliance
  24517. * with the License. You may obtain a copy of the License at
  24518. *
  24519. * http://www.apache.org/licenses/LICENSE-2.0
  24520. *
  24521. * Unless required by applicable law or agreed to in writing,
  24522. * software distributed under the License is distributed on an
  24523. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24524. * KIND, either express or implied. See the License for the
  24525. * specific language governing permissions and limitations
  24526. * under the License.
  24527. */
  24528. function getItemVisualFromData(data, dataIndex, key) {
  24529. switch (key) {
  24530. case 'color':
  24531. var style = data.getItemVisual(dataIndex, 'style');
  24532. return style[data.getVisual('drawType')];
  24533. case 'opacity':
  24534. return data.getItemVisual(dataIndex, 'style').opacity;
  24535. case 'symbol':
  24536. case 'symbolSize':
  24537. case 'liftZ':
  24538. return data.getItemVisual(dataIndex, key);
  24539. default:
  24540. if ("development" !== 'production') {
  24541. console.warn("Unknown visual type " + key);
  24542. }
  24543. }
  24544. }
  24545. function getVisualFromData(data, key) {
  24546. switch (key) {
  24547. case 'color':
  24548. var style = data.getVisual('style');
  24549. return style[data.getVisual('drawType')];
  24550. case 'opacity':
  24551. return data.getVisual('style').opacity;
  24552. case 'symbol':
  24553. case 'symbolSize':
  24554. case 'liftZ':
  24555. return data.getVisual(key);
  24556. default:
  24557. if ("development" !== 'production') {
  24558. console.warn("Unknown visual type " + key);
  24559. }
  24560. }
  24561. }
  24562. // Legacy data selection action.
  24563. // Includes: pieSelect, pieUnSelect, pieToggleSelect, mapSelect, mapUnSelect, mapToggleSelect
  24564. function createLegacyDataSelectAction(seriesType, ecRegisterAction) {
  24565. function getSeriesIndices(ecModel, payload) {
  24566. var seriesIndices = [];
  24567. ecModel.eachComponent({
  24568. mainType: 'series',
  24569. subType: seriesType,
  24570. query: payload
  24571. }, function (seriesModel) {
  24572. seriesIndices.push(seriesModel.seriesIndex);
  24573. });
  24574. return seriesIndices;
  24575. }
  24576. each([[seriesType + 'ToggleSelect', 'toggleSelect'], [seriesType + 'Select', 'select'], [seriesType + 'UnSelect', 'unselect']], function (eventsMap) {
  24577. ecRegisterAction(eventsMap[0], function (payload, ecModel, api) {
  24578. payload = extend({}, payload);
  24579. if ("development" !== 'production') {
  24580. deprecateReplaceLog(payload.type, eventsMap[1]);
  24581. }
  24582. api.dispatchAction(extend(payload, {
  24583. type: eventsMap[1],
  24584. seriesIndex: getSeriesIndices(ecModel, payload)
  24585. }));
  24586. });
  24587. });
  24588. }
  24589. function handleSeriesLegacySelectEvents(type, eventPostfix, ecIns, ecModel, payload) {
  24590. var legacyEventName = type + eventPostfix;
  24591. if (!ecIns.isSilent(legacyEventName)) {
  24592. if ("development" !== 'production') {
  24593. deprecateLog("event " + legacyEventName + " is deprecated.");
  24594. }
  24595. ecModel.eachComponent({
  24596. mainType: 'series',
  24597. subType: 'pie'
  24598. }, function (seriesModel) {
  24599. var seriesIndex = seriesModel.seriesIndex;
  24600. var selectedMap = seriesModel.option.selectedMap;
  24601. var selected = payload.selected;
  24602. for (var i = 0; i < selected.length; i++) {
  24603. if (selected[i].seriesIndex === seriesIndex) {
  24604. var data = seriesModel.getData();
  24605. var dataIndex = queryDataIndex(data, payload.fromActionPayload);
  24606. ecIns.trigger(legacyEventName, {
  24607. type: legacyEventName,
  24608. seriesId: seriesModel.id,
  24609. name: isArray(dataIndex) ? data.getName(dataIndex[0]) : data.getName(dataIndex),
  24610. selected: isString(selectedMap) ? selectedMap : extend({}, selectedMap)
  24611. });
  24612. }
  24613. }
  24614. });
  24615. }
  24616. }
  24617. function handleLegacySelectEvents(messageCenter, ecIns, api) {
  24618. messageCenter.on('selectchanged', function (params) {
  24619. var ecModel = api.getModel();
  24620. if (params.isFromClick) {
  24621. handleSeriesLegacySelectEvents('map', 'selectchanged', ecIns, ecModel, params);
  24622. handleSeriesLegacySelectEvents('pie', 'selectchanged', ecIns, ecModel, params);
  24623. } else if (params.fromAction === 'select') {
  24624. handleSeriesLegacySelectEvents('map', 'selected', ecIns, ecModel, params);
  24625. handleSeriesLegacySelectEvents('pie', 'selected', ecIns, ecModel, params);
  24626. } else if (params.fromAction === 'unselect') {
  24627. handleSeriesLegacySelectEvents('map', 'unselected', ecIns, ecModel, params);
  24628. handleSeriesLegacySelectEvents('pie', 'unselected', ecIns, ecModel, params);
  24629. }
  24630. });
  24631. }
  24632. /*
  24633. * Licensed to the Apache Software Foundation (ASF) under one
  24634. * or more contributor license agreements. See the NOTICE file
  24635. * distributed with this work for additional information
  24636. * regarding copyright ownership. The ASF licenses this file
  24637. * to you under the Apache License, Version 2.0 (the
  24638. * "License"); you may not use this file except in compliance
  24639. * with the License. You may obtain a copy of the License at
  24640. *
  24641. * http://www.apache.org/licenses/LICENSE-2.0
  24642. *
  24643. * Unless required by applicable law or agreed to in writing,
  24644. * software distributed under the License is distributed on an
  24645. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24646. * KIND, either express or implied. See the License for the
  24647. * specific language governing permissions and limitations
  24648. * under the License.
  24649. */
  24650. /**
  24651. * AUTO-GENERATED FILE. DO NOT MODIFY.
  24652. */
  24653. /*
  24654. * Licensed to the Apache Software Foundation (ASF) under one
  24655. * or more contributor license agreements. See the NOTICE file
  24656. * distributed with this work for additional information
  24657. * regarding copyright ownership. The ASF licenses this file
  24658. * to you under the Apache License, Version 2.0 (the
  24659. * "License"); you may not use this file except in compliance
  24660. * with the License. You may obtain a copy of the License at
  24661. *
  24662. * http://www.apache.org/licenses/LICENSE-2.0
  24663. *
  24664. * Unless required by applicable law or agreed to in writing,
  24665. * software distributed under the License is distributed on an
  24666. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24667. * KIND, either express or implied. See the License for the
  24668. * specific language governing permissions and limitations
  24669. * under the License.
  24670. */
  24671. function findEventDispatcher(target, det, returnFirstMatch) {
  24672. var found;
  24673. while (target) {
  24674. if (det(target)) {
  24675. found = target;
  24676. if (returnFirstMatch) {
  24677. break;
  24678. }
  24679. }
  24680. target = target.__hostTarget || target.parent;
  24681. }
  24682. return found;
  24683. }
  24684. var wmUniqueIndex = Math.round(Math.random() * 9);
  24685. var supportDefineProperty = typeof Object.defineProperty === 'function';
  24686. var WeakMap = (function () {
  24687. function WeakMap() {
  24688. this._id = '__ec_inner_' + wmUniqueIndex++;
  24689. }
  24690. WeakMap.prototype.get = function (key) {
  24691. return this._guard(key)[this._id];
  24692. };
  24693. WeakMap.prototype.set = function (key, value) {
  24694. var target = this._guard(key);
  24695. if (supportDefineProperty) {
  24696. Object.defineProperty(target, this._id, {
  24697. value: value,
  24698. enumerable: false,
  24699. configurable: true
  24700. });
  24701. }
  24702. else {
  24703. target[this._id] = value;
  24704. }
  24705. return this;
  24706. };
  24707. WeakMap.prototype["delete"] = function (key) {
  24708. if (this.has(key)) {
  24709. delete this._guard(key)[this._id];
  24710. return true;
  24711. }
  24712. return false;
  24713. };
  24714. WeakMap.prototype.has = function (key) {
  24715. return !!this._guard(key)[this._id];
  24716. };
  24717. WeakMap.prototype._guard = function (key) {
  24718. if (key !== Object(key)) {
  24719. throw TypeError('Value of WeakMap is not a non-null object.');
  24720. }
  24721. return key;
  24722. };
  24723. return WeakMap;
  24724. }());
  24725. /**
  24726. * Triangle shape
  24727. * @inner
  24728. */
  24729. var Triangle = Path.extend({
  24730. type: 'triangle',
  24731. shape: {
  24732. cx: 0,
  24733. cy: 0,
  24734. width: 0,
  24735. height: 0
  24736. },
  24737. buildPath: function (path, shape) {
  24738. var cx = shape.cx;
  24739. var cy = shape.cy;
  24740. var width = shape.width / 2;
  24741. var height = shape.height / 2;
  24742. path.moveTo(cx, cy - height);
  24743. path.lineTo(cx + width, cy + height);
  24744. path.lineTo(cx - width, cy + height);
  24745. path.closePath();
  24746. }
  24747. });
  24748. /**
  24749. * Diamond shape
  24750. * @inner
  24751. */
  24752. var Diamond = Path.extend({
  24753. type: 'diamond',
  24754. shape: {
  24755. cx: 0,
  24756. cy: 0,
  24757. width: 0,
  24758. height: 0
  24759. },
  24760. buildPath: function (path, shape) {
  24761. var cx = shape.cx;
  24762. var cy = shape.cy;
  24763. var width = shape.width / 2;
  24764. var height = shape.height / 2;
  24765. path.moveTo(cx, cy - height);
  24766. path.lineTo(cx + width, cy);
  24767. path.lineTo(cx, cy + height);
  24768. path.lineTo(cx - width, cy);
  24769. path.closePath();
  24770. }
  24771. });
  24772. /**
  24773. * Pin shape
  24774. * @inner
  24775. */
  24776. var Pin = Path.extend({
  24777. type: 'pin',
  24778. shape: {
  24779. // x, y on the cusp
  24780. x: 0,
  24781. y: 0,
  24782. width: 0,
  24783. height: 0
  24784. },
  24785. buildPath: function (path, shape) {
  24786. var x = shape.x;
  24787. var y = shape.y;
  24788. var w = shape.width / 5 * 3;
  24789. // Height must be larger than width
  24790. var h = Math.max(w, shape.height);
  24791. var r = w / 2;
  24792. // Dist on y with tangent point and circle center
  24793. var dy = r * r / (h - r);
  24794. var cy = y - h + r + dy;
  24795. var angle = Math.asin(dy / r);
  24796. // Dist on x with tangent point and circle center
  24797. var dx = Math.cos(angle) * r;
  24798. var tanX = Math.sin(angle);
  24799. var tanY = Math.cos(angle);
  24800. var cpLen = r * 0.6;
  24801. var cpLen2 = r * 0.7;
  24802. path.moveTo(x - dx, cy + dy);
  24803. path.arc(x, cy, r, Math.PI - angle, Math.PI * 2 + angle);
  24804. path.bezierCurveTo(x + dx - tanX * cpLen, cy + dy + tanY * cpLen, x, y - cpLen2, x, y);
  24805. path.bezierCurveTo(x, y - cpLen2, x - dx + tanX * cpLen, cy + dy + tanY * cpLen, x - dx, cy + dy);
  24806. path.closePath();
  24807. }
  24808. });
  24809. /**
  24810. * Arrow shape
  24811. * @inner
  24812. */
  24813. var Arrow = Path.extend({
  24814. type: 'arrow',
  24815. shape: {
  24816. x: 0,
  24817. y: 0,
  24818. width: 0,
  24819. height: 0
  24820. },
  24821. buildPath: function (ctx, shape) {
  24822. var height = shape.height;
  24823. var width = shape.width;
  24824. var x = shape.x;
  24825. var y = shape.y;
  24826. var dx = width / 3 * 2;
  24827. ctx.moveTo(x, y);
  24828. ctx.lineTo(x + dx, y + height);
  24829. ctx.lineTo(x, y + height / 4 * 3);
  24830. ctx.lineTo(x - dx, y + height);
  24831. ctx.lineTo(x, y);
  24832. ctx.closePath();
  24833. }
  24834. });
  24835. /**
  24836. * Map of path constructors
  24837. */
  24838. // TODO Use function to build symbol path.
  24839. var symbolCtors = {
  24840. line: Line,
  24841. rect: Rect,
  24842. roundRect: Rect,
  24843. square: Rect,
  24844. circle: Circle,
  24845. diamond: Diamond,
  24846. pin: Pin,
  24847. arrow: Arrow,
  24848. triangle: Triangle
  24849. };
  24850. var symbolShapeMakers = {
  24851. line: function (x, y, w, h, shape) {
  24852. shape.x1 = x;
  24853. shape.y1 = y + h / 2;
  24854. shape.x2 = x + w;
  24855. shape.y2 = y + h / 2;
  24856. },
  24857. rect: function (x, y, w, h, shape) {
  24858. shape.x = x;
  24859. shape.y = y;
  24860. shape.width = w;
  24861. shape.height = h;
  24862. },
  24863. roundRect: function (x, y, w, h, shape) {
  24864. shape.x = x;
  24865. shape.y = y;
  24866. shape.width = w;
  24867. shape.height = h;
  24868. shape.r = Math.min(w, h) / 4;
  24869. },
  24870. square: function (x, y, w, h, shape) {
  24871. var size = Math.min(w, h);
  24872. shape.x = x;
  24873. shape.y = y;
  24874. shape.width = size;
  24875. shape.height = size;
  24876. },
  24877. circle: function (x, y, w, h, shape) {
  24878. // Put circle in the center of square
  24879. shape.cx = x + w / 2;
  24880. shape.cy = y + h / 2;
  24881. shape.r = Math.min(w, h) / 2;
  24882. },
  24883. diamond: function (x, y, w, h, shape) {
  24884. shape.cx = x + w / 2;
  24885. shape.cy = y + h / 2;
  24886. shape.width = w;
  24887. shape.height = h;
  24888. },
  24889. pin: function (x, y, w, h, shape) {
  24890. shape.x = x + w / 2;
  24891. shape.y = y + h / 2;
  24892. shape.width = w;
  24893. shape.height = h;
  24894. },
  24895. arrow: function (x, y, w, h, shape) {
  24896. shape.x = x + w / 2;
  24897. shape.y = y + h / 2;
  24898. shape.width = w;
  24899. shape.height = h;
  24900. },
  24901. triangle: function (x, y, w, h, shape) {
  24902. shape.cx = x + w / 2;
  24903. shape.cy = y + h / 2;
  24904. shape.width = w;
  24905. shape.height = h;
  24906. }
  24907. };
  24908. var symbolBuildProxies = {};
  24909. each(symbolCtors, function (Ctor, name) {
  24910. symbolBuildProxies[name] = new Ctor();
  24911. });
  24912. var SymbolClz = Path.extend({
  24913. type: 'symbol',
  24914. shape: {
  24915. symbolType: '',
  24916. x: 0,
  24917. y: 0,
  24918. width: 0,
  24919. height: 0
  24920. },
  24921. calculateTextPosition: function (out, config, rect) {
  24922. var res = calculateTextPosition(out, config, rect);
  24923. var shape = this.shape;
  24924. if (shape && shape.symbolType === 'pin' && config.position === 'inside') {
  24925. res.y = rect.y + rect.height * 0.4;
  24926. }
  24927. return res;
  24928. },
  24929. buildPath: function (ctx, shape, inBundle) {
  24930. var symbolType = shape.symbolType;
  24931. if (symbolType !== 'none') {
  24932. var proxySymbol = symbolBuildProxies[symbolType];
  24933. if (!proxySymbol) {
  24934. // Default rect
  24935. symbolType = 'rect';
  24936. proxySymbol = symbolBuildProxies[symbolType];
  24937. }
  24938. symbolShapeMakers[symbolType](shape.x, shape.y, shape.width, shape.height, proxySymbol.shape);
  24939. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  24940. }
  24941. }
  24942. });
  24943. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  24944. function symbolPathSetColor(color, innerColor) {
  24945. if (this.type !== 'image') {
  24946. var symbolStyle = this.style;
  24947. if (this.__isEmptyBrush) {
  24948. symbolStyle.stroke = color;
  24949. symbolStyle.fill = innerColor || tokens.color.neutral00;
  24950. // TODO Same width with lineStyle in LineView
  24951. symbolStyle.lineWidth = 2;
  24952. } else if (this.shape.symbolType === 'line') {
  24953. symbolStyle.stroke = color;
  24954. } else {
  24955. symbolStyle.fill = color;
  24956. }
  24957. this.markRedraw();
  24958. }
  24959. }
  24960. /**
  24961. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  24962. */
  24963. function createSymbol(symbolType, x, y, w, h, color,
  24964. // whether to keep the ratio of w/h,
  24965. keepAspect) {
  24966. // TODO Support image object, DynamicImage.
  24967. var isEmpty = symbolType.indexOf('empty') === 0;
  24968. if (isEmpty) {
  24969. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  24970. }
  24971. var symbolPath;
  24972. if (symbolType.indexOf('image://') === 0) {
  24973. symbolPath = makeImage(symbolType.slice(8), new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  24974. } else if (symbolType.indexOf('path://') === 0) {
  24975. symbolPath = makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  24976. } else {
  24977. symbolPath = new SymbolClz({
  24978. shape: {
  24979. symbolType: symbolType,
  24980. x: x,
  24981. y: y,
  24982. width: w,
  24983. height: h
  24984. }
  24985. });
  24986. }
  24987. symbolPath.__isEmptyBrush = isEmpty;
  24988. // TODO Should deprecate setColor
  24989. symbolPath.setColor = symbolPathSetColor;
  24990. if (color) {
  24991. symbolPath.setColor(color);
  24992. }
  24993. return symbolPath;
  24994. }
  24995. function normalizeSymbolSize(symbolSize) {
  24996. if (!isArray(symbolSize)) {
  24997. symbolSize = [+symbolSize, +symbolSize];
  24998. }
  24999. return [symbolSize[0] || 0, symbolSize[1] || 0];
  25000. }
  25001. function normalizeSymbolOffset(symbolOffset, symbolSize) {
  25002. if (symbolOffset == null) {
  25003. return;
  25004. }
  25005. if (!isArray(symbolOffset)) {
  25006. symbolOffset = [symbolOffset, symbolOffset];
  25007. }
  25008. return [parsePercent$1(symbolOffset[0], symbolSize[0]) || 0, parsePercent$1(retrieve2(symbolOffset[1], symbolOffset[0]), symbolSize[1]) || 0];
  25009. }
  25010. function isSafeNum(num) {
  25011. return isFinite(num);
  25012. }
  25013. function createLinearGradient(ctx, obj, rect) {
  25014. var x = obj.x == null ? 0 : obj.x;
  25015. var x2 = obj.x2 == null ? 1 : obj.x2;
  25016. var y = obj.y == null ? 0 : obj.y;
  25017. var y2 = obj.y2 == null ? 0 : obj.y2;
  25018. if (!obj.global) {
  25019. x = x * rect.width + rect.x;
  25020. x2 = x2 * rect.width + rect.x;
  25021. y = y * rect.height + rect.y;
  25022. y2 = y2 * rect.height + rect.y;
  25023. }
  25024. x = isSafeNum(x) ? x : 0;
  25025. x2 = isSafeNum(x2) ? x2 : 1;
  25026. y = isSafeNum(y) ? y : 0;
  25027. y2 = isSafeNum(y2) ? y2 : 0;
  25028. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  25029. return canvasGradient;
  25030. }
  25031. function createRadialGradient(ctx, obj, rect) {
  25032. var width = rect.width;
  25033. var height = rect.height;
  25034. var min = Math.min(width, height);
  25035. var x = obj.x == null ? 0.5 : obj.x;
  25036. var y = obj.y == null ? 0.5 : obj.y;
  25037. var r = obj.r == null ? 0.5 : obj.r;
  25038. if (!obj.global) {
  25039. x = x * width + rect.x;
  25040. y = y * height + rect.y;
  25041. r = r * min;
  25042. }
  25043. x = isSafeNum(x) ? x : 0.5;
  25044. y = isSafeNum(y) ? y : 0.5;
  25045. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  25046. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  25047. return canvasGradient;
  25048. }
  25049. function getCanvasGradient(ctx, obj, rect) {
  25050. var canvasGradient = obj.type === 'radial'
  25051. ? createRadialGradient(ctx, obj, rect)
  25052. : createLinearGradient(ctx, obj, rect);
  25053. var colorStops = obj.colorStops;
  25054. for (var i = 0; i < colorStops.length; i++) {
  25055. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  25056. }
  25057. return canvasGradient;
  25058. }
  25059. function isClipPathChanged(clipPaths, prevClipPaths) {
  25060. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  25061. return false;
  25062. }
  25063. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  25064. return true;
  25065. }
  25066. for (var i = 0; i < clipPaths.length; i++) {
  25067. if (clipPaths[i] !== prevClipPaths[i]) {
  25068. return true;
  25069. }
  25070. }
  25071. return false;
  25072. }
  25073. function parseInt10(val) {
  25074. return parseInt(val, 10);
  25075. }
  25076. function getSize(root, whIdx, opts) {
  25077. var wh = ['width', 'height'][whIdx];
  25078. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  25079. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  25080. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  25081. if (opts[wh] != null && opts[wh] !== 'auto') {
  25082. return parseFloat(opts[wh]);
  25083. }
  25084. var stl = document.defaultView.getComputedStyle(root);
  25085. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  25086. - (parseInt10(stl[plt]) || 0)
  25087. - (parseInt10(stl[prb]) || 0)) | 0;
  25088. }
  25089. function normalizeLineDash(lineType, lineWidth) {
  25090. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  25091. return null;
  25092. }
  25093. return lineType === 'dashed'
  25094. ? [4 * lineWidth, 2 * lineWidth]
  25095. : lineType === 'dotted'
  25096. ? [lineWidth]
  25097. : isNumber(lineType)
  25098. ? [lineType] : isArray(lineType) ? lineType : null;
  25099. }
  25100. function getLineDash(el) {
  25101. var style = el.style;
  25102. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  25103. var lineDashOffset = style.lineDashOffset;
  25104. if (lineDash) {
  25105. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  25106. if (lineScale_1 && lineScale_1 !== 1) {
  25107. lineDash = map(lineDash, function (rawVal) {
  25108. return rawVal / lineScale_1;
  25109. });
  25110. lineDashOffset /= lineScale_1;
  25111. }
  25112. }
  25113. return [lineDash, lineDashOffset];
  25114. }
  25115. var pathProxyForDraw = new PathProxy(true);
  25116. function styleHasStroke(style) {
  25117. var stroke = style.stroke;
  25118. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  25119. }
  25120. function isValidStrokeFillStyle(strokeOrFill) {
  25121. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  25122. }
  25123. function styleHasFill(style) {
  25124. var fill = style.fill;
  25125. return fill != null && fill !== 'none';
  25126. }
  25127. function doFillPath(ctx, style) {
  25128. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  25129. var originalGlobalAlpha = ctx.globalAlpha;
  25130. ctx.globalAlpha = style.fillOpacity * style.opacity;
  25131. ctx.fill();
  25132. ctx.globalAlpha = originalGlobalAlpha;
  25133. }
  25134. else {
  25135. ctx.fill();
  25136. }
  25137. }
  25138. function doStrokePath(ctx, style) {
  25139. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  25140. var originalGlobalAlpha = ctx.globalAlpha;
  25141. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  25142. ctx.stroke();
  25143. ctx.globalAlpha = originalGlobalAlpha;
  25144. }
  25145. else {
  25146. ctx.stroke();
  25147. }
  25148. }
  25149. function createCanvasPattern(ctx, pattern, el) {
  25150. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  25151. if (isImageReady(image)) {
  25152. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  25153. if (typeof DOMMatrix === 'function'
  25154. && canvasPattern
  25155. && canvasPattern.setTransform) {
  25156. var matrix = new DOMMatrix();
  25157. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  25158. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  25159. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  25160. canvasPattern.setTransform(matrix);
  25161. }
  25162. return canvasPattern;
  25163. }
  25164. }
  25165. function brushPath(ctx, el, style, inBatch) {
  25166. var _a;
  25167. var hasStroke = styleHasStroke(style);
  25168. var hasFill = styleHasFill(style);
  25169. var strokePercent = style.strokePercent;
  25170. var strokePart = strokePercent < 1;
  25171. var firstDraw = !el.path;
  25172. if ((!el.silent || strokePart) && firstDraw) {
  25173. el.createPathProxy();
  25174. }
  25175. var path = el.path || pathProxyForDraw;
  25176. var dirtyFlag = el.__dirty;
  25177. if (!inBatch) {
  25178. var fill = style.fill;
  25179. var stroke = style.stroke;
  25180. var hasFillGradient = hasFill && !!fill.colorStops;
  25181. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  25182. var hasFillPattern = hasFill && !!fill.image;
  25183. var hasStrokePattern = hasStroke && !!stroke.image;
  25184. var fillGradient = void 0;
  25185. var strokeGradient = void 0;
  25186. var fillPattern = void 0;
  25187. var strokePattern = void 0;
  25188. var rect = void 0;
  25189. if (hasFillGradient || hasStrokeGradient) {
  25190. rect = el.getBoundingRect();
  25191. }
  25192. if (hasFillGradient) {
  25193. fillGradient = dirtyFlag
  25194. ? getCanvasGradient(ctx, fill, rect)
  25195. : el.__canvasFillGradient;
  25196. el.__canvasFillGradient = fillGradient;
  25197. }
  25198. if (hasStrokeGradient) {
  25199. strokeGradient = dirtyFlag
  25200. ? getCanvasGradient(ctx, stroke, rect)
  25201. : el.__canvasStrokeGradient;
  25202. el.__canvasStrokeGradient = strokeGradient;
  25203. }
  25204. if (hasFillPattern) {
  25205. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  25206. ? createCanvasPattern(ctx, fill, el)
  25207. : el.__canvasFillPattern;
  25208. el.__canvasFillPattern = fillPattern;
  25209. }
  25210. if (hasStrokePattern) {
  25211. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  25212. ? createCanvasPattern(ctx, stroke, el)
  25213. : el.__canvasStrokePattern;
  25214. el.__canvasStrokePattern = strokePattern;
  25215. }
  25216. if (hasFillGradient) {
  25217. ctx.fillStyle = fillGradient;
  25218. }
  25219. else if (hasFillPattern) {
  25220. if (fillPattern) {
  25221. ctx.fillStyle = fillPattern;
  25222. }
  25223. else {
  25224. hasFill = false;
  25225. }
  25226. }
  25227. if (hasStrokeGradient) {
  25228. ctx.strokeStyle = strokeGradient;
  25229. }
  25230. else if (hasStrokePattern) {
  25231. if (strokePattern) {
  25232. ctx.strokeStyle = strokePattern;
  25233. }
  25234. else {
  25235. hasStroke = false;
  25236. }
  25237. }
  25238. }
  25239. var scale = el.getGlobalScale();
  25240. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  25241. var lineDash;
  25242. var lineDashOffset;
  25243. if (ctx.setLineDash && style.lineDash) {
  25244. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  25245. }
  25246. var needsRebuild = true;
  25247. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  25248. path.setDPR(ctx.dpr);
  25249. if (strokePart) {
  25250. path.setContext(null);
  25251. }
  25252. else {
  25253. path.setContext(ctx);
  25254. needsRebuild = false;
  25255. }
  25256. path.reset();
  25257. el.buildPath(path, el.shape, inBatch);
  25258. path.toStatic();
  25259. el.pathUpdated();
  25260. }
  25261. if (needsRebuild) {
  25262. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  25263. }
  25264. if (lineDash) {
  25265. ctx.setLineDash(lineDash);
  25266. ctx.lineDashOffset = lineDashOffset;
  25267. }
  25268. if (!inBatch) {
  25269. if (style.strokeFirst) {
  25270. if (hasStroke) {
  25271. doStrokePath(ctx, style);
  25272. }
  25273. if (hasFill) {
  25274. doFillPath(ctx, style);
  25275. }
  25276. }
  25277. else {
  25278. if (hasFill) {
  25279. doFillPath(ctx, style);
  25280. }
  25281. if (hasStroke) {
  25282. doStrokePath(ctx, style);
  25283. }
  25284. }
  25285. }
  25286. if (lineDash) {
  25287. ctx.setLineDash([]);
  25288. }
  25289. }
  25290. function brushImage(ctx, el, style) {
  25291. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  25292. if (!image || !isImageReady(image)) {
  25293. return;
  25294. }
  25295. var x = style.x || 0;
  25296. var y = style.y || 0;
  25297. var width = el.getWidth();
  25298. var height = el.getHeight();
  25299. var aspect = image.width / image.height;
  25300. if (width == null && height != null) {
  25301. width = height * aspect;
  25302. }
  25303. else if (height == null && width != null) {
  25304. height = width / aspect;
  25305. }
  25306. else if (width == null && height == null) {
  25307. width = image.width;
  25308. height = image.height;
  25309. }
  25310. if (style.sWidth && style.sHeight) {
  25311. var sx = style.sx || 0;
  25312. var sy = style.sy || 0;
  25313. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  25314. }
  25315. else if (style.sx && style.sy) {
  25316. var sx = style.sx;
  25317. var sy = style.sy;
  25318. var sWidth = width - sx;
  25319. var sHeight = height - sy;
  25320. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  25321. }
  25322. else {
  25323. ctx.drawImage(image, x, y, width, height);
  25324. }
  25325. }
  25326. function brushText(ctx, el, style) {
  25327. var _a;
  25328. var text = style.text;
  25329. text != null && (text += '');
  25330. if (text) {
  25331. ctx.font = style.font || DEFAULT_FONT;
  25332. ctx.textAlign = style.textAlign;
  25333. ctx.textBaseline = style.textBaseline;
  25334. var lineDash = void 0;
  25335. var lineDashOffset = void 0;
  25336. if (ctx.setLineDash && style.lineDash) {
  25337. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  25338. }
  25339. if (lineDash) {
  25340. ctx.setLineDash(lineDash);
  25341. ctx.lineDashOffset = lineDashOffset;
  25342. }
  25343. if (style.strokeFirst) {
  25344. if (styleHasStroke(style)) {
  25345. ctx.strokeText(text, style.x, style.y);
  25346. }
  25347. if (styleHasFill(style)) {
  25348. ctx.fillText(text, style.x, style.y);
  25349. }
  25350. }
  25351. else {
  25352. if (styleHasFill(style)) {
  25353. ctx.fillText(text, style.x, style.y);
  25354. }
  25355. if (styleHasStroke(style)) {
  25356. ctx.strokeText(text, style.x, style.y);
  25357. }
  25358. }
  25359. if (lineDash) {
  25360. ctx.setLineDash([]);
  25361. }
  25362. }
  25363. }
  25364. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  25365. var STROKE_PROPS = [
  25366. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  25367. ];
  25368. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  25369. var styleChanged = false;
  25370. if (!forceSetAll) {
  25371. prevStyle = prevStyle || {};
  25372. if (style === prevStyle) {
  25373. return false;
  25374. }
  25375. }
  25376. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  25377. flushPathDrawn(ctx, scope);
  25378. styleChanged = true;
  25379. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  25380. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  25381. }
  25382. if (forceSetAll || style.blend !== prevStyle.blend) {
  25383. if (!styleChanged) {
  25384. flushPathDrawn(ctx, scope);
  25385. styleChanged = true;
  25386. }
  25387. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  25388. }
  25389. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  25390. var propName = SHADOW_NUMBER_PROPS[i];
  25391. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  25392. if (!styleChanged) {
  25393. flushPathDrawn(ctx, scope);
  25394. styleChanged = true;
  25395. }
  25396. ctx[propName] = ctx.dpr * (style[propName] || 0);
  25397. }
  25398. }
  25399. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  25400. if (!styleChanged) {
  25401. flushPathDrawn(ctx, scope);
  25402. styleChanged = true;
  25403. }
  25404. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  25405. }
  25406. return styleChanged;
  25407. }
  25408. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  25409. var style = getStyle(el, scope.inHover);
  25410. var prevStyle = forceSetAll
  25411. ? null
  25412. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  25413. if (style === prevStyle) {
  25414. return false;
  25415. }
  25416. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  25417. if (forceSetAll || style.fill !== prevStyle.fill) {
  25418. if (!styleChanged) {
  25419. flushPathDrawn(ctx, scope);
  25420. styleChanged = true;
  25421. }
  25422. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  25423. }
  25424. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  25425. if (!styleChanged) {
  25426. flushPathDrawn(ctx, scope);
  25427. styleChanged = true;
  25428. }
  25429. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  25430. }
  25431. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  25432. if (!styleChanged) {
  25433. flushPathDrawn(ctx, scope);
  25434. styleChanged = true;
  25435. }
  25436. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  25437. }
  25438. if (el.hasStroke()) {
  25439. var lineWidth = style.lineWidth;
  25440. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  25441. if (ctx.lineWidth !== newLineWidth) {
  25442. if (!styleChanged) {
  25443. flushPathDrawn(ctx, scope);
  25444. styleChanged = true;
  25445. }
  25446. ctx.lineWidth = newLineWidth;
  25447. }
  25448. }
  25449. for (var i = 0; i < STROKE_PROPS.length; i++) {
  25450. var prop = STROKE_PROPS[i];
  25451. var propName = prop[0];
  25452. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  25453. if (!styleChanged) {
  25454. flushPathDrawn(ctx, scope);
  25455. styleChanged = true;
  25456. }
  25457. ctx[propName] = style[propName] || prop[1];
  25458. }
  25459. }
  25460. return styleChanged;
  25461. }
  25462. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  25463. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  25464. }
  25465. function setContextTransform(ctx, el) {
  25466. var m = el.transform;
  25467. var dpr = ctx.dpr || 1;
  25468. if (m) {
  25469. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  25470. }
  25471. else {
  25472. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  25473. }
  25474. }
  25475. function updateClipStatus(clipPaths, ctx, scope) {
  25476. var allClipped = false;
  25477. for (var i = 0; i < clipPaths.length; i++) {
  25478. var clipPath = clipPaths[i];
  25479. allClipped = allClipped || clipPath.isZeroArea();
  25480. setContextTransform(ctx, clipPath);
  25481. ctx.beginPath();
  25482. clipPath.buildPath(ctx, clipPath.shape);
  25483. ctx.clip();
  25484. }
  25485. scope.allClipped = allClipped;
  25486. }
  25487. function isTransformChanged(m0, m1) {
  25488. if (m0 && m1) {
  25489. return m0[0] !== m1[0]
  25490. || m0[1] !== m1[1]
  25491. || m0[2] !== m1[2]
  25492. || m0[3] !== m1[3]
  25493. || m0[4] !== m1[4]
  25494. || m0[5] !== m1[5];
  25495. }
  25496. else if (!m0 && !m1) {
  25497. return false;
  25498. }
  25499. return true;
  25500. }
  25501. var DRAW_TYPE_PATH = 1;
  25502. var DRAW_TYPE_IMAGE = 2;
  25503. var DRAW_TYPE_TEXT = 3;
  25504. var DRAW_TYPE_INCREMENTAL = 4;
  25505. function canPathBatch(style) {
  25506. var hasFill = styleHasFill(style);
  25507. var hasStroke = styleHasStroke(style);
  25508. return !(style.lineDash
  25509. || !(+hasFill ^ +hasStroke)
  25510. || (hasFill && typeof style.fill !== 'string')
  25511. || (hasStroke && typeof style.stroke !== 'string')
  25512. || style.strokePercent < 1
  25513. || style.strokeOpacity < 1
  25514. || style.fillOpacity < 1);
  25515. }
  25516. function flushPathDrawn(ctx, scope) {
  25517. scope.batchFill && ctx.fill();
  25518. scope.batchStroke && ctx.stroke();
  25519. scope.batchFill = '';
  25520. scope.batchStroke = '';
  25521. }
  25522. function getStyle(el, inHover) {
  25523. return inHover ? (el.__hoverStyle || el.style) : el.style;
  25524. }
  25525. function brushSingle(ctx, el) {
  25526. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  25527. }
  25528. function brush(ctx, el, scope, isLast) {
  25529. var m = el.transform;
  25530. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  25531. el.__dirty &= ~REDRAW_BIT;
  25532. el.__isRendered = false;
  25533. return;
  25534. }
  25535. var clipPaths = el.__clipPaths;
  25536. var prevElClipPaths = scope.prevElClipPaths;
  25537. var forceSetTransform = false;
  25538. var forceSetStyle = false;
  25539. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  25540. if (prevElClipPaths && prevElClipPaths.length) {
  25541. flushPathDrawn(ctx, scope);
  25542. ctx.restore();
  25543. forceSetStyle = forceSetTransform = true;
  25544. scope.prevElClipPaths = null;
  25545. scope.allClipped = false;
  25546. scope.prevEl = null;
  25547. }
  25548. if (clipPaths && clipPaths.length) {
  25549. flushPathDrawn(ctx, scope);
  25550. ctx.save();
  25551. updateClipStatus(clipPaths, ctx, scope);
  25552. forceSetTransform = true;
  25553. }
  25554. scope.prevElClipPaths = clipPaths;
  25555. }
  25556. if (scope.allClipped) {
  25557. el.__isRendered = false;
  25558. return;
  25559. }
  25560. el.beforeBrush && el.beforeBrush();
  25561. el.innerBeforeBrush();
  25562. var prevEl = scope.prevEl;
  25563. if (!prevEl) {
  25564. forceSetStyle = forceSetTransform = true;
  25565. }
  25566. var canBatchPath = el instanceof Path
  25567. && el.autoBatch
  25568. && canPathBatch(el.style);
  25569. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  25570. flushPathDrawn(ctx, scope);
  25571. setContextTransform(ctx, el);
  25572. }
  25573. else if (!canBatchPath) {
  25574. flushPathDrawn(ctx, scope);
  25575. }
  25576. var style = getStyle(el, scope.inHover);
  25577. if (el instanceof Path) {
  25578. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  25579. forceSetStyle = true;
  25580. scope.lastDrawType = DRAW_TYPE_PATH;
  25581. }
  25582. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  25583. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  25584. ctx.beginPath();
  25585. }
  25586. brushPath(ctx, el, style, canBatchPath);
  25587. if (canBatchPath) {
  25588. scope.batchFill = style.fill || '';
  25589. scope.batchStroke = style.stroke || '';
  25590. }
  25591. }
  25592. else {
  25593. if (el instanceof TSpan) {
  25594. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  25595. forceSetStyle = true;
  25596. scope.lastDrawType = DRAW_TYPE_TEXT;
  25597. }
  25598. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  25599. brushText(ctx, el, style);
  25600. }
  25601. else if (el instanceof ZRImage) {
  25602. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  25603. forceSetStyle = true;
  25604. scope.lastDrawType = DRAW_TYPE_IMAGE;
  25605. }
  25606. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  25607. brushImage(ctx, el, style);
  25608. }
  25609. else if (el.getTemporalDisplayables) {
  25610. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  25611. forceSetStyle = true;
  25612. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  25613. }
  25614. brushIncremental(ctx, el, scope);
  25615. }
  25616. }
  25617. if (canBatchPath && isLast) {
  25618. flushPathDrawn(ctx, scope);
  25619. }
  25620. el.innerAfterBrush();
  25621. el.afterBrush && el.afterBrush();
  25622. scope.prevEl = el;
  25623. el.__dirty = 0;
  25624. el.__isRendered = true;
  25625. }
  25626. function brushIncremental(ctx, el, scope) {
  25627. var displayables = el.getDisplayables();
  25628. var temporalDisplayables = el.getTemporalDisplayables();
  25629. ctx.save();
  25630. var innerScope = {
  25631. prevElClipPaths: null,
  25632. prevEl: null,
  25633. allClipped: false,
  25634. viewWidth: scope.viewWidth,
  25635. viewHeight: scope.viewHeight,
  25636. inHover: scope.inHover
  25637. };
  25638. var i;
  25639. var len;
  25640. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  25641. var displayable = displayables[i];
  25642. displayable.beforeBrush && displayable.beforeBrush();
  25643. displayable.innerBeforeBrush();
  25644. brush(ctx, displayable, innerScope, i === len - 1);
  25645. displayable.innerAfterBrush();
  25646. displayable.afterBrush && displayable.afterBrush();
  25647. innerScope.prevEl = displayable;
  25648. }
  25649. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  25650. var displayable = temporalDisplayables[i_1];
  25651. displayable.beforeBrush && displayable.beforeBrush();
  25652. displayable.innerBeforeBrush();
  25653. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  25654. displayable.innerAfterBrush();
  25655. displayable.afterBrush && displayable.afterBrush();
  25656. innerScope.prevEl = displayable;
  25657. }
  25658. el.clearTemporalDisplayables();
  25659. el.notClear = true;
  25660. ctx.restore();
  25661. }
  25662. var decalMap = new WeakMap();
  25663. var decalCache = new LRU(100);
  25664. var decalKeys = ['symbol', 'symbolSize', 'symbolKeepAspect', 'color', 'backgroundColor', 'dashArrayX', 'dashArrayY', 'maxTileWidth', 'maxTileHeight'];
  25665. /**
  25666. * Create or update pattern image from decal options
  25667. *
  25668. * @param {InnerDecalObject | 'none'} decalObject decal options, 'none' if no decal
  25669. * @return {Pattern} pattern with generated image, null if no decal
  25670. */
  25671. function createOrUpdatePatternFromDecal(decalObject, api) {
  25672. if (decalObject === 'none') {
  25673. return null;
  25674. }
  25675. var dpr = api.getDevicePixelRatio();
  25676. var zr = api.getZr();
  25677. var isSVG = zr.painter.type === 'svg';
  25678. if (decalObject.dirty) {
  25679. decalMap["delete"](decalObject);
  25680. }
  25681. var oldPattern = decalMap.get(decalObject);
  25682. if (oldPattern) {
  25683. return oldPattern;
  25684. }
  25685. var decalOpt = defaults(decalObject, {
  25686. symbol: 'rect',
  25687. symbolSize: 1,
  25688. symbolKeepAspect: true,
  25689. color: 'rgba(0, 0, 0, 0.2)',
  25690. backgroundColor: null,
  25691. dashArrayX: 5,
  25692. dashArrayY: 5,
  25693. rotation: 0,
  25694. maxTileWidth: 512,
  25695. maxTileHeight: 512
  25696. });
  25697. if (decalOpt.backgroundColor === 'none') {
  25698. decalOpt.backgroundColor = null;
  25699. }
  25700. var pattern = {
  25701. repeat: 'repeat'
  25702. };
  25703. setPatternnSource(pattern);
  25704. pattern.rotation = decalOpt.rotation;
  25705. pattern.scaleX = pattern.scaleY = isSVG ? 1 : 1 / dpr;
  25706. decalMap.set(decalObject, pattern);
  25707. decalObject.dirty = false;
  25708. return pattern;
  25709. function setPatternnSource(pattern) {
  25710. var keys = [dpr];
  25711. var isValidKey = true;
  25712. for (var i = 0; i < decalKeys.length; ++i) {
  25713. var value = decalOpt[decalKeys[i]];
  25714. if (value != null && !isArray(value) && !isString(value) && !isNumber(value) && typeof value !== 'boolean') {
  25715. isValidKey = false;
  25716. break;
  25717. }
  25718. keys.push(value);
  25719. }
  25720. var cacheKey;
  25721. if (isValidKey) {
  25722. cacheKey = keys.join(',') + (isSVG ? '-svg' : '');
  25723. var cache = decalCache.get(cacheKey);
  25724. if (cache) {
  25725. isSVG ? pattern.svgElement = cache : pattern.image = cache;
  25726. }
  25727. }
  25728. var dashArrayX = normalizeDashArrayX(decalOpt.dashArrayX);
  25729. var dashArrayY = normalizeDashArrayY(decalOpt.dashArrayY);
  25730. var symbolArray = normalizeSymbolArray(decalOpt.symbol);
  25731. var lineBlockLengthsX = getLineBlockLengthX(dashArrayX);
  25732. var lineBlockLengthY = getLineBlockLengthY(dashArrayY);
  25733. var canvas = !isSVG && platformApi.createCanvas();
  25734. var svgRoot = isSVG && {
  25735. tag: 'g',
  25736. attrs: {},
  25737. key: 'dcl',
  25738. children: []
  25739. };
  25740. var pSize = getPatternSize();
  25741. var ctx;
  25742. if (canvas) {
  25743. canvas.width = pSize.width * dpr;
  25744. canvas.height = pSize.height * dpr;
  25745. ctx = canvas.getContext('2d');
  25746. }
  25747. brushDecal();
  25748. if (isValidKey) {
  25749. decalCache.put(cacheKey, canvas || svgRoot);
  25750. }
  25751. pattern.image = canvas;
  25752. pattern.svgElement = svgRoot;
  25753. pattern.svgWidth = pSize.width;
  25754. pattern.svgHeight = pSize.height;
  25755. /**
  25756. * Get minimum length that can make a repeatable pattern.
  25757. *
  25758. * @return {Object} pattern width and height
  25759. */
  25760. function getPatternSize() {
  25761. /**
  25762. * For example, if dash is [[3, 2], [2, 1]] for X, it looks like
  25763. * |--- --- --- --- --- ...
  25764. * |-- -- -- -- -- -- -- -- ...
  25765. * |--- --- --- --- --- ...
  25766. * |-- -- -- -- -- -- -- -- ...
  25767. * So the minimum length of X is 15,
  25768. * which is the least common multiple of `3 + 2` and `2 + 1`
  25769. * |--- --- --- |--- --- ...
  25770. * |-- -- -- -- -- |-- -- -- ...
  25771. */
  25772. var width = 1;
  25773. for (var i = 0, xlen = lineBlockLengthsX.length; i < xlen; ++i) {
  25774. width = getLeastCommonMultiple(width, lineBlockLengthsX[i]);
  25775. }
  25776. var symbolRepeats = 1;
  25777. for (var i = 0, xlen = symbolArray.length; i < xlen; ++i) {
  25778. symbolRepeats = getLeastCommonMultiple(symbolRepeats, symbolArray[i].length);
  25779. }
  25780. width *= symbolRepeats;
  25781. var height = lineBlockLengthY * lineBlockLengthsX.length * symbolArray.length;
  25782. if ("development" !== 'production') {
  25783. var warn = function (attrName) {
  25784. /* eslint-disable-next-line */
  25785. console.warn("Calculated decal size is greater than " + attrName + " due to decal option settings so " + attrName + " is used for the decal size. Please consider changing the decal option to make a smaller decal or set " + attrName + " to be larger to avoid incontinuity.");
  25786. };
  25787. if (width > decalOpt.maxTileWidth) {
  25788. warn('maxTileWidth');
  25789. }
  25790. if (height > decalOpt.maxTileHeight) {
  25791. warn('maxTileHeight');
  25792. }
  25793. }
  25794. return {
  25795. width: Math.max(1, Math.min(width, decalOpt.maxTileWidth)),
  25796. height: Math.max(1, Math.min(height, decalOpt.maxTileHeight))
  25797. };
  25798. }
  25799. function brushDecal() {
  25800. if (ctx) {
  25801. ctx.clearRect(0, 0, canvas.width, canvas.height);
  25802. if (decalOpt.backgroundColor) {
  25803. ctx.fillStyle = decalOpt.backgroundColor;
  25804. ctx.fillRect(0, 0, canvas.width, canvas.height);
  25805. }
  25806. }
  25807. var ySum = 0;
  25808. for (var i = 0; i < dashArrayY.length; ++i) {
  25809. ySum += dashArrayY[i];
  25810. }
  25811. if (ySum <= 0) {
  25812. // dashArrayY is 0, draw nothing
  25813. return;
  25814. }
  25815. var y = -lineBlockLengthY;
  25816. var yId = 0;
  25817. var yIdTotal = 0;
  25818. var xId0 = 0;
  25819. while (y < pSize.height) {
  25820. if (yId % 2 === 0) {
  25821. var symbolYId = yIdTotal / 2 % symbolArray.length;
  25822. var x = 0;
  25823. var xId1 = 0;
  25824. var xId1Total = 0;
  25825. while (x < pSize.width * 2) {
  25826. var xSum = 0;
  25827. for (var i = 0; i < dashArrayX[xId0].length; ++i) {
  25828. xSum += dashArrayX[xId0][i];
  25829. }
  25830. if (xSum <= 0) {
  25831. // Skip empty line
  25832. break;
  25833. }
  25834. // E.g., [15, 5, 20, 5] draws only for 15 and 20
  25835. if (xId1 % 2 === 0) {
  25836. var size = (1 - decalOpt.symbolSize) * 0.5;
  25837. var left = x + dashArrayX[xId0][xId1] * size;
  25838. var top_1 = y + dashArrayY[yId] * size;
  25839. var width = dashArrayX[xId0][xId1] * decalOpt.symbolSize;
  25840. var height = dashArrayY[yId] * decalOpt.symbolSize;
  25841. var symbolXId = xId1Total / 2 % symbolArray[symbolYId].length;
  25842. brushSymbol(left, top_1, width, height, symbolArray[symbolYId][symbolXId]);
  25843. }
  25844. x += dashArrayX[xId0][xId1];
  25845. ++xId1Total;
  25846. ++xId1;
  25847. if (xId1 === dashArrayX[xId0].length) {
  25848. xId1 = 0;
  25849. }
  25850. }
  25851. ++xId0;
  25852. if (xId0 === dashArrayX.length) {
  25853. xId0 = 0;
  25854. }
  25855. }
  25856. y += dashArrayY[yId];
  25857. ++yIdTotal;
  25858. ++yId;
  25859. if (yId === dashArrayY.length) {
  25860. yId = 0;
  25861. }
  25862. }
  25863. function brushSymbol(x, y, width, height, symbolType) {
  25864. var scale = isSVG ? 1 : dpr;
  25865. var symbol = createSymbol(symbolType, x * scale, y * scale, width * scale, height * scale, decalOpt.color, decalOpt.symbolKeepAspect);
  25866. if (isSVG) {
  25867. var symbolVNode = zr.painter.renderOneToVNode(symbol);
  25868. if (symbolVNode) {
  25869. svgRoot.children.push(symbolVNode);
  25870. }
  25871. } else {
  25872. // Paint to canvas for all other renderers.
  25873. brushSingle(ctx, symbol);
  25874. }
  25875. }
  25876. }
  25877. }
  25878. }
  25879. /**
  25880. * Convert symbol array into normalized array
  25881. *
  25882. * @param {string | (string | string[])[]} symbol symbol input
  25883. * @return {string[][]} normolized symbol array
  25884. */
  25885. function normalizeSymbolArray(symbol) {
  25886. if (!symbol || symbol.length === 0) {
  25887. return [['rect']];
  25888. }
  25889. if (isString(symbol)) {
  25890. return [[symbol]];
  25891. }
  25892. var isAllString = true;
  25893. for (var i = 0; i < symbol.length; ++i) {
  25894. if (!isString(symbol[i])) {
  25895. isAllString = false;
  25896. break;
  25897. }
  25898. }
  25899. if (isAllString) {
  25900. return normalizeSymbolArray([symbol]);
  25901. }
  25902. var result = [];
  25903. for (var i = 0; i < symbol.length; ++i) {
  25904. if (isString(symbol[i])) {
  25905. result.push([symbol[i]]);
  25906. } else {
  25907. result.push(symbol[i]);
  25908. }
  25909. }
  25910. return result;
  25911. }
  25912. /**
  25913. * Convert dash input into dashArray
  25914. *
  25915. * @param {DecalDashArrayX} dash dash input
  25916. * @return {number[][]} normolized dash array
  25917. */
  25918. function normalizeDashArrayX(dash) {
  25919. if (!dash || dash.length === 0) {
  25920. return [[0, 0]];
  25921. }
  25922. if (isNumber(dash)) {
  25923. var dashValue = Math.ceil(dash);
  25924. return [[dashValue, dashValue]];
  25925. }
  25926. /**
  25927. * [20, 5] should be normalized into [[20, 5]],
  25928. * while [20, [5, 10]] should be normalized into [[20, 20], [5, 10]]
  25929. */
  25930. var isAllNumber = true;
  25931. for (var i = 0; i < dash.length; ++i) {
  25932. if (!isNumber(dash[i])) {
  25933. isAllNumber = false;
  25934. break;
  25935. }
  25936. }
  25937. if (isAllNumber) {
  25938. return normalizeDashArrayX([dash]);
  25939. }
  25940. var result = [];
  25941. for (var i = 0; i < dash.length; ++i) {
  25942. if (isNumber(dash[i])) {
  25943. var dashValue = Math.ceil(dash[i]);
  25944. result.push([dashValue, dashValue]);
  25945. } else {
  25946. var dashValue = map(dash[i], function (n) {
  25947. return Math.ceil(n);
  25948. });
  25949. if (dashValue.length % 2 === 1) {
  25950. // [4, 2, 1] means |---- - -- |---- - -- |
  25951. // so normalize it to be [4, 2, 1, 4, 2, 1]
  25952. result.push(dashValue.concat(dashValue));
  25953. } else {
  25954. result.push(dashValue);
  25955. }
  25956. }
  25957. }
  25958. return result;
  25959. }
  25960. /**
  25961. * Convert dash input into dashArray
  25962. *
  25963. * @param {DecalDashArrayY} dash dash input
  25964. * @return {number[]} normolized dash array
  25965. */
  25966. function normalizeDashArrayY(dash) {
  25967. if (!dash || typeof dash === 'object' && dash.length === 0) {
  25968. return [0, 0];
  25969. }
  25970. if (isNumber(dash)) {
  25971. var dashValue_1 = Math.ceil(dash);
  25972. return [dashValue_1, dashValue_1];
  25973. }
  25974. var dashValue = map(dash, function (n) {
  25975. return Math.ceil(n);
  25976. });
  25977. return dash.length % 2 ? dashValue.concat(dashValue) : dashValue;
  25978. }
  25979. /**
  25980. * Get block length of each line. A block is the length of dash line and space.
  25981. * For example, a line with [4, 1] has a dash line of 4 and a space of 1 after
  25982. * that, so the block length of this line is 5.
  25983. *
  25984. * @param {number[][]} dash dash array of X or Y
  25985. * @return {number[]} block length of each line
  25986. */
  25987. function getLineBlockLengthX(dash) {
  25988. return map(dash, function (line) {
  25989. return getLineBlockLengthY(line);
  25990. });
  25991. }
  25992. function getLineBlockLengthY(dash) {
  25993. var blockLength = 0;
  25994. for (var i = 0; i < dash.length; ++i) {
  25995. blockLength += dash[i];
  25996. }
  25997. if (dash.length % 2 === 1) {
  25998. // [4, 2, 1] means |---- - -- |---- - -- |
  25999. // So total length is (4 + 2 + 1) * 2
  26000. return blockLength * 2;
  26001. }
  26002. return blockLength;
  26003. }
  26004. function decalVisual(ecModel, api) {
  26005. ecModel.eachRawSeries(function (seriesModel) {
  26006. if (ecModel.isSeriesFiltered(seriesModel)) {
  26007. return;
  26008. }
  26009. var data = seriesModel.getData();
  26010. if (data.hasItemVisual()) {
  26011. data.each(function (idx) {
  26012. var decal = data.getItemVisual(idx, 'decal');
  26013. if (decal) {
  26014. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  26015. itemStyle.decal = createOrUpdatePatternFromDecal(decal, api);
  26016. }
  26017. });
  26018. }
  26019. var decal = data.getVisual('decal');
  26020. if (decal) {
  26021. var style = data.getVisual('style');
  26022. style.decal = createOrUpdatePatternFromDecal(decal, api);
  26023. }
  26024. });
  26025. }
  26026. var lifecycle = new Eventful();
  26027. // Implementation of exported APIs. For example registerMap, getMap.
  26028. // The implementations will be registered when installing the component.
  26029. // Avoid these code being bundled to the core module.
  26030. var implsStore = {};
  26031. // TODO Type
  26032. function registerImpl(name, impl) {
  26033. if ("development" !== 'production') {
  26034. if (implsStore[name]) {
  26035. error("Already has an implementation of " + name + ".");
  26036. }
  26037. }
  26038. implsStore[name] = impl;
  26039. }
  26040. function getImpl(name) {
  26041. if ("development" !== 'production') {
  26042. if (!implsStore[name]) {
  26043. error("Implementation of " + name + " doesn't exists.");
  26044. }
  26045. }
  26046. return implsStore[name];
  26047. }
  26048. var version$1 = '6.0.0';
  26049. var dependencies = {
  26050. zrender: '6.0.0'
  26051. };
  26052. var TEST_FRAME_REMAIN_TIME = 1;
  26053. var PRIORITY_PROCESSOR_SERIES_FILTER = 800;
  26054. // Some data processors depends on the stack result dimension (to calculate data extent).
  26055. // So data stack stage should be in front of data processing stage.
  26056. var PRIORITY_PROCESSOR_DATASTACK = 900;
  26057. // "Data filter" will block the stream, so it should be
  26058. // put at the beginning of data processing.
  26059. var PRIORITY_PROCESSOR_FILTER = 1000;
  26060. var PRIORITY_PROCESSOR_DEFAULT = 2000;
  26061. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  26062. var PRIORITY_VISUAL_LAYOUT = 1000;
  26063. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  26064. var PRIORITY_VISUAL_GLOBAL = 2000;
  26065. var PRIORITY_VISUAL_CHART = 3000;
  26066. var PRIORITY_VISUAL_COMPONENT = 4000;
  26067. // Visual property in data. Greater than `PRIORITY_VISUAL_COMPONENT` to enable to
  26068. // overwrite the viusal result of component (like `visualMap`)
  26069. // using data item specific setting (like itemStyle.xxx on data item)
  26070. var PRIORITY_VISUAL_CHART_DATA_CUSTOM = 4500;
  26071. // Greater than `PRIORITY_VISUAL_CHART_DATA_CUSTOM` to enable to layout based on
  26072. // visual result like `symbolSize`.
  26073. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 4600;
  26074. var PRIORITY_VISUAL_BRUSH = 5000;
  26075. var PRIORITY_VISUAL_ARIA = 6000;
  26076. var PRIORITY_VISUAL_DECAL = 7000;
  26077. var PRIORITY = {
  26078. PROCESSOR: {
  26079. FILTER: PRIORITY_PROCESSOR_FILTER,
  26080. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  26081. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  26082. },
  26083. VISUAL: {
  26084. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  26085. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  26086. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  26087. CHART: PRIORITY_VISUAL_CHART,
  26088. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  26089. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  26090. BRUSH: PRIORITY_VISUAL_BRUSH,
  26091. CHART_ITEM: PRIORITY_VISUAL_CHART_DATA_CUSTOM,
  26092. ARIA: PRIORITY_VISUAL_ARIA,
  26093. DECAL: PRIORITY_VISUAL_DECAL
  26094. }
  26095. };
  26096. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  26097. // where they must not be invoked nestedly, except the only case: invoke
  26098. // dispatchAction with updateMethod "none" in main process.
  26099. // This flag is used to carry out this rule.
  26100. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  26101. var IN_MAIN_PROCESS_KEY = '__flagInMainProcess';
  26102. // Useful for detecting outdated rendering results in scenarios that these issues are involved:
  26103. // - Use shortcut (such as, updateTransform, or no update) to start a main process.
  26104. // - Asynchronously update rendered view (e.g., graph force layout).
  26105. // - Multiple ChartView/ComponentView render to one group cooperatively.
  26106. var MAIN_PROCESS_VERSION_KEY = '__mainProcessVersion';
  26107. var PENDING_UPDATE = '__pendingUpdate';
  26108. var STATUS_NEEDS_UPDATE_KEY = '__needsUpdateStatus';
  26109. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  26110. var CONNECT_STATUS_KEY = '__connectUpdateStatus';
  26111. var CONNECT_STATUS_PENDING = 0;
  26112. var CONNECT_STATUS_UPDATING = 1;
  26113. var CONNECT_STATUS_UPDATED = 2;
  26114. function createRegisterEventWithLowercaseECharts(method) {
  26115. return function () {
  26116. var args = [];
  26117. for (var _i = 0; _i < arguments.length; _i++) {
  26118. args[_i] = arguments[_i];
  26119. }
  26120. if (this.isDisposed()) {
  26121. disposedWarning(this.id);
  26122. return;
  26123. }
  26124. return toLowercaseNameAndCallEventful(this, method, args);
  26125. };
  26126. }
  26127. function createRegisterEventWithLowercaseMessageCenter(method) {
  26128. return function () {
  26129. var args = [];
  26130. for (var _i = 0; _i < arguments.length; _i++) {
  26131. args[_i] = arguments[_i];
  26132. }
  26133. return toLowercaseNameAndCallEventful(this, method, args);
  26134. };
  26135. }
  26136. function toLowercaseNameAndCallEventful(host, method, args) {
  26137. // `args[0]` is event name. Event name is all lowercase.
  26138. args[0] = args[0] && args[0].toLowerCase();
  26139. return Eventful.prototype[method].apply(host, args);
  26140. }
  26141. var MessageCenter = /** @class */function (_super) {
  26142. __extends(MessageCenter, _super);
  26143. function MessageCenter() {
  26144. return _super !== null && _super.apply(this, arguments) || this;
  26145. }
  26146. return MessageCenter;
  26147. }(Eventful);
  26148. var messageCenterProto = MessageCenter.prototype;
  26149. messageCenterProto.on = createRegisterEventWithLowercaseMessageCenter('on');
  26150. messageCenterProto.off = createRegisterEventWithLowercaseMessageCenter('off');
  26151. // ---------------------------------------
  26152. // Internal method names for class ECharts
  26153. // ---------------------------------------
  26154. var prepare;
  26155. var prepareView;
  26156. var updateDirectly;
  26157. var updateMethods;
  26158. var doConvertPixel;
  26159. var updateStreamModes;
  26160. var doDispatchAction;
  26161. var flushPendingActions;
  26162. var triggerUpdatedEvent;
  26163. var bindRenderedEvent;
  26164. var bindMouseEvent;
  26165. var render;
  26166. var renderComponents;
  26167. var renderSeries;
  26168. var createExtensionAPI;
  26169. var enableConnect;
  26170. var markStatusToUpdate;
  26171. var applyChangedStates;
  26172. var updateMainProcessVersion;
  26173. var ECharts = /** @class */function (_super) {
  26174. __extends(ECharts, _super);
  26175. function ECharts(dom,
  26176. // Theme name or themeOption.
  26177. theme, opts) {
  26178. var _this = _super.call(this, new ECEventProcessor()) || this;
  26179. _this._chartsViews = [];
  26180. _this._chartsMap = {};
  26181. _this._componentsViews = [];
  26182. _this._componentsMap = {};
  26183. // Can't dispatch action during rendering procedure
  26184. _this._pendingActions = [];
  26185. opts = opts || {};
  26186. _this._dom = dom;
  26187. var defaultRenderer = 'canvas';
  26188. var defaultCoarsePointer = 'auto';
  26189. var defaultUseDirtyRect = false;
  26190. _this[MAIN_PROCESS_VERSION_KEY] = 1;
  26191. if ("development" !== 'production') {
  26192. var root = /* eslint-disable-next-line */
  26193. env.hasGlobalWindow ? window : global;
  26194. if (root) {
  26195. defaultRenderer = retrieve2(root.__ECHARTS__DEFAULT__RENDERER__, defaultRenderer);
  26196. defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer);
  26197. defaultUseDirtyRect = retrieve2(root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__, defaultUseDirtyRect);
  26198. }
  26199. }
  26200. if (opts.ssr) {
  26201. registerSSRDataGetter(function (el) {
  26202. var ecData = getECData(el);
  26203. var dataIndex = ecData.dataIndex;
  26204. if (dataIndex == null) {
  26205. return;
  26206. }
  26207. var hashMap = createHashMap();
  26208. hashMap.set('series_index', ecData.seriesIndex);
  26209. hashMap.set('data_index', dataIndex);
  26210. ecData.ssrType && hashMap.set('ssr_type', ecData.ssrType);
  26211. return hashMap;
  26212. });
  26213. }
  26214. var zr = _this._zr = init(dom, {
  26215. renderer: opts.renderer || defaultRenderer,
  26216. devicePixelRatio: opts.devicePixelRatio,
  26217. width: opts.width,
  26218. height: opts.height,
  26219. ssr: opts.ssr,
  26220. useDirtyRect: retrieve2(opts.useDirtyRect, defaultUseDirtyRect),
  26221. useCoarsePointer: retrieve2(opts.useCoarsePointer, defaultCoarsePointer),
  26222. pointerSize: opts.pointerSize
  26223. });
  26224. _this._ssr = opts.ssr;
  26225. // Expect 60 fps.
  26226. _this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  26227. _this._updateTheme(theme);
  26228. _this._locale = createLocaleObject(opts.locale || SYSTEM_LANG);
  26229. _this._coordSysMgr = new CoordinateSystemManager();
  26230. var api = _this._api = createExtensionAPI(_this);
  26231. // Sort on demand
  26232. function prioritySortFunc(a, b) {
  26233. return a.__prio - b.__prio;
  26234. }
  26235. sort(visualFuncs, prioritySortFunc);
  26236. sort(dataProcessorFuncs, prioritySortFunc);
  26237. _this._scheduler = new Scheduler(_this, api, dataProcessorFuncs, visualFuncs);
  26238. _this._messageCenter = new MessageCenter();
  26239. // Init mouse events
  26240. _this._initEvents();
  26241. // In case some people write `window.onresize = chart.resize`
  26242. _this.resize = bind(_this.resize, _this);
  26243. zr.animation.on('frame', _this._onframe, _this);
  26244. bindRenderedEvent(zr, _this);
  26245. bindMouseEvent(zr, _this);
  26246. // ECharts instance can be used as value.
  26247. setAsPrimitive(_this);
  26248. return _this;
  26249. }
  26250. ECharts.prototype._onframe = function () {
  26251. if (this._disposed) {
  26252. return;
  26253. }
  26254. applyChangedStates(this);
  26255. var scheduler = this._scheduler;
  26256. // Lazy update
  26257. if (this[PENDING_UPDATE]) {
  26258. var silent = this[PENDING_UPDATE].silent;
  26259. this[IN_MAIN_PROCESS_KEY] = true;
  26260. updateMainProcessVersion(this);
  26261. try {
  26262. prepare(this);
  26263. updateMethods.update.call(this, null, this[PENDING_UPDATE].updateParams);
  26264. } catch (e) {
  26265. this[IN_MAIN_PROCESS_KEY] = false;
  26266. this[PENDING_UPDATE] = null;
  26267. throw e;
  26268. }
  26269. // At present, in each frame, zrender performs:
  26270. // (1) animation step forward.
  26271. // (2) trigger('frame') (where this `_onframe` is called)
  26272. // (3) zrender flush (render).
  26273. // If we do nothing here, since we use `setToFinal: true`, the step (3) above
  26274. // will render the final state of the elements before the real animation started.
  26275. this._zr.flush();
  26276. this[IN_MAIN_PROCESS_KEY] = false;
  26277. this[PENDING_UPDATE] = null;
  26278. flushPendingActions.call(this, silent);
  26279. triggerUpdatedEvent.call(this, silent);
  26280. }
  26281. // Avoid do both lazy update and progress in one frame.
  26282. else if (scheduler.unfinished) {
  26283. // Stream progress.
  26284. var remainTime = TEST_FRAME_REMAIN_TIME;
  26285. var ecModel = this._model;
  26286. var api = this._api;
  26287. scheduler.unfinished = false;
  26288. do {
  26289. var startTime = +new Date();
  26290. scheduler.performSeriesTasks(ecModel);
  26291. // Currently dataProcessorFuncs do not check threshold.
  26292. scheduler.performDataProcessorTasks(ecModel);
  26293. updateStreamModes(this, ecModel);
  26294. // Do not update coordinate system here. Because that coord system update in
  26295. // each frame is not a good user experience. So we follow the rule that
  26296. // the extent of the coordinate system is determined in the first frame (the
  26297. // frame is executed immediately after task reset.
  26298. // this._coordSysMgr.update(ecModel, api);
  26299. // console.log('--- ec frame visual ---', remainTime);
  26300. scheduler.performVisualTasks(ecModel);
  26301. renderSeries(this, this._model, api, 'remain', {});
  26302. remainTime -= +new Date() - startTime;
  26303. } while (remainTime > 0 && scheduler.unfinished);
  26304. // Call flush explicitly for trigger finished event.
  26305. if (!scheduler.unfinished) {
  26306. this._zr.flush();
  26307. }
  26308. // Else, zr flushing be ensue within the same frame,
  26309. // because zr flushing is after onframe event.
  26310. }
  26311. };
  26312. ECharts.prototype.getDom = function () {
  26313. return this._dom;
  26314. };
  26315. ECharts.prototype.getId = function () {
  26316. return this.id;
  26317. };
  26318. ECharts.prototype.getZr = function () {
  26319. return this._zr;
  26320. };
  26321. ECharts.prototype.isSSR = function () {
  26322. return this._ssr;
  26323. };
  26324. /* eslint-disable-next-line */
  26325. ECharts.prototype.setOption = function (option, notMerge, lazyUpdate) {
  26326. if (this[IN_MAIN_PROCESS_KEY]) {
  26327. if ("development" !== 'production') {
  26328. error('`setOption` should not be called during main process.');
  26329. }
  26330. return;
  26331. }
  26332. if (this._disposed) {
  26333. disposedWarning(this.id);
  26334. return;
  26335. }
  26336. var silent;
  26337. var replaceMerge;
  26338. var transitionOpt;
  26339. if (isObject(notMerge)) {
  26340. lazyUpdate = notMerge.lazyUpdate;
  26341. silent = notMerge.silent;
  26342. replaceMerge = notMerge.replaceMerge;
  26343. transitionOpt = notMerge.transition;
  26344. notMerge = notMerge.notMerge;
  26345. }
  26346. this[IN_MAIN_PROCESS_KEY] = true;
  26347. updateMainProcessVersion(this);
  26348. if (!this._model || notMerge) {
  26349. var optionManager = new OptionManager(this._api);
  26350. var theme = this._theme;
  26351. var ecModel = this._model = new GlobalModel();
  26352. ecModel.scheduler = this._scheduler;
  26353. ecModel.ssr = this._ssr;
  26354. ecModel.init(null, null, null, theme, this._locale, optionManager);
  26355. }
  26356. this._model.setOption(option, {
  26357. replaceMerge: replaceMerge
  26358. }, optionPreprocessorFuncs);
  26359. var updateParams = {
  26360. seriesTransition: transitionOpt,
  26361. optionChanged: true
  26362. };
  26363. if (lazyUpdate) {
  26364. this[PENDING_UPDATE] = {
  26365. silent: silent,
  26366. updateParams: updateParams
  26367. };
  26368. this[IN_MAIN_PROCESS_KEY] = false;
  26369. // `setOption(option, {lazyMode: true})` may be called when zrender has been slept.
  26370. // It should wake it up to make sure zrender start to render at the next frame.
  26371. this.getZr().wakeUp();
  26372. } else {
  26373. try {
  26374. prepare(this);
  26375. updateMethods.update.call(this, null, updateParams);
  26376. } catch (e) {
  26377. this[PENDING_UPDATE] = null;
  26378. this[IN_MAIN_PROCESS_KEY] = false;
  26379. throw e;
  26380. }
  26381. // Ensure zr refresh sychronously, and then pixel in canvas can be
  26382. // fetched after `setOption`.
  26383. if (!this._ssr) {
  26384. // not use flush when using ssr mode.
  26385. this._zr.flush();
  26386. }
  26387. this[PENDING_UPDATE] = null;
  26388. this[IN_MAIN_PROCESS_KEY] = false;
  26389. flushPendingActions.call(this, silent);
  26390. triggerUpdatedEvent.call(this, silent);
  26391. }
  26392. };
  26393. /**
  26394. * Update theme with name or theme option and repaint the chart.
  26395. * @param theme Theme name or theme option.
  26396. * @param opts Optional settings
  26397. */
  26398. ECharts.prototype.setTheme = function (theme, opts) {
  26399. if (this[IN_MAIN_PROCESS_KEY]) {
  26400. if ("development" !== 'production') {
  26401. error('`setTheme` should not be called during main process.');
  26402. }
  26403. return;
  26404. }
  26405. if (this._disposed) {
  26406. disposedWarning(this.id);
  26407. return;
  26408. }
  26409. var ecModel = this._model;
  26410. if (!ecModel) {
  26411. return;
  26412. }
  26413. var silent = opts && opts.silent;
  26414. var updateParams = null;
  26415. if (this[PENDING_UPDATE]) {
  26416. if (silent == null) {
  26417. silent = this[PENDING_UPDATE].silent;
  26418. }
  26419. updateParams = this[PENDING_UPDATE].updateParams;
  26420. this[PENDING_UPDATE] = null;
  26421. }
  26422. this[IN_MAIN_PROCESS_KEY] = true;
  26423. updateMainProcessVersion(this);
  26424. try {
  26425. this._updateTheme(theme);
  26426. ecModel.setTheme(this._theme);
  26427. prepare(this);
  26428. updateMethods.update.call(this, {
  26429. type: 'setTheme'
  26430. }, updateParams);
  26431. } catch (e) {
  26432. this[IN_MAIN_PROCESS_KEY] = false;
  26433. throw e;
  26434. }
  26435. this[IN_MAIN_PROCESS_KEY] = false;
  26436. flushPendingActions.call(this, silent);
  26437. triggerUpdatedEvent.call(this, silent);
  26438. };
  26439. ECharts.prototype._updateTheme = function (theme) {
  26440. if (isString(theme)) {
  26441. theme = themeStorage[theme];
  26442. }
  26443. if (theme) {
  26444. theme = clone(theme);
  26445. theme && globalBackwardCompat(theme, true);
  26446. this._theme = theme;
  26447. }
  26448. };
  26449. // We don't want developers to use getModel directly.
  26450. ECharts.prototype.getModel = function () {
  26451. return this._model;
  26452. };
  26453. ECharts.prototype.getOption = function () {
  26454. return this._model && this._model.getOption();
  26455. };
  26456. ECharts.prototype.getWidth = function () {
  26457. return this._zr.getWidth();
  26458. };
  26459. ECharts.prototype.getHeight = function () {
  26460. return this._zr.getHeight();
  26461. };
  26462. ECharts.prototype.getDevicePixelRatio = function () {
  26463. return this._zr.painter.dpr
  26464. /* eslint-disable-next-line */ || env.hasGlobalWindow && window.devicePixelRatio || 1;
  26465. };
  26466. /**
  26467. * Get canvas which has all thing rendered
  26468. * @deprecated Use renderToCanvas instead.
  26469. */
  26470. ECharts.prototype.getRenderedCanvas = function (opts) {
  26471. if ("development" !== 'production') {
  26472. deprecateReplaceLog('getRenderedCanvas', 'renderToCanvas');
  26473. }
  26474. return this.renderToCanvas(opts);
  26475. };
  26476. ECharts.prototype.renderToCanvas = function (opts) {
  26477. opts = opts || {};
  26478. var painter = this._zr.painter;
  26479. if ("development" !== 'production') {
  26480. if (painter.type !== 'canvas') {
  26481. throw new Error('renderToCanvas can only be used in the canvas renderer.');
  26482. }
  26483. }
  26484. return painter.getRenderedCanvas({
  26485. backgroundColor: opts.backgroundColor || this._model.get('backgroundColor'),
  26486. pixelRatio: opts.pixelRatio || this.getDevicePixelRatio()
  26487. });
  26488. };
  26489. ECharts.prototype.renderToSVGString = function (opts) {
  26490. opts = opts || {};
  26491. var painter = this._zr.painter;
  26492. if ("development" !== 'production') {
  26493. if (painter.type !== 'svg') {
  26494. throw new Error('renderToSVGString can only be used in the svg renderer.');
  26495. }
  26496. }
  26497. return painter.renderToString({
  26498. useViewBox: opts.useViewBox
  26499. });
  26500. };
  26501. /**
  26502. * Get svg data url
  26503. */
  26504. ECharts.prototype.getSvgDataURL = function () {
  26505. var zr = this._zr;
  26506. var list = zr.storage.getDisplayList();
  26507. // Stop animations
  26508. each(list, function (el) {
  26509. el.stopAnimation(null, true);
  26510. });
  26511. return zr.painter.toDataURL();
  26512. };
  26513. ECharts.prototype.getDataURL = function (opts) {
  26514. if (this._disposed) {
  26515. disposedWarning(this.id);
  26516. return;
  26517. }
  26518. opts = opts || {};
  26519. var excludeComponents = opts.excludeComponents;
  26520. var ecModel = this._model;
  26521. var excludesComponentViews = [];
  26522. var self = this;
  26523. each(excludeComponents, function (componentType) {
  26524. ecModel.eachComponent({
  26525. mainType: componentType
  26526. }, function (component) {
  26527. var view = self._componentsMap[component.__viewId];
  26528. if (!view.group.ignore) {
  26529. excludesComponentViews.push(view);
  26530. view.group.ignore = true;
  26531. }
  26532. });
  26533. });
  26534. var url = this._zr.painter.getType() === 'svg' ? this.getSvgDataURL() : this.renderToCanvas(opts).toDataURL('image/' + (opts && opts.type || 'png'));
  26535. each(excludesComponentViews, function (view) {
  26536. view.group.ignore = false;
  26537. });
  26538. return url;
  26539. };
  26540. ECharts.prototype.getConnectedDataURL = function (opts) {
  26541. if (this._disposed) {
  26542. disposedWarning(this.id);
  26543. return;
  26544. }
  26545. var isSvg = opts.type === 'svg';
  26546. var groupId = this.group;
  26547. var mathMin = Math.min;
  26548. var mathMax = Math.max;
  26549. var MAX_NUMBER = Infinity;
  26550. if (connectedGroups[groupId]) {
  26551. var left_1 = MAX_NUMBER;
  26552. var top_1 = MAX_NUMBER;
  26553. var right_1 = -MAX_NUMBER;
  26554. var bottom_1 = -MAX_NUMBER;
  26555. var canvasList_1 = [];
  26556. var dpr_1 = opts && opts.pixelRatio || this.getDevicePixelRatio();
  26557. each(instances$1, function (chart, id) {
  26558. if (chart.group === groupId) {
  26559. var canvas = isSvg ? chart.getZr().painter.getSvgDom().innerHTML : chart.renderToCanvas(clone(opts));
  26560. var boundingRect = chart.getDom().getBoundingClientRect();
  26561. left_1 = mathMin(boundingRect.left, left_1);
  26562. top_1 = mathMin(boundingRect.top, top_1);
  26563. right_1 = mathMax(boundingRect.right, right_1);
  26564. bottom_1 = mathMax(boundingRect.bottom, bottom_1);
  26565. canvasList_1.push({
  26566. dom: canvas,
  26567. left: boundingRect.left,
  26568. top: boundingRect.top
  26569. });
  26570. }
  26571. });
  26572. left_1 *= dpr_1;
  26573. top_1 *= dpr_1;
  26574. right_1 *= dpr_1;
  26575. bottom_1 *= dpr_1;
  26576. var width = right_1 - left_1;
  26577. var height = bottom_1 - top_1;
  26578. var targetCanvas = platformApi.createCanvas();
  26579. var zr_1 = init(targetCanvas, {
  26580. renderer: isSvg ? 'svg' : 'canvas'
  26581. });
  26582. zr_1.resize({
  26583. width: width,
  26584. height: height
  26585. });
  26586. if (isSvg) {
  26587. var content_1 = '';
  26588. each(canvasList_1, function (item) {
  26589. var x = item.left - left_1;
  26590. var y = item.top - top_1;
  26591. content_1 += '<g transform="translate(' + x + ',' + y + ')">' + item.dom + '</g>';
  26592. });
  26593. zr_1.painter.getSvgRoot().innerHTML = content_1;
  26594. if (opts.connectedBackgroundColor) {
  26595. zr_1.painter.setBackgroundColor(opts.connectedBackgroundColor);
  26596. }
  26597. zr_1.refreshImmediately();
  26598. return zr_1.painter.toDataURL();
  26599. } else {
  26600. // Background between the charts
  26601. if (opts.connectedBackgroundColor) {
  26602. zr_1.add(new Rect({
  26603. shape: {
  26604. x: 0,
  26605. y: 0,
  26606. width: width,
  26607. height: height
  26608. },
  26609. style: {
  26610. fill: opts.connectedBackgroundColor
  26611. }
  26612. }));
  26613. }
  26614. each(canvasList_1, function (item) {
  26615. var img = new ZRImage({
  26616. style: {
  26617. x: item.left * dpr_1 - left_1,
  26618. y: item.top * dpr_1 - top_1,
  26619. image: item.dom
  26620. }
  26621. });
  26622. zr_1.add(img);
  26623. });
  26624. zr_1.refreshImmediately();
  26625. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  26626. }
  26627. } else {
  26628. return this.getDataURL(opts);
  26629. }
  26630. };
  26631. ECharts.prototype.convertToPixel = function (finder, value, opt) {
  26632. return doConvertPixel(this, 'convertToPixel', finder, value, opt);
  26633. };
  26634. /**
  26635. * Convert from logical coordinate system to pixel coordinate system.
  26636. * See CoordinateSystem#convertToPixel.
  26637. *
  26638. * @see CoordinateSystem['dataToLayout'] for parameters and return.
  26639. * @see CoordinateSystemDataCoord
  26640. */
  26641. ECharts.prototype.convertToLayout = function (finder, value, opt) {
  26642. return doConvertPixel(this, 'convertToLayout', finder, value, opt);
  26643. };
  26644. // The above are signatures from before v6, thus they should be preserved for backward compat.
  26645. ECharts.prototype.convertFromPixel = function (finder, value, opt) {
  26646. return doConvertPixel(this, 'convertFromPixel', finder, value, opt);
  26647. };
  26648. /**
  26649. * Is the specified coordinate systems or components contain the given pixel point.
  26650. * @param {Array|number} value
  26651. * @return {boolean} result
  26652. */
  26653. ECharts.prototype.containPixel = function (finder, value) {
  26654. if (this._disposed) {
  26655. disposedWarning(this.id);
  26656. return;
  26657. }
  26658. var ecModel = this._model;
  26659. var result;
  26660. var findResult = parseFinder(ecModel, finder);
  26661. each(findResult, function (models, key) {
  26662. key.indexOf('Models') >= 0 && each(models, function (model) {
  26663. var coordSys = model.coordinateSystem;
  26664. if (coordSys && coordSys.containPoint) {
  26665. result = result || !!coordSys.containPoint(value);
  26666. } else if (key === 'seriesModels') {
  26667. var view = this._chartsMap[model.__viewId];
  26668. if (view && view.containPoint) {
  26669. result = result || view.containPoint(value, model);
  26670. } else {
  26671. if ("development" !== 'production') {
  26672. warn(key + ': ' + (view ? 'The found component do not support containPoint.' : 'No view mapping to the found component.'));
  26673. }
  26674. }
  26675. } else {
  26676. if ("development" !== 'production') {
  26677. warn(key + ': containPoint is not supported');
  26678. }
  26679. }
  26680. }, this);
  26681. }, this);
  26682. return !!result;
  26683. };
  26684. /**
  26685. * Get visual from series or data.
  26686. * @param finder
  26687. * If string, e.g., 'series', means {seriesIndex: 0}.
  26688. * If Object, could contain some of these properties below:
  26689. * {
  26690. * seriesIndex / seriesId / seriesName,
  26691. * dataIndex / dataIndexInside
  26692. * }
  26693. * If dataIndex is not specified, series visual will be fetched,
  26694. * but not data item visual.
  26695. * If all of seriesIndex, seriesId, seriesName are not specified,
  26696. * visual will be fetched from first series.
  26697. * @param visualType 'color', 'symbol', 'symbolSize'
  26698. */
  26699. ECharts.prototype.getVisual = function (finder, visualType) {
  26700. var ecModel = this._model;
  26701. var parsedFinder = parseFinder(ecModel, finder, {
  26702. defaultMainType: 'series'
  26703. });
  26704. var seriesModel = parsedFinder.seriesModel;
  26705. if ("development" !== 'production') {
  26706. if (!seriesModel) {
  26707. warn('There is no specified series model');
  26708. }
  26709. }
  26710. var data = seriesModel.getData();
  26711. var dataIndexInside = parsedFinder.hasOwnProperty('dataIndexInside') ? parsedFinder.dataIndexInside : parsedFinder.hasOwnProperty('dataIndex') ? data.indexOfRawIndex(parsedFinder.dataIndex) : null;
  26712. return dataIndexInside != null ? getItemVisualFromData(data, dataIndexInside, visualType) : getVisualFromData(data, visualType);
  26713. };
  26714. /**
  26715. * Get view of corresponding component model
  26716. */
  26717. ECharts.prototype.getViewOfComponentModel = function (componentModel) {
  26718. return this._componentsMap[componentModel.__viewId];
  26719. };
  26720. /**
  26721. * Get view of corresponding series model
  26722. */
  26723. ECharts.prototype.getViewOfSeriesModel = function (seriesModel) {
  26724. return this._chartsMap[seriesModel.__viewId];
  26725. };
  26726. ECharts.prototype._initEvents = function () {
  26727. var _this = this;
  26728. each(MOUSE_EVENT_NAMES, function (eveName) {
  26729. var handler = function (e) {
  26730. var ecModel = _this.getModel();
  26731. var el = e.target;
  26732. var params;
  26733. var isGlobalOut = eveName === 'globalout';
  26734. // no e.target when 'globalout'.
  26735. if (isGlobalOut) {
  26736. params = {};
  26737. } else {
  26738. el && findEventDispatcher(el, function (parent) {
  26739. var ecData = getECData(parent);
  26740. if (ecData && ecData.dataIndex != null) {
  26741. var dataModel = ecData.dataModel || ecModel.getSeriesByIndex(ecData.seriesIndex);
  26742. params = dataModel && dataModel.getDataParams(ecData.dataIndex, ecData.dataType, el) || {};
  26743. return true;
  26744. }
  26745. // If element has custom eventData of components
  26746. else if (ecData.eventData) {
  26747. params = extend({}, ecData.eventData);
  26748. return true;
  26749. }
  26750. }, true);
  26751. }
  26752. // Contract: if params prepared in mouse event,
  26753. // these properties must be specified:
  26754. // {
  26755. // componentType: string (component main type)
  26756. // componentIndex: number
  26757. // }
  26758. // Otherwise event query can not work.
  26759. if (params) {
  26760. var componentType = params.componentType;
  26761. var componentIndex = params.componentIndex;
  26762. // Special handling for historic reason: when trigger by
  26763. // markLine/markPoint/markArea, the componentType is
  26764. // 'markLine'/'markPoint'/'markArea', but we should better
  26765. // enable them to be queried by seriesIndex, since their
  26766. // option is set in each series.
  26767. if (componentType === 'markLine' || componentType === 'markPoint' || componentType === 'markArea') {
  26768. componentType = 'series';
  26769. componentIndex = params.seriesIndex;
  26770. }
  26771. var model = componentType && componentIndex != null && ecModel.getComponent(componentType, componentIndex);
  26772. var view = model && _this[model.mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId];
  26773. if ("development" !== 'production') {
  26774. // `event.componentType` and `event[componentTpype + 'Index']` must not
  26775. // be missed, otherwise there is no way to distinguish source component.
  26776. // See `dataFormat.getDataParams`.
  26777. if (!isGlobalOut && !(model && view)) {
  26778. warn('model or view can not be found by params');
  26779. }
  26780. }
  26781. params.event = e;
  26782. params.type = eveName;
  26783. _this._$eventProcessor.eventInfo = {
  26784. targetEl: el,
  26785. packedEvent: params,
  26786. model: model,
  26787. view: view
  26788. };
  26789. _this.trigger(eveName, params);
  26790. }
  26791. };
  26792. // Consider that some component (like tooltip, brush, ...)
  26793. // register zr event handler, but user event handler might
  26794. // do anything, such as call `setOption` or `dispatchAction`,
  26795. // which probably update any of the content and probably
  26796. // cause problem if it is called previous other inner handlers.
  26797. handler.zrEventfulCallAtLast = true;
  26798. _this._zr.on(eveName, handler, _this);
  26799. });
  26800. var messageCenter = this._messageCenter;
  26801. each(publicEventTypeMap, function (_, eventType) {
  26802. messageCenter.on(eventType, function (event) {
  26803. _this.trigger(eventType, event);
  26804. });
  26805. });
  26806. handleLegacySelectEvents(messageCenter, this, this._api);
  26807. };
  26808. ECharts.prototype.isDisposed = function () {
  26809. return this._disposed;
  26810. };
  26811. ECharts.prototype.clear = function () {
  26812. if (this._disposed) {
  26813. disposedWarning(this.id);
  26814. return;
  26815. }
  26816. this.setOption({
  26817. series: []
  26818. }, true);
  26819. };
  26820. ECharts.prototype.dispose = function () {
  26821. if (this._disposed) {
  26822. disposedWarning(this.id);
  26823. return;
  26824. }
  26825. this._disposed = true;
  26826. var dom = this.getDom();
  26827. if (dom) {
  26828. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  26829. }
  26830. var chart = this;
  26831. var api = chart._api;
  26832. var ecModel = chart._model;
  26833. each(chart._componentsViews, function (component) {
  26834. component.dispose(ecModel, api);
  26835. });
  26836. each(chart._chartsViews, function (chart) {
  26837. chart.dispose(ecModel, api);
  26838. });
  26839. // Dispose after all views disposed
  26840. chart._zr.dispose();
  26841. // Set properties to null.
  26842. // To reduce the memory cost in case the top code still holds this instance unexpectedly.
  26843. chart._dom = chart._model = chart._chartsMap = chart._componentsMap = chart._chartsViews = chart._componentsViews = chart._scheduler = chart._api = chart._zr = chart._throttledZrFlush = chart._theme = chart._coordSysMgr = chart._messageCenter = null;
  26844. delete instances$1[chart.id];
  26845. };
  26846. /**
  26847. * Resize the chart
  26848. */
  26849. ECharts.prototype.resize = function (opts) {
  26850. if (this[IN_MAIN_PROCESS_KEY]) {
  26851. if ("development" !== 'production') {
  26852. error('`resize` should not be called during main process.');
  26853. }
  26854. return;
  26855. }
  26856. if (this._disposed) {
  26857. disposedWarning(this.id);
  26858. return;
  26859. }
  26860. this._zr.resize(opts);
  26861. var ecModel = this._model;
  26862. // Resize loading effect
  26863. this._loadingFX && this._loadingFX.resize();
  26864. if (!ecModel) {
  26865. return;
  26866. }
  26867. var needPrepare = ecModel.resetOption('media');
  26868. var silent = opts && opts.silent;
  26869. // There is some real cases that:
  26870. // chart.setOption(option, { lazyUpdate: true });
  26871. // chart.resize();
  26872. if (this[PENDING_UPDATE]) {
  26873. if (silent == null) {
  26874. silent = this[PENDING_UPDATE].silent;
  26875. }
  26876. needPrepare = true;
  26877. this[PENDING_UPDATE] = null;
  26878. }
  26879. this[IN_MAIN_PROCESS_KEY] = true;
  26880. updateMainProcessVersion(this);
  26881. try {
  26882. needPrepare && prepare(this);
  26883. updateMethods.update.call(this, {
  26884. type: 'resize',
  26885. animation: extend({
  26886. // Disable animation
  26887. duration: 0
  26888. }, opts && opts.animation)
  26889. });
  26890. } catch (e) {
  26891. this[IN_MAIN_PROCESS_KEY] = false;
  26892. throw e;
  26893. }
  26894. this[IN_MAIN_PROCESS_KEY] = false;
  26895. flushPendingActions.call(this, silent);
  26896. triggerUpdatedEvent.call(this, silent);
  26897. };
  26898. ECharts.prototype.showLoading = function (name, cfg) {
  26899. if (this._disposed) {
  26900. disposedWarning(this.id);
  26901. return;
  26902. }
  26903. if (isObject(name)) {
  26904. cfg = name;
  26905. name = '';
  26906. }
  26907. name = name || 'default';
  26908. this.hideLoading();
  26909. if (!loadingEffects[name]) {
  26910. if ("development" !== 'production') {
  26911. warn('Loading effects ' + name + ' not exists.');
  26912. }
  26913. return;
  26914. }
  26915. var el = loadingEffects[name](this._api, cfg);
  26916. var zr = this._zr;
  26917. this._loadingFX = el;
  26918. zr.add(el);
  26919. };
  26920. /**
  26921. * Hide loading effect
  26922. */
  26923. ECharts.prototype.hideLoading = function () {
  26924. if (this._disposed) {
  26925. disposedWarning(this.id);
  26926. return;
  26927. }
  26928. this._loadingFX && this._zr.remove(this._loadingFX);
  26929. this._loadingFX = null;
  26930. };
  26931. ECharts.prototype.makeActionFromEvent = function (eventObj) {
  26932. var payload = extend({}, eventObj);
  26933. payload.type = connectionEventRevertMap[eventObj.type];
  26934. return payload;
  26935. };
  26936. /**
  26937. * @param opt If pass boolean, means opt.silent
  26938. * @param opt.silent Default `false`. Whether trigger events.
  26939. * @param opt.flush Default `undefined`.
  26940. * true: Flush immediately, and then pixel in canvas can be fetched
  26941. * immediately. Caution: it might affect performance.
  26942. * false: Not flush.
  26943. * undefined: Auto decide whether perform flush.
  26944. */
  26945. ECharts.prototype.dispatchAction = function (payload, opt) {
  26946. if (this._disposed) {
  26947. disposedWarning(this.id);
  26948. return;
  26949. }
  26950. if (!isObject(opt)) {
  26951. opt = {
  26952. silent: !!opt
  26953. };
  26954. }
  26955. if (!actions[payload.type]) {
  26956. return;
  26957. }
  26958. // Avoid dispatch action before setOption. Especially in `connect`.
  26959. if (!this._model) {
  26960. return;
  26961. }
  26962. // May dispatchAction in rendering procedure
  26963. if (this[IN_MAIN_PROCESS_KEY]) {
  26964. this._pendingActions.push(payload);
  26965. return;
  26966. }
  26967. var silent = opt.silent;
  26968. doDispatchAction.call(this, payload, silent);
  26969. var flush = opt.flush;
  26970. if (flush) {
  26971. this._zr.flush();
  26972. } else if (flush !== false && env.browser.weChat) {
  26973. // In WeChat embedded browser, `requestAnimationFrame` and `setInterval`
  26974. // hang when sliding page (on touch event), which cause that zr does not
  26975. // refresh until user interaction finished, which is not expected.
  26976. // But `dispatchAction` may be called too frequently when pan on touch
  26977. // screen, which impacts performance if do not throttle them.
  26978. this._throttledZrFlush();
  26979. }
  26980. flushPendingActions.call(this, silent);
  26981. triggerUpdatedEvent.call(this, silent);
  26982. };
  26983. ECharts.prototype.updateLabelLayout = function () {
  26984. lifecycle.trigger('series:layoutlabels', this._model, this._api, {
  26985. // Not adding series labels.
  26986. // TODO
  26987. updatedSeries: []
  26988. });
  26989. };
  26990. ECharts.prototype.appendData = function (params) {
  26991. if (this._disposed) {
  26992. disposedWarning(this.id);
  26993. return;
  26994. }
  26995. var seriesIndex = params.seriesIndex;
  26996. var ecModel = this.getModel();
  26997. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  26998. if ("development" !== 'production') {
  26999. assert(params.data && seriesModel);
  27000. }
  27001. seriesModel.appendData(params);
  27002. // Note: `appendData` does not support that update extent of coordinate
  27003. // system, util some scenario require that. In the expected usage of
  27004. // `appendData`, the initial extent of coordinate system should better
  27005. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  27006. // the extent changed while `appendData`, the location of the painted
  27007. // graphic elements have to be changed, which make the usage of
  27008. // `appendData` meaningless.
  27009. this._scheduler.unfinished = true;
  27010. this.getZr().wakeUp();
  27011. };
  27012. // A work around for no `internal` modifier in ts yet but
  27013. // need to strictly hide private methods to JS users.
  27014. ECharts.internalField = function () {
  27015. prepare = function (ecIns) {
  27016. var scheduler = ecIns._scheduler;
  27017. scheduler.restorePipelines(ecIns._model);
  27018. scheduler.prepareStageTasks();
  27019. prepareView(ecIns, true);
  27020. prepareView(ecIns, false);
  27021. scheduler.plan();
  27022. };
  27023. /**
  27024. * Prepare view instances of charts and components
  27025. */
  27026. prepareView = function (ecIns, isComponent) {
  27027. var ecModel = ecIns._model;
  27028. var scheduler = ecIns._scheduler;
  27029. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  27030. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  27031. var zr = ecIns._zr;
  27032. var api = ecIns._api;
  27033. for (var i = 0; i < viewList.length; i++) {
  27034. viewList[i].__alive = false;
  27035. }
  27036. isComponent ? ecModel.eachComponent(function (componentType, model) {
  27037. componentType !== 'series' && doPrepare(model);
  27038. }) : ecModel.eachSeries(doPrepare);
  27039. function doPrepare(model) {
  27040. // By default view will be reused if possible for the case that `setOption` with "notMerge"
  27041. // mode and need to enable transition animation. (Usually, when they have the same id, or
  27042. // especially no id but have the same type & name & index. See the `model.id` generation
  27043. // rule in `makeIdAndName` and `viewId` generation rule here).
  27044. // But in `replaceMerge` mode, this feature should be able to disabled when it is clear that
  27045. // the new model has nothing to do with the old model.
  27046. var requireNewView = model.__requireNewView;
  27047. // This command should not work twice.
  27048. model.__requireNewView = false;
  27049. // Consider: id same and type changed.
  27050. var viewId = '_ec_' + model.id + '_' + model.type;
  27051. var view = !requireNewView && viewMap[viewId];
  27052. if (!view) {
  27053. var classType = parseClassType(model.type);
  27054. var Clazz = isComponent ? ComponentView.getClass(classType.main, classType.sub) :
  27055. // FIXME:TS
  27056. // (ChartView as ChartViewConstructor).getClass('series', classType.sub)
  27057. // For backward compat, still support a chart type declared as only subType
  27058. // like "liquidfill", but recommend "series.liquidfill"
  27059. // But need a base class to make a type series.
  27060. ChartView.getClass(classType.sub);
  27061. if ("development" !== 'production') {
  27062. assert(Clazz, classType.sub + ' does not exist.');
  27063. }
  27064. view = new Clazz();
  27065. view.init(ecModel, api);
  27066. viewMap[viewId] = view;
  27067. viewList.push(view);
  27068. zr.add(view.group);
  27069. }
  27070. model.__viewId = view.__id = viewId;
  27071. view.__alive = true;
  27072. view.__model = model;
  27073. view.group.__ecComponentInfo = {
  27074. mainType: model.mainType,
  27075. index: model.componentIndex
  27076. };
  27077. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  27078. }
  27079. for (var i = 0; i < viewList.length;) {
  27080. var view = viewList[i];
  27081. if (!view.__alive) {
  27082. !isComponent && view.renderTask.dispose();
  27083. zr.remove(view.group);
  27084. view.dispose(ecModel, api);
  27085. viewList.splice(i, 1);
  27086. if (viewMap[view.__id] === view) {
  27087. delete viewMap[view.__id];
  27088. }
  27089. view.__id = view.group.__ecComponentInfo = null;
  27090. } else {
  27091. i++;
  27092. }
  27093. }
  27094. };
  27095. updateDirectly = function (ecIns, method, payload, mainType, subType) {
  27096. var ecModel = ecIns._model;
  27097. ecModel.setUpdatePayload(payload);
  27098. // broadcast
  27099. if (!mainType) {
  27100. // FIXME
  27101. // Chart will not be update directly here, except set dirty.
  27102. // But there is no such scenario now.
  27103. each([].concat(ecIns._componentsViews).concat(ecIns._chartsViews), callView);
  27104. return;
  27105. }
  27106. var query = {};
  27107. query[mainType + 'Id'] = payload[mainType + 'Id'];
  27108. query[mainType + 'Index'] = payload[mainType + 'Index'];
  27109. query[mainType + 'Name'] = payload[mainType + 'Name'];
  27110. var condition = {
  27111. mainType: mainType,
  27112. query: query
  27113. };
  27114. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  27115. var excludeSeriesId = payload.excludeSeriesId;
  27116. var excludeSeriesIdMap;
  27117. if (excludeSeriesId != null) {
  27118. excludeSeriesIdMap = createHashMap();
  27119. each(normalizeToArray(excludeSeriesId), function (id) {
  27120. var modelId = convertOptionIdName(id, null);
  27121. if (modelId != null) {
  27122. excludeSeriesIdMap.set(modelId, true);
  27123. }
  27124. });
  27125. }
  27126. // If dispatchAction before setOption, do nothing.
  27127. ecModel && ecModel.eachComponent(condition, function (model) {
  27128. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) != null;
  27129. if (isExcluded) {
  27130. return;
  27131. }
  27132. if (isHighDownPayload(payload)) {
  27133. if (model instanceof SeriesModel) {
  27134. if (payload.type === HIGHLIGHT_ACTION_TYPE && !payload.notBlur && !model.get(['emphasis', 'disabled'])) {
  27135. blurSeriesFromHighlightPayload(model, payload, ecIns._api);
  27136. }
  27137. } else {
  27138. var _a = findComponentHighDownDispatchers(model.mainType, model.componentIndex, payload.name, ecIns._api),
  27139. focusSelf = _a.focusSelf,
  27140. dispatchers = _a.dispatchers;
  27141. if (payload.type === HIGHLIGHT_ACTION_TYPE && focusSelf && !payload.notBlur) {
  27142. blurComponent(model.mainType, model.componentIndex, ecIns._api);
  27143. }
  27144. // PENDING:
  27145. // Whether to put this "enter emphasis" code in `ComponentView`,
  27146. // which will be the same as `ChartView` but might be not necessary
  27147. // and will be far from this logic.
  27148. if (dispatchers) {
  27149. each(dispatchers, function (dispatcher) {
  27150. payload.type === HIGHLIGHT_ACTION_TYPE ? enterEmphasis(dispatcher) : leaveEmphasis(dispatcher);
  27151. });
  27152. }
  27153. }
  27154. } else if (isSelectChangePayload(payload)) {
  27155. // TODO geo
  27156. if (model instanceof SeriesModel) {
  27157. toggleSelectionFromPayload(model, payload, ecIns._api);
  27158. updateSeriesElementSelection(model);
  27159. markStatusToUpdate(ecIns);
  27160. }
  27161. }
  27162. }, ecIns);
  27163. ecModel && ecModel.eachComponent(condition, function (model) {
  27164. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) != null;
  27165. if (isExcluded) {
  27166. return;
  27167. }
  27168. callView(ecIns[mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId]);
  27169. }, ecIns);
  27170. function callView(view) {
  27171. view && view.__alive && view[method] && view[method](view.__model, ecModel, ecIns._api, payload);
  27172. }
  27173. };
  27174. updateMethods = {
  27175. prepareAndUpdate: function (payload) {
  27176. prepare(this);
  27177. updateMethods.update.call(this, payload, payload && {
  27178. // Needs to mark option changed if newOption is given.
  27179. // It's from MagicType.
  27180. // TODO If use a separate flag optionChanged in payload?
  27181. optionChanged: payload.newOption != null
  27182. });
  27183. },
  27184. update: function (payload, updateParams) {
  27185. var ecModel = this._model;
  27186. var api = this._api;
  27187. var zr = this._zr;
  27188. var coordSysMgr = this._coordSysMgr;
  27189. var scheduler = this._scheduler;
  27190. // update before setOption
  27191. if (!ecModel) {
  27192. return;
  27193. }
  27194. ecModel.setUpdatePayload(payload);
  27195. scheduler.restoreData(ecModel, payload);
  27196. scheduler.performSeriesTasks(ecModel);
  27197. // TODO
  27198. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  27199. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  27200. // Create new coordinate system each update
  27201. // In LineView may save the old coordinate system and use it to get the original point.
  27202. coordSysMgr.create(ecModel, api);
  27203. scheduler.performDataProcessorTasks(ecModel, payload);
  27204. // Current stream render is not supported in data process. So we can update
  27205. // stream modes after data processing, where the filtered data is used to
  27206. // determine whether to use progressive rendering.
  27207. updateStreamModes(this, ecModel);
  27208. // We update stream modes before coordinate system updated, then the modes info
  27209. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  27210. // the drawback is the full coord info can not be fetched. Fortunately this full
  27211. // coord is not required in stream mode updater currently.
  27212. coordSysMgr.update(ecModel, api);
  27213. clearColorPalette(ecModel);
  27214. scheduler.performVisualTasks(ecModel, payload);
  27215. // Set background and dark mode before rendering, because they affect auto-color-determination
  27216. // in zrender Text, and consequently affect the bounding rect if stroke is added.
  27217. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  27218. zr.setBackgroundColor(backgroundColor);
  27219. // Force set dark mode.
  27220. var darkMode = ecModel.get('darkMode');
  27221. if (darkMode != null && darkMode !== 'auto') {
  27222. zr.setDarkMode(darkMode);
  27223. }
  27224. render(this, ecModel, api, payload, updateParams);
  27225. lifecycle.trigger('afterupdate', ecModel, api);
  27226. },
  27227. updateTransform: function (payload) {
  27228. var _this = this;
  27229. var ecModel = this._model;
  27230. var api = this._api;
  27231. // update before setOption
  27232. if (!ecModel) {
  27233. return;
  27234. }
  27235. ecModel.setUpdatePayload(payload);
  27236. // ChartView.markUpdateMethod(payload, 'updateTransform');
  27237. var componentDirtyList = [];
  27238. ecModel.eachComponent(function (componentType, componentModel) {
  27239. if (componentType === 'series') {
  27240. return;
  27241. }
  27242. var componentView = _this.getViewOfComponentModel(componentModel);
  27243. if (componentView && componentView.__alive) {
  27244. if (componentView.updateTransform) {
  27245. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  27246. result && result.update && componentDirtyList.push(componentView);
  27247. } else {
  27248. componentDirtyList.push(componentView);
  27249. }
  27250. }
  27251. });
  27252. var seriesDirtyMap = createHashMap();
  27253. ecModel.eachSeries(function (seriesModel) {
  27254. var chartView = _this._chartsMap[seriesModel.__viewId];
  27255. if (chartView.updateTransform) {
  27256. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  27257. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  27258. } else {
  27259. seriesDirtyMap.set(seriesModel.uid, 1);
  27260. }
  27261. });
  27262. clearColorPalette(ecModel);
  27263. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27264. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  27265. this._scheduler.performVisualTasks(ecModel, payload, {
  27266. setDirty: true,
  27267. dirtyMap: seriesDirtyMap
  27268. });
  27269. // Currently, not call render of components. Geo render cost a lot.
  27270. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  27271. renderSeries(this, ecModel, api, payload, {}, seriesDirtyMap);
  27272. lifecycle.trigger('afterupdate', ecModel, api);
  27273. },
  27274. updateView: function (payload) {
  27275. var ecModel = this._model;
  27276. // update before setOption
  27277. if (!ecModel) {
  27278. return;
  27279. }
  27280. ecModel.setUpdatePayload(payload);
  27281. ChartView.markUpdateMethod(payload, 'updateView');
  27282. clearColorPalette(ecModel);
  27283. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27284. this._scheduler.performVisualTasks(ecModel, payload, {
  27285. setDirty: true
  27286. });
  27287. render(this, ecModel, this._api, payload, {});
  27288. lifecycle.trigger('afterupdate', ecModel, this._api);
  27289. },
  27290. updateVisual: function (payload) {
  27291. // updateMethods.update.call(this, payload);
  27292. var _this = this;
  27293. var ecModel = this._model;
  27294. // update before setOption
  27295. if (!ecModel) {
  27296. return;
  27297. }
  27298. ecModel.setUpdatePayload(payload);
  27299. // clear all visual
  27300. ecModel.eachSeries(function (seriesModel) {
  27301. seriesModel.getData().clearAllVisual();
  27302. });
  27303. // Perform visual
  27304. ChartView.markUpdateMethod(payload, 'updateVisual');
  27305. clearColorPalette(ecModel);
  27306. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27307. this._scheduler.performVisualTasks(ecModel, payload, {
  27308. visualType: 'visual',
  27309. setDirty: true
  27310. });
  27311. ecModel.eachComponent(function (componentType, componentModel) {
  27312. if (componentType !== 'series') {
  27313. var componentView = _this.getViewOfComponentModel(componentModel);
  27314. componentView && componentView.__alive && componentView.updateVisual(componentModel, ecModel, _this._api, payload);
  27315. }
  27316. });
  27317. ecModel.eachSeries(function (seriesModel) {
  27318. var chartView = _this._chartsMap[seriesModel.__viewId];
  27319. chartView.updateVisual(seriesModel, ecModel, _this._api, payload);
  27320. });
  27321. lifecycle.trigger('afterupdate', ecModel, this._api);
  27322. },
  27323. updateLayout: function (payload) {
  27324. updateMethods.update.call(this, payload);
  27325. }
  27326. };
  27327. function doConvertPixelImpl(ecIns, methodName, finder, value, opt) {
  27328. if (ecIns._disposed) {
  27329. disposedWarning(ecIns.id);
  27330. return;
  27331. }
  27332. var ecModel = ecIns._model;
  27333. var coordSysList = ecIns._coordSysMgr.getCoordinateSystems();
  27334. var result;
  27335. var parsedFinder = parseFinder(ecModel, finder);
  27336. for (var i = 0; i < coordSysList.length; i++) {
  27337. var coordSys = coordSysList[i];
  27338. if (coordSys[methodName] && (result = coordSys[methodName](ecModel, parsedFinder, value, opt)) != null) {
  27339. return result;
  27340. }
  27341. }
  27342. if ("development" !== 'production') {
  27343. warn('No coordinate system that supports ' + methodName + ' found by the given finder.');
  27344. }
  27345. }
  27346. doConvertPixel = doConvertPixelImpl;
  27347. updateStreamModes = function (ecIns, ecModel) {
  27348. var chartsMap = ecIns._chartsMap;
  27349. var scheduler = ecIns._scheduler;
  27350. ecModel.eachSeries(function (seriesModel) {
  27351. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  27352. });
  27353. };
  27354. doDispatchAction = function (payload, silent) {
  27355. var _this = this;
  27356. var ecModel = this.getModel();
  27357. var payloadType = payload.type;
  27358. var escapeConnect = payload.escapeConnect;
  27359. var actionInfo = actions[payloadType];
  27360. var cptTypeTmp = (actionInfo.update || 'update').split(':');
  27361. var updateMethod = cptTypeTmp.pop();
  27362. var cptType = cptTypeTmp[0] != null && parseClassType(cptTypeTmp[0]);
  27363. this[IN_MAIN_PROCESS_KEY] = true;
  27364. updateMainProcessVersion(this);
  27365. var payloads = [payload];
  27366. var batched = false;
  27367. // Batch action
  27368. if (payload.batch) {
  27369. batched = true;
  27370. payloads = map(payload.batch, function (item) {
  27371. item = defaults(extend({}, item), payload);
  27372. item.batch = null;
  27373. return item;
  27374. });
  27375. }
  27376. var eventObjBatch = [];
  27377. var eventObj;
  27378. var actionResultBatch = [];
  27379. var nonRefinedEventType = actionInfo.nonRefinedEventType;
  27380. var isSelectChange = isSelectChangePayload(payload);
  27381. var isHighDown = isHighDownPayload(payload);
  27382. // Only leave blur once if there are multiple batches.
  27383. if (isHighDown) {
  27384. allLeaveBlur(this._api);
  27385. }
  27386. each(payloads, function (batchItem) {
  27387. // Action can specify the event by return it.
  27388. var actionResult = actionInfo.action(batchItem, ecModel, _this._api);
  27389. if (actionInfo.refineEvent) {
  27390. actionResultBatch.push(actionResult);
  27391. } else {
  27392. eventObj = actionResult;
  27393. }
  27394. eventObj = eventObj || extend({}, batchItem);
  27395. eventObj.type = nonRefinedEventType;
  27396. eventObjBatch.push(eventObj);
  27397. // light update does not perform data process, layout and visual.
  27398. if (isHighDown) {
  27399. var _a = preParseFinder(payload),
  27400. queryOptionMap = _a.queryOptionMap,
  27401. mainTypeSpecified = _a.mainTypeSpecified;
  27402. var componentMainType = mainTypeSpecified ? queryOptionMap.keys()[0] : 'series';
  27403. updateDirectly(_this, updateMethod, batchItem, componentMainType);
  27404. markStatusToUpdate(_this);
  27405. } else if (isSelectChange) {
  27406. // At present `dispatchAction({ type: 'select', ... })` is not supported on components.
  27407. // geo still use 'geoselect'.
  27408. updateDirectly(_this, updateMethod, batchItem, 'series');
  27409. markStatusToUpdate(_this);
  27410. } else if (cptType) {
  27411. updateDirectly(_this, updateMethod, batchItem, cptType.main, cptType.sub);
  27412. }
  27413. });
  27414. if (updateMethod !== 'none' && !isHighDown && !isSelectChange && !cptType) {
  27415. try {
  27416. // Still dirty
  27417. if (this[PENDING_UPDATE]) {
  27418. prepare(this);
  27419. updateMethods.update.call(this, payload);
  27420. this[PENDING_UPDATE] = null;
  27421. } else {
  27422. updateMethods[updateMethod].call(this, payload);
  27423. }
  27424. } catch (e) {
  27425. this[IN_MAIN_PROCESS_KEY] = false;
  27426. throw e;
  27427. }
  27428. }
  27429. // Follow the rule of action batch
  27430. if (batched) {
  27431. eventObj = {
  27432. type: nonRefinedEventType,
  27433. escapeConnect: escapeConnect,
  27434. batch: eventObjBatch
  27435. };
  27436. } else {
  27437. eventObj = eventObjBatch[0];
  27438. }
  27439. this[IN_MAIN_PROCESS_KEY] = false;
  27440. if (!silent) {
  27441. var refinedEvent = void 0;
  27442. if (actionInfo.refineEvent) {
  27443. var eventContent = actionInfo.refineEvent(actionResultBatch, payload, ecModel, this._api).eventContent;
  27444. assert(isObject(eventContent));
  27445. refinedEvent = defaults({
  27446. type: actionInfo.refinedEventType
  27447. }, eventContent);
  27448. refinedEvent.fromAction = payload.type;
  27449. refinedEvent.fromActionPayload = payload;
  27450. refinedEvent.escapeConnect = true;
  27451. }
  27452. var messageCenter = this._messageCenter;
  27453. // - If `refineEvent` created a `refinedEvent`, `eventObj` (replicated from the original payload)
  27454. // is still needed to be triggered for the feature `connect`. But it will not be triggered to
  27455. // users in this case.
  27456. // - If no `refineEvent` used, `eventObj` will be triggered for both `connect` and users.
  27457. messageCenter.trigger(eventObj.type, eventObj);
  27458. if (refinedEvent) {
  27459. messageCenter.trigger(refinedEvent.type, refinedEvent);
  27460. }
  27461. }
  27462. };
  27463. flushPendingActions = function (silent) {
  27464. var pendingActions = this._pendingActions;
  27465. while (pendingActions.length) {
  27466. var payload = pendingActions.shift();
  27467. doDispatchAction.call(this, payload, silent);
  27468. }
  27469. };
  27470. triggerUpdatedEvent = function (silent) {
  27471. !silent && this.trigger('updated');
  27472. };
  27473. /**
  27474. * Event `rendered` is triggered when zr
  27475. * rendered. It is useful for realtime
  27476. * snapshot (reflect animation).
  27477. *
  27478. * Event `finished` is triggered when:
  27479. * (1) zrender rendering finished.
  27480. * (2) initial animation finished.
  27481. * (3) progressive rendering finished.
  27482. * (4) no pending action.
  27483. * (5) no delayed setOption needs to be processed.
  27484. */
  27485. bindRenderedEvent = function (zr, ecIns) {
  27486. zr.on('rendered', function (params) {
  27487. ecIns.trigger('rendered', params);
  27488. // The `finished` event should not be triggered repeatedly,
  27489. // so it should only be triggered when rendering indeed happens
  27490. // in zrender. (Consider the case that dipatchAction is keep
  27491. // triggering when mouse move).
  27492. if (
  27493. // Although zr is dirty if initial animation is not finished
  27494. // and this checking is called on frame, we also check
  27495. // animation finished for robustness.
  27496. zr.animation.isFinished() && !ecIns[PENDING_UPDATE] && !ecIns._scheduler.unfinished && !ecIns._pendingActions.length) {
  27497. ecIns.trigger('finished');
  27498. }
  27499. });
  27500. };
  27501. bindMouseEvent = function (zr, ecIns) {
  27502. zr.on('mouseover', function (e) {
  27503. var el = e.target;
  27504. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  27505. if (dispatcher) {
  27506. handleGlobalMouseOverForHighDown(dispatcher, e, ecIns._api);
  27507. markStatusToUpdate(ecIns);
  27508. }
  27509. }).on('mouseout', function (e) {
  27510. var el = e.target;
  27511. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  27512. if (dispatcher) {
  27513. handleGlobalMouseOutForHighDown(dispatcher, e, ecIns._api);
  27514. markStatusToUpdate(ecIns);
  27515. }
  27516. }).on('click', function (e) {
  27517. var el = e.target;
  27518. var dispatcher = findEventDispatcher(el, function (target) {
  27519. return getECData(target).dataIndex != null;
  27520. }, true);
  27521. if (dispatcher) {
  27522. var actionType = dispatcher.selected ? 'unselect' : 'select';
  27523. var ecData = getECData(dispatcher);
  27524. ecIns._api.dispatchAction({
  27525. type: actionType,
  27526. dataType: ecData.dataType,
  27527. dataIndexInside: ecData.dataIndex,
  27528. seriesIndex: ecData.seriesIndex,
  27529. isFromClick: true
  27530. });
  27531. }
  27532. });
  27533. };
  27534. function clearColorPalette(ecModel) {
  27535. ecModel.clearColorPalette();
  27536. ecModel.eachSeries(function (seriesModel) {
  27537. seriesModel.clearColorPalette();
  27538. });
  27539. }
  27540. // Allocate zlevels for series and components
  27541. function allocateZlevels(ecModel) {
  27542. var componentZLevels = [];
  27543. var seriesZLevels = [];
  27544. var hasSeparateZLevel = false;
  27545. ecModel.eachComponent(function (componentType, componentModel) {
  27546. var zlevel = componentModel.get('zlevel') || 0;
  27547. var z = componentModel.get('z') || 0;
  27548. var zlevelKey = componentModel.getZLevelKey();
  27549. hasSeparateZLevel = hasSeparateZLevel || !!zlevelKey;
  27550. (componentType === 'series' ? seriesZLevels : componentZLevels).push({
  27551. zlevel: zlevel,
  27552. z: z,
  27553. idx: componentModel.componentIndex,
  27554. type: componentType,
  27555. key: zlevelKey
  27556. });
  27557. });
  27558. if (hasSeparateZLevel) {
  27559. // Series after component
  27560. var zLevels = componentZLevels.concat(seriesZLevels);
  27561. var lastSeriesZLevel_1;
  27562. var lastSeriesKey_1;
  27563. sort(zLevels, function (a, b) {
  27564. if (a.zlevel === b.zlevel) {
  27565. return a.z - b.z;
  27566. }
  27567. return a.zlevel - b.zlevel;
  27568. });
  27569. each(zLevels, function (item) {
  27570. var componentModel = ecModel.getComponent(item.type, item.idx);
  27571. var zlevel = item.zlevel;
  27572. var key = item.key;
  27573. if (lastSeriesZLevel_1 != null) {
  27574. zlevel = Math.max(lastSeriesZLevel_1, zlevel);
  27575. }
  27576. if (key) {
  27577. if (zlevel === lastSeriesZLevel_1 && key !== lastSeriesKey_1) {
  27578. zlevel++;
  27579. }
  27580. lastSeriesKey_1 = key;
  27581. } else if (lastSeriesKey_1) {
  27582. if (zlevel === lastSeriesZLevel_1) {
  27583. zlevel++;
  27584. }
  27585. lastSeriesKey_1 = '';
  27586. }
  27587. lastSeriesZLevel_1 = zlevel;
  27588. componentModel.setZLevel(zlevel);
  27589. });
  27590. }
  27591. }
  27592. render = function (ecIns, ecModel, api, payload, updateParams) {
  27593. allocateZlevels(ecModel);
  27594. renderComponents(ecIns, ecModel, api, payload, updateParams);
  27595. each(ecIns._chartsViews, function (chart) {
  27596. chart.__alive = false;
  27597. });
  27598. renderSeries(ecIns, ecModel, api, payload, updateParams);
  27599. // Remove groups of unrendered charts
  27600. each(ecIns._chartsViews, function (chart) {
  27601. if (!chart.__alive) {
  27602. chart.remove(ecModel, api);
  27603. }
  27604. });
  27605. };
  27606. renderComponents = function (ecIns, ecModel, api, payload, updateParams, dirtyList) {
  27607. each(dirtyList || ecIns._componentsViews, function (componentView) {
  27608. var componentModel = componentView.__model;
  27609. clearStates(componentModel, componentView);
  27610. componentView.render(componentModel, ecModel, api, payload);
  27611. updateZ(componentModel, componentView);
  27612. updateStates(componentModel, componentView);
  27613. });
  27614. };
  27615. /**
  27616. * Render each chart and component
  27617. */
  27618. renderSeries = function (ecIns, ecModel, api, payload, updateParams, dirtyMap) {
  27619. // Render all charts
  27620. var scheduler = ecIns._scheduler;
  27621. updateParams = extend(updateParams || {}, {
  27622. updatedSeries: ecModel.getSeries()
  27623. });
  27624. // TODO progressive?
  27625. lifecycle.trigger('series:beforeupdate', ecModel, api, updateParams);
  27626. var unfinished = false;
  27627. ecModel.eachSeries(function (seriesModel) {
  27628. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  27629. chartView.__alive = true;
  27630. var renderTask = chartView.renderTask;
  27631. scheduler.updatePayload(renderTask, payload);
  27632. // TODO states on marker.
  27633. clearStates(seriesModel, chartView);
  27634. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  27635. renderTask.dirty();
  27636. }
  27637. if (renderTask.perform(scheduler.getPerformArgs(renderTask))) {
  27638. unfinished = true;
  27639. }
  27640. chartView.group.silent = !!seriesModel.get('silent');
  27641. // Should not call markRedraw on group, because it will disable zrender
  27642. // incremental render (always render from the __startIndex each frame)
  27643. // chartView.group.markRedraw();
  27644. updateBlend(seriesModel, chartView);
  27645. updateSeriesElementSelection(seriesModel);
  27646. });
  27647. scheduler.unfinished = unfinished || scheduler.unfinished;
  27648. lifecycle.trigger('series:layoutlabels', ecModel, api, updateParams);
  27649. // transition after label is layouted.
  27650. lifecycle.trigger('series:transition', ecModel, api, updateParams);
  27651. ecModel.eachSeries(function (seriesModel) {
  27652. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  27653. // Update Z after labels updated. Before applying states.
  27654. updateZ(seriesModel, chartView);
  27655. // NOTE: Update states after label is updated.
  27656. // label should be in normal status when layouting.
  27657. updateStates(seriesModel, chartView);
  27658. });
  27659. // If use hover layer
  27660. updateHoverLayerStatus(ecIns, ecModel);
  27661. lifecycle.trigger('series:afterupdate', ecModel, api, updateParams);
  27662. };
  27663. markStatusToUpdate = function (ecIns) {
  27664. ecIns[STATUS_NEEDS_UPDATE_KEY] = true;
  27665. // Wake up zrender if it's sleep. Let it update states in the next frame.
  27666. ecIns.getZr().wakeUp();
  27667. };
  27668. updateMainProcessVersion = function (ecIns) {
  27669. ecIns[MAIN_PROCESS_VERSION_KEY] = (ecIns[MAIN_PROCESS_VERSION_KEY] + 1) % 1000;
  27670. };
  27671. applyChangedStates = function (ecIns) {
  27672. if (!ecIns[STATUS_NEEDS_UPDATE_KEY]) {
  27673. return;
  27674. }
  27675. ecIns.getZr().storage.traverse(function (el) {
  27676. // Not applied on removed elements, it may still in fading.
  27677. if (isElementRemoved(el)) {
  27678. return;
  27679. }
  27680. applyElementStates(el);
  27681. });
  27682. ecIns[STATUS_NEEDS_UPDATE_KEY] = false;
  27683. };
  27684. function applyElementStates(el) {
  27685. var newStates = [];
  27686. var oldStates = el.currentStates;
  27687. // Keep other states.
  27688. for (var i = 0; i < oldStates.length; i++) {
  27689. var stateName = oldStates[i];
  27690. if (!(stateName === 'emphasis' || stateName === 'blur' || stateName === 'select')) {
  27691. newStates.push(stateName);
  27692. }
  27693. }
  27694. // Only use states when it's exists.
  27695. if (el.selected && el.states.select) {
  27696. newStates.push('select');
  27697. }
  27698. if (el.hoverState === HOVER_STATE_EMPHASIS && el.states.emphasis) {
  27699. newStates.push('emphasis');
  27700. } else if (el.hoverState === HOVER_STATE_BLUR && el.states.blur) {
  27701. newStates.push('blur');
  27702. }
  27703. el.useStates(newStates);
  27704. }
  27705. function updateHoverLayerStatus(ecIns, ecModel) {
  27706. var zr = ecIns._zr;
  27707. var storage = zr.storage;
  27708. var elCount = 0;
  27709. storage.traverse(function (el) {
  27710. if (!el.isGroup) {
  27711. elCount++;
  27712. }
  27713. });
  27714. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node && !env.worker) {
  27715. ecModel.eachSeries(function (seriesModel) {
  27716. if (seriesModel.preventUsingHoverLayer) {
  27717. return;
  27718. }
  27719. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  27720. if (chartView.__alive) {
  27721. chartView.eachRendered(function (el) {
  27722. if (el.states.emphasis) {
  27723. el.states.emphasis.hoverLayer = true;
  27724. }
  27725. });
  27726. }
  27727. });
  27728. }
  27729. }
  27730. /**
  27731. * Update chart and blend.
  27732. */
  27733. function updateBlend(seriesModel, chartView) {
  27734. var blendMode = seriesModel.get('blendMode') || null;
  27735. chartView.eachRendered(function (el) {
  27736. // FIXME marker and other components
  27737. if (!el.isGroup) {
  27738. // DON'T mark the element dirty. In case element is incremental and don't want to rerender.
  27739. el.style.blend = blendMode;
  27740. }
  27741. });
  27742. }
  27743. function updateZ(model, view) {
  27744. if (model.preventAutoZ) {
  27745. return;
  27746. }
  27747. var zInfo = retrieveZInfo(model);
  27748. // Set z and zlevel
  27749. view.eachRendered(function (el) {
  27750. traverseUpdateZ(el, zInfo.z, zInfo.zlevel);
  27751. // Don't traverse the children because it has been traversed in _updateZ.
  27752. return true;
  27753. });
  27754. }
  27755. // Clear states without animation.
  27756. // TODO States on component.
  27757. function clearStates(model, view) {
  27758. view.eachRendered(function (el) {
  27759. // Not applied on removed elements, it may still in fading.
  27760. if (isElementRemoved(el)) {
  27761. return;
  27762. }
  27763. var textContent = el.getTextContent();
  27764. var textGuide = el.getTextGuideLine();
  27765. if (el.stateTransition) {
  27766. el.stateTransition = null;
  27767. }
  27768. if (textContent && textContent.stateTransition) {
  27769. textContent.stateTransition = null;
  27770. }
  27771. if (textGuide && textGuide.stateTransition) {
  27772. textGuide.stateTransition = null;
  27773. }
  27774. // TODO If el is incremental.
  27775. if (el.hasState()) {
  27776. el.prevStates = el.currentStates;
  27777. el.clearStates();
  27778. } else if (el.prevStates) {
  27779. el.prevStates = null;
  27780. }
  27781. });
  27782. }
  27783. function updateStates(model, view) {
  27784. var stateAnimationModel = model.getModel('stateAnimation');
  27785. var enableAnimation = model.isAnimationEnabled();
  27786. var duration = stateAnimationModel.get('duration');
  27787. var stateTransition = duration > 0 ? {
  27788. duration: duration,
  27789. delay: stateAnimationModel.get('delay'),
  27790. easing: stateAnimationModel.get('easing')
  27791. // additive: stateAnimationModel.get('additive')
  27792. } : null;
  27793. view.eachRendered(function (el) {
  27794. if (el.states && el.states.emphasis) {
  27795. // Not applied on removed elements, it may still in fading.
  27796. if (isElementRemoved(el)) {
  27797. return;
  27798. }
  27799. if (el instanceof Path) {
  27800. savePathStates(el);
  27801. }
  27802. // Only updated on changed element. In case element is incremental and don't want to rerender.
  27803. // TODO, a more proper way?
  27804. if (el.__dirty) {
  27805. var prevStates = el.prevStates;
  27806. // Restore states without animation
  27807. if (prevStates) {
  27808. el.useStates(prevStates);
  27809. }
  27810. }
  27811. // Update state transition and enable animation again.
  27812. if (enableAnimation) {
  27813. el.stateTransition = stateTransition;
  27814. var textContent = el.getTextContent();
  27815. var textGuide = el.getTextGuideLine();
  27816. // TODO Is it necessary to animate label?
  27817. if (textContent) {
  27818. textContent.stateTransition = stateTransition;
  27819. }
  27820. if (textGuide) {
  27821. textGuide.stateTransition = stateTransition;
  27822. }
  27823. }
  27824. // Use highlighted and selected flag to toggle states.
  27825. if (el.__dirty) {
  27826. applyElementStates(el);
  27827. }
  27828. }
  27829. });
  27830. }
  27831. createExtensionAPI = function (ecIns) {
  27832. return new (/** @class */function (_super) {
  27833. __extends(class_1, _super);
  27834. function class_1() {
  27835. return _super !== null && _super.apply(this, arguments) || this;
  27836. }
  27837. class_1.prototype.getCoordinateSystems = function () {
  27838. return ecIns._coordSysMgr.getCoordinateSystems();
  27839. };
  27840. class_1.prototype.getComponentByElement = function (el) {
  27841. while (el) {
  27842. var modelInfo = el.__ecComponentInfo;
  27843. if (modelInfo != null) {
  27844. return ecIns._model.getComponent(modelInfo.mainType, modelInfo.index);
  27845. }
  27846. el = el.parent;
  27847. }
  27848. };
  27849. class_1.prototype.enterEmphasis = function (el, highlightDigit) {
  27850. enterEmphasis(el, highlightDigit);
  27851. markStatusToUpdate(ecIns);
  27852. };
  27853. class_1.prototype.leaveEmphasis = function (el, highlightDigit) {
  27854. leaveEmphasis(el, highlightDigit);
  27855. markStatusToUpdate(ecIns);
  27856. };
  27857. class_1.prototype.enterBlur = function (el) {
  27858. enterBlur(el);
  27859. markStatusToUpdate(ecIns);
  27860. };
  27861. class_1.prototype.leaveBlur = function (el) {
  27862. leaveBlur(el);
  27863. markStatusToUpdate(ecIns);
  27864. };
  27865. class_1.prototype.enterSelect = function (el) {
  27866. enterSelect(el);
  27867. markStatusToUpdate(ecIns);
  27868. };
  27869. class_1.prototype.leaveSelect = function (el) {
  27870. leaveSelect(el);
  27871. markStatusToUpdate(ecIns);
  27872. };
  27873. class_1.prototype.getModel = function () {
  27874. return ecIns.getModel();
  27875. };
  27876. class_1.prototype.getViewOfComponentModel = function (componentModel) {
  27877. return ecIns.getViewOfComponentModel(componentModel);
  27878. };
  27879. class_1.prototype.getViewOfSeriesModel = function (seriesModel) {
  27880. return ecIns.getViewOfSeriesModel(seriesModel);
  27881. };
  27882. class_1.prototype.getMainProcessVersion = function () {
  27883. return ecIns[MAIN_PROCESS_VERSION_KEY];
  27884. };
  27885. return class_1;
  27886. }(ExtensionAPI))(ecIns);
  27887. };
  27888. enableConnect = function (chart) {
  27889. function updateConnectedChartsStatus(charts, status) {
  27890. for (var i = 0; i < charts.length; i++) {
  27891. var otherChart = charts[i];
  27892. otherChart[CONNECT_STATUS_KEY] = status;
  27893. }
  27894. }
  27895. each(connectionEventRevertMap, function (_, eventType) {
  27896. chart._messageCenter.on(eventType, function (event) {
  27897. if (connectedGroups[chart.group] && chart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_PENDING) {
  27898. if (event && event.escapeConnect) {
  27899. return;
  27900. }
  27901. var action_1 = chart.makeActionFromEvent(event);
  27902. var otherCharts_1 = [];
  27903. each(instances$1, function (otherChart) {
  27904. if (otherChart !== chart && otherChart.group === chart.group) {
  27905. otherCharts_1.push(otherChart);
  27906. }
  27907. });
  27908. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_PENDING);
  27909. each(otherCharts_1, function (otherChart) {
  27910. if (otherChart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_UPDATING) {
  27911. otherChart.dispatchAction(action_1);
  27912. }
  27913. });
  27914. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_UPDATED);
  27915. }
  27916. });
  27917. });
  27918. };
  27919. }();
  27920. return ECharts;
  27921. }(Eventful);
  27922. var echartsProto = ECharts.prototype;
  27923. echartsProto.on = createRegisterEventWithLowercaseECharts('on');
  27924. echartsProto.off = createRegisterEventWithLowercaseECharts('off');
  27925. /**
  27926. * @deprecated
  27927. */
  27928. // @ts-ignore
  27929. echartsProto.one = function (eventName, cb, ctx) {
  27930. var self = this;
  27931. deprecateLog('ECharts#one is deprecated.');
  27932. function wrapped() {
  27933. var args2 = [];
  27934. for (var _i = 0; _i < arguments.length; _i++) {
  27935. args2[_i] = arguments[_i];
  27936. }
  27937. cb && cb.apply && cb.apply(this, args2);
  27938. // @ts-ignore
  27939. self.off(eventName, wrapped);
  27940. }
  27941. // @ts-ignore
  27942. this.on.call(this, eventName, wrapped, ctx);
  27943. };
  27944. var MOUSE_EVENT_NAMES = ['click', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'globalout', 'contextmenu'];
  27945. function disposedWarning(id) {
  27946. if ("development" !== 'production') {
  27947. warn('Instance ' + id + ' has been disposed');
  27948. }
  27949. }
  27950. var actions = {};
  27951. /**
  27952. * Map event type to action type for reproducing action from event for `connect`.
  27953. */
  27954. var connectionEventRevertMap = {};
  27955. /**
  27956. * To remove duplication.
  27957. */
  27958. var publicEventTypeMap = {};
  27959. var dataProcessorFuncs = [];
  27960. var optionPreprocessorFuncs = [];
  27961. var visualFuncs = [];
  27962. var themeStorage = {};
  27963. var loadingEffects = {};
  27964. var instances$1 = {};
  27965. var connectedGroups = {};
  27966. var idBase = +new Date() - 0;
  27967. var groupIdBase = +new Date() - 0;
  27968. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  27969. /**
  27970. * @param opts.devicePixelRatio Use window.devicePixelRatio by default
  27971. * @param opts.renderer Can choose 'canvas' or 'svg' to render the chart.
  27972. * @param opts.width Use clientWidth of the input `dom` by default.
  27973. * Can be 'auto' (the same as null/undefined)
  27974. * @param opts.height Use clientHeight of the input `dom` by default.
  27975. * Can be 'auto' (the same as null/undefined)
  27976. * @param opts.locale Specify the locale.
  27977. * @param opts.useDirtyRect Enable dirty rectangle rendering or not.
  27978. */
  27979. function init$1(dom, theme, opts) {
  27980. var isClient = !(opts && opts.ssr);
  27981. if (isClient) {
  27982. if ("development" !== 'production') {
  27983. if (!dom) {
  27984. throw new Error('Initialize failed: invalid dom.');
  27985. }
  27986. }
  27987. var existInstance = getInstanceByDom(dom);
  27988. if (existInstance) {
  27989. if ("development" !== 'production') {
  27990. warn('There is a chart instance already initialized on the dom.');
  27991. }
  27992. return existInstance;
  27993. }
  27994. if ("development" !== 'production') {
  27995. if (isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth && (!opts || opts.width == null) || !dom.clientHeight && (!opts || opts.height == null))) {
  27996. warn('Can\'t get DOM width or height. Please check ' + 'dom.clientWidth and dom.clientHeight. They should not be 0.' + 'For example, you may need to call this in the callback ' + 'of window.onload.');
  27997. }
  27998. }
  27999. }
  28000. var chart = new ECharts(dom, theme, opts);
  28001. chart.id = 'ec_' + idBase++;
  28002. instances$1[chart.id] = chart;
  28003. isClient && setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  28004. enableConnect(chart);
  28005. lifecycle.trigger('afterinit', chart);
  28006. return chart;
  28007. }
  28008. /**
  28009. * @usage
  28010. * (A)
  28011. * ```js
  28012. * let chart1 = echarts.init(dom1);
  28013. * let chart2 = echarts.init(dom2);
  28014. * chart1.group = 'xxx';
  28015. * chart2.group = 'xxx';
  28016. * echarts.connect('xxx');
  28017. * ```
  28018. * (B)
  28019. * ```js
  28020. * let chart1 = echarts.init(dom1);
  28021. * let chart2 = echarts.init(dom2);
  28022. * echarts.connect('xxx', [chart1, chart2]);
  28023. * ```
  28024. */
  28025. function connect(groupId) {
  28026. // Is array of charts
  28027. if (isArray(groupId)) {
  28028. var charts = groupId;
  28029. groupId = null;
  28030. // If any chart has group
  28031. each(charts, function (chart) {
  28032. if (chart.group != null) {
  28033. groupId = chart.group;
  28034. }
  28035. });
  28036. groupId = groupId || 'g_' + groupIdBase++;
  28037. each(charts, function (chart) {
  28038. chart.group = groupId;
  28039. });
  28040. }
  28041. connectedGroups[groupId] = true;
  28042. return groupId;
  28043. }
  28044. function disconnect(groupId) {
  28045. connectedGroups[groupId] = false;
  28046. }
  28047. /**
  28048. * Alias and backward compatibility
  28049. * @deprecated
  28050. */
  28051. var disConnect = disconnect;
  28052. /**
  28053. * Dispose a chart instance
  28054. */
  28055. function dispose$1(chart) {
  28056. if (isString(chart)) {
  28057. chart = instances$1[chart];
  28058. } else if (!(chart instanceof ECharts)) {
  28059. // Try to treat as dom
  28060. chart = getInstanceByDom(chart);
  28061. }
  28062. if (chart instanceof ECharts && !chart.isDisposed()) {
  28063. chart.dispose();
  28064. }
  28065. }
  28066. function getInstanceByDom(dom) {
  28067. return instances$1[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  28068. }
  28069. function getInstanceById(key) {
  28070. return instances$1[key];
  28071. }
  28072. /**
  28073. * Register theme
  28074. */
  28075. function registerTheme(name, theme) {
  28076. themeStorage[name] = theme;
  28077. }
  28078. /**
  28079. * Register option preprocessor
  28080. */
  28081. function registerPreprocessor(preprocessorFunc) {
  28082. if (indexOf(optionPreprocessorFuncs, preprocessorFunc) < 0) {
  28083. optionPreprocessorFuncs.push(preprocessorFunc);
  28084. }
  28085. }
  28086. function registerProcessor(priority, processor) {
  28087. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_DEFAULT);
  28088. }
  28089. /**
  28090. * Register postIniter
  28091. * @param {Function} postInitFunc
  28092. */
  28093. function registerPostInit(postInitFunc) {
  28094. registerUpdateLifecycle('afterinit', postInitFunc);
  28095. }
  28096. /**
  28097. * Register postUpdater
  28098. * @param {Function} postUpdateFunc
  28099. */
  28100. function registerPostUpdate(postUpdateFunc) {
  28101. registerUpdateLifecycle('afterupdate', postUpdateFunc);
  28102. }
  28103. function registerUpdateLifecycle(name, cb) {
  28104. lifecycle.on(name, cb);
  28105. }
  28106. function registerAction(arg0, arg1, action) {
  28107. var actionType;
  28108. var publicEventType;
  28109. var refineEvent;
  28110. var update;
  28111. var publishNonRefinedEvent;
  28112. if (isFunction(arg1)) {
  28113. action = arg1;
  28114. arg1 = '';
  28115. }
  28116. if (isObject(arg0)) {
  28117. actionType = arg0.type;
  28118. publicEventType = arg0.event;
  28119. update = arg0.update;
  28120. publishNonRefinedEvent = arg0.publishNonRefinedEvent;
  28121. if (!action) {
  28122. action = arg0.action;
  28123. }
  28124. refineEvent = arg0.refineEvent;
  28125. } else {
  28126. actionType = arg0;
  28127. publicEventType = arg1;
  28128. }
  28129. function createEventType(actionOrEventType) {
  28130. // Event type should be all lowercase
  28131. return actionOrEventType.toLowerCase();
  28132. }
  28133. publicEventType = createEventType(publicEventType || actionType);
  28134. // See comments on {ActionInfo} for the reason.
  28135. var nonRefinedEventType = refineEvent ? createEventType(actionType) : publicEventType;
  28136. // Support calling `registerAction` multiple times with the same action
  28137. // type; subsequent calls have no effect.
  28138. if (actions[actionType]) {
  28139. return;
  28140. }
  28141. // Validate action type and event name.
  28142. assert(ACTION_REG.test(actionType) && ACTION_REG.test(publicEventType));
  28143. if (refineEvent) {
  28144. // An event replicated from the action will be triggered internally for `connect` in this case.
  28145. assert(publicEventType !== actionType);
  28146. }
  28147. actions[actionType] = {
  28148. actionType: actionType,
  28149. refinedEventType: publicEventType,
  28150. nonRefinedEventType: nonRefinedEventType,
  28151. update: update,
  28152. action: action,
  28153. refineEvent: refineEvent
  28154. };
  28155. publicEventTypeMap[publicEventType] = 1;
  28156. if (refineEvent && publishNonRefinedEvent) {
  28157. publicEventTypeMap[nonRefinedEventType] = 1;
  28158. }
  28159. if ("development" !== 'production' && connectionEventRevertMap[nonRefinedEventType]) {
  28160. error(nonRefinedEventType + " must not be shared; use \"refineEvent\" if you intend to share an event name.");
  28161. }
  28162. connectionEventRevertMap[nonRefinedEventType] = actionType;
  28163. }
  28164. function registerCoordinateSystem(type, coordSysCreator) {
  28165. CoordinateSystemManager.register(type, coordSysCreator);
  28166. }
  28167. /**
  28168. * Get dimensions of specified coordinate system.
  28169. * @param {string} type
  28170. * @return {Array.<string|Object>}
  28171. */
  28172. function getCoordinateSystemDimensions(type) {
  28173. var coordSysCreator = CoordinateSystemManager.get(type);
  28174. if (coordSysCreator) {
  28175. return coordSysCreator.getDimensionsInfo ? coordSysCreator.getDimensionsInfo() : coordSysCreator.dimensions.slice();
  28176. }
  28177. }
  28178. function registerCustomSeries(seriesType, renderItem) {
  28179. }
  28180. function registerLayout(priority, layoutTask) {
  28181. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  28182. }
  28183. function registerVisual(priority, visualTask) {
  28184. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  28185. }
  28186. var registeredTasks = [];
  28187. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  28188. if (isFunction(priority) || isObject(priority)) {
  28189. fn = priority;
  28190. priority = defaultPriority;
  28191. }
  28192. if ("development" !== 'production') {
  28193. if (isNaN(priority) || priority == null) {
  28194. throw new Error('Illegal priority');
  28195. }
  28196. // Check duplicate
  28197. each(targetList, function (wrap) {
  28198. assert(wrap.__raw !== fn);
  28199. });
  28200. }
  28201. // Already registered
  28202. if (indexOf(registeredTasks, fn) >= 0) {
  28203. return;
  28204. }
  28205. registeredTasks.push(fn);
  28206. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  28207. stageHandler.__prio = priority;
  28208. stageHandler.__raw = fn;
  28209. targetList.push(stageHandler);
  28210. }
  28211. function registerLoading(name, loadingFx) {
  28212. loadingEffects[name] = loadingFx;
  28213. }
  28214. /**
  28215. * ZRender need a canvas context to do measureText.
  28216. * But in node environment canvas may be created by node-canvas.
  28217. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  28218. *
  28219. *
  28220. * @deprecated use setPlatformAPI({ createCanvas }) instead.
  28221. *
  28222. * @example
  28223. * let Canvas = require('canvas');
  28224. * let echarts = require('echarts');
  28225. * echarts.setCanvasCreator(function () {
  28226. * // Small size is enough.
  28227. * return new Canvas(32, 32);
  28228. * });
  28229. */
  28230. function setCanvasCreator(creator) {
  28231. if ("development" !== 'production') {
  28232. deprecateLog('setCanvasCreator is deprecated. Use setPlatformAPI({ createCanvas }) instead.');
  28233. }
  28234. setPlatformAPI({
  28235. createCanvas: creator
  28236. });
  28237. }
  28238. /**
  28239. * The parameters and usage: see `geoSourceManager.registerMap`.
  28240. * Compatible with previous `echarts.registerMap`.
  28241. */
  28242. function registerMap(mapName, geoJson, specialAreas) {
  28243. var registerMap = getImpl('registerMap');
  28244. registerMap && registerMap(mapName, geoJson, specialAreas);
  28245. }
  28246. function getMap(mapName) {
  28247. var getMap = getImpl('getMap');
  28248. return getMap && getMap(mapName);
  28249. }
  28250. var registerTransform = registerExternalTransform;
  28251. /**
  28252. * Globa dispatchAction to a specified chart instance.
  28253. */
  28254. // export function dispatchAction(payload: { chartId: string } & Payload, opt?: Parameters<ECharts['dispatchAction']>[1]) {
  28255. // if (!payload || !payload.chartId) {
  28256. // // Must have chartId to find chart
  28257. // return;
  28258. // }
  28259. // const chart = instances[payload.chartId];
  28260. // if (chart) {
  28261. // chart.dispatchAction(payload, opt);
  28262. // }
  28263. // }
  28264. // Builtin global visual
  28265. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesStyleTask);
  28266. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataStyleTask);
  28267. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataColorPaletteTask);
  28268. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesSymbolTask);
  28269. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataSymbolTask);
  28270. registerVisual(PRIORITY_VISUAL_DECAL, decalVisual);
  28271. registerPreprocessor(globalBackwardCompat);
  28272. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  28273. registerLoading('default', defaultLoading);
  28274. // Default actions
  28275. registerAction({
  28276. type: HIGHLIGHT_ACTION_TYPE,
  28277. event: HIGHLIGHT_ACTION_TYPE,
  28278. update: HIGHLIGHT_ACTION_TYPE
  28279. }, noop);
  28280. registerAction({
  28281. type: DOWNPLAY_ACTION_TYPE,
  28282. event: DOWNPLAY_ACTION_TYPE,
  28283. update: DOWNPLAY_ACTION_TYPE
  28284. }, noop);
  28285. registerAction({
  28286. type: SELECT_ACTION_TYPE,
  28287. event: SELECT_CHANGED_EVENT_TYPE,
  28288. update: SELECT_ACTION_TYPE,
  28289. action: noop,
  28290. refineEvent: makeSelectChangedEvent,
  28291. publishNonRefinedEvent: true
  28292. });
  28293. registerAction({
  28294. type: UNSELECT_ACTION_TYPE,
  28295. event: SELECT_CHANGED_EVENT_TYPE,
  28296. update: UNSELECT_ACTION_TYPE,
  28297. action: noop,
  28298. refineEvent: makeSelectChangedEvent,
  28299. publishNonRefinedEvent: true
  28300. });
  28301. registerAction({
  28302. type: TOGGLE_SELECT_ACTION_TYPE,
  28303. event: SELECT_CHANGED_EVENT_TYPE,
  28304. update: TOGGLE_SELECT_ACTION_TYPE,
  28305. action: noop,
  28306. refineEvent: makeSelectChangedEvent,
  28307. publishNonRefinedEvent: true
  28308. });
  28309. function makeSelectChangedEvent(actionResultBatch, payload, ecModel, api) {
  28310. return {
  28311. eventContent: {
  28312. selected: getAllSelectedIndices(ecModel),
  28313. isFromClick: payload.isFromClick || false
  28314. }
  28315. };
  28316. }
  28317. // Default theme, so that we can use `chart.setTheme('default')` to revert to
  28318. // the default theme after changing to other themes.
  28319. registerTheme('default', {});
  28320. registerTheme('dark', theme);
  28321. // For backward compatibility, where the namespace `dataTool` will
  28322. // be mounted on `echarts` is the extension `dataTool` is imported.
  28323. var dataTool = {};
  28324. var extensions = [];
  28325. var extensionRegisters = {
  28326. registerPreprocessor: registerPreprocessor,
  28327. registerProcessor: registerProcessor,
  28328. registerPostInit: registerPostInit,
  28329. registerPostUpdate: registerPostUpdate,
  28330. registerUpdateLifecycle: registerUpdateLifecycle,
  28331. registerAction: registerAction,
  28332. registerCoordinateSystem: registerCoordinateSystem,
  28333. registerLayout: registerLayout,
  28334. registerVisual: registerVisual,
  28335. registerTransform: registerTransform,
  28336. registerLoading: registerLoading,
  28337. registerMap: registerMap,
  28338. registerImpl: registerImpl,
  28339. PRIORITY: PRIORITY,
  28340. ComponentModel: ComponentModel,
  28341. ComponentView: ComponentView,
  28342. SeriesModel: SeriesModel,
  28343. ChartView: ChartView,
  28344. // TODO Use ComponentModel and SeriesModel instead of Constructor
  28345. registerComponentModel: function (ComponentModelClass) {
  28346. ComponentModel.registerClass(ComponentModelClass);
  28347. },
  28348. registerComponentView: function (ComponentViewClass) {
  28349. ComponentView.registerClass(ComponentViewClass);
  28350. },
  28351. registerSeriesModel: function (SeriesModelClass) {
  28352. SeriesModel.registerClass(SeriesModelClass);
  28353. },
  28354. registerChartView: function (ChartViewClass) {
  28355. ChartView.registerClass(ChartViewClass);
  28356. },
  28357. registerCustomSeries: function (seriesType, renderItem) {
  28358. },
  28359. registerSubTypeDefaulter: function (componentType, defaulter) {
  28360. ComponentModel.registerSubTypeDefaulter(componentType, defaulter);
  28361. },
  28362. registerPainter: function (painterType, PainterCtor) {
  28363. registerPainter(painterType, PainterCtor);
  28364. }
  28365. };
  28366. function use(ext) {
  28367. if (isArray(ext)) {
  28368. // use([ChartLine, ChartBar]);
  28369. each(ext, function (singleExt) {
  28370. use(singleExt);
  28371. });
  28372. return;
  28373. }
  28374. if (indexOf(extensions, ext) >= 0) {
  28375. return;
  28376. }
  28377. extensions.push(ext);
  28378. if (isFunction(ext)) {
  28379. ext = {
  28380. install: ext
  28381. };
  28382. }
  28383. ext.install(extensionRegisters);
  28384. }
  28385. /*
  28386. * Licensed to the Apache Software Foundation (ASF) under one
  28387. * or more contributor license agreements. See the NOTICE file
  28388. * distributed with this work for additional information
  28389. * regarding copyright ownership. The ASF licenses this file
  28390. * to you under the Apache License, Version 2.0 (the
  28391. * "License"); you may not use this file except in compliance
  28392. * with the License. You may obtain a copy of the License at
  28393. *
  28394. * http://www.apache.org/licenses/LICENSE-2.0
  28395. *
  28396. * Unless required by applicable law or agreed to in writing,
  28397. * software distributed under the License is distributed on an
  28398. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28399. * KIND, either express or implied. See the License for the
  28400. * specific language governing permissions and limitations
  28401. * under the License.
  28402. */
  28403. /**
  28404. * AUTO-GENERATED FILE. DO NOT MODIFY.
  28405. */
  28406. /*
  28407. * Licensed to the Apache Software Foundation (ASF) under one
  28408. * or more contributor license agreements. See the NOTICE file
  28409. * distributed with this work for additional information
  28410. * regarding copyright ownership. The ASF licenses this file
  28411. * to you under the Apache License, Version 2.0 (the
  28412. * "License"); you may not use this file except in compliance
  28413. * with the License. You may obtain a copy of the License at
  28414. *
  28415. * http://www.apache.org/licenses/LICENSE-2.0
  28416. *
  28417. * Unless required by applicable law or agreed to in writing,
  28418. * software distributed under the License is distributed on an
  28419. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28420. * KIND, either express or implied. See the License for the
  28421. * specific language governing permissions and limitations
  28422. * under the License.
  28423. */
  28424. function dataIndexMapValueLength(valNumOrArrLengthMoreThan2) {
  28425. return valNumOrArrLengthMoreThan2 == null ? 0 : valNumOrArrLengthMoreThan2.length || 1;
  28426. }
  28427. function defaultKeyGetter(item) {
  28428. return item;
  28429. }
  28430. var DataDiffer = /** @class */function () {
  28431. /**
  28432. * @param context Can be visited by this.context in callback.
  28433. */
  28434. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context,
  28435. // By default: 'oneToOne'.
  28436. diffMode) {
  28437. this._old = oldArr;
  28438. this._new = newArr;
  28439. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  28440. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  28441. // Visible in callback via `this.context`;
  28442. this.context = context;
  28443. this._diffModeMultiple = diffMode === 'multiple';
  28444. }
  28445. /**
  28446. * Callback function when add a data
  28447. */
  28448. DataDiffer.prototype.add = function (func) {
  28449. this._add = func;
  28450. return this;
  28451. };
  28452. /**
  28453. * Callback function when update a data
  28454. */
  28455. DataDiffer.prototype.update = function (func) {
  28456. this._update = func;
  28457. return this;
  28458. };
  28459. /**
  28460. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28461. */
  28462. DataDiffer.prototype.updateManyToOne = function (func) {
  28463. this._updateManyToOne = func;
  28464. return this;
  28465. };
  28466. /**
  28467. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28468. */
  28469. DataDiffer.prototype.updateOneToMany = function (func) {
  28470. this._updateOneToMany = func;
  28471. return this;
  28472. };
  28473. /**
  28474. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28475. */
  28476. DataDiffer.prototype.updateManyToMany = function (func) {
  28477. this._updateManyToMany = func;
  28478. return this;
  28479. };
  28480. /**
  28481. * Callback function when remove a data
  28482. */
  28483. DataDiffer.prototype.remove = function (func) {
  28484. this._remove = func;
  28485. return this;
  28486. };
  28487. DataDiffer.prototype.execute = function () {
  28488. this[this._diffModeMultiple ? '_executeMultiple' : '_executeOneToOne']();
  28489. };
  28490. DataDiffer.prototype._executeOneToOne = function () {
  28491. var oldArr = this._old;
  28492. var newArr = this._new;
  28493. var newDataIndexMap = {};
  28494. var oldDataKeyArr = new Array(oldArr.length);
  28495. var newDataKeyArr = new Array(newArr.length);
  28496. this._initIndexMap(oldArr, null, oldDataKeyArr, '_oldKeyGetter');
  28497. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  28498. for (var i = 0; i < oldArr.length; i++) {
  28499. var oldKey = oldDataKeyArr[i];
  28500. var newIdxMapVal = newDataIndexMap[oldKey];
  28501. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  28502. // idx can never be empty array here. see 'set null' logic below.
  28503. if (newIdxMapValLen > 1) {
  28504. // Consider there is duplicate key (for example, use dataItem.name as key).
  28505. // We should make sure every item in newArr and oldArr can be visited.
  28506. var newIdx = newIdxMapVal.shift();
  28507. if (newIdxMapVal.length === 1) {
  28508. newDataIndexMap[oldKey] = newIdxMapVal[0];
  28509. }
  28510. this._update && this._update(newIdx, i);
  28511. } else if (newIdxMapValLen === 1) {
  28512. newDataIndexMap[oldKey] = null;
  28513. this._update && this._update(newIdxMapVal, i);
  28514. } else {
  28515. this._remove && this._remove(i);
  28516. }
  28517. }
  28518. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  28519. };
  28520. /**
  28521. * For example, consider the case:
  28522. * oldData: [o0, o1, o2, o3, o4, o5, o6, o7],
  28523. * newData: [n0, n1, n2, n3, n4, n5, n6, n7, n8],
  28524. * Where:
  28525. * o0, o1, n0 has key 'a' (many to one)
  28526. * o5, n4, n5, n6 has key 'b' (one to many)
  28527. * o2, n1 has key 'c' (one to one)
  28528. * n2, n3 has key 'd' (add)
  28529. * o3, o4 has key 'e' (remove)
  28530. * o6, o7, n7, n8 has key 'f' (many to many, treated as add and remove)
  28531. * Then:
  28532. * (The order of the following directives are not ensured.)
  28533. * this._updateManyToOne(n0, [o0, o1]);
  28534. * this._updateOneToMany([n4, n5, n6], o5);
  28535. * this._update(n1, o2);
  28536. * this._remove(o3);
  28537. * this._remove(o4);
  28538. * this._remove(o6);
  28539. * this._remove(o7);
  28540. * this._add(n2);
  28541. * this._add(n3);
  28542. * this._add(n7);
  28543. * this._add(n8);
  28544. */
  28545. DataDiffer.prototype._executeMultiple = function () {
  28546. var oldArr = this._old;
  28547. var newArr = this._new;
  28548. var oldDataIndexMap = {};
  28549. var newDataIndexMap = {};
  28550. var oldDataKeyArr = [];
  28551. var newDataKeyArr = [];
  28552. this._initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter');
  28553. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  28554. for (var i = 0; i < oldDataKeyArr.length; i++) {
  28555. var oldKey = oldDataKeyArr[i];
  28556. var oldIdxMapVal = oldDataIndexMap[oldKey];
  28557. var newIdxMapVal = newDataIndexMap[oldKey];
  28558. var oldIdxMapValLen = dataIndexMapValueLength(oldIdxMapVal);
  28559. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  28560. if (oldIdxMapValLen > 1 && newIdxMapValLen === 1) {
  28561. this._updateManyToOne && this._updateManyToOne(newIdxMapVal, oldIdxMapVal);
  28562. newDataIndexMap[oldKey] = null;
  28563. } else if (oldIdxMapValLen === 1 && newIdxMapValLen > 1) {
  28564. this._updateOneToMany && this._updateOneToMany(newIdxMapVal, oldIdxMapVal);
  28565. newDataIndexMap[oldKey] = null;
  28566. } else if (oldIdxMapValLen === 1 && newIdxMapValLen === 1) {
  28567. this._update && this._update(newIdxMapVal, oldIdxMapVal);
  28568. newDataIndexMap[oldKey] = null;
  28569. } else if (oldIdxMapValLen > 1 && newIdxMapValLen > 1) {
  28570. this._updateManyToMany && this._updateManyToMany(newIdxMapVal, oldIdxMapVal);
  28571. newDataIndexMap[oldKey] = null;
  28572. } else if (oldIdxMapValLen > 1) {
  28573. for (var i_1 = 0; i_1 < oldIdxMapValLen; i_1++) {
  28574. this._remove && this._remove(oldIdxMapVal[i_1]);
  28575. }
  28576. } else {
  28577. this._remove && this._remove(oldIdxMapVal);
  28578. }
  28579. }
  28580. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  28581. };
  28582. DataDiffer.prototype._performRestAdd = function (newDataKeyArr, newDataIndexMap) {
  28583. for (var i = 0; i < newDataKeyArr.length; i++) {
  28584. var newKey = newDataKeyArr[i];
  28585. var newIdxMapVal = newDataIndexMap[newKey];
  28586. var idxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  28587. if (idxMapValLen > 1) {
  28588. for (var j = 0; j < idxMapValLen; j++) {
  28589. this._add && this._add(newIdxMapVal[j]);
  28590. }
  28591. } else if (idxMapValLen === 1) {
  28592. this._add && this._add(newIdxMapVal);
  28593. }
  28594. // Support both `newDataKeyArr` are duplication removed or not removed.
  28595. newDataIndexMap[newKey] = null;
  28596. }
  28597. };
  28598. DataDiffer.prototype._initIndexMap = function (arr,
  28599. // Can be null.
  28600. map,
  28601. // In 'byKey', the output `keyArr` is duplication removed.
  28602. // In 'byIndex', the output `keyArr` is not duplication removed and
  28603. // its indices are accurately corresponding to `arr`.
  28604. keyArr, keyGetterName) {
  28605. var cbModeMultiple = this._diffModeMultiple;
  28606. for (var i = 0; i < arr.length; i++) {
  28607. // Add prefix to avoid conflict with Object.prototype.
  28608. var key = '_ec_' + this[keyGetterName](arr[i], i);
  28609. if (!cbModeMultiple) {
  28610. keyArr[i] = key;
  28611. }
  28612. if (!map) {
  28613. continue;
  28614. }
  28615. var idxMapVal = map[key];
  28616. var idxMapValLen = dataIndexMapValueLength(idxMapVal);
  28617. if (idxMapValLen === 0) {
  28618. // Simple optimize: in most cases, one index has one key,
  28619. // do not need array.
  28620. map[key] = i;
  28621. if (cbModeMultiple) {
  28622. keyArr.push(key);
  28623. }
  28624. } else if (idxMapValLen === 1) {
  28625. map[key] = [idxMapVal, i];
  28626. } else {
  28627. idxMapVal.push(i);
  28628. }
  28629. }
  28630. };
  28631. return DataDiffer;
  28632. }();
  28633. var DimensionUserOuput = /** @class */function () {
  28634. function DimensionUserOuput(encode, dimRequest) {
  28635. this._encode = encode;
  28636. this._schema = dimRequest;
  28637. }
  28638. DimensionUserOuput.prototype.get = function () {
  28639. return {
  28640. // Do not generate full dimension name until fist used.
  28641. fullDimensions: this._getFullDimensionNames(),
  28642. encode: this._encode
  28643. };
  28644. };
  28645. /**
  28646. * Get all data store dimension names.
  28647. * Theoretically a series data store is defined both by series and used dataset (if any).
  28648. * If some dimensions are omitted for performance reason in `this.dimensions`,
  28649. * the dimension name may not be auto-generated if user does not specify a dimension name.
  28650. * In this case, the dimension name is `null`/`undefined`.
  28651. */
  28652. DimensionUserOuput.prototype._getFullDimensionNames = function () {
  28653. if (!this._cachedDimNames) {
  28654. this._cachedDimNames = this._schema ? this._schema.makeOutputDimensionNames() : [];
  28655. }
  28656. return this._cachedDimNames;
  28657. };
  28658. return DimensionUserOuput;
  28659. }();
  28660. function summarizeDimensions(data, schema) {
  28661. var summary = {};
  28662. var encode = summary.encode = {};
  28663. var notExtraCoordDimMap = createHashMap();
  28664. var defaultedLabel = [];
  28665. var defaultedTooltip = [];
  28666. var userOutputEncode = {};
  28667. each(data.dimensions, function (dimName) {
  28668. var dimItem = data.getDimensionInfo(dimName);
  28669. var coordDim = dimItem.coordDim;
  28670. if (coordDim) {
  28671. if ("development" !== 'production') {
  28672. assert(VISUAL_DIMENSIONS.get(coordDim) == null);
  28673. }
  28674. var coordDimIndex = dimItem.coordDimIndex;
  28675. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  28676. if (!dimItem.isExtraCoord) {
  28677. notExtraCoordDimMap.set(coordDim, 1);
  28678. // Use the last coord dim (and label friendly) as default label,
  28679. // because when dataset is used, it is hard to guess which dimension
  28680. // can be value dimension. If both show x, y on label is not look good,
  28681. // and conventionally y axis is focused more.
  28682. if (mayLabelDimType(dimItem.type)) {
  28683. defaultedLabel[0] = dimName;
  28684. }
  28685. // User output encode do not contain generated coords.
  28686. // And it only has index. User can use index to retrieve value from the raw item array.
  28687. getOrCreateEncodeArr(userOutputEncode, coordDim)[coordDimIndex] = data.getDimensionIndex(dimItem.name);
  28688. }
  28689. if (dimItem.defaultTooltip) {
  28690. defaultedTooltip.push(dimName);
  28691. }
  28692. }
  28693. VISUAL_DIMENSIONS.each(function (v, otherDim) {
  28694. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  28695. var dimIndex = dimItem.otherDims[otherDim];
  28696. if (dimIndex != null && dimIndex !== false) {
  28697. encodeArr[dimIndex] = dimItem.name;
  28698. }
  28699. });
  28700. });
  28701. var dataDimsOnCoord = [];
  28702. var encodeFirstDimNotExtra = {};
  28703. notExtraCoordDimMap.each(function (v, coordDim) {
  28704. var dimArr = encode[coordDim];
  28705. encodeFirstDimNotExtra[coordDim] = dimArr[0];
  28706. // Not necessary to remove duplicate, because a data
  28707. // dim canot on more than one coordDim.
  28708. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  28709. });
  28710. summary.dataDimsOnCoord = dataDimsOnCoord;
  28711. summary.dataDimIndicesOnCoord = map(dataDimsOnCoord, function (dimName) {
  28712. return data.getDimensionInfo(dimName).storeDimIndex;
  28713. });
  28714. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  28715. var encodeLabel = encode.label;
  28716. // FIXME `encode.label` is not recommended, because formatter cannot be set
  28717. // in this way. Use label.formatter instead. Maybe remove this approach someday.
  28718. if (encodeLabel && encodeLabel.length) {
  28719. defaultedLabel = encodeLabel.slice();
  28720. }
  28721. var encodeTooltip = encode.tooltip;
  28722. if (encodeTooltip && encodeTooltip.length) {
  28723. defaultedTooltip = encodeTooltip.slice();
  28724. } else if (!defaultedTooltip.length) {
  28725. defaultedTooltip = defaultedLabel.slice();
  28726. }
  28727. encode.defaultedLabel = defaultedLabel;
  28728. encode.defaultedTooltip = defaultedTooltip;
  28729. summary.userOutput = new DimensionUserOuput(userOutputEncode, schema);
  28730. return summary;
  28731. }
  28732. function getOrCreateEncodeArr(encode, dim) {
  28733. if (!encode.hasOwnProperty(dim)) {
  28734. encode[dim] = [];
  28735. }
  28736. return encode[dim];
  28737. }
  28738. // FIXME:TS should be type `AxisType`
  28739. function getDimensionTypeByAxis(axisType) {
  28740. return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
  28741. }
  28742. function mayLabelDimType(dimType) {
  28743. // In most cases, ordinal and time do not suitable for label.
  28744. // Ordinal info can be displayed on axis. Time is too long.
  28745. return !(dimType === 'ordinal' || dimType === 'time');
  28746. }
  28747. // function findTheLastDimMayLabel(data) {
  28748. // // Get last value dim
  28749. // let dimensions = data.dimensions.slice();
  28750. // let valueType;
  28751. // let valueDim;
  28752. // while (dimensions.length && (
  28753. // valueDim = dimensions.pop(),
  28754. // valueType = data.getDimensionInfo(valueDim).type,
  28755. // valueType === 'ordinal' || valueType === 'time'
  28756. // )) {} // jshint ignore:line
  28757. // return valueDim;
  28758. // }
  28759. var SeriesDimensionDefine = /** @class */function () {
  28760. /**
  28761. * @param opt All of the fields will be shallow copied.
  28762. */
  28763. function SeriesDimensionDefine(opt) {
  28764. /**
  28765. * The format of `otherDims` is:
  28766. * ```js
  28767. * {
  28768. * tooltip?: number
  28769. * label?: number
  28770. * itemName?: number
  28771. * seriesName?: number
  28772. * }
  28773. * ```
  28774. *
  28775. * A `series.encode` can specified these fields:
  28776. * ```js
  28777. * encode: {
  28778. * // "3, 1, 5" is the index of data dimension.
  28779. * tooltip: [3, 1, 5],
  28780. * label: [0, 3],
  28781. * ...
  28782. * }
  28783. * ```
  28784. * `otherDims` is the parse result of the `series.encode` above, like:
  28785. * ```js
  28786. * // Suppose the index of this data dimension is `3`.
  28787. * this.otherDims = {
  28788. * // `3` is at the index `0` of the `encode.tooltip`
  28789. * tooltip: 0,
  28790. * // `3` is at the index `1` of the `encode.label`
  28791. * label: 1
  28792. * };
  28793. * ```
  28794. *
  28795. * This prop should never be `null`/`undefined` after initialized.
  28796. */
  28797. this.otherDims = {};
  28798. if (opt != null) {
  28799. extend(this, opt);
  28800. }
  28801. }
  28802. return SeriesDimensionDefine;
  28803. }();
  28804. var inner$4 = makeInner();
  28805. var dimTypeShort = {
  28806. float: 'f',
  28807. int: 'i',
  28808. ordinal: 'o',
  28809. number: 'n',
  28810. time: 't'
  28811. };
  28812. /**
  28813. * Represents the dimension requirement of a series.
  28814. *
  28815. * NOTICE:
  28816. * When there are too many dimensions in dataset and many series, only the used dimensions
  28817. * (i.e., used by coord sys and declared in `series.encode`) are add to `dimensionDefineList`.
  28818. * But users may query data by other unused dimension names.
  28819. * In this case, users can only query data if and only if they have defined dimension names
  28820. * via ec option, so we provide `getDimensionIndexFromSource`, which only query them from
  28821. * `source` dimensions.
  28822. */
  28823. var SeriesDataSchema = /** @class */function () {
  28824. function SeriesDataSchema(opt) {
  28825. this.dimensions = opt.dimensions;
  28826. this._dimOmitted = opt.dimensionOmitted;
  28827. this.source = opt.source;
  28828. this._fullDimCount = opt.fullDimensionCount;
  28829. this._updateDimOmitted(opt.dimensionOmitted);
  28830. }
  28831. SeriesDataSchema.prototype.isDimensionOmitted = function () {
  28832. return this._dimOmitted;
  28833. };
  28834. SeriesDataSchema.prototype._updateDimOmitted = function (dimensionOmitted) {
  28835. this._dimOmitted = dimensionOmitted;
  28836. if (!dimensionOmitted) {
  28837. return;
  28838. }
  28839. if (!this._dimNameMap) {
  28840. this._dimNameMap = ensureSourceDimNameMap(this.source);
  28841. }
  28842. };
  28843. /**
  28844. * @caution Can only be used when `dimensionOmitted: true`.
  28845. *
  28846. * Get index by user defined dimension name (i.e., not internal generate name).
  28847. * That is, get index from `dimensionsDefine`.
  28848. * If no `dimensionsDefine`, or no name get, return -1.
  28849. */
  28850. SeriesDataSchema.prototype.getSourceDimensionIndex = function (dimName) {
  28851. return retrieve2(this._dimNameMap.get(dimName), -1);
  28852. };
  28853. /**
  28854. * @caution Can only be used when `dimensionOmitted: true`.
  28855. *
  28856. * Notice: may return `null`/`undefined` if user not specify dimension names.
  28857. */
  28858. SeriesDataSchema.prototype.getSourceDimension = function (dimIndex) {
  28859. var dimensionsDefine = this.source.dimensionsDefine;
  28860. if (dimensionsDefine) {
  28861. return dimensionsDefine[dimIndex];
  28862. }
  28863. };
  28864. SeriesDataSchema.prototype.makeStoreSchema = function () {
  28865. var dimCount = this._fullDimCount;
  28866. var willRetrieveDataByName = shouldRetrieveDataByName(this.source);
  28867. var makeHashStrict = !shouldOmitUnusedDimensions(dimCount);
  28868. // If source don't have dimensions or series don't omit unsed dimensions.
  28869. // Generate from seriesDimList directly
  28870. var dimHash = '';
  28871. var dims = [];
  28872. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < dimCount; fullDimIdx++) {
  28873. var property = void 0;
  28874. var type = void 0;
  28875. var ordinalMeta = void 0;
  28876. var seriesDimDef = this.dimensions[seriesDimIdx];
  28877. // The list has been sorted by `storeDimIndex` asc.
  28878. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  28879. property = willRetrieveDataByName ? seriesDimDef.name : null;
  28880. type = seriesDimDef.type;
  28881. ordinalMeta = seriesDimDef.ordinalMeta;
  28882. seriesDimIdx++;
  28883. } else {
  28884. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  28885. if (sourceDimDef) {
  28886. property = willRetrieveDataByName ? sourceDimDef.name : null;
  28887. type = sourceDimDef.type;
  28888. }
  28889. }
  28890. dims.push({
  28891. property: property,
  28892. type: type,
  28893. ordinalMeta: ordinalMeta
  28894. });
  28895. // If retrieving data by index,
  28896. // use <index, type, ordinalMeta> to determine whether data can be shared.
  28897. // (Because in this case there might be no dimension name defined in dataset, but indices always exists).
  28898. // (Indices are always 0, 1, 2, ..., so we can ignore them to shorten the hash).
  28899. // Otherwise if retrieving data by property name (like `data: [{aa: 123, bb: 765}, ...]`),
  28900. // use <property, type, ordinalMeta> in hash.
  28901. if (willRetrieveDataByName && property != null
  28902. // For data stack, we have make sure each series has its own dim on this store.
  28903. // So we do not add property to hash to make sure they can share this store.
  28904. && (!seriesDimDef || !seriesDimDef.isCalculationCoord)) {
  28905. dimHash += makeHashStrict
  28906. // Use escape character '`' in case that property name contains '$'.
  28907. ? property.replace(/\`/g, '`1').replace(/\$/g, '`2')
  28908. // For better performance, when there are large dimensions, tolerant this defects that hardly meet.
  28909. : property;
  28910. }
  28911. dimHash += '$';
  28912. dimHash += dimTypeShort[type] || 'f';
  28913. if (ordinalMeta) {
  28914. dimHash += ordinalMeta.uid;
  28915. }
  28916. dimHash += '$';
  28917. }
  28918. // Source from endpoint(usually series) will be read differently
  28919. // when seriesLayoutBy or startIndex(which is affected by sourceHeader) are different.
  28920. // So we use this three props as key.
  28921. var source = this.source;
  28922. var hash = [source.seriesLayoutBy, source.startIndex, dimHash].join('$$');
  28923. return {
  28924. dimensions: dims,
  28925. hash: hash
  28926. };
  28927. };
  28928. SeriesDataSchema.prototype.makeOutputDimensionNames = function () {
  28929. var result = [];
  28930. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < this._fullDimCount; fullDimIdx++) {
  28931. var name_1 = void 0;
  28932. var seriesDimDef = this.dimensions[seriesDimIdx];
  28933. // The list has been sorted by `storeDimIndex` asc.
  28934. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  28935. if (!seriesDimDef.isCalculationCoord) {
  28936. name_1 = seriesDimDef.name;
  28937. }
  28938. seriesDimIdx++;
  28939. } else {
  28940. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  28941. if (sourceDimDef) {
  28942. name_1 = sourceDimDef.name;
  28943. }
  28944. }
  28945. result.push(name_1);
  28946. }
  28947. return result;
  28948. };
  28949. SeriesDataSchema.prototype.appendCalculationDimension = function (dimDef) {
  28950. this.dimensions.push(dimDef);
  28951. dimDef.isCalculationCoord = true;
  28952. this._fullDimCount++;
  28953. // If append dimension on a data store, consider the store
  28954. // might be shared by different series, series dimensions not
  28955. // really map to store dimensions.
  28956. this._updateDimOmitted(true);
  28957. };
  28958. return SeriesDataSchema;
  28959. }();
  28960. function isSeriesDataSchema(schema) {
  28961. return schema instanceof SeriesDataSchema;
  28962. }
  28963. function createDimNameMap(dimsDef) {
  28964. var dataDimNameMap = createHashMap();
  28965. for (var i = 0; i < (dimsDef || []).length; i++) {
  28966. var dimDefItemRaw = dimsDef[i];
  28967. var userDimName = isObject(dimDefItemRaw) ? dimDefItemRaw.name : dimDefItemRaw;
  28968. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  28969. dataDimNameMap.set(userDimName, i);
  28970. }
  28971. }
  28972. return dataDimNameMap;
  28973. }
  28974. function ensureSourceDimNameMap(source) {
  28975. var innerSource = inner$4(source);
  28976. return innerSource.dimNameMap || (innerSource.dimNameMap = createDimNameMap(source.dimensionsDefine));
  28977. }
  28978. function shouldOmitUnusedDimensions(dimCount) {
  28979. return dimCount > 30;
  28980. }
  28981. var isObject$2 = isObject;
  28982. var map$1 = map;
  28983. var CtorInt32Array$1 = typeof Int32Array === 'undefined' ? Array : Int32Array;
  28984. // Use prefix to avoid index to be the same as otherIdList[idx],
  28985. // which will cause weird update animation.
  28986. var ID_PREFIX = 'e\0\0';
  28987. var INDEX_NOT_FOUND = -1;
  28988. // type SeriesDimensionIndex = DimensionIndex;
  28989. var TRANSFERABLE_PROPERTIES = ['hasItemOption', '_nameList', '_idList', '_invertedIndicesMap', '_dimSummary', 'userOutput', '_rawData', '_dimValueGetter', '_nameDimIdx', '_idDimIdx', '_nameRepeatCount'];
  28990. var CLONE_PROPERTIES = ['_approximateExtent'];
  28991. // -----------------------------
  28992. // Internal method declarations:
  28993. // -----------------------------
  28994. var prepareInvertedIndex;
  28995. var getId;
  28996. var getIdNameFromStore;
  28997. var normalizeDimensions;
  28998. var transferProperties;
  28999. var cloneListForMapAndSample;
  29000. var makeIdFromName;
  29001. var SeriesData = /** @class */function () {
  29002. /**
  29003. * @param dimensionsInput.dimensions
  29004. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  29005. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  29006. */
  29007. function SeriesData(dimensionsInput, hostModel) {
  29008. this.type = 'list';
  29009. this._dimOmitted = false;
  29010. this._nameList = [];
  29011. this._idList = [];
  29012. // Models of data option is stored sparse for optimizing memory cost
  29013. // Never used yet (not used yet).
  29014. // private _optionModels: Model[] = [];
  29015. // Global visual properties after visual coding
  29016. this._visual = {};
  29017. // Global layout properties.
  29018. this._layout = {};
  29019. // Item visual properties after visual coding
  29020. this._itemVisuals = [];
  29021. // Item layout properties after layout
  29022. this._itemLayouts = [];
  29023. // Graphic elements
  29024. this._graphicEls = [];
  29025. // key: dim, value: extent
  29026. this._approximateExtent = {};
  29027. this._calculationInfo = {};
  29028. // Having detected that there is data item is non primitive type
  29029. // (in type `OptionDataItemObject`).
  29030. // Like `data: [ { value: xx, itemStyle: {...} }, ...]`
  29031. // At present it only happen in `SOURCE_FORMAT_ORIGINAL`.
  29032. this.hasItemOption = false;
  29033. // Methods that create a new list based on this list should be listed here.
  29034. // Notice that those method should `RETURN` the new list.
  29035. this.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'minmaxDownSample', 'lttbDownSample', 'map'];
  29036. // Methods that change indices of this list should be listed here.
  29037. this.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  29038. this.DOWNSAMPLE_METHODS = ['downSample', 'minmaxDownSample', 'lttbDownSample'];
  29039. var dimensions;
  29040. var assignStoreDimIdx = false;
  29041. if (isSeriesDataSchema(dimensionsInput)) {
  29042. dimensions = dimensionsInput.dimensions;
  29043. this._dimOmitted = dimensionsInput.isDimensionOmitted();
  29044. this._schema = dimensionsInput;
  29045. } else {
  29046. assignStoreDimIdx = true;
  29047. dimensions = dimensionsInput;
  29048. }
  29049. dimensions = dimensions || ['x', 'y'];
  29050. var dimensionInfos = {};
  29051. var dimensionNames = [];
  29052. var invertedIndicesMap = {};
  29053. var needsHasOwn = false;
  29054. var emptyObj = {};
  29055. for (var i = 0; i < dimensions.length; i++) {
  29056. // Use the original dimensions[i], where other flag props may exists.
  29057. var dimInfoInput = dimensions[i];
  29058. var dimensionInfo = isString(dimInfoInput) ? new SeriesDimensionDefine({
  29059. name: dimInfoInput
  29060. }) : !(dimInfoInput instanceof SeriesDimensionDefine) ? new SeriesDimensionDefine(dimInfoInput) : dimInfoInput;
  29061. var dimensionName = dimensionInfo.name;
  29062. dimensionInfo.type = dimensionInfo.type || 'float';
  29063. if (!dimensionInfo.coordDim) {
  29064. dimensionInfo.coordDim = dimensionName;
  29065. dimensionInfo.coordDimIndex = 0;
  29066. }
  29067. var otherDims = dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  29068. dimensionNames.push(dimensionName);
  29069. dimensionInfos[dimensionName] = dimensionInfo;
  29070. if (emptyObj[dimensionName] != null) {
  29071. needsHasOwn = true;
  29072. }
  29073. if (dimensionInfo.createInvertedIndices) {
  29074. invertedIndicesMap[dimensionName] = [];
  29075. }
  29076. var dimIdx = i;
  29077. if (isNumber(dimensionInfo.storeDimIndex)) {
  29078. dimIdx = dimensionInfo.storeDimIndex;
  29079. }
  29080. if (otherDims.itemName === 0) {
  29081. this._nameDimIdx = dimIdx;
  29082. }
  29083. if (otherDims.itemId === 0) {
  29084. this._idDimIdx = dimIdx;
  29085. }
  29086. if ("development" !== 'production') {
  29087. assert(assignStoreDimIdx || dimensionInfo.storeDimIndex >= 0);
  29088. }
  29089. if (assignStoreDimIdx) {
  29090. dimensionInfo.storeDimIndex = i;
  29091. }
  29092. }
  29093. this.dimensions = dimensionNames;
  29094. this._dimInfos = dimensionInfos;
  29095. this._initGetDimensionInfo(needsHasOwn);
  29096. this.hostModel = hostModel;
  29097. this._invertedIndicesMap = invertedIndicesMap;
  29098. if (this._dimOmitted) {
  29099. var dimIdxToName_1 = this._dimIdxToName = createHashMap();
  29100. each(dimensionNames, function (dimName) {
  29101. dimIdxToName_1.set(dimensionInfos[dimName].storeDimIndex, dimName);
  29102. });
  29103. }
  29104. }
  29105. /**
  29106. *
  29107. * Get concrete dimension name by dimension name or dimension index.
  29108. * If input a dimension name, do not validate whether the dimension name exits.
  29109. *
  29110. * @caution
  29111. * @param dim Must make sure the dimension is `SeriesDimensionLoose`.
  29112. * Because only those dimensions will have auto-generated dimension names if not
  29113. * have a user-specified name, and other dimensions will get a return of null/undefined.
  29114. *
  29115. * @notice Because of this reason, should better use `getDimensionIndex` instead, for examples:
  29116. * ```js
  29117. * const val = data.getStore().get(data.getDimensionIndex(dim), dataIdx);
  29118. * ```
  29119. *
  29120. * @return Concrete dim name.
  29121. */
  29122. SeriesData.prototype.getDimension = function (dim) {
  29123. var dimIdx = this._recognizeDimIndex(dim);
  29124. if (dimIdx == null) {
  29125. return dim;
  29126. }
  29127. dimIdx = dim;
  29128. if (!this._dimOmitted) {
  29129. return this.dimensions[dimIdx];
  29130. }
  29131. // Retrieve from series dimension definition because it probably contains
  29132. // generated dimension name (like 'x', 'y').
  29133. var dimName = this._dimIdxToName.get(dimIdx);
  29134. if (dimName != null) {
  29135. return dimName;
  29136. }
  29137. var sourceDimDef = this._schema.getSourceDimension(dimIdx);
  29138. if (sourceDimDef) {
  29139. return sourceDimDef.name;
  29140. }
  29141. };
  29142. /**
  29143. * Get dimension index in data store. Return -1 if not found.
  29144. * Can be used to index value from getRawValue.
  29145. */
  29146. SeriesData.prototype.getDimensionIndex = function (dim) {
  29147. var dimIdx = this._recognizeDimIndex(dim);
  29148. if (dimIdx != null) {
  29149. return dimIdx;
  29150. }
  29151. if (dim == null) {
  29152. return -1;
  29153. }
  29154. var dimInfo = this._getDimInfo(dim);
  29155. return dimInfo ? dimInfo.storeDimIndex : this._dimOmitted ? this._schema.getSourceDimensionIndex(dim) : -1;
  29156. };
  29157. /**
  29158. * The meanings of the input parameter `dim`:
  29159. *
  29160. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  29161. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  29162. * + If dim is a number-like string (e.g., `"1"`):
  29163. * + If there is the same concrete dim name defined in `series.dimensions` or `dataset.dimensions`,
  29164. * it means that concrete name.
  29165. * + If not, it will be converted to a number, which means the index of the dimension.
  29166. * (why? because of the backward compatibility. We have been tolerating number-like string in
  29167. * dimension setting, although now it seems that it is not a good idea.)
  29168. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  29169. * if no dimension name is defined as `"1"`.
  29170. * + If dim is a not-number-like string, it means the concrete dim name.
  29171. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  29172. * or customized in `dimensions` property of option like `"age"`.
  29173. *
  29174. * @return recognized `DimensionIndex`. Otherwise return null/undefined (means that dim is `DimensionName`).
  29175. */
  29176. SeriesData.prototype._recognizeDimIndex = function (dim) {
  29177. if (isNumber(dim)
  29178. // If being a number-like string but not being defined as a dimension name.
  29179. || dim != null && !isNaN(dim) && !this._getDimInfo(dim) && (!this._dimOmitted || this._schema.getSourceDimensionIndex(dim) < 0)) {
  29180. return +dim;
  29181. }
  29182. };
  29183. SeriesData.prototype._getStoreDimIndex = function (dim) {
  29184. var dimIdx = this.getDimensionIndex(dim);
  29185. if ("development" !== 'production') {
  29186. if (dimIdx == null) {
  29187. throw new Error('Unknown dimension ' + dim);
  29188. }
  29189. }
  29190. return dimIdx;
  29191. };
  29192. /**
  29193. * Get type and calculation info of particular dimension
  29194. * @param dim
  29195. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  29196. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  29197. */
  29198. SeriesData.prototype.getDimensionInfo = function (dim) {
  29199. // Do not clone, because there may be categories in dimInfo.
  29200. return this._getDimInfo(this.getDimension(dim));
  29201. };
  29202. SeriesData.prototype._initGetDimensionInfo = function (needsHasOwn) {
  29203. var dimensionInfos = this._dimInfos;
  29204. this._getDimInfo = needsHasOwn ? function (dimName) {
  29205. return dimensionInfos.hasOwnProperty(dimName) ? dimensionInfos[dimName] : undefined;
  29206. } : function (dimName) {
  29207. return dimensionInfos[dimName];
  29208. };
  29209. };
  29210. /**
  29211. * concrete dimension name list on coord.
  29212. */
  29213. SeriesData.prototype.getDimensionsOnCoord = function () {
  29214. return this._dimSummary.dataDimsOnCoord.slice();
  29215. };
  29216. SeriesData.prototype.mapDimension = function (coordDim, idx) {
  29217. var dimensionsSummary = this._dimSummary;
  29218. if (idx == null) {
  29219. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  29220. }
  29221. var dims = dimensionsSummary.encode[coordDim];
  29222. return dims ? dims[idx] : null;
  29223. };
  29224. SeriesData.prototype.mapDimensionsAll = function (coordDim) {
  29225. var dimensionsSummary = this._dimSummary;
  29226. var dims = dimensionsSummary.encode[coordDim];
  29227. return (dims || []).slice();
  29228. };
  29229. SeriesData.prototype.getStore = function () {
  29230. return this._store;
  29231. };
  29232. /**
  29233. * Initialize from data
  29234. * @param data source or data or data store.
  29235. * @param nameList The name of a datum is used on data diff and
  29236. * default label/tooltip.
  29237. * A name can be specified in encode.itemName,
  29238. * or dataItem.name (only for series option data),
  29239. * or provided in nameList from outside.
  29240. */
  29241. SeriesData.prototype.initData = function (data, nameList, dimValueGetter) {
  29242. var _this = this;
  29243. var store;
  29244. if (data instanceof DataStore) {
  29245. store = data;
  29246. }
  29247. if (!store) {
  29248. var dimensions = this.dimensions;
  29249. var provider = isSourceInstance(data) || isArrayLike(data) ? new DefaultDataProvider(data, dimensions.length) : data;
  29250. store = new DataStore();
  29251. var dimensionInfos = map$1(dimensions, function (dimName) {
  29252. return {
  29253. type: _this._dimInfos[dimName].type,
  29254. property: dimName
  29255. };
  29256. });
  29257. store.initData(provider, dimensionInfos, dimValueGetter);
  29258. }
  29259. this._store = store;
  29260. // Reset
  29261. this._nameList = (nameList || []).slice();
  29262. this._idList = [];
  29263. this._nameRepeatCount = {};
  29264. this._doInit(0, store.count());
  29265. // Cache summary info for fast visit. See "dimensionHelper".
  29266. // Needs to be initialized after store is prepared.
  29267. this._dimSummary = summarizeDimensions(this, this._schema);
  29268. this.userOutput = this._dimSummary.userOutput;
  29269. };
  29270. /**
  29271. * Caution: Can be only called on raw data (before `this._indices` created).
  29272. */
  29273. SeriesData.prototype.appendData = function (data) {
  29274. var range = this._store.appendData(data);
  29275. this._doInit(range[0], range[1]);
  29276. };
  29277. /**
  29278. * Caution: Can be only called on raw data (before `this._indices` created).
  29279. * This method does not modify `rawData` (`dataProvider`), but only
  29280. * add values to store.
  29281. *
  29282. * The final count will be increased by `Math.max(values.length, names.length)`.
  29283. *
  29284. * @param values That is the SourceType: 'arrayRows', like
  29285. * [
  29286. * [12, 33, 44],
  29287. * [NaN, 43, 1],
  29288. * ['-', 'asdf', 0]
  29289. * ]
  29290. * Each item is exactly corresponding to a dimension.
  29291. */
  29292. SeriesData.prototype.appendValues = function (values, names) {
  29293. var _a = this._store.appendValues(values, names && names.length),
  29294. start = _a.start,
  29295. end = _a.end;
  29296. var shouldMakeIdFromName = this._shouldMakeIdFromName();
  29297. this._updateOrdinalMeta();
  29298. if (names) {
  29299. for (var idx = start; idx < end; idx++) {
  29300. var sourceIdx = idx - start;
  29301. this._nameList[idx] = names[sourceIdx];
  29302. if (shouldMakeIdFromName) {
  29303. makeIdFromName(this, idx);
  29304. }
  29305. }
  29306. }
  29307. };
  29308. SeriesData.prototype._updateOrdinalMeta = function () {
  29309. var store = this._store;
  29310. var dimensions = this.dimensions;
  29311. for (var i = 0; i < dimensions.length; i++) {
  29312. var dimInfo = this._dimInfos[dimensions[i]];
  29313. if (dimInfo.ordinalMeta) {
  29314. store.collectOrdinalMeta(dimInfo.storeDimIndex, dimInfo.ordinalMeta);
  29315. }
  29316. }
  29317. };
  29318. SeriesData.prototype._shouldMakeIdFromName = function () {
  29319. var provider = this._store.getProvider();
  29320. return this._idDimIdx == null && provider.getSource().sourceFormat !== SOURCE_FORMAT_TYPED_ARRAY && !provider.fillStorage;
  29321. };
  29322. SeriesData.prototype._doInit = function (start, end) {
  29323. if (start >= end) {
  29324. return;
  29325. }
  29326. var store = this._store;
  29327. var provider = store.getProvider();
  29328. this._updateOrdinalMeta();
  29329. var nameList = this._nameList;
  29330. var idList = this._idList;
  29331. var sourceFormat = provider.getSource().sourceFormat;
  29332. var isFormatOriginal = sourceFormat === SOURCE_FORMAT_ORIGINAL;
  29333. // Each data item is value
  29334. // [1, 2]
  29335. // 2
  29336. // Bar chart, line chart which uses category axis
  29337. // only gives the 'y' value. 'x' value is the indices of category
  29338. // Use a tempValue to normalize the value to be a (x, y) value
  29339. // If dataItem is {name: ...} or {id: ...}, it has highest priority.
  29340. // This kind of ids and names are always stored `_nameList` and `_idList`.
  29341. if (isFormatOriginal && !provider.pure) {
  29342. var sharedDataItem = [];
  29343. for (var idx = start; idx < end; idx++) {
  29344. // NOTICE: Try not to write things into dataItem
  29345. var dataItem = provider.getItem(idx, sharedDataItem);
  29346. if (!this.hasItemOption && isDataItemOption(dataItem)) {
  29347. this.hasItemOption = true;
  29348. }
  29349. if (dataItem) {
  29350. var itemName = dataItem.name;
  29351. if (nameList[idx] == null && itemName != null) {
  29352. nameList[idx] = convertOptionIdName(itemName, null);
  29353. }
  29354. var itemId = dataItem.id;
  29355. if (idList[idx] == null && itemId != null) {
  29356. idList[idx] = convertOptionIdName(itemId, null);
  29357. }
  29358. }
  29359. }
  29360. }
  29361. if (this._shouldMakeIdFromName()) {
  29362. for (var idx = start; idx < end; idx++) {
  29363. makeIdFromName(this, idx);
  29364. }
  29365. }
  29366. prepareInvertedIndex(this);
  29367. };
  29368. /**
  29369. * PENDING: In fact currently this function is only used to short-circuit
  29370. * the calling of `scale.unionExtentFromData` when data have been filtered by modules
  29371. * like "dataZoom". `scale.unionExtentFromData` is used to calculate data extent for series on
  29372. * an axis, but if a "axis related data filter module" is used, the extent of the axis have
  29373. * been fixed and no need to calling `scale.unionExtentFromData` actually.
  29374. * But if we add "custom data filter" in future, which is not "axis related", this method may
  29375. * be still needed.
  29376. *
  29377. * Optimize for the scenario that data is filtered by a given extent.
  29378. * Consider that if data amount is more than hundreds of thousand,
  29379. * extent calculation will cost more than 10ms and the cache will
  29380. * be erased because of the filtering.
  29381. */
  29382. SeriesData.prototype.getApproximateExtent = function (dim) {
  29383. return this._approximateExtent[dim] || this._store.getDataExtent(this._getStoreDimIndex(dim));
  29384. };
  29385. /**
  29386. * Calculate extent on a filtered data might be time consuming.
  29387. * Approximate extent is only used for: calculate extent of filtered data outside.
  29388. */
  29389. SeriesData.prototype.setApproximateExtent = function (extent, dim) {
  29390. dim = this.getDimension(dim);
  29391. this._approximateExtent[dim] = extent.slice();
  29392. };
  29393. SeriesData.prototype.getCalculationInfo = function (key) {
  29394. return this._calculationInfo[key];
  29395. };
  29396. SeriesData.prototype.setCalculationInfo = function (key, value) {
  29397. isObject$2(key) ? extend(this._calculationInfo, key) : this._calculationInfo[key] = value;
  29398. };
  29399. /**
  29400. * @return Never be null/undefined. `number` will be converted to string. Because:
  29401. * In most cases, name is used in display, where returning a string is more convenient.
  29402. * In other cases, name is used in query (see `indexOfName`), where we can keep the
  29403. * rule that name `2` equals to name `'2'`.
  29404. */
  29405. SeriesData.prototype.getName = function (idx) {
  29406. var rawIndex = this.getRawIndex(idx);
  29407. var name = this._nameList[rawIndex];
  29408. if (name == null && this._nameDimIdx != null) {
  29409. name = getIdNameFromStore(this, this._nameDimIdx, rawIndex);
  29410. }
  29411. if (name == null) {
  29412. name = '';
  29413. }
  29414. return name;
  29415. };
  29416. SeriesData.prototype._getCategory = function (dimIdx, idx) {
  29417. var ordinal = this._store.get(dimIdx, idx);
  29418. var ordinalMeta = this._store.getOrdinalMeta(dimIdx);
  29419. if (ordinalMeta) {
  29420. return ordinalMeta.categories[ordinal];
  29421. }
  29422. return ordinal;
  29423. };
  29424. /**
  29425. * @return Never null/undefined. `number` will be converted to string. Because:
  29426. * In all cases having encountered at present, id is used in making diff comparison, which
  29427. * are usually based on hash map. We can keep the rule that the internal id are always string
  29428. * (treat `2` is the same as `'2'`) to make the related logic simple.
  29429. */
  29430. SeriesData.prototype.getId = function (idx) {
  29431. return getId(this, this.getRawIndex(idx));
  29432. };
  29433. SeriesData.prototype.count = function () {
  29434. return this._store.count();
  29435. };
  29436. /**
  29437. * Get value. Return NaN if idx is out of range.
  29438. *
  29439. * @notice Should better to use `data.getStore().get(dimIndex, dataIdx)` instead.
  29440. */
  29441. SeriesData.prototype.get = function (dim, idx) {
  29442. var store = this._store;
  29443. var dimInfo = this._dimInfos[dim];
  29444. if (dimInfo) {
  29445. return store.get(dimInfo.storeDimIndex, idx);
  29446. }
  29447. };
  29448. /**
  29449. * @notice Should better to use `data.getStore().getByRawIndex(dimIndex, dataIdx)` instead.
  29450. */
  29451. SeriesData.prototype.getByRawIndex = function (dim, rawIdx) {
  29452. var store = this._store;
  29453. var dimInfo = this._dimInfos[dim];
  29454. if (dimInfo) {
  29455. return store.getByRawIndex(dimInfo.storeDimIndex, rawIdx);
  29456. }
  29457. };
  29458. SeriesData.prototype.getIndices = function () {
  29459. return this._store.getIndices();
  29460. };
  29461. SeriesData.prototype.getDataExtent = function (dim) {
  29462. return this._store.getDataExtent(this._getStoreDimIndex(dim));
  29463. };
  29464. SeriesData.prototype.getSum = function (dim) {
  29465. return this._store.getSum(this._getStoreDimIndex(dim));
  29466. };
  29467. SeriesData.prototype.getMedian = function (dim) {
  29468. return this._store.getMedian(this._getStoreDimIndex(dim));
  29469. };
  29470. SeriesData.prototype.getValues = function (dimensions, idx) {
  29471. var _this = this;
  29472. var store = this._store;
  29473. return isArray(dimensions) ? store.getValues(map$1(dimensions, function (dim) {
  29474. return _this._getStoreDimIndex(dim);
  29475. }), idx) : store.getValues(dimensions);
  29476. };
  29477. /**
  29478. * If value is NaN. Including '-'
  29479. * Only check the coord dimensions.
  29480. */
  29481. SeriesData.prototype.hasValue = function (idx) {
  29482. var dataDimIndicesOnCoord = this._dimSummary.dataDimIndicesOnCoord;
  29483. for (var i = 0, len = dataDimIndicesOnCoord.length; i < len; i++) {
  29484. // Ordinal type originally can be string or number.
  29485. // But when an ordinal type is used on coord, it can
  29486. // not be string but only number. So we can also use isNaN.
  29487. if (isNaN(this._store.get(dataDimIndicesOnCoord[i], idx))) {
  29488. return false;
  29489. }
  29490. }
  29491. return true;
  29492. };
  29493. /**
  29494. * Retrieve the index with given name
  29495. */
  29496. SeriesData.prototype.indexOfName = function (name) {
  29497. for (var i = 0, len = this._store.count(); i < len; i++) {
  29498. if (this.getName(i) === name) {
  29499. return i;
  29500. }
  29501. }
  29502. return -1;
  29503. };
  29504. SeriesData.prototype.getRawIndex = function (idx) {
  29505. return this._store.getRawIndex(idx);
  29506. };
  29507. SeriesData.prototype.indexOfRawIndex = function (rawIndex) {
  29508. return this._store.indexOfRawIndex(rawIndex);
  29509. };
  29510. /**
  29511. * Only support the dimension which inverted index created.
  29512. * Do not support other cases until required.
  29513. * @param dim concrete dim
  29514. * @param value ordinal index
  29515. * @return rawIndex
  29516. */
  29517. SeriesData.prototype.rawIndexOf = function (dim, value) {
  29518. var invertedIndices = dim && this._invertedIndicesMap[dim];
  29519. if ("development" !== 'production') {
  29520. if (!invertedIndices) {
  29521. throw new Error('Do not supported yet');
  29522. }
  29523. }
  29524. var rawIndex = invertedIndices && invertedIndices[value];
  29525. if (rawIndex == null || isNaN(rawIndex)) {
  29526. return INDEX_NOT_FOUND;
  29527. }
  29528. return rawIndex;
  29529. };
  29530. SeriesData.prototype.each = function (dims, cb, ctx) {
  29531. if (isFunction(dims)) {
  29532. ctx = cb;
  29533. cb = dims;
  29534. dims = [];
  29535. }
  29536. // ctxCompat just for compat echarts3
  29537. var fCtx = ctx || this;
  29538. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29539. this._store.each(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29540. };
  29541. SeriesData.prototype.filterSelf = function (dims, cb, ctx) {
  29542. if (isFunction(dims)) {
  29543. ctx = cb;
  29544. cb = dims;
  29545. dims = [];
  29546. }
  29547. // ctxCompat just for compat echarts3
  29548. var fCtx = ctx || this;
  29549. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29550. this._store = this._store.filter(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29551. return this;
  29552. };
  29553. /**
  29554. * Select data in range. (For optimization of filter)
  29555. * (Manually inline code, support 5 million data filtering in data zoom.)
  29556. */
  29557. SeriesData.prototype.selectRange = function (range) {
  29558. var _this = this;
  29559. var innerRange = {};
  29560. var dims = keys(range);
  29561. each(dims, function (dim) {
  29562. var dimIdx = _this._getStoreDimIndex(dim);
  29563. innerRange[dimIdx] = range[dim];
  29564. });
  29565. this._store = this._store.selectRange(innerRange);
  29566. return this;
  29567. };
  29568. /* eslint-enable max-len */
  29569. SeriesData.prototype.mapArray = function (dims, cb, ctx) {
  29570. if (isFunction(dims)) {
  29571. ctx = cb;
  29572. cb = dims;
  29573. dims = [];
  29574. }
  29575. // ctxCompat just for compat echarts3
  29576. ctx = ctx || this;
  29577. var result = [];
  29578. this.each(dims, function () {
  29579. result.push(cb && cb.apply(this, arguments));
  29580. }, ctx);
  29581. return result;
  29582. };
  29583. SeriesData.prototype.map = function (dims, cb, ctx, ctxCompat) {
  29584. // ctxCompat just for compat echarts3
  29585. var fCtx = ctx || ctxCompat || this;
  29586. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29587. var list = cloneListForMapAndSample(this);
  29588. list._store = this._store.map(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29589. return list;
  29590. };
  29591. SeriesData.prototype.modify = function (dims, cb, ctx, ctxCompat) {
  29592. var _this = this;
  29593. // ctxCompat just for compat echarts3
  29594. var fCtx = ctx || ctxCompat || this;
  29595. if ("development" !== 'production') {
  29596. each(normalizeDimensions(dims), function (dim) {
  29597. var dimInfo = _this.getDimensionInfo(dim);
  29598. if (!dimInfo.isCalculationCoord) {
  29599. console.error('Danger: only stack dimension can be modified');
  29600. }
  29601. });
  29602. }
  29603. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29604. // If do shallow clone here, if there are too many stacked series,
  29605. // it still cost lots of memory, because `_store.dimensions` are not shared.
  29606. // We should consider there probably be shallow clone happen in each series
  29607. // in consequent filter/map.
  29608. this._store.modify(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29609. };
  29610. /**
  29611. * Large data down sampling on given dimension
  29612. * @param sampleIndex Sample index for name and id
  29613. */
  29614. SeriesData.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  29615. var list = cloneListForMapAndSample(this);
  29616. list._store = this._store.downSample(this._getStoreDimIndex(dimension), rate, sampleValue, sampleIndex);
  29617. return list;
  29618. };
  29619. /**
  29620. * Large data down sampling using min-max
  29621. * @param {string} valueDimension
  29622. * @param {number} rate
  29623. */
  29624. SeriesData.prototype.minmaxDownSample = function (valueDimension, rate) {
  29625. var list = cloneListForMapAndSample(this);
  29626. list._store = this._store.minmaxDownSample(this._getStoreDimIndex(valueDimension), rate);
  29627. return list;
  29628. };
  29629. /**
  29630. * Large data down sampling using largest-triangle-three-buckets
  29631. * @param {string} valueDimension
  29632. * @param {number} targetCount
  29633. */
  29634. SeriesData.prototype.lttbDownSample = function (valueDimension, rate) {
  29635. var list = cloneListForMapAndSample(this);
  29636. list._store = this._store.lttbDownSample(this._getStoreDimIndex(valueDimension), rate);
  29637. return list;
  29638. };
  29639. SeriesData.prototype.getRawDataItem = function (idx) {
  29640. return this._store.getRawDataItem(idx);
  29641. };
  29642. /**
  29643. * Get model of one data item.
  29644. */
  29645. // TODO: Type of data item
  29646. SeriesData.prototype.getItemModel = function (idx) {
  29647. var hostModel = this.hostModel;
  29648. var dataItem = this.getRawDataItem(idx);
  29649. return new Model(dataItem, hostModel, hostModel && hostModel.ecModel);
  29650. };
  29651. /**
  29652. * Create a data differ
  29653. */
  29654. SeriesData.prototype.diff = function (otherList) {
  29655. var thisList = this;
  29656. return new DataDiffer(otherList ? otherList.getStore().getIndices() : [], this.getStore().getIndices(), function (idx) {
  29657. return getId(otherList, idx);
  29658. }, function (idx) {
  29659. return getId(thisList, idx);
  29660. });
  29661. };
  29662. /**
  29663. * Get visual property.
  29664. */
  29665. SeriesData.prototype.getVisual = function (key) {
  29666. var visual = this._visual;
  29667. return visual && visual[key];
  29668. };
  29669. SeriesData.prototype.setVisual = function (kvObj, val) {
  29670. this._visual = this._visual || {};
  29671. if (isObject$2(kvObj)) {
  29672. extend(this._visual, kvObj);
  29673. } else {
  29674. this._visual[kvObj] = val;
  29675. }
  29676. };
  29677. /**
  29678. * Get visual property of single data item
  29679. */
  29680. // eslint-disable-next-line
  29681. SeriesData.prototype.getItemVisual = function (idx, key) {
  29682. var itemVisual = this._itemVisuals[idx];
  29683. var val = itemVisual && itemVisual[key];
  29684. if (val == null) {
  29685. // Use global visual property
  29686. return this.getVisual(key);
  29687. }
  29688. return val;
  29689. };
  29690. /**
  29691. * If exists visual property of single data item
  29692. */
  29693. SeriesData.prototype.hasItemVisual = function () {
  29694. return this._itemVisuals.length > 0;
  29695. };
  29696. /**
  29697. * Make sure itemVisual property is unique
  29698. */
  29699. // TODO: use key to save visual to reduce memory.
  29700. SeriesData.prototype.ensureUniqueItemVisual = function (idx, key) {
  29701. var itemVisuals = this._itemVisuals;
  29702. var itemVisual = itemVisuals[idx];
  29703. if (!itemVisual) {
  29704. itemVisual = itemVisuals[idx] = {};
  29705. }
  29706. var val = itemVisual[key];
  29707. if (val == null) {
  29708. val = this.getVisual(key);
  29709. // TODO Performance?
  29710. if (isArray(val)) {
  29711. val = val.slice();
  29712. } else if (isObject$2(val)) {
  29713. val = extend({}, val);
  29714. }
  29715. itemVisual[key] = val;
  29716. }
  29717. return val;
  29718. };
  29719. // eslint-disable-next-line
  29720. SeriesData.prototype.setItemVisual = function (idx, key, value) {
  29721. var itemVisual = this._itemVisuals[idx] || {};
  29722. this._itemVisuals[idx] = itemVisual;
  29723. if (isObject$2(key)) {
  29724. extend(itemVisual, key);
  29725. } else {
  29726. itemVisual[key] = value;
  29727. }
  29728. };
  29729. /**
  29730. * Clear itemVisuals and list visual.
  29731. */
  29732. SeriesData.prototype.clearAllVisual = function () {
  29733. this._visual = {};
  29734. this._itemVisuals = [];
  29735. };
  29736. SeriesData.prototype.setLayout = function (key, val) {
  29737. isObject$2(key) ? extend(this._layout, key) : this._layout[key] = val;
  29738. };
  29739. /**
  29740. * Get layout property.
  29741. */
  29742. SeriesData.prototype.getLayout = function (key) {
  29743. return this._layout[key];
  29744. };
  29745. /**
  29746. * Get layout of single data item
  29747. */
  29748. SeriesData.prototype.getItemLayout = function (idx) {
  29749. return this._itemLayouts[idx];
  29750. };
  29751. /**
  29752. * Set layout of single data item
  29753. */
  29754. SeriesData.prototype.setItemLayout = function (idx, layout, merge) {
  29755. this._itemLayouts[idx] = merge ? extend(this._itemLayouts[idx] || {}, layout) : layout;
  29756. };
  29757. /**
  29758. * Clear all layout of single data item
  29759. */
  29760. SeriesData.prototype.clearItemLayouts = function () {
  29761. this._itemLayouts.length = 0;
  29762. };
  29763. /**
  29764. * Set graphic element relative to data. It can be set as null
  29765. */
  29766. SeriesData.prototype.setItemGraphicEl = function (idx, el) {
  29767. var seriesIndex = this.hostModel && this.hostModel.seriesIndex;
  29768. setCommonECData(seriesIndex, this.dataType, idx, el);
  29769. this._graphicEls[idx] = el;
  29770. };
  29771. SeriesData.prototype.getItemGraphicEl = function (idx) {
  29772. return this._graphicEls[idx];
  29773. };
  29774. SeriesData.prototype.eachItemGraphicEl = function (cb, context) {
  29775. each(this._graphicEls, function (el, idx) {
  29776. if (el) {
  29777. cb && cb.call(context, el, idx);
  29778. }
  29779. });
  29780. };
  29781. /**
  29782. * Shallow clone a new list except visual and layout properties, and graph elements.
  29783. * New list only change the indices.
  29784. */
  29785. SeriesData.prototype.cloneShallow = function (list) {
  29786. if (!list) {
  29787. list = new SeriesData(this._schema ? this._schema : map$1(this.dimensions, this._getDimInfo, this), this.hostModel);
  29788. }
  29789. transferProperties(list, this);
  29790. list._store = this._store;
  29791. return list;
  29792. };
  29793. /**
  29794. * Wrap some method to add more feature
  29795. */
  29796. SeriesData.prototype.wrapMethod = function (methodName, injectFunction) {
  29797. var originalMethod = this[methodName];
  29798. if (!isFunction(originalMethod)) {
  29799. return;
  29800. }
  29801. this.__wrappedMethods = this.__wrappedMethods || [];
  29802. this.__wrappedMethods.push(methodName);
  29803. this[methodName] = function () {
  29804. var res = originalMethod.apply(this, arguments);
  29805. return injectFunction.apply(this, [res].concat(slice(arguments)));
  29806. };
  29807. };
  29808. // ----------------------------------------------------------
  29809. // A work around for internal method visiting private member.
  29810. // ----------------------------------------------------------
  29811. SeriesData.internalField = function () {
  29812. prepareInvertedIndex = function (data) {
  29813. var invertedIndicesMap = data._invertedIndicesMap;
  29814. each(invertedIndicesMap, function (invertedIndices, dim) {
  29815. var dimInfo = data._dimInfos[dim];
  29816. // Currently, only dimensions that has ordinalMeta can create inverted indices.
  29817. var ordinalMeta = dimInfo.ordinalMeta;
  29818. var store = data._store;
  29819. if (ordinalMeta) {
  29820. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array$1(ordinalMeta.categories.length);
  29821. // The default value of TypedArray is 0. To avoid miss
  29822. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  29823. for (var i = 0; i < invertedIndices.length; i++) {
  29824. invertedIndices[i] = INDEX_NOT_FOUND;
  29825. }
  29826. for (var i = 0; i < store.count(); i++) {
  29827. // Only support the case that all values are distinct.
  29828. invertedIndices[store.get(dimInfo.storeDimIndex, i)] = i;
  29829. }
  29830. }
  29831. });
  29832. };
  29833. getIdNameFromStore = function (data, dimIdx, idx) {
  29834. return convertOptionIdName(data._getCategory(dimIdx, idx), null);
  29835. };
  29836. /**
  29837. * @see the comment of `List['getId']`.
  29838. */
  29839. getId = function (data, rawIndex) {
  29840. var id = data._idList[rawIndex];
  29841. if (id == null && data._idDimIdx != null) {
  29842. id = getIdNameFromStore(data, data._idDimIdx, rawIndex);
  29843. }
  29844. if (id == null) {
  29845. id = ID_PREFIX + rawIndex;
  29846. }
  29847. return id;
  29848. };
  29849. normalizeDimensions = function (dimensions) {
  29850. if (!isArray(dimensions)) {
  29851. dimensions = dimensions != null ? [dimensions] : [];
  29852. }
  29853. return dimensions;
  29854. };
  29855. /**
  29856. * Data in excludeDimensions is copied, otherwise transferred.
  29857. */
  29858. cloneListForMapAndSample = function (original) {
  29859. var list = new SeriesData(original._schema ? original._schema : map$1(original.dimensions, original._getDimInfo, original), original.hostModel);
  29860. // FIXME If needs stackedOn, value may already been stacked
  29861. transferProperties(list, original);
  29862. return list;
  29863. };
  29864. transferProperties = function (target, source) {
  29865. each(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  29866. if (source.hasOwnProperty(propName)) {
  29867. target[propName] = source[propName];
  29868. }
  29869. });
  29870. target.__wrappedMethods = source.__wrappedMethods;
  29871. each(CLONE_PROPERTIES, function (propName) {
  29872. target[propName] = clone(source[propName]);
  29873. });
  29874. target._calculationInfo = extend({}, source._calculationInfo);
  29875. };
  29876. makeIdFromName = function (data, idx) {
  29877. var nameList = data._nameList;
  29878. var idList = data._idList;
  29879. var nameDimIdx = data._nameDimIdx;
  29880. var idDimIdx = data._idDimIdx;
  29881. var name = nameList[idx];
  29882. var id = idList[idx];
  29883. if (name == null && nameDimIdx != null) {
  29884. nameList[idx] = name = getIdNameFromStore(data, nameDimIdx, idx);
  29885. }
  29886. if (id == null && idDimIdx != null) {
  29887. idList[idx] = id = getIdNameFromStore(data, idDimIdx, idx);
  29888. }
  29889. if (id == null && name != null) {
  29890. var nameRepeatCount = data._nameRepeatCount;
  29891. var nmCnt = nameRepeatCount[name] = (nameRepeatCount[name] || 0) + 1;
  29892. id = name;
  29893. if (nmCnt > 1) {
  29894. id += '__ec__' + nmCnt;
  29895. }
  29896. idList[idx] = id;
  29897. }
  29898. };
  29899. }();
  29900. return SeriesData;
  29901. }();
  29902. /**
  29903. * For outside usage compat (like echarts-gl are using it).
  29904. */
  29905. function createDimensions(source, opt) {
  29906. return prepareSeriesDataSchema(source, opt).dimensions;
  29907. }
  29908. /**
  29909. * This method builds the relationship between:
  29910. * + "what the coord sys or series requires (see `coordDimensions`)",
  29911. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimensionsDefine` and `opt.encodeDefine`)"
  29912. * + "what the data source provids (see `source`)".
  29913. *
  29914. * Some guess strategy will be adapted if user does not define something.
  29915. * If no 'value' dimension specified, the first no-named dimension will be
  29916. * named as 'value'.
  29917. *
  29918. * @return The results are always sorted by `storeDimIndex` asc.
  29919. */
  29920. function prepareSeriesDataSchema(
  29921. // TODO: TYPE completeDimensions type
  29922. source, opt) {
  29923. if (!isSourceInstance(source)) {
  29924. source = createSourceFromSeriesDataOption(source);
  29925. }
  29926. opt = opt || {};
  29927. var sysDims = opt.coordDimensions || [];
  29928. var dimsDef = opt.dimensionsDefine || source.dimensionsDefine || [];
  29929. var coordDimNameMap = createHashMap();
  29930. var resultList = [];
  29931. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimensionsCount);
  29932. // Try to ignore unused dimensions if sharing a high dimension datastore
  29933. // 30 is an experience value.
  29934. var omitUnusedDimensions = opt.canOmitUnusedDimensions && shouldOmitUnusedDimensions(dimCount);
  29935. var isUsingSourceDimensionsDef = dimsDef === source.dimensionsDefine;
  29936. var dataDimNameMap = isUsingSourceDimensionsDef ? ensureSourceDimNameMap(source) : createDimNameMap(dimsDef);
  29937. var encodeDef = opt.encodeDefine;
  29938. if (!encodeDef && opt.encodeDefaulter) {
  29939. encodeDef = opt.encodeDefaulter(source, dimCount);
  29940. }
  29941. var encodeDefMap = createHashMap(encodeDef);
  29942. var indicesMap = new CtorInt32Array(dimCount);
  29943. for (var i = 0; i < indicesMap.length; i++) {
  29944. indicesMap[i] = -1;
  29945. }
  29946. function getResultItem(dimIdx) {
  29947. var idx = indicesMap[dimIdx];
  29948. if (idx < 0) {
  29949. var dimDefItemRaw = dimsDef[dimIdx];
  29950. var dimDefItem = isObject(dimDefItemRaw) ? dimDefItemRaw : {
  29951. name: dimDefItemRaw
  29952. };
  29953. var resultItem = new SeriesDimensionDefine();
  29954. var userDimName = dimDefItem.name;
  29955. if (userDimName != null && dataDimNameMap.get(userDimName) != null) {
  29956. // Only if `series.dimensions` is defined in option
  29957. // displayName, will be set, and dimension will be displayed vertically in
  29958. // tooltip by default.
  29959. resultItem.name = resultItem.displayName = userDimName;
  29960. }
  29961. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  29962. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  29963. var newIdx = resultList.length;
  29964. indicesMap[dimIdx] = newIdx;
  29965. resultItem.storeDimIndex = dimIdx;
  29966. resultList.push(resultItem);
  29967. return resultItem;
  29968. }
  29969. return resultList[idx];
  29970. }
  29971. if (!omitUnusedDimensions) {
  29972. for (var i = 0; i < dimCount; i++) {
  29973. getResultItem(i);
  29974. }
  29975. }
  29976. // Set `coordDim` and `coordDimIndex` by `encodeDefMap` and normalize `encodeDefMap`.
  29977. encodeDefMap.each(function (dataDimsRaw, coordDim) {
  29978. var dataDims = normalizeToArray(dataDimsRaw).slice();
  29979. // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  29980. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  29981. // this case.
  29982. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  29983. encodeDefMap.set(coordDim, false);
  29984. return;
  29985. }
  29986. var validDataDims = encodeDefMap.set(coordDim, []);
  29987. each(dataDims, function (resultDimIdxOrName, idx) {
  29988. // The input resultDimIdx can be dim name or index.
  29989. var resultDimIdx = isString(resultDimIdxOrName) ? dataDimNameMap.get(resultDimIdxOrName) : resultDimIdxOrName;
  29990. if (resultDimIdx != null && resultDimIdx < dimCount) {
  29991. validDataDims[idx] = resultDimIdx;
  29992. applyDim(getResultItem(resultDimIdx), coordDim, idx);
  29993. }
  29994. });
  29995. });
  29996. // Apply templates and default order from `sysDims`.
  29997. var availDimIdx = 0;
  29998. each(sysDims, function (sysDimItemRaw) {
  29999. var coordDim;
  30000. var sysDimItemDimsDef;
  30001. var sysDimItemOtherDims;
  30002. var sysDimItem;
  30003. if (isString(sysDimItemRaw)) {
  30004. coordDim = sysDimItemRaw;
  30005. sysDimItem = {};
  30006. } else {
  30007. sysDimItem = sysDimItemRaw;
  30008. coordDim = sysDimItem.name;
  30009. var ordinalMeta = sysDimItem.ordinalMeta;
  30010. sysDimItem.ordinalMeta = null;
  30011. sysDimItem = extend({}, sysDimItem);
  30012. sysDimItem.ordinalMeta = ordinalMeta;
  30013. // `coordDimIndex` should not be set directly.
  30014. sysDimItemDimsDef = sysDimItem.dimsDef;
  30015. sysDimItemOtherDims = sysDimItem.otherDims;
  30016. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  30017. }
  30018. var dataDims = encodeDefMap.get(coordDim);
  30019. // negative resultDimIdx means no need to mapping.
  30020. if (dataDims === false) {
  30021. return;
  30022. }
  30023. dataDims = normalizeToArray(dataDims);
  30024. // dimensions provides default dim sequences.
  30025. if (!dataDims.length) {
  30026. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  30027. while (availDimIdx < dimCount && getResultItem(availDimIdx).coordDim != null) {
  30028. availDimIdx++;
  30029. }
  30030. availDimIdx < dimCount && dataDims.push(availDimIdx++);
  30031. }
  30032. }
  30033. // Apply templates.
  30034. each(dataDims, function (resultDimIdx, coordDimIndex) {
  30035. var resultItem = getResultItem(resultDimIdx);
  30036. // Coordinate system has a higher priority on dim type than source.
  30037. if (isUsingSourceDimensionsDef && sysDimItem.type != null) {
  30038. resultItem.type = sysDimItem.type;
  30039. }
  30040. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  30041. if (resultItem.name == null && sysDimItemDimsDef) {
  30042. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  30043. !isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
  30044. name: sysDimItemDimsDefItem
  30045. });
  30046. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  30047. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  30048. }
  30049. // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  30050. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  30051. });
  30052. });
  30053. function applyDim(resultItem, coordDim, coordDimIndex) {
  30054. if (VISUAL_DIMENSIONS.get(coordDim) != null) {
  30055. resultItem.otherDims[coordDim] = coordDimIndex;
  30056. } else {
  30057. resultItem.coordDim = coordDim;
  30058. resultItem.coordDimIndex = coordDimIndex;
  30059. coordDimNameMap.set(coordDim, true);
  30060. }
  30061. }
  30062. // Make sure the first extra dim is 'value'.
  30063. var generateCoord = opt.generateCoord;
  30064. var generateCoordCount = opt.generateCoordCount;
  30065. var fromZero = generateCoordCount != null;
  30066. generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
  30067. var extra = generateCoord || 'value';
  30068. function ifNoNameFillWithCoordName(resultItem) {
  30069. if (resultItem.name == null) {
  30070. // Duplication will be removed in the next step.
  30071. resultItem.name = resultItem.coordDim;
  30072. }
  30073. }
  30074. // Set dim `name` and other `coordDim` and other props.
  30075. if (!omitUnusedDimensions) {
  30076. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  30077. var resultItem = getResultItem(resultDimIdx);
  30078. var coordDim = resultItem.coordDim;
  30079. if (coordDim == null) {
  30080. // TODO no need to generate coordDim for isExtraCoord?
  30081. resultItem.coordDim = genCoordDimName(extra, coordDimNameMap, fromZero);
  30082. resultItem.coordDimIndex = 0;
  30083. // Series specified generateCoord is using out.
  30084. if (!generateCoord || generateCoordCount <= 0) {
  30085. resultItem.isExtraCoord = true;
  30086. }
  30087. generateCoordCount--;
  30088. }
  30089. ifNoNameFillWithCoordName(resultItem);
  30090. if (resultItem.type == null && (guessOrdinal(source, resultDimIdx) === BE_ORDINAL.Must
  30091. // Consider the case:
  30092. // {
  30093. // dataset: {source: [
  30094. // ['2001', 123],
  30095. // ['2002', 456],
  30096. // ...
  30097. // ['The others', 987],
  30098. // ]},
  30099. // series: {type: 'pie'}
  30100. // }
  30101. // The first column should better be treated as a "ordinal" although it
  30102. // might not be detected as an "ordinal" by `guessOrdinal`.
  30103. || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
  30104. resultItem.type = 'ordinal';
  30105. }
  30106. }
  30107. } else {
  30108. each(resultList, function (resultItem) {
  30109. // PENDING: guessOrdinal or let user specify type: 'ordinal' manually?
  30110. ifNoNameFillWithCoordName(resultItem);
  30111. });
  30112. // Sort dimensions: there are some rule that use the last dim as label,
  30113. // and for some latter travel process easier.
  30114. resultList.sort(function (item0, item1) {
  30115. return item0.storeDimIndex - item1.storeDimIndex;
  30116. });
  30117. }
  30118. removeDuplication(resultList);
  30119. return new SeriesDataSchema({
  30120. source: source,
  30121. dimensions: resultList,
  30122. fullDimensionCount: dimCount,
  30123. dimensionOmitted: omitUnusedDimensions
  30124. });
  30125. }
  30126. function removeDuplication(result) {
  30127. var duplicationMap = createHashMap();
  30128. for (var i = 0; i < result.length; i++) {
  30129. var dim = result[i];
  30130. var dimOriginalName = dim.name;
  30131. var count = duplicationMap.get(dimOriginalName) || 0;
  30132. if (count > 0) {
  30133. // Starts from 0.
  30134. dim.name = dimOriginalName + (count - 1);
  30135. }
  30136. count++;
  30137. duplicationMap.set(dimOriginalName, count);
  30138. }
  30139. }
  30140. // ??? TODO
  30141. // Originally detect dimCount by data[0]. Should we
  30142. // optimize it to only by sysDims and dimensions and encode.
  30143. // So only necessary dims will be initialized.
  30144. // But
  30145. // (1) custom series should be considered. where other dims
  30146. // may be visited.
  30147. // (2) sometimes user need to calculate bubble size or use visualMap
  30148. // on other dimensions besides coordSys needed.
  30149. // So, dims that is not used by system, should be shared in data store?
  30150. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  30151. // Note that the result dimCount should not small than columns count
  30152. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  30153. var dimCount = Math.max(source.dimensionsDetectedCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
  30154. each(sysDims, function (sysDimItem) {
  30155. var sysDimItemDimsDef;
  30156. if (isObject(sysDimItem) && (sysDimItemDimsDef = sysDimItem.dimsDef)) {
  30157. dimCount = Math.max(dimCount, sysDimItemDimsDef.length);
  30158. }
  30159. });
  30160. return dimCount;
  30161. }
  30162. function genCoordDimName(name, map, fromZero) {
  30163. if (fromZero || map.hasKey(name)) {
  30164. var i = 0;
  30165. while (map.hasKey(name + i)) {
  30166. i++;
  30167. }
  30168. name += i;
  30169. }
  30170. map.set(name, true);
  30171. return name;
  30172. }
  30173. /**
  30174. * @class
  30175. * For example:
  30176. * {
  30177. * coordSysName: 'cartesian2d',
  30178. * coordSysDims: ['x', 'y', ...],
  30179. * axisMap: HashMap({
  30180. * x: xAxisModel,
  30181. * y: yAxisModel
  30182. * }),
  30183. * categoryAxisMap: HashMap({
  30184. * x: xAxisModel,
  30185. * y: undefined
  30186. * }),
  30187. * // The index of the first category axis in `coordSysDims`.
  30188. * // `null/undefined` means no category axis exists.
  30189. * firstCategoryDimIndex: 1,
  30190. * // To replace user specified encode.
  30191. * }
  30192. */
  30193. var CoordSysInfo = /** @class */function () {
  30194. function CoordSysInfo(coordSysName) {
  30195. this.coordSysDims = [];
  30196. this.axisMap = createHashMap();
  30197. this.categoryAxisMap = createHashMap();
  30198. this.coordSysName = coordSysName;
  30199. }
  30200. return CoordSysInfo;
  30201. }();
  30202. function getCoordSysInfoBySeries(seriesModel) {
  30203. var coordSysName = seriesModel.get('coordinateSystem');
  30204. var result = new CoordSysInfo(coordSysName);
  30205. var fetch = fetchers[coordSysName];
  30206. if (fetch) {
  30207. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  30208. return result;
  30209. }
  30210. }
  30211. // TODO: refactor them to static member of each coord sys, rather than hard code here.
  30212. var fetchers = {
  30213. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  30214. var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  30215. var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  30216. if ("development" !== 'production') {
  30217. if (!xAxisModel) {
  30218. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  30219. }
  30220. if (!yAxisModel) {
  30221. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  30222. }
  30223. }
  30224. result.coordSysDims = ['x', 'y'];
  30225. axisMap.set('x', xAxisModel);
  30226. axisMap.set('y', yAxisModel);
  30227. if (isCategory(xAxisModel)) {
  30228. categoryAxisMap.set('x', xAxisModel);
  30229. result.firstCategoryDimIndex = 0;
  30230. }
  30231. if (isCategory(yAxisModel)) {
  30232. categoryAxisMap.set('y', yAxisModel);
  30233. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  30234. }
  30235. },
  30236. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  30237. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  30238. if ("development" !== 'production') {
  30239. if (!singleAxisModel) {
  30240. throw new Error('singleAxis should be specified.');
  30241. }
  30242. }
  30243. result.coordSysDims = ['single'];
  30244. axisMap.set('single', singleAxisModel);
  30245. if (isCategory(singleAxisModel)) {
  30246. categoryAxisMap.set('single', singleAxisModel);
  30247. result.firstCategoryDimIndex = 0;
  30248. }
  30249. },
  30250. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  30251. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  30252. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  30253. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  30254. if ("development" !== 'production') {
  30255. if (!angleAxisModel) {
  30256. throw new Error('angleAxis option not found');
  30257. }
  30258. if (!radiusAxisModel) {
  30259. throw new Error('radiusAxis option not found');
  30260. }
  30261. }
  30262. result.coordSysDims = ['radius', 'angle'];
  30263. axisMap.set('radius', radiusAxisModel);
  30264. axisMap.set('angle', angleAxisModel);
  30265. if (isCategory(radiusAxisModel)) {
  30266. categoryAxisMap.set('radius', radiusAxisModel);
  30267. result.firstCategoryDimIndex = 0;
  30268. }
  30269. if (isCategory(angleAxisModel)) {
  30270. categoryAxisMap.set('angle', angleAxisModel);
  30271. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  30272. }
  30273. },
  30274. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  30275. result.coordSysDims = ['lng', 'lat'];
  30276. },
  30277. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  30278. var ecModel = seriesModel.ecModel;
  30279. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  30280. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  30281. each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  30282. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  30283. var axisDim = coordSysDims[index];
  30284. axisMap.set(axisDim, axisModel);
  30285. if (isCategory(axisModel)) {
  30286. categoryAxisMap.set(axisDim, axisModel);
  30287. if (result.firstCategoryDimIndex == null) {
  30288. result.firstCategoryDimIndex = index;
  30289. }
  30290. }
  30291. });
  30292. },
  30293. matrix: function (seriesModel, result, axisMap, categoryAxisMap) {
  30294. var matrixModel = seriesModel.getReferringComponents('matrix', SINGLE_REFERRING).models[0];
  30295. if ("development" !== 'production') {
  30296. if (!matrixModel) {
  30297. throw new Error('matrix coordinate system should be specified.');
  30298. }
  30299. }
  30300. result.coordSysDims = ['x', 'y'];
  30301. var xModel = matrixModel.getDimensionModel('x');
  30302. var yModel = matrixModel.getDimensionModel('y');
  30303. axisMap.set('x', xModel);
  30304. axisMap.set('y', yModel);
  30305. categoryAxisMap.set('x', xModel);
  30306. categoryAxisMap.set('y', yModel);
  30307. }
  30308. };
  30309. function isCategory(axisModel) {
  30310. return axisModel.get('type') === 'category';
  30311. }
  30312. /**
  30313. * Note that it is too complicated to support 3d stack by value
  30314. * (have to create two-dimension inverted index), so in 3d case
  30315. * we just support that stacked by index.
  30316. *
  30317. * @param seriesModel
  30318. * @param dimensionsInput The same as the input of <module:echarts/data/SeriesData>.
  30319. * The input will be modified.
  30320. * @param opt
  30321. * @param opt.stackedCoordDimension Specify a coord dimension if needed.
  30322. * @param opt.byIndex=false
  30323. * @return calculationInfo
  30324. * {
  30325. * stackedDimension: string
  30326. * stackedByDimension: string
  30327. * isStackedByIndex: boolean
  30328. * stackedOverDimension: string
  30329. * stackResultDimension: string
  30330. * }
  30331. */
  30332. function enableDataStack(seriesModel, dimensionsInput, opt) {
  30333. opt = opt || {};
  30334. var byIndex = opt.byIndex;
  30335. var stackedCoordDimension = opt.stackedCoordDimension;
  30336. var dimensionDefineList;
  30337. var schema;
  30338. var store;
  30339. if (isLegacyDimensionsInput(dimensionsInput)) {
  30340. dimensionDefineList = dimensionsInput;
  30341. } else {
  30342. schema = dimensionsInput.schema;
  30343. dimensionDefineList = schema.dimensions;
  30344. store = dimensionsInput.store;
  30345. }
  30346. // Compatibal: when `stack` is set as '', do not stack.
  30347. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  30348. var stackedByDimInfo;
  30349. var stackedDimInfo;
  30350. var stackResultDimension;
  30351. var stackedOverDimension;
  30352. each(dimensionDefineList, function (dimensionInfo, index) {
  30353. if (isString(dimensionInfo)) {
  30354. dimensionDefineList[index] = dimensionInfo = {
  30355. name: dimensionInfo
  30356. };
  30357. }
  30358. if (mayStack && !dimensionInfo.isExtraCoord) {
  30359. // Find the first ordinal dimension as the stackedByDimInfo.
  30360. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  30361. stackedByDimInfo = dimensionInfo;
  30362. }
  30363. // Find the first stackable dimension as the stackedDimInfo.
  30364. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  30365. stackedDimInfo = dimensionInfo;
  30366. }
  30367. }
  30368. });
  30369. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  30370. // Compatible with previous design, value axis (time axis) only stack by index.
  30371. // It may make sense if the user provides elaborately constructed data.
  30372. byIndex = true;
  30373. }
  30374. // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  30375. // That put stack logic in List is for using conveniently in echarts extensions, but it
  30376. // might not be a good way.
  30377. if (stackedDimInfo) {
  30378. // Use a weird name that not duplicated with other names.
  30379. // Also need to use seriesModel.id as postfix because different
  30380. // series may share same data store. The stack dimension needs to be distinguished.
  30381. stackResultDimension = '__\0ecstackresult_' + seriesModel.id;
  30382. stackedOverDimension = '__\0ecstackedover_' + seriesModel.id;
  30383. // Create inverted index to fast query index by value.
  30384. if (stackedByDimInfo) {
  30385. stackedByDimInfo.createInvertedIndices = true;
  30386. }
  30387. var stackedDimCoordDim_1 = stackedDimInfo.coordDim;
  30388. var stackedDimType = stackedDimInfo.type;
  30389. var stackedDimCoordIndex_1 = 0;
  30390. each(dimensionDefineList, function (dimensionInfo) {
  30391. if (dimensionInfo.coordDim === stackedDimCoordDim_1) {
  30392. stackedDimCoordIndex_1++;
  30393. }
  30394. });
  30395. var stackedOverDimensionDefine = {
  30396. name: stackResultDimension,
  30397. coordDim: stackedDimCoordDim_1,
  30398. coordDimIndex: stackedDimCoordIndex_1,
  30399. type: stackedDimType,
  30400. isExtraCoord: true,
  30401. isCalculationCoord: true,
  30402. storeDimIndex: dimensionDefineList.length
  30403. };
  30404. var stackResultDimensionDefine = {
  30405. name: stackedOverDimension,
  30406. // This dimension contains stack base (generally, 0), so do not set it as
  30407. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  30408. coordDim: stackedOverDimension,
  30409. coordDimIndex: stackedDimCoordIndex_1 + 1,
  30410. type: stackedDimType,
  30411. isExtraCoord: true,
  30412. isCalculationCoord: true,
  30413. storeDimIndex: dimensionDefineList.length + 1
  30414. };
  30415. if (schema) {
  30416. if (store) {
  30417. stackedOverDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackedOverDimension, stackedDimType);
  30418. stackResultDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackResultDimension, stackedDimType);
  30419. }
  30420. schema.appendCalculationDimension(stackedOverDimensionDefine);
  30421. schema.appendCalculationDimension(stackResultDimensionDefine);
  30422. } else {
  30423. dimensionDefineList.push(stackedOverDimensionDefine);
  30424. dimensionDefineList.push(stackResultDimensionDefine);
  30425. }
  30426. }
  30427. return {
  30428. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  30429. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  30430. isStackedByIndex: byIndex,
  30431. stackedOverDimension: stackedOverDimension,
  30432. stackResultDimension: stackResultDimension
  30433. };
  30434. }
  30435. function isLegacyDimensionsInput(dimensionsInput) {
  30436. return !isSeriesDataSchema(dimensionsInput.schema);
  30437. }
  30438. function isDimensionStacked(data, stackedDim) {
  30439. // Each single series only maps to one pair of axis. So we do not need to
  30440. // check stackByDim, whatever stacked by a dimension or stacked by index.
  30441. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  30442. }
  30443. function getStackedDimension(data, targetDim) {
  30444. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  30445. }
  30446. function getCoordSysDimDefs(seriesModel, coordSysInfo) {
  30447. var coordSysName = seriesModel.get('coordinateSystem');
  30448. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  30449. var coordSysDimDefs;
  30450. if (coordSysInfo && coordSysInfo.coordSysDims) {
  30451. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  30452. var dimInfo = {
  30453. name: dim
  30454. };
  30455. var axisModel = coordSysInfo.axisMap.get(dim);
  30456. if (axisModel) {
  30457. var axisType = axisModel.get('type');
  30458. dimInfo.type = getDimensionTypeByAxis(axisType);
  30459. }
  30460. return dimInfo;
  30461. });
  30462. }
  30463. if (!coordSysDimDefs) {
  30464. // Get dimensions from registered coordinate system
  30465. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  30466. }
  30467. return coordSysDimDefs;
  30468. }
  30469. function injectOrdinalMeta(dimInfoList, createInvertedIndices, coordSysInfo) {
  30470. var firstCategoryDimIndex;
  30471. var hasNameEncode;
  30472. coordSysInfo && each(dimInfoList, function (dimInfo, dimIndex) {
  30473. var coordDim = dimInfo.coordDim;
  30474. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  30475. if (categoryAxisModel) {
  30476. if (firstCategoryDimIndex == null) {
  30477. firstCategoryDimIndex = dimIndex;
  30478. }
  30479. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  30480. if (createInvertedIndices) {
  30481. dimInfo.createInvertedIndices = true;
  30482. }
  30483. }
  30484. if (dimInfo.otherDims.itemName != null) {
  30485. hasNameEncode = true;
  30486. }
  30487. });
  30488. if (!hasNameEncode && firstCategoryDimIndex != null) {
  30489. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  30490. }
  30491. return firstCategoryDimIndex;
  30492. }
  30493. /**
  30494. * Caution: there are side effects to `sourceManager` in this method.
  30495. * Should better only be called in `Series['getInitialData']`.
  30496. */
  30497. function createSeriesData(sourceRaw, seriesModel, opt) {
  30498. opt = opt || {};
  30499. var sourceManager = seriesModel.getSourceManager();
  30500. var source;
  30501. var isOriginalSource = false;
  30502. if (sourceRaw) {
  30503. isOriginalSource = true;
  30504. source = createSourceFromSeriesDataOption(sourceRaw);
  30505. } else {
  30506. source = sourceManager.getSource();
  30507. // Is series.data. not dataset.
  30508. isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
  30509. }
  30510. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  30511. var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
  30512. var useEncodeDefaulter = opt.useEncodeDefaulter;
  30513. var encodeDefaulter = isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
  30514. var createDimensionOptions = {
  30515. coordDimensions: coordSysDimDefs,
  30516. generateCoord: opt.generateCoord,
  30517. encodeDefine: seriesModel.getEncode(),
  30518. encodeDefaulter: encodeDefaulter,
  30519. canOmitUnusedDimensions: !isOriginalSource
  30520. };
  30521. var schema = prepareSeriesDataSchema(source, createDimensionOptions);
  30522. var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
  30523. var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
  30524. var stackCalculationInfo = enableDataStack(seriesModel, {
  30525. schema: schema,
  30526. store: store
  30527. });
  30528. var data = new SeriesData(schema, seriesModel);
  30529. data.setCalculationInfo(stackCalculationInfo);
  30530. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source)
  30531. /**
  30532. * This serves this case:
  30533. * var echarts_option = {
  30534. * xAxis: { data: ['a', 'b', 'c'] },
  30535. * yAxis: {}
  30536. * series: { data: [555, 666, 777] }
  30537. * };
  30538. * The `series.data` is completed to:
  30539. * [[0, 555], [1, 666], [2, 777]]
  30540. */ ? function (itemOpt, dimName, dataIndex, dimIndex) {
  30541. // Use dataIndex as ordinal value in categoryAxis
  30542. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  30543. } : null;
  30544. data.hasItemOption = false;
  30545. data.initData(
  30546. // Try to reuse the data store in sourceManager if using dataset.
  30547. isOriginalSource ? source : store, null, dimValueGetter);
  30548. return data;
  30549. }
  30550. function isNeedCompleteOrdinalData(source) {
  30551. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  30552. var sampleItem = firstDataNotNull(source.data || []);
  30553. return !isArray(getDataItemValue(sampleItem));
  30554. }
  30555. }
  30556. function firstDataNotNull(arr) {
  30557. var i = 0;
  30558. while (i < arr.length && arr[i] == null) {
  30559. i++;
  30560. }
  30561. return arr[i];
  30562. }
  30563. function isValueNice(val) {
  30564. var exp10 = Math.pow(10, quantityExponent(Math.abs(val)));
  30565. var f = Math.abs(val / exp10);
  30566. return f === 0 || f === 1 || f === 2 || f === 3 || f === 5;
  30567. }
  30568. function isIntervalOrLogScale(scale) {
  30569. return scale.type === 'interval' || scale.type === 'log';
  30570. }
  30571. /**
  30572. * @param extent Both extent[0] and extent[1] should be valid number.
  30573. * Should be extent[0] < extent[1].
  30574. * @param splitNumber splitNumber should be >= 1.
  30575. */
  30576. function intervalScaleNiceTicks(extent, spanWithBreaks, splitNumber, minInterval, maxInterval) {
  30577. var result = {};
  30578. var interval = result.interval = nice(spanWithBreaks / splitNumber, true);
  30579. if (minInterval != null && interval < minInterval) {
  30580. interval = result.interval = minInterval;
  30581. }
  30582. if (maxInterval != null && interval > maxInterval) {
  30583. interval = result.interval = maxInterval;
  30584. }
  30585. // Tow more digital for tick.
  30586. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  30587. // Niced extent inside original extent
  30588. var niceTickExtent = result.niceTickExtent = [round(Math.ceil(extent[0] / interval) * interval, precision), round(Math.floor(extent[1] / interval) * interval, precision)];
  30589. fixExtent(niceTickExtent, extent);
  30590. return result;
  30591. }
  30592. function increaseInterval(interval) {
  30593. var exp10 = Math.pow(10, quantityExponent(interval));
  30594. // Increase interval
  30595. var f = interval / exp10;
  30596. if (!f) {
  30597. f = 1;
  30598. } else if (f === 2) {
  30599. f = 3;
  30600. } else if (f === 3) {
  30601. f = 5;
  30602. } else {
  30603. // f is 1 or 5
  30604. f *= 2;
  30605. }
  30606. return round(f * exp10);
  30607. }
  30608. /**
  30609. * @return interval precision
  30610. */
  30611. function getIntervalPrecision(interval) {
  30612. // Tow more digital for tick.
  30613. return getPrecision(interval) + 2;
  30614. }
  30615. function clamp(niceTickExtent, idx, extent) {
  30616. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  30617. }
  30618. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  30619. function fixExtent(niceTickExtent, extent) {
  30620. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  30621. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  30622. clamp(niceTickExtent, 0, extent);
  30623. clamp(niceTickExtent, 1, extent);
  30624. if (niceTickExtent[0] > niceTickExtent[1]) {
  30625. niceTickExtent[0] = niceTickExtent[1];
  30626. }
  30627. }
  30628. function contain$1(val, extent) {
  30629. return val >= extent[0] && val <= extent[1];
  30630. }
  30631. var ScaleCalculator = /** @class */function () {
  30632. function ScaleCalculator() {
  30633. this.normalize = normalize$1;
  30634. this.scale = scale$2;
  30635. }
  30636. ScaleCalculator.prototype.updateMethods = function (brkCtx) {
  30637. if (brkCtx.hasBreaks()) {
  30638. this.normalize = bind(brkCtx.normalize, brkCtx);
  30639. this.scale = bind(brkCtx.scale, brkCtx);
  30640. } else {
  30641. this.normalize = normalize$1;
  30642. this.scale = scale$2;
  30643. }
  30644. };
  30645. return ScaleCalculator;
  30646. }();
  30647. function normalize$1(val, extent) {
  30648. if (extent[1] === extent[0]) {
  30649. return 0.5;
  30650. }
  30651. return (val - extent[0]) / (extent[1] - extent[0]);
  30652. }
  30653. function scale$2(val, extent) {
  30654. return val * (extent[1] - extent[0]) + extent[0];
  30655. }
  30656. function logTransform(base, extent, noClampNegative) {
  30657. var loggedBase = Math.log(base);
  30658. return [
  30659. // log(negative) is NaN, so safe guard here.
  30660. // PENDING: But even getting a -Infinity still does not make sense in extent.
  30661. // Just keep it as is, getting a NaN to make some previous cases works by coincidence.
  30662. Math.log(noClampNegative ? extent[0] : Math.max(0, extent[0])) / loggedBase, Math.log(noClampNegative ? extent[1] : Math.max(0, extent[1])) / loggedBase];
  30663. }
  30664. var Scale = /** @class */function () {
  30665. function Scale(setting) {
  30666. this._calculator = new ScaleCalculator();
  30667. this._setting = setting || {};
  30668. this._extent = [Infinity, -Infinity];
  30669. }
  30670. Scale.prototype.getSetting = function (name) {
  30671. return this._setting[name];
  30672. };
  30673. /**
  30674. * [CAVEAT]: It should not be overridden!
  30675. */
  30676. Scale.prototype._innerUnionExtent = function (other) {
  30677. var extent = this._extent;
  30678. // Considered that number could be NaN and should not write into the extent.
  30679. this._innerSetExtent(other[0] < extent[0] ? other[0] : extent[0], other[1] > extent[1] ? other[1] : extent[1]);
  30680. };
  30681. /**
  30682. * Set extent from data
  30683. */
  30684. Scale.prototype.unionExtentFromData = function (data, dim) {
  30685. this._innerUnionExtent(data.getApproximateExtent(dim));
  30686. };
  30687. /**
  30688. * Get a new slice of extent.
  30689. * Extent is always in increase order.
  30690. */
  30691. Scale.prototype.getExtent = function () {
  30692. return this._extent.slice();
  30693. };
  30694. Scale.prototype.setExtent = function (start, end) {
  30695. this._innerSetExtent(start, end);
  30696. };
  30697. /**
  30698. * [CAVEAT]: It should not be overridden!
  30699. */
  30700. Scale.prototype._innerSetExtent = function (start, end) {
  30701. var thisExtent = this._extent;
  30702. if (!isNaN(start)) {
  30703. thisExtent[0] = start;
  30704. }
  30705. if (!isNaN(end)) {
  30706. thisExtent[1] = end;
  30707. }
  30708. this._brkCtx && this._brkCtx.update(thisExtent);
  30709. };
  30710. /**
  30711. * Prerequisite: Scale#parse is ready.
  30712. */
  30713. Scale.prototype.setBreaksFromOption = function (breakOptionList) {
  30714. };
  30715. /**
  30716. * [CAVEAT]: It should not be overridden!
  30717. */
  30718. Scale.prototype._innerSetBreak = function (parsed) {
  30719. if (this._brkCtx) {
  30720. this._brkCtx.setBreaks(parsed);
  30721. this._calculator.updateMethods(this._brkCtx);
  30722. this._brkCtx.update(this._extent);
  30723. }
  30724. };
  30725. /**
  30726. * [CAVEAT]: It should not be overridden!
  30727. */
  30728. Scale.prototype._innerGetBreaks = function () {
  30729. return this._brkCtx ? this._brkCtx.breaks : [];
  30730. };
  30731. /**
  30732. * Do not expose the internal `_breaks` unless necessary.
  30733. */
  30734. Scale.prototype.hasBreaks = function () {
  30735. return this._brkCtx ? this._brkCtx.hasBreaks() : false;
  30736. };
  30737. Scale.prototype._getExtentSpanWithBreaks = function () {
  30738. return this._brkCtx && this._brkCtx.hasBreaks() ? this._brkCtx.getExtentSpan() : this._extent[1] - this._extent[0];
  30739. };
  30740. /**
  30741. * If value is in extent range
  30742. */
  30743. Scale.prototype.isInExtentRange = function (value) {
  30744. return this._extent[0] <= value && this._extent[1] >= value;
  30745. };
  30746. /**
  30747. * When axis extent depends on data and no data exists,
  30748. * axis ticks should not be drawn, which is named 'blank'.
  30749. */
  30750. Scale.prototype.isBlank = function () {
  30751. return this._isBlank;
  30752. };
  30753. /**
  30754. * When axis extent depends on data and no data exists,
  30755. * axis ticks should not be drawn, which is named 'blank'.
  30756. */
  30757. Scale.prototype.setBlank = function (isBlank) {
  30758. this._isBlank = isBlank;
  30759. };
  30760. return Scale;
  30761. }();
  30762. enableClassManagement(Scale);
  30763. var uidBase = 0;
  30764. var OrdinalMeta = /** @class */function () {
  30765. /**
  30766. * PENDING - Regarding forcibly converting to string:
  30767. * In the early days, the underlying hash map impl used JS plain object and converted the key to
  30768. * string; later in https://github.com/ecomfe/zrender/pull/966 it was changed to a JS Map (in supported
  30769. * platforms), which does not require string keys. But consider any input that `scale/Ordinal['parse']`
  30770. * is involved, a number input represents an `OrdinalNumber` (i.e., an index), and affect the query
  30771. * behavior:
  30772. * - If forcbily converting to string:
  30773. * pros: users can use numeric string (such as, '123') to query the raw data (123), tho it's probably
  30774. * still confusing.
  30775. * cons: NaN/null/undefined in data will be equals to 'NaN'/'null'/'undefined', if simply using
  30776. * `val + ''` to convert them, like currently `getName` does.
  30777. * - Otherwise:
  30778. * pros: see NaN/null/undefined case above.
  30779. * cons: users cannot query the raw data (123) any more.
  30780. * There are two inconsistent behaviors in the current impl:
  30781. * - Force conversion is applied on the case `xAxis{data: ['aaa', 'bbb', ...]}`,
  30782. * but no conversion applied to the case `xAxis{data: [{value: 'aaa'}, ...]}` and
  30783. * the case `dataset: {source: [['aaa', 123], ['bbb', 234], ...]}`.
  30784. * - behaves differently according to whether JS Map is supported (the polyfill is simply using JS
  30785. * plain object) (tho it seems rare platform that do not support it).
  30786. * Since there's no sufficient good solution to offset cost of the breaking change, we preserve the
  30787. * current behavior, until real issues is reported.
  30788. */
  30789. function OrdinalMeta(opt) {
  30790. this.categories = opt.categories || [];
  30791. this._needCollect = opt.needCollect;
  30792. this._deduplication = opt.deduplication;
  30793. this.uid = ++uidBase;
  30794. this._onCollect = opt.onCollect;
  30795. }
  30796. OrdinalMeta.createByAxisModel = function (axisModel) {
  30797. var option = axisModel.option;
  30798. var data = option.data;
  30799. var categories = data && map(data, getName);
  30800. return new OrdinalMeta({
  30801. categories: categories,
  30802. needCollect: !categories,
  30803. // deduplication is default in axis.
  30804. deduplication: option.dedplication !== false
  30805. });
  30806. };
  30807. OrdinalMeta.prototype.getOrdinal = function (category) {
  30808. return this._getOrCreateMap().get(category);
  30809. };
  30810. /**
  30811. * @return The ordinal. If not found, return NaN.
  30812. */
  30813. OrdinalMeta.prototype.parseAndCollect = function (category) {
  30814. var index;
  30815. var needCollect = this._needCollect;
  30816. // The value of category dim can be the index of the given category set.
  30817. // This feature is only supported when !needCollect, because we should
  30818. // consider a common case: a value is 2017, which is a number but is
  30819. // expected to be tread as a category. This case usually happen in dataset,
  30820. // where it happent to be no need of the index feature.
  30821. if (!isString(category) && !needCollect) {
  30822. return category;
  30823. }
  30824. // Optimize for the scenario:
  30825. // category is ['2012-01-01', '2012-01-02', ...], where the input
  30826. // data has been ensured not duplicate and is large data.
  30827. // Notice, if a dataset dimension provide categroies, usually echarts
  30828. // should remove duplication except user tell echarts dont do that
  30829. // (set axis.deduplication = false), because echarts do not know whether
  30830. // the values in the category dimension has duplication (consider the
  30831. // parallel-aqi example)
  30832. if (needCollect && !this._deduplication) {
  30833. index = this.categories.length;
  30834. this.categories[index] = category;
  30835. this._onCollect && this._onCollect(category, index);
  30836. return index;
  30837. }
  30838. var map = this._getOrCreateMap();
  30839. index = map.get(category);
  30840. if (index == null) {
  30841. if (needCollect) {
  30842. index = this.categories.length;
  30843. this.categories[index] = category;
  30844. map.set(category, index);
  30845. this._onCollect && this._onCollect(category, index);
  30846. } else {
  30847. index = NaN;
  30848. }
  30849. }
  30850. return index;
  30851. };
  30852. // Consider big data, do not create map until needed.
  30853. OrdinalMeta.prototype._getOrCreateMap = function () {
  30854. return this._map || (this._map = createHashMap(this.categories));
  30855. };
  30856. return OrdinalMeta;
  30857. }();
  30858. function getName(obj) {
  30859. if (isObject(obj) && obj.value != null) {
  30860. return obj.value;
  30861. } else {
  30862. return obj + '';
  30863. }
  30864. }
  30865. var OrdinalScale = /** @class */function (_super) {
  30866. __extends(OrdinalScale, _super);
  30867. function OrdinalScale(setting) {
  30868. var _this = _super.call(this, setting) || this;
  30869. _this.type = 'ordinal';
  30870. var ordinalMeta = _this.getSetting('ordinalMeta');
  30871. // Caution: Should not use instanceof, consider ec-extensions using
  30872. // import approach to get OrdinalMeta class.
  30873. if (!ordinalMeta) {
  30874. ordinalMeta = new OrdinalMeta({});
  30875. }
  30876. if (isArray(ordinalMeta)) {
  30877. ordinalMeta = new OrdinalMeta({
  30878. categories: map(ordinalMeta, function (item) {
  30879. return isObject(item) ? item.value : item;
  30880. })
  30881. });
  30882. }
  30883. _this._ordinalMeta = ordinalMeta;
  30884. _this._extent = _this.getSetting('extent') || [0, ordinalMeta.categories.length - 1];
  30885. return _this;
  30886. }
  30887. OrdinalScale.prototype.parse = function (val) {
  30888. // Caution: Math.round(null) will return `0` rather than `NaN`
  30889. if (val == null) {
  30890. return NaN;
  30891. }
  30892. return isString(val) ? this._ordinalMeta.getOrdinal(val)
  30893. // val might be float.
  30894. : Math.round(val);
  30895. };
  30896. OrdinalScale.prototype.contain = function (val) {
  30897. return contain$1(val, this._extent) && val >= 0 && val < this._ordinalMeta.categories.length;
  30898. };
  30899. /**
  30900. * Normalize given rank or name to linear [0, 1]
  30901. * @param val raw ordinal number.
  30902. * @return normalized value in [0, 1].
  30903. */
  30904. OrdinalScale.prototype.normalize = function (val) {
  30905. val = this._getTickNumber(val);
  30906. return this._calculator.normalize(val, this._extent);
  30907. };
  30908. /**
  30909. * @param val normalized value in [0, 1].
  30910. * @return raw ordinal number.
  30911. */
  30912. OrdinalScale.prototype.scale = function (val) {
  30913. val = Math.round(this._calculator.scale(val, this._extent));
  30914. return this.getRawOrdinalNumber(val);
  30915. };
  30916. OrdinalScale.prototype.getTicks = function () {
  30917. var ticks = [];
  30918. var extent = this._extent;
  30919. var rank = extent[0];
  30920. while (rank <= extent[1]) {
  30921. ticks.push({
  30922. value: rank
  30923. });
  30924. rank++;
  30925. }
  30926. return ticks;
  30927. };
  30928. OrdinalScale.prototype.getMinorTicks = function (splitNumber) {
  30929. // Not support.
  30930. return;
  30931. };
  30932. /**
  30933. * @see `Ordinal['_ordinalNumbersByTick']`
  30934. */
  30935. OrdinalScale.prototype.setSortInfo = function (info) {
  30936. if (info == null) {
  30937. this._ordinalNumbersByTick = this._ticksByOrdinalNumber = null;
  30938. return;
  30939. }
  30940. var infoOrdinalNumbers = info.ordinalNumbers;
  30941. var ordinalsByTick = this._ordinalNumbersByTick = [];
  30942. var ticksByOrdinal = this._ticksByOrdinalNumber = [];
  30943. // Unnecessary support negative tick in `realtimeSort`.
  30944. var tickNum = 0;
  30945. var allCategoryLen = this._ordinalMeta.categories.length;
  30946. for (var len = Math.min(allCategoryLen, infoOrdinalNumbers.length); tickNum < len; ++tickNum) {
  30947. var ordinalNumber = infoOrdinalNumbers[tickNum];
  30948. ordinalsByTick[tickNum] = ordinalNumber;
  30949. ticksByOrdinal[ordinalNumber] = tickNum;
  30950. }
  30951. // Handle that `series.data` only covers part of the `axis.category.data`.
  30952. var unusedOrdinal = 0;
  30953. for (; tickNum < allCategoryLen; ++tickNum) {
  30954. while (ticksByOrdinal[unusedOrdinal] != null) {
  30955. unusedOrdinal++;
  30956. }
  30957. ordinalsByTick.push(unusedOrdinal);
  30958. ticksByOrdinal[unusedOrdinal] = tickNum;
  30959. }
  30960. };
  30961. OrdinalScale.prototype._getTickNumber = function (ordinal) {
  30962. var ticksByOrdinalNumber = this._ticksByOrdinalNumber;
  30963. // also support ordinal out of range of `ordinalMeta.categories.length`,
  30964. // where ordinal numbers are used as tick value directly.
  30965. return ticksByOrdinalNumber && ordinal >= 0 && ordinal < ticksByOrdinalNumber.length ? ticksByOrdinalNumber[ordinal] : ordinal;
  30966. };
  30967. /**
  30968. * @usage
  30969. * ```js
  30970. * const ordinalNumber = ordinalScale.getRawOrdinalNumber(tickVal);
  30971. *
  30972. * // case0
  30973. * const rawOrdinalValue = axisModel.getCategories()[ordinalNumber];
  30974. * // case1
  30975. * const rawOrdinalValue = this._ordinalMeta.categories[ordinalNumber];
  30976. * // case2
  30977. * const coord = axis.dataToCoord(ordinalNumber);
  30978. * ```
  30979. *
  30980. * @param {OrdinalNumber} tickNumber index of display
  30981. */
  30982. OrdinalScale.prototype.getRawOrdinalNumber = function (tickNumber) {
  30983. var ordinalNumbersByTick = this._ordinalNumbersByTick;
  30984. // tickNumber may be out of range, e.g., when axis max is larger than `ordinalMeta.categories.length`.,
  30985. // where ordinal numbers are used as tick value directly.
  30986. return ordinalNumbersByTick && tickNumber >= 0 && tickNumber < ordinalNumbersByTick.length ? ordinalNumbersByTick[tickNumber] : tickNumber;
  30987. };
  30988. /**
  30989. * Get item on tick
  30990. */
  30991. OrdinalScale.prototype.getLabel = function (tick) {
  30992. if (!this.isBlank()) {
  30993. var ordinalNumber = this.getRawOrdinalNumber(tick.value);
  30994. var cateogry = this._ordinalMeta.categories[ordinalNumber];
  30995. // Note that if no data, ordinalMeta.categories is an empty array.
  30996. // Return empty if it's not exist.
  30997. return cateogry == null ? '' : cateogry + '';
  30998. }
  30999. };
  31000. OrdinalScale.prototype.count = function () {
  31001. return this._extent[1] - this._extent[0] + 1;
  31002. };
  31003. /**
  31004. * @override
  31005. * If value is in extent range
  31006. */
  31007. OrdinalScale.prototype.isInExtentRange = function (value) {
  31008. value = this._getTickNumber(value);
  31009. return this._extent[0] <= value && this._extent[1] >= value;
  31010. };
  31011. OrdinalScale.prototype.getOrdinalMeta = function () {
  31012. return this._ordinalMeta;
  31013. };
  31014. OrdinalScale.prototype.calcNiceTicks = function () {};
  31015. OrdinalScale.prototype.calcNiceExtent = function () {};
  31016. OrdinalScale.type = 'ordinal';
  31017. return OrdinalScale;
  31018. }(Scale);
  31019. Scale.registerClass(OrdinalScale);
  31020. var roundNumber = round;
  31021. var IntervalScale = /** @class */function (_super) {
  31022. __extends(IntervalScale, _super);
  31023. function IntervalScale() {
  31024. var _this = _super !== null && _super.apply(this, arguments) || this;
  31025. _this.type = 'interval';
  31026. // Step is calculated in adjustExtent.
  31027. _this._interval = 0;
  31028. _this._intervalPrecision = 2;
  31029. return _this;
  31030. }
  31031. IntervalScale.prototype.parse = function (val) {
  31032. // `Scale#parse` (and its overrids) are typically applied at the axis values input
  31033. // in echarts option. e.g., `axis.min/max`, `dataZoom.min/max`, etc.
  31034. // but `series.data` is not included, which uses `dataValueHelper.ts`#`parseDataValue`.
  31035. // `Scale#parse` originally introduced in fb8c813215098b9d2458966229bb95c510883d5e
  31036. // at 2016 for dataZoom start/end settings (See `parseAxisModelMinMax`).
  31037. //
  31038. // Historically `scale/Interval.ts` returns the input value directly. But numeric
  31039. // values (such as a number-like string '123') effectively passed through here and
  31040. // were involved in calculations, which was error-prone and inconsistent with the
  31041. // declared TS return type. Previously such issues are fixed separately in different
  31042. // places case by case (such as #2475).
  31043. //
  31044. // Now, we perform actual parse to ensure its `number` type here. The parsing rule
  31045. // follows the series data parsing rule (`dataValueHelper.ts`#`parseDataValue`)
  31046. // and maintains compatibility as much as possible (thus a more strict parsing
  31047. // `number.ts`#`numericToNumber` is not used here.)
  31048. //
  31049. // FIXME: `ScaleDataValue` also need to be modified to include numeric string type,
  31050. // since it effectively does.
  31051. return val == null || val === '' ? NaN
  31052. // If string (like '-'), using '+' parse to NaN
  31053. // If object, also parse to NaN
  31054. : Number(val);
  31055. };
  31056. IntervalScale.prototype.contain = function (val) {
  31057. return contain$1(val, this._extent);
  31058. };
  31059. IntervalScale.prototype.normalize = function (val) {
  31060. return this._calculator.normalize(val, this._extent);
  31061. };
  31062. IntervalScale.prototype.scale = function (val) {
  31063. return this._calculator.scale(val, this._extent);
  31064. };
  31065. IntervalScale.prototype.getInterval = function () {
  31066. return this._interval;
  31067. };
  31068. IntervalScale.prototype.setInterval = function (interval) {
  31069. this._interval = interval;
  31070. // Dropped auto calculated niceExtent and use user-set extent.
  31071. // We assume user wants to set both interval, min, max to get a better result.
  31072. this._niceExtent = this._extent.slice();
  31073. this._intervalPrecision = getIntervalPrecision(interval);
  31074. };
  31075. /**
  31076. * @override
  31077. */
  31078. IntervalScale.prototype.getTicks = function (opt) {
  31079. opt = opt || {};
  31080. var interval = this._interval;
  31081. var extent = this._extent;
  31082. var niceTickExtent = this._niceExtent;
  31083. var intervalPrecision = this._intervalPrecision;
  31084. var scaleBreakHelper = getScaleBreakHelper();
  31085. var ticks = [];
  31086. // If interval is 0, return [];
  31087. if (!interval) {
  31088. return ticks;
  31089. }
  31090. if (opt.breakTicks === 'only_break' && scaleBreakHelper) {
  31091. scaleBreakHelper.addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent);
  31092. return ticks;
  31093. }
  31094. // Consider this case: using dataZoom toolbox, zoom and zoom.
  31095. var safeLimit = 10000;
  31096. if (extent[0] < niceTickExtent[0]) {
  31097. if (opt.expandToNicedExtent) {
  31098. ticks.push({
  31099. value: roundNumber(niceTickExtent[0] - interval, intervalPrecision)
  31100. });
  31101. } else {
  31102. ticks.push({
  31103. value: extent[0]
  31104. });
  31105. }
  31106. }
  31107. var estimateNiceMultiple = function (tickVal, targetTick) {
  31108. return Math.round((targetTick - tickVal) / interval);
  31109. };
  31110. var tick = niceTickExtent[0];
  31111. while (tick <= niceTickExtent[1]) {
  31112. ticks.push({
  31113. value: tick
  31114. });
  31115. // Avoid rounding error
  31116. tick = roundNumber(tick + interval, intervalPrecision);
  31117. if (this._brkCtx) {
  31118. var moreMultiple = this._brkCtx.calcNiceTickMultiple(tick, estimateNiceMultiple);
  31119. if (moreMultiple >= 0) {
  31120. tick = roundNumber(tick + moreMultiple * interval, intervalPrecision);
  31121. }
  31122. }
  31123. if (ticks.length > 0 && tick === ticks[ticks.length - 1].value) {
  31124. // Consider out of safe float point, e.g.,
  31125. // -3711126.9907707 + 2e-10 === -3711126.9907707
  31126. break;
  31127. }
  31128. if (ticks.length > safeLimit) {
  31129. return [];
  31130. }
  31131. }
  31132. // Consider this case: the last item of ticks is smaller
  31133. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  31134. var lastNiceTick = ticks.length ? ticks[ticks.length - 1].value : niceTickExtent[1];
  31135. if (extent[1] > lastNiceTick) {
  31136. if (opt.expandToNicedExtent) {
  31137. ticks.push({
  31138. value: roundNumber(lastNiceTick + interval, intervalPrecision)
  31139. });
  31140. } else {
  31141. ticks.push({
  31142. value: extent[1]
  31143. });
  31144. }
  31145. }
  31146. if (opt.breakTicks !== 'none' && scaleBreakHelper) {
  31147. scaleBreakHelper.addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent);
  31148. }
  31149. return ticks;
  31150. };
  31151. IntervalScale.prototype.getMinorTicks = function (splitNumber) {
  31152. var ticks = this.getTicks({
  31153. expandToNicedExtent: true
  31154. });
  31155. // NOTE: In log-scale, do not support minor ticks when breaks exist.
  31156. // because currently log-scale minor ticks is calculated based on raw values
  31157. // rather than log-transformed value, due to an odd effect when breaks exist.
  31158. var minorTicks = [];
  31159. var extent = this.getExtent();
  31160. for (var i = 1; i < ticks.length; i++) {
  31161. var nextTick = ticks[i];
  31162. var prevTick = ticks[i - 1];
  31163. if (prevTick["break"] || nextTick["break"]) {
  31164. // Do not build minor ticks to the adjacent ticks to breaks ticks,
  31165. // since the interval might be irregular.
  31166. continue;
  31167. }
  31168. var count = 0;
  31169. var minorTicksGroup = [];
  31170. var interval = nextTick.value - prevTick.value;
  31171. var minorInterval = interval / splitNumber;
  31172. var minorIntervalPrecision = getIntervalPrecision(minorInterval);
  31173. while (count < splitNumber - 1) {
  31174. var minorTick = roundNumber(prevTick.value + (count + 1) * minorInterval, minorIntervalPrecision);
  31175. // For the first and last interval. The count may be less than splitNumber.
  31176. if (minorTick > extent[0] && minorTick < extent[1]) {
  31177. minorTicksGroup.push(minorTick);
  31178. }
  31179. count++;
  31180. }
  31181. var scaleBreakHelper = getScaleBreakHelper();
  31182. scaleBreakHelper && scaleBreakHelper.pruneTicksByBreak('auto', minorTicksGroup, this._getNonTransBreaks(), function (value) {
  31183. return value;
  31184. }, this._interval, extent);
  31185. minorTicks.push(minorTicksGroup);
  31186. }
  31187. return minorTicks;
  31188. };
  31189. IntervalScale.prototype._getNonTransBreaks = function () {
  31190. return this._brkCtx ? this._brkCtx.breaks : [];
  31191. };
  31192. /**
  31193. * @param opt.precision If 'auto', use nice presision.
  31194. * @param opt.pad returns 1.50 but not 1.5 if precision is 2.
  31195. */
  31196. IntervalScale.prototype.getLabel = function (data, opt) {
  31197. if (data == null) {
  31198. return '';
  31199. }
  31200. var precision = opt && opt.precision;
  31201. if (precision == null) {
  31202. precision = getPrecision(data.value) || 0;
  31203. } else if (precision === 'auto') {
  31204. // Should be more precise then tick.
  31205. precision = this._intervalPrecision;
  31206. }
  31207. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  31208. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  31209. var dataNum = roundNumber(data.value, precision, true);
  31210. return addCommas(dataNum);
  31211. };
  31212. /**
  31213. * FIXME: refactor - disallow override, use composition instead.
  31214. *
  31215. * The override of `calcNiceTicks` should ensure these members are provided:
  31216. * this._intervalPrecision
  31217. * this._interval
  31218. *
  31219. * @param splitNumber By default `5`.
  31220. */
  31221. IntervalScale.prototype.calcNiceTicks = function (splitNumber, minInterval, maxInterval) {
  31222. splitNumber = splitNumber || 5;
  31223. var extent = this._extent.slice();
  31224. var span = this._getExtentSpanWithBreaks();
  31225. if (!isFinite(span)) {
  31226. return;
  31227. }
  31228. // User may set axis min 0 and data are all negative
  31229. // FIXME If it needs to reverse ?
  31230. if (span < 0) {
  31231. span = -span;
  31232. extent.reverse();
  31233. this._innerSetExtent(extent[0], extent[1]);
  31234. extent = this._extent.slice();
  31235. }
  31236. var result = intervalScaleNiceTicks(extent, span, splitNumber, minInterval, maxInterval);
  31237. this._intervalPrecision = result.intervalPrecision;
  31238. this._interval = result.interval;
  31239. this._niceExtent = result.niceTickExtent;
  31240. };
  31241. IntervalScale.prototype.calcNiceExtent = function (opt) {
  31242. var extent = this._extent.slice();
  31243. // If extent start and end are same, expand them
  31244. if (extent[0] === extent[1]) {
  31245. if (extent[0] !== 0) {
  31246. // Expand extent
  31247. // Note that extents can be both negative. See #13154
  31248. var expandSize = Math.abs(extent[0]);
  31249. // In the fowllowing case
  31250. // Axis has been fixed max 100
  31251. // Plus data are all 100 and axis extent are [100, 100].
  31252. // Extend to the both side will cause expanded max is larger than fixed max.
  31253. // So only expand to the smaller side.
  31254. if (!opt.fixMax) {
  31255. extent[1] += expandSize / 2;
  31256. extent[0] -= expandSize / 2;
  31257. } else {
  31258. extent[0] -= expandSize / 2;
  31259. }
  31260. } else {
  31261. extent[1] = 1;
  31262. }
  31263. }
  31264. var span = extent[1] - extent[0];
  31265. // If there are no data and extent are [Infinity, -Infinity]
  31266. if (!isFinite(span)) {
  31267. extent[0] = 0;
  31268. extent[1] = 1;
  31269. }
  31270. this._innerSetExtent(extent[0], extent[1]);
  31271. extent = this._extent.slice();
  31272. this.calcNiceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  31273. var interval = this._interval;
  31274. var intervalPrecition = this._intervalPrecision;
  31275. if (!opt.fixMin) {
  31276. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval, intervalPrecition);
  31277. }
  31278. if (!opt.fixMax) {
  31279. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval, intervalPrecition);
  31280. }
  31281. this._innerSetExtent(extent[0], extent[1]);
  31282. };
  31283. IntervalScale.prototype.setNiceExtent = function (min, max) {
  31284. this._niceExtent = [min, max];
  31285. };
  31286. IntervalScale.type = 'interval';
  31287. return IntervalScale;
  31288. }(Scale);
  31289. Scale.registerClass(IntervalScale);
  31290. /* global Float32Array */
  31291. var supportFloat32Array = typeof Float32Array !== 'undefined';
  31292. var Float32ArrayCtor = !supportFloat32Array ? Array : Float32Array;
  31293. function createFloat32Array(arg) {
  31294. if (isArray(arg)) {
  31295. // Return self directly if don't support TypedArray.
  31296. return supportFloat32Array ? new Float32Array(arg) : arg;
  31297. }
  31298. // Else is number
  31299. return new Float32ArrayCtor(arg);
  31300. }
  31301. var STACK_PREFIX = '__ec_stack_';
  31302. function getSeriesStackId(seriesModel) {
  31303. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  31304. }
  31305. function getAxisKey(axis) {
  31306. return axis.dim + axis.index;
  31307. }
  31308. function prepareLayoutBarSeries(seriesType, ecModel) {
  31309. var seriesModels = [];
  31310. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  31311. // Check series coordinate, do layout for cartesian2d only
  31312. if (isOnCartesian(seriesModel)) {
  31313. seriesModels.push(seriesModel);
  31314. }
  31315. });
  31316. return seriesModels;
  31317. }
  31318. /**
  31319. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  31320. * values.
  31321. * This works for time axes, value axes, and log axes.
  31322. * For a single time axis, return value is in the form like
  31323. * {'x_0': [1000000]}.
  31324. * The value of 1000000 is in milliseconds.
  31325. */
  31326. function getValueAxesMinGaps(barSeries) {
  31327. /**
  31328. * Map from axis.index to values.
  31329. * For a single time axis, axisValues is in the form like
  31330. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  31331. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  31332. * series.
  31333. */
  31334. var axisValues = {};
  31335. each(barSeries, function (seriesModel) {
  31336. var cartesian = seriesModel.coordinateSystem;
  31337. var baseAxis = cartesian.getBaseAxis();
  31338. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  31339. return;
  31340. }
  31341. var data = seriesModel.getData();
  31342. var key = baseAxis.dim + '_' + baseAxis.index;
  31343. var dimIdx = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  31344. var store = data.getStore();
  31345. for (var i = 0, cnt = store.count(); i < cnt; ++i) {
  31346. var value = store.get(dimIdx, i);
  31347. if (!axisValues[key]) {
  31348. // No previous data for the axis
  31349. axisValues[key] = [value];
  31350. } else {
  31351. // No value in previous series
  31352. axisValues[key].push(value);
  31353. }
  31354. // Ignore duplicated time values in the same axis
  31355. }
  31356. });
  31357. var axisMinGaps = {};
  31358. for (var key in axisValues) {
  31359. if (axisValues.hasOwnProperty(key)) {
  31360. var valuesInAxis = axisValues[key];
  31361. if (valuesInAxis) {
  31362. // Sort axis values into ascending order to calculate gaps
  31363. valuesInAxis.sort(function (a, b) {
  31364. return a - b;
  31365. });
  31366. var min = null;
  31367. for (var j = 1; j < valuesInAxis.length; ++j) {
  31368. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  31369. if (delta > 0) {
  31370. // Ignore 0 delta because they are of the same axis value
  31371. min = min === null ? delta : Math.min(min, delta);
  31372. }
  31373. }
  31374. // Set to null if only have one data
  31375. axisMinGaps[key] = min;
  31376. }
  31377. }
  31378. }
  31379. return axisMinGaps;
  31380. }
  31381. function makeColumnLayout(barSeries) {
  31382. var axisMinGaps = getValueAxesMinGaps(barSeries);
  31383. var seriesInfoList = [];
  31384. each(barSeries, function (seriesModel) {
  31385. var cartesian = seriesModel.coordinateSystem;
  31386. var baseAxis = cartesian.getBaseAxis();
  31387. var axisExtent = baseAxis.getExtent();
  31388. var bandWidth;
  31389. if (baseAxis.type === 'category') {
  31390. bandWidth = baseAxis.getBandWidth();
  31391. } else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  31392. var key = baseAxis.dim + '_' + baseAxis.index;
  31393. var minGap = axisMinGaps[key];
  31394. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  31395. var scale = baseAxis.scale.getExtent();
  31396. var scaleSpan = Math.abs(scale[1] - scale[0]);
  31397. bandWidth = minGap ? extentSpan / scaleSpan * minGap : extentSpan; // When there is only one data value
  31398. } else {
  31399. var data = seriesModel.getData();
  31400. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  31401. }
  31402. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  31403. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  31404. var barMinWidth = parsePercent$1(
  31405. // barMinWidth by default is 0.5 / 1 in cartesian. Because in value axis,
  31406. // the auto-calculated bar width might be less than 0.5 / 1.
  31407. seriesModel.get('barMinWidth') || (isInLargeMode(seriesModel) ? 0.5 : 1), bandWidth);
  31408. var barGap = seriesModel.get('barGap');
  31409. var barCategoryGap = seriesModel.get('barCategoryGap');
  31410. var defaultBarGap = seriesModel.get('defaultBarGap');
  31411. seriesInfoList.push({
  31412. bandWidth: bandWidth,
  31413. barWidth: barWidth,
  31414. barMaxWidth: barMaxWidth,
  31415. barMinWidth: barMinWidth,
  31416. barGap: barGap,
  31417. barCategoryGap: barCategoryGap,
  31418. defaultBarGap: defaultBarGap,
  31419. axisKey: getAxisKey(baseAxis),
  31420. stackId: getSeriesStackId(seriesModel)
  31421. });
  31422. });
  31423. return doCalBarWidthAndOffset(seriesInfoList);
  31424. }
  31425. function doCalBarWidthAndOffset(seriesInfoList) {
  31426. // Columns info on each category axis. Key is cartesian name
  31427. var columnsMap = {};
  31428. each(seriesInfoList, function (seriesInfo, idx) {
  31429. var axisKey = seriesInfo.axisKey;
  31430. var bandWidth = seriesInfo.bandWidth;
  31431. var columnsOnAxis = columnsMap[axisKey] || {
  31432. bandWidth: bandWidth,
  31433. remainedWidth: bandWidth,
  31434. autoWidthCount: 0,
  31435. categoryGap: null,
  31436. gap: seriesInfo.defaultBarGap || 0,
  31437. stacks: {}
  31438. };
  31439. var stacks = columnsOnAxis.stacks;
  31440. columnsMap[axisKey] = columnsOnAxis;
  31441. var stackId = seriesInfo.stackId;
  31442. if (!stacks[stackId]) {
  31443. columnsOnAxis.autoWidthCount++;
  31444. }
  31445. stacks[stackId] = stacks[stackId] || {
  31446. width: 0,
  31447. maxWidth: 0
  31448. };
  31449. // Caution: In a single coordinate system, these barGrid attributes
  31450. // will be shared by series. Consider that they have default values,
  31451. // only the attributes set on the last series will work.
  31452. // Do not change this fact unless there will be a break change.
  31453. var barWidth = seriesInfo.barWidth;
  31454. if (barWidth && !stacks[stackId].width) {
  31455. // See #6312, do not restrict width.
  31456. stacks[stackId].width = barWidth;
  31457. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  31458. columnsOnAxis.remainedWidth -= barWidth;
  31459. }
  31460. var barMaxWidth = seriesInfo.barMaxWidth;
  31461. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  31462. var barMinWidth = seriesInfo.barMinWidth;
  31463. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  31464. var barGap = seriesInfo.barGap;
  31465. barGap != null && (columnsOnAxis.gap = barGap);
  31466. var barCategoryGap = seriesInfo.barCategoryGap;
  31467. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  31468. });
  31469. var result = {};
  31470. each(columnsMap, function (columnsOnAxis, coordSysName) {
  31471. result[coordSysName] = {};
  31472. var stacks = columnsOnAxis.stacks;
  31473. var bandWidth = columnsOnAxis.bandWidth;
  31474. var categoryGapPercent = columnsOnAxis.categoryGap;
  31475. if (categoryGapPercent == null) {
  31476. var columnCount = keys(stacks).length;
  31477. // More columns in one group
  31478. // the spaces between group is smaller. Or the column will be too thin.
  31479. categoryGapPercent = Math.max(35 - columnCount * 4, 15) + '%';
  31480. }
  31481. var categoryGap = parsePercent$1(categoryGapPercent, bandWidth);
  31482. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  31483. var remainedWidth = columnsOnAxis.remainedWidth;
  31484. var autoWidthCount = columnsOnAxis.autoWidthCount;
  31485. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  31486. autoWidth = Math.max(autoWidth, 0);
  31487. // Find if any auto calculated bar exceeded maxBarWidth
  31488. each(stacks, function (column) {
  31489. var maxWidth = column.maxWidth;
  31490. var minWidth = column.minWidth;
  31491. if (!column.width) {
  31492. var finalWidth = autoWidth;
  31493. if (maxWidth && maxWidth < finalWidth) {
  31494. finalWidth = Math.min(maxWidth, remainedWidth);
  31495. }
  31496. // `minWidth` has higher priority. `minWidth` decide that whether the
  31497. // bar is able to be visible. So `minWidth` should not be restricted
  31498. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  31499. // the extreme cases for `value` axis, bars are allowed to overlap
  31500. // with each other if `minWidth` specified.
  31501. if (minWidth && minWidth > finalWidth) {
  31502. finalWidth = minWidth;
  31503. }
  31504. if (finalWidth !== autoWidth) {
  31505. column.width = finalWidth;
  31506. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  31507. autoWidthCount--;
  31508. }
  31509. } else {
  31510. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  31511. // CSS does. Because barWidth can be a percent value, where
  31512. // `barMaxWidth` can be used to restrict the final width.
  31513. var finalWidth = column.width;
  31514. if (maxWidth) {
  31515. finalWidth = Math.min(finalWidth, maxWidth);
  31516. }
  31517. // `minWidth` has higher priority, as described above
  31518. if (minWidth) {
  31519. finalWidth = Math.max(finalWidth, minWidth);
  31520. }
  31521. column.width = finalWidth;
  31522. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  31523. autoWidthCount--;
  31524. }
  31525. });
  31526. // Recalculate width again
  31527. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  31528. autoWidth = Math.max(autoWidth, 0);
  31529. var widthSum = 0;
  31530. var lastColumn;
  31531. each(stacks, function (column, idx) {
  31532. if (!column.width) {
  31533. column.width = autoWidth;
  31534. }
  31535. lastColumn = column;
  31536. widthSum += column.width * (1 + barGapPercent);
  31537. });
  31538. if (lastColumn) {
  31539. widthSum -= lastColumn.width * barGapPercent;
  31540. }
  31541. var offset = -widthSum / 2;
  31542. each(stacks, function (column, stackId) {
  31543. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  31544. bandWidth: bandWidth,
  31545. offset: offset,
  31546. width: column.width
  31547. };
  31548. offset += column.width * (1 + barGapPercent);
  31549. });
  31550. });
  31551. return result;
  31552. }
  31553. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  31554. if (barWidthAndOffset && axis) {
  31555. var result = barWidthAndOffset[getAxisKey(axis)];
  31556. if (result != null && seriesModel != null) {
  31557. return result[getSeriesStackId(seriesModel)];
  31558. }
  31559. return result;
  31560. }
  31561. }
  31562. function layout(seriesType, ecModel) {
  31563. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  31564. var barWidthAndOffset = makeColumnLayout(seriesModels);
  31565. each(seriesModels, function (seriesModel) {
  31566. var data = seriesModel.getData();
  31567. var cartesian = seriesModel.coordinateSystem;
  31568. var baseAxis = cartesian.getBaseAxis();
  31569. var stackId = getSeriesStackId(seriesModel);
  31570. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  31571. var columnOffset = columnLayoutInfo.offset;
  31572. var columnWidth = columnLayoutInfo.width;
  31573. data.setLayout({
  31574. bandWidth: columnLayoutInfo.bandWidth,
  31575. offset: columnOffset,
  31576. size: columnWidth
  31577. });
  31578. });
  31579. }
  31580. // TODO: Do not support stack in large mode yet.
  31581. function createProgressiveLayout(seriesType) {
  31582. return {
  31583. seriesType: seriesType,
  31584. plan: createRenderPlanner(),
  31585. reset: function (seriesModel) {
  31586. if (!isOnCartesian(seriesModel)) {
  31587. return;
  31588. }
  31589. var data = seriesModel.getData();
  31590. var cartesian = seriesModel.coordinateSystem;
  31591. var baseAxis = cartesian.getBaseAxis();
  31592. var valueAxis = cartesian.getOtherAxis(baseAxis);
  31593. var valueDimIdx = data.getDimensionIndex(data.mapDimension(valueAxis.dim));
  31594. var baseDimIdx = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  31595. var drawBackground = seriesModel.get('showBackground', true);
  31596. var valueDim = data.mapDimension(valueAxis.dim);
  31597. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  31598. var stacked = isDimensionStacked(data, valueDim) && !!data.getCalculationInfo('stackedOnSeries');
  31599. var isValueAxisH = valueAxis.isHorizontal();
  31600. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis);
  31601. var isLarge = isInLargeMode(seriesModel);
  31602. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  31603. var stackedDimIdx = stackResultDim && data.getDimensionIndex(stackResultDim);
  31604. // Layout info.
  31605. var columnWidth = data.getLayout('size');
  31606. var columnOffset = data.getLayout('offset');
  31607. return {
  31608. progress: function (params, data) {
  31609. var count = params.count;
  31610. var largePoints = isLarge && createFloat32Array(count * 3);
  31611. var largeBackgroundPoints = isLarge && drawBackground && createFloat32Array(count * 3);
  31612. var largeDataIndices = isLarge && createFloat32Array(count);
  31613. var coordLayout = cartesian.master.getRect();
  31614. var bgSize = isValueAxisH ? coordLayout.width : coordLayout.height;
  31615. var dataIndex;
  31616. var store = data.getStore();
  31617. var idxOffset = 0;
  31618. while ((dataIndex = params.next()) != null) {
  31619. var value = store.get(stacked ? stackedDimIdx : valueDimIdx, dataIndex);
  31620. var baseValue = store.get(baseDimIdx, dataIndex);
  31621. var baseCoord = valueAxisStart;
  31622. var stackStartValue = void 0;
  31623. // Because of the barMinHeight, we can not use the value in
  31624. // stackResultDimension directly.
  31625. if (stacked) {
  31626. stackStartValue = +value - store.get(valueDimIdx, dataIndex);
  31627. }
  31628. var x = void 0;
  31629. var y = void 0;
  31630. var width = void 0;
  31631. var height = void 0;
  31632. if (isValueAxisH) {
  31633. var coord = cartesian.dataToPoint([value, baseValue]);
  31634. if (stacked) {
  31635. var startCoord = cartesian.dataToPoint([stackStartValue, baseValue]);
  31636. baseCoord = startCoord[0];
  31637. }
  31638. x = baseCoord;
  31639. y = coord[1] + columnOffset;
  31640. width = coord[0] - baseCoord;
  31641. height = columnWidth;
  31642. if (Math.abs(width) < barMinHeight) {
  31643. width = (width < 0 ? -1 : 1) * barMinHeight;
  31644. }
  31645. } else {
  31646. var coord = cartesian.dataToPoint([baseValue, value]);
  31647. if (stacked) {
  31648. var startCoord = cartesian.dataToPoint([baseValue, stackStartValue]);
  31649. baseCoord = startCoord[1];
  31650. }
  31651. x = coord[0] + columnOffset;
  31652. y = baseCoord;
  31653. width = columnWidth;
  31654. height = coord[1] - baseCoord;
  31655. if (Math.abs(height) < barMinHeight) {
  31656. // Include zero to has a positive bar
  31657. height = (height <= 0 ? -1 : 1) * barMinHeight;
  31658. }
  31659. }
  31660. if (!isLarge) {
  31661. data.setItemLayout(dataIndex, {
  31662. x: x,
  31663. y: y,
  31664. width: width,
  31665. height: height
  31666. });
  31667. } else {
  31668. largePoints[idxOffset] = x;
  31669. largePoints[idxOffset + 1] = y;
  31670. largePoints[idxOffset + 2] = isValueAxisH ? width : height;
  31671. if (largeBackgroundPoints) {
  31672. largeBackgroundPoints[idxOffset] = isValueAxisH ? coordLayout.x : x;
  31673. largeBackgroundPoints[idxOffset + 1] = isValueAxisH ? y : coordLayout.y;
  31674. largeBackgroundPoints[idxOffset + 2] = bgSize;
  31675. }
  31676. largeDataIndices[dataIndex] = dataIndex;
  31677. }
  31678. idxOffset += 3;
  31679. }
  31680. if (isLarge) {
  31681. data.setLayout({
  31682. largePoints: largePoints,
  31683. largeDataIndices: largeDataIndices,
  31684. largeBackgroundPoints: largeBackgroundPoints,
  31685. valueAxisHorizontal: isValueAxisH
  31686. });
  31687. }
  31688. }
  31689. };
  31690. }
  31691. };
  31692. }
  31693. function isOnCartesian(seriesModel) {
  31694. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  31695. }
  31696. function isInLargeMode(seriesModel) {
  31697. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  31698. }
  31699. // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  31700. function getValueAxisStart(baseAxis, valueAxis) {
  31701. var startValue = valueAxis.model.get('startValue');
  31702. if (!startValue) {
  31703. startValue = 0;
  31704. }
  31705. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? startValue > 0 ? startValue : 1 : startValue));
  31706. }
  31707. // FIXME 公用?
  31708. var bisect = function (a, x, lo, hi) {
  31709. while (lo < hi) {
  31710. var mid = lo + hi >>> 1;
  31711. if (a[mid][1] < x) {
  31712. lo = mid + 1;
  31713. } else {
  31714. hi = mid;
  31715. }
  31716. }
  31717. return lo;
  31718. };
  31719. var TimeScale = /** @class */function (_super) {
  31720. __extends(TimeScale, _super);
  31721. function TimeScale(settings) {
  31722. var _this = _super.call(this, settings) || this;
  31723. _this.type = 'time';
  31724. return _this;
  31725. }
  31726. /**
  31727. * Get label is mainly for other components like dataZoom, tooltip.
  31728. */
  31729. TimeScale.prototype.getLabel = function (tick) {
  31730. var useUTC = this.getSetting('useUTC');
  31731. return format(tick.value, fullLeveledFormatter[getDefaultFormatPrecisionOfInterval(getPrimaryTimeUnit(this._minLevelUnit))] || fullLeveledFormatter.second, useUTC, this.getSetting('locale'));
  31732. };
  31733. TimeScale.prototype.getFormattedLabel = function (tick, idx, labelFormatter) {
  31734. var isUTC = this.getSetting('useUTC');
  31735. var lang = this.getSetting('locale');
  31736. return leveledFormat(tick, idx, labelFormatter, lang, isUTC);
  31737. };
  31738. /**
  31739. * @override
  31740. */
  31741. TimeScale.prototype.getTicks = function (opt) {
  31742. var interval = this._interval;
  31743. var extent = this._extent;
  31744. var ticks = [];
  31745. // If interval is 0, return [];
  31746. if (!interval) {
  31747. return ticks;
  31748. }
  31749. var useUTC = this.getSetting('useUTC');
  31750. var extent0Unit = getUnitFromValue(extent[1], useUTC);
  31751. ticks.push({
  31752. value: extent[0],
  31753. time: {
  31754. level: 0,
  31755. upperTimeUnit: extent0Unit,
  31756. lowerTimeUnit: extent0Unit
  31757. }
  31758. });
  31759. var innerTicks = getIntervalTicks(this._minLevelUnit, this._approxInterval, useUTC, extent, this._getExtentSpanWithBreaks(), this._brkCtx);
  31760. ticks = ticks.concat(innerTicks);
  31761. var extent1Unit = getUnitFromValue(extent[1], useUTC);
  31762. ticks.push({
  31763. value: extent[1],
  31764. time: {
  31765. level: 0,
  31766. upperTimeUnit: extent1Unit,
  31767. lowerTimeUnit: extent1Unit
  31768. }
  31769. });
  31770. var isUTC = this.getSetting('useUTC');
  31771. var upperUnitIndex = primaryTimeUnits.length - 1;
  31772. var maxLevel = 0;
  31773. each(ticks, function (tick) {
  31774. upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit));
  31775. maxLevel = Math.max(maxLevel, tick.time.level);
  31776. });
  31777. return ticks;
  31778. };
  31779. TimeScale.prototype.calcNiceExtent = function (opt) {
  31780. var extent = this.getExtent();
  31781. // If extent start and end are same, expand them
  31782. if (extent[0] === extent[1]) {
  31783. // Expand extent
  31784. extent[0] -= ONE_DAY;
  31785. extent[1] += ONE_DAY;
  31786. }
  31787. // If there are no data and extent are [Infinity, -Infinity]
  31788. if (extent[1] === -Infinity && extent[0] === Infinity) {
  31789. var d = new Date();
  31790. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  31791. extent[0] = extent[1] - ONE_DAY;
  31792. }
  31793. this._innerSetExtent(extent[0], extent[1]);
  31794. this.calcNiceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  31795. };
  31796. TimeScale.prototype.calcNiceTicks = function (approxTickNum, minInterval, maxInterval) {
  31797. approxTickNum = approxTickNum || 10;
  31798. var span = this._getExtentSpanWithBreaks();
  31799. this._approxInterval = span / approxTickNum;
  31800. if (minInterval != null && this._approxInterval < minInterval) {
  31801. this._approxInterval = minInterval;
  31802. }
  31803. if (maxInterval != null && this._approxInterval > maxInterval) {
  31804. this._approxInterval = maxInterval;
  31805. }
  31806. var scaleIntervalsLen = scaleIntervals.length;
  31807. var idx = Math.min(bisect(scaleIntervals, this._approxInterval, 0, scaleIntervalsLen), scaleIntervalsLen - 1);
  31808. // Interval that can be used to calculate ticks
  31809. this._interval = scaleIntervals[idx][1];
  31810. this._intervalPrecision = getIntervalPrecision(this._interval);
  31811. // Min level used when picking ticks from top down.
  31812. // We check one more level to avoid the ticks are to sparse in some case.
  31813. this._minLevelUnit = scaleIntervals[Math.max(idx - 1, 0)][0];
  31814. };
  31815. TimeScale.prototype.parse = function (val) {
  31816. // val might be float.
  31817. return isNumber(val) ? val : +parseDate(val);
  31818. };
  31819. TimeScale.prototype.contain = function (val) {
  31820. return contain$1(val, this._extent);
  31821. };
  31822. TimeScale.prototype.normalize = function (val) {
  31823. return this._calculator.normalize(val, this._extent);
  31824. };
  31825. TimeScale.prototype.scale = function (val) {
  31826. return this._calculator.scale(val, this._extent);
  31827. };
  31828. TimeScale.type = 'time';
  31829. return TimeScale;
  31830. }(IntervalScale);
  31831. /**
  31832. * This implementation was originally copied from "d3.js"
  31833. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  31834. * with some modifications made for this program.
  31835. * See the license statement at the head of this file.
  31836. */
  31837. var scaleIntervals = [
  31838. // Format interval
  31839. ['second', ONE_SECOND], ['minute', ONE_MINUTE], ['hour', ONE_HOUR], ['quarter-day', ONE_HOUR * 6], ['half-day', ONE_HOUR * 12], ['day', ONE_DAY * 1.2], ['half-week', ONE_DAY * 3.5], ['week', ONE_DAY * 7], ['month', ONE_DAY * 31], ['quarter', ONE_DAY * 95], ['half-year', ONE_YEAR / 2], ['year', ONE_YEAR] // 1Y
  31840. ];
  31841. function isPrimaryUnitValueAndGreaterSame(unit, valueA, valueB, isUTC) {
  31842. return roundTime(new Date(valueA), unit, isUTC).getTime() === roundTime(new Date(valueB), unit, isUTC).getTime();
  31843. }
  31844. // function isUnitValueSame(
  31845. // unit: PrimaryTimeUnit,
  31846. // valueA: number,
  31847. // valueB: number,
  31848. // isUTC: boolean
  31849. // ): boolean {
  31850. // const dateA = numberUtil.parseDate(valueA) as any;
  31851. // const dateB = numberUtil.parseDate(valueB) as any;
  31852. // const isSame = (unit: PrimaryTimeUnit) => {
  31853. // return getUnitValue(dateA, unit, isUTC)
  31854. // === getUnitValue(dateB, unit, isUTC);
  31855. // };
  31856. // const isSameYear = () => isSame('year');
  31857. // // const isSameHalfYear = () => isSameYear() && isSame('half-year');
  31858. // // const isSameQuater = () => isSameYear() && isSame('quarter');
  31859. // const isSameMonth = () => isSameYear() && isSame('month');
  31860. // const isSameDay = () => isSameMonth() && isSame('day');
  31861. // // const isSameHalfDay = () => isSameDay() && isSame('half-day');
  31862. // const isSameHour = () => isSameDay() && isSame('hour');
  31863. // const isSameMinute = () => isSameHour() && isSame('minute');
  31864. // const isSameSecond = () => isSameMinute() && isSame('second');
  31865. // const isSameMilliSecond = () => isSameSecond() && isSame('millisecond');
  31866. // switch (unit) {
  31867. // case 'year':
  31868. // return isSameYear();
  31869. // case 'month':
  31870. // return isSameMonth();
  31871. // case 'day':
  31872. // return isSameDay();
  31873. // case 'hour':
  31874. // return isSameHour();
  31875. // case 'minute':
  31876. // return isSameMinute();
  31877. // case 'second':
  31878. // return isSameSecond();
  31879. // case 'millisecond':
  31880. // return isSameMilliSecond();
  31881. // }
  31882. // }
  31883. // const primaryUnitGetters = {
  31884. // year: fullYearGetterName(),
  31885. // month: monthGetterName(),
  31886. // day: dateGetterName(),
  31887. // hour: hoursGetterName(),
  31888. // minute: minutesGetterName(),
  31889. // second: secondsGetterName(),
  31890. // millisecond: millisecondsGetterName()
  31891. // };
  31892. // const primaryUnitUTCGetters = {
  31893. // year: fullYearGetterName(true),
  31894. // month: monthGetterName(true),
  31895. // day: dateGetterName(true),
  31896. // hour: hoursGetterName(true),
  31897. // minute: minutesGetterName(true),
  31898. // second: secondsGetterName(true),
  31899. // millisecond: millisecondsGetterName(true)
  31900. // };
  31901. // function moveTick(date: Date, unitName: TimeUnit, step: number, isUTC: boolean) {
  31902. // step = step || 1;
  31903. // switch (getPrimaryTimeUnit(unitName)) {
  31904. // case 'year':
  31905. // date[fullYearSetterName(isUTC)](date[fullYearGetterName(isUTC)]() + step);
  31906. // break;
  31907. // case 'month':
  31908. // date[monthSetterName(isUTC)](date[monthGetterName(isUTC)]() + step);
  31909. // break;
  31910. // case 'day':
  31911. // date[dateSetterName(isUTC)](date[dateGetterName(isUTC)]() + step);
  31912. // break;
  31913. // case 'hour':
  31914. // date[hoursSetterName(isUTC)](date[hoursGetterName(isUTC)]() + step);
  31915. // break;
  31916. // case 'minute':
  31917. // date[minutesSetterName(isUTC)](date[minutesGetterName(isUTC)]() + step);
  31918. // break;
  31919. // case 'second':
  31920. // date[secondsSetterName(isUTC)](date[secondsGetterName(isUTC)]() + step);
  31921. // break;
  31922. // case 'millisecond':
  31923. // date[millisecondsSetterName(isUTC)](date[millisecondsGetterName(isUTC)]() + step);
  31924. // break;
  31925. // }
  31926. // return date.getTime();
  31927. // }
  31928. // const DATE_INTERVALS = [[8, 7.5], [4, 3.5], [2, 1.5]];
  31929. // const MONTH_INTERVALS = [[6, 5.5], [3, 2.5], [2, 1.5]];
  31930. // const MINUTES_SECONDS_INTERVALS = [[30, 30], [20, 20], [15, 15], [10, 10], [5, 5], [2, 2]];
  31931. function getDateInterval(approxInterval, daysInMonth) {
  31932. approxInterval /= ONE_DAY;
  31933. return approxInterval > 16 ? 16
  31934. // Math.floor(daysInMonth / 2) + 1 // In this case we only want one tick between two months.
  31935. : approxInterval > 7.5 ? 7 // TODO week 7 or day 8?
  31936. : approxInterval > 3.5 ? 4 : approxInterval > 1.5 ? 2 : 1;
  31937. }
  31938. function getMonthInterval(approxInterval) {
  31939. var APPROX_ONE_MONTH = 30 * ONE_DAY;
  31940. approxInterval /= APPROX_ONE_MONTH;
  31941. return approxInterval > 6 ? 6 : approxInterval > 3 ? 3 : approxInterval > 2 ? 2 : 1;
  31942. }
  31943. function getHourInterval(approxInterval) {
  31944. approxInterval /= ONE_HOUR;
  31945. return approxInterval > 12 ? 12 : approxInterval > 6 ? 6 : approxInterval > 3.5 ? 4 : approxInterval > 2 ? 2 : 1;
  31946. }
  31947. function getMinutesAndSecondsInterval(approxInterval, isMinutes) {
  31948. approxInterval /= isMinutes ? ONE_MINUTE : ONE_SECOND;
  31949. return approxInterval > 30 ? 30 : approxInterval > 20 ? 20 : approxInterval > 15 ? 15 : approxInterval > 10 ? 10 : approxInterval > 5 ? 5 : approxInterval > 2 ? 2 : 1;
  31950. }
  31951. function getMillisecondsInterval(approxInterval) {
  31952. return nice(approxInterval, true);
  31953. }
  31954. // e.g., if the input unit is 'day', start calculate ticks from the first day of
  31955. // that month to make ticks "nice".
  31956. function getFirstTimestampOfUnit(timestamp, unitName, isUTC) {
  31957. var upperUnitIdx = Math.max(0, indexOf(primaryTimeUnits, unitName) - 1);
  31958. return roundTime(new Date(timestamp), primaryTimeUnits[upperUnitIdx], isUTC).getTime();
  31959. }
  31960. function createEstimateNiceMultiple(setMethodName, dateMethodInterval) {
  31961. var tmpDate = new Date(0);
  31962. tmpDate[setMethodName](1);
  31963. var tmpTime = tmpDate.getTime();
  31964. tmpDate[setMethodName](1 + dateMethodInterval);
  31965. var approxTimeInterval = tmpDate.getTime() - tmpTime;
  31966. return function (tickVal, targetValue) {
  31967. // Only in month that accurate result can not get by division of
  31968. // timestamp interval, but no need accurate here.
  31969. return Math.max(0, Math.round((targetValue - tickVal) / approxTimeInterval));
  31970. };
  31971. }
  31972. function getIntervalTicks(bottomUnitName, approxInterval, isUTC, extent, extentSpanWithBreaks, brkCtx) {
  31973. var safeLimit = 10000;
  31974. var unitNames = timeUnits;
  31975. var iter = 0;
  31976. function addTicksInSpan(interval, minTimestamp, maxTimestamp, getMethodName, setMethodName, isDate, out) {
  31977. var estimateNiceMultiple = createEstimateNiceMultiple(setMethodName, interval);
  31978. var dateTime = minTimestamp;
  31979. var date = new Date(dateTime);
  31980. // if (isDate) {
  31981. // d -= 1; // Starts with 0; PENDING
  31982. // }
  31983. while (dateTime < maxTimestamp && dateTime <= extent[1]) {
  31984. out.push({
  31985. value: dateTime
  31986. });
  31987. if (iter++ > safeLimit) {
  31988. if ("development" !== 'production') {
  31989. warn('Exceed safe limit in time scale.');
  31990. }
  31991. break;
  31992. }
  31993. date[setMethodName](date[getMethodName]() + interval);
  31994. dateTime = date.getTime();
  31995. if (brkCtx) {
  31996. var moreMultiple = brkCtx.calcNiceTickMultiple(dateTime, estimateNiceMultiple);
  31997. if (moreMultiple > 0) {
  31998. date[setMethodName](date[getMethodName]() + moreMultiple * interval);
  31999. dateTime = date.getTime();
  32000. }
  32001. }
  32002. }
  32003. // This extra tick is for calcuating ticks of next level. Will not been added to the final result
  32004. out.push({
  32005. value: dateTime,
  32006. notAdd: true
  32007. });
  32008. }
  32009. function addLevelTicks(unitName, lastLevelTicks, levelTicks) {
  32010. var newAddedTicks = [];
  32011. var isFirstLevel = !lastLevelTicks.length;
  32012. if (isPrimaryUnitValueAndGreaterSame(getPrimaryTimeUnit(unitName), extent[0], extent[1], isUTC)) {
  32013. return;
  32014. }
  32015. if (isFirstLevel) {
  32016. lastLevelTicks = [{
  32017. value: getFirstTimestampOfUnit(extent[0], unitName, isUTC)
  32018. }, {
  32019. value: extent[1]
  32020. }];
  32021. }
  32022. for (var i = 0; i < lastLevelTicks.length - 1; i++) {
  32023. var startTick = lastLevelTicks[i].value;
  32024. var endTick = lastLevelTicks[i + 1].value;
  32025. if (startTick === endTick) {
  32026. continue;
  32027. }
  32028. var interval = void 0;
  32029. var getterName = void 0;
  32030. var setterName = void 0;
  32031. var isDate = false;
  32032. switch (unitName) {
  32033. case 'year':
  32034. interval = Math.max(1, Math.round(approxInterval / ONE_DAY / 365));
  32035. getterName = fullYearGetterName(isUTC);
  32036. setterName = fullYearSetterName(isUTC);
  32037. break;
  32038. case 'half-year':
  32039. case 'quarter':
  32040. case 'month':
  32041. interval = getMonthInterval(approxInterval);
  32042. getterName = monthGetterName(isUTC);
  32043. setterName = monthSetterName(isUTC);
  32044. break;
  32045. case 'week': // PENDING If week is added. Ignore day.
  32046. case 'half-week':
  32047. case 'day':
  32048. interval = getDateInterval(approxInterval); // Use 32 days and let interval been 16
  32049. getterName = dateGetterName(isUTC);
  32050. setterName = dateSetterName(isUTC);
  32051. isDate = true;
  32052. break;
  32053. case 'half-day':
  32054. case 'quarter-day':
  32055. case 'hour':
  32056. interval = getHourInterval(approxInterval);
  32057. getterName = hoursGetterName(isUTC);
  32058. setterName = hoursSetterName(isUTC);
  32059. break;
  32060. case 'minute':
  32061. interval = getMinutesAndSecondsInterval(approxInterval, true);
  32062. getterName = minutesGetterName(isUTC);
  32063. setterName = minutesSetterName(isUTC);
  32064. break;
  32065. case 'second':
  32066. interval = getMinutesAndSecondsInterval(approxInterval, false);
  32067. getterName = secondsGetterName(isUTC);
  32068. setterName = secondsSetterName(isUTC);
  32069. break;
  32070. case 'millisecond':
  32071. interval = getMillisecondsInterval(approxInterval);
  32072. getterName = millisecondsGetterName(isUTC);
  32073. setterName = millisecondsSetterName(isUTC);
  32074. break;
  32075. }
  32076. // Notice: This expansion by `getFirstTimestampOfUnit` may cause too many ticks and
  32077. // iteration. e.g., when three levels of ticks is displayed, which can be caused by
  32078. // data zoom and axis breaks. Thus trim them here.
  32079. if (endTick >= extent[0] && startTick <= extent[1]) {
  32080. addTicksInSpan(interval, startTick, endTick, getterName, setterName, isDate, newAddedTicks);
  32081. }
  32082. if (unitName === 'year' && levelTicks.length > 1 && i === 0) {
  32083. // Add nearest years to the left extent.
  32084. levelTicks.unshift({
  32085. value: levelTicks[0].value - interval
  32086. });
  32087. }
  32088. }
  32089. for (var i = 0; i < newAddedTicks.length; i++) {
  32090. levelTicks.push(newAddedTicks[i]);
  32091. }
  32092. }
  32093. var levelsTicks = [];
  32094. var currentLevelTicks = [];
  32095. var tickCount = 0;
  32096. var lastLevelTickCount = 0;
  32097. for (var i = 0; i < unitNames.length; ++i) {
  32098. var primaryTimeUnit = getPrimaryTimeUnit(unitNames[i]);
  32099. if (!isPrimaryTimeUnit(unitNames[i])) {
  32100. // TODO
  32101. continue;
  32102. }
  32103. addLevelTicks(unitNames[i], levelsTicks[levelsTicks.length - 1] || [], currentLevelTicks);
  32104. var nextPrimaryTimeUnit = unitNames[i + 1] ? getPrimaryTimeUnit(unitNames[i + 1]) : null;
  32105. if (primaryTimeUnit !== nextPrimaryTimeUnit) {
  32106. if (currentLevelTicks.length) {
  32107. lastLevelTickCount = tickCount;
  32108. // Remove the duplicate so the tick count can be precisely.
  32109. currentLevelTicks.sort(function (a, b) {
  32110. return a.value - b.value;
  32111. });
  32112. var levelTicksRemoveDuplicated = [];
  32113. for (var i_1 = 0; i_1 < currentLevelTicks.length; ++i_1) {
  32114. var tickValue = currentLevelTicks[i_1].value;
  32115. if (i_1 === 0 || currentLevelTicks[i_1 - 1].value !== tickValue) {
  32116. levelTicksRemoveDuplicated.push(currentLevelTicks[i_1]);
  32117. if (tickValue >= extent[0] && tickValue <= extent[1]) {
  32118. tickCount++;
  32119. }
  32120. }
  32121. }
  32122. var targetTickNum = extentSpanWithBreaks / approxInterval;
  32123. // Added too much in this level and not too less in last level
  32124. if (tickCount > targetTickNum * 1.5 && lastLevelTickCount > targetTickNum / 1.5) {
  32125. break;
  32126. }
  32127. // Only treat primary time unit as one level.
  32128. levelsTicks.push(levelTicksRemoveDuplicated);
  32129. if (tickCount > targetTickNum || bottomUnitName === unitNames[i]) {
  32130. break;
  32131. }
  32132. }
  32133. // Reset if next unitName is primary
  32134. currentLevelTicks = [];
  32135. }
  32136. }
  32137. var levelsTicksInExtent = filter(map(levelsTicks, function (levelTicks) {
  32138. return filter(levelTicks, function (tick) {
  32139. return tick.value >= extent[0] && tick.value <= extent[1] && !tick.notAdd;
  32140. });
  32141. }), function (levelTicks) {
  32142. return levelTicks.length > 0;
  32143. });
  32144. var ticks = [];
  32145. var maxLevel = levelsTicksInExtent.length - 1;
  32146. for (var i = 0; i < levelsTicksInExtent.length; ++i) {
  32147. var levelTicks = levelsTicksInExtent[i];
  32148. for (var k = 0; k < levelTicks.length; ++k) {
  32149. var unit = getUnitFromValue(levelTicks[k].value, isUTC);
  32150. ticks.push({
  32151. value: levelTicks[k].value,
  32152. time: {
  32153. level: maxLevel - i,
  32154. upperTimeUnit: unit,
  32155. lowerTimeUnit: unit
  32156. }
  32157. });
  32158. }
  32159. }
  32160. ticks.sort(function (a, b) {
  32161. return a.value - b.value;
  32162. });
  32163. // Remove duplicates
  32164. var result = [];
  32165. for (var i = 0; i < ticks.length; ++i) {
  32166. if (i === 0 || ticks[i].value !== ticks[i - 1].value) {
  32167. result.push(ticks[i]);
  32168. }
  32169. }
  32170. return result;
  32171. }
  32172. Scale.registerClass(TimeScale);
  32173. var fixRound = round;
  32174. var mathFloor = Math.floor;
  32175. var mathCeil = Math.ceil;
  32176. var mathPow$1 = Math.pow;
  32177. var mathLog = Math.log;
  32178. var LogScale = /** @class */function (_super) {
  32179. __extends(LogScale, _super);
  32180. function LogScale() {
  32181. var _this = _super !== null && _super.apply(this, arguments) || this;
  32182. _this.type = 'log';
  32183. _this.base = 10;
  32184. _this._originalScale = new IntervalScale();
  32185. return _this;
  32186. }
  32187. /**
  32188. * @param Whether expand the ticks to niced extent.
  32189. */
  32190. LogScale.prototype.getTicks = function (opt) {
  32191. opt = opt || {};
  32192. var extent = this._extent.slice();
  32193. var originalExtent = this._originalScale.getExtent();
  32194. var ticks = _super.prototype.getTicks.call(this, opt);
  32195. var base = this.base;
  32196. var originalBreaks = this._originalScale._innerGetBreaks();
  32197. return map(ticks, function (tick) {
  32198. var val = tick.value;
  32199. var roundingCriterion = null;
  32200. var powVal = mathPow$1(base, val);
  32201. // Fix #4158
  32202. if (val === extent[0] && this._fixMin) {
  32203. roundingCriterion = originalExtent[0];
  32204. } else if (val === extent[1] && this._fixMax) {
  32205. roundingCriterion = originalExtent[1];
  32206. }
  32207. var vBreak;
  32208. if (roundingCriterion != null) {
  32209. powVal = fixRoundingError(powVal, roundingCriterion);
  32210. }
  32211. return {
  32212. value: powVal,
  32213. "break": vBreak
  32214. };
  32215. }, this);
  32216. };
  32217. LogScale.prototype._getNonTransBreaks = function () {
  32218. return this._originalScale._innerGetBreaks();
  32219. };
  32220. LogScale.prototype.setExtent = function (start, end) {
  32221. this._originalScale.setExtent(start, end);
  32222. var loggedExtent = logTransform(this.base, [start, end]);
  32223. _super.prototype.setExtent.call(this, loggedExtent[0], loggedExtent[1]);
  32224. };
  32225. /**
  32226. * @return {number} end
  32227. */
  32228. LogScale.prototype.getExtent = function () {
  32229. var base = this.base;
  32230. var extent = _super.prototype.getExtent.call(this);
  32231. extent[0] = mathPow$1(base, extent[0]);
  32232. extent[1] = mathPow$1(base, extent[1]);
  32233. // Fix #4158
  32234. var originalExtent = this._originalScale.getExtent();
  32235. this._fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  32236. this._fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  32237. return extent;
  32238. };
  32239. LogScale.prototype.unionExtentFromData = function (data, dim) {
  32240. this._originalScale.unionExtentFromData(data, dim);
  32241. var loggedOther = logTransform(this.base, data.getApproximateExtent(dim), true);
  32242. this._innerUnionExtent(loggedOther);
  32243. };
  32244. /**
  32245. * Update interval and extent of intervals for nice ticks
  32246. * @param approxTickNum default 10 Given approx tick number
  32247. */
  32248. LogScale.prototype.calcNiceTicks = function (approxTickNum) {
  32249. approxTickNum = approxTickNum || 10;
  32250. var extent = this._extent.slice();
  32251. var span = this._getExtentSpanWithBreaks();
  32252. if (!isFinite(span) || span <= 0) {
  32253. return;
  32254. }
  32255. var interval = quantity(span);
  32256. var err = approxTickNum / span * interval;
  32257. // Filter ticks to get closer to the desired count.
  32258. if (err <= 0.5) {
  32259. interval *= 10;
  32260. }
  32261. // Interval should be integer
  32262. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  32263. interval *= 10;
  32264. }
  32265. var niceExtent = [fixRound(mathCeil(extent[0] / interval) * interval), fixRound(mathFloor(extent[1] / interval) * interval)];
  32266. this._interval = interval;
  32267. this._intervalPrecision = getIntervalPrecision(interval);
  32268. this._niceExtent = niceExtent;
  32269. };
  32270. LogScale.prototype.calcNiceExtent = function (opt) {
  32271. _super.prototype.calcNiceExtent.call(this, opt);
  32272. this._fixMin = opt.fixMin;
  32273. this._fixMax = opt.fixMax;
  32274. };
  32275. LogScale.prototype.contain = function (val) {
  32276. val = mathLog(val) / mathLog(this.base);
  32277. return _super.prototype.contain.call(this, val);
  32278. };
  32279. LogScale.prototype.normalize = function (val) {
  32280. val = mathLog(val) / mathLog(this.base);
  32281. return _super.prototype.normalize.call(this, val);
  32282. };
  32283. LogScale.prototype.scale = function (val) {
  32284. val = _super.prototype.scale.call(this, val);
  32285. return mathPow$1(this.base, val);
  32286. };
  32287. LogScale.prototype.setBreaksFromOption = function (breakOptionList) {
  32288. {
  32289. return;
  32290. }
  32291. };
  32292. LogScale.type = 'log';
  32293. return LogScale;
  32294. }(IntervalScale);
  32295. function fixRoundingError(val, originalVal) {
  32296. return fixRound(val, getPrecision(originalVal));
  32297. }
  32298. Scale.registerClass(LogScale);
  32299. var ScaleRawExtentInfo = /** @class */function () {
  32300. function ScaleRawExtentInfo(scale, model,
  32301. // Usually: data extent from all series on this axis.
  32302. originalExtent) {
  32303. this._prepareParams(scale, model, originalExtent);
  32304. }
  32305. /**
  32306. * Parameters depending on outside (like model, user callback)
  32307. * are prepared and fixed here.
  32308. */
  32309. ScaleRawExtentInfo.prototype._prepareParams = function (scale, model,
  32310. // Usually: data extent from all series on this axis.
  32311. dataExtent) {
  32312. if (dataExtent[1] < dataExtent[0]) {
  32313. dataExtent = [NaN, NaN];
  32314. }
  32315. this._dataMin = dataExtent[0];
  32316. this._dataMax = dataExtent[1];
  32317. var isOrdinal = this._isOrdinal = scale.type === 'ordinal';
  32318. this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();
  32319. var axisMinValue = model.get('min', true);
  32320. if (axisMinValue == null) {
  32321. axisMinValue = model.get('startValue', true);
  32322. }
  32323. var modelMinRaw = this._modelMinRaw = axisMinValue;
  32324. if (isFunction(modelMinRaw)) {
  32325. // This callback always provides users the full data extent (before data is filtered).
  32326. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw({
  32327. min: dataExtent[0],
  32328. max: dataExtent[1]
  32329. }));
  32330. } else if (modelMinRaw !== 'dataMin') {
  32331. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw);
  32332. }
  32333. var modelMaxRaw = this._modelMaxRaw = model.get('max', true);
  32334. if (isFunction(modelMaxRaw)) {
  32335. // This callback always provides users the full data extent (before data is filtered).
  32336. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw({
  32337. min: dataExtent[0],
  32338. max: dataExtent[1]
  32339. }));
  32340. } else if (modelMaxRaw !== 'dataMax') {
  32341. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw);
  32342. }
  32343. if (isOrdinal) {
  32344. // FIXME: there is a flaw here: if there is no "block" data processor like `dataZoom`,
  32345. // and progressive rendering is using, here the category result might just only contain
  32346. // the processed chunk rather than the entire result.
  32347. this._axisDataLen = model.getCategories().length;
  32348. } else {
  32349. var boundaryGap = model.get('boundaryGap');
  32350. var boundaryGapArr = isArray(boundaryGap) ? boundaryGap : [boundaryGap || 0, boundaryGap || 0];
  32351. if (typeof boundaryGapArr[0] === 'boolean' || typeof boundaryGapArr[1] === 'boolean') {
  32352. if ("development" !== 'production') {
  32353. console.warn('Boolean type for boundaryGap is only ' + 'allowed for ordinal axis. Please use string in ' + 'percentage instead, e.g., "20%". Currently, ' + 'boundaryGap is set to be 0.');
  32354. }
  32355. this._boundaryGapInner = [0, 0];
  32356. } else {
  32357. this._boundaryGapInner = [parsePercent(boundaryGapArr[0], 1), parsePercent(boundaryGapArr[1], 1)];
  32358. }
  32359. }
  32360. };
  32361. /**
  32362. * Calculate extent by prepared parameters.
  32363. * This method has no external dependency and can be called duplicatedly,
  32364. * getting the same result.
  32365. * If parameters changed, should call this method to recalcuate.
  32366. */
  32367. ScaleRawExtentInfo.prototype.calculate = function () {
  32368. // Notice: When min/max is not set (that is, when there are null/undefined,
  32369. // which is the most common case), these cases should be ensured:
  32370. // (1) For 'ordinal', show all axis.data.
  32371. // (2) For others:
  32372. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  32373. // disabled).
  32374. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  32375. // be the result that originalExtent enlarged by boundaryGap.
  32376. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  32377. var isOrdinal = this._isOrdinal;
  32378. var dataMin = this._dataMin;
  32379. var dataMax = this._dataMax;
  32380. var axisDataLen = this._axisDataLen;
  32381. var boundaryGapInner = this._boundaryGapInner;
  32382. var span = !isOrdinal ? dataMax - dataMin || Math.abs(dataMin) : null;
  32383. // Currently if a `'value'` axis model min is specified as 'dataMin'/'dataMax',
  32384. // `boundaryGap` will not be used. It's the different from specifying as `null`/`undefined`.
  32385. var min = this._modelMinRaw === 'dataMin' ? dataMin : this._modelMinNum;
  32386. var max = this._modelMaxRaw === 'dataMax' ? dataMax : this._modelMaxNum;
  32387. // If `_modelMinNum`/`_modelMaxNum` is `null`/`undefined`, should not be fixed.
  32388. var minFixed = min != null;
  32389. var maxFixed = max != null;
  32390. if (min == null) {
  32391. min = isOrdinal ? axisDataLen ? 0 : NaN : dataMin - boundaryGapInner[0] * span;
  32392. }
  32393. if (max == null) {
  32394. max = isOrdinal ? axisDataLen ? axisDataLen - 1 : NaN : dataMax + boundaryGapInner[1] * span;
  32395. }
  32396. (min == null || !isFinite(min)) && (min = NaN);
  32397. (max == null || !isFinite(max)) && (max = NaN);
  32398. var isBlank = eqNaN(min) || eqNaN(max) || isOrdinal && !axisDataLen;
  32399. // If data extent modified, need to recalculated to ensure cross zero.
  32400. if (this._needCrossZero) {
  32401. // Axis is over zero and min is not set
  32402. if (min > 0 && max > 0 && !minFixed) {
  32403. min = 0;
  32404. // minFixed = true;
  32405. }
  32406. // Axis is under zero and max is not set
  32407. if (min < 0 && max < 0 && !maxFixed) {
  32408. max = 0;
  32409. // maxFixed = true;
  32410. }
  32411. // PENDING:
  32412. // When `needCrossZero` and all data is positive/negative, should it be ensured
  32413. // that the results processed by boundaryGap are positive/negative?
  32414. // If so, here `minFixed`/`maxFixed` need to be set.
  32415. }
  32416. var determinedMin = this._determinedMin;
  32417. var determinedMax = this._determinedMax;
  32418. if (determinedMin != null) {
  32419. min = determinedMin;
  32420. minFixed = true;
  32421. }
  32422. if (determinedMax != null) {
  32423. max = determinedMax;
  32424. maxFixed = true;
  32425. }
  32426. // Ensure min/max be finite number or NaN here. (not to be null/undefined)
  32427. // `NaN` means min/max axis is blank.
  32428. return {
  32429. min: min,
  32430. max: max,
  32431. minFixed: minFixed,
  32432. maxFixed: maxFixed,
  32433. isBlank: isBlank
  32434. };
  32435. };
  32436. ScaleRawExtentInfo.prototype.modifyDataMinMax = function (minMaxName, val) {
  32437. if ("development" !== 'production') {
  32438. assert(!this.frozen);
  32439. }
  32440. this[DATA_MIN_MAX_ATTR[minMaxName]] = val;
  32441. };
  32442. ScaleRawExtentInfo.prototype.setDeterminedMinMax = function (minMaxName, val) {
  32443. var attr = DETERMINED_MIN_MAX_ATTR[minMaxName];
  32444. if ("development" !== 'production') {
  32445. assert(!this.frozen
  32446. // Earse them usually means logic flaw.
  32447. && this[attr] == null);
  32448. }
  32449. this[attr] = val;
  32450. };
  32451. ScaleRawExtentInfo.prototype.freeze = function () {
  32452. // @ts-ignore
  32453. this.frozen = true;
  32454. };
  32455. return ScaleRawExtentInfo;
  32456. }();
  32457. var DETERMINED_MIN_MAX_ATTR = {
  32458. min: '_determinedMin',
  32459. max: '_determinedMax'
  32460. };
  32461. var DATA_MIN_MAX_ATTR = {
  32462. min: '_dataMin',
  32463. max: '_dataMax'
  32464. };
  32465. /**
  32466. * Get scale min max and related info only depends on model settings.
  32467. * This method can be called after coordinate system created.
  32468. * For example, in data processing stage.
  32469. *
  32470. * Scale extent info probably be required multiple times during a workflow.
  32471. * For example:
  32472. * (1) `dataZoom` depends it to get the axis extent in "100%" state.
  32473. * (2) `processor/extentCalculator` depends it to make sure whether axis extent is specified.
  32474. * (3) `coordSys.update` use it to finally decide the scale extent.
  32475. * But the callback of `min`/`max` should not be called multiple times.
  32476. * The code below should not be implemented repeatedly either.
  32477. * So we cache the result in the scale instance, which will be recreated at the beginning
  32478. * of the workflow (because `scale` instance will be recreated each round of the workflow).
  32479. */
  32480. function ensureScaleRawExtentInfo(scale, model,
  32481. // Usually: data extent from all series on this axis.
  32482. originalExtent) {
  32483. // Do not permit to recreate.
  32484. var rawExtentInfo = scale.rawExtentInfo;
  32485. if (rawExtentInfo) {
  32486. return rawExtentInfo;
  32487. }
  32488. rawExtentInfo = new ScaleRawExtentInfo(scale, model, originalExtent);
  32489. // @ts-ignore
  32490. scale.rawExtentInfo = rawExtentInfo;
  32491. return rawExtentInfo;
  32492. }
  32493. function parseAxisModelMinMax(scale, minMax) {
  32494. return minMax == null ? null : eqNaN(minMax) ? NaN : scale.parse(minMax);
  32495. }
  32496. /**
  32497. * Get axis scale extent before niced.
  32498. * Item of returned array can only be number (including Infinity and NaN).
  32499. *
  32500. * Caution:
  32501. * Precondition of calling this method:
  32502. * The scale extent has been initialized using series data extent via
  32503. * `scale.setExtent` or `scale.unionExtentFromData`;
  32504. */
  32505. function getScaleExtent(scale, model) {
  32506. var scaleType = scale.type;
  32507. var rawExtentResult = ensureScaleRawExtentInfo(scale, model, scale.getExtent()).calculate();
  32508. scale.setBlank(rawExtentResult.isBlank);
  32509. var min = rawExtentResult.min;
  32510. var max = rawExtentResult.max;
  32511. // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  32512. // is base axis
  32513. // FIXME
  32514. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  32515. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  32516. // Should not depend on series type `bar`?
  32517. // (3) Fix that might overlap when using dataZoom.
  32518. // (4) Consider other chart types using `barGrid`?
  32519. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  32520. var ecModel = model.ecModel;
  32521. if (ecModel && scaleType === 'time' /* || scaleType === 'interval' */) {
  32522. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  32523. var isBaseAxisAndHasBarSeries_1 = false;
  32524. each(barSeriesModels, function (seriesModel) {
  32525. isBaseAxisAndHasBarSeries_1 = isBaseAxisAndHasBarSeries_1 || seriesModel.getBaseAxis() === model.axis;
  32526. });
  32527. if (isBaseAxisAndHasBarSeries_1) {
  32528. // Calculate placement of bars on axis. TODO should be decoupled
  32529. // with barLayout
  32530. var barWidthAndOffset = makeColumnLayout(barSeriesModels);
  32531. // Adjust axis min and max to account for overflow
  32532. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  32533. min = adjustedScale.min;
  32534. max = adjustedScale.max;
  32535. }
  32536. }
  32537. return {
  32538. extent: [min, max],
  32539. // "fix" means "fixed", the value should not be
  32540. // changed in the subsequent steps.
  32541. fixMin: rawExtentResult.minFixed,
  32542. fixMax: rawExtentResult.maxFixed
  32543. };
  32544. }
  32545. function adjustScaleForOverflow(min, max, model,
  32546. // Only support cartesian coord yet.
  32547. barWidthAndOffset) {
  32548. // Get Axis Length
  32549. var axisExtent = model.axis.getExtent();
  32550. var axisLength = Math.abs(axisExtent[1] - axisExtent[0]);
  32551. // Get bars on current base axis and calculate min and max overflow
  32552. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  32553. if (barsOnCurrentAxis === undefined) {
  32554. return {
  32555. min: min,
  32556. max: max
  32557. };
  32558. }
  32559. var minOverflow = Infinity;
  32560. each(barsOnCurrentAxis, function (item) {
  32561. minOverflow = Math.min(item.offset, minOverflow);
  32562. });
  32563. var maxOverflow = -Infinity;
  32564. each(barsOnCurrentAxis, function (item) {
  32565. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  32566. });
  32567. minOverflow = Math.abs(minOverflow);
  32568. maxOverflow = Math.abs(maxOverflow);
  32569. var totalOverFlow = minOverflow + maxOverflow;
  32570. // Calculate required buffer based on old range and overflow
  32571. var oldRange = max - min;
  32572. var oldRangePercentOfNew = 1 - (minOverflow + maxOverflow) / axisLength;
  32573. var overflowBuffer = oldRange / oldRangePercentOfNew - oldRange;
  32574. max += overflowBuffer * (maxOverflow / totalOverFlow);
  32575. min -= overflowBuffer * (minOverflow / totalOverFlow);
  32576. return {
  32577. min: min,
  32578. max: max
  32579. };
  32580. }
  32581. // Precondition of calling this method:
  32582. // The scale extent has been initialized using series data extent via
  32583. // `scale.setExtent` or `scale.unionExtentFromData`;
  32584. function niceScaleExtent(scale, inModel) {
  32585. var model = inModel;
  32586. var extentInfo = getScaleExtent(scale, model);
  32587. var extent = extentInfo.extent;
  32588. var splitNumber = model.get('splitNumber');
  32589. if (scale instanceof LogScale) {
  32590. scale.base = model.get('logBase');
  32591. }
  32592. var scaleType = scale.type;
  32593. var interval = model.get('interval');
  32594. var isIntervalOrTime = scaleType === 'interval' || scaleType === 'time';
  32595. scale.setBreaksFromOption(retrieveAxisBreaksOption(model));
  32596. scale.setExtent(extent[0], extent[1]);
  32597. scale.calcNiceExtent({
  32598. splitNumber: splitNumber,
  32599. fixMin: extentInfo.fixMin,
  32600. fixMax: extentInfo.fixMax,
  32601. minInterval: isIntervalOrTime ? model.get('minInterval') : null,
  32602. maxInterval: isIntervalOrTime ? model.get('maxInterval') : null
  32603. });
  32604. // If some one specified the min, max. And the default calculated interval
  32605. // is not good enough. He can specify the interval. It is often appeared
  32606. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  32607. // to be 60.
  32608. // FIXME
  32609. if (interval != null) {
  32610. scale.setInterval && scale.setInterval(interval);
  32611. }
  32612. }
  32613. /**
  32614. * @param axisType Default retrieve from model.type
  32615. */
  32616. function createScaleByModel(model, axisType) {
  32617. axisType = axisType || model.get('type');
  32618. if (axisType) {
  32619. switch (axisType) {
  32620. // Buildin scale
  32621. case 'category':
  32622. return new OrdinalScale({
  32623. ordinalMeta: model.getOrdinalMeta ? model.getOrdinalMeta() : model.getCategories(),
  32624. extent: [Infinity, -Infinity]
  32625. });
  32626. case 'time':
  32627. return new TimeScale({
  32628. locale: model.ecModel.getLocaleModel(),
  32629. useUTC: model.ecModel.get('useUTC')
  32630. });
  32631. default:
  32632. // case 'value'/'interval', 'log', or others.
  32633. return new (Scale.getClass(axisType) || IntervalScale)();
  32634. }
  32635. }
  32636. }
  32637. /**
  32638. * Check if the axis cross 0
  32639. */
  32640. function ifAxisCrossZero(axis) {
  32641. var dataExtent = axis.scale.getExtent();
  32642. var min = dataExtent[0];
  32643. var max = dataExtent[1];
  32644. return !(min > 0 && max > 0 || min < 0 && max < 0);
  32645. }
  32646. /**
  32647. * @param axis
  32648. * @return Label formatter function.
  32649. * param: {number} tickValue,
  32650. * param: {number} idx, the index in all ticks.
  32651. * If category axis, this param is not required.
  32652. * return: {string} label string.
  32653. */
  32654. function makeLabelFormatter(axis) {
  32655. var labelFormatter = axis.getLabelModel().get('formatter');
  32656. if (axis.type === 'time') {
  32657. var parsed_1 = parseTimeAxisLabelFormatter(labelFormatter);
  32658. return function (tick, idx) {
  32659. return axis.scale.getFormattedLabel(tick, idx, parsed_1);
  32660. };
  32661. } else if (isString(labelFormatter)) {
  32662. return function (tick) {
  32663. // For category axis, get raw value; for numeric axis,
  32664. // get formatted label like '1,333,444'.
  32665. var label = axis.scale.getLabel(tick);
  32666. var text = labelFormatter.replace('{value}', label != null ? label : '');
  32667. return text;
  32668. };
  32669. } else if (isFunction(labelFormatter)) {
  32670. if (axis.type === 'category') {
  32671. return function (tick, idx) {
  32672. // The original intention of `idx` is "the index of the tick in all ticks".
  32673. // But the previous implementation of category axis do not consider the
  32674. // `axisLabel.interval`, which cause that, for example, the `interval` is
  32675. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  32676. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  32677. // the definition here for back compatibility.
  32678. return labelFormatter(getAxisRawValue(axis, tick), tick.value - axis.scale.getExtent()[0], null // Using `null` just for backward compat.
  32679. );
  32680. };
  32681. }
  32682. var scaleBreakHelper_1 = getScaleBreakHelper();
  32683. return function (tick, idx) {
  32684. // Using `null` just for backward compat. It's been found that in the `test/axis-customTicks.html`,
  32685. // there is a formatter `function (value, index, revers = true) { ... }`. Although the third param
  32686. // `revers` is incorrect and always `null`, changing it might introduce a breaking change.
  32687. var extra = null;
  32688. if (scaleBreakHelper_1) {
  32689. extra = scaleBreakHelper_1.makeAxisLabelFormatterParamBreak(extra, tick["break"]);
  32690. }
  32691. return labelFormatter(getAxisRawValue(axis, tick), idx, extra);
  32692. };
  32693. } else {
  32694. return function (tick) {
  32695. return axis.scale.getLabel(tick);
  32696. };
  32697. }
  32698. }
  32699. function getAxisRawValue(axis, tick) {
  32700. // In category axis with data zoom, tick is not the original
  32701. // index of axis.data. So tick should not be exposed to user
  32702. // in category axis.
  32703. return axis.type === 'category' ? axis.scale.getLabel(tick) : tick.value;
  32704. }
  32705. /**
  32706. * @param model axisLabelModel or axisTickModel
  32707. * @return {number|String} Can be null|'auto'|number|function
  32708. */
  32709. function getOptionCategoryInterval(model) {
  32710. var interval = model.get('interval');
  32711. return interval == null ? 'auto' : interval;
  32712. }
  32713. /**
  32714. * Set `categoryInterval` as 0 implicitly indicates that
  32715. * show all labels regardless of overlap.
  32716. * @param {Object} axis axisModel.axis
  32717. */
  32718. function shouldShowAllLabels(axis) {
  32719. return axis.type === 'category' && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  32720. }
  32721. function getDataDimensionsOnAxis(data, axisDim) {
  32722. // Remove duplicated dat dimensions caused by `getStackedDimension`.
  32723. var dataDimMap = {};
  32724. // Currently `mapDimensionsAll` will contain stack result dimension ('__\0ecstackresult').
  32725. // PENDING: is it reasonable? Do we need to remove the original dim from "coord dim" since
  32726. // there has been stacked result dim?
  32727. each(data.mapDimensionsAll(axisDim), function (dataDim) {
  32728. // For example, the extent of the original dimension
  32729. // is [0.1, 0.5], the extent of the `stackResultDimension`
  32730. // is [7, 9], the final extent should NOT include [0.1, 0.5],
  32731. // because there is no graphic corresponding to [0.1, 0.5].
  32732. // See the case in `test/area-stack.html` `main1`, where area line
  32733. // stack needs `yAxis` not start from 0.
  32734. dataDimMap[getStackedDimension(data, dataDim)] = true;
  32735. });
  32736. return keys(dataDimMap);
  32737. }
  32738. function isNameLocationCenter(nameLocation) {
  32739. return nameLocation === 'middle' || nameLocation === 'center';
  32740. }
  32741. function shouldAxisShow(axisModel) {
  32742. return axisModel.getShallow('show');
  32743. }
  32744. function retrieveAxisBreaksOption(model) {
  32745. var option = model.get('breaks', true);
  32746. if (option != null) {
  32747. {
  32748. if ("development" !== 'production') {
  32749. error('Must `import {AxisBreak} from "echarts/features.js"; use(AxisBreak);` first if using breaks option.');
  32750. }
  32751. return undefined;
  32752. }
  32753. }
  32754. }
  32755. /*
  32756. * Licensed to the Apache Software Foundation (ASF) under one
  32757. * or more contributor license agreements. See the NOTICE file
  32758. * distributed with this work for additional information
  32759. * regarding copyright ownership. The ASF licenses this file
  32760. * to you under the Apache License, Version 2.0 (the
  32761. * "License"); you may not use this file except in compliance
  32762. * with the License. You may obtain a copy of the License at
  32763. *
  32764. * http://www.apache.org/licenses/LICENSE-2.0
  32765. *
  32766. * Unless required by applicable law or agreed to in writing,
  32767. * software distributed under the License is distributed on an
  32768. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32769. * KIND, either express or implied. See the License for the
  32770. * specific language governing permissions and limitations
  32771. * under the License.
  32772. */
  32773. /**
  32774. * AUTO-GENERATED FILE. DO NOT MODIFY.
  32775. */
  32776. /*
  32777. * Licensed to the Apache Software Foundation (ASF) under one
  32778. * or more contributor license agreements. See the NOTICE file
  32779. * distributed with this work for additional information
  32780. * regarding copyright ownership. The ASF licenses this file
  32781. * to you under the Apache License, Version 2.0 (the
  32782. * "License"); you may not use this file except in compliance
  32783. * with the License. You may obtain a copy of the License at
  32784. *
  32785. * http://www.apache.org/licenses/LICENSE-2.0
  32786. *
  32787. * Unless required by applicable law or agreed to in writing,
  32788. * software distributed under the License is distributed on an
  32789. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32790. * KIND, either express or implied. See the License for the
  32791. * specific language governing permissions and limitations
  32792. * under the License.
  32793. */
  32794. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  32795. var AxisModelCommonMixin = /** @class */function () {
  32796. function AxisModelCommonMixin() {}
  32797. AxisModelCommonMixin.prototype.getNeedCrossZero = function () {
  32798. var option = this.option;
  32799. return !option.scale;
  32800. };
  32801. /**
  32802. * Should be implemented by each axis model if necessary.
  32803. * @return coordinate system model
  32804. */
  32805. AxisModelCommonMixin.prototype.getCoordSysModel = function () {
  32806. return;
  32807. };
  32808. return AxisModelCommonMixin;
  32809. }();
  32810. /**
  32811. * Create a multi dimension List structure from seriesModel.
  32812. */
  32813. function createList(seriesModel) {
  32814. return createSeriesData(null, seriesModel);
  32815. }
  32816. var dataStack$1 = {
  32817. isDimensionStacked: isDimensionStacked,
  32818. enableDataStack: enableDataStack,
  32819. getStackedDimension: getStackedDimension
  32820. };
  32821. /**
  32822. * Create scale
  32823. * @param {Array.<number>} dataExtent
  32824. * @param {Object|module:echarts/Model} option If `optoin.type`
  32825. * is secified, it can only be `'value'` currently.
  32826. */
  32827. function createScale(dataExtent, option) {
  32828. var axisModel = option;
  32829. if (!(option instanceof Model)) {
  32830. axisModel = new Model(option);
  32831. // FIXME
  32832. // Currently AxisModelCommonMixin has nothing to do with the
  32833. // the requirements of `axisHelper.createScaleByModel`. For
  32834. // example the methods `getCategories` and `getOrdinalMeta`
  32835. // are required for `'category'` axis, and ecModel is required
  32836. // for `'time'` axis. But occasionally echarts-gl happened
  32837. // to only use `'value'` axis.
  32838. // zrUtil.mixin(axisModel, AxisModelCommonMixin);
  32839. }
  32840. var scale = createScaleByModel(axisModel);
  32841. scale.setExtent(dataExtent[0], dataExtent[1]);
  32842. niceScaleExtent(scale, axisModel);
  32843. return scale;
  32844. }
  32845. /**
  32846. * Mixin common methods to axis model,
  32847. *
  32848. * Include methods
  32849. * `getFormattedLabels() => Array.<string>`
  32850. * `getCategories() => Array.<string>`
  32851. * `getMin(origin: boolean) => number`
  32852. * `getMax(origin: boolean) => number`
  32853. * `getNeedCrossZero() => boolean`
  32854. */
  32855. function mixinAxisModelCommonMethods(Model) {
  32856. mixin(Model, AxisModelCommonMixin);
  32857. }
  32858. function createTextStyle$1(textStyleModel, opts) {
  32859. opts = opts || {};
  32860. return createTextStyle(textStyleModel, null, null, opts.state !== 'normal');
  32861. }
  32862. var helper = /*#__PURE__*/Object.freeze({
  32863. __proto__: null,
  32864. createList: createList,
  32865. getLayoutRect: getLayoutRect,
  32866. dataStack: dataStack$1,
  32867. createScale: createScale,
  32868. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  32869. getECData: getECData,
  32870. createTextStyle: createTextStyle$1,
  32871. createDimensions: createDimensions,
  32872. createSymbol: createSymbol,
  32873. enableHoverEmphasis: enableHoverEmphasis
  32874. });
  32875. var EPSILON$4 = 1e-8;
  32876. function isAroundEqual$1(a, b) {
  32877. return Math.abs(a - b) < EPSILON$4;
  32878. }
  32879. function contain$2(points, x, y) {
  32880. var w = 0;
  32881. var p = points[0];
  32882. if (!p) {
  32883. return false;
  32884. }
  32885. for (var i = 1; i < points.length; i++) {
  32886. var p2 = points[i];
  32887. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  32888. p = p2;
  32889. }
  32890. var p0 = points[0];
  32891. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  32892. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  32893. }
  32894. return w !== 0;
  32895. }
  32896. var TMP_TRANSFORM = [];
  32897. function transformPoints(points, transform) {
  32898. for (var p = 0; p < points.length; p++) {
  32899. applyTransform(points[p], points[p], transform);
  32900. }
  32901. }
  32902. function updateBBoxFromPoints(points, min$1, max$1, projection) {
  32903. for (var i = 0; i < points.length; i++) {
  32904. var p = points[i];
  32905. if (projection) {
  32906. // projection may return null point.
  32907. p = projection.project(p);
  32908. }
  32909. if (p && isFinite(p[0]) && isFinite(p[1])) {
  32910. min(min$1, min$1, p);
  32911. max(max$1, max$1, p);
  32912. }
  32913. }
  32914. }
  32915. function centroid(points) {
  32916. var signedArea = 0;
  32917. var cx = 0;
  32918. var cy = 0;
  32919. var len = points.length;
  32920. var x0 = points[len - 1][0];
  32921. var y0 = points[len - 1][1];
  32922. // Polygon should been closed.
  32923. for (var i = 0; i < len; i++) {
  32924. var x1 = points[i][0];
  32925. var y1 = points[i][1];
  32926. var a = x0 * y1 - x1 * y0;
  32927. signedArea += a;
  32928. cx += (x0 + x1) * a;
  32929. cy += (y0 + y1) * a;
  32930. x0 = x1;
  32931. y0 = y1;
  32932. }
  32933. return signedArea ? [cx / signedArea / 3, cy / signedArea / 3, signedArea] : [points[0][0] || 0, points[0][1] || 0];
  32934. }
  32935. var Region = /** @class */function () {
  32936. function Region(name) {
  32937. this.name = name;
  32938. }
  32939. Region.prototype.setCenter = function (center) {
  32940. this._center = center;
  32941. };
  32942. /**
  32943. * Get center point in data unit. That is,
  32944. * for GeoJSONRegion, the unit is lat/lng,
  32945. * for GeoSVGRegion, the unit is SVG local coord.
  32946. */
  32947. Region.prototype.getCenter = function () {
  32948. var center = this._center;
  32949. if (!center) {
  32950. // In most cases there are no need to calculate this center.
  32951. // So calculate only when called.
  32952. center = this._center = this.calcCenter();
  32953. }
  32954. return center;
  32955. };
  32956. return Region;
  32957. }();
  32958. var GeoJSONPolygonGeometry = /** @class */function () {
  32959. function GeoJSONPolygonGeometry(exterior, interiors) {
  32960. this.type = 'polygon';
  32961. this.exterior = exterior;
  32962. this.interiors = interiors;
  32963. }
  32964. return GeoJSONPolygonGeometry;
  32965. }();
  32966. var GeoJSONLineStringGeometry = /** @class */function () {
  32967. function GeoJSONLineStringGeometry(points) {
  32968. this.type = 'linestring';
  32969. this.points = points;
  32970. }
  32971. return GeoJSONLineStringGeometry;
  32972. }();
  32973. var GeoJSONRegion = /** @class */function (_super) {
  32974. __extends(GeoJSONRegion, _super);
  32975. function GeoJSONRegion(name, geometries, cp) {
  32976. var _this = _super.call(this, name) || this;
  32977. _this.type = 'geoJSON';
  32978. _this.geometries = geometries;
  32979. _this._center = cp && [cp[0], cp[1]];
  32980. return _this;
  32981. }
  32982. GeoJSONRegion.prototype.calcCenter = function () {
  32983. var geometries = this.geometries;
  32984. var largestGeo;
  32985. var largestGeoSize = 0;
  32986. for (var i = 0; i < geometries.length; i++) {
  32987. var geo = geometries[i];
  32988. var exterior = geo.exterior;
  32989. // Simple trick to use points count instead of polygon area as region size.
  32990. // Ignore linestring
  32991. var size = exterior && exterior.length;
  32992. if (size > largestGeoSize) {
  32993. largestGeo = geo;
  32994. largestGeoSize = size;
  32995. }
  32996. }
  32997. if (largestGeo) {
  32998. return centroid(largestGeo.exterior);
  32999. }
  33000. // from bounding rect by default.
  33001. var rect = this.getBoundingRect();
  33002. return [rect.x + rect.width / 2, rect.y + rect.height / 2];
  33003. };
  33004. GeoJSONRegion.prototype.getBoundingRect = function (projection) {
  33005. var rect = this._rect;
  33006. // Always recalculate if using projection.
  33007. if (rect && !projection) {
  33008. return rect;
  33009. }
  33010. var min = [Infinity, Infinity];
  33011. var max = [-Infinity, -Infinity];
  33012. var geometries = this.geometries;
  33013. each(geometries, function (geo) {
  33014. if (geo.type === 'polygon') {
  33015. // Doesn't consider hole
  33016. updateBBoxFromPoints(geo.exterior, min, max, projection);
  33017. } else {
  33018. each(geo.points, function (points) {
  33019. updateBBoxFromPoints(points, min, max, projection);
  33020. });
  33021. }
  33022. });
  33023. // Normalie invalid bounding.
  33024. if (!(isFinite(min[0]) && isFinite(min[1]) && isFinite(max[0]) && isFinite(max[1]))) {
  33025. min[0] = min[1] = max[0] = max[1] = 0;
  33026. }
  33027. rect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  33028. if (!projection) {
  33029. this._rect = rect;
  33030. }
  33031. return rect;
  33032. };
  33033. GeoJSONRegion.prototype.contain = function (coord) {
  33034. var rect = this.getBoundingRect();
  33035. var geometries = this.geometries;
  33036. if (!rect.contain(coord[0], coord[1])) {
  33037. return false;
  33038. }
  33039. loopGeo: for (var i = 0, len = geometries.length; i < len; i++) {
  33040. var geo = geometries[i];
  33041. // Only support polygon.
  33042. if (geo.type !== 'polygon') {
  33043. continue;
  33044. }
  33045. var exterior = geo.exterior;
  33046. var interiors = geo.interiors;
  33047. if (contain$2(exterior, coord[0], coord[1])) {
  33048. // Not in the region if point is in the hole.
  33049. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  33050. if (contain$2(interiors[k], coord[0], coord[1])) {
  33051. continue loopGeo;
  33052. }
  33053. }
  33054. return true;
  33055. }
  33056. }
  33057. return false;
  33058. };
  33059. /**
  33060. * Transform the raw coords to target bounding.
  33061. * @param x
  33062. * @param y
  33063. * @param width
  33064. * @param height
  33065. */
  33066. GeoJSONRegion.prototype.transformTo = function (x, y, width, height) {
  33067. var rect = this.getBoundingRect();
  33068. var aspect = rect.width / rect.height;
  33069. if (!width) {
  33070. width = aspect * height;
  33071. } else if (!height) {
  33072. height = width / aspect;
  33073. }
  33074. var target = new BoundingRect(x, y, width, height);
  33075. var transform = rect.calculateTransform(target);
  33076. var geometries = this.geometries;
  33077. for (var i = 0; i < geometries.length; i++) {
  33078. var geo = geometries[i];
  33079. if (geo.type === 'polygon') {
  33080. transformPoints(geo.exterior, transform);
  33081. each(geo.interiors, function (interior) {
  33082. transformPoints(interior, transform);
  33083. });
  33084. } else {
  33085. each(geo.points, function (points) {
  33086. transformPoints(points, transform);
  33087. });
  33088. }
  33089. }
  33090. rect = this._rect;
  33091. rect.copy(target);
  33092. // Update center
  33093. this._center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  33094. };
  33095. GeoJSONRegion.prototype.cloneShallow = function (name) {
  33096. name == null && (name = this.name);
  33097. var newRegion = new GeoJSONRegion(name, this.geometries, this._center);
  33098. newRegion._rect = this._rect;
  33099. newRegion.transformTo = null; // Simply avoid to be called.
  33100. return newRegion;
  33101. };
  33102. return GeoJSONRegion;
  33103. }(Region);
  33104. var GeoSVGRegion = /** @class */function (_super) {
  33105. __extends(GeoSVGRegion, _super);
  33106. function GeoSVGRegion(name, elOnlyForCalculate) {
  33107. var _this = _super.call(this, name) || this;
  33108. _this.type = 'geoSVG';
  33109. _this._elOnlyForCalculate = elOnlyForCalculate;
  33110. return _this;
  33111. }
  33112. GeoSVGRegion.prototype.calcCenter = function () {
  33113. var el = this._elOnlyForCalculate;
  33114. var rect = el.getBoundingRect();
  33115. var center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  33116. var mat = identity(TMP_TRANSFORM);
  33117. var target = el;
  33118. while (target && !target.isGeoSVGGraphicRoot) {
  33119. mul$1(mat, target.getLocalTransform(), mat);
  33120. target = target.parent;
  33121. }
  33122. invert(mat, mat);
  33123. applyTransform(center, center, mat);
  33124. return center;
  33125. };
  33126. return GeoSVGRegion;
  33127. }(Region);
  33128. function decode(json) {
  33129. if (!json.UTF8Encoding) {
  33130. return json;
  33131. }
  33132. var jsonCompressed = json;
  33133. var encodeScale = jsonCompressed.UTF8Scale;
  33134. if (encodeScale == null) {
  33135. encodeScale = 1024;
  33136. }
  33137. var features = jsonCompressed.features;
  33138. each(features, function (feature) {
  33139. var geometry = feature.geometry;
  33140. var encodeOffsets = geometry.encodeOffsets;
  33141. var coordinates = geometry.coordinates;
  33142. // Geometry may be appeded manually in the script after json loaded.
  33143. // In this case this geometry is usually not encoded.
  33144. if (!encodeOffsets) {
  33145. return;
  33146. }
  33147. switch (geometry.type) {
  33148. case 'LineString':
  33149. geometry.coordinates = decodeRing(coordinates, encodeOffsets, encodeScale);
  33150. break;
  33151. case 'Polygon':
  33152. decodeRings(coordinates, encodeOffsets, encodeScale);
  33153. break;
  33154. case 'MultiLineString':
  33155. decodeRings(coordinates, encodeOffsets, encodeScale);
  33156. break;
  33157. case 'MultiPolygon':
  33158. each(coordinates, function (rings, idx) {
  33159. return decodeRings(rings, encodeOffsets[idx], encodeScale);
  33160. });
  33161. }
  33162. });
  33163. // Has been decoded
  33164. jsonCompressed.UTF8Encoding = false;
  33165. return jsonCompressed;
  33166. }
  33167. function decodeRings(rings, encodeOffsets, encodeScale) {
  33168. for (var c = 0; c < rings.length; c++) {
  33169. rings[c] = decodeRing(rings[c], encodeOffsets[c], encodeScale);
  33170. }
  33171. }
  33172. function decodeRing(coordinate, encodeOffsets, encodeScale) {
  33173. var result = [];
  33174. var prevX = encodeOffsets[0];
  33175. var prevY = encodeOffsets[1];
  33176. for (var i = 0; i < coordinate.length; i += 2) {
  33177. var x = coordinate.charCodeAt(i) - 64;
  33178. var y = coordinate.charCodeAt(i + 1) - 64;
  33179. // ZigZag decoding
  33180. x = x >> 1 ^ -(x & 1);
  33181. y = y >> 1 ^ -(y & 1);
  33182. // Delta deocding
  33183. x += prevX;
  33184. y += prevY;
  33185. prevX = x;
  33186. prevY = y;
  33187. // Dequantize
  33188. result.push([x / encodeScale, y / encodeScale]);
  33189. }
  33190. return result;
  33191. }
  33192. function parseGeoJSON(geoJson, nameProperty) {
  33193. geoJson = decode(geoJson);
  33194. return map(filter(geoJson.features, function (featureObj) {
  33195. // Output of mapshaper may have geometry null
  33196. return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
  33197. }), function (featureObj) {
  33198. var properties = featureObj.properties;
  33199. var geo = featureObj.geometry;
  33200. var geometries = [];
  33201. switch (geo.type) {
  33202. case 'Polygon':
  33203. var coordinates = geo.coordinates;
  33204. // According to the GeoJSON specification.
  33205. // First must be exterior, and the rest are all interior(holes).
  33206. geometries.push(new GeoJSONPolygonGeometry(coordinates[0], coordinates.slice(1)));
  33207. break;
  33208. case 'MultiPolygon':
  33209. each(geo.coordinates, function (item) {
  33210. if (item[0]) {
  33211. geometries.push(new GeoJSONPolygonGeometry(item[0], item.slice(1)));
  33212. }
  33213. });
  33214. break;
  33215. case 'LineString':
  33216. geometries.push(new GeoJSONLineStringGeometry([geo.coordinates]));
  33217. break;
  33218. case 'MultiLineString':
  33219. geometries.push(new GeoJSONLineStringGeometry(geo.coordinates));
  33220. }
  33221. var region = new GeoJSONRegion(properties[nameProperty || 'name'], geometries, properties.cp);
  33222. region.properties = properties;
  33223. return region;
  33224. });
  33225. }
  33226. var number = /*#__PURE__*/Object.freeze({
  33227. __proto__: null,
  33228. linearMap: linearMap,
  33229. round: round,
  33230. asc: asc,
  33231. getPrecision: getPrecision,
  33232. getPrecisionSafe: getPrecisionSafe,
  33233. getPixelPrecision: getPixelPrecision,
  33234. getPercentWithPrecision: getPercentWithPrecision,
  33235. parsePercent: parsePercent$1,
  33236. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  33237. remRadian: remRadian,
  33238. isRadianAroundZero: isRadianAroundZero,
  33239. parseDate: parseDate,
  33240. quantity: quantity,
  33241. quantityExponent: quantityExponent,
  33242. nice: nice,
  33243. quantile: quantile,
  33244. reformIntervals: reformIntervals,
  33245. isNumeric: isNumeric,
  33246. numericToNumber: numericToNumber
  33247. });
  33248. var time = /*#__PURE__*/Object.freeze({
  33249. __proto__: null,
  33250. parse: parseDate,
  33251. format: format,
  33252. roundTime: roundTime
  33253. });
  33254. var graphic = /*#__PURE__*/Object.freeze({
  33255. __proto__: null,
  33256. extendShape: extendShape,
  33257. extendPath: extendPath,
  33258. makePath: makePath,
  33259. makeImage: makeImage,
  33260. mergePath: mergePath$1,
  33261. resizePath: resizePath,
  33262. createIcon: createIcon,
  33263. updateProps: updateProps,
  33264. initProps: initProps,
  33265. getTransform: getTransform,
  33266. clipPointsByRect: clipPointsByRect,
  33267. clipRectByRect: clipRectByRect,
  33268. registerShape: registerShape,
  33269. getShapeClass: getShapeClass,
  33270. Group: Group,
  33271. Image: ZRImage,
  33272. Text: ZRText,
  33273. Circle: Circle,
  33274. Ellipse: Ellipse,
  33275. Sector: Sector,
  33276. Ring: Ring,
  33277. Polygon: Polygon,
  33278. Polyline: Polyline,
  33279. Rect: Rect,
  33280. Line: Line,
  33281. BezierCurve: BezierCurve,
  33282. Arc: Arc,
  33283. IncrementalDisplayable: IncrementalDisplayable,
  33284. CompoundPath: CompoundPath,
  33285. LinearGradient: LinearGradient,
  33286. RadialGradient: RadialGradient,
  33287. BoundingRect: BoundingRect
  33288. });
  33289. var format$1 = /*#__PURE__*/Object.freeze({
  33290. __proto__: null,
  33291. addCommas: addCommas,
  33292. toCamelCase: toCamelCase,
  33293. normalizeCssArray: normalizeCssArray$1,
  33294. encodeHTML: encodeHTML,
  33295. formatTpl: formatTpl,
  33296. getTooltipMarker: getTooltipMarker,
  33297. formatTime: formatTime,
  33298. capitalFirst: capitalFirst,
  33299. truncateText: truncateText,
  33300. getTextRect: getTextRect
  33301. });
  33302. var util$1 = /*#__PURE__*/Object.freeze({
  33303. __proto__: null,
  33304. map: map,
  33305. each: each,
  33306. indexOf: indexOf,
  33307. inherits: inherits,
  33308. reduce: reduce,
  33309. filter: filter,
  33310. bind: bind,
  33311. curry: curry,
  33312. isArray: isArray,
  33313. isString: isString,
  33314. isObject: isObject,
  33315. isFunction: isFunction,
  33316. extend: extend,
  33317. defaults: defaults,
  33318. clone: clone,
  33319. merge: merge
  33320. });
  33321. var modelInner = makeInner();
  33322. var axisInner = makeInner();
  33323. var AxisTickLabelComputingKind = {
  33324. estimate: 1,
  33325. determine: 2
  33326. };
  33327. function createAxisLabelsComputingContext(kind) {
  33328. return {
  33329. out: {
  33330. noPxChangeTryDetermine: []
  33331. },
  33332. kind: kind
  33333. };
  33334. }
  33335. function tickValuesToNumbers(axis, values) {
  33336. var nums = map(values, function (val) {
  33337. return axis.scale.parse(val);
  33338. });
  33339. if (axis.type === 'time' && nums.length > 0) {
  33340. // Time axis needs duplicate first/last tick (see TimeScale.getTicks())
  33341. // The first and last tick/label don't get drawn
  33342. nums.sort();
  33343. nums.unshift(nums[0]);
  33344. nums.push(nums[nums.length - 1]);
  33345. }
  33346. return nums;
  33347. }
  33348. function createAxisLabels(axis, ctx) {
  33349. var custom = axis.getLabelModel().get('customValues');
  33350. if (custom) {
  33351. var labelFormatter_1 = makeLabelFormatter(axis);
  33352. var extent_1 = axis.scale.getExtent();
  33353. var tickNumbers = tickValuesToNumbers(axis, custom);
  33354. var ticks = filter(tickNumbers, function (val) {
  33355. return val >= extent_1[0] && val <= extent_1[1];
  33356. });
  33357. return {
  33358. labels: map(ticks, function (numval) {
  33359. var tick = {
  33360. value: numval
  33361. };
  33362. return {
  33363. formattedLabel: labelFormatter_1(tick),
  33364. rawLabel: axis.scale.getLabel(tick),
  33365. tickValue: numval,
  33366. time: undefined,
  33367. "break": undefined
  33368. };
  33369. })
  33370. };
  33371. }
  33372. // Only ordinal scale support tick interval
  33373. return axis.type === 'category' ? makeCategoryLabels(axis, ctx) : makeRealNumberLabels(axis);
  33374. }
  33375. /**
  33376. * @param tickModel For example, can be axisTick, splitLine, splitArea.
  33377. */
  33378. function createAxisTicks(axis, tickModel, opt) {
  33379. var custom = axis.getTickModel().get('customValues');
  33380. if (custom) {
  33381. var extent_2 = axis.scale.getExtent();
  33382. var tickNumbers = tickValuesToNumbers(axis, custom);
  33383. return {
  33384. ticks: filter(tickNumbers, function (val) {
  33385. return val >= extent_2[0] && val <= extent_2[1];
  33386. })
  33387. };
  33388. }
  33389. // Only ordinal scale support tick interval
  33390. return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
  33391. ticks: map(axis.scale.getTicks(opt), function (tick) {
  33392. return tick.value;
  33393. })
  33394. };
  33395. }
  33396. function makeCategoryLabels(axis, ctx) {
  33397. var labelModel = axis.getLabelModel();
  33398. var result = makeCategoryLabelsActually(axis, labelModel, ctx);
  33399. return !labelModel.get('show') || axis.scale.isBlank() ? {
  33400. labels: []
  33401. } : result;
  33402. }
  33403. function makeCategoryLabelsActually(axis, labelModel, ctx) {
  33404. var labelsCache = ensureCategoryLabelCache(axis);
  33405. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  33406. var isEstimate = ctx.kind === AxisTickLabelComputingKind.estimate;
  33407. // In AxisTickLabelComputingKind.estimate, the result likely varies during a single
  33408. // pass of ec main process,due to the change of axisExtent, and will not be shared with
  33409. // splitLine. Therefore no cache is used.
  33410. if (!isEstimate) {
  33411. // PENDING: check necessary?
  33412. var result_1 = axisCacheGet(labelsCache, optionLabelInterval);
  33413. if (result_1) {
  33414. return result_1;
  33415. }
  33416. }
  33417. var labels;
  33418. var numericLabelInterval;
  33419. if (isFunction(optionLabelInterval)) {
  33420. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  33421. } else {
  33422. numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis, ctx) : optionLabelInterval;
  33423. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  33424. }
  33425. var result = {
  33426. labels: labels,
  33427. labelCategoryInterval: numericLabelInterval
  33428. };
  33429. if (!isEstimate) {
  33430. axisCacheSet(labelsCache, optionLabelInterval, result);
  33431. } else {
  33432. ctx.out.noPxChangeTryDetermine.push(function () {
  33433. axisCacheSet(labelsCache, optionLabelInterval, result);
  33434. return true;
  33435. });
  33436. }
  33437. return result;
  33438. }
  33439. function makeCategoryTicks(axis, tickModel) {
  33440. var ticksCache = ensureCategoryTickCache(axis);
  33441. var optionTickInterval = getOptionCategoryInterval(tickModel);
  33442. var result = axisCacheGet(ticksCache, optionTickInterval);
  33443. if (result) {
  33444. return result;
  33445. }
  33446. var ticks;
  33447. var tickCategoryInterval;
  33448. // Optimize for the case that large category data and no label displayed,
  33449. // we should not return all ticks.
  33450. if (!tickModel.get('show') || axis.scale.isBlank()) {
  33451. ticks = [];
  33452. }
  33453. if (isFunction(optionTickInterval)) {
  33454. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  33455. }
  33456. // Always use label interval by default despite label show. Consider this
  33457. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  33458. // labels. `splitLine` and `axisTick` should be consistent in this case.
  33459. else if (optionTickInterval === 'auto') {
  33460. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel(), createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine));
  33461. tickCategoryInterval = labelsResult.labelCategoryInterval;
  33462. ticks = map(labelsResult.labels, function (labelItem) {
  33463. return labelItem.tickValue;
  33464. });
  33465. } else {
  33466. tickCategoryInterval = optionTickInterval;
  33467. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  33468. }
  33469. // Cache to avoid calling interval function repeatedly.
  33470. return axisCacheSet(ticksCache, optionTickInterval, {
  33471. ticks: ticks,
  33472. tickCategoryInterval: tickCategoryInterval
  33473. });
  33474. }
  33475. function makeRealNumberLabels(axis) {
  33476. var ticks = axis.scale.getTicks();
  33477. var labelFormatter = makeLabelFormatter(axis);
  33478. return {
  33479. labels: map(ticks, function (tick, idx) {
  33480. return {
  33481. formattedLabel: labelFormatter(tick, idx),
  33482. rawLabel: axis.scale.getLabel(tick),
  33483. tickValue: tick.value,
  33484. time: tick.time,
  33485. "break": tick["break"]
  33486. };
  33487. })
  33488. };
  33489. }
  33490. // Large category data calculation is performance sensitive, and ticks and label probably will
  33491. // be fetched multiple times (e.g. shared by splitLine and axisTick). So we cache the result.
  33492. // axis is created each time during a ec process, so we do not need to clear cache.
  33493. var ensureCategoryTickCache = initAxisCacheMethod('axisTick');
  33494. var ensureCategoryLabelCache = initAxisCacheMethod('axisLabel');
  33495. /**
  33496. * PENDING: refactor to JS Map? Because key can be a function or more complicated object, and
  33497. * cache size always is small, and currently no JS Map object key polyfill, we use a simple
  33498. * array cache instead of plain object hash.
  33499. */
  33500. function initAxisCacheMethod(prop) {
  33501. return function ensureCache(axis) {
  33502. return axisInner(axis)[prop] || (axisInner(axis)[prop] = {
  33503. list: []
  33504. });
  33505. };
  33506. }
  33507. function axisCacheGet(cache, key) {
  33508. for (var i = 0; i < cache.list.length; i++) {
  33509. if (cache.list[i].key === key) {
  33510. return cache.list[i].value;
  33511. }
  33512. }
  33513. }
  33514. function axisCacheSet(cache, key, value) {
  33515. cache.list.push({
  33516. key: key,
  33517. value: value
  33518. });
  33519. return value;
  33520. }
  33521. function makeAutoCategoryInterval(axis, ctx) {
  33522. if (ctx.kind === AxisTickLabelComputingKind.estimate) {
  33523. // Currently axisTick is not involved in estimate kind, and the result likely varies during a
  33524. // single pass of ec main process, due to the change of axisExtent. Therefore no cache is used.
  33525. var result_2 = axis.calculateCategoryInterval(ctx);
  33526. ctx.out.noPxChangeTryDetermine.push(function () {
  33527. axisInner(axis).autoInterval = result_2;
  33528. return true;
  33529. });
  33530. return result_2;
  33531. }
  33532. // Both tick and label uses this result, cacah it to avoid recompute.
  33533. var result = axisInner(axis).autoInterval;
  33534. return result != null ? result : axisInner(axis).autoInterval = axis.calculateCategoryInterval(ctx);
  33535. }
  33536. /**
  33537. * Calculate interval for category axis ticks and labels.
  33538. * Use a stretegy to try to avoid overlapping.
  33539. * To get precise result, at least one of `getRotate` and `isHorizontal`
  33540. * should be implemented in axis.
  33541. */
  33542. function calculateCategoryInterval(axis, ctx) {
  33543. var kind = ctx.kind;
  33544. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  33545. var labelFormatter = makeLabelFormatter(axis);
  33546. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  33547. var ordinalScale = axis.scale;
  33548. var ordinalExtent = ordinalScale.getExtent();
  33549. // Providing this method is for optimization:
  33550. // avoid generating a long array by `getTicks`
  33551. // in large category data case.
  33552. var tickCount = ordinalScale.count();
  33553. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  33554. return 0;
  33555. }
  33556. var step = 1;
  33557. // Simple optimization. Arbitrary value.
  33558. var maxCount = 40;
  33559. if (tickCount > maxCount) {
  33560. step = Math.max(1, Math.floor(tickCount / maxCount));
  33561. }
  33562. var tickValue = ordinalExtent[0];
  33563. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  33564. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  33565. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  33566. var maxW = 0;
  33567. var maxH = 0;
  33568. // Caution: Performance sensitive for large category data.
  33569. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  33570. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  33571. var width = 0;
  33572. var height = 0;
  33573. // Not precise, do not consider align and vertical align
  33574. // and each distance from axis line yet.
  33575. var rect = getBoundingRect(labelFormatter({
  33576. value: tickValue
  33577. }), params.font, 'center', 'top');
  33578. // Magic number
  33579. width = rect.width * 1.3;
  33580. height = rect.height * 1.3;
  33581. // Min size, void long loop.
  33582. maxW = Math.max(maxW, width, 7);
  33583. maxH = Math.max(maxH, height, 7);
  33584. }
  33585. var dw = maxW / unitW;
  33586. var dh = maxH / unitH;
  33587. // 0/0 is NaN, 1/0 is Infinity.
  33588. isNaN(dw) && (dw = Infinity);
  33589. isNaN(dh) && (dh = Infinity);
  33590. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  33591. if (kind === AxisTickLabelComputingKind.estimate) {
  33592. // In estimate kind, the inteval likely varies, thus do not erase the cache.
  33593. ctx.out.noPxChangeTryDetermine.push(bind(calculateCategoryIntervalTryDetermine, null, axis, interval, tickCount));
  33594. return interval;
  33595. }
  33596. var lastInterval = calculateCategoryIntervalDealCache(axis, interval, tickCount);
  33597. return lastInterval != null ? lastInterval : interval;
  33598. }
  33599. function calculateCategoryIntervalTryDetermine(axis, interval, tickCount) {
  33600. return calculateCategoryIntervalDealCache(axis, interval, tickCount) == null;
  33601. }
  33602. // Return the lastInterval if need to use it, otherwise return NullUndefined and save cache.
  33603. function calculateCategoryIntervalDealCache(axis, interval, tickCount) {
  33604. var cache = modelInner(axis.model);
  33605. var axisExtent = axis.getExtent();
  33606. var lastAutoInterval = cache.lastAutoInterval;
  33607. var lastTickCount = cache.lastTickCount;
  33608. // Use cache to keep interval stable while moving zoom window,
  33609. // otherwise the calculated interval might jitter when the zoom
  33610. // window size is close to the interval-changing size.
  33611. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  33612. // The jitter will cause that sometimes the displayed labels are
  33613. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  33614. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1
  33615. // Always choose the bigger one, otherwise the critical
  33616. // point is not the same when zooming in or zooming out.
  33617. && lastAutoInterval > interval
  33618. // If the axis change is caused by chart resize, the cache should not
  33619. // be used. Otherwise some hidden labels might not be shown again.
  33620. && cache.axisExtent0 === axisExtent[0] && cache.axisExtent1 === axisExtent[1]) {
  33621. return lastAutoInterval;
  33622. }
  33623. // Only update cache if cache not used, otherwise the
  33624. // changing of interval is too insensitive.
  33625. else {
  33626. cache.lastTickCount = tickCount;
  33627. cache.lastAutoInterval = interval;
  33628. cache.axisExtent0 = axisExtent[0];
  33629. cache.axisExtent1 = axisExtent[1];
  33630. }
  33631. }
  33632. function fetchAutoCategoryIntervalCalculationParams(axis) {
  33633. var labelModel = axis.getLabelModel();
  33634. return {
  33635. axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
  33636. labelRotate: labelModel.get('rotate') || 0,
  33637. font: labelModel.getFont()
  33638. };
  33639. }
  33640. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  33641. var labelFormatter = makeLabelFormatter(axis);
  33642. var ordinalScale = axis.scale;
  33643. var ordinalExtent = ordinalScale.getExtent();
  33644. var labelModel = axis.getLabelModel();
  33645. var result = [];
  33646. // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  33647. var step = Math.max((categoryInterval || 0) + 1, 1);
  33648. var startTick = ordinalExtent[0];
  33649. var tickCount = ordinalScale.count();
  33650. // Calculate start tick based on zero if possible to keep label consistent
  33651. // while zooming and moving while interval > 0. Otherwise the selection
  33652. // of displayable ticks and symbols probably keep changing.
  33653. // 3 is empirical value.
  33654. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  33655. startTick = Math.round(Math.ceil(startTick / step) * step);
  33656. }
  33657. // (1) Only add min max label here but leave overlap checking
  33658. // to render stage, which also ensure the returned list
  33659. // suitable for splitLine and splitArea rendering.
  33660. // (2) Scales except category always contain min max label so
  33661. // do not need to perform this process.
  33662. var showAllLabel = shouldShowAllLabels(axis);
  33663. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  33664. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  33665. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  33666. addItem(ordinalExtent[0]);
  33667. }
  33668. // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  33669. var tickValue = startTick;
  33670. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  33671. addItem(tickValue);
  33672. }
  33673. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  33674. addItem(ordinalExtent[1]);
  33675. }
  33676. function addItem(tickValue) {
  33677. var tickObj = {
  33678. value: tickValue
  33679. };
  33680. result.push(onlyTick ? tickValue : {
  33681. formattedLabel: labelFormatter(tickObj),
  33682. rawLabel: ordinalScale.getLabel(tickObj),
  33683. tickValue: tickValue,
  33684. time: undefined,
  33685. "break": undefined
  33686. });
  33687. }
  33688. return result;
  33689. }
  33690. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  33691. var ordinalScale = axis.scale;
  33692. var labelFormatter = makeLabelFormatter(axis);
  33693. var result = [];
  33694. each(ordinalScale.getTicks(), function (tick) {
  33695. var rawLabel = ordinalScale.getLabel(tick);
  33696. var tickValue = tick.value;
  33697. if (categoryInterval(tick.value, rawLabel)) {
  33698. result.push(onlyTick ? tickValue : {
  33699. formattedLabel: labelFormatter(tick),
  33700. rawLabel: rawLabel,
  33701. tickValue: tickValue,
  33702. time: undefined,
  33703. "break": undefined
  33704. });
  33705. }
  33706. });
  33707. return result;
  33708. }
  33709. var NORMALIZED_EXTENT = [0, 1];
  33710. /**
  33711. * Base class of Axis.
  33712. *
  33713. * Lifetime: recreate for each main process.
  33714. * [NOTICE]: Some caches is stored on the axis instance (see `axisTickLabelBuilder.ts`)
  33715. * which is based on this lifetime.
  33716. */
  33717. var Axis = /** @class */function () {
  33718. function Axis(dim, scale, extent) {
  33719. this.onBand = false;
  33720. // Make sure that `extent[0] > extent[1]` only if `inverse: true`.
  33721. // `inverse` can be inferred by `extent` unless `extent[0] === extent[1]`.
  33722. this.inverse = false;
  33723. this.dim = dim;
  33724. this.scale = scale;
  33725. this._extent = extent || [0, 0];
  33726. }
  33727. /**
  33728. * If axis extent contain given coord
  33729. */
  33730. Axis.prototype.contain = function (coord) {
  33731. var extent = this._extent;
  33732. var min = Math.min(extent[0], extent[1]);
  33733. var max = Math.max(extent[0], extent[1]);
  33734. return coord >= min && coord <= max;
  33735. };
  33736. /**
  33737. * If axis extent contain given data
  33738. */
  33739. Axis.prototype.containData = function (data) {
  33740. return this.scale.contain(this.scale.parse(data));
  33741. };
  33742. /**
  33743. * Get coord extent.
  33744. */
  33745. Axis.prototype.getExtent = function () {
  33746. return this._extent.slice();
  33747. };
  33748. /**
  33749. * Get precision used for formatting
  33750. */
  33751. Axis.prototype.getPixelPrecision = function (dataExtent) {
  33752. return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
  33753. };
  33754. /**
  33755. * Set coord extent
  33756. */
  33757. Axis.prototype.setExtent = function (start, end) {
  33758. var extent = this._extent;
  33759. extent[0] = start;
  33760. extent[1] = end;
  33761. };
  33762. /**
  33763. * Convert data to coord. Data is the rank if it has an ordinal scale
  33764. */
  33765. Axis.prototype.dataToCoord = function (data, clamp) {
  33766. var extent = this._extent;
  33767. var scale = this.scale;
  33768. data = scale.normalize(scale.parse(data));
  33769. if (this.onBand && scale.type === 'ordinal') {
  33770. extent = extent.slice();
  33771. fixExtentWithBands(extent, scale.count());
  33772. }
  33773. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  33774. };
  33775. /**
  33776. * Convert coord to data. Data is the rank if it has an ordinal scale
  33777. */
  33778. Axis.prototype.coordToData = function (coord, clamp) {
  33779. var extent = this._extent;
  33780. var scale = this.scale;
  33781. if (this.onBand && scale.type === 'ordinal') {
  33782. extent = extent.slice();
  33783. fixExtentWithBands(extent, scale.count());
  33784. }
  33785. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  33786. return this.scale.scale(t);
  33787. };
  33788. /**
  33789. * Convert pixel point to data in axis
  33790. */
  33791. Axis.prototype.pointToData = function (point, clamp) {
  33792. // Should be implemented in derived class if necessary.
  33793. return;
  33794. };
  33795. /**
  33796. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  33797. * `axis.getTicksCoords` considers `onBand`, which is used by
  33798. * `boundaryGap:true` of category axis and splitLine and splitArea.
  33799. * @param opt.tickModel default: axis.model.getModel('axisTick')
  33800. * @param opt.clamp If `true`, the first and the last
  33801. * tick must be at the axis end points. Otherwise, clip ticks
  33802. * that outside the axis extent.
  33803. */
  33804. Axis.prototype.getTicksCoords = function (opt) {
  33805. opt = opt || {};
  33806. var tickModel = opt.tickModel || this.getTickModel();
  33807. var result = createAxisTicks(this, tickModel, {
  33808. breakTicks: opt.breakTicks,
  33809. pruneByBreak: opt.pruneByBreak
  33810. });
  33811. var ticks = result.ticks;
  33812. var ticksCoords = map(ticks, function (tickVal) {
  33813. return {
  33814. coord: this.dataToCoord(this.scale.type === 'ordinal' ? this.scale.getRawOrdinalNumber(tickVal) : tickVal),
  33815. tickValue: tickVal
  33816. };
  33817. }, this);
  33818. var alignWithLabel = tickModel.get('alignWithLabel');
  33819. fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
  33820. return ticksCoords;
  33821. };
  33822. Axis.prototype.getMinorTicksCoords = function () {
  33823. if (this.scale.type === 'ordinal') {
  33824. // Category axis doesn't support minor ticks
  33825. return [];
  33826. }
  33827. var minorTickModel = this.model.getModel('minorTick');
  33828. var splitNumber = minorTickModel.get('splitNumber');
  33829. // Protection.
  33830. if (!(splitNumber > 0 && splitNumber < 100)) {
  33831. splitNumber = 5;
  33832. }
  33833. var minorTicks = this.scale.getMinorTicks(splitNumber);
  33834. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  33835. return map(minorTicksGroup, function (minorTick) {
  33836. return {
  33837. coord: this.dataToCoord(minorTick),
  33838. tickValue: minorTick
  33839. };
  33840. }, this);
  33841. }, this);
  33842. return minorTicksCoords;
  33843. };
  33844. Axis.prototype.getViewLabels = function (ctx) {
  33845. ctx = ctx || createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine);
  33846. return createAxisLabels(this, ctx).labels;
  33847. };
  33848. Axis.prototype.getLabelModel = function () {
  33849. return this.model.getModel('axisLabel');
  33850. };
  33851. /**
  33852. * Notice here we only get the default tick model. For splitLine
  33853. * or splitArea, we should pass the splitLineModel or splitAreaModel
  33854. * manually when calling `getTicksCoords`.
  33855. * In GL, this method may be overridden to:
  33856. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  33857. */
  33858. Axis.prototype.getTickModel = function () {
  33859. return this.model.getModel('axisTick');
  33860. };
  33861. /**
  33862. * Get width of band
  33863. */
  33864. Axis.prototype.getBandWidth = function () {
  33865. var axisExtent = this._extent;
  33866. var dataExtent = this.scale.getExtent();
  33867. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  33868. // Fix #2728, avoid NaN when only one data.
  33869. len === 0 && (len = 1);
  33870. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  33871. return Math.abs(size) / len;
  33872. };
  33873. /**
  33874. * Only be called in category axis.
  33875. * Can be overridden, consider other axes like in 3D.
  33876. * @return Auto interval for cateogry axis tick and label
  33877. */
  33878. Axis.prototype.calculateCategoryInterval = function (ctx) {
  33879. ctx = ctx || createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine);
  33880. return calculateCategoryInterval(this, ctx);
  33881. };
  33882. return Axis;
  33883. }();
  33884. function fixExtentWithBands(extent, nTick) {
  33885. var size = extent[1] - extent[0];
  33886. var len = nTick;
  33887. var margin = size / len / 2;
  33888. extent[0] += margin;
  33889. extent[1] -= margin;
  33890. }
  33891. // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  33892. // |---1---|---2---|---3---|---4---|.
  33893. // So the displayed ticks and splitLine/splitArea should between
  33894. // each data item, otherwise cause misleading (e.g., split tow bars
  33895. // of a single data item when there are two bar series).
  33896. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  33897. // splitLine/spliteArea should layout appropriately corresponding
  33898. // to displayed labels. (So we should not use `getBandWidth` in this
  33899. // case).
  33900. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  33901. var ticksLen = ticksCoords.length;
  33902. if (!axis.onBand || alignWithLabel || !ticksLen) {
  33903. return;
  33904. }
  33905. var axisExtent = axis.getExtent();
  33906. var last;
  33907. var diffSize;
  33908. if (ticksLen === 1) {
  33909. ticksCoords[0].coord = axisExtent[0];
  33910. ticksCoords[0].onBand = true;
  33911. last = ticksCoords[1] = {
  33912. coord: axisExtent[1],
  33913. tickValue: ticksCoords[0].tickValue,
  33914. onBand: true
  33915. };
  33916. } else {
  33917. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  33918. var shift_1 = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  33919. each(ticksCoords, function (ticksItem) {
  33920. ticksItem.coord -= shift_1 / 2;
  33921. ticksItem.onBand = true;
  33922. });
  33923. var dataExtent = axis.scale.getExtent();
  33924. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  33925. last = {
  33926. coord: ticksCoords[ticksLen - 1].coord + shift_1 * diffSize,
  33927. tickValue: dataExtent[1] + 1,
  33928. onBand: true
  33929. };
  33930. ticksCoords.push(last);
  33931. }
  33932. var inverse = axisExtent[0] > axisExtent[1];
  33933. // Handling clamp.
  33934. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  33935. clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
  33936. }
  33937. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  33938. ticksCoords.unshift({
  33939. coord: axisExtent[0],
  33940. onBand: true
  33941. });
  33942. }
  33943. if (littleThan(axisExtent[1], last.coord)) {
  33944. clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
  33945. }
  33946. if (clamp && littleThan(last.coord, axisExtent[1])) {
  33947. ticksCoords.push({
  33948. coord: axisExtent[1],
  33949. onBand: true
  33950. });
  33951. }
  33952. function littleThan(a, b) {
  33953. // Avoid rounding error cause calculated tick coord different with extent.
  33954. // It may cause an extra unnecessary tick added.
  33955. a = round(a);
  33956. b = round(b);
  33957. return inverse ? a > b : a < b;
  33958. }
  33959. }
  33960. // --------------------- Deprecated Extension Methods ---------------------
  33961. // Should use `ComponentModel.extend` or `class XXXX extend ComponentModel` to create class.
  33962. // Then use `registerComponentModel` in `install` parameter when `use` this extension. For example:
  33963. // class Bar3DModel extends ComponentModel {}
  33964. // export function install(registers) { registers.registerComponentModel(Bar3DModel); }
  33965. // echarts.use(install);
  33966. function extendComponentModel(proto) {
  33967. var Model = ComponentModel.extend(proto);
  33968. ComponentModel.registerClass(Model);
  33969. return Model;
  33970. }
  33971. function extendComponentView(proto) {
  33972. var View = ComponentView.extend(proto);
  33973. ComponentView.registerClass(View);
  33974. return View;
  33975. }
  33976. function extendSeriesModel(proto) {
  33977. var Model = SeriesModel.extend(proto);
  33978. SeriesModel.registerClass(Model);
  33979. return Model;
  33980. }
  33981. function extendChartView(proto) {
  33982. var View = ChartView.extend(proto);
  33983. ChartView.registerClass(View);
  33984. return View;
  33985. }
  33986. function projectPointToLine(x1, y1, x2, y2, x, y, out, limitToEnds) {
  33987. var dx = x - x1;
  33988. var dy = y - y1;
  33989. var dx1 = x2 - x1;
  33990. var dy1 = y2 - y1;
  33991. var lineLen = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  33992. dx1 /= lineLen;
  33993. dy1 /= lineLen;
  33994. // dot product
  33995. var projectedLen = dx * dx1 + dy * dy1;
  33996. var t = projectedLen / lineLen;
  33997. if (limitToEnds) {
  33998. t = Math.min(Math.max(t, 0), 1);
  33999. }
  34000. t *= lineLen;
  34001. var ox = out[0] = x1 + t * dx1;
  34002. var oy = out[1] = y1 + t * dy1;
  34003. return Math.sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
  34004. }
  34005. // Temporal variable for intermediate usage.
  34006. var pt0 = new Point();
  34007. var pt1 = new Point();
  34008. var pt2 = new Point();
  34009. var dir = new Point();
  34010. var dir2 = new Point();
  34011. // Temporal variable for the limitTurnAngle function
  34012. var tmpArr = [];
  34013. var tmpProjPoint = new Point();
  34014. /**
  34015. * Reduce the line segment attached to the label to limit the turn angle between two segments.
  34016. * @param linePoints
  34017. * @param minTurnAngle Radian of minimum turn angle. 0 - 180
  34018. */
  34019. function limitTurnAngle(linePoints, minTurnAngle) {
  34020. if (!(minTurnAngle <= 180 && minTurnAngle > 0)) {
  34021. return;
  34022. }
  34023. minTurnAngle = minTurnAngle / 180 * Math.PI;
  34024. // The line points can be
  34025. // /pt1----pt2 (label)
  34026. // /
  34027. // pt0/
  34028. pt0.fromArray(linePoints[0]);
  34029. pt1.fromArray(linePoints[1]);
  34030. pt2.fromArray(linePoints[2]);
  34031. Point.sub(dir, pt0, pt1);
  34032. Point.sub(dir2, pt2, pt1);
  34033. var len1 = dir.len();
  34034. var len2 = dir2.len();
  34035. if (len1 < 1e-3 || len2 < 1e-3) {
  34036. return;
  34037. }
  34038. dir.scale(1 / len1);
  34039. dir2.scale(1 / len2);
  34040. var angleCos = dir.dot(dir2);
  34041. var minTurnAngleCos = Math.cos(minTurnAngle);
  34042. if (minTurnAngleCos < angleCos) {
  34043. // Smaller than minTurnAngle
  34044. // Calculate project point of pt0 on pt1-pt2
  34045. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  34046. tmpProjPoint.fromArray(tmpArr);
  34047. // Calculate new projected length with limited minTurnAngle and get the new connect point
  34048. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI - minTurnAngle));
  34049. // Limit the new calculated connect point between pt1 and pt2.
  34050. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  34051. if (isNaN(t)) {
  34052. return;
  34053. }
  34054. if (t < 0) {
  34055. Point.copy(tmpProjPoint, pt1);
  34056. } else if (t > 1) {
  34057. Point.copy(tmpProjPoint, pt2);
  34058. }
  34059. tmpProjPoint.toArray(linePoints[1]);
  34060. }
  34061. }
  34062. /**
  34063. * Limit the angle of line and the surface
  34064. * @param maxSurfaceAngle Radian of minimum turn angle. 0 - 180. 0 is same direction to normal. 180 is opposite
  34065. */
  34066. function limitSurfaceAngle(linePoints, surfaceNormal, maxSurfaceAngle) {
  34067. if (!(maxSurfaceAngle <= 180 && maxSurfaceAngle > 0)) {
  34068. return;
  34069. }
  34070. maxSurfaceAngle = maxSurfaceAngle / 180 * Math.PI;
  34071. pt0.fromArray(linePoints[0]);
  34072. pt1.fromArray(linePoints[1]);
  34073. pt2.fromArray(linePoints[2]);
  34074. Point.sub(dir, pt1, pt0);
  34075. Point.sub(dir2, pt2, pt1);
  34076. var len1 = dir.len();
  34077. var len2 = dir2.len();
  34078. if (len1 < 1e-3 || len2 < 1e-3) {
  34079. return;
  34080. }
  34081. dir.scale(1 / len1);
  34082. dir2.scale(1 / len2);
  34083. var angleCos = dir.dot(surfaceNormal);
  34084. var maxSurfaceAngleCos = Math.cos(maxSurfaceAngle);
  34085. if (angleCos < maxSurfaceAngleCos) {
  34086. // Calculate project point of pt0 on pt1-pt2
  34087. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  34088. tmpProjPoint.fromArray(tmpArr);
  34089. var HALF_PI = Math.PI / 2;
  34090. var angle2 = Math.acos(dir2.dot(surfaceNormal));
  34091. var newAngle = HALF_PI + angle2 - maxSurfaceAngle;
  34092. if (newAngle >= HALF_PI) {
  34093. // parallel
  34094. Point.copy(tmpProjPoint, pt2);
  34095. } else {
  34096. // Calculate new projected length with limited minTurnAngle and get the new connect point
  34097. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI / 2 - newAngle));
  34098. // Limit the new calculated connect point between pt1 and pt2.
  34099. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  34100. if (isNaN(t)) {
  34101. return;
  34102. }
  34103. if (t < 0) {
  34104. Point.copy(tmpProjPoint, pt1);
  34105. } else if (t > 1) {
  34106. Point.copy(tmpProjPoint, pt2);
  34107. }
  34108. }
  34109. tmpProjPoint.toArray(linePoints[1]);
  34110. }
  34111. }
  34112. function setLabelLineState(labelLine, ignore, stateName, stateModel) {
  34113. var isNormal = stateName === 'normal';
  34114. var stateObj = isNormal ? labelLine : labelLine.ensureState(stateName);
  34115. // Make sure display.
  34116. stateObj.ignore = ignore;
  34117. // Set smooth
  34118. var smooth = stateModel.get('smooth');
  34119. if (smooth && smooth === true) {
  34120. smooth = 0.3;
  34121. }
  34122. stateObj.shape = stateObj.shape || {};
  34123. if (smooth > 0) {
  34124. stateObj.shape.smooth = smooth;
  34125. }
  34126. var styleObj = stateModel.getModel('lineStyle').getLineStyle();
  34127. isNormal ? labelLine.useStyle(styleObj) : stateObj.style = styleObj;
  34128. }
  34129. function buildLabelLinePath(path, shape) {
  34130. var smooth = shape.smooth;
  34131. var points = shape.points;
  34132. if (!points) {
  34133. return;
  34134. }
  34135. path.moveTo(points[0][0], points[0][1]);
  34136. if (smooth > 0 && points.length >= 3) {
  34137. var len1 = dist(points[0], points[1]);
  34138. var len2 = dist(points[1], points[2]);
  34139. if (!len1 || !len2) {
  34140. path.lineTo(points[1][0], points[1][1]);
  34141. path.lineTo(points[2][0], points[2][1]);
  34142. return;
  34143. }
  34144. var moveLen = Math.min(len1, len2) * smooth;
  34145. var midPoint0 = lerp([], points[1], points[0], moveLen / len1);
  34146. var midPoint2 = lerp([], points[1], points[2], moveLen / len2);
  34147. var midPoint1 = lerp([], midPoint0, midPoint2, 0.5);
  34148. path.bezierCurveTo(midPoint0[0], midPoint0[1], midPoint0[0], midPoint0[1], midPoint1[0], midPoint1[1]);
  34149. path.bezierCurveTo(midPoint2[0], midPoint2[1], midPoint2[0], midPoint2[1], points[2][0], points[2][1]);
  34150. } else {
  34151. for (var i = 1; i < points.length; i++) {
  34152. path.lineTo(points[i][0], points[i][1]);
  34153. }
  34154. }
  34155. }
  34156. /**
  34157. * Create a label line if necessary and set it's style.
  34158. */
  34159. function setLabelLineStyle(targetEl, statesModels, defaultStyle) {
  34160. var labelLine = targetEl.getTextGuideLine();
  34161. var label = targetEl.getTextContent();
  34162. if (!label) {
  34163. // Not show label line if there is no label.
  34164. if (labelLine) {
  34165. targetEl.removeTextGuideLine();
  34166. }
  34167. return;
  34168. }
  34169. var normalModel = statesModels.normal;
  34170. var showNormal = normalModel.get('show');
  34171. var labelIgnoreNormal = label.ignore;
  34172. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  34173. var stateName = DISPLAY_STATES[i];
  34174. var stateModel = statesModels[stateName];
  34175. var isNormal = stateName === 'normal';
  34176. if (stateModel) {
  34177. var stateShow = stateModel.get('show');
  34178. var isLabelIgnored = isNormal ? labelIgnoreNormal : retrieve2(label.states[stateName] && label.states[stateName].ignore, labelIgnoreNormal);
  34179. if (isLabelIgnored // Not show when label is not shown in this state.
  34180. || !retrieve2(stateShow, showNormal) // Use normal state by default if not set.
  34181. ) {
  34182. var stateObj = isNormal ? labelLine : labelLine && labelLine.states[stateName];
  34183. if (stateObj) {
  34184. stateObj.ignore = true;
  34185. }
  34186. if (!!labelLine) {
  34187. setLabelLineState(labelLine, true, stateName, stateModel);
  34188. }
  34189. continue;
  34190. }
  34191. // Create labelLine if not exists
  34192. if (!labelLine) {
  34193. labelLine = new Polyline();
  34194. targetEl.setTextGuideLine(labelLine);
  34195. // Reset state of normal because it's new created.
  34196. // NOTE: NORMAL should always been the first!
  34197. if (!isNormal && (labelIgnoreNormal || !showNormal)) {
  34198. setLabelLineState(labelLine, true, 'normal', statesModels.normal);
  34199. }
  34200. // Use same state proxy.
  34201. if (targetEl.stateProxy) {
  34202. labelLine.stateProxy = targetEl.stateProxy;
  34203. }
  34204. }
  34205. setLabelLineState(labelLine, false, stateName, stateModel);
  34206. }
  34207. }
  34208. if (labelLine) {
  34209. defaults(labelLine.style, defaultStyle);
  34210. // Not fill.
  34211. labelLine.style.fill = null;
  34212. var showAbove = normalModel.get('showAbove');
  34213. var labelLineConfig = targetEl.textGuideLineConfig = targetEl.textGuideLineConfig || {};
  34214. labelLineConfig.showAbove = showAbove || false;
  34215. // Custom the buildPath.
  34216. labelLine.buildPath = buildLabelLinePath;
  34217. }
  34218. }
  34219. function getLabelLineStatesModels(itemModel, labelLineName) {
  34220. labelLineName = labelLineName || 'labelLine';
  34221. var statesModels = {
  34222. normal: itemModel.getModel(labelLineName)
  34223. };
  34224. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  34225. var stateName = SPECIAL_STATES[i];
  34226. statesModels[stateName] = itemModel.getModel([stateName, labelLineName]);
  34227. }
  34228. return statesModels;
  34229. }
  34230. var LABEL_LAYOUT_BASE_PROPS = ['label', 'labelLine', 'layoutOption', 'priority', 'defaultAttr', 'marginForce', 'minMarginForce', 'marginDefault', 'suggestIgnore'];
  34231. var LABEL_LAYOUT_DIRTY_BIT_OTHERS = 1;
  34232. var LABEL_LAYOUT_DIRTY_BIT_OBB = 2;
  34233. var LABEL_LAYOUT_DIRTY_ALL = LABEL_LAYOUT_DIRTY_BIT_OTHERS | LABEL_LAYOUT_DIRTY_BIT_OBB;
  34234. function setLabelLayoutDirty(labelGeometry, dirtyOrClear, dirtyBits) {
  34235. dirtyBits = dirtyBits || LABEL_LAYOUT_DIRTY_ALL;
  34236. dirtyOrClear ? labelGeometry.dirty |= dirtyBits : labelGeometry.dirty &= ~dirtyBits;
  34237. }
  34238. function isLabelLayoutDirty(labelGeometry, dirtyBits) {
  34239. dirtyBits = dirtyBits || LABEL_LAYOUT_DIRTY_ALL;
  34240. return labelGeometry.dirty == null || !!(labelGeometry.dirty & dirtyBits);
  34241. }
  34242. /**
  34243. * [CAUTION]
  34244. * - No auto dirty propagation mechanism yet. If the transform of the raw label or any of its ancestors is
  34245. * changed, must sync the changes to the props of `LabelGeometry` by:
  34246. * either explicitly call:
  34247. * `setLabelLayoutDirty(labelLayout, true); ensureLabelLayoutWithGeometry(labelLayout);`
  34248. * or call (if only translation is performed):
  34249. * `labelLayoutApplyTranslation(labelLayout);`
  34250. * - `label.ignore` is not necessarily falsy, and not considered in computing `LabelGeometry`,
  34251. * since it might be modified by some overlap resolving handling.
  34252. * - To duplicate or make a variation:
  34253. * use `newLabelLayoutWithGeometry`.
  34254. *
  34255. * The result can also be the input of this method.
  34256. * @return `NullUndefined` if and only if `labelLayout` is `NullUndefined`.
  34257. */
  34258. function ensureLabelLayoutWithGeometry(labelLayout) {
  34259. if (!labelLayout) {
  34260. return;
  34261. }
  34262. if (isLabelLayoutDirty(labelLayout)) {
  34263. computeLabelGeometry(labelLayout, labelLayout.label, labelLayout);
  34264. }
  34265. return labelLayout;
  34266. }
  34267. /**
  34268. * The props in `out` will be filled if existing, or created.
  34269. */
  34270. function computeLabelGeometry(out, label, opt) {
  34271. // [CAUTION] These props may be modified directly for performance consideration,
  34272. // therefore, do not output the internal data structure of zrender Element.
  34273. var rawTransform = label.getComputedTransform();
  34274. out.transform = ensureCopyTransform(out.transform, rawTransform);
  34275. // NOTE: should call `getBoundingRect` after `getComputedTransform`, or may get an inaccurate bounding rect.
  34276. // The reason is that `getComputedTransform` calls `__host.updateInnerText()` internally, which updates the label
  34277. // by `textConfig` mounted on the host.
  34278. // PENDING: add a dirty bit for that in zrender?
  34279. var outLocalRect = out.localRect = ensureCopyRect(out.localRect, label.getBoundingRect());
  34280. var labelStyleExt = label.style;
  34281. var margin = labelStyleExt.margin;
  34282. var marginForce = opt && opt.marginForce;
  34283. var minMarginForce = opt && opt.minMarginForce;
  34284. var marginDefault = opt && opt.marginDefault;
  34285. var marginType = labelStyleExt.__marginType;
  34286. if (marginType == null && marginDefault) {
  34287. margin = marginDefault;
  34288. marginType = LabelMarginType.textMargin;
  34289. }
  34290. // `textMargin` and `minMargin` can not exist both.
  34291. for (var i = 0; i < 4; i++) {
  34292. _tmpLabelMargin[i] = marginType === LabelMarginType.minMargin && minMarginForce && minMarginForce[i] != null ? minMarginForce[i] : marginForce && marginForce[i] != null ? marginForce[i] : margin ? margin[i] : 0;
  34293. }
  34294. if (marginType === LabelMarginType.textMargin) {
  34295. expandOrShrinkRect(outLocalRect, _tmpLabelMargin, false, false);
  34296. }
  34297. var outGlobalRect = out.rect = ensureCopyRect(out.rect, outLocalRect);
  34298. if (rawTransform) {
  34299. outGlobalRect.applyTransform(rawTransform);
  34300. }
  34301. // Notice: label.style.margin is actually `minMargin / 2`, handled by `setTextStyleCommon`.
  34302. if (marginType === LabelMarginType.minMargin) {
  34303. expandOrShrinkRect(outGlobalRect, _tmpLabelMargin, false, false);
  34304. }
  34305. out.axisAligned = isBoundingRectAxisAligned(rawTransform);
  34306. (out.label = out.label || {}).ignore = label.ignore;
  34307. setLabelLayoutDirty(out, false);
  34308. setLabelLayoutDirty(out, true, LABEL_LAYOUT_DIRTY_BIT_OBB);
  34309. // Do not remove `obb` (if existing) for reuse, just reset the dirty bit.
  34310. return out;
  34311. }
  34312. var _tmpLabelMargin = [0, 0, 0, 0];
  34313. /**
  34314. * The props in `out` will be filled if existing, or created.
  34315. */
  34316. function computeLabelGeometry2(out, rawLocalRect, rawTransform) {
  34317. out.transform = ensureCopyTransform(out.transform, rawTransform);
  34318. out.localRect = ensureCopyRect(out.localRect, rawLocalRect);
  34319. out.rect = ensureCopyRect(out.rect, rawLocalRect);
  34320. if (rawTransform) {
  34321. out.rect.applyTransform(rawTransform);
  34322. }
  34323. out.axisAligned = isBoundingRectAxisAligned(rawTransform);
  34324. out.obb = undefined; // Reset to undefined, will be created by `ensureOBB` when using.
  34325. (out.label = out.label || {}).ignore = false;
  34326. return out;
  34327. }
  34328. /**
  34329. * This is a shortcut of
  34330. * ```js
  34331. * labelLayout.label.x = newX;
  34332. * labelLayout.label.y = newY;
  34333. * setLabelLayoutDirty(labelLayout, true);
  34334. * ensureLabelLayoutWithGeometry(labelLayout);
  34335. * ```
  34336. * and provide better performance in this common case.
  34337. */
  34338. function labelLayoutApplyTranslation(labelLayout, offset) {
  34339. if (!labelLayout) {
  34340. return;
  34341. }
  34342. labelLayout.label.x += offset.x;
  34343. labelLayout.label.y += offset.y;
  34344. labelLayout.label.markRedraw();
  34345. var transform = labelLayout.transform;
  34346. if (transform) {
  34347. transform[4] += offset.x;
  34348. transform[5] += offset.y;
  34349. }
  34350. var globalRect = labelLayout.rect;
  34351. if (globalRect) {
  34352. globalRect.x += offset.x;
  34353. globalRect.y += offset.y;
  34354. }
  34355. var obb = labelLayout.obb;
  34356. if (obb) {
  34357. obb.fromBoundingRect(labelLayout.localRect, transform);
  34358. }
  34359. }
  34360. /**
  34361. * To duplicate or make a variation of a label layout.
  34362. * Copy the only relevant properties to avoid the conflict or wrongly reuse of the props of `LabelLayoutWithGeometry`.
  34363. */
  34364. function newLabelLayoutWithGeometry(newBaseWithDefaults, source) {
  34365. for (var i = 0; i < LABEL_LAYOUT_BASE_PROPS.length; i++) {
  34366. var prop = LABEL_LAYOUT_BASE_PROPS[i];
  34367. if (newBaseWithDefaults[prop] == null) {
  34368. newBaseWithDefaults[prop] = source[prop];
  34369. }
  34370. }
  34371. return ensureLabelLayoutWithGeometry(newBaseWithDefaults);
  34372. }
  34373. /**
  34374. * Create obb if no one, can cache it.
  34375. */
  34376. function ensureOBB(labelGeometry) {
  34377. var obb = labelGeometry.obb;
  34378. if (!obb || isLabelLayoutDirty(labelGeometry, LABEL_LAYOUT_DIRTY_BIT_OBB)) {
  34379. labelGeometry.obb = obb = obb || new OrientedBoundingRect();
  34380. obb.fromBoundingRect(labelGeometry.localRect, labelGeometry.transform);
  34381. setLabelLayoutDirty(labelGeometry, false, LABEL_LAYOUT_DIRTY_BIT_OBB);
  34382. }
  34383. return obb;
  34384. }
  34385. /**
  34386. * Adjust labels on x/y direction to avoid overlap.
  34387. *
  34388. * PENDING: the current implementation is based on the global bounding rect rather than the local rect,
  34389. * which may be not preferable in some edge cases when the label has rotation, but works for most cases,
  34390. * since rotation is unnecessary when there is sufficient space, while squeezing is applied regardless
  34391. * of overlapping when there is no enough space.
  34392. *
  34393. * NOTICE:
  34394. * - The input `list` and its content will be modified (sort, label.x/y, rect).
  34395. * - The caller should sync the modifications to the other parts by
  34396. * `setLabelLayoutDirty` and `ensureLabelLayoutWithGeometry` if needed.
  34397. *
  34398. * @return adjusted
  34399. */
  34400. function shiftLayoutOnXY(list, xyDimIdx,
  34401. // 0 for x, 1 for y
  34402. minBound,
  34403. // for x, leftBound; for y, topBound
  34404. maxBound,
  34405. // for x, rightBound; for y, bottomBound
  34406. // If average the shifts on all labels and add them to 0
  34407. // TODO: Not sure if should enable it.
  34408. // Pros: The angle of lines will distribute more equally
  34409. // Cons: In some layout. It may not what user wanted. like in pie. the label of last sector is usually changed unexpectedly.
  34410. balanceShift) {
  34411. var len = list.length;
  34412. var xyDim = XY$1[xyDimIdx];
  34413. var sizeDim = WH$1[xyDimIdx];
  34414. if (len < 2) {
  34415. return false;
  34416. }
  34417. list.sort(function (a, b) {
  34418. return a.rect[xyDim] - b.rect[xyDim];
  34419. });
  34420. var lastPos = 0;
  34421. var delta;
  34422. var adjusted = false;
  34423. // const shifts = [];
  34424. var totalShifts = 0;
  34425. for (var i = 0; i < len; i++) {
  34426. var item = list[i];
  34427. var rect = item.rect;
  34428. delta = rect[xyDim] - lastPos;
  34429. if (delta < 0) {
  34430. // shiftForward(i, len, -delta);
  34431. rect[xyDim] -= delta;
  34432. item.label[xyDim] -= delta;
  34433. adjusted = true;
  34434. }
  34435. var shift = Math.max(-delta, 0);
  34436. // shifts.push(shift);
  34437. totalShifts += shift;
  34438. lastPos = rect[xyDim] + rect[sizeDim];
  34439. }
  34440. if (totalShifts > 0 && balanceShift) {
  34441. // Shift back to make the distribution more equally.
  34442. shiftList(-totalShifts / len, 0, len);
  34443. }
  34444. // TODO bleedMargin?
  34445. var first = list[0];
  34446. var last = list[len - 1];
  34447. var minGap;
  34448. var maxGap;
  34449. updateMinMaxGap();
  34450. // If ends exceed two bounds, squeeze at most 80%, then take the gap of two bounds.
  34451. minGap < 0 && squeezeGaps(-minGap, 0.8);
  34452. maxGap < 0 && squeezeGaps(maxGap, 0.8);
  34453. updateMinMaxGap();
  34454. takeBoundsGap(minGap, maxGap, 1);
  34455. takeBoundsGap(maxGap, minGap, -1);
  34456. // Handle bailout when there is not enough space.
  34457. updateMinMaxGap();
  34458. if (minGap < 0) {
  34459. squeezeWhenBailout(-minGap);
  34460. }
  34461. if (maxGap < 0) {
  34462. squeezeWhenBailout(maxGap);
  34463. }
  34464. function updateMinMaxGap() {
  34465. minGap = first.rect[xyDim] - minBound;
  34466. maxGap = maxBound - last.rect[xyDim] - last.rect[sizeDim];
  34467. }
  34468. function takeBoundsGap(gapThisBound, gapOtherBound, moveDir) {
  34469. if (gapThisBound < 0) {
  34470. // Move from other gap if can.
  34471. var moveFromMaxGap = Math.min(gapOtherBound, -gapThisBound);
  34472. if (moveFromMaxGap > 0) {
  34473. shiftList(moveFromMaxGap * moveDir, 0, len);
  34474. var remained = moveFromMaxGap + gapThisBound;
  34475. if (remained < 0) {
  34476. squeezeGaps(-remained * moveDir, 1);
  34477. }
  34478. } else {
  34479. squeezeGaps(-gapThisBound * moveDir, 1);
  34480. }
  34481. }
  34482. }
  34483. function shiftList(delta, start, end) {
  34484. if (delta !== 0) {
  34485. adjusted = true;
  34486. }
  34487. for (var i = start; i < end; i++) {
  34488. var item = list[i];
  34489. var rect = item.rect;
  34490. rect[xyDim] += delta;
  34491. item.label[xyDim] += delta;
  34492. }
  34493. }
  34494. // Squeeze gaps if the labels exceed margin.
  34495. function squeezeGaps(delta, maxSqeezePercent) {
  34496. var gaps = [];
  34497. var totalGaps = 0;
  34498. for (var i = 1; i < len; i++) {
  34499. var prevItemRect = list[i - 1].rect;
  34500. var gap = Math.max(list[i].rect[xyDim] - prevItemRect[xyDim] - prevItemRect[sizeDim], 0);
  34501. gaps.push(gap);
  34502. totalGaps += gap;
  34503. }
  34504. if (!totalGaps) {
  34505. return;
  34506. }
  34507. var squeezePercent = Math.min(Math.abs(delta) / totalGaps, maxSqeezePercent);
  34508. if (delta > 0) {
  34509. for (var i = 0; i < len - 1; i++) {
  34510. // Distribute the shift delta to all gaps.
  34511. var movement = gaps[i] * squeezePercent;
  34512. // Forward
  34513. shiftList(movement, 0, i + 1);
  34514. }
  34515. } else {
  34516. // Backward
  34517. for (var i = len - 1; i > 0; i--) {
  34518. // Distribute the shift delta to all gaps.
  34519. var movement = gaps[i - 1] * squeezePercent;
  34520. shiftList(-movement, i, len);
  34521. }
  34522. }
  34523. }
  34524. /**
  34525. * Squeeze to allow overlap if there is no more space available.
  34526. * Let other overlapping strategy like hideOverlap do the job instead of keep exceeding the bounds.
  34527. */
  34528. function squeezeWhenBailout(delta) {
  34529. var dir = delta < 0 ? -1 : 1;
  34530. delta = Math.abs(delta);
  34531. var moveForEachLabel = Math.ceil(delta / (len - 1));
  34532. for (var i = 0; i < len - 1; i++) {
  34533. if (dir > 0) {
  34534. // Forward
  34535. shiftList(moveForEachLabel, 0, i + 1);
  34536. } else {
  34537. // Backward
  34538. shiftList(-moveForEachLabel, len - i - 1, len);
  34539. }
  34540. delta -= moveForEachLabel;
  34541. if (delta <= 0) {
  34542. return;
  34543. }
  34544. }
  34545. }
  34546. return adjusted;
  34547. }
  34548. /**
  34549. * [NOTICE - restore]:
  34550. * 'series:layoutlabels' may be triggered during some shortcut passes, such as zooming in series.graph/geo
  34551. * (`updateLabelLayout`), where the modified `Element` props should be restorable from `defaultAttr`.
  34552. * @see `SavedLabelAttr` in `LabelManager.ts`
  34553. * `restoreIgnore` can be called to perform the restore, if needed.
  34554. *
  34555. * [NOTICE - state]:
  34556. * Regarding Element's states, this method is only designed for the normal state.
  34557. * PENDING: although currently this method is effectively called in other states in `updateLabelLayout` case,
  34558. * the bad case is not noticeable in the zooming scenario.
  34559. */
  34560. function hideOverlap(labelList) {
  34561. var displayedLabels = [];
  34562. // TODO, render overflow visible first, put in the displayedLabels.
  34563. labelList.sort(function (a, b) {
  34564. return (b.suggestIgnore ? 1 : 0) - (a.suggestIgnore ? 1 : 0) || b.priority - a.priority;
  34565. });
  34566. function hideEl(el) {
  34567. if (!el.ignore) {
  34568. // Show on emphasis.
  34569. var emphasisState = el.ensureState('emphasis');
  34570. if (emphasisState.ignore == null) {
  34571. emphasisState.ignore = false;
  34572. }
  34573. }
  34574. el.ignore = true;
  34575. }
  34576. for (var i = 0; i < labelList.length; i++) {
  34577. var labelItem = ensureLabelLayoutWithGeometry(labelList[i]);
  34578. // The current `el.ignore` is involved, since some previous overlap
  34579. // resolving strategies may have set `el.ignore` to true.
  34580. if (labelItem.label.ignore) {
  34581. continue;
  34582. }
  34583. var label = labelItem.label;
  34584. var labelLine = labelItem.labelLine;
  34585. // NOTICE: even when the with/height of globalRect of a label is 0, the label line should
  34586. // still be displayed, since we should follow the concept of "truncation", meaning that
  34587. // something exists even if it cannot be fully displayed. A visible label line is necessary
  34588. // to allow users to get a tooltip with label info on hover.
  34589. var overlapped = false;
  34590. for (var j = 0; j < displayedLabels.length; j++) {
  34591. if (labelIntersect(labelItem, displayedLabels[j], null, {
  34592. touchThreshold: 0.05
  34593. })) {
  34594. overlapped = true;
  34595. break;
  34596. }
  34597. }
  34598. // TODO Callback to determine if this overlap should be handled?
  34599. if (overlapped) {
  34600. hideEl(label);
  34601. labelLine && hideEl(labelLine);
  34602. } else {
  34603. displayedLabels.push(labelItem);
  34604. }
  34605. }
  34606. }
  34607. /**
  34608. * Enable fast check for performance; use obb if inevitable.
  34609. * If `mtv` is used, `targetLayoutInfo` can be moved based on the values filled into `mtv`.
  34610. *
  34611. * This method is based only on the current `Element` states (regardless of other states).
  34612. * Typically this method (and the entire layout process) is performed in normal state.
  34613. */
  34614. function labelIntersect(baseLayoutInfo, targetLayoutInfo, mtv, intersectOpt) {
  34615. if (!baseLayoutInfo || !targetLayoutInfo) {
  34616. return false;
  34617. }
  34618. if (baseLayoutInfo.label && baseLayoutInfo.label.ignore || targetLayoutInfo.label && targetLayoutInfo.label.ignore) {
  34619. return false;
  34620. }
  34621. // Fast rejection.
  34622. if (!baseLayoutInfo.rect.intersect(targetLayoutInfo.rect, mtv, intersectOpt)) {
  34623. return false;
  34624. }
  34625. if (baseLayoutInfo.axisAligned && targetLayoutInfo.axisAligned) {
  34626. return true; // obb is the same as the normal bounding rect.
  34627. }
  34628. return ensureOBB(baseLayoutInfo).intersect(ensureOBB(targetLayoutInfo), mtv, intersectOpt);
  34629. }
  34630. function createDom(id, painter, dpr) {
  34631. var newDom = platformApi.createCanvas();
  34632. var width = painter.getWidth();
  34633. var height = painter.getHeight();
  34634. var newDomStyle = newDom.style;
  34635. if (newDomStyle) {
  34636. newDomStyle.position = 'absolute';
  34637. newDomStyle.left = '0';
  34638. newDomStyle.top = '0';
  34639. newDomStyle.width = width + 'px';
  34640. newDomStyle.height = height + 'px';
  34641. newDom.setAttribute('data-zr-dom-id', id);
  34642. }
  34643. newDom.width = width * dpr;
  34644. newDom.height = height * dpr;
  34645. return newDom;
  34646. }
  34647. var Layer = (function (_super) {
  34648. __extends(Layer, _super);
  34649. function Layer(id, painter, dpr) {
  34650. var _this = _super.call(this) || this;
  34651. _this.motionBlur = false;
  34652. _this.lastFrameAlpha = 0.7;
  34653. _this.dpr = 1;
  34654. _this.virtual = false;
  34655. _this.config = {};
  34656. _this.incremental = false;
  34657. _this.zlevel = 0;
  34658. _this.maxRepaintRectCount = 5;
  34659. _this.__dirty = true;
  34660. _this.__firstTimePaint = true;
  34661. _this.__used = false;
  34662. _this.__drawIndex = 0;
  34663. _this.__startIndex = 0;
  34664. _this.__endIndex = 0;
  34665. _this.__prevStartIndex = null;
  34666. _this.__prevEndIndex = null;
  34667. var dom;
  34668. dpr = dpr || devicePixelRatio;
  34669. if (typeof id === 'string') {
  34670. dom = createDom(id, painter, dpr);
  34671. }
  34672. else if (isObject(id)) {
  34673. dom = id;
  34674. id = dom.id;
  34675. }
  34676. _this.id = id;
  34677. _this.dom = dom;
  34678. var domStyle = dom.style;
  34679. if (domStyle) {
  34680. disableUserSelect(dom);
  34681. dom.onselectstart = function () { return false; };
  34682. domStyle.padding = '0';
  34683. domStyle.margin = '0';
  34684. domStyle.borderWidth = '0';
  34685. }
  34686. _this.painter = painter;
  34687. _this.dpr = dpr;
  34688. return _this;
  34689. }
  34690. Layer.prototype.getElementCount = function () {
  34691. return this.__endIndex - this.__startIndex;
  34692. };
  34693. Layer.prototype.afterBrush = function () {
  34694. this.__prevStartIndex = this.__startIndex;
  34695. this.__prevEndIndex = this.__endIndex;
  34696. };
  34697. Layer.prototype.initContext = function () {
  34698. this.ctx = this.dom.getContext('2d');
  34699. this.ctx.dpr = this.dpr;
  34700. };
  34701. Layer.prototype.setUnpainted = function () {
  34702. this.__firstTimePaint = true;
  34703. };
  34704. Layer.prototype.createBackBuffer = function () {
  34705. var dpr = this.dpr;
  34706. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  34707. this.ctxBack = this.domBack.getContext('2d');
  34708. if (dpr !== 1) {
  34709. this.ctxBack.scale(dpr, dpr);
  34710. }
  34711. };
  34712. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  34713. if (this.__firstTimePaint) {
  34714. this.__firstTimePaint = false;
  34715. return null;
  34716. }
  34717. var mergedRepaintRects = [];
  34718. var maxRepaintRectCount = this.maxRepaintRectCount;
  34719. var full = false;
  34720. var pendingRect = new BoundingRect(0, 0, 0, 0);
  34721. function addRectToMergePool(rect) {
  34722. if (!rect.isFinite() || rect.isZero()) {
  34723. return;
  34724. }
  34725. if (mergedRepaintRects.length === 0) {
  34726. var boundingRect = new BoundingRect(0, 0, 0, 0);
  34727. boundingRect.copy(rect);
  34728. mergedRepaintRects.push(boundingRect);
  34729. }
  34730. else {
  34731. var isMerged = false;
  34732. var minDeltaArea = Infinity;
  34733. var bestRectToMergeIdx = 0;
  34734. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  34735. var mergedRect = mergedRepaintRects[i];
  34736. if (mergedRect.intersect(rect)) {
  34737. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  34738. pendingRect_1.copy(mergedRect);
  34739. pendingRect_1.union(rect);
  34740. mergedRepaintRects[i] = pendingRect_1;
  34741. isMerged = true;
  34742. break;
  34743. }
  34744. else if (full) {
  34745. pendingRect.copy(rect);
  34746. pendingRect.union(mergedRect);
  34747. var aArea = rect.width * rect.height;
  34748. var bArea = mergedRect.width * mergedRect.height;
  34749. var pendingArea = pendingRect.width * pendingRect.height;
  34750. var deltaArea = pendingArea - aArea - bArea;
  34751. if (deltaArea < minDeltaArea) {
  34752. minDeltaArea = deltaArea;
  34753. bestRectToMergeIdx = i;
  34754. }
  34755. }
  34756. }
  34757. if (full) {
  34758. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  34759. isMerged = true;
  34760. }
  34761. if (!isMerged) {
  34762. var boundingRect = new BoundingRect(0, 0, 0, 0);
  34763. boundingRect.copy(rect);
  34764. mergedRepaintRects.push(boundingRect);
  34765. }
  34766. if (!full) {
  34767. full = mergedRepaintRects.length >= maxRepaintRectCount;
  34768. }
  34769. }
  34770. }
  34771. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  34772. var el = displayList[i];
  34773. if (el) {
  34774. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  34775. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  34776. ? el.getPrevPaintRect()
  34777. : null;
  34778. if (prevRect) {
  34779. addRectToMergePool(prevRect);
  34780. }
  34781. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  34782. ? el.getPaintRect()
  34783. : null;
  34784. if (curRect) {
  34785. addRectToMergePool(curRect);
  34786. }
  34787. }
  34788. }
  34789. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  34790. var el = prevList[i];
  34791. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  34792. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  34793. var prevRect = el.getPrevPaintRect();
  34794. if (prevRect) {
  34795. addRectToMergePool(prevRect);
  34796. }
  34797. }
  34798. }
  34799. var hasIntersections;
  34800. do {
  34801. hasIntersections = false;
  34802. for (var i = 0; i < mergedRepaintRects.length;) {
  34803. if (mergedRepaintRects[i].isZero()) {
  34804. mergedRepaintRects.splice(i, 1);
  34805. continue;
  34806. }
  34807. for (var j = i + 1; j < mergedRepaintRects.length;) {
  34808. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  34809. hasIntersections = true;
  34810. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  34811. mergedRepaintRects.splice(j, 1);
  34812. }
  34813. else {
  34814. j++;
  34815. }
  34816. }
  34817. i++;
  34818. }
  34819. } while (hasIntersections);
  34820. this._paintRects = mergedRepaintRects;
  34821. return mergedRepaintRects;
  34822. };
  34823. Layer.prototype.debugGetPaintRects = function () {
  34824. return (this._paintRects || []).slice();
  34825. };
  34826. Layer.prototype.resize = function (width, height) {
  34827. var dpr = this.dpr;
  34828. var dom = this.dom;
  34829. var domStyle = dom.style;
  34830. var domBack = this.domBack;
  34831. if (domStyle) {
  34832. domStyle.width = width + 'px';
  34833. domStyle.height = height + 'px';
  34834. }
  34835. dom.width = width * dpr;
  34836. dom.height = height * dpr;
  34837. if (domBack) {
  34838. domBack.width = width * dpr;
  34839. domBack.height = height * dpr;
  34840. if (dpr !== 1) {
  34841. this.ctxBack.scale(dpr, dpr);
  34842. }
  34843. }
  34844. };
  34845. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  34846. var dom = this.dom;
  34847. var ctx = this.ctx;
  34848. var width = dom.width;
  34849. var height = dom.height;
  34850. clearColor = clearColor || this.clearColor;
  34851. var haveMotionBLur = this.motionBlur && !clearAll;
  34852. var lastFrameAlpha = this.lastFrameAlpha;
  34853. var dpr = this.dpr;
  34854. var self = this;
  34855. if (haveMotionBLur) {
  34856. if (!this.domBack) {
  34857. this.createBackBuffer();
  34858. }
  34859. this.ctxBack.globalCompositeOperation = 'copy';
  34860. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  34861. }
  34862. var domBack = this.domBack;
  34863. function doClear(x, y, width, height) {
  34864. ctx.clearRect(x, y, width, height);
  34865. if (clearColor && clearColor !== 'transparent') {
  34866. var clearColorGradientOrPattern = void 0;
  34867. if (isGradientObject(clearColor)) {
  34868. var shouldCache = clearColor.global || (clearColor.__width === width
  34869. && clearColor.__height === height);
  34870. clearColorGradientOrPattern = shouldCache
  34871. && clearColor.__canvasGradient
  34872. || getCanvasGradient(ctx, clearColor, {
  34873. x: 0,
  34874. y: 0,
  34875. width: width,
  34876. height: height
  34877. });
  34878. clearColor.__canvasGradient = clearColorGradientOrPattern;
  34879. clearColor.__width = width;
  34880. clearColor.__height = height;
  34881. }
  34882. else if (isImagePatternObject(clearColor)) {
  34883. clearColor.scaleX = clearColor.scaleX || dpr;
  34884. clearColor.scaleY = clearColor.scaleY || dpr;
  34885. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  34886. dirty: function () {
  34887. self.setUnpainted();
  34888. self.painter.refresh();
  34889. }
  34890. });
  34891. }
  34892. ctx.save();
  34893. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  34894. ctx.fillRect(x, y, width, height);
  34895. ctx.restore();
  34896. }
  34897. if (haveMotionBLur) {
  34898. ctx.save();
  34899. ctx.globalAlpha = lastFrameAlpha;
  34900. ctx.drawImage(domBack, x, y, width, height);
  34901. ctx.restore();
  34902. }
  34903. }
  34904. if (!repaintRects || haveMotionBLur) {
  34905. doClear(0, 0, width, height);
  34906. }
  34907. else if (repaintRects.length) {
  34908. each(repaintRects, function (rect) {
  34909. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  34910. });
  34911. }
  34912. };
  34913. return Layer;
  34914. }(Eventful));
  34915. var HOVER_LAYER_ZLEVEL = 1e5;
  34916. var CANVAS_ZLEVEL = 314159;
  34917. var EL_AFTER_INCREMENTAL_INC = 0.01;
  34918. var INCREMENTAL_INC = 0.001;
  34919. function isLayerValid(layer) {
  34920. if (!layer) {
  34921. return false;
  34922. }
  34923. if (layer.__builtin__) {
  34924. return true;
  34925. }
  34926. if (typeof (layer.resize) !== 'function'
  34927. || typeof (layer.refresh) !== 'function') {
  34928. return false;
  34929. }
  34930. return true;
  34931. }
  34932. function createRoot(width, height) {
  34933. var domRoot = document.createElement('div');
  34934. domRoot.style.cssText = [
  34935. 'position:relative',
  34936. 'width:' + width + 'px',
  34937. 'height:' + height + 'px',
  34938. 'padding:0',
  34939. 'margin:0',
  34940. 'border-width:0'
  34941. ].join(';') + ';';
  34942. return domRoot;
  34943. }
  34944. var CanvasPainter = (function () {
  34945. function CanvasPainter(root, storage, opts, id) {
  34946. this.type = 'canvas';
  34947. this._zlevelList = [];
  34948. this._prevDisplayList = [];
  34949. this._layers = {};
  34950. this._layerConfig = {};
  34951. this._needsManuallyCompositing = false;
  34952. this.type = 'canvas';
  34953. var singleCanvas = !root.nodeName
  34954. || root.nodeName.toUpperCase() === 'CANVAS';
  34955. this._opts = opts = extend({}, opts || {});
  34956. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  34957. this._singleCanvas = singleCanvas;
  34958. this.root = root;
  34959. var rootStyle = root.style;
  34960. if (rootStyle) {
  34961. disableUserSelect(root);
  34962. root.innerHTML = '';
  34963. }
  34964. this.storage = storage;
  34965. var zlevelList = this._zlevelList;
  34966. this._prevDisplayList = [];
  34967. var layers = this._layers;
  34968. if (!singleCanvas) {
  34969. this._width = getSize(root, 0, opts);
  34970. this._height = getSize(root, 1, opts);
  34971. var domRoot = this._domRoot = createRoot(this._width, this._height);
  34972. root.appendChild(domRoot);
  34973. }
  34974. else {
  34975. var rootCanvas = root;
  34976. var width = rootCanvas.width;
  34977. var height = rootCanvas.height;
  34978. if (opts.width != null) {
  34979. width = opts.width;
  34980. }
  34981. if (opts.height != null) {
  34982. height = opts.height;
  34983. }
  34984. this.dpr = opts.devicePixelRatio || 1;
  34985. rootCanvas.width = width * this.dpr;
  34986. rootCanvas.height = height * this.dpr;
  34987. this._width = width;
  34988. this._height = height;
  34989. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  34990. mainLayer.__builtin__ = true;
  34991. mainLayer.initContext();
  34992. layers[CANVAS_ZLEVEL] = mainLayer;
  34993. mainLayer.zlevel = CANVAS_ZLEVEL;
  34994. zlevelList.push(CANVAS_ZLEVEL);
  34995. this._domRoot = root;
  34996. }
  34997. }
  34998. CanvasPainter.prototype.getType = function () {
  34999. return 'canvas';
  35000. };
  35001. CanvasPainter.prototype.isSingleCanvas = function () {
  35002. return this._singleCanvas;
  35003. };
  35004. CanvasPainter.prototype.getViewportRoot = function () {
  35005. return this._domRoot;
  35006. };
  35007. CanvasPainter.prototype.getViewportRootOffset = function () {
  35008. var viewportRoot = this.getViewportRoot();
  35009. if (viewportRoot) {
  35010. return {
  35011. offsetLeft: viewportRoot.offsetLeft || 0,
  35012. offsetTop: viewportRoot.offsetTop || 0
  35013. };
  35014. }
  35015. };
  35016. CanvasPainter.prototype.refresh = function (paintAll) {
  35017. var list = this.storage.getDisplayList(true);
  35018. var prevList = this._prevDisplayList;
  35019. var zlevelList = this._zlevelList;
  35020. this._redrawId = Math.random();
  35021. this._paintList(list, prevList, paintAll, this._redrawId);
  35022. for (var i = 0; i < zlevelList.length; i++) {
  35023. var z = zlevelList[i];
  35024. var layer = this._layers[z];
  35025. if (!layer.__builtin__ && layer.refresh) {
  35026. var clearColor = i === 0 ? this._backgroundColor : null;
  35027. layer.refresh(clearColor);
  35028. }
  35029. }
  35030. if (this._opts.useDirtyRect) {
  35031. this._prevDisplayList = list.slice();
  35032. }
  35033. return this;
  35034. };
  35035. CanvasPainter.prototype.refreshHover = function () {
  35036. this._paintHoverList(this.storage.getDisplayList(false));
  35037. };
  35038. CanvasPainter.prototype._paintHoverList = function (list) {
  35039. var len = list.length;
  35040. var hoverLayer = this._hoverlayer;
  35041. hoverLayer && hoverLayer.clear();
  35042. if (!len) {
  35043. return;
  35044. }
  35045. var scope = {
  35046. inHover: true,
  35047. viewWidth: this._width,
  35048. viewHeight: this._height
  35049. };
  35050. var ctx;
  35051. for (var i = 0; i < len; i++) {
  35052. var el = list[i];
  35053. if (el.__inHover) {
  35054. if (!hoverLayer) {
  35055. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  35056. }
  35057. if (!ctx) {
  35058. ctx = hoverLayer.ctx;
  35059. ctx.save();
  35060. }
  35061. brush(ctx, el, scope, i === len - 1);
  35062. }
  35063. }
  35064. if (ctx) {
  35065. ctx.restore();
  35066. }
  35067. };
  35068. CanvasPainter.prototype.getHoverLayer = function () {
  35069. return this.getLayer(HOVER_LAYER_ZLEVEL);
  35070. };
  35071. CanvasPainter.prototype.paintOne = function (ctx, el) {
  35072. brushSingle(ctx, el);
  35073. };
  35074. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  35075. if (this._redrawId !== redrawId) {
  35076. return;
  35077. }
  35078. paintAll = paintAll || false;
  35079. this._updateLayerStatus(list);
  35080. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  35081. if (this._needsManuallyCompositing) {
  35082. this._compositeManually();
  35083. }
  35084. if (needsRefreshHover) {
  35085. this._paintHoverList(list);
  35086. }
  35087. if (!finished) {
  35088. var self_1 = this;
  35089. requestAnimationFrame$1(function () {
  35090. self_1._paintList(list, prevList, paintAll, redrawId);
  35091. });
  35092. }
  35093. else {
  35094. this.eachLayer(function (layer) {
  35095. layer.afterBrush && layer.afterBrush();
  35096. });
  35097. }
  35098. };
  35099. CanvasPainter.prototype._compositeManually = function () {
  35100. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  35101. var width = this._domRoot.width;
  35102. var height = this._domRoot.height;
  35103. ctx.clearRect(0, 0, width, height);
  35104. this.eachBuiltinLayer(function (layer) {
  35105. if (layer.virtual) {
  35106. ctx.drawImage(layer.dom, 0, 0, width, height);
  35107. }
  35108. });
  35109. };
  35110. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  35111. var _this = this;
  35112. var layerList = [];
  35113. var useDirtyRect = this._opts.useDirtyRect;
  35114. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  35115. var zlevel = this._zlevelList[zi];
  35116. var layer = this._layers[zlevel];
  35117. if (layer.__builtin__
  35118. && layer !== this._hoverlayer
  35119. && (layer.__dirty || paintAll)) {
  35120. layerList.push(layer);
  35121. }
  35122. }
  35123. var finished = true;
  35124. var needsRefreshHover = false;
  35125. var _loop_1 = function (k) {
  35126. var layer = layerList[k];
  35127. var ctx = layer.ctx;
  35128. var repaintRects = useDirtyRect
  35129. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  35130. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  35131. var useTimer = !paintAll && layer.incremental && Date.now;
  35132. var startTime = useTimer && Date.now();
  35133. var clearColor = layer.zlevel === this_1._zlevelList[0]
  35134. ? this_1._backgroundColor : null;
  35135. if (layer.__startIndex === layer.__endIndex) {
  35136. layer.clear(false, clearColor, repaintRects);
  35137. }
  35138. else if (start === layer.__startIndex) {
  35139. var firstEl = list[start];
  35140. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  35141. layer.clear(false, clearColor, repaintRects);
  35142. }
  35143. }
  35144. if (start === -1) {
  35145. console.error('For some unknown reason. drawIndex is -1');
  35146. start = layer.__startIndex;
  35147. }
  35148. var i;
  35149. var repaint = function (repaintRect) {
  35150. var scope = {
  35151. inHover: false,
  35152. allClipped: false,
  35153. prevEl: null,
  35154. viewWidth: _this._width,
  35155. viewHeight: _this._height
  35156. };
  35157. for (i = start; i < layer.__endIndex; i++) {
  35158. var el = list[i];
  35159. if (el.__inHover) {
  35160. needsRefreshHover = true;
  35161. }
  35162. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  35163. if (useTimer) {
  35164. var dTime = Date.now() - startTime;
  35165. if (dTime > 15) {
  35166. break;
  35167. }
  35168. }
  35169. }
  35170. if (scope.prevElClipPaths) {
  35171. ctx.restore();
  35172. }
  35173. };
  35174. if (repaintRects) {
  35175. if (repaintRects.length === 0) {
  35176. i = layer.__endIndex;
  35177. }
  35178. else {
  35179. var dpr = this_1.dpr;
  35180. for (var r = 0; r < repaintRects.length; ++r) {
  35181. var rect = repaintRects[r];
  35182. ctx.save();
  35183. ctx.beginPath();
  35184. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  35185. ctx.clip();
  35186. repaint(rect);
  35187. ctx.restore();
  35188. }
  35189. }
  35190. }
  35191. else {
  35192. ctx.save();
  35193. repaint();
  35194. ctx.restore();
  35195. }
  35196. layer.__drawIndex = i;
  35197. if (layer.__drawIndex < layer.__endIndex) {
  35198. finished = false;
  35199. }
  35200. };
  35201. var this_1 = this;
  35202. for (var k = 0; k < layerList.length; k++) {
  35203. _loop_1(k);
  35204. }
  35205. if (env.wxa) {
  35206. each(this._layers, function (layer) {
  35207. if (layer && layer.ctx && layer.ctx.draw) {
  35208. layer.ctx.draw();
  35209. }
  35210. });
  35211. }
  35212. return {
  35213. finished: finished,
  35214. needsRefreshHover: needsRefreshHover
  35215. };
  35216. };
  35217. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  35218. var ctx = currentLayer.ctx;
  35219. if (useDirtyRect) {
  35220. var paintRect = el.getPaintRect();
  35221. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  35222. brush(ctx, el, scope, isLast);
  35223. el.setPrevPaintRect(paintRect);
  35224. }
  35225. }
  35226. else {
  35227. brush(ctx, el, scope, isLast);
  35228. }
  35229. };
  35230. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  35231. if (this._singleCanvas && !this._needsManuallyCompositing) {
  35232. zlevel = CANVAS_ZLEVEL;
  35233. }
  35234. var layer = this._layers[zlevel];
  35235. if (!layer) {
  35236. layer = new Layer('zr_' + zlevel, this, this.dpr);
  35237. layer.zlevel = zlevel;
  35238. layer.__builtin__ = true;
  35239. if (this._layerConfig[zlevel]) {
  35240. merge(layer, this._layerConfig[zlevel], true);
  35241. }
  35242. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  35243. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  35244. }
  35245. if (virtual) {
  35246. layer.virtual = virtual;
  35247. }
  35248. this.insertLayer(zlevel, layer);
  35249. layer.initContext();
  35250. }
  35251. return layer;
  35252. };
  35253. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  35254. var layersMap = this._layers;
  35255. var zlevelList = this._zlevelList;
  35256. var len = zlevelList.length;
  35257. var domRoot = this._domRoot;
  35258. var prevLayer = null;
  35259. var i = -1;
  35260. if (layersMap[zlevel]) {
  35261. if ("development" !== 'production') {
  35262. logError('ZLevel ' + zlevel + ' has been used already');
  35263. }
  35264. return;
  35265. }
  35266. if (!isLayerValid(layer)) {
  35267. if ("development" !== 'production') {
  35268. logError('Layer of zlevel ' + zlevel + ' is not valid');
  35269. }
  35270. return;
  35271. }
  35272. if (len > 0 && zlevel > zlevelList[0]) {
  35273. for (i = 0; i < len - 1; i++) {
  35274. if (zlevelList[i] < zlevel
  35275. && zlevelList[i + 1] > zlevel) {
  35276. break;
  35277. }
  35278. }
  35279. prevLayer = layersMap[zlevelList[i]];
  35280. }
  35281. zlevelList.splice(i + 1, 0, zlevel);
  35282. layersMap[zlevel] = layer;
  35283. if (!layer.virtual) {
  35284. if (prevLayer) {
  35285. var prevDom = prevLayer.dom;
  35286. if (prevDom.nextSibling) {
  35287. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  35288. }
  35289. else {
  35290. domRoot.appendChild(layer.dom);
  35291. }
  35292. }
  35293. else {
  35294. if (domRoot.firstChild) {
  35295. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  35296. }
  35297. else {
  35298. domRoot.appendChild(layer.dom);
  35299. }
  35300. }
  35301. }
  35302. layer.painter || (layer.painter = this);
  35303. };
  35304. CanvasPainter.prototype.eachLayer = function (cb, context) {
  35305. var zlevelList = this._zlevelList;
  35306. for (var i = 0; i < zlevelList.length; i++) {
  35307. var z = zlevelList[i];
  35308. cb.call(context, this._layers[z], z);
  35309. }
  35310. };
  35311. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  35312. var zlevelList = this._zlevelList;
  35313. for (var i = 0; i < zlevelList.length; i++) {
  35314. var z = zlevelList[i];
  35315. var layer = this._layers[z];
  35316. if (layer.__builtin__) {
  35317. cb.call(context, layer, z);
  35318. }
  35319. }
  35320. };
  35321. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  35322. var zlevelList = this._zlevelList;
  35323. for (var i = 0; i < zlevelList.length; i++) {
  35324. var z = zlevelList[i];
  35325. var layer = this._layers[z];
  35326. if (!layer.__builtin__) {
  35327. cb.call(context, layer, z);
  35328. }
  35329. }
  35330. };
  35331. CanvasPainter.prototype.getLayers = function () {
  35332. return this._layers;
  35333. };
  35334. CanvasPainter.prototype._updateLayerStatus = function (list) {
  35335. this.eachBuiltinLayer(function (layer, z) {
  35336. layer.__dirty = layer.__used = false;
  35337. });
  35338. function updatePrevLayer(idx) {
  35339. if (prevLayer) {
  35340. if (prevLayer.__endIndex !== idx) {
  35341. prevLayer.__dirty = true;
  35342. }
  35343. prevLayer.__endIndex = idx;
  35344. }
  35345. }
  35346. if (this._singleCanvas) {
  35347. for (var i_1 = 1; i_1 < list.length; i_1++) {
  35348. var el = list[i_1];
  35349. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  35350. this._needsManuallyCompositing = true;
  35351. break;
  35352. }
  35353. }
  35354. }
  35355. var prevLayer = null;
  35356. var incrementalLayerCount = 0;
  35357. var prevZlevel;
  35358. var i;
  35359. for (i = 0; i < list.length; i++) {
  35360. var el = list[i];
  35361. var zlevel = el.zlevel;
  35362. var layer = void 0;
  35363. if (prevZlevel !== zlevel) {
  35364. prevZlevel = zlevel;
  35365. incrementalLayerCount = 0;
  35366. }
  35367. if (el.incremental) {
  35368. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  35369. layer.incremental = true;
  35370. incrementalLayerCount = 1;
  35371. }
  35372. else {
  35373. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  35374. }
  35375. if (!layer.__builtin__) {
  35376. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  35377. }
  35378. if (layer !== prevLayer) {
  35379. layer.__used = true;
  35380. if (layer.__startIndex !== i) {
  35381. layer.__dirty = true;
  35382. }
  35383. layer.__startIndex = i;
  35384. if (!layer.incremental) {
  35385. layer.__drawIndex = i;
  35386. }
  35387. else {
  35388. layer.__drawIndex = -1;
  35389. }
  35390. updatePrevLayer(i);
  35391. prevLayer = layer;
  35392. }
  35393. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  35394. layer.__dirty = true;
  35395. if (layer.incremental && layer.__drawIndex < 0) {
  35396. layer.__drawIndex = i;
  35397. }
  35398. }
  35399. }
  35400. updatePrevLayer(i);
  35401. this.eachBuiltinLayer(function (layer, z) {
  35402. if (!layer.__used && layer.getElementCount() > 0) {
  35403. layer.__dirty = true;
  35404. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  35405. }
  35406. if (layer.__dirty && layer.__drawIndex < 0) {
  35407. layer.__drawIndex = layer.__startIndex;
  35408. }
  35409. });
  35410. };
  35411. CanvasPainter.prototype.clear = function () {
  35412. this.eachBuiltinLayer(this._clearLayer);
  35413. return this;
  35414. };
  35415. CanvasPainter.prototype._clearLayer = function (layer) {
  35416. layer.clear();
  35417. };
  35418. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  35419. this._backgroundColor = backgroundColor;
  35420. each(this._layers, function (layer) {
  35421. layer.setUnpainted();
  35422. });
  35423. };
  35424. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  35425. if (config) {
  35426. var layerConfig = this._layerConfig;
  35427. if (!layerConfig[zlevel]) {
  35428. layerConfig[zlevel] = config;
  35429. }
  35430. else {
  35431. merge(layerConfig[zlevel], config, true);
  35432. }
  35433. for (var i = 0; i < this._zlevelList.length; i++) {
  35434. var _zlevel = this._zlevelList[i];
  35435. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  35436. var layer = this._layers[_zlevel];
  35437. merge(layer, layerConfig[zlevel], true);
  35438. }
  35439. }
  35440. }
  35441. };
  35442. CanvasPainter.prototype.delLayer = function (zlevel) {
  35443. var layers = this._layers;
  35444. var zlevelList = this._zlevelList;
  35445. var layer = layers[zlevel];
  35446. if (!layer) {
  35447. return;
  35448. }
  35449. layer.dom.parentNode.removeChild(layer.dom);
  35450. delete layers[zlevel];
  35451. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  35452. };
  35453. CanvasPainter.prototype.resize = function (width, height) {
  35454. if (!this._domRoot.style) {
  35455. if (width == null || height == null) {
  35456. return;
  35457. }
  35458. this._width = width;
  35459. this._height = height;
  35460. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  35461. }
  35462. else {
  35463. var domRoot = this._domRoot;
  35464. domRoot.style.display = 'none';
  35465. var opts = this._opts;
  35466. var root = this.root;
  35467. width != null && (opts.width = width);
  35468. height != null && (opts.height = height);
  35469. width = getSize(root, 0, opts);
  35470. height = getSize(root, 1, opts);
  35471. domRoot.style.display = '';
  35472. if (this._width !== width || height !== this._height) {
  35473. domRoot.style.width = width + 'px';
  35474. domRoot.style.height = height + 'px';
  35475. for (var id in this._layers) {
  35476. if (this._layers.hasOwnProperty(id)) {
  35477. this._layers[id].resize(width, height);
  35478. }
  35479. }
  35480. this.refresh(true);
  35481. }
  35482. this._width = width;
  35483. this._height = height;
  35484. }
  35485. return this;
  35486. };
  35487. CanvasPainter.prototype.clearLayer = function (zlevel) {
  35488. var layer = this._layers[zlevel];
  35489. if (layer) {
  35490. layer.clear();
  35491. }
  35492. };
  35493. CanvasPainter.prototype.dispose = function () {
  35494. this.root.innerHTML = '';
  35495. this.root =
  35496. this.storage =
  35497. this._domRoot =
  35498. this._layers = null;
  35499. };
  35500. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  35501. opts = opts || {};
  35502. if (this._singleCanvas && !this._compositeManually) {
  35503. return this._layers[CANVAS_ZLEVEL].dom;
  35504. }
  35505. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  35506. imageLayer.initContext();
  35507. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  35508. var ctx = imageLayer.ctx;
  35509. if (opts.pixelRatio <= this.dpr) {
  35510. this.refresh();
  35511. var width_1 = imageLayer.dom.width;
  35512. var height_1 = imageLayer.dom.height;
  35513. this.eachLayer(function (layer) {
  35514. if (layer.__builtin__) {
  35515. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  35516. }
  35517. else if (layer.renderToCanvas) {
  35518. ctx.save();
  35519. layer.renderToCanvas(ctx);
  35520. ctx.restore();
  35521. }
  35522. });
  35523. }
  35524. else {
  35525. var scope = {
  35526. inHover: false,
  35527. viewWidth: this._width,
  35528. viewHeight: this._height
  35529. };
  35530. var displayList = this.storage.getDisplayList(true);
  35531. for (var i = 0, len = displayList.length; i < len; i++) {
  35532. var el = displayList[i];
  35533. brush(ctx, el, scope, i === len - 1);
  35534. }
  35535. }
  35536. return imageLayer.dom;
  35537. };
  35538. CanvasPainter.prototype.getWidth = function () {
  35539. return this._width;
  35540. };
  35541. CanvasPainter.prototype.getHeight = function () {
  35542. return this._height;
  35543. };
  35544. return CanvasPainter;
  35545. }());
  35546. function install(registers) {
  35547. registers.registerPainter('canvas', CanvasPainter);
  35548. }
  35549. var LineSeriesModel = /** @class */function (_super) {
  35550. __extends(LineSeriesModel, _super);
  35551. function LineSeriesModel() {
  35552. var _this = _super !== null && _super.apply(this, arguments) || this;
  35553. _this.type = LineSeriesModel.type;
  35554. _this.hasSymbolVisual = true;
  35555. return _this;
  35556. }
  35557. LineSeriesModel.prototype.getInitialData = function (option) {
  35558. if ("development" !== 'production') {
  35559. var coordSys = option.coordinateSystem;
  35560. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  35561. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  35562. }
  35563. }
  35564. return createSeriesData(null, this, {
  35565. useEncodeDefaulter: true
  35566. });
  35567. };
  35568. LineSeriesModel.prototype.getLegendIcon = function (opt) {
  35569. var group = new Group();
  35570. var line = createSymbol('line', 0, opt.itemHeight / 2, opt.itemWidth, 0, opt.lineStyle.stroke, false);
  35571. group.add(line);
  35572. line.setStyle(opt.lineStyle);
  35573. var visualType = this.getData().getVisual('symbol');
  35574. var visualRotate = this.getData().getVisual('symbolRotate');
  35575. var symbolType = visualType === 'none' ? 'circle' : visualType;
  35576. // Symbol size is 80% when there is a line
  35577. var size = opt.itemHeight * 0.8;
  35578. var symbol = createSymbol(symbolType, (opt.itemWidth - size) / 2, (opt.itemHeight - size) / 2, size, size, opt.itemStyle.fill);
  35579. group.add(symbol);
  35580. symbol.setStyle(opt.itemStyle);
  35581. var symbolRotate = opt.iconRotate === 'inherit' ? visualRotate : opt.iconRotate || 0;
  35582. symbol.rotation = symbolRotate * Math.PI / 180;
  35583. symbol.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
  35584. if (symbolType.indexOf('empty') > -1) {
  35585. symbol.style.stroke = symbol.style.fill;
  35586. symbol.style.fill = tokens.color.neutral00;
  35587. symbol.style.lineWidth = 2;
  35588. }
  35589. return group;
  35590. };
  35591. LineSeriesModel.type = 'series.line';
  35592. LineSeriesModel.dependencies = ['grid', 'polar'];
  35593. LineSeriesModel.defaultOption = {
  35594. // zlevel: 0,
  35595. z: 3,
  35596. coordinateSystem: 'cartesian2d',
  35597. legendHoverLink: true,
  35598. clip: true,
  35599. label: {
  35600. position: 'top'
  35601. },
  35602. // itemStyle: {
  35603. // },
  35604. endLabel: {
  35605. show: false,
  35606. valueAnimation: true,
  35607. distance: 8
  35608. },
  35609. lineStyle: {
  35610. width: 2,
  35611. type: 'solid'
  35612. },
  35613. emphasis: {
  35614. scale: true
  35615. },
  35616. // areaStyle: {
  35617. // origin of areaStyle. Valid values:
  35618. // `'auto'/null/undefined`: from axisLine to data
  35619. // `'start'`: from min to data
  35620. // `'end'`: from data to max
  35621. // origin: 'auto'
  35622. // },
  35623. // false, 'start', 'end', 'middle'
  35624. step: false,
  35625. // Disabled if step is true
  35626. smooth: false,
  35627. smoothMonotone: null,
  35628. symbol: 'emptyCircle',
  35629. symbolSize: 6,
  35630. symbolRotate: null,
  35631. showSymbol: true,
  35632. // `false`: follow the label interval strategy.
  35633. // `true`: show all symbols.
  35634. // `'auto'`: If possible, show all symbols, otherwise
  35635. // follow the label interval strategy.
  35636. showAllSymbol: 'auto',
  35637. // Whether to connect break point.
  35638. connectNulls: false,
  35639. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum', 'lttb'.
  35640. sampling: 'none',
  35641. animationEasing: 'linear',
  35642. // Disable progressive
  35643. progressive: 0,
  35644. hoverLayerThreshold: Infinity,
  35645. universalTransition: {
  35646. divideShape: 'clone'
  35647. },
  35648. triggerLineEvent: false
  35649. };
  35650. return LineSeriesModel;
  35651. }(SeriesModel);
  35652. /**
  35653. * @return label string. Not null/undefined
  35654. */
  35655. function getDefaultLabel(data, dataIndex) {
  35656. var labelDims = data.mapDimensionsAll('defaultedLabel');
  35657. var len = labelDims.length;
  35658. // Simple optimization (in lots of cases, label dims length is 1)
  35659. if (len === 1) {
  35660. var rawVal = retrieveRawValue(data, dataIndex, labelDims[0]);
  35661. return rawVal != null ? rawVal + '' : null;
  35662. } else if (len) {
  35663. var vals = [];
  35664. for (var i = 0; i < labelDims.length; i++) {
  35665. vals.push(retrieveRawValue(data, dataIndex, labelDims[i]));
  35666. }
  35667. return vals.join(' ');
  35668. }
  35669. }
  35670. function getDefaultInterpolatedLabel(data, interpolatedValue) {
  35671. var labelDims = data.mapDimensionsAll('defaultedLabel');
  35672. if (!isArray(interpolatedValue)) {
  35673. return interpolatedValue + '';
  35674. }
  35675. var vals = [];
  35676. for (var i = 0; i < labelDims.length; i++) {
  35677. var dimIndex = data.getDimensionIndex(labelDims[i]);
  35678. if (dimIndex >= 0) {
  35679. vals.push(interpolatedValue[dimIndex]);
  35680. }
  35681. }
  35682. return vals.join(' ');
  35683. }
  35684. var Symbol = /** @class */function (_super) {
  35685. __extends(Symbol, _super);
  35686. function Symbol(data, idx, seriesScope, opts) {
  35687. var _this = _super.call(this) || this;
  35688. _this.updateData(data, idx, seriesScope, opts);
  35689. return _this;
  35690. }
  35691. Symbol.prototype._createSymbol = function (symbolType, data, idx, symbolSize, z2, keepAspect) {
  35692. // Remove paths created before
  35693. this.removeAll();
  35694. // let symbolPath = createSymbol(
  35695. // symbolType, -0.5, -0.5, 1, 1, color
  35696. // );
  35697. // If width/height are set too small (e.g., set to 1) on ios10
  35698. // and macOS Sierra, a circle stroke become a rect, no matter what
  35699. // the scale is set. So we set width/height as 2. See #4150.
  35700. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, null, keepAspect);
  35701. symbolPath.attr({
  35702. z2: retrieve2(z2, 100),
  35703. culling: true,
  35704. scaleX: symbolSize[0] / 2,
  35705. scaleY: symbolSize[1] / 2
  35706. });
  35707. // Rewrite drift method
  35708. symbolPath.drift = driftSymbol;
  35709. this._symbolType = symbolType;
  35710. this.add(symbolPath);
  35711. };
  35712. /**
  35713. * Stop animation
  35714. * @param {boolean} toLastFrame
  35715. */
  35716. Symbol.prototype.stopSymbolAnimation = function (toLastFrame) {
  35717. this.childAt(0).stopAnimation(null, toLastFrame);
  35718. };
  35719. Symbol.prototype.getSymbolType = function () {
  35720. return this._symbolType;
  35721. };
  35722. /**
  35723. * FIXME:
  35724. * Caution: This method breaks the encapsulation of this module,
  35725. * but it indeed brings convenience. So do not use the method
  35726. * unless you detailedly know all the implements of `Symbol`,
  35727. * especially animation.
  35728. *
  35729. * Get symbol path element.
  35730. */
  35731. Symbol.prototype.getSymbolPath = function () {
  35732. return this.childAt(0);
  35733. };
  35734. /**
  35735. * Highlight symbol
  35736. */
  35737. Symbol.prototype.highlight = function () {
  35738. enterEmphasis(this.childAt(0));
  35739. };
  35740. /**
  35741. * Downplay symbol
  35742. */
  35743. Symbol.prototype.downplay = function () {
  35744. leaveEmphasis(this.childAt(0));
  35745. };
  35746. /**
  35747. * @param {number} zlevel
  35748. * @param {number} z
  35749. */
  35750. Symbol.prototype.setZ = function (zlevel, z) {
  35751. var symbolPath = this.childAt(0);
  35752. symbolPath.zlevel = zlevel;
  35753. symbolPath.z = z;
  35754. };
  35755. Symbol.prototype.setDraggable = function (draggable, hasCursorOption) {
  35756. var symbolPath = this.childAt(0);
  35757. symbolPath.draggable = draggable;
  35758. symbolPath.cursor = !hasCursorOption && draggable ? 'move' : symbolPath.cursor;
  35759. };
  35760. /**
  35761. * Update symbol properties
  35762. */
  35763. Symbol.prototype.updateData = function (data, idx, seriesScope, opts) {
  35764. this.silent = false;
  35765. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  35766. var seriesModel = data.hostModel;
  35767. var symbolSize = Symbol.getSymbolSize(data, idx);
  35768. var z2 = Symbol.getSymbolZ2(data, idx);
  35769. var isInit = symbolType !== this._symbolType;
  35770. var disableAnimation = opts && opts.disableAnimation;
  35771. if (isInit) {
  35772. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  35773. this._createSymbol(symbolType, data, idx, symbolSize, z2, keepAspect);
  35774. } else {
  35775. var symbolPath = this.childAt(0);
  35776. symbolPath.silent = false;
  35777. var target = {
  35778. scaleX: symbolSize[0] / 2,
  35779. scaleY: symbolSize[1] / 2
  35780. };
  35781. disableAnimation ? symbolPath.attr(target) : updateProps(symbolPath, target, seriesModel, idx);
  35782. saveOldStyle(symbolPath);
  35783. }
  35784. this._updateCommon(data, idx, symbolSize, seriesScope, opts);
  35785. if (isInit) {
  35786. var symbolPath = this.childAt(0);
  35787. if (!disableAnimation) {
  35788. var target = {
  35789. scaleX: this._sizeX,
  35790. scaleY: this._sizeY,
  35791. style: {
  35792. // Always fadeIn. Because it has fadeOut animation when symbol is removed..
  35793. opacity: symbolPath.style.opacity
  35794. }
  35795. };
  35796. symbolPath.scaleX = symbolPath.scaleY = 0;
  35797. symbolPath.style.opacity = 0;
  35798. initProps(symbolPath, target, seriesModel, idx);
  35799. }
  35800. }
  35801. if (disableAnimation) {
  35802. // Must stop leave transition manually if don't call initProps or updateProps.
  35803. this.childAt(0).stopAnimation('leave');
  35804. }
  35805. };
  35806. Symbol.prototype._updateCommon = function (data, idx, symbolSize, seriesScope, opts) {
  35807. var symbolPath = this.childAt(0);
  35808. var seriesModel = data.hostModel;
  35809. var emphasisItemStyle;
  35810. var blurItemStyle;
  35811. var selectItemStyle;
  35812. var focus;
  35813. var blurScope;
  35814. var emphasisDisabled;
  35815. var labelStatesModels;
  35816. var hoverScale;
  35817. var cursorStyle;
  35818. if (seriesScope) {
  35819. emphasisItemStyle = seriesScope.emphasisItemStyle;
  35820. blurItemStyle = seriesScope.blurItemStyle;
  35821. selectItemStyle = seriesScope.selectItemStyle;
  35822. focus = seriesScope.focus;
  35823. blurScope = seriesScope.blurScope;
  35824. labelStatesModels = seriesScope.labelStatesModels;
  35825. hoverScale = seriesScope.hoverScale;
  35826. cursorStyle = seriesScope.cursorStyle;
  35827. emphasisDisabled = seriesScope.emphasisDisabled;
  35828. }
  35829. if (!seriesScope || data.hasItemOption) {
  35830. var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx);
  35831. var emphasisModel = itemModel.getModel('emphasis');
  35832. emphasisItemStyle = emphasisModel.getModel('itemStyle').getItemStyle();
  35833. selectItemStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
  35834. blurItemStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
  35835. focus = emphasisModel.get('focus');
  35836. blurScope = emphasisModel.get('blurScope');
  35837. emphasisDisabled = emphasisModel.get('disabled');
  35838. labelStatesModels = getLabelStatesModels(itemModel);
  35839. hoverScale = emphasisModel.getShallow('scale');
  35840. cursorStyle = itemModel.getShallow('cursor');
  35841. }
  35842. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  35843. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  35844. var symbolOffset = normalizeSymbolOffset(data.getItemVisual(idx, 'symbolOffset'), symbolSize);
  35845. if (symbolOffset) {
  35846. symbolPath.x = symbolOffset[0];
  35847. symbolPath.y = symbolOffset[1];
  35848. }
  35849. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  35850. var symbolStyle = data.getItemVisual(idx, 'style');
  35851. var visualColor = symbolStyle.fill;
  35852. if (symbolPath instanceof ZRImage) {
  35853. var pathStyle = symbolPath.style;
  35854. symbolPath.useStyle(extend({
  35855. // TODO other properties like x, y ?
  35856. image: pathStyle.image,
  35857. x: pathStyle.x,
  35858. y: pathStyle.y,
  35859. width: pathStyle.width,
  35860. height: pathStyle.height
  35861. }, symbolStyle));
  35862. } else {
  35863. if (symbolPath.__isEmptyBrush) {
  35864. // fill and stroke will be swapped if it's empty.
  35865. // So we cloned a new style to avoid it affecting the original style in visual storage.
  35866. // TODO Better implementation. No empty logic!
  35867. symbolPath.useStyle(extend({}, symbolStyle));
  35868. } else {
  35869. symbolPath.useStyle(symbolStyle);
  35870. }
  35871. // Disable decal because symbol scale will been applied on the decal.
  35872. symbolPath.style.decal = null;
  35873. symbolPath.setColor(visualColor, opts && opts.symbolInnerColor);
  35874. symbolPath.style.strokeNoScale = true;
  35875. }
  35876. var liftZ = data.getItemVisual(idx, 'liftZ');
  35877. var z2Origin = this._z2;
  35878. if (liftZ != null) {
  35879. if (z2Origin == null) {
  35880. this._z2 = symbolPath.z2;
  35881. symbolPath.z2 += liftZ;
  35882. }
  35883. } else if (z2Origin != null) {
  35884. symbolPath.z2 = z2Origin;
  35885. this._z2 = null;
  35886. }
  35887. var useNameLabel = opts && opts.useNameLabel;
  35888. setLabelStyle(symbolPath, labelStatesModels, {
  35889. labelFetcher: seriesModel,
  35890. labelDataIndex: idx,
  35891. defaultText: getLabelDefaultText,
  35892. inheritColor: visualColor,
  35893. defaultOpacity: symbolStyle.opacity
  35894. });
  35895. // Do not execute util needed.
  35896. function getLabelDefaultText(idx) {
  35897. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  35898. }
  35899. this._sizeX = symbolSize[0] / 2;
  35900. this._sizeY = symbolSize[1] / 2;
  35901. var emphasisState = symbolPath.ensureState('emphasis');
  35902. emphasisState.style = emphasisItemStyle;
  35903. symbolPath.ensureState('select').style = selectItemStyle;
  35904. symbolPath.ensureState('blur').style = blurItemStyle;
  35905. // null / undefined / true means to use default strategy.
  35906. // 0 / false / negative number / NaN / Infinity means no scale.
  35907. var scaleRatio = hoverScale == null || hoverScale === true ? Math.max(1.1, 3 / this._sizeY)
  35908. // PENDING: restrict hoverScale > 1? It seems unreasonable to scale down
  35909. : isFinite(hoverScale) && hoverScale > 0 ? +hoverScale : 1;
  35910. // always set scale to allow resetting
  35911. emphasisState.scaleX = this._sizeX * scaleRatio;
  35912. emphasisState.scaleY = this._sizeY * scaleRatio;
  35913. this.setSymbolScale(1);
  35914. toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
  35915. };
  35916. Symbol.prototype.setSymbolScale = function (scale) {
  35917. this.scaleX = this.scaleY = scale;
  35918. };
  35919. Symbol.prototype.fadeOut = function (cb, seriesModel, opt) {
  35920. var symbolPath = this.childAt(0);
  35921. var dataIndex = getECData(this).dataIndex;
  35922. var animationOpt = opt && opt.animation;
  35923. // Avoid mistaken hover when fading out
  35924. this.silent = symbolPath.silent = true;
  35925. // Not show text when animating
  35926. if (opt && opt.fadeLabel) {
  35927. var textContent = symbolPath.getTextContent();
  35928. if (textContent) {
  35929. removeElement(textContent, {
  35930. style: {
  35931. opacity: 0
  35932. }
  35933. }, seriesModel, {
  35934. dataIndex: dataIndex,
  35935. removeOpt: animationOpt,
  35936. cb: function () {
  35937. symbolPath.removeTextContent();
  35938. }
  35939. });
  35940. }
  35941. } else {
  35942. symbolPath.removeTextContent();
  35943. }
  35944. removeElement(symbolPath, {
  35945. style: {
  35946. opacity: 0
  35947. },
  35948. scaleX: 0,
  35949. scaleY: 0
  35950. }, seriesModel, {
  35951. dataIndex: dataIndex,
  35952. cb: cb,
  35953. removeOpt: animationOpt
  35954. });
  35955. };
  35956. Symbol.getSymbolSize = function (data, idx) {
  35957. return normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  35958. };
  35959. Symbol.getSymbolZ2 = function (data, idx) {
  35960. return data.getItemVisual(idx, 'z2');
  35961. };
  35962. return Symbol;
  35963. }(Group);
  35964. function driftSymbol(dx, dy) {
  35965. this.parent.drift(dx, dy);
  35966. }
  35967. function symbolNeedsDraw(data, point, idx, opt) {
  35968. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(opt.isIgnore && opt.isIgnore(idx))
  35969. // We do not set clipShape on group, because it will cut part of
  35970. // the symbol element shape. We use the same clip shape here as
  35971. // the line clip.
  35972. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1])) && data.getItemVisual(idx, 'symbol') !== 'none';
  35973. }
  35974. function normalizeUpdateOpt(opt) {
  35975. if (opt != null && !isObject(opt)) {
  35976. opt = {
  35977. isIgnore: opt
  35978. };
  35979. }
  35980. return opt || {};
  35981. }
  35982. function makeSeriesScope(data) {
  35983. var seriesModel = data.hostModel;
  35984. var emphasisModel = seriesModel.getModel('emphasis');
  35985. return {
  35986. emphasisItemStyle: emphasisModel.getModel('itemStyle').getItemStyle(),
  35987. blurItemStyle: seriesModel.getModel(['blur', 'itemStyle']).getItemStyle(),
  35988. selectItemStyle: seriesModel.getModel(['select', 'itemStyle']).getItemStyle(),
  35989. focus: emphasisModel.get('focus'),
  35990. blurScope: emphasisModel.get('blurScope'),
  35991. emphasisDisabled: emphasisModel.get('disabled'),
  35992. hoverScale: emphasisModel.get('scale'),
  35993. labelStatesModels: getLabelStatesModels(seriesModel),
  35994. cursorStyle: seriesModel.get('cursor')
  35995. };
  35996. }
  35997. var SymbolDraw = /** @class */function () {
  35998. function SymbolDraw(SymbolCtor) {
  35999. this.group = new Group();
  36000. this._SymbolCtor = SymbolCtor || Symbol;
  36001. }
  36002. /**
  36003. * Update symbols draw by new data
  36004. */
  36005. SymbolDraw.prototype.updateData = function (data, opt) {
  36006. // Remove progressive els.
  36007. this._progressiveEls = null;
  36008. opt = normalizeUpdateOpt(opt);
  36009. var group = this.group;
  36010. var seriesModel = data.hostModel;
  36011. var oldData = this._data;
  36012. var SymbolCtor = this._SymbolCtor;
  36013. var disableAnimation = opt.disableAnimation;
  36014. var seriesScope = makeSeriesScope(data);
  36015. var symbolUpdateOpt = {
  36016. disableAnimation: disableAnimation
  36017. };
  36018. var getSymbolPoint = opt.getSymbolPoint || function (idx) {
  36019. return data.getItemLayout(idx);
  36020. };
  36021. // There is no oldLineData only when first rendering or switching from
  36022. // stream mode to normal mode, where previous elements should be removed.
  36023. if (!oldData) {
  36024. group.removeAll();
  36025. }
  36026. data.diff(oldData).add(function (newIdx) {
  36027. var point = getSymbolPoint(newIdx);
  36028. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  36029. var symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  36030. symbolEl.setPosition(point);
  36031. data.setItemGraphicEl(newIdx, symbolEl);
  36032. group.add(symbolEl);
  36033. }
  36034. }).update(function (newIdx, oldIdx) {
  36035. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  36036. var point = getSymbolPoint(newIdx);
  36037. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  36038. group.remove(symbolEl);
  36039. return;
  36040. }
  36041. var newSymbolType = data.getItemVisual(newIdx, 'symbol') || 'circle';
  36042. var oldSymbolType = symbolEl && symbolEl.getSymbolType && symbolEl.getSymbolType();
  36043. if (!symbolEl
  36044. // Create a new if symbol type changed.
  36045. || oldSymbolType && oldSymbolType !== newSymbolType) {
  36046. group.remove(symbolEl);
  36047. symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  36048. symbolEl.setPosition(point);
  36049. } else {
  36050. symbolEl.updateData(data, newIdx, seriesScope, symbolUpdateOpt);
  36051. var target = {
  36052. x: point[0],
  36053. y: point[1]
  36054. };
  36055. disableAnimation ? symbolEl.attr(target) : updateProps(symbolEl, target, seriesModel);
  36056. }
  36057. // Add back
  36058. group.add(symbolEl);
  36059. data.setItemGraphicEl(newIdx, symbolEl);
  36060. }).remove(function (oldIdx) {
  36061. var el = oldData.getItemGraphicEl(oldIdx);
  36062. el && el.fadeOut(function () {
  36063. group.remove(el);
  36064. }, seriesModel);
  36065. }).execute();
  36066. this._getSymbolPoint = getSymbolPoint;
  36067. this._data = data;
  36068. };
  36069. SymbolDraw.prototype.updateLayout = function () {
  36070. var _this = this;
  36071. var data = this._data;
  36072. if (data) {
  36073. // Not use animation
  36074. data.eachItemGraphicEl(function (el, idx) {
  36075. var point = _this._getSymbolPoint(idx);
  36076. el.setPosition(point);
  36077. el.markRedraw();
  36078. });
  36079. }
  36080. };
  36081. SymbolDraw.prototype.incrementalPrepareUpdate = function (data) {
  36082. this._seriesScope = makeSeriesScope(data);
  36083. this._data = null;
  36084. this.group.removeAll();
  36085. };
  36086. /**
  36087. * Update symbols draw by new data
  36088. */
  36089. SymbolDraw.prototype.incrementalUpdate = function (taskParams, data, opt) {
  36090. // Clear
  36091. this._progressiveEls = [];
  36092. opt = normalizeUpdateOpt(opt);
  36093. function updateIncrementalAndHover(el) {
  36094. if (!el.isGroup) {
  36095. el.incremental = true;
  36096. el.ensureState('emphasis').hoverLayer = true;
  36097. }
  36098. }
  36099. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  36100. var point = data.getItemLayout(idx);
  36101. if (symbolNeedsDraw(data, point, idx, opt)) {
  36102. var el = new this._SymbolCtor(data, idx, this._seriesScope);
  36103. el.traverse(updateIncrementalAndHover);
  36104. el.setPosition(point);
  36105. this.group.add(el);
  36106. data.setItemGraphicEl(idx, el);
  36107. this._progressiveEls.push(el);
  36108. }
  36109. }
  36110. };
  36111. SymbolDraw.prototype.eachRendered = function (cb) {
  36112. traverseElements(this._progressiveEls || this.group, cb);
  36113. };
  36114. SymbolDraw.prototype.remove = function (enableAnimation) {
  36115. var group = this.group;
  36116. var data = this._data;
  36117. // Incremental model do not have this._data.
  36118. if (data && enableAnimation) {
  36119. data.eachItemGraphicEl(function (el) {
  36120. el.fadeOut(function () {
  36121. group.remove(el);
  36122. }, data.hostModel);
  36123. });
  36124. } else {
  36125. group.removeAll();
  36126. }
  36127. };
  36128. return SymbolDraw;
  36129. }();
  36130. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  36131. var baseAxis = coordSys.getBaseAxis();
  36132. var valueAxis = coordSys.getOtherAxis(baseAxis);
  36133. var valueStart = getValueStart(valueAxis, valueOrigin);
  36134. var baseAxisDim = baseAxis.dim;
  36135. var valueAxisDim = valueAxis.dim;
  36136. var valueDim = data.mapDimension(valueAxisDim);
  36137. var baseDim = data.mapDimension(baseAxisDim);
  36138. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  36139. var dims = map(coordSys.dimensions, function (coordDim) {
  36140. return data.mapDimension(coordDim);
  36141. });
  36142. var stacked = false;
  36143. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  36144. if (isDimensionStacked(data, dims[0] /* , dims[1] */)) {
  36145. // jshint ignore:line
  36146. stacked = true;
  36147. dims[0] = stackResultDim;
  36148. }
  36149. if (isDimensionStacked(data, dims[1] /* , dims[0] */)) {
  36150. // jshint ignore:line
  36151. stacked = true;
  36152. dims[1] = stackResultDim;
  36153. }
  36154. return {
  36155. dataDimsForPoint: dims,
  36156. valueStart: valueStart,
  36157. valueAxisDim: valueAxisDim,
  36158. baseAxisDim: baseAxisDim,
  36159. stacked: !!stacked,
  36160. valueDim: valueDim,
  36161. baseDim: baseDim,
  36162. baseDataOffset: baseDataOffset,
  36163. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  36164. };
  36165. }
  36166. function getValueStart(valueAxis, valueOrigin) {
  36167. var valueStart = 0;
  36168. var extent = valueAxis.scale.getExtent();
  36169. if (valueOrigin === 'start') {
  36170. valueStart = extent[0];
  36171. } else if (valueOrigin === 'end') {
  36172. valueStart = extent[1];
  36173. }
  36174. // If origin is specified as a number, use it as
  36175. // valueStart directly
  36176. else if (isNumber(valueOrigin) && !isNaN(valueOrigin)) {
  36177. valueStart = valueOrigin;
  36178. }
  36179. // auto
  36180. else {
  36181. // Both positive
  36182. if (extent[0] > 0) {
  36183. valueStart = extent[0];
  36184. }
  36185. // Both negative
  36186. else if (extent[1] < 0) {
  36187. valueStart = extent[1];
  36188. }
  36189. // If is one positive, and one negative, onZero shall be true
  36190. }
  36191. return valueStart;
  36192. }
  36193. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  36194. var value = NaN;
  36195. if (dataCoordInfo.stacked) {
  36196. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  36197. }
  36198. if (isNaN(value)) {
  36199. value = dataCoordInfo.valueStart;
  36200. }
  36201. var baseDataOffset = dataCoordInfo.baseDataOffset;
  36202. var stackedData = [];
  36203. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  36204. stackedData[1 - baseDataOffset] = value;
  36205. return coordSys.dataToPoint(stackedData);
  36206. }
  36207. function diffData(oldData, newData) {
  36208. var diffResult = [];
  36209. newData.diff(oldData).add(function (idx) {
  36210. diffResult.push({
  36211. cmd: '+',
  36212. idx: idx
  36213. });
  36214. }).update(function (newIdx, oldIdx) {
  36215. diffResult.push({
  36216. cmd: '=',
  36217. idx: oldIdx,
  36218. idx1: newIdx
  36219. });
  36220. }).remove(function (idx) {
  36221. diffResult.push({
  36222. cmd: '-',
  36223. idx: idx
  36224. });
  36225. }).execute();
  36226. return diffResult;
  36227. }
  36228. function lineAnimationDiff(oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  36229. var diff = diffData(oldData, newData);
  36230. // let newIdList = newData.mapArray(newData.getId);
  36231. // let oldIdList = oldData.mapArray(oldData.getId);
  36232. // convertToIntId(newIdList, oldIdList);
  36233. // // FIXME One data ?
  36234. // diff = arrayDiff(oldIdList, newIdList);
  36235. var currPoints = [];
  36236. var nextPoints = [];
  36237. // Points for stacking base line
  36238. var currStackedPoints = [];
  36239. var nextStackedPoints = [];
  36240. var status = [];
  36241. var sortedIndices = [];
  36242. var rawIndices = [];
  36243. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  36244. // const oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  36245. var oldPoints = oldData.getLayout('points') || [];
  36246. var newPoints = newData.getLayout('points') || [];
  36247. for (var i = 0; i < diff.length; i++) {
  36248. var diffItem = diff[i];
  36249. var pointAdded = true;
  36250. var oldIdx2 = void 0;
  36251. var newIdx2 = void 0;
  36252. // FIXME, animation is not so perfect when dataZoom window moves fast
  36253. // Which is in case remvoing or add more than one data in the tail or head
  36254. switch (diffItem.cmd) {
  36255. case '=':
  36256. oldIdx2 = diffItem.idx * 2;
  36257. newIdx2 = diffItem.idx1 * 2;
  36258. var currentX = oldPoints[oldIdx2];
  36259. var currentY = oldPoints[oldIdx2 + 1];
  36260. var nextX = newPoints[newIdx2];
  36261. var nextY = newPoints[newIdx2 + 1];
  36262. // If previous data is NaN, use next point directly
  36263. if (isNaN(currentX) || isNaN(currentY)) {
  36264. currentX = nextX;
  36265. currentY = nextY;
  36266. }
  36267. currPoints.push(currentX, currentY);
  36268. nextPoints.push(nextX, nextY);
  36269. currStackedPoints.push(oldStackedOnPoints[oldIdx2], oldStackedOnPoints[oldIdx2 + 1]);
  36270. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  36271. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  36272. break;
  36273. case '+':
  36274. var newIdx = diffItem.idx;
  36275. var newDataDimsForPoint = newDataOldCoordInfo.dataDimsForPoint;
  36276. var oldPt = oldCoordSys.dataToPoint([newData.get(newDataDimsForPoint[0], newIdx), newData.get(newDataDimsForPoint[1], newIdx)]);
  36277. newIdx2 = newIdx * 2;
  36278. currPoints.push(oldPt[0], oldPt[1]);
  36279. nextPoints.push(newPoints[newIdx2], newPoints[newIdx2 + 1]);
  36280. var stackedOnPoint = getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, newIdx);
  36281. currStackedPoints.push(stackedOnPoint[0], stackedOnPoint[1]);
  36282. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  36283. rawIndices.push(newData.getRawIndex(newIdx));
  36284. break;
  36285. case '-':
  36286. pointAdded = false;
  36287. }
  36288. // Original indices
  36289. if (pointAdded) {
  36290. status.push(diffItem);
  36291. sortedIndices.push(sortedIndices.length);
  36292. }
  36293. }
  36294. // Diff result may be crossed if all items are changed
  36295. // Sort by data index
  36296. sortedIndices.sort(function (a, b) {
  36297. return rawIndices[a] - rawIndices[b];
  36298. });
  36299. var len = currPoints.length;
  36300. var sortedCurrPoints = createFloat32Array(len);
  36301. var sortedNextPoints = createFloat32Array(len);
  36302. var sortedCurrStackedPoints = createFloat32Array(len);
  36303. var sortedNextStackedPoints = createFloat32Array(len);
  36304. var sortedStatus = [];
  36305. for (var i = 0; i < sortedIndices.length; i++) {
  36306. var idx = sortedIndices[i];
  36307. var i2 = i * 2;
  36308. var idx2 = idx * 2;
  36309. sortedCurrPoints[i2] = currPoints[idx2];
  36310. sortedCurrPoints[i2 + 1] = currPoints[idx2 + 1];
  36311. sortedNextPoints[i2] = nextPoints[idx2];
  36312. sortedNextPoints[i2 + 1] = nextPoints[idx2 + 1];
  36313. sortedCurrStackedPoints[i2] = currStackedPoints[idx2];
  36314. sortedCurrStackedPoints[i2 + 1] = currStackedPoints[idx2 + 1];
  36315. sortedNextStackedPoints[i2] = nextStackedPoints[idx2];
  36316. sortedNextStackedPoints[i2 + 1] = nextStackedPoints[idx2 + 1];
  36317. sortedStatus[i] = status[idx];
  36318. }
  36319. return {
  36320. current: sortedCurrPoints,
  36321. next: sortedNextPoints,
  36322. stackedOnCurrent: sortedCurrStackedPoints,
  36323. stackedOnNext: sortedNextStackedPoints,
  36324. status: sortedStatus
  36325. };
  36326. }
  36327. var mathMin$6 = Math.min;
  36328. var mathMax$6 = Math.max;
  36329. function isPointNull(x, y) {
  36330. return isNaN(x) || isNaN(y);
  36331. }
  36332. /**
  36333. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  36334. * situations. This should be used when points are non-monotone neither in x or
  36335. * y dimension.
  36336. */
  36337. function drawSegment(ctx, points, start, segLen, allLen, dir, smooth, smoothMonotone, connectNulls) {
  36338. var prevX;
  36339. var prevY;
  36340. var cpx0;
  36341. var cpy0;
  36342. var cpx1;
  36343. var cpy1;
  36344. var idx = start;
  36345. var k = 0;
  36346. for (; k < segLen; k++) {
  36347. var x = points[idx * 2];
  36348. var y = points[idx * 2 + 1];
  36349. if (idx >= allLen || idx < 0) {
  36350. break;
  36351. }
  36352. if (isPointNull(x, y)) {
  36353. if (connectNulls) {
  36354. idx += dir;
  36355. continue;
  36356. }
  36357. break;
  36358. }
  36359. if (idx === start) {
  36360. ctx[dir > 0 ? 'moveTo' : 'lineTo'](x, y);
  36361. cpx0 = x;
  36362. cpy0 = y;
  36363. } else {
  36364. var dx = x - prevX;
  36365. var dy = y - prevY;
  36366. // Ignore tiny segment.
  36367. if (dx * dx + dy * dy < 0.5) {
  36368. idx += dir;
  36369. continue;
  36370. }
  36371. if (smooth > 0) {
  36372. var nextIdx = idx + dir;
  36373. var nextX = points[nextIdx * 2];
  36374. var nextY = points[nextIdx * 2 + 1];
  36375. // Ignore duplicate point
  36376. while (nextX === x && nextY === y && k < segLen) {
  36377. k++;
  36378. nextIdx += dir;
  36379. idx += dir;
  36380. nextX = points[nextIdx * 2];
  36381. nextY = points[nextIdx * 2 + 1];
  36382. x = points[idx * 2];
  36383. y = points[idx * 2 + 1];
  36384. dx = x - prevX;
  36385. dy = y - prevY;
  36386. }
  36387. var tmpK = k + 1;
  36388. if (connectNulls) {
  36389. // Find next point not null
  36390. while (isPointNull(nextX, nextY) && tmpK < segLen) {
  36391. tmpK++;
  36392. nextIdx += dir;
  36393. nextX = points[nextIdx * 2];
  36394. nextY = points[nextIdx * 2 + 1];
  36395. }
  36396. }
  36397. var ratioNextSeg = 0.5;
  36398. var vx = 0;
  36399. var vy = 0;
  36400. var nextCpx0 = void 0;
  36401. var nextCpy0 = void 0;
  36402. // Is last point
  36403. if (tmpK >= segLen || isPointNull(nextX, nextY)) {
  36404. cpx1 = x;
  36405. cpy1 = y;
  36406. } else {
  36407. vx = nextX - prevX;
  36408. vy = nextY - prevY;
  36409. var dx0 = x - prevX;
  36410. var dx1 = nextX - x;
  36411. var dy0 = y - prevY;
  36412. var dy1 = nextY - y;
  36413. var lenPrevSeg = void 0;
  36414. var lenNextSeg = void 0;
  36415. if (smoothMonotone === 'x') {
  36416. lenPrevSeg = Math.abs(dx0);
  36417. lenNextSeg = Math.abs(dx1);
  36418. var dir_1 = vx > 0 ? 1 : -1;
  36419. cpx1 = x - dir_1 * lenPrevSeg * smooth;
  36420. cpy1 = y;
  36421. nextCpx0 = x + dir_1 * lenNextSeg * smooth;
  36422. nextCpy0 = y;
  36423. } else if (smoothMonotone === 'y') {
  36424. lenPrevSeg = Math.abs(dy0);
  36425. lenNextSeg = Math.abs(dy1);
  36426. var dir_2 = vy > 0 ? 1 : -1;
  36427. cpx1 = x;
  36428. cpy1 = y - dir_2 * lenPrevSeg * smooth;
  36429. nextCpx0 = x;
  36430. nextCpy0 = y + dir_2 * lenNextSeg * smooth;
  36431. } else {
  36432. lenPrevSeg = Math.sqrt(dx0 * dx0 + dy0 * dy0);
  36433. lenNextSeg = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  36434. // Use ratio of seg length
  36435. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  36436. cpx1 = x - vx * smooth * (1 - ratioNextSeg);
  36437. cpy1 = y - vy * smooth * (1 - ratioNextSeg);
  36438. // cp0 of next segment
  36439. nextCpx0 = x + vx * smooth * ratioNextSeg;
  36440. nextCpy0 = y + vy * smooth * ratioNextSeg;
  36441. // Smooth constraint between point and next point.
  36442. // Avoid exceeding extreme after smoothing.
  36443. nextCpx0 = mathMin$6(nextCpx0, mathMax$6(nextX, x));
  36444. nextCpy0 = mathMin$6(nextCpy0, mathMax$6(nextY, y));
  36445. nextCpx0 = mathMax$6(nextCpx0, mathMin$6(nextX, x));
  36446. nextCpy0 = mathMax$6(nextCpy0, mathMin$6(nextY, y));
  36447. // Reclaculate cp1 based on the adjusted cp0 of next seg.
  36448. vx = nextCpx0 - x;
  36449. vy = nextCpy0 - y;
  36450. cpx1 = x - vx * lenPrevSeg / lenNextSeg;
  36451. cpy1 = y - vy * lenPrevSeg / lenNextSeg;
  36452. // Smooth constraint between point and prev point.
  36453. // Avoid exceeding extreme after smoothing.
  36454. cpx1 = mathMin$6(cpx1, mathMax$6(prevX, x));
  36455. cpy1 = mathMin$6(cpy1, mathMax$6(prevY, y));
  36456. cpx1 = mathMax$6(cpx1, mathMin$6(prevX, x));
  36457. cpy1 = mathMax$6(cpy1, mathMin$6(prevY, y));
  36458. // Adjust next cp0 again.
  36459. vx = x - cpx1;
  36460. vy = y - cpy1;
  36461. nextCpx0 = x + vx * lenNextSeg / lenPrevSeg;
  36462. nextCpy0 = y + vy * lenNextSeg / lenPrevSeg;
  36463. }
  36464. }
  36465. ctx.bezierCurveTo(cpx0, cpy0, cpx1, cpy1, x, y);
  36466. cpx0 = nextCpx0;
  36467. cpy0 = nextCpy0;
  36468. } else {
  36469. ctx.lineTo(x, y);
  36470. }
  36471. }
  36472. prevX = x;
  36473. prevY = y;
  36474. idx += dir;
  36475. }
  36476. return k;
  36477. }
  36478. var ECPolylineShape = /** @class */function () {
  36479. function ECPolylineShape() {
  36480. this.smooth = 0;
  36481. this.smoothConstraint = true;
  36482. }
  36483. return ECPolylineShape;
  36484. }();
  36485. var ECPolyline = /** @class */function (_super) {
  36486. __extends(ECPolyline, _super);
  36487. function ECPolyline(opts) {
  36488. var _this = _super.call(this, opts) || this;
  36489. _this.type = 'ec-polyline';
  36490. return _this;
  36491. }
  36492. ECPolyline.prototype.getDefaultStyle = function () {
  36493. return {
  36494. stroke: tokens.color.neutral99,
  36495. fill: null
  36496. };
  36497. };
  36498. ECPolyline.prototype.getDefaultShape = function () {
  36499. return new ECPolylineShape();
  36500. };
  36501. ECPolyline.prototype.buildPath = function (ctx, shape) {
  36502. var points = shape.points;
  36503. var i = 0;
  36504. var len = points.length / 2;
  36505. // const result = getBoundingBox(points, shape.smoothConstraint);
  36506. if (shape.connectNulls) {
  36507. // Must remove first and last null values avoid draw error in polygon
  36508. for (; len > 0; len--) {
  36509. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  36510. break;
  36511. }
  36512. }
  36513. for (; i < len; i++) {
  36514. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  36515. break;
  36516. }
  36517. }
  36518. }
  36519. while (i < len) {
  36520. i += drawSegment(ctx, points, i, len, len, 1, shape.smooth, shape.smoothMonotone, shape.connectNulls) + 1;
  36521. }
  36522. };
  36523. ECPolyline.prototype.getPointOn = function (xOrY, dim) {
  36524. if (!this.path) {
  36525. this.createPathProxy();
  36526. this.buildPath(this.path, this.shape);
  36527. }
  36528. var path = this.path;
  36529. var data = path.data;
  36530. var CMD = PathProxy.CMD;
  36531. var x0;
  36532. var y0;
  36533. var isDimX = dim === 'x';
  36534. var roots = [];
  36535. for (var i = 0; i < data.length;) {
  36536. var cmd = data[i++];
  36537. var x = void 0;
  36538. var y = void 0;
  36539. var x2 = void 0;
  36540. var y2 = void 0;
  36541. var x3 = void 0;
  36542. var y3 = void 0;
  36543. var t = void 0;
  36544. switch (cmd) {
  36545. case CMD.M:
  36546. x0 = data[i++];
  36547. y0 = data[i++];
  36548. break;
  36549. case CMD.L:
  36550. x = data[i++];
  36551. y = data[i++];
  36552. t = isDimX ? (xOrY - x0) / (x - x0) : (xOrY - y0) / (y - y0);
  36553. if (t <= 1 && t >= 0) {
  36554. var val = isDimX ? (y - y0) * t + y0 : (x - x0) * t + x0;
  36555. return isDimX ? [xOrY, val] : [val, xOrY];
  36556. }
  36557. x0 = x;
  36558. y0 = y;
  36559. break;
  36560. case CMD.C:
  36561. x = data[i++];
  36562. y = data[i++];
  36563. x2 = data[i++];
  36564. y2 = data[i++];
  36565. x3 = data[i++];
  36566. y3 = data[i++];
  36567. var nRoot = isDimX ? cubicRootAt(x0, x, x2, x3, xOrY, roots) : cubicRootAt(y0, y, y2, y3, xOrY, roots);
  36568. if (nRoot > 0) {
  36569. for (var i_1 = 0; i_1 < nRoot; i_1++) {
  36570. var t_1 = roots[i_1];
  36571. if (t_1 <= 1 && t_1 >= 0) {
  36572. var val = isDimX ? cubicAt(y0, y, y2, y3, t_1) : cubicAt(x0, x, x2, x3, t_1);
  36573. return isDimX ? [xOrY, val] : [val, xOrY];
  36574. }
  36575. }
  36576. }
  36577. x0 = x3;
  36578. y0 = y3;
  36579. break;
  36580. }
  36581. }
  36582. };
  36583. return ECPolyline;
  36584. }(Path);
  36585. var ECPolygonShape = /** @class */function (_super) {
  36586. __extends(ECPolygonShape, _super);
  36587. function ECPolygonShape() {
  36588. return _super !== null && _super.apply(this, arguments) || this;
  36589. }
  36590. return ECPolygonShape;
  36591. }(ECPolylineShape);
  36592. var ECPolygon = /** @class */function (_super) {
  36593. __extends(ECPolygon, _super);
  36594. function ECPolygon(opts) {
  36595. var _this = _super.call(this, opts) || this;
  36596. _this.type = 'ec-polygon';
  36597. return _this;
  36598. }
  36599. ECPolygon.prototype.getDefaultShape = function () {
  36600. return new ECPolygonShape();
  36601. };
  36602. ECPolygon.prototype.buildPath = function (ctx, shape) {
  36603. var points = shape.points;
  36604. var stackedOnPoints = shape.stackedOnPoints;
  36605. var i = 0;
  36606. var len = points.length / 2;
  36607. var smoothMonotone = shape.smoothMonotone;
  36608. if (shape.connectNulls) {
  36609. // Must remove first and last null values avoid draw error in polygon
  36610. for (; len > 0; len--) {
  36611. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  36612. break;
  36613. }
  36614. }
  36615. for (; i < len; i++) {
  36616. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  36617. break;
  36618. }
  36619. }
  36620. }
  36621. while (i < len) {
  36622. var k = drawSegment(ctx, points, i, len, len, 1, shape.smooth, smoothMonotone, shape.connectNulls);
  36623. drawSegment(ctx, stackedOnPoints, i + k - 1, k, len, -1, shape.stackedOnSmooth, smoothMonotone, shape.connectNulls);
  36624. i += k + 1;
  36625. ctx.closePath();
  36626. }
  36627. };
  36628. return ECPolygon;
  36629. }(Path);
  36630. function createGridClipPath(cartesian, hasAnimation, seriesModel, done, during) {
  36631. var rect = cartesian.getArea();
  36632. var x = rect.x;
  36633. var y = rect.y;
  36634. var width = rect.width;
  36635. var height = rect.height;
  36636. var lineWidth = seriesModel.get(['lineStyle', 'width']) || 0;
  36637. // Expand the clip path a bit to avoid the border is clipped and looks thinner
  36638. x -= lineWidth / 2;
  36639. y -= lineWidth / 2;
  36640. width += lineWidth;
  36641. height += lineWidth;
  36642. // fix: https://github.com/apache/incubator-echarts/issues/11369
  36643. width = Math.ceil(width);
  36644. if (x !== Math.floor(x)) {
  36645. x = Math.floor(x);
  36646. // if no extra 1px on `width`, it will still be clipped since `x` is floored
  36647. width++;
  36648. }
  36649. var clipPath = new Rect({
  36650. shape: {
  36651. x: x,
  36652. y: y,
  36653. width: width,
  36654. height: height
  36655. }
  36656. });
  36657. if (hasAnimation) {
  36658. var baseAxis = cartesian.getBaseAxis();
  36659. var isHorizontal = baseAxis.isHorizontal();
  36660. var isAxisInversed = baseAxis.inverse;
  36661. if (isHorizontal) {
  36662. if (isAxisInversed) {
  36663. clipPath.shape.x += width;
  36664. }
  36665. clipPath.shape.width = 0;
  36666. } else {
  36667. if (!isAxisInversed) {
  36668. clipPath.shape.y += height;
  36669. }
  36670. clipPath.shape.height = 0;
  36671. }
  36672. var duringCb = isFunction(during) ? function (percent) {
  36673. during(percent, clipPath);
  36674. } : null;
  36675. initProps(clipPath, {
  36676. shape: {
  36677. width: width,
  36678. height: height,
  36679. x: x,
  36680. y: y
  36681. }
  36682. }, seriesModel, null, done, duringCb);
  36683. }
  36684. return clipPath;
  36685. }
  36686. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  36687. var sectorArea = polar.getArea();
  36688. // Avoid float number rounding error for symbol on the edge of axis extent.
  36689. var r0 = round(sectorArea.r0, 1);
  36690. var r = round(sectorArea.r, 1);
  36691. var clipPath = new Sector({
  36692. shape: {
  36693. cx: round(polar.cx, 1),
  36694. cy: round(polar.cy, 1),
  36695. r0: r0,
  36696. r: r,
  36697. startAngle: sectorArea.startAngle,
  36698. endAngle: sectorArea.endAngle,
  36699. clockwise: sectorArea.clockwise
  36700. }
  36701. });
  36702. if (hasAnimation) {
  36703. var isRadial = polar.getBaseAxis().dim === 'angle';
  36704. if (isRadial) {
  36705. clipPath.shape.endAngle = sectorArea.startAngle;
  36706. } else {
  36707. clipPath.shape.r = r0;
  36708. }
  36709. initProps(clipPath, {
  36710. shape: {
  36711. endAngle: sectorArea.endAngle,
  36712. r: r
  36713. }
  36714. }, seriesModel);
  36715. }
  36716. return clipPath;
  36717. }
  36718. function createClipPath(coordSys, hasAnimation, seriesModel, done, during) {
  36719. if (!coordSys) {
  36720. return null;
  36721. } else if (coordSys.type === 'polar') {
  36722. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  36723. } else if (coordSys.type === 'cartesian2d') {
  36724. return createGridClipPath(coordSys, hasAnimation, seriesModel, done, during);
  36725. }
  36726. return null;
  36727. }
  36728. /*
  36729. * Licensed to the Apache Software Foundation (ASF) under one
  36730. * or more contributor license agreements. See the NOTICE file
  36731. * distributed with this work for additional information
  36732. * regarding copyright ownership. The ASF licenses this file
  36733. * to you under the Apache License, Version 2.0 (the
  36734. * "License"); you may not use this file except in compliance
  36735. * with the License. You may obtain a copy of the License at
  36736. *
  36737. * http://www.apache.org/licenses/LICENSE-2.0
  36738. *
  36739. * Unless required by applicable law or agreed to in writing,
  36740. * software distributed under the License is distributed on an
  36741. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36742. * KIND, either express or implied. See the License for the
  36743. * specific language governing permissions and limitations
  36744. * under the License.
  36745. */
  36746. /**
  36747. * AUTO-GENERATED FILE. DO NOT MODIFY.
  36748. */
  36749. /*
  36750. * Licensed to the Apache Software Foundation (ASF) under one
  36751. * or more contributor license agreements. See the NOTICE file
  36752. * distributed with this work for additional information
  36753. * regarding copyright ownership. The ASF licenses this file
  36754. * to you under the Apache License, Version 2.0 (the
  36755. * "License"); you may not use this file except in compliance
  36756. * with the License. You may obtain a copy of the License at
  36757. *
  36758. * http://www.apache.org/licenses/LICENSE-2.0
  36759. *
  36760. * Unless required by applicable law or agreed to in writing,
  36761. * software distributed under the License is distributed on an
  36762. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36763. * KIND, either express or implied. See the License for the
  36764. * specific language governing permissions and limitations
  36765. * under the License.
  36766. */
  36767. function isCoordinateSystemType(coordSys, type) {
  36768. return coordSys.type === type;
  36769. }
  36770. function isPointsSame(points1, points2) {
  36771. if (points1.length !== points2.length) {
  36772. return;
  36773. }
  36774. for (var i = 0; i < points1.length; i++) {
  36775. if (points1[i] !== points2[i]) {
  36776. return;
  36777. }
  36778. }
  36779. return true;
  36780. }
  36781. function bboxFromPoints(points) {
  36782. var minX = Infinity;
  36783. var minY = Infinity;
  36784. var maxX = -Infinity;
  36785. var maxY = -Infinity;
  36786. for (var i = 0; i < points.length;) {
  36787. var x = points[i++];
  36788. var y = points[i++];
  36789. if (!isNaN(x)) {
  36790. minX = Math.min(x, minX);
  36791. maxX = Math.max(x, maxX);
  36792. }
  36793. if (!isNaN(y)) {
  36794. minY = Math.min(y, minY);
  36795. maxY = Math.max(y, maxY);
  36796. }
  36797. }
  36798. return [[minX, minY], [maxX, maxY]];
  36799. }
  36800. function getBoundingDiff(points1, points2) {
  36801. var _a = bboxFromPoints(points1),
  36802. min1 = _a[0],
  36803. max1 = _a[1];
  36804. var _b = bboxFromPoints(points2),
  36805. min2 = _b[0],
  36806. max2 = _b[1];
  36807. // Get a max value from each corner of two boundings.
  36808. return Math.max(Math.abs(min1[0] - min2[0]), Math.abs(min1[1] - min2[1]), Math.abs(max1[0] - max2[0]), Math.abs(max1[1] - max2[1]));
  36809. }
  36810. function getSmooth(smooth) {
  36811. return isNumber(smooth) ? smooth : smooth ? 0.5 : 0;
  36812. }
  36813. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  36814. if (!dataCoordInfo.valueDim) {
  36815. return [];
  36816. }
  36817. var len = data.count();
  36818. var points = createFloat32Array(len * 2);
  36819. for (var idx = 0; idx < len; idx++) {
  36820. var pt = getStackedOnPoint(dataCoordInfo, coordSys, data, idx);
  36821. points[idx * 2] = pt[0];
  36822. points[idx * 2 + 1] = pt[1];
  36823. }
  36824. return points;
  36825. }
  36826. /**
  36827. * Filter the null data and extend data for step considering `stepTurnAt`
  36828. *
  36829. * @param points data to convert, that may containing null
  36830. * @param basePoints base data to reference, used only for areaStyle points
  36831. * @param coordSys coordinate system
  36832. * @param stepTurnAt 'start' | 'end' | 'middle' | true
  36833. * @param connectNulls whether to connect nulls
  36834. * @returns converted point positions
  36835. */
  36836. function turnPointsIntoStep(points, basePoints, coordSys, stepTurnAt, connectNulls) {
  36837. var baseAxis = coordSys.getBaseAxis();
  36838. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  36839. var stepPoints = [];
  36840. var i = 0;
  36841. var stepPt = [];
  36842. var pt = [];
  36843. var nextPt = [];
  36844. var filteredPoints = [];
  36845. if (connectNulls) {
  36846. for (i = 0; i < points.length; i += 2) {
  36847. /**
  36848. * For areaStyle of stepped lines, `stackedOnPoints` should be
  36849. * filtered the same as `points` so that the base axis values
  36850. * should stay the same as the lines above. See #20021
  36851. */
  36852. var reference = basePoints || points;
  36853. if (!isNaN(reference[i]) && !isNaN(reference[i + 1])) {
  36854. filteredPoints.push(points[i], points[i + 1]);
  36855. }
  36856. }
  36857. points = filteredPoints;
  36858. }
  36859. for (i = 0; i < points.length - 2; i += 2) {
  36860. nextPt[0] = points[i + 2];
  36861. nextPt[1] = points[i + 3];
  36862. pt[0] = points[i];
  36863. pt[1] = points[i + 1];
  36864. stepPoints.push(pt[0], pt[1]);
  36865. switch (stepTurnAt) {
  36866. case 'end':
  36867. stepPt[baseIndex] = nextPt[baseIndex];
  36868. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  36869. stepPoints.push(stepPt[0], stepPt[1]);
  36870. break;
  36871. case 'middle':
  36872. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  36873. var stepPt2 = [];
  36874. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  36875. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  36876. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  36877. stepPoints.push(stepPt[0], stepPt[1]);
  36878. stepPoints.push(stepPt2[0], stepPt2[1]);
  36879. break;
  36880. default:
  36881. // default is start
  36882. stepPt[baseIndex] = pt[baseIndex];
  36883. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  36884. stepPoints.push(stepPt[0], stepPt[1]);
  36885. }
  36886. }
  36887. // Last points
  36888. stepPoints.push(points[i++], points[i++]);
  36889. return stepPoints;
  36890. }
  36891. /**
  36892. * Clip color stops to edge. Avoid creating too large gradients.
  36893. * Which may lead to blurry when GPU acceleration is enabled. See #15680
  36894. *
  36895. * The stops has been sorted from small to large.
  36896. */
  36897. function clipColorStops(colorStops, maxSize) {
  36898. var newColorStops = [];
  36899. var len = colorStops.length;
  36900. // coord will always < 0 in prevOutOfRangeColorStop.
  36901. var prevOutOfRangeColorStop;
  36902. var prevInRangeColorStop;
  36903. function lerpStop(stop0, stop1, clippedCoord) {
  36904. var coord0 = stop0.coord;
  36905. var p = (clippedCoord - coord0) / (stop1.coord - coord0);
  36906. var color = lerp$1(p, [stop0.color, stop1.color]);
  36907. return {
  36908. coord: clippedCoord,
  36909. color: color
  36910. };
  36911. }
  36912. for (var i = 0; i < len; i++) {
  36913. var stop_1 = colorStops[i];
  36914. var coord = stop_1.coord;
  36915. if (coord < 0) {
  36916. prevOutOfRangeColorStop = stop_1;
  36917. } else if (coord > maxSize) {
  36918. if (prevInRangeColorStop) {
  36919. newColorStops.push(lerpStop(prevInRangeColorStop, stop_1, maxSize));
  36920. } else if (prevOutOfRangeColorStop) {
  36921. // If there are two stops and coord range is between these two stops
  36922. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0), lerpStop(prevOutOfRangeColorStop, stop_1, maxSize));
  36923. }
  36924. // All following stop will be out of range. So just ignore them.
  36925. break;
  36926. } else {
  36927. if (prevOutOfRangeColorStop) {
  36928. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0));
  36929. // Reset
  36930. prevOutOfRangeColorStop = null;
  36931. }
  36932. newColorStops.push(stop_1);
  36933. prevInRangeColorStop = stop_1;
  36934. }
  36935. }
  36936. return newColorStops;
  36937. }
  36938. function getVisualGradient(data, coordSys, api) {
  36939. var visualMetaList = data.getVisual('visualMeta');
  36940. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  36941. // When data.count() is 0, gradient range can not be calculated.
  36942. return;
  36943. }
  36944. if (coordSys.type !== 'cartesian2d') {
  36945. if ("development" !== 'production') {
  36946. console.warn('Visual map on line style is only supported on cartesian2d.');
  36947. }
  36948. return;
  36949. }
  36950. var coordDim;
  36951. var visualMeta;
  36952. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  36953. var dimInfo = data.getDimensionInfo(visualMetaList[i].dimension);
  36954. coordDim = dimInfo && dimInfo.coordDim;
  36955. // Can only be x or y
  36956. if (coordDim === 'x' || coordDim === 'y') {
  36957. visualMeta = visualMetaList[i];
  36958. break;
  36959. }
  36960. }
  36961. if (!visualMeta) {
  36962. if ("development" !== 'production') {
  36963. console.warn('Visual map on line style only support x or y dimension.');
  36964. }
  36965. return;
  36966. }
  36967. // If the area to be rendered is bigger than area defined by LinearGradient,
  36968. // the canvas spec prescribes that the color of the first stop and the last
  36969. // stop should be used. But if two stops are added at offset 0, in effect
  36970. // browsers use the color of the second stop to render area outside
  36971. // LinearGradient. So we can only infinitesimally extend area defined in
  36972. // LinearGradient to render `outerColors`.
  36973. var axis = coordSys.getAxis(coordDim);
  36974. // dataToCoord mapping may not be linear, but must be monotonic.
  36975. var colorStops = map(visualMeta.stops, function (stop) {
  36976. // offset will be calculated later.
  36977. return {
  36978. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  36979. color: stop.color
  36980. };
  36981. });
  36982. var stopLen = colorStops.length;
  36983. var outerColors = visualMeta.outerColors.slice();
  36984. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  36985. colorStops.reverse();
  36986. outerColors.reverse();
  36987. }
  36988. var colorStopsInRange = clipColorStops(colorStops, coordDim === 'x' ? api.getWidth() : api.getHeight());
  36989. var inRangeStopLen = colorStopsInRange.length;
  36990. if (!inRangeStopLen && stopLen) {
  36991. // All stops are out of range. All will be the same color.
  36992. return colorStops[0].coord < 0 ? outerColors[1] ? outerColors[1] : colorStops[stopLen - 1].color : outerColors[0] ? outerColors[0] : colorStops[0].color;
  36993. }
  36994. var tinyExtent = 10; // Arbitrary value: 10px
  36995. var minCoord = colorStopsInRange[0].coord - tinyExtent;
  36996. var maxCoord = colorStopsInRange[inRangeStopLen - 1].coord + tinyExtent;
  36997. var coordSpan = maxCoord - minCoord;
  36998. if (coordSpan < 1e-3) {
  36999. return 'transparent';
  37000. }
  37001. each(colorStopsInRange, function (stop) {
  37002. stop.offset = (stop.coord - minCoord) / coordSpan;
  37003. });
  37004. colorStopsInRange.push({
  37005. // NOTE: inRangeStopLen may still be 0 if stoplen is zero.
  37006. offset: inRangeStopLen ? colorStopsInRange[inRangeStopLen - 1].offset : 0.5,
  37007. color: outerColors[1] || 'transparent'
  37008. });
  37009. colorStopsInRange.unshift({
  37010. offset: inRangeStopLen ? colorStopsInRange[0].offset : 0.5,
  37011. color: outerColors[0] || 'transparent'
  37012. });
  37013. var gradient = new LinearGradient(0, 0, 0, 0, colorStopsInRange, true);
  37014. gradient[coordDim] = minCoord;
  37015. gradient[coordDim + '2'] = maxCoord;
  37016. return gradient;
  37017. }
  37018. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  37019. var showAllSymbol = seriesModel.get('showAllSymbol');
  37020. var isAuto = showAllSymbol === 'auto';
  37021. if (showAllSymbol && !isAuto) {
  37022. return;
  37023. }
  37024. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  37025. if (!categoryAxis) {
  37026. return;
  37027. }
  37028. // Note that category label interval strategy might bring some weird effect
  37029. // in some scenario: users may wonder why some of the symbols are not
  37030. // displayed. So we show all symbols as possible as we can.
  37031. if (isAuto
  37032. // Simplify the logic, do not determine label overlap here.
  37033. && canShowAllSymbolForCategory(categoryAxis, data)) {
  37034. return;
  37035. }
  37036. // Otherwise follow the label interval strategy on category axis.
  37037. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  37038. var labelMap = {};
  37039. each(categoryAxis.getViewLabels(), function (labelItem) {
  37040. var ordinalNumber = categoryAxis.scale.getRawOrdinalNumber(labelItem.tickValue);
  37041. labelMap[ordinalNumber] = 1;
  37042. });
  37043. return function (dataIndex) {
  37044. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  37045. };
  37046. }
  37047. function canShowAllSymbolForCategory(categoryAxis, data) {
  37048. // In most cases, line is monotonous on category axis, and the label size
  37049. // is close with each other. So we check the symbol size and some of the
  37050. // label size alone with the category axis to estimate whether all symbol
  37051. // can be shown without overlap.
  37052. var axisExtent = categoryAxis.getExtent();
  37053. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  37054. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  37055. // Sampling some points, max 5.
  37056. var dataLen = data.count();
  37057. var step = Math.max(1, Math.round(dataLen / 5));
  37058. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  37059. if (Symbol.getSymbolSize(data, dataIndex
  37060. // Only for cartesian, where `isHorizontal` exists.
  37061. )[categoryAxis.isHorizontal() ? 1 : 0]
  37062. // Empirical number
  37063. * 1.5 > availSize) {
  37064. return false;
  37065. }
  37066. }
  37067. return true;
  37068. }
  37069. function isPointNull$1(x, y) {
  37070. return isNaN(x) || isNaN(y);
  37071. }
  37072. function getLastIndexNotNull(points) {
  37073. var len = points.length / 2;
  37074. for (; len > 0; len--) {
  37075. if (!isPointNull$1(points[len * 2 - 2], points[len * 2 - 1])) {
  37076. break;
  37077. }
  37078. }
  37079. return len - 1;
  37080. }
  37081. function getPointAtIndex(points, idx) {
  37082. return [points[idx * 2], points[idx * 2 + 1]];
  37083. }
  37084. function getIndexRange(points, xOrY, dim) {
  37085. var len = points.length / 2;
  37086. var dimIdx = dim === 'x' ? 0 : 1;
  37087. var a;
  37088. var b;
  37089. var prevIndex = 0;
  37090. var nextIndex = -1;
  37091. for (var i = 0; i < len; i++) {
  37092. b = points[i * 2 + dimIdx];
  37093. if (isNaN(b) || isNaN(points[i * 2 + 1 - dimIdx])) {
  37094. continue;
  37095. }
  37096. if (i === 0) {
  37097. a = b;
  37098. continue;
  37099. }
  37100. if (a <= xOrY && b >= xOrY || a >= xOrY && b <= xOrY) {
  37101. nextIndex = i;
  37102. break;
  37103. }
  37104. prevIndex = i;
  37105. a = b;
  37106. }
  37107. return {
  37108. range: [prevIndex, nextIndex],
  37109. t: (xOrY - a) / (b - a)
  37110. };
  37111. }
  37112. function anyStateShowEndLabel(seriesModel) {
  37113. if (seriesModel.get(['endLabel', 'show'])) {
  37114. return true;
  37115. }
  37116. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  37117. if (seriesModel.get([SPECIAL_STATES[i], 'endLabel', 'show'])) {
  37118. return true;
  37119. }
  37120. }
  37121. return false;
  37122. }
  37123. function createLineClipPath(lineView, coordSys, hasAnimation, seriesModel) {
  37124. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  37125. var endLabelModel_1 = seriesModel.getModel('endLabel');
  37126. var valueAnimation_1 = endLabelModel_1.get('valueAnimation');
  37127. var data_1 = seriesModel.getData();
  37128. var labelAnimationRecord_1 = {
  37129. lastFrameIndex: 0
  37130. };
  37131. var during = anyStateShowEndLabel(seriesModel) ? function (percent, clipRect) {
  37132. lineView._endLabelOnDuring(percent, clipRect, data_1, labelAnimationRecord_1, valueAnimation_1, endLabelModel_1, coordSys);
  37133. } : null;
  37134. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  37135. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, function () {
  37136. var endLabel = lineView._endLabel;
  37137. if (endLabel && hasAnimation) {
  37138. if (labelAnimationRecord_1.originalX != null) {
  37139. endLabel.attr({
  37140. x: labelAnimationRecord_1.originalX,
  37141. y: labelAnimationRecord_1.originalY
  37142. });
  37143. }
  37144. }
  37145. }, during);
  37146. // Expand clip shape to avoid clipping when line value exceeds axis
  37147. if (!seriesModel.get('clip', true)) {
  37148. var rectShape = clipPath.shape;
  37149. var expandSize = Math.max(rectShape.width, rectShape.height);
  37150. if (isHorizontal) {
  37151. rectShape.y -= expandSize;
  37152. rectShape.height += expandSize * 2;
  37153. } else {
  37154. rectShape.x -= expandSize;
  37155. rectShape.width += expandSize * 2;
  37156. }
  37157. }
  37158. // Set to the final frame. To make sure label layout is right.
  37159. if (during) {
  37160. during(1, clipPath);
  37161. }
  37162. return clipPath;
  37163. } else {
  37164. if ("development" !== 'production') {
  37165. if (seriesModel.get(['endLabel', 'show'])) {
  37166. console.warn('endLabel is not supported for lines in polar systems.');
  37167. }
  37168. }
  37169. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  37170. }
  37171. }
  37172. function getEndLabelStateSpecified(endLabelModel, coordSys) {
  37173. var baseAxis = coordSys.getBaseAxis();
  37174. var isHorizontal = baseAxis.isHorizontal();
  37175. var isBaseInversed = baseAxis.inverse;
  37176. var align = isHorizontal ? isBaseInversed ? 'right' : 'left' : 'center';
  37177. var verticalAlign = isHorizontal ? 'middle' : isBaseInversed ? 'top' : 'bottom';
  37178. return {
  37179. normal: {
  37180. align: endLabelModel.get('align') || align,
  37181. verticalAlign: endLabelModel.get('verticalAlign') || verticalAlign
  37182. }
  37183. };
  37184. }
  37185. var LineView = /** @class */function (_super) {
  37186. __extends(LineView, _super);
  37187. function LineView() {
  37188. return _super !== null && _super.apply(this, arguments) || this;
  37189. }
  37190. LineView.prototype.init = function () {
  37191. var lineGroup = new Group();
  37192. var symbolDraw = new SymbolDraw();
  37193. this.group.add(symbolDraw.group);
  37194. this._symbolDraw = symbolDraw;
  37195. this._lineGroup = lineGroup;
  37196. this._changePolyState = bind(this._changePolyState, this);
  37197. };
  37198. LineView.prototype.render = function (seriesModel, ecModel, api) {
  37199. var coordSys = seriesModel.coordinateSystem;
  37200. var group = this.group;
  37201. var data = seriesModel.getData();
  37202. var lineStyleModel = seriesModel.getModel('lineStyle');
  37203. var areaStyleModel = seriesModel.getModel('areaStyle');
  37204. var points = data.getLayout('points') || [];
  37205. var isCoordSysPolar = coordSys.type === 'polar';
  37206. var prevCoordSys = this._coordSys;
  37207. var symbolDraw = this._symbolDraw;
  37208. var polyline = this._polyline;
  37209. var polygon = this._polygon;
  37210. var lineGroup = this._lineGroup;
  37211. var hasAnimation = !ecModel.ssr && seriesModel.get('animation');
  37212. var isAreaChart = !areaStyleModel.isEmpty();
  37213. var valueOrigin = areaStyleModel.get('origin');
  37214. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  37215. var stackedOnPoints = isAreaChart && getStackedOnPoints(coordSys, data, dataCoordInfo);
  37216. var showSymbol = seriesModel.get('showSymbol');
  37217. var connectNulls = seriesModel.get('connectNulls');
  37218. var isIgnoreFunc = showSymbol && !isCoordSysPolar && getIsIgnoreFunc(seriesModel, data, coordSys);
  37219. // Remove temporary symbols
  37220. var oldData = this._data;
  37221. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  37222. if (el.__temp) {
  37223. group.remove(el);
  37224. oldData.setItemGraphicEl(idx, null);
  37225. }
  37226. });
  37227. // Remove previous created symbols if showSymbol changed to false
  37228. if (!showSymbol) {
  37229. symbolDraw.remove();
  37230. }
  37231. group.add(lineGroup);
  37232. // FIXME step not support polar
  37233. var step = !isCoordSysPolar ? seriesModel.get('step') : false;
  37234. var clipShapeForSymbol;
  37235. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  37236. clipShapeForSymbol = coordSys.getArea();
  37237. // Avoid float number rounding error for symbol on the edge of axis extent.
  37238. // See #7913 and `test/dataZoom-clip.html`.
  37239. if (clipShapeForSymbol.width != null) {
  37240. clipShapeForSymbol.x -= 0.1;
  37241. clipShapeForSymbol.y -= 0.1;
  37242. clipShapeForSymbol.width += 0.2;
  37243. clipShapeForSymbol.height += 0.2;
  37244. } else if (clipShapeForSymbol.r0) {
  37245. clipShapeForSymbol.r0 -= 0.5;
  37246. clipShapeForSymbol.r += 0.5;
  37247. }
  37248. }
  37249. this._clipShapeForSymbol = clipShapeForSymbol;
  37250. var visualColor = getVisualGradient(data, coordSys, api) || data.getVisual('style')[data.getVisual('drawType')];
  37251. // Initialization animation or coordinate system changed
  37252. if (!(polyline && prevCoordSys.type === coordSys.type && step === this._step)) {
  37253. showSymbol && symbolDraw.updateData(data, {
  37254. isIgnore: isIgnoreFunc,
  37255. clipShape: clipShapeForSymbol,
  37256. disableAnimation: true,
  37257. getSymbolPoint: function (idx) {
  37258. return [points[idx * 2], points[idx * 2 + 1]];
  37259. }
  37260. });
  37261. hasAnimation && this._initSymbolLabelAnimation(data, coordSys, clipShapeForSymbol);
  37262. if (step) {
  37263. if (stackedOnPoints) {
  37264. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
  37265. }
  37266. // TODO If stacked series is not step
  37267. points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
  37268. }
  37269. polyline = this._newPolyline(points);
  37270. if (isAreaChart) {
  37271. polygon = this._newPolygon(points, stackedOnPoints);
  37272. } // If areaStyle is removed
  37273. else if (polygon) {
  37274. lineGroup.remove(polygon);
  37275. polygon = this._polygon = null;
  37276. }
  37277. // NOTE: Must update _endLabel before setClipPath.
  37278. if (!isCoordSysPolar) {
  37279. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  37280. }
  37281. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  37282. } else {
  37283. if (isAreaChart && !polygon) {
  37284. // If areaStyle is added
  37285. polygon = this._newPolygon(points, stackedOnPoints);
  37286. } else if (polygon && !isAreaChart) {
  37287. // If areaStyle is removed
  37288. lineGroup.remove(polygon);
  37289. polygon = this._polygon = null;
  37290. }
  37291. // NOTE: Must update _endLabel before setClipPath.
  37292. if (!isCoordSysPolar) {
  37293. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  37294. }
  37295. // Update clipPath
  37296. var oldClipPath = lineGroup.getClipPath();
  37297. if (oldClipPath) {
  37298. var newClipPath = createLineClipPath(this, coordSys, false, seriesModel);
  37299. initProps(oldClipPath, {
  37300. shape: newClipPath.shape
  37301. }, seriesModel);
  37302. } else {
  37303. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  37304. }
  37305. // Always update, or it is wrong in the case turning on legend
  37306. // because points are not changed.
  37307. showSymbol && symbolDraw.updateData(data, {
  37308. isIgnore: isIgnoreFunc,
  37309. clipShape: clipShapeForSymbol,
  37310. disableAnimation: true,
  37311. getSymbolPoint: function (idx) {
  37312. return [points[idx * 2], points[idx * 2 + 1]];
  37313. }
  37314. });
  37315. // In the case data zoom triggered refreshing frequently
  37316. // Data may not change if line has a category axis. So it should animate nothing.
  37317. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints) || !isPointsSame(this._points, points)) {
  37318. if (hasAnimation) {
  37319. this._doUpdateAnimation(data, stackedOnPoints, coordSys, api, step, valueOrigin, connectNulls);
  37320. } else {
  37321. // Not do it in update with animation
  37322. if (step) {
  37323. if (stackedOnPoints) {
  37324. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
  37325. }
  37326. // TODO If stacked series is not step
  37327. points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
  37328. }
  37329. polyline.setShape({
  37330. points: points
  37331. });
  37332. polygon && polygon.setShape({
  37333. points: points,
  37334. stackedOnPoints: stackedOnPoints
  37335. });
  37336. }
  37337. }
  37338. }
  37339. var emphasisModel = seriesModel.getModel('emphasis');
  37340. var focus = emphasisModel.get('focus');
  37341. var blurScope = emphasisModel.get('blurScope');
  37342. var emphasisDisabled = emphasisModel.get('disabled');
  37343. polyline.useStyle(defaults(
  37344. // Use color in lineStyle first
  37345. lineStyleModel.getLineStyle(), {
  37346. fill: 'none',
  37347. stroke: visualColor,
  37348. lineJoin: 'bevel'
  37349. }));
  37350. setStatesStylesFromModel(polyline, seriesModel, 'lineStyle');
  37351. if (polyline.style.lineWidth > 0 && seriesModel.get(['emphasis', 'lineStyle', 'width']) === 'bolder') {
  37352. var emphasisLineStyle = polyline.getState('emphasis').style;
  37353. emphasisLineStyle.lineWidth = +polyline.style.lineWidth + 1;
  37354. }
  37355. // Needs seriesIndex for focus
  37356. getECData(polyline).seriesIndex = seriesModel.seriesIndex;
  37357. toggleHoverEmphasis(polyline, focus, blurScope, emphasisDisabled);
  37358. var smooth = getSmooth(seriesModel.get('smooth'));
  37359. var smoothMonotone = seriesModel.get('smoothMonotone');
  37360. polyline.setShape({
  37361. smooth: smooth,
  37362. smoothMonotone: smoothMonotone,
  37363. connectNulls: connectNulls
  37364. });
  37365. if (polygon) {
  37366. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  37367. var stackedOnSmooth = 0;
  37368. polygon.useStyle(defaults(areaStyleModel.getAreaStyle(), {
  37369. fill: visualColor,
  37370. opacity: 0.7,
  37371. lineJoin: 'bevel',
  37372. decal: data.getVisual('style').decal
  37373. }));
  37374. if (stackedOnSeries) {
  37375. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  37376. }
  37377. polygon.setShape({
  37378. smooth: smooth,
  37379. stackedOnSmooth: stackedOnSmooth,
  37380. smoothMonotone: smoothMonotone,
  37381. connectNulls: connectNulls
  37382. });
  37383. setStatesStylesFromModel(polygon, seriesModel, 'areaStyle');
  37384. // Needs seriesIndex for focus
  37385. getECData(polygon).seriesIndex = seriesModel.seriesIndex;
  37386. toggleHoverEmphasis(polygon, focus, blurScope, emphasisDisabled);
  37387. }
  37388. var changePolyState = this._changePolyState;
  37389. data.eachItemGraphicEl(function (el) {
  37390. // Switch polyline / polygon state if element changed its state.
  37391. el && (el.onHoverStateChange = changePolyState);
  37392. });
  37393. this._polyline.onHoverStateChange = changePolyState;
  37394. this._data = data;
  37395. // Save the coordinate system for transition animation when data changed
  37396. this._coordSys = coordSys;
  37397. this._stackedOnPoints = stackedOnPoints;
  37398. this._points = points;
  37399. this._step = step;
  37400. this._valueOrigin = valueOrigin;
  37401. if (seriesModel.get('triggerLineEvent')) {
  37402. this.packEventData(seriesModel, polyline);
  37403. polygon && this.packEventData(seriesModel, polygon);
  37404. }
  37405. };
  37406. LineView.prototype.packEventData = function (seriesModel, el) {
  37407. getECData(el).eventData = {
  37408. componentType: 'series',
  37409. componentSubType: 'line',
  37410. componentIndex: seriesModel.componentIndex,
  37411. seriesIndex: seriesModel.seriesIndex,
  37412. seriesName: seriesModel.name,
  37413. seriesType: 'line'
  37414. };
  37415. };
  37416. LineView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  37417. var data = seriesModel.getData();
  37418. var dataIndex = queryDataIndex(data, payload);
  37419. this._changePolyState('emphasis');
  37420. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  37421. var points = data.getLayout('points');
  37422. var symbol = data.getItemGraphicEl(dataIndex);
  37423. if (!symbol) {
  37424. // Create a temporary symbol if it is not exists
  37425. var x = points[dataIndex * 2];
  37426. var y = points[dataIndex * 2 + 1];
  37427. if (isNaN(x) || isNaN(y)) {
  37428. // Null data
  37429. return;
  37430. }
  37431. // fix #11360: shouldn't draw symbol outside clipShapeForSymbol
  37432. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(x, y)) {
  37433. return;
  37434. }
  37435. var zlevel = seriesModel.get('zlevel') || 0;
  37436. var z = seriesModel.get('z') || 0;
  37437. symbol = new Symbol(data, dataIndex);
  37438. symbol.x = x;
  37439. symbol.y = y;
  37440. symbol.setZ(zlevel, z);
  37441. // ensure label text of the temporary symbol is in front of line and area polygon
  37442. var symbolLabel = symbol.getSymbolPath().getTextContent();
  37443. if (symbolLabel) {
  37444. symbolLabel.zlevel = zlevel;
  37445. symbolLabel.z = z;
  37446. symbolLabel.z2 = this._polyline.z2 + 1;
  37447. }
  37448. symbol.__temp = true;
  37449. data.setItemGraphicEl(dataIndex, symbol);
  37450. // Stop scale animation
  37451. symbol.stopSymbolAnimation(true);
  37452. this.group.add(symbol);
  37453. }
  37454. symbol.highlight();
  37455. } else {
  37456. // Highlight whole series
  37457. ChartView.prototype.highlight.call(this, seriesModel, ecModel, api, payload);
  37458. }
  37459. };
  37460. LineView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  37461. var data = seriesModel.getData();
  37462. var dataIndex = queryDataIndex(data, payload);
  37463. this._changePolyState('normal');
  37464. if (dataIndex != null && dataIndex >= 0) {
  37465. var symbol = data.getItemGraphicEl(dataIndex);
  37466. if (symbol) {
  37467. if (symbol.__temp) {
  37468. data.setItemGraphicEl(dataIndex, null);
  37469. this.group.remove(symbol);
  37470. } else {
  37471. symbol.downplay();
  37472. }
  37473. }
  37474. } else {
  37475. // FIXME
  37476. // can not downplay completely.
  37477. // Downplay whole series
  37478. ChartView.prototype.downplay.call(this, seriesModel, ecModel, api, payload);
  37479. }
  37480. };
  37481. LineView.prototype._changePolyState = function (toState) {
  37482. var polygon = this._polygon;
  37483. setStatesFlag(this._polyline, toState);
  37484. polygon && setStatesFlag(polygon, toState);
  37485. };
  37486. LineView.prototype._newPolyline = function (points) {
  37487. var polyline = this._polyline;
  37488. // Remove previous created polyline
  37489. if (polyline) {
  37490. this._lineGroup.remove(polyline);
  37491. }
  37492. polyline = new ECPolyline({
  37493. shape: {
  37494. points: points
  37495. },
  37496. segmentIgnoreThreshold: 2,
  37497. z2: 10
  37498. });
  37499. this._lineGroup.add(polyline);
  37500. this._polyline = polyline;
  37501. return polyline;
  37502. };
  37503. LineView.prototype._newPolygon = function (points, stackedOnPoints) {
  37504. var polygon = this._polygon;
  37505. // Remove previous created polygon
  37506. if (polygon) {
  37507. this._lineGroup.remove(polygon);
  37508. }
  37509. polygon = new ECPolygon({
  37510. shape: {
  37511. points: points,
  37512. stackedOnPoints: stackedOnPoints
  37513. },
  37514. segmentIgnoreThreshold: 2
  37515. });
  37516. this._lineGroup.add(polygon);
  37517. this._polygon = polygon;
  37518. return polygon;
  37519. };
  37520. LineView.prototype._initSymbolLabelAnimation = function (data, coordSys, clipShape) {
  37521. var isHorizontalOrRadial;
  37522. var isCoordSysPolar;
  37523. var baseAxis = coordSys.getBaseAxis();
  37524. var isAxisInverse = baseAxis.inverse;
  37525. if (coordSys.type === 'cartesian2d') {
  37526. isHorizontalOrRadial = baseAxis.isHorizontal();
  37527. isCoordSysPolar = false;
  37528. } else if (coordSys.type === 'polar') {
  37529. isHorizontalOrRadial = baseAxis.dim === 'angle';
  37530. isCoordSysPolar = true;
  37531. }
  37532. var seriesModel = data.hostModel;
  37533. var seriesDuration = seriesModel.get('animationDuration');
  37534. if (isFunction(seriesDuration)) {
  37535. seriesDuration = seriesDuration(null);
  37536. }
  37537. var seriesDelay = seriesModel.get('animationDelay') || 0;
  37538. var seriesDelayValue = isFunction(seriesDelay) ? seriesDelay(null) : seriesDelay;
  37539. data.eachItemGraphicEl(function (symbol, idx) {
  37540. var el = symbol;
  37541. if (el) {
  37542. var point = [symbol.x, symbol.y];
  37543. var start = void 0;
  37544. var end = void 0;
  37545. var current = void 0;
  37546. if (clipShape) {
  37547. if (isCoordSysPolar) {
  37548. var polarClip = clipShape;
  37549. var coord = coordSys.pointToCoord(point);
  37550. if (isHorizontalOrRadial) {
  37551. start = polarClip.startAngle;
  37552. end = polarClip.endAngle;
  37553. current = -coord[1] / 180 * Math.PI;
  37554. } else {
  37555. start = polarClip.r0;
  37556. end = polarClip.r;
  37557. current = coord[0];
  37558. }
  37559. } else {
  37560. var gridClip = clipShape;
  37561. if (isHorizontalOrRadial) {
  37562. start = gridClip.x;
  37563. end = gridClip.x + gridClip.width;
  37564. current = symbol.x;
  37565. } else {
  37566. start = gridClip.y + gridClip.height;
  37567. end = gridClip.y;
  37568. current = symbol.y;
  37569. }
  37570. }
  37571. }
  37572. var ratio = end === start ? 0 : (current - start) / (end - start);
  37573. if (isAxisInverse) {
  37574. ratio = 1 - ratio;
  37575. }
  37576. var delay = isFunction(seriesDelay) ? seriesDelay(idx) : seriesDuration * ratio + seriesDelayValue;
  37577. var symbolPath = el.getSymbolPath();
  37578. var text = symbolPath.getTextContent();
  37579. el.attr({
  37580. scaleX: 0,
  37581. scaleY: 0
  37582. });
  37583. el.animateTo({
  37584. scaleX: 1,
  37585. scaleY: 1
  37586. }, {
  37587. duration: 200,
  37588. setToFinal: true,
  37589. delay: delay
  37590. });
  37591. if (text) {
  37592. text.animateFrom({
  37593. style: {
  37594. opacity: 0
  37595. }
  37596. }, {
  37597. duration: 300,
  37598. delay: delay
  37599. });
  37600. }
  37601. symbolPath.disableLabelAnimation = true;
  37602. }
  37603. });
  37604. };
  37605. LineView.prototype._initOrUpdateEndLabel = function (seriesModel, coordSys, inheritColor) {
  37606. var endLabelModel = seriesModel.getModel('endLabel');
  37607. if (anyStateShowEndLabel(seriesModel)) {
  37608. var data_2 = seriesModel.getData();
  37609. var polyline = this._polyline;
  37610. // series may be filtered.
  37611. var points = data_2.getLayout('points');
  37612. if (!points) {
  37613. polyline.removeTextContent();
  37614. this._endLabel = null;
  37615. return;
  37616. }
  37617. var endLabel = this._endLabel;
  37618. if (!endLabel) {
  37619. endLabel = this._endLabel = new ZRText({
  37620. z2: 200 // should be higher than item symbol
  37621. });
  37622. endLabel.ignoreClip = true;
  37623. polyline.setTextContent(this._endLabel);
  37624. polyline.disableLabelAnimation = true;
  37625. }
  37626. // Find last non-NaN data to display data
  37627. var dataIndex = getLastIndexNotNull(points);
  37628. if (dataIndex >= 0) {
  37629. setLabelStyle(polyline, getLabelStatesModels(seriesModel, 'endLabel'), {
  37630. inheritColor: inheritColor,
  37631. labelFetcher: seriesModel,
  37632. labelDataIndex: dataIndex,
  37633. defaultText: function (dataIndex, opt, interpolatedValue) {
  37634. return interpolatedValue != null ? getDefaultInterpolatedLabel(data_2, interpolatedValue) : getDefaultLabel(data_2, dataIndex);
  37635. },
  37636. enableTextSetter: true
  37637. }, getEndLabelStateSpecified(endLabelModel, coordSys));
  37638. polyline.textConfig.position = null;
  37639. }
  37640. } else if (this._endLabel) {
  37641. this._polyline.removeTextContent();
  37642. this._endLabel = null;
  37643. }
  37644. };
  37645. LineView.prototype._endLabelOnDuring = function (percent, clipRect, data, animationRecord, valueAnimation, endLabelModel, coordSys) {
  37646. var endLabel = this._endLabel;
  37647. var polyline = this._polyline;
  37648. if (endLabel) {
  37649. // NOTE: Don't remove percent < 1. percent === 1 means the first frame during render.
  37650. // The label is not prepared at this time.
  37651. if (percent < 1 && animationRecord.originalX == null) {
  37652. animationRecord.originalX = endLabel.x;
  37653. animationRecord.originalY = endLabel.y;
  37654. }
  37655. var points = data.getLayout('points');
  37656. var seriesModel = data.hostModel;
  37657. var connectNulls = seriesModel.get('connectNulls');
  37658. var precision = endLabelModel.get('precision');
  37659. var distance = endLabelModel.get('distance') || 0;
  37660. var baseAxis = coordSys.getBaseAxis();
  37661. var isHorizontal = baseAxis.isHorizontal();
  37662. var isBaseInversed = baseAxis.inverse;
  37663. var clipShape = clipRect.shape;
  37664. var xOrY = isBaseInversed ? isHorizontal ? clipShape.x : clipShape.y + clipShape.height : isHorizontal ? clipShape.x + clipShape.width : clipShape.y;
  37665. var distanceX = (isHorizontal ? distance : 0) * (isBaseInversed ? -1 : 1);
  37666. var distanceY = (isHorizontal ? 0 : -distance) * (isBaseInversed ? -1 : 1);
  37667. var dim = isHorizontal ? 'x' : 'y';
  37668. var dataIndexRange = getIndexRange(points, xOrY, dim);
  37669. var indices = dataIndexRange.range;
  37670. var diff = indices[1] - indices[0];
  37671. var value = void 0;
  37672. if (diff >= 1) {
  37673. // diff > 1 && connectNulls, which is on the null data.
  37674. if (diff > 1 && !connectNulls) {
  37675. var pt = getPointAtIndex(points, indices[0]);
  37676. endLabel.attr({
  37677. x: pt[0] + distanceX,
  37678. y: pt[1] + distanceY
  37679. });
  37680. valueAnimation && (value = seriesModel.getRawValue(indices[0]));
  37681. } else {
  37682. var pt = polyline.getPointOn(xOrY, dim);
  37683. pt && endLabel.attr({
  37684. x: pt[0] + distanceX,
  37685. y: pt[1] + distanceY
  37686. });
  37687. var startValue = seriesModel.getRawValue(indices[0]);
  37688. var endValue = seriesModel.getRawValue(indices[1]);
  37689. valueAnimation && (value = interpolateRawValues(data, precision, startValue, endValue, dataIndexRange.t));
  37690. }
  37691. animationRecord.lastFrameIndex = indices[0];
  37692. } else {
  37693. // If diff <= 0, which is the range is not found(Include NaN)
  37694. // Choose the first point or last point.
  37695. var idx = percent === 1 || animationRecord.lastFrameIndex > 0 ? indices[0] : 0;
  37696. var pt = getPointAtIndex(points, idx);
  37697. valueAnimation && (value = seriesModel.getRawValue(idx));
  37698. endLabel.attr({
  37699. x: pt[0] + distanceX,
  37700. y: pt[1] + distanceY
  37701. });
  37702. }
  37703. if (valueAnimation) {
  37704. var inner = labelInner(endLabel);
  37705. if (typeof inner.setLabelText === 'function') {
  37706. inner.setLabelText(value);
  37707. }
  37708. }
  37709. }
  37710. };
  37711. /**
  37712. * @private
  37713. */
  37714. // FIXME Two value axis
  37715. LineView.prototype._doUpdateAnimation = function (data, stackedOnPoints, coordSys, api, step, valueOrigin, connectNulls) {
  37716. var polyline = this._polyline;
  37717. var polygon = this._polygon;
  37718. var seriesModel = data.hostModel;
  37719. var diff = lineAnimationDiff(this._data, data, this._stackedOnPoints, stackedOnPoints, this._coordSys, coordSys, this._valueOrigin);
  37720. var current = diff.current;
  37721. var stackedOnCurrent = diff.stackedOnCurrent;
  37722. var next = diff.next;
  37723. var stackedOnNext = diff.stackedOnNext;
  37724. if (step) {
  37725. // TODO If stacked series is not step
  37726. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, diff.current, coordSys, step, connectNulls);
  37727. current = turnPointsIntoStep(diff.current, null, coordSys, step, connectNulls);
  37728. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, diff.next, coordSys, step, connectNulls);
  37729. next = turnPointsIntoStep(diff.next, null, coordSys, step, connectNulls);
  37730. }
  37731. // Don't apply animation if diff is large.
  37732. // For better result and avoid memory explosion problems like
  37733. // https://github.com/apache/incubator-echarts/issues/12229
  37734. if (getBoundingDiff(current, next) > 3000 || polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000) {
  37735. polyline.stopAnimation();
  37736. polyline.setShape({
  37737. points: next
  37738. });
  37739. if (polygon) {
  37740. polygon.stopAnimation();
  37741. polygon.setShape({
  37742. points: next,
  37743. stackedOnPoints: stackedOnNext
  37744. });
  37745. }
  37746. return;
  37747. }
  37748. polyline.shape.__points = diff.current;
  37749. polyline.shape.points = current;
  37750. var target = {
  37751. shape: {
  37752. points: next
  37753. }
  37754. };
  37755. // Also animate the original points.
  37756. // If points reference is changed when turning into step line.
  37757. if (diff.current !== current) {
  37758. target.shape.__points = diff.next;
  37759. }
  37760. // Stop previous animation.
  37761. polyline.stopAnimation();
  37762. updateProps(polyline, target, seriesModel);
  37763. if (polygon) {
  37764. polygon.setShape({
  37765. // Reuse the points with polyline.
  37766. points: current,
  37767. stackedOnPoints: stackedOnCurrent
  37768. });
  37769. polygon.stopAnimation();
  37770. updateProps(polygon, {
  37771. shape: {
  37772. stackedOnPoints: stackedOnNext
  37773. }
  37774. }, seriesModel);
  37775. // If use attr directly in updateProps.
  37776. if (polyline.shape.points !== polygon.shape.points) {
  37777. polygon.shape.points = polyline.shape.points;
  37778. }
  37779. }
  37780. var updatedDataInfo = [];
  37781. var diffStatus = diff.status;
  37782. for (var i = 0; i < diffStatus.length; i++) {
  37783. var cmd = diffStatus[i].cmd;
  37784. if (cmd === '=') {
  37785. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  37786. if (el) {
  37787. updatedDataInfo.push({
  37788. el: el,
  37789. ptIdx: i // Index of points
  37790. });
  37791. }
  37792. }
  37793. }
  37794. if (polyline.animators && polyline.animators.length) {
  37795. polyline.animators[0].during(function () {
  37796. polygon && polygon.dirtyShape();
  37797. var points = polyline.shape.__points;
  37798. for (var i = 0; i < updatedDataInfo.length; i++) {
  37799. var el = updatedDataInfo[i].el;
  37800. var offset = updatedDataInfo[i].ptIdx * 2;
  37801. el.x = points[offset];
  37802. el.y = points[offset + 1];
  37803. el.markRedraw();
  37804. }
  37805. });
  37806. }
  37807. };
  37808. LineView.prototype.remove = function (ecModel) {
  37809. var group = this.group;
  37810. var oldData = this._data;
  37811. this._lineGroup.removeAll();
  37812. this._symbolDraw.remove(true);
  37813. // Remove temporary created elements when highlighting
  37814. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  37815. if (el.__temp) {
  37816. group.remove(el);
  37817. oldData.setItemGraphicEl(idx, null);
  37818. }
  37819. });
  37820. this._polyline = this._polygon = this._coordSys = this._points = this._stackedOnPoints = this._endLabel = this._data = null;
  37821. };
  37822. LineView.type = 'line';
  37823. return LineView;
  37824. }(ChartView);
  37825. function pointsLayout(seriesType, forceStoreInTypedArray) {
  37826. return {
  37827. seriesType: seriesType,
  37828. plan: createRenderPlanner(),
  37829. reset: function (seriesModel) {
  37830. var data = seriesModel.getData();
  37831. var coordSys = seriesModel.coordinateSystem;
  37832. var pipelineContext = seriesModel.pipelineContext;
  37833. var useTypedArray = forceStoreInTypedArray || pipelineContext.large;
  37834. if (!coordSys) {
  37835. return;
  37836. }
  37837. var dims = map(coordSys.dimensions, function (dim) {
  37838. return data.mapDimension(dim);
  37839. }).slice(0, 2);
  37840. var dimLen = dims.length;
  37841. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  37842. if (isDimensionStacked(data, dims[0])) {
  37843. dims[0] = stackResultDim;
  37844. }
  37845. if (isDimensionStacked(data, dims[1])) {
  37846. dims[1] = stackResultDim;
  37847. }
  37848. var store = data.getStore();
  37849. var dimIdx0 = data.getDimensionIndex(dims[0]);
  37850. var dimIdx1 = data.getDimensionIndex(dims[1]);
  37851. return dimLen && {
  37852. progress: function (params, data) {
  37853. var segCount = params.end - params.start;
  37854. var points = useTypedArray && createFloat32Array(segCount * dimLen);
  37855. var tmpIn = [];
  37856. var tmpOut = [];
  37857. for (var i = params.start, offset = 0; i < params.end; i++) {
  37858. var point = void 0;
  37859. if (dimLen === 1) {
  37860. var x = store.get(dimIdx0, i);
  37861. // NOTE: Make sure the second parameter is null to use default strategy.
  37862. point = coordSys.dataToPoint(x, null, tmpOut);
  37863. } else {
  37864. tmpIn[0] = store.get(dimIdx0, i);
  37865. tmpIn[1] = store.get(dimIdx1, i);
  37866. // Let coordinate system to handle the NaN data.
  37867. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  37868. }
  37869. if (useTypedArray) {
  37870. points[offset++] = point[0];
  37871. points[offset++] = point[1];
  37872. } else {
  37873. data.setItemLayout(i, point.slice());
  37874. }
  37875. }
  37876. useTypedArray && data.setLayout('points', points);
  37877. }
  37878. };
  37879. }
  37880. };
  37881. }
  37882. var samplers = {
  37883. average: function (frame) {
  37884. var sum = 0;
  37885. var count = 0;
  37886. for (var i = 0; i < frame.length; i++) {
  37887. if (!isNaN(frame[i])) {
  37888. sum += frame[i];
  37889. count++;
  37890. }
  37891. }
  37892. // Return NaN if count is 0
  37893. return count === 0 ? NaN : sum / count;
  37894. },
  37895. sum: function (frame) {
  37896. var sum = 0;
  37897. for (var i = 0; i < frame.length; i++) {
  37898. // Ignore NaN
  37899. sum += frame[i] || 0;
  37900. }
  37901. return sum;
  37902. },
  37903. max: function (frame) {
  37904. var max = -Infinity;
  37905. for (var i = 0; i < frame.length; i++) {
  37906. frame[i] > max && (max = frame[i]);
  37907. }
  37908. // NaN will cause illegal axis extent.
  37909. return isFinite(max) ? max : NaN;
  37910. },
  37911. min: function (frame) {
  37912. var min = Infinity;
  37913. for (var i = 0; i < frame.length; i++) {
  37914. frame[i] < min && (min = frame[i]);
  37915. }
  37916. // NaN will cause illegal axis extent.
  37917. return isFinite(min) ? min : NaN;
  37918. },
  37919. // TODO
  37920. // Median
  37921. nearest: function (frame) {
  37922. return frame[0];
  37923. }
  37924. };
  37925. var indexSampler = function (frame) {
  37926. return Math.round(frame.length / 2);
  37927. };
  37928. function dataSample(seriesType) {
  37929. return {
  37930. seriesType: seriesType,
  37931. // FIXME:TS never used, so comment it
  37932. // modifyOutputEnd: true,
  37933. reset: function (seriesModel, ecModel, api) {
  37934. var data = seriesModel.getData();
  37935. var sampling = seriesModel.get('sampling');
  37936. var coordSys = seriesModel.coordinateSystem;
  37937. var count = data.count();
  37938. // Only cartesian2d support down sampling. Disable it when there is few data.
  37939. if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
  37940. var baseAxis = coordSys.getBaseAxis();
  37941. var valueAxis = coordSys.getOtherAxis(baseAxis);
  37942. var extent = baseAxis.getExtent();
  37943. var dpr = api.getDevicePixelRatio();
  37944. // Coordinste system has been resized
  37945. var size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
  37946. var rate = Math.round(count / size);
  37947. if (isFinite(rate) && rate > 1) {
  37948. if (sampling === 'lttb') {
  37949. seriesModel.setData(data.lttbDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
  37950. } else if (sampling === 'minmax') {
  37951. seriesModel.setData(data.minmaxDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
  37952. }
  37953. var sampler = void 0;
  37954. if (isString(sampling)) {
  37955. sampler = samplers[sampling];
  37956. } else if (isFunction(sampling)) {
  37957. sampler = sampling;
  37958. }
  37959. if (sampler) {
  37960. // Only support sample the first dim mapped from value axis.
  37961. seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
  37962. }
  37963. }
  37964. }
  37965. }
  37966. };
  37967. }
  37968. function install$1(registers) {
  37969. registers.registerChartView(LineView);
  37970. registers.registerSeriesModel(LineSeriesModel);
  37971. registers.registerLayout(pointsLayout('line', true));
  37972. registers.registerVisual({
  37973. seriesType: 'line',
  37974. reset: function (seriesModel) {
  37975. var data = seriesModel.getData();
  37976. // Visual coding for legend
  37977. var lineStyle = seriesModel.getModel('lineStyle').getLineStyle();
  37978. if (lineStyle && !lineStyle.stroke) {
  37979. // Fill in visual should be palette color if
  37980. // has color callback
  37981. lineStyle.stroke = data.getVisual('style').fill;
  37982. }
  37983. data.setVisual('legendLineStyle', lineStyle);
  37984. }
  37985. });
  37986. // Down sample after filter
  37987. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('line'));
  37988. }
  37989. var BaseBarSeriesModel = /** @class */function (_super) {
  37990. __extends(BaseBarSeriesModel, _super);
  37991. function BaseBarSeriesModel() {
  37992. var _this = _super !== null && _super.apply(this, arguments) || this;
  37993. _this.type = BaseBarSeriesModel.type;
  37994. return _this;
  37995. }
  37996. BaseBarSeriesModel.prototype.getInitialData = function (option, ecModel) {
  37997. return createSeriesData(null, this, {
  37998. useEncodeDefaulter: true
  37999. });
  38000. };
  38001. BaseBarSeriesModel.prototype.getMarkerPosition = function (value, dims, startingAtTick) {
  38002. var coordSys = this.coordinateSystem;
  38003. if (coordSys && coordSys.clampData) {
  38004. // PENDING if clamp ?
  38005. var clampData_1 = coordSys.clampData(value);
  38006. var pt_1 = coordSys.dataToPoint(clampData_1);
  38007. if (startingAtTick) {
  38008. each(coordSys.getAxes(), function (axis, idx) {
  38009. // If axis type is category, use tick coords instead
  38010. if (axis.type === 'category' && dims != null) {
  38011. var tickCoords = axis.getTicksCoords();
  38012. var alignTicksWithLabel = axis.getTickModel().get('alignWithLabel');
  38013. var targetTickId = clampData_1[idx];
  38014. // The index of rightmost tick of markArea is 1 larger than x1/y1 index
  38015. var isEnd = dims[idx] === 'x1' || dims[idx] === 'y1';
  38016. if (isEnd && !alignTicksWithLabel) {
  38017. targetTickId += 1;
  38018. }
  38019. // The only contains one tick, tickCoords is
  38020. // like [{coord: 0, tickValue: 0}, {coord: 0}]
  38021. // to the length should always be larger than 1
  38022. if (tickCoords.length < 2) {
  38023. return;
  38024. } else if (tickCoords.length === 2) {
  38025. // The left value and right value of the axis are
  38026. // the same. coord is 0 in both items. Use the max
  38027. // value of the axis as the coord
  38028. pt_1[idx] = axis.toGlobalCoord(axis.getExtent()[isEnd ? 1 : 0]);
  38029. return;
  38030. }
  38031. var leftCoord = void 0;
  38032. var coord = void 0;
  38033. var stepTickValue = 1;
  38034. for (var i = 0; i < tickCoords.length; i++) {
  38035. var tickCoord = tickCoords[i].coord;
  38036. // The last item of tickCoords doesn't contain
  38037. // tickValue
  38038. var tickValue = i === tickCoords.length - 1 ? tickCoords[i - 1].tickValue + stepTickValue : tickCoords[i].tickValue;
  38039. if (tickValue === targetTickId) {
  38040. coord = tickCoord;
  38041. break;
  38042. } else if (tickValue < targetTickId) {
  38043. leftCoord = tickCoord;
  38044. } else if (leftCoord != null && tickValue > targetTickId) {
  38045. coord = (tickCoord + leftCoord) / 2;
  38046. break;
  38047. }
  38048. if (i === 1) {
  38049. // Here we assume the step of category axes is
  38050. // the same
  38051. stepTickValue = tickValue - tickCoords[0].tickValue;
  38052. }
  38053. }
  38054. if (coord == null) {
  38055. if (!leftCoord) {
  38056. // targetTickId is smaller than all tick ids in the
  38057. // visible area, use the leftmost tick coord
  38058. coord = tickCoords[0].coord;
  38059. } else if (leftCoord) {
  38060. // targetTickId is larger than all tick ids in the
  38061. // visible area, use the rightmost tick coord
  38062. coord = tickCoords[tickCoords.length - 1].coord;
  38063. }
  38064. }
  38065. pt_1[idx] = axis.toGlobalCoord(coord);
  38066. }
  38067. });
  38068. } else {
  38069. var data = this.getData();
  38070. var offset = data.getLayout('offset');
  38071. var size = data.getLayout('size');
  38072. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  38073. pt_1[offsetIndex] += offset + size / 2;
  38074. }
  38075. return pt_1;
  38076. }
  38077. return [NaN, NaN];
  38078. };
  38079. BaseBarSeriesModel.type = 'series.__base_bar__';
  38080. BaseBarSeriesModel.defaultOption = {
  38081. // zlevel: 0,
  38082. z: 2,
  38083. coordinateSystem: 'cartesian2d',
  38084. legendHoverLink: true,
  38085. // stack: null
  38086. // Cartesian coordinate system
  38087. // xAxisIndex: 0,
  38088. // yAxisIndex: 0,
  38089. barMinHeight: 0,
  38090. barMinAngle: 0,
  38091. // cursor: null,
  38092. large: false,
  38093. largeThreshold: 400,
  38094. progressive: 3e3,
  38095. progressiveChunkMode: 'mod',
  38096. defaultBarGap: '10%'
  38097. };
  38098. return BaseBarSeriesModel;
  38099. }(SeriesModel);
  38100. SeriesModel.registerClass(BaseBarSeriesModel);
  38101. var BarSeriesModel = /** @class */function (_super) {
  38102. __extends(BarSeriesModel, _super);
  38103. function BarSeriesModel() {
  38104. var _this = _super !== null && _super.apply(this, arguments) || this;
  38105. _this.type = BarSeriesModel.type;
  38106. return _this;
  38107. }
  38108. BarSeriesModel.prototype.getInitialData = function () {
  38109. return createSeriesData(null, this, {
  38110. useEncodeDefaulter: true,
  38111. createInvertedIndices: !!this.get('realtimeSort', true) || null
  38112. });
  38113. };
  38114. /**
  38115. * @override
  38116. */
  38117. BarSeriesModel.prototype.getProgressive = function () {
  38118. // Do not support progressive in normal mode.
  38119. return this.get('large') ? this.get('progressive') : false;
  38120. };
  38121. /**
  38122. * @override
  38123. */
  38124. BarSeriesModel.prototype.getProgressiveThreshold = function () {
  38125. // Do not support progressive in normal mode.
  38126. var progressiveThreshold = this.get('progressiveThreshold');
  38127. var largeThreshold = this.get('largeThreshold');
  38128. if (largeThreshold > progressiveThreshold) {
  38129. progressiveThreshold = largeThreshold;
  38130. }
  38131. return progressiveThreshold;
  38132. };
  38133. BarSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  38134. return selectors.rect(data.getItemLayout(dataIndex));
  38135. };
  38136. BarSeriesModel.type = 'series.bar';
  38137. BarSeriesModel.dependencies = ['grid', 'polar'];
  38138. BarSeriesModel.defaultOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
  38139. // If clipped
  38140. // Only available on cartesian2d
  38141. clip: true,
  38142. roundCap: false,
  38143. showBackground: false,
  38144. backgroundStyle: {
  38145. color: 'rgba(180, 180, 180, 0.2)',
  38146. borderColor: null,
  38147. borderWidth: 0,
  38148. borderType: 'solid',
  38149. borderRadius: 0,
  38150. shadowBlur: 0,
  38151. shadowColor: null,
  38152. shadowOffsetX: 0,
  38153. shadowOffsetY: 0,
  38154. opacity: 1
  38155. },
  38156. select: {
  38157. itemStyle: {
  38158. borderColor: tokens.color.primary,
  38159. borderWidth: 2
  38160. }
  38161. },
  38162. realtimeSort: false
  38163. });
  38164. return BarSeriesModel;
  38165. }(BaseBarSeriesModel);
  38166. /**
  38167. * Sausage: similar to sector, but have half circle on both sides
  38168. */
  38169. var SausageShape = /** @class */function () {
  38170. function SausageShape() {
  38171. this.cx = 0;
  38172. this.cy = 0;
  38173. this.r0 = 0;
  38174. this.r = 0;
  38175. this.startAngle = 0;
  38176. this.endAngle = Math.PI * 2;
  38177. this.clockwise = true;
  38178. }
  38179. return SausageShape;
  38180. }();
  38181. var SausagePath = /** @class */function (_super) {
  38182. __extends(SausagePath, _super);
  38183. function SausagePath(opts) {
  38184. var _this = _super.call(this, opts) || this;
  38185. _this.type = 'sausage';
  38186. return _this;
  38187. }
  38188. SausagePath.prototype.getDefaultShape = function () {
  38189. return new SausageShape();
  38190. };
  38191. SausagePath.prototype.buildPath = function (ctx, shape) {
  38192. var cx = shape.cx;
  38193. var cy = shape.cy;
  38194. var r0 = Math.max(shape.r0 || 0, 0);
  38195. var r = Math.max(shape.r, 0);
  38196. var dr = (r - r0) * 0.5;
  38197. var rCenter = r0 + dr;
  38198. var startAngle = shape.startAngle;
  38199. var endAngle = shape.endAngle;
  38200. var clockwise = shape.clockwise;
  38201. var PI2 = Math.PI * 2;
  38202. var lessThanCircle = clockwise ? endAngle - startAngle < PI2 : startAngle - endAngle < PI2;
  38203. if (!lessThanCircle) {
  38204. // Normalize angles
  38205. startAngle = endAngle - (clockwise ? PI2 : -PI2);
  38206. }
  38207. var unitStartX = Math.cos(startAngle);
  38208. var unitStartY = Math.sin(startAngle);
  38209. var unitEndX = Math.cos(endAngle);
  38210. var unitEndY = Math.sin(endAngle);
  38211. if (lessThanCircle) {
  38212. ctx.moveTo(unitStartX * r0 + cx, unitStartY * r0 + cy);
  38213. ctx.arc(unitStartX * rCenter + cx, unitStartY * rCenter + cy, dr, -Math.PI + startAngle, startAngle, !clockwise);
  38214. } else {
  38215. ctx.moveTo(unitStartX * r + cx, unitStartY * r + cy);
  38216. }
  38217. ctx.arc(cx, cy, r, startAngle, endAngle, !clockwise);
  38218. ctx.arc(unitEndX * rCenter + cx, unitEndY * rCenter + cy, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
  38219. if (r0 !== 0) {
  38220. ctx.arc(cx, cy, r0, endAngle, startAngle, clockwise);
  38221. }
  38222. // ctx.closePath();
  38223. };
  38224. return SausagePath;
  38225. }(Path);
  38226. function createSectorCalculateTextPosition(positionMapping, opts) {
  38227. opts = opts || {};
  38228. var isRoundCap = opts.isRoundCap;
  38229. return function (out, opts, boundingRect) {
  38230. var textPosition = opts.position;
  38231. if (!textPosition || textPosition instanceof Array) {
  38232. return calculateTextPosition(out, opts, boundingRect);
  38233. }
  38234. var mappedSectorPosition = positionMapping(textPosition);
  38235. var distance = opts.distance != null ? opts.distance : 5;
  38236. var sector = this.shape;
  38237. var cx = sector.cx;
  38238. var cy = sector.cy;
  38239. var r = sector.r;
  38240. var r0 = sector.r0;
  38241. var middleR = (r + r0) / 2;
  38242. var startAngle = sector.startAngle;
  38243. var endAngle = sector.endAngle;
  38244. var middleAngle = (startAngle + endAngle) / 2;
  38245. var extraDist = isRoundCap ? Math.abs(r - r0) / 2 : 0;
  38246. var mathCos = Math.cos;
  38247. var mathSin = Math.sin;
  38248. // base position: top-left
  38249. var x = cx + r * mathCos(startAngle);
  38250. var y = cy + r * mathSin(startAngle);
  38251. var textAlign = 'left';
  38252. var textVerticalAlign = 'top';
  38253. switch (mappedSectorPosition) {
  38254. case 'startArc':
  38255. x = cx + (r0 - distance) * mathCos(middleAngle);
  38256. y = cy + (r0 - distance) * mathSin(middleAngle);
  38257. textAlign = 'center';
  38258. textVerticalAlign = 'top';
  38259. break;
  38260. case 'insideStartArc':
  38261. x = cx + (r0 + distance) * mathCos(middleAngle);
  38262. y = cy + (r0 + distance) * mathSin(middleAngle);
  38263. textAlign = 'center';
  38264. textVerticalAlign = 'bottom';
  38265. break;
  38266. case 'startAngle':
  38267. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, distance + extraDist, false);
  38268. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, distance + extraDist, false);
  38269. textAlign = 'right';
  38270. textVerticalAlign = 'middle';
  38271. break;
  38272. case 'insideStartAngle':
  38273. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, -distance + extraDist, false);
  38274. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, -distance + extraDist, false);
  38275. textAlign = 'left';
  38276. textVerticalAlign = 'middle';
  38277. break;
  38278. case 'middle':
  38279. x = cx + middleR * mathCos(middleAngle);
  38280. y = cy + middleR * mathSin(middleAngle);
  38281. textAlign = 'center';
  38282. textVerticalAlign = 'middle';
  38283. break;
  38284. case 'endArc':
  38285. x = cx + (r + distance) * mathCos(middleAngle);
  38286. y = cy + (r + distance) * mathSin(middleAngle);
  38287. textAlign = 'center';
  38288. textVerticalAlign = 'bottom';
  38289. break;
  38290. case 'insideEndArc':
  38291. x = cx + (r - distance) * mathCos(middleAngle);
  38292. y = cy + (r - distance) * mathSin(middleAngle);
  38293. textAlign = 'center';
  38294. textVerticalAlign = 'top';
  38295. break;
  38296. case 'endAngle':
  38297. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, distance + extraDist, true);
  38298. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, distance + extraDist, true);
  38299. textAlign = 'left';
  38300. textVerticalAlign = 'middle';
  38301. break;
  38302. case 'insideEndAngle':
  38303. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, -distance + extraDist, true);
  38304. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, -distance + extraDist, true);
  38305. textAlign = 'right';
  38306. textVerticalAlign = 'middle';
  38307. break;
  38308. default:
  38309. return calculateTextPosition(out, opts, boundingRect);
  38310. }
  38311. out = out || {};
  38312. out.x = x;
  38313. out.y = y;
  38314. out.align = textAlign;
  38315. out.verticalAlign = textVerticalAlign;
  38316. return out;
  38317. };
  38318. }
  38319. function setSectorTextRotation(sector, textPosition, positionMapping, rotateType) {
  38320. if (isNumber(rotateType)) {
  38321. // user-set rotation
  38322. sector.setTextConfig({
  38323. rotation: rotateType
  38324. });
  38325. return;
  38326. } else if (isArray(textPosition)) {
  38327. // user-set position, use 0 as auto rotation
  38328. sector.setTextConfig({
  38329. rotation: 0
  38330. });
  38331. return;
  38332. }
  38333. var shape = sector.shape;
  38334. var startAngle = shape.clockwise ? shape.startAngle : shape.endAngle;
  38335. var endAngle = shape.clockwise ? shape.endAngle : shape.startAngle;
  38336. var middleAngle = (startAngle + endAngle) / 2;
  38337. var anchorAngle;
  38338. var mappedSectorPosition = positionMapping(textPosition);
  38339. switch (mappedSectorPosition) {
  38340. case 'startArc':
  38341. case 'insideStartArc':
  38342. case 'middle':
  38343. case 'insideEndArc':
  38344. case 'endArc':
  38345. anchorAngle = middleAngle;
  38346. break;
  38347. case 'startAngle':
  38348. case 'insideStartAngle':
  38349. anchorAngle = startAngle;
  38350. break;
  38351. case 'endAngle':
  38352. case 'insideEndAngle':
  38353. anchorAngle = endAngle;
  38354. break;
  38355. default:
  38356. sector.setTextConfig({
  38357. rotation: 0
  38358. });
  38359. return;
  38360. }
  38361. var rotate = Math.PI * 1.5 - anchorAngle;
  38362. /**
  38363. * TODO: labels with rotate > Math.PI / 2 should be rotate another
  38364. * half round flipped to increase readability. However, only middle
  38365. * position supports this for now, because in other positions, the
  38366. * anchor point is not at the center of the text, so the positions
  38367. * after rotating is not as expected.
  38368. */
  38369. if (mappedSectorPosition === 'middle' && rotate > Math.PI / 2 && rotate < Math.PI * 1.5) {
  38370. rotate -= Math.PI;
  38371. }
  38372. sector.setTextConfig({
  38373. rotation: rotate
  38374. });
  38375. }
  38376. function adjustAngleDistanceX(angle, distance, isEnd) {
  38377. return distance * Math.sin(angle) * (isEnd ? -1 : 1);
  38378. }
  38379. function adjustAngleDistanceY(angle, distance, isEnd) {
  38380. return distance * Math.cos(angle) * (isEnd ? 1 : -1);
  38381. }
  38382. function getSectorCornerRadius(model, shape, zeroIfNull) {
  38383. var cornerRadius = model.get('borderRadius');
  38384. if (cornerRadius == null) {
  38385. return zeroIfNull ? {
  38386. cornerRadius: 0
  38387. } : null;
  38388. }
  38389. if (!isArray(cornerRadius)) {
  38390. cornerRadius = [cornerRadius, cornerRadius, cornerRadius, cornerRadius];
  38391. }
  38392. var dr = Math.abs(shape.r || 0 - shape.r0 || 0);
  38393. return {
  38394. cornerRadius: map(cornerRadius, function (cr) {
  38395. return parsePercent(cr, dr);
  38396. })
  38397. };
  38398. }
  38399. var mathMax$7 = Math.max;
  38400. var mathMin$7 = Math.min;
  38401. function getClipArea(coord, data) {
  38402. var coordSysClipArea = coord.getArea && coord.getArea();
  38403. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  38404. var baseAxis = coord.getBaseAxis();
  38405. // When boundaryGap is false or using time axis. bar may exceed the grid.
  38406. // We should not clip this part.
  38407. // See test/bar2.html
  38408. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  38409. var expandWidth = data.getLayout('bandWidth');
  38410. if (baseAxis.isHorizontal()) {
  38411. coordSysClipArea.x -= expandWidth;
  38412. coordSysClipArea.width += expandWidth * 2;
  38413. } else {
  38414. coordSysClipArea.y -= expandWidth;
  38415. coordSysClipArea.height += expandWidth * 2;
  38416. }
  38417. }
  38418. }
  38419. return coordSysClipArea;
  38420. }
  38421. var BarView = /** @class */function (_super) {
  38422. __extends(BarView, _super);
  38423. function BarView() {
  38424. var _this = _super.call(this) || this;
  38425. _this.type = BarView.type;
  38426. _this._isFirstFrame = true;
  38427. return _this;
  38428. }
  38429. BarView.prototype.render = function (seriesModel, ecModel, api, payload) {
  38430. this._model = seriesModel;
  38431. this._removeOnRenderedListener(api);
  38432. this._updateDrawMode(seriesModel);
  38433. var coordinateSystemType = seriesModel.get('coordinateSystem');
  38434. if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
  38435. // Clear previously rendered progressive elements.
  38436. this._progressiveEls = null;
  38437. this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api, payload);
  38438. } else if ("development" !== 'production') {
  38439. warn('Only cartesian2d and polar supported for bar.');
  38440. }
  38441. };
  38442. BarView.prototype.incrementalPrepareRender = function (seriesModel) {
  38443. this._clear();
  38444. this._updateDrawMode(seriesModel);
  38445. // incremental also need to clip, otherwise might be overlow.
  38446. // But must not set clip in each frame, otherwise all of the children will be marked redraw.
  38447. this._updateLargeClip(seriesModel);
  38448. };
  38449. BarView.prototype.incrementalRender = function (params, seriesModel) {
  38450. // Reset
  38451. this._progressiveEls = [];
  38452. // Do not support progressive in normal mode.
  38453. this._incrementalRenderLarge(params, seriesModel);
  38454. };
  38455. BarView.prototype.eachRendered = function (cb) {
  38456. traverseElements(this._progressiveEls || this.group, cb);
  38457. };
  38458. BarView.prototype._updateDrawMode = function (seriesModel) {
  38459. var isLargeDraw = seriesModel.pipelineContext.large;
  38460. if (this._isLargeDraw == null || isLargeDraw !== this._isLargeDraw) {
  38461. this._isLargeDraw = isLargeDraw;
  38462. this._clear();
  38463. }
  38464. };
  38465. BarView.prototype._renderNormal = function (seriesModel, ecModel, api, payload) {
  38466. var group = this.group;
  38467. var data = seriesModel.getData();
  38468. var oldData = this._data;
  38469. var coord = seriesModel.coordinateSystem;
  38470. var baseAxis = coord.getBaseAxis();
  38471. var isHorizontalOrRadial;
  38472. if (coord.type === 'cartesian2d') {
  38473. isHorizontalOrRadial = baseAxis.isHorizontal();
  38474. } else if (coord.type === 'polar') {
  38475. isHorizontalOrRadial = baseAxis.dim === 'angle';
  38476. }
  38477. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  38478. var realtimeSortCfg = shouldRealtimeSort(seriesModel, coord);
  38479. if (realtimeSortCfg) {
  38480. this._enableRealtimeSort(realtimeSortCfg, data, api);
  38481. }
  38482. var needsClip = seriesModel.get('clip', true) || realtimeSortCfg;
  38483. var coordSysClipArea = getClipArea(coord, data);
  38484. // If there is clipPath created in large mode. Remove it.
  38485. group.removeClipPath();
  38486. // We don't use clipPath in normal mode because we needs a perfect animation
  38487. // And don't want the label are clipped.
  38488. var roundCap = seriesModel.get('roundCap', true);
  38489. var drawBackground = seriesModel.get('showBackground', true);
  38490. var backgroundModel = seriesModel.getModel('backgroundStyle');
  38491. var barBorderRadius = backgroundModel.get('borderRadius') || 0;
  38492. var bgEls = [];
  38493. var oldBgEls = this._backgroundEls;
  38494. var isInitSort = payload && payload.isInitSort;
  38495. var isChangeOrder = payload && payload.type === 'changeAxisOrder';
  38496. function createBackground(dataIndex) {
  38497. var bgLayout = getLayout[coord.type](data, dataIndex);
  38498. if (!bgLayout) {
  38499. return null;
  38500. }
  38501. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  38502. bgEl.useStyle(backgroundModel.getItemStyle());
  38503. // Only cartesian2d support borderRadius.
  38504. if (coord.type === 'cartesian2d') {
  38505. bgEl.setShape('r', barBorderRadius);
  38506. } else {
  38507. bgEl.setShape('cornerRadius', barBorderRadius);
  38508. }
  38509. bgEls[dataIndex] = bgEl;
  38510. return bgEl;
  38511. }
  38512. data.diff(oldData).add(function (dataIndex) {
  38513. var itemModel = data.getItemModel(dataIndex);
  38514. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  38515. if (!layout) {
  38516. return;
  38517. }
  38518. if (drawBackground) {
  38519. createBackground(dataIndex);
  38520. }
  38521. // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  38522. if (!data.hasValue(dataIndex) || !isValidLayout[coord.type](layout)) {
  38523. return;
  38524. }
  38525. var isClipped = false;
  38526. if (needsClip) {
  38527. // Clip will modify the layout params.
  38528. // And return a boolean to determine if the shape are fully clipped.
  38529. isClipped = clip[coord.type](coordSysClipArea, layout);
  38530. }
  38531. var el = elementCreator[coord.type](seriesModel, data, dataIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, false, roundCap);
  38532. if (realtimeSortCfg) {
  38533. /**
  38534. * Force label animation because even if the element is
  38535. * ignored because it's clipped, it may not be clipped after
  38536. * changing order. Then, if not using forceLabelAnimation,
  38537. * the label animation was never started, in which case,
  38538. * the label will be the final value and doesn't have label
  38539. * animation.
  38540. */
  38541. el.forceLabelAnimation = true;
  38542. }
  38543. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  38544. if (isInitSort) {
  38545. el.attr({
  38546. shape: layout
  38547. });
  38548. } else if (realtimeSortCfg) {
  38549. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, dataIndex, isHorizontalOrRadial, false, false);
  38550. } else {
  38551. initProps(el, {
  38552. shape: layout
  38553. }, seriesModel, dataIndex);
  38554. }
  38555. data.setItemGraphicEl(dataIndex, el);
  38556. group.add(el);
  38557. el.ignore = isClipped;
  38558. }).update(function (newIndex, oldIndex) {
  38559. var itemModel = data.getItemModel(newIndex);
  38560. var layout = getLayout[coord.type](data, newIndex, itemModel);
  38561. if (!layout) {
  38562. return;
  38563. }
  38564. if (drawBackground) {
  38565. var bgEl = void 0;
  38566. if (oldBgEls.length === 0) {
  38567. bgEl = createBackground(oldIndex);
  38568. } else {
  38569. bgEl = oldBgEls[oldIndex];
  38570. bgEl.useStyle(backgroundModel.getItemStyle());
  38571. // Only cartesian2d support borderRadius.
  38572. if (coord.type === 'cartesian2d') {
  38573. bgEl.setShape('r', barBorderRadius);
  38574. } else {
  38575. bgEl.setShape('cornerRadius', barBorderRadius);
  38576. }
  38577. bgEls[newIndex] = bgEl;
  38578. }
  38579. var bgLayout = getLayout[coord.type](data, newIndex);
  38580. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  38581. updateProps(bgEl, {
  38582. shape: shape
  38583. }, animationModel, newIndex);
  38584. }
  38585. var el = oldData.getItemGraphicEl(oldIndex);
  38586. if (!data.hasValue(newIndex) || !isValidLayout[coord.type](layout)) {
  38587. group.remove(el);
  38588. return;
  38589. }
  38590. var isClipped = false;
  38591. if (needsClip) {
  38592. isClipped = clip[coord.type](coordSysClipArea, layout);
  38593. if (isClipped) {
  38594. group.remove(el);
  38595. }
  38596. }
  38597. var roundCapChanged = el && (el.type === 'sector' && roundCap || el.type === 'sausage' && !roundCap);
  38598. if (roundCapChanged) {
  38599. // roundCap changed, there is no way to use animation from a `sector` to a `sausage` shape,
  38600. // so remove the old one and create a new shape
  38601. el && removeElementWithFadeOut(el, seriesModel, oldIndex);
  38602. el = null;
  38603. }
  38604. if (!el) {
  38605. el = elementCreator[coord.type](seriesModel, data, newIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, true, roundCap);
  38606. } else {
  38607. saveOldStyle(el);
  38608. }
  38609. if (realtimeSortCfg) {
  38610. el.forceLabelAnimation = true;
  38611. }
  38612. if (isChangeOrder) {
  38613. var textEl = el.getTextContent();
  38614. if (textEl) {
  38615. var labelInnerStore = labelInner(textEl);
  38616. if (labelInnerStore.prevValue != null) {
  38617. /**
  38618. * Set preValue to be value so that no new label
  38619. * should be started, otherwise, it will take a full
  38620. * `animationDurationUpdate` time to finish the
  38621. * animation, which is not expected.
  38622. */
  38623. labelInnerStore.prevValue = labelInnerStore.value;
  38624. }
  38625. }
  38626. }
  38627. // Not change anything if only order changed.
  38628. // Especially not change label.
  38629. else {
  38630. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  38631. }
  38632. if (isInitSort) {
  38633. el.attr({
  38634. shape: layout
  38635. });
  38636. } else if (realtimeSortCfg) {
  38637. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, newIndex, isHorizontalOrRadial, true, isChangeOrder);
  38638. } else {
  38639. updateProps(el, {
  38640. shape: layout
  38641. }, seriesModel, newIndex, null);
  38642. }
  38643. data.setItemGraphicEl(newIndex, el);
  38644. el.ignore = isClipped;
  38645. group.add(el);
  38646. }).remove(function (dataIndex) {
  38647. var el = oldData.getItemGraphicEl(dataIndex);
  38648. el && removeElementWithFadeOut(el, seriesModel, dataIndex);
  38649. }).execute();
  38650. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  38651. bgGroup.removeAll();
  38652. for (var i = 0; i < bgEls.length; ++i) {
  38653. bgGroup.add(bgEls[i]);
  38654. }
  38655. group.add(bgGroup);
  38656. this._backgroundEls = bgEls;
  38657. this._data = data;
  38658. };
  38659. BarView.prototype._renderLarge = function (seriesModel, ecModel, api) {
  38660. this._clear();
  38661. createLarge(seriesModel, this.group);
  38662. this._updateLargeClip(seriesModel);
  38663. };
  38664. BarView.prototype._incrementalRenderLarge = function (params, seriesModel) {
  38665. this._removeBackground();
  38666. createLarge(seriesModel, this.group, this._progressiveEls, true);
  38667. };
  38668. BarView.prototype._updateLargeClip = function (seriesModel) {
  38669. // Use clipPath in large mode.
  38670. var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
  38671. var group = this.group;
  38672. if (clipPath) {
  38673. group.setClipPath(clipPath);
  38674. } else {
  38675. group.removeClipPath();
  38676. }
  38677. };
  38678. BarView.prototype._enableRealtimeSort = function (realtimeSortCfg, data, api) {
  38679. var _this = this;
  38680. // If no data in the first frame, wait for data to initSort
  38681. if (!data.count()) {
  38682. return;
  38683. }
  38684. var baseAxis = realtimeSortCfg.baseAxis;
  38685. if (this._isFirstFrame) {
  38686. this._dispatchInitSort(data, realtimeSortCfg, api);
  38687. this._isFirstFrame = false;
  38688. } else {
  38689. var orderMapping_1 = function (idx) {
  38690. var el = data.getItemGraphicEl(idx);
  38691. var shape = el && el.shape;
  38692. return shape &&
  38693. // The result should be consistent with the initial sort by data value.
  38694. // Do not support the case that both positive and negative exist.
  38695. Math.abs(baseAxis.isHorizontal() ? shape.height : shape.width)
  38696. // If data is NaN, shape.xxx may be NaN, so use || 0 here in case
  38697. || 0;
  38698. };
  38699. this._onRendered = function () {
  38700. _this._updateSortWithinSameData(data, orderMapping_1, baseAxis, api);
  38701. };
  38702. api.getZr().on('rendered', this._onRendered);
  38703. }
  38704. };
  38705. BarView.prototype._dataSort = function (data, baseAxis, orderMapping) {
  38706. var info = [];
  38707. data.each(data.mapDimension(baseAxis.dim), function (ordinalNumber, dataIdx) {
  38708. var mappedValue = orderMapping(dataIdx);
  38709. mappedValue = mappedValue == null ? NaN : mappedValue;
  38710. info.push({
  38711. dataIndex: dataIdx,
  38712. mappedValue: mappedValue,
  38713. ordinalNumber: ordinalNumber
  38714. });
  38715. });
  38716. info.sort(function (a, b) {
  38717. // If NaN, it will be treated as min val.
  38718. return b.mappedValue - a.mappedValue;
  38719. });
  38720. return {
  38721. ordinalNumbers: map(info, function (item) {
  38722. return item.ordinalNumber;
  38723. })
  38724. };
  38725. };
  38726. BarView.prototype._isOrderChangedWithinSameData = function (data, orderMapping, baseAxis) {
  38727. var scale = baseAxis.scale;
  38728. var ordinalDataDim = data.mapDimension(baseAxis.dim);
  38729. var lastValue = Number.MAX_VALUE;
  38730. for (var tickNum = 0, len = scale.getOrdinalMeta().categories.length; tickNum < len; ++tickNum) {
  38731. var rawIdx = data.rawIndexOf(ordinalDataDim, scale.getRawOrdinalNumber(tickNum));
  38732. var value = rawIdx < 0
  38733. // If some tick have no bar, the tick will be treated as min.
  38734. ? Number.MIN_VALUE
  38735. // PENDING: if dataZoom on baseAxis exits, is it a performance issue?
  38736. : orderMapping(data.indexOfRawIndex(rawIdx));
  38737. if (value > lastValue) {
  38738. return true;
  38739. }
  38740. lastValue = value;
  38741. }
  38742. return false;
  38743. };
  38744. /*
  38745. * Consider the case when A and B changed order, whose representing
  38746. * bars are both out of sight, we don't wish to trigger reorder action
  38747. * as long as the order in the view doesn't change.
  38748. */
  38749. BarView.prototype._isOrderDifferentInView = function (orderInfo, baseAxis) {
  38750. var scale = baseAxis.scale;
  38751. var extent = scale.getExtent();
  38752. var tickNum = Math.max(0, extent[0]);
  38753. var tickMax = Math.min(extent[1], scale.getOrdinalMeta().categories.length - 1);
  38754. for (; tickNum <= tickMax; ++tickNum) {
  38755. if (orderInfo.ordinalNumbers[tickNum] !== scale.getRawOrdinalNumber(tickNum)) {
  38756. return true;
  38757. }
  38758. }
  38759. };
  38760. BarView.prototype._updateSortWithinSameData = function (data, orderMapping, baseAxis, api) {
  38761. if (!this._isOrderChangedWithinSameData(data, orderMapping, baseAxis)) {
  38762. return;
  38763. }
  38764. var sortInfo = this._dataSort(data, baseAxis, orderMapping);
  38765. if (this._isOrderDifferentInView(sortInfo, baseAxis)) {
  38766. this._removeOnRenderedListener(api);
  38767. api.dispatchAction({
  38768. type: 'changeAxisOrder',
  38769. componentType: baseAxis.dim + 'Axis',
  38770. axisId: baseAxis.index,
  38771. sortInfo: sortInfo
  38772. });
  38773. }
  38774. };
  38775. BarView.prototype._dispatchInitSort = function (data, realtimeSortCfg, api) {
  38776. var baseAxis = realtimeSortCfg.baseAxis;
  38777. var sortResult = this._dataSort(data, baseAxis, function (dataIdx) {
  38778. return data.get(data.mapDimension(realtimeSortCfg.otherAxis.dim), dataIdx);
  38779. });
  38780. api.dispatchAction({
  38781. type: 'changeAxisOrder',
  38782. componentType: baseAxis.dim + 'Axis',
  38783. isInitSort: true,
  38784. axisId: baseAxis.index,
  38785. sortInfo: sortResult
  38786. });
  38787. };
  38788. BarView.prototype.remove = function (ecModel, api) {
  38789. this._clear(this._model);
  38790. this._removeOnRenderedListener(api);
  38791. };
  38792. BarView.prototype.dispose = function (ecModel, api) {
  38793. this._removeOnRenderedListener(api);
  38794. };
  38795. BarView.prototype._removeOnRenderedListener = function (api) {
  38796. if (this._onRendered) {
  38797. api.getZr().off('rendered', this._onRendered);
  38798. this._onRendered = null;
  38799. }
  38800. };
  38801. BarView.prototype._clear = function (model) {
  38802. var group = this.group;
  38803. var data = this._data;
  38804. if (model && model.isAnimationEnabled() && data && !this._isLargeDraw) {
  38805. this._removeBackground();
  38806. this._backgroundEls = [];
  38807. data.eachItemGraphicEl(function (el) {
  38808. removeElementWithFadeOut(el, model, getECData(el).dataIndex);
  38809. });
  38810. } else {
  38811. group.removeAll();
  38812. }
  38813. this._data = null;
  38814. this._isFirstFrame = true;
  38815. };
  38816. BarView.prototype._removeBackground = function () {
  38817. this.group.remove(this._backgroundGroup);
  38818. this._backgroundGroup = null;
  38819. };
  38820. BarView.type = 'bar';
  38821. return BarView;
  38822. }(ChartView);
  38823. var clip = {
  38824. cartesian2d: function (coordSysBoundingRect, layout) {
  38825. var signWidth = layout.width < 0 ? -1 : 1;
  38826. var signHeight = layout.height < 0 ? -1 : 1;
  38827. // Needs positive width and height
  38828. if (signWidth < 0) {
  38829. layout.x += layout.width;
  38830. layout.width = -layout.width;
  38831. }
  38832. if (signHeight < 0) {
  38833. layout.y += layout.height;
  38834. layout.height = -layout.height;
  38835. }
  38836. var coordSysX2 = coordSysBoundingRect.x + coordSysBoundingRect.width;
  38837. var coordSysY2 = coordSysBoundingRect.y + coordSysBoundingRect.height;
  38838. var x = mathMax$7(layout.x, coordSysBoundingRect.x);
  38839. var x2 = mathMin$7(layout.x + layout.width, coordSysX2);
  38840. var y = mathMax$7(layout.y, coordSysBoundingRect.y);
  38841. var y2 = mathMin$7(layout.y + layout.height, coordSysY2);
  38842. var xClipped = x2 < x;
  38843. var yClipped = y2 < y;
  38844. // When xClipped or yClipped, the element will be marked as `ignore`.
  38845. // But we should also place the element at the edge of the coord sys bounding rect.
  38846. // Because if data changed and the bar shows again, its transition animation
  38847. // will begin at this place.
  38848. layout.x = xClipped && x > coordSysX2 ? x2 : x;
  38849. layout.y = yClipped && y > coordSysY2 ? y2 : y;
  38850. layout.width = xClipped ? 0 : x2 - x;
  38851. layout.height = yClipped ? 0 : y2 - y;
  38852. // Reverse back
  38853. if (signWidth < 0) {
  38854. layout.x += layout.width;
  38855. layout.width = -layout.width;
  38856. }
  38857. if (signHeight < 0) {
  38858. layout.y += layout.height;
  38859. layout.height = -layout.height;
  38860. }
  38861. return xClipped || yClipped;
  38862. },
  38863. polar: function (coordSysClipArea, layout) {
  38864. var signR = layout.r0 <= layout.r ? 1 : -1;
  38865. // Make sure r is larger than r0
  38866. if (signR < 0) {
  38867. var tmp = layout.r;
  38868. layout.r = layout.r0;
  38869. layout.r0 = tmp;
  38870. }
  38871. var r = mathMin$7(layout.r, coordSysClipArea.r);
  38872. var r0 = mathMax$7(layout.r0, coordSysClipArea.r0);
  38873. layout.r = r;
  38874. layout.r0 = r0;
  38875. var clipped = r - r0 < 0;
  38876. // Reverse back
  38877. if (signR < 0) {
  38878. var tmp = layout.r;
  38879. layout.r = layout.r0;
  38880. layout.r0 = tmp;
  38881. }
  38882. return clipped;
  38883. }
  38884. };
  38885. var elementCreator = {
  38886. cartesian2d: function (seriesModel, data, newIndex, layout, isHorizontal, animationModel, axisModel, isUpdate, roundCap) {
  38887. var rect = new Rect({
  38888. shape: extend({}, layout),
  38889. z2: 1
  38890. });
  38891. rect.__dataIndex = newIndex;
  38892. rect.name = 'item';
  38893. if (animationModel) {
  38894. var rectShape = rect.shape;
  38895. var animateProperty = isHorizontal ? 'height' : 'width';
  38896. rectShape[animateProperty] = 0;
  38897. }
  38898. return rect;
  38899. },
  38900. polar: function (seriesModel, data, newIndex, layout, isRadial, animationModel, axisModel, isUpdate, roundCap) {
  38901. var ShapeClass = !isRadial && roundCap ? SausagePath : Sector;
  38902. var sector = new ShapeClass({
  38903. shape: layout,
  38904. z2: 1
  38905. });
  38906. sector.name = 'item';
  38907. var positionMap = createPolarPositionMapping(isRadial);
  38908. sector.calculateTextPosition = createSectorCalculateTextPosition(positionMap, {
  38909. isRoundCap: ShapeClass === SausagePath
  38910. });
  38911. // Animation
  38912. if (animationModel) {
  38913. var sectorShape = sector.shape;
  38914. var animateProperty = isRadial ? 'r' : 'endAngle';
  38915. var animateTarget = {};
  38916. sectorShape[animateProperty] = isRadial ? layout.r0 : layout.startAngle;
  38917. animateTarget[animateProperty] = layout[animateProperty];
  38918. (isUpdate ? updateProps : initProps)(sector, {
  38919. shape: animateTarget
  38920. // __value: typeof dataValue === 'string' ? parseInt(dataValue, 10) : dataValue
  38921. }, animationModel);
  38922. }
  38923. return sector;
  38924. }
  38925. };
  38926. function shouldRealtimeSort(seriesModel, coordSys) {
  38927. var realtimeSortOption = seriesModel.get('realtimeSort', true);
  38928. var baseAxis = coordSys.getBaseAxis();
  38929. if ("development" !== 'production') {
  38930. if (realtimeSortOption) {
  38931. if (baseAxis.type !== 'category') {
  38932. warn('`realtimeSort` will not work because this bar series is not based on a category axis.');
  38933. }
  38934. if (coordSys.type !== 'cartesian2d') {
  38935. warn('`realtimeSort` will not work because this bar series is not on cartesian2d.');
  38936. }
  38937. }
  38938. }
  38939. if (realtimeSortOption && baseAxis.type === 'category' && coordSys.type === 'cartesian2d') {
  38940. return {
  38941. baseAxis: baseAxis,
  38942. otherAxis: coordSys.getOtherAxis(baseAxis)
  38943. };
  38944. }
  38945. }
  38946. function updateRealtimeAnimation(realtimeSortCfg, seriesAnimationModel, el, layout, newIndex, isHorizontal, isUpdate, isChangeOrder) {
  38947. var seriesTarget;
  38948. var axisTarget;
  38949. if (isHorizontal) {
  38950. axisTarget = {
  38951. x: layout.x,
  38952. width: layout.width
  38953. };
  38954. seriesTarget = {
  38955. y: layout.y,
  38956. height: layout.height
  38957. };
  38958. } else {
  38959. axisTarget = {
  38960. y: layout.y,
  38961. height: layout.height
  38962. };
  38963. seriesTarget = {
  38964. x: layout.x,
  38965. width: layout.width
  38966. };
  38967. }
  38968. if (!isChangeOrder) {
  38969. // Keep the original growth animation if only axis order changed.
  38970. // Not start a new animation.
  38971. (isUpdate ? updateProps : initProps)(el, {
  38972. shape: seriesTarget
  38973. }, seriesAnimationModel, newIndex, null);
  38974. }
  38975. var axisAnimationModel = seriesAnimationModel ? realtimeSortCfg.baseAxis.model : null;
  38976. (isUpdate ? updateProps : initProps)(el, {
  38977. shape: axisTarget
  38978. }, axisAnimationModel, newIndex);
  38979. }
  38980. function checkPropertiesNotValid(obj, props) {
  38981. for (var i = 0; i < props.length; i++) {
  38982. if (!isFinite(obj[props[i]])) {
  38983. return true;
  38984. }
  38985. }
  38986. return false;
  38987. }
  38988. var rectPropties = ['x', 'y', 'width', 'height'];
  38989. var polarPropties = ['cx', 'cy', 'r', 'startAngle', 'endAngle'];
  38990. var isValidLayout = {
  38991. cartesian2d: function (layout) {
  38992. return !checkPropertiesNotValid(layout, rectPropties);
  38993. },
  38994. polar: function (layout) {
  38995. return !checkPropertiesNotValid(layout, polarPropties);
  38996. }
  38997. };
  38998. var getLayout = {
  38999. // itemModel is only used to get borderWidth, which is not needed
  39000. // when calculating bar background layout.
  39001. cartesian2d: function (data, dataIndex, itemModel) {
  39002. var layout = data.getItemLayout(dataIndex);
  39003. if (!layout) {
  39004. return null;
  39005. }
  39006. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0;
  39007. // fix layout with lineWidth
  39008. var signX = layout.width > 0 ? 1 : -1;
  39009. var signY = layout.height > 0 ? 1 : -1;
  39010. return {
  39011. x: layout.x + signX * fixedLineWidth / 2,
  39012. y: layout.y + signY * fixedLineWidth / 2,
  39013. width: layout.width - signX * fixedLineWidth,
  39014. height: layout.height - signY * fixedLineWidth
  39015. };
  39016. },
  39017. polar: function (data, dataIndex, itemModel) {
  39018. var layout = data.getItemLayout(dataIndex);
  39019. return {
  39020. cx: layout.cx,
  39021. cy: layout.cy,
  39022. r0: layout.r0,
  39023. r: layout.r,
  39024. startAngle: layout.startAngle,
  39025. endAngle: layout.endAngle,
  39026. clockwise: layout.clockwise
  39027. };
  39028. }
  39029. };
  39030. function isZeroOnPolar(layout) {
  39031. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  39032. }
  39033. function createPolarPositionMapping(isRadial) {
  39034. return function (isRadial) {
  39035. var arcOrAngle = isRadial ? 'Arc' : 'Angle';
  39036. return function (position) {
  39037. switch (position) {
  39038. case 'start':
  39039. case 'insideStart':
  39040. case 'end':
  39041. case 'insideEnd':
  39042. return position + arcOrAngle;
  39043. default:
  39044. return position;
  39045. }
  39046. };
  39047. }(isRadial);
  39048. }
  39049. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, isPolar) {
  39050. var style = data.getItemVisual(dataIndex, 'style');
  39051. if (!isPolar) {
  39052. var borderRadius = itemModel.get(['itemStyle', 'borderRadius']) || 0;
  39053. el.setShape('r', borderRadius);
  39054. } else if (!seriesModel.get('roundCap')) {
  39055. var sectorShape = el.shape;
  39056. var cornerRadius = getSectorCornerRadius(itemModel.getModel('itemStyle'), sectorShape, true);
  39057. extend(sectorShape, cornerRadius);
  39058. el.setShape(sectorShape);
  39059. }
  39060. el.useStyle(style);
  39061. var cursorStyle = itemModel.getShallow('cursor');
  39062. cursorStyle && el.attr('cursor', cursorStyle);
  39063. var labelPositionOutside = isPolar ? isHorizontalOrRadial ? layout.r >= layout.r0 ? 'endArc' : 'startArc' : layout.endAngle >= layout.startAngle ? 'endAngle' : 'startAngle' : isHorizontalOrRadial ? layout.height >= 0 ? 'bottom' : 'top' : layout.width >= 0 ? 'right' : 'left';
  39064. var labelStatesModels = getLabelStatesModels(itemModel);
  39065. setLabelStyle(el, labelStatesModels, {
  39066. labelFetcher: seriesModel,
  39067. labelDataIndex: dataIndex,
  39068. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  39069. inheritColor: style.fill,
  39070. defaultOpacity: style.opacity,
  39071. defaultOutsidePosition: labelPositionOutside
  39072. });
  39073. var label = el.getTextContent();
  39074. if (isPolar && label) {
  39075. var position = itemModel.get(['label', 'position']);
  39076. el.textConfig.inside = position === 'middle' ? true : null;
  39077. setSectorTextRotation(el, position === 'outside' ? labelPositionOutside : position, createPolarPositionMapping(isHorizontalOrRadial), itemModel.get(['label', 'rotate']));
  39078. }
  39079. setLabelValueAnimation(label, labelStatesModels, seriesModel.getRawValue(dataIndex), function (value) {
  39080. return getDefaultInterpolatedLabel(data, value);
  39081. });
  39082. var emphasisModel = itemModel.getModel(['emphasis']);
  39083. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  39084. setStatesStylesFromModel(el, itemModel);
  39085. if (isZeroOnPolar(layout)) {
  39086. el.style.fill = 'none';
  39087. el.style.stroke = 'none';
  39088. each(el.states, function (state) {
  39089. if (state.style) {
  39090. state.style.fill = state.style.stroke = 'none';
  39091. }
  39092. });
  39093. }
  39094. }
  39095. // In case width or height are too small.
  39096. function getLineWidth(itemModel, rawLayout) {
  39097. // Has no border.
  39098. var borderColor = itemModel.get(['itemStyle', 'borderColor']);
  39099. if (!borderColor || borderColor === 'none') {
  39100. return 0;
  39101. }
  39102. var lineWidth = itemModel.get(['itemStyle', 'borderWidth']) || 0;
  39103. // width or height may be NaN for empty data
  39104. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  39105. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  39106. return Math.min(lineWidth, width, height);
  39107. }
  39108. var LagePathShape = /** @class */function () {
  39109. function LagePathShape() {}
  39110. return LagePathShape;
  39111. }();
  39112. var LargePath = /** @class */function (_super) {
  39113. __extends(LargePath, _super);
  39114. function LargePath(opts) {
  39115. var _this = _super.call(this, opts) || this;
  39116. _this.type = 'largeBar';
  39117. return _this;
  39118. }
  39119. LargePath.prototype.getDefaultShape = function () {
  39120. return new LagePathShape();
  39121. };
  39122. LargePath.prototype.buildPath = function (ctx, shape) {
  39123. // Drawing lines is more efficient than drawing
  39124. // a whole line or drawing rects.
  39125. var points = shape.points;
  39126. var baseDimIdx = this.baseDimIdx;
  39127. var valueDimIdx = 1 - this.baseDimIdx;
  39128. var startPoint = [];
  39129. var size = [];
  39130. var barWidth = this.barWidth;
  39131. for (var i = 0; i < points.length; i += 3) {
  39132. size[baseDimIdx] = barWidth;
  39133. size[valueDimIdx] = points[i + 2];
  39134. startPoint[baseDimIdx] = points[i + baseDimIdx];
  39135. startPoint[valueDimIdx] = points[i + valueDimIdx];
  39136. ctx.rect(startPoint[0], startPoint[1], size[0], size[1]);
  39137. }
  39138. };
  39139. return LargePath;
  39140. }(Path);
  39141. function createLarge(seriesModel, group, progressiveEls, incremental) {
  39142. // TODO support polar
  39143. var data = seriesModel.getData();
  39144. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  39145. var largeDataIndices = data.getLayout('largeDataIndices');
  39146. var barWidth = data.getLayout('size');
  39147. var backgroundModel = seriesModel.getModel('backgroundStyle');
  39148. var bgPoints = data.getLayout('largeBackgroundPoints');
  39149. if (bgPoints) {
  39150. var bgEl = new LargePath({
  39151. shape: {
  39152. points: bgPoints
  39153. },
  39154. incremental: !!incremental,
  39155. silent: true,
  39156. z2: 0
  39157. });
  39158. bgEl.baseDimIdx = baseDimIdx;
  39159. bgEl.largeDataIndices = largeDataIndices;
  39160. bgEl.barWidth = barWidth;
  39161. bgEl.useStyle(backgroundModel.getItemStyle());
  39162. group.add(bgEl);
  39163. progressiveEls && progressiveEls.push(bgEl);
  39164. }
  39165. var el = new LargePath({
  39166. shape: {
  39167. points: data.getLayout('largePoints')
  39168. },
  39169. incremental: !!incremental,
  39170. ignoreCoarsePointer: true,
  39171. z2: 1
  39172. });
  39173. el.baseDimIdx = baseDimIdx;
  39174. el.largeDataIndices = largeDataIndices;
  39175. el.barWidth = barWidth;
  39176. group.add(el);
  39177. el.useStyle(data.getVisual('style'));
  39178. // Stroke is rendered first to avoid overlapping with fill
  39179. el.style.stroke = null;
  39180. // Enable tooltip and user mouse/touch event handlers.
  39181. getECData(el).seriesIndex = seriesModel.seriesIndex;
  39182. if (!seriesModel.get('silent')) {
  39183. el.on('mousedown', largePathUpdateDataIndex);
  39184. el.on('mousemove', largePathUpdateDataIndex);
  39185. }
  39186. progressiveEls && progressiveEls.push(el);
  39187. }
  39188. // Use throttle to avoid frequently traverse to find dataIndex.
  39189. var largePathUpdateDataIndex = throttle(function (event) {
  39190. var largePath = this;
  39191. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  39192. getECData(largePath).dataIndex = dataIndex >= 0 ? dataIndex : null;
  39193. }, 30, false);
  39194. function largePathFindDataIndex(largePath, x, y) {
  39195. var baseDimIdx = largePath.baseDimIdx;
  39196. var valueDimIdx = 1 - baseDimIdx;
  39197. var points = largePath.shape.points;
  39198. var largeDataIndices = largePath.largeDataIndices;
  39199. var startPoint = [];
  39200. var size = [];
  39201. var barWidth = largePath.barWidth;
  39202. for (var i = 0, len = points.length / 3; i < len; i++) {
  39203. var ii = i * 3;
  39204. size[baseDimIdx] = barWidth;
  39205. size[valueDimIdx] = points[ii + 2];
  39206. startPoint[baseDimIdx] = points[ii + baseDimIdx];
  39207. startPoint[valueDimIdx] = points[ii + valueDimIdx];
  39208. if (size[valueDimIdx] < 0) {
  39209. startPoint[valueDimIdx] += size[valueDimIdx];
  39210. size[valueDimIdx] = -size[valueDimIdx];
  39211. }
  39212. if (x >= startPoint[0] && x <= startPoint[0] + size[0] && y >= startPoint[1] && y <= startPoint[1] + size[1]) {
  39213. return largeDataIndices[i];
  39214. }
  39215. }
  39216. return -1;
  39217. }
  39218. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  39219. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  39220. var rectShape = layout;
  39221. var coordLayout = coord.getArea();
  39222. return {
  39223. x: isHorizontalOrRadial ? rectShape.x : coordLayout.x,
  39224. y: isHorizontalOrRadial ? coordLayout.y : rectShape.y,
  39225. width: isHorizontalOrRadial ? rectShape.width : coordLayout.width,
  39226. height: isHorizontalOrRadial ? coordLayout.height : rectShape.height
  39227. };
  39228. } else {
  39229. var coordLayout = coord.getArea();
  39230. var sectorShape = layout;
  39231. return {
  39232. cx: coordLayout.cx,
  39233. cy: coordLayout.cy,
  39234. r0: isHorizontalOrRadial ? coordLayout.r0 : sectorShape.r0,
  39235. r: isHorizontalOrRadial ? coordLayout.r : sectorShape.r,
  39236. startAngle: isHorizontalOrRadial ? sectorShape.startAngle : 0,
  39237. endAngle: isHorizontalOrRadial ? sectorShape.endAngle : Math.PI * 2
  39238. };
  39239. }
  39240. }
  39241. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  39242. var ElementClz = coord.type === 'polar' ? Sector : Rect;
  39243. return new ElementClz({
  39244. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  39245. silent: true,
  39246. z2: 0
  39247. });
  39248. }
  39249. function install$2(registers) {
  39250. registers.registerChartView(BarView);
  39251. registers.registerSeriesModel(BarSeriesModel);
  39252. registers.registerLayout(registers.PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar'));
  39253. // Do layout after other overall layout, which can prepare some information.
  39254. registers.registerLayout(registers.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, createProgressiveLayout('bar'));
  39255. // Down sample after filter
  39256. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('bar'));
  39257. /**
  39258. * @payload
  39259. * @property {string} [componentType=series]
  39260. * @property {number} [dx]
  39261. * @property {number} [dy]
  39262. * @property {number} [zoom]
  39263. * @property {number} [originX]
  39264. * @property {number} [originY]
  39265. */
  39266. registers.registerAction({
  39267. type: 'changeAxisOrder',
  39268. event: 'changeAxisOrder',
  39269. update: 'update'
  39270. }, function (payload, ecModel) {
  39271. var componentType = payload.componentType || 'series';
  39272. ecModel.eachComponent({
  39273. mainType: componentType,
  39274. query: payload
  39275. }, function (componentModel) {
  39276. if (payload.sortInfo) {
  39277. componentModel.axis.setCategorySortInfo(payload.sortInfo);
  39278. }
  39279. });
  39280. });
  39281. }
  39282. var PI2$6 = Math.PI * 2;
  39283. var RADIAN = Math.PI / 180;
  39284. function pieLayout(seriesType, ecModel, api) {
  39285. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  39286. var data = seriesModel.getData();
  39287. var valueDim = data.mapDimension('value');
  39288. var _a = getCircleLayout(seriesModel, api),
  39289. cx = _a.cx,
  39290. cy = _a.cy,
  39291. r = _a.r,
  39292. r0 = _a.r0,
  39293. viewRect = _a.viewRect;
  39294. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  39295. var endAngle = seriesModel.get('endAngle');
  39296. var padAngle = seriesModel.get('padAngle') * RADIAN;
  39297. endAngle = endAngle === 'auto' ? startAngle - PI2$6 : -endAngle * RADIAN;
  39298. var minAngle = seriesModel.get('minAngle') * RADIAN;
  39299. var minAndPadAngle = minAngle + padAngle;
  39300. var validDataCount = 0;
  39301. data.each(valueDim, function (value) {
  39302. !isNaN(value) && validDataCount++;
  39303. });
  39304. var sum = data.getSum(valueDim);
  39305. // Sum may be 0
  39306. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  39307. var clockwise = seriesModel.get('clockwise');
  39308. var roseType = seriesModel.get('roseType');
  39309. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  39310. // [0...max]
  39311. var extent = data.getDataExtent(valueDim);
  39312. extent[0] = 0;
  39313. var dir = clockwise ? 1 : -1;
  39314. var angles = [startAngle, endAngle];
  39315. var halfPadAngle = dir * padAngle / 2;
  39316. normalizeArcAngles(angles, !clockwise);
  39317. startAngle = angles[0], endAngle = angles[1];
  39318. var layoutData = getSeriesLayoutData(seriesModel);
  39319. layoutData.startAngle = startAngle;
  39320. layoutData.endAngle = endAngle;
  39321. layoutData.clockwise = clockwise;
  39322. layoutData.cx = cx;
  39323. layoutData.cy = cy;
  39324. layoutData.r = r;
  39325. layoutData.r0 = r0;
  39326. var angleRange = Math.abs(endAngle - startAngle);
  39327. // In the case some sector angle is smaller than minAngle
  39328. var restAngle = angleRange;
  39329. var valueSumLargerThanMinAngle = 0;
  39330. var currentAngle = startAngle;
  39331. // Requird by `pieLabelLayout`.
  39332. data.setLayout({
  39333. viewRect: viewRect,
  39334. r: r
  39335. });
  39336. data.each(valueDim, function (value, idx) {
  39337. var angle;
  39338. if (isNaN(value)) {
  39339. data.setItemLayout(idx, {
  39340. angle: NaN,
  39341. startAngle: NaN,
  39342. endAngle: NaN,
  39343. clockwise: clockwise,
  39344. cx: cx,
  39345. cy: cy,
  39346. r0: r0,
  39347. r: roseType ? NaN : r
  39348. });
  39349. return;
  39350. }
  39351. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  39352. if (roseType !== 'area') {
  39353. angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
  39354. } else {
  39355. angle = angleRange / validDataCount;
  39356. }
  39357. if (angle < minAndPadAngle) {
  39358. angle = minAndPadAngle;
  39359. restAngle -= minAndPadAngle;
  39360. } else {
  39361. valueSumLargerThanMinAngle += value;
  39362. }
  39363. var endAngle = currentAngle + dir * angle;
  39364. // calculate display angle
  39365. var actualStartAngle = 0;
  39366. var actualEndAngle = 0;
  39367. if (padAngle > angle) {
  39368. actualStartAngle = currentAngle + dir * angle / 2;
  39369. actualEndAngle = actualStartAngle;
  39370. } else {
  39371. actualStartAngle = currentAngle + halfPadAngle;
  39372. actualEndAngle = endAngle - halfPadAngle;
  39373. }
  39374. data.setItemLayout(idx, {
  39375. angle: angle,
  39376. startAngle: actualStartAngle,
  39377. endAngle: actualEndAngle,
  39378. clockwise: clockwise,
  39379. cx: cx,
  39380. cy: cy,
  39381. r0: r0,
  39382. r: roseType ? linearMap(value, extent, [r0, r]) : r
  39383. });
  39384. currentAngle = endAngle;
  39385. });
  39386. // Some sector is constrained by minAngle and padAngle
  39387. // Rest sectors needs recalculate angle
  39388. if (restAngle < PI2$6 && validDataCount) {
  39389. // Average the angle if rest angle is not enough after all angles is
  39390. // Constrained by minAngle and padAngle
  39391. if (restAngle <= 1e-3) {
  39392. var angle_1 = angleRange / validDataCount;
  39393. data.each(valueDim, function (value, idx) {
  39394. if (!isNaN(value)) {
  39395. var layout = data.getItemLayout(idx);
  39396. layout.angle = angle_1;
  39397. var actualStartAngle = 0;
  39398. var actualEndAngle = 0;
  39399. if (angle_1 < padAngle) {
  39400. actualStartAngle = startAngle + dir * (idx + 1 / 2) * angle_1;
  39401. actualEndAngle = actualStartAngle;
  39402. } else {
  39403. actualStartAngle = startAngle + dir * idx * angle_1 + halfPadAngle;
  39404. actualEndAngle = startAngle + dir * (idx + 1) * angle_1 - halfPadAngle;
  39405. }
  39406. layout.startAngle = actualStartAngle;
  39407. layout.endAngle = actualEndAngle;
  39408. }
  39409. });
  39410. } else {
  39411. unitRadian = restAngle / valueSumLargerThanMinAngle;
  39412. currentAngle = startAngle;
  39413. data.each(valueDim, function (value, idx) {
  39414. if (!isNaN(value)) {
  39415. var layout = data.getItemLayout(idx);
  39416. var angle = layout.angle === minAndPadAngle ? minAndPadAngle : value * unitRadian;
  39417. var actualStartAngle = 0;
  39418. var actualEndAngle = 0;
  39419. if (angle < padAngle) {
  39420. actualStartAngle = currentAngle + dir * angle / 2;
  39421. actualEndAngle = actualStartAngle;
  39422. } else {
  39423. actualStartAngle = currentAngle + halfPadAngle;
  39424. actualEndAngle = currentAngle + dir * angle - halfPadAngle;
  39425. }
  39426. layout.startAngle = actualStartAngle;
  39427. layout.endAngle = actualEndAngle;
  39428. currentAngle += dir * angle;
  39429. }
  39430. });
  39431. }
  39432. }
  39433. });
  39434. }
  39435. var getSeriesLayoutData = makeInner();
  39436. /*
  39437. * Licensed to the Apache Software Foundation (ASF) under one
  39438. * or more contributor license agreements. See the NOTICE file
  39439. * distributed with this work for additional information
  39440. * regarding copyright ownership. The ASF licenses this file
  39441. * to you under the Apache License, Version 2.0 (the
  39442. * "License"); you may not use this file except in compliance
  39443. * with the License. You may obtain a copy of the License at
  39444. *
  39445. * http://www.apache.org/licenses/LICENSE-2.0
  39446. *
  39447. * Unless required by applicable law or agreed to in writing,
  39448. * software distributed under the License is distributed on an
  39449. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39450. * KIND, either express or implied. See the License for the
  39451. * specific language governing permissions and limitations
  39452. * under the License.
  39453. */
  39454. /**
  39455. * AUTO-GENERATED FILE. DO NOT MODIFY.
  39456. */
  39457. /*
  39458. * Licensed to the Apache Software Foundation (ASF) under one
  39459. * or more contributor license agreements. See the NOTICE file
  39460. * distributed with this work for additional information
  39461. * regarding copyright ownership. The ASF licenses this file
  39462. * to you under the Apache License, Version 2.0 (the
  39463. * "License"); you may not use this file except in compliance
  39464. * with the License. You may obtain a copy of the License at
  39465. *
  39466. * http://www.apache.org/licenses/LICENSE-2.0
  39467. *
  39468. * Unless required by applicable law or agreed to in writing,
  39469. * software distributed under the License is distributed on an
  39470. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39471. * KIND, either express or implied. See the License for the
  39472. * specific language governing permissions and limitations
  39473. * under the License.
  39474. */
  39475. function dataFilter(seriesType) {
  39476. return {
  39477. seriesType: seriesType,
  39478. reset: function (seriesModel, ecModel) {
  39479. var legendModels = ecModel.findComponents({
  39480. mainType: 'legend'
  39481. });
  39482. if (!legendModels || !legendModels.length) {
  39483. return;
  39484. }
  39485. var data = seriesModel.getData();
  39486. data.filterSelf(function (idx) {
  39487. var name = data.getName(idx);
  39488. // If in any legend component the status is not selected.
  39489. for (var i = 0; i < legendModels.length; i++) {
  39490. // @ts-ignore FIXME: LegendModel
  39491. if (!legendModels[i].isSelected(name)) {
  39492. return false;
  39493. }
  39494. }
  39495. return true;
  39496. });
  39497. }
  39498. };
  39499. }
  39500. var RADIAN$1 = Math.PI / 180;
  39501. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
  39502. if (list.length < 2) {
  39503. return;
  39504. }
  39505. function recalculateXOnSemiToAlignOnEllipseCurve(semi) {
  39506. var rB = semi.rB;
  39507. var rB2 = rB * rB;
  39508. for (var i = 0; i < semi.list.length; i++) {
  39509. var item = semi.list[i];
  39510. var dy = Math.abs(item.label.y - cy);
  39511. // horizontal r is always same with original r because x is not changed.
  39512. var rA = r + item.len;
  39513. var rA2 = rA * rA;
  39514. // Use ellipse implicit function to calculate x
  39515. var dx = Math.sqrt(Math.abs((1 - dy * dy / rB2) * rA2));
  39516. var newX = cx + (dx + item.len2) * dir;
  39517. var deltaX = newX - item.label.x;
  39518. var newTargetWidth = item.targetTextWidth - deltaX * dir;
  39519. // text x is changed, so need to recalculate width.
  39520. constrainTextWidth(item, newTargetWidth, true);
  39521. item.label.x = newX;
  39522. }
  39523. }
  39524. // Adjust X based on the shifted y. Make tight labels aligned on an ellipse curve.
  39525. function recalculateX(items) {
  39526. // Extremes of
  39527. var topSemi = {
  39528. list: [],
  39529. maxY: 0
  39530. };
  39531. var bottomSemi = {
  39532. list: [],
  39533. maxY: 0
  39534. };
  39535. for (var i = 0; i < items.length; i++) {
  39536. if (items[i].labelAlignTo !== 'none') {
  39537. continue;
  39538. }
  39539. var item = items[i];
  39540. var semi = item.label.y > cy ? bottomSemi : topSemi;
  39541. var dy = Math.abs(item.label.y - cy);
  39542. if (dy >= semi.maxY) {
  39543. var dx = item.label.x - cx - item.len2 * dir;
  39544. // horizontal r is always same with original r because x is not changed.
  39545. var rA = r + item.len;
  39546. // Canculate rB based on the topest / bottemest label.
  39547. var rB = Math.abs(dx) < rA ? Math.sqrt(dy * dy / (1 - dx * dx / rA / rA)) : rA;
  39548. semi.rB = rB;
  39549. semi.maxY = dy;
  39550. }
  39551. semi.list.push(item);
  39552. }
  39553. recalculateXOnSemiToAlignOnEllipseCurve(topSemi);
  39554. recalculateXOnSemiToAlignOnEllipseCurve(bottomSemi);
  39555. }
  39556. var len = list.length;
  39557. for (var i = 0; i < len; i++) {
  39558. if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
  39559. var dx = list[i].label.x - farthestX;
  39560. list[i].linePoints[1][0] += dx;
  39561. list[i].label.x = farthestX;
  39562. }
  39563. }
  39564. if (shiftLayoutOnXY(list, 1, viewTop, viewTop + viewHeight)) {
  39565. recalculateX(list);
  39566. }
  39567. }
  39568. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
  39569. var leftList = [];
  39570. var rightList = [];
  39571. var leftmostX = Number.MAX_VALUE;
  39572. var rightmostX = -Number.MAX_VALUE;
  39573. for (var i = 0; i < labelLayoutList.length; i++) {
  39574. var label = labelLayoutList[i].label;
  39575. if (isPositionCenter(labelLayoutList[i])) {
  39576. continue;
  39577. }
  39578. if (label.x < cx) {
  39579. leftmostX = Math.min(leftmostX, label.x);
  39580. leftList.push(labelLayoutList[i]);
  39581. } else {
  39582. rightmostX = Math.max(rightmostX, label.x);
  39583. rightList.push(labelLayoutList[i]);
  39584. }
  39585. }
  39586. for (var i = 0; i < labelLayoutList.length; i++) {
  39587. var layout = labelLayoutList[i];
  39588. if (!isPositionCenter(layout) && layout.linePoints) {
  39589. if (layout.labelStyleWidth != null) {
  39590. continue;
  39591. }
  39592. var label = layout.label;
  39593. var linePoints = layout.linePoints;
  39594. var targetTextWidth = void 0;
  39595. if (layout.labelAlignTo === 'edge') {
  39596. if (label.x < cx) {
  39597. targetTextWidth = linePoints[2][0] - layout.labelDistance - viewLeft - layout.edgeDistance;
  39598. } else {
  39599. targetTextWidth = viewLeft + viewWidth - layout.edgeDistance - linePoints[2][0] - layout.labelDistance;
  39600. }
  39601. } else if (layout.labelAlignTo === 'labelLine') {
  39602. if (label.x < cx) {
  39603. targetTextWidth = leftmostX - viewLeft - layout.bleedMargin;
  39604. } else {
  39605. targetTextWidth = viewLeft + viewWidth - rightmostX - layout.bleedMargin;
  39606. }
  39607. } else {
  39608. if (label.x < cx) {
  39609. targetTextWidth = label.x - viewLeft - layout.bleedMargin;
  39610. } else {
  39611. targetTextWidth = viewLeft + viewWidth - label.x - layout.bleedMargin;
  39612. }
  39613. }
  39614. layout.targetTextWidth = targetTextWidth;
  39615. constrainTextWidth(layout, targetTextWidth, false);
  39616. }
  39617. }
  39618. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
  39619. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
  39620. for (var i = 0; i < labelLayoutList.length; i++) {
  39621. var layout = labelLayoutList[i];
  39622. if (!isPositionCenter(layout) && layout.linePoints) {
  39623. var label = layout.label;
  39624. var linePoints = layout.linePoints;
  39625. var isAlignToEdge = layout.labelAlignTo === 'edge';
  39626. var padding = label.style.padding;
  39627. var paddingH = padding ? padding[1] + padding[3] : 0;
  39628. // textRect.width already contains paddingH if bgColor is set
  39629. var extraPaddingH = label.style.backgroundColor ? 0 : paddingH;
  39630. var realTextWidth = layout.rect.width + extraPaddingH;
  39631. var dist = linePoints[1][0] - linePoints[2][0];
  39632. if (isAlignToEdge) {
  39633. if (label.x < cx) {
  39634. linePoints[2][0] = viewLeft + layout.edgeDistance + realTextWidth + layout.labelDistance;
  39635. } else {
  39636. linePoints[2][0] = viewLeft + viewWidth - layout.edgeDistance - realTextWidth - layout.labelDistance;
  39637. }
  39638. } else {
  39639. if (label.x < cx) {
  39640. linePoints[2][0] = label.x + layout.labelDistance;
  39641. } else {
  39642. linePoints[2][0] = label.x - layout.labelDistance;
  39643. }
  39644. linePoints[1][0] = linePoints[2][0] + dist;
  39645. }
  39646. linePoints[1][1] = linePoints[2][1] = label.y;
  39647. }
  39648. }
  39649. }
  39650. /**
  39651. * Set max width of each label, and then wrap each label to the max width.
  39652. *
  39653. * @param layout label layout
  39654. * @param availableWidth max width for the label to display
  39655. * @param forceRecalculate recaculate the text layout even if the current width
  39656. * is smaller than `availableWidth`. This is useful when the text was previously
  39657. * wrapped by calling `constrainTextWidth` but now `availableWidth` changed, in
  39658. * which case, previous wrapping should be redo.
  39659. */
  39660. function constrainTextWidth(layout, availableWidth, forceRecalculate) {
  39661. if (layout.labelStyleWidth != null) {
  39662. // User-defined style.width has the highest priority.
  39663. return;
  39664. }
  39665. var label = layout.label;
  39666. var style = label.style;
  39667. var textRect = layout.rect;
  39668. var bgColor = style.backgroundColor;
  39669. var padding = style.padding;
  39670. var paddingH = padding ? padding[1] + padding[3] : 0;
  39671. var overflow = style.overflow;
  39672. // textRect.width already contains paddingH if bgColor is set
  39673. var oldOuterWidth = textRect.width + (bgColor ? 0 : paddingH);
  39674. if (availableWidth < oldOuterWidth || forceRecalculate) {
  39675. if (overflow && overflow.match('break')) {
  39676. // Temporarily set background to be null to calculate
  39677. // the bounding box without background.
  39678. label.setStyle('backgroundColor', null);
  39679. // Set constraining width
  39680. label.setStyle('width', availableWidth - paddingH);
  39681. // This is the real bounding box of the text without padding.
  39682. var innerRect = label.getBoundingRect();
  39683. label.setStyle('width', Math.ceil(innerRect.width));
  39684. label.setStyle('backgroundColor', bgColor);
  39685. } else {
  39686. var availableInnerWidth = availableWidth - paddingH;
  39687. var newWidth = availableWidth < oldOuterWidth
  39688. // Current text is too wide, use `availableWidth` as max width.
  39689. ? availableInnerWidth :
  39690. // Current available width is enough, but the text may have
  39691. // already been wrapped with a smaller available width.
  39692. forceRecalculate ? availableInnerWidth > layout.unconstrainedWidth
  39693. // Current available is larger than text width,
  39694. // so don't constrain width (otherwise it may have
  39695. // empty space in the background).
  39696. ? null
  39697. // Current available is smaller than text width, so
  39698. // use the current available width as constraining
  39699. // width.
  39700. : availableInnerWidth
  39701. // Current available width is enough, so no need to
  39702. // constrain.
  39703. : null;
  39704. label.setStyle('width', newWidth);
  39705. }
  39706. computeLabelGlobalRect(textRect, label);
  39707. }
  39708. }
  39709. function computeLabelGlobalRect(out, label) {
  39710. _tmpLabelGeometry.rect = out;
  39711. computeLabelGeometry(_tmpLabelGeometry, label, _computeLabelGeometryOpt);
  39712. }
  39713. var _computeLabelGeometryOpt = {
  39714. minMarginForce: [null, 0, null, 0],
  39715. marginDefault: [1, 0, 1, 0]
  39716. };
  39717. var _tmpLabelGeometry = {};
  39718. function isPositionCenter(sectorShape) {
  39719. // Not change x for center label
  39720. return sectorShape.position === 'center';
  39721. }
  39722. function pieLabelLayout(seriesModel) {
  39723. var data = seriesModel.getData();
  39724. var labelLayoutList = [];
  39725. var cx;
  39726. var cy;
  39727. var hasLabelRotate = false;
  39728. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  39729. var viewRect = data.getLayout('viewRect');
  39730. var r = data.getLayout('r');
  39731. var viewWidth = viewRect.width;
  39732. var viewLeft = viewRect.x;
  39733. var viewTop = viewRect.y;
  39734. var viewHeight = viewRect.height;
  39735. function setNotShow(el) {
  39736. el.ignore = true;
  39737. }
  39738. function isLabelShown(label) {
  39739. if (!label.ignore) {
  39740. return true;
  39741. }
  39742. for (var key in label.states) {
  39743. if (label.states[key].ignore === false) {
  39744. return true;
  39745. }
  39746. }
  39747. return false;
  39748. }
  39749. data.each(function (idx) {
  39750. var sector = data.getItemGraphicEl(idx);
  39751. var sectorShape = sector.shape;
  39752. var label = sector.getTextContent();
  39753. var labelLine = sector.getTextGuideLine();
  39754. var itemModel = data.getItemModel(idx);
  39755. var labelModel = itemModel.getModel('label');
  39756. // Use position in normal or emphasis
  39757. var labelPosition = labelModel.get('position') || itemModel.get(['emphasis', 'label', 'position']);
  39758. var labelDistance = labelModel.get('distanceToLabelLine');
  39759. var labelAlignTo = labelModel.get('alignTo');
  39760. var edgeDistance = parsePercent$1(labelModel.get('edgeDistance'), viewWidth);
  39761. var bleedMargin = labelModel.get('bleedMargin');
  39762. if (bleedMargin == null) {
  39763. // An arbitrary strategy for small viewRect - especial pie is layout in calendar or matrix coord sys.
  39764. bleedMargin = Math.min(viewWidth, viewHeight) > 200 ? 10 : 2;
  39765. }
  39766. var labelLineModel = itemModel.getModel('labelLine');
  39767. var labelLineLen = labelLineModel.get('length');
  39768. labelLineLen = parsePercent$1(labelLineLen, viewWidth);
  39769. var labelLineLen2 = labelLineModel.get('length2');
  39770. labelLineLen2 = parsePercent$1(labelLineLen2, viewWidth);
  39771. if (Math.abs(sectorShape.endAngle - sectorShape.startAngle) < minShowLabelRadian) {
  39772. each(label.states, setNotShow);
  39773. label.ignore = true;
  39774. if (labelLine) {
  39775. each(labelLine.states, setNotShow);
  39776. labelLine.ignore = true;
  39777. }
  39778. return;
  39779. }
  39780. if (!isLabelShown(label)) {
  39781. return;
  39782. }
  39783. var midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2;
  39784. var nx = Math.cos(midAngle);
  39785. var ny = Math.sin(midAngle);
  39786. var textX;
  39787. var textY;
  39788. var linePoints;
  39789. var textAlign;
  39790. cx = sectorShape.cx;
  39791. cy = sectorShape.cy;
  39792. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  39793. if (labelPosition === 'center') {
  39794. textX = sectorShape.cx;
  39795. textY = sectorShape.cy;
  39796. textAlign = 'center';
  39797. } else {
  39798. var x1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * nx : sectorShape.r * nx) + cx;
  39799. var y1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * ny : sectorShape.r * ny) + cy;
  39800. textX = x1 + nx * 3;
  39801. textY = y1 + ny * 3;
  39802. if (!isLabelInside) {
  39803. // For roseType
  39804. var x2 = x1 + nx * (labelLineLen + r - sectorShape.r);
  39805. var y2 = y1 + ny * (labelLineLen + r - sectorShape.r);
  39806. var x3 = x2 + (nx < 0 ? -1 : 1) * labelLineLen2;
  39807. var y3 = y2;
  39808. if (labelAlignTo === 'edge') {
  39809. // Adjust textX because text align of edge is opposite
  39810. textX = nx < 0 ? viewLeft + edgeDistance : viewLeft + viewWidth - edgeDistance;
  39811. } else {
  39812. textX = x3 + (nx < 0 ? -labelDistance : labelDistance);
  39813. }
  39814. textY = y3;
  39815. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  39816. }
  39817. textAlign = isLabelInside ? 'center' : labelAlignTo === 'edge' ? nx > 0 ? 'right' : 'left' : nx > 0 ? 'left' : 'right';
  39818. }
  39819. var PI = Math.PI;
  39820. var labelRotate = 0;
  39821. var rotate = labelModel.get('rotate');
  39822. if (isNumber(rotate)) {
  39823. labelRotate = rotate * (PI / 180);
  39824. } else if (labelPosition === 'center') {
  39825. labelRotate = 0;
  39826. } else if (rotate === 'radial' || rotate === true) {
  39827. var radialAngle = nx < 0 ? -midAngle + PI : -midAngle;
  39828. labelRotate = radialAngle;
  39829. } else if (rotate === 'tangential' && labelPosition !== 'outside' && labelPosition !== 'outer') {
  39830. var rad = Math.atan2(nx, ny);
  39831. if (rad < 0) {
  39832. rad = PI * 2 + rad;
  39833. }
  39834. var isDown = ny > 0;
  39835. if (isDown) {
  39836. rad = PI + rad;
  39837. }
  39838. labelRotate = rad - PI;
  39839. }
  39840. hasLabelRotate = !!labelRotate;
  39841. label.x = textX;
  39842. label.y = textY;
  39843. label.rotation = labelRotate;
  39844. label.setStyle({
  39845. verticalAlign: 'middle'
  39846. });
  39847. // Not sectorShape the inside label
  39848. if (!isLabelInside) {
  39849. var textRect = new BoundingRect(0, 0, 0, 0);
  39850. computeLabelGlobalRect(textRect, label);
  39851. labelLayoutList.push({
  39852. label: label,
  39853. labelLine: labelLine,
  39854. position: labelPosition,
  39855. len: labelLineLen,
  39856. len2: labelLineLen2,
  39857. minTurnAngle: labelLineModel.get('minTurnAngle'),
  39858. maxSurfaceAngle: labelLineModel.get('maxSurfaceAngle'),
  39859. surfaceNormal: new Point(nx, ny),
  39860. linePoints: linePoints,
  39861. textAlign: textAlign,
  39862. labelDistance: labelDistance,
  39863. labelAlignTo: labelAlignTo,
  39864. edgeDistance: edgeDistance,
  39865. bleedMargin: bleedMargin,
  39866. rect: textRect,
  39867. unconstrainedWidth: textRect.width,
  39868. labelStyleWidth: label.style.width
  39869. });
  39870. } else {
  39871. label.setStyle({
  39872. align: textAlign
  39873. });
  39874. var selectState = label.states.select;
  39875. if (selectState) {
  39876. selectState.x += label.x;
  39877. selectState.y += label.y;
  39878. }
  39879. }
  39880. sector.setTextConfig({
  39881. inside: isLabelInside
  39882. });
  39883. });
  39884. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  39885. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
  39886. }
  39887. for (var i = 0; i < labelLayoutList.length; i++) {
  39888. var layout = labelLayoutList[i];
  39889. var label = layout.label;
  39890. var labelLine = layout.labelLine;
  39891. var notShowLabel = isNaN(label.x) || isNaN(label.y);
  39892. if (label) {
  39893. label.setStyle({
  39894. align: layout.textAlign
  39895. });
  39896. if (notShowLabel) {
  39897. each(label.states, setNotShow);
  39898. label.ignore = true;
  39899. }
  39900. var selectState = label.states.select;
  39901. if (selectState) {
  39902. selectState.x += label.x;
  39903. selectState.y += label.y;
  39904. }
  39905. }
  39906. if (labelLine) {
  39907. var linePoints = layout.linePoints;
  39908. if (notShowLabel || !linePoints) {
  39909. each(labelLine.states, setNotShow);
  39910. labelLine.ignore = true;
  39911. } else {
  39912. limitTurnAngle(linePoints, layout.minTurnAngle);
  39913. limitSurfaceAngle(linePoints, layout.surfaceNormal, layout.maxSurfaceAngle);
  39914. labelLine.setShape({
  39915. points: linePoints
  39916. });
  39917. // Set the anchor to the midpoint of sector
  39918. label.__hostTarget.textGuideLineConfig = {
  39919. anchor: new Point(linePoints[0][0], linePoints[0][1])
  39920. };
  39921. }
  39922. }
  39923. }
  39924. }
  39925. /**
  39926. * Piece of pie including Sector, Label, LabelLine
  39927. */
  39928. var PiePiece = /** @class */function (_super) {
  39929. __extends(PiePiece, _super);
  39930. function PiePiece(data, idx, startAngle) {
  39931. var _this = _super.call(this) || this;
  39932. _this.z2 = 2;
  39933. var text = new ZRText();
  39934. _this.setTextContent(text);
  39935. _this.updateData(data, idx, startAngle, true);
  39936. return _this;
  39937. }
  39938. PiePiece.prototype.updateData = function (data, idx, startAngle, firstCreate) {
  39939. var sector = this;
  39940. var seriesModel = data.hostModel;
  39941. var itemModel = data.getItemModel(idx);
  39942. var emphasisModel = itemModel.getModel('emphasis');
  39943. var layout = data.getItemLayout(idx);
  39944. // cornerRadius & innerCornerRadius doesn't exist in the item layout. Use `0` if null value is specified.
  39945. // see `setItemLayout` in `pieLayout.ts`.
  39946. var sectorShape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout);
  39947. // Ignore NaN data.
  39948. if (isNaN(sectorShape.startAngle)) {
  39949. // Use NaN shape to avoid drawing shape.
  39950. sector.setShape(sectorShape);
  39951. return;
  39952. }
  39953. if (firstCreate) {
  39954. sector.setShape(sectorShape);
  39955. var animationType = seriesModel.getShallow('animationType');
  39956. if (seriesModel.ecModel.ssr) {
  39957. // Use scale animation in SSR mode(opacity?)
  39958. // Because CSS SVG animation doesn't support very customized shape animation.
  39959. initProps(sector, {
  39960. scaleX: 0,
  39961. scaleY: 0
  39962. }, seriesModel, {
  39963. dataIndex: idx,
  39964. isFrom: true
  39965. });
  39966. sector.originX = sectorShape.cx;
  39967. sector.originY = sectorShape.cy;
  39968. } else if (animationType === 'scale') {
  39969. sector.shape.r = layout.r0;
  39970. initProps(sector, {
  39971. shape: {
  39972. r: layout.r
  39973. }
  39974. }, seriesModel, idx);
  39975. }
  39976. // Expansion
  39977. else {
  39978. if (startAngle != null) {
  39979. sector.setShape({
  39980. startAngle: startAngle,
  39981. endAngle: startAngle
  39982. });
  39983. initProps(sector, {
  39984. shape: {
  39985. startAngle: layout.startAngle,
  39986. endAngle: layout.endAngle
  39987. }
  39988. }, seriesModel, idx);
  39989. } else {
  39990. sector.shape.endAngle = layout.startAngle;
  39991. updateProps(sector, {
  39992. shape: {
  39993. endAngle: layout.endAngle
  39994. }
  39995. }, seriesModel, idx);
  39996. }
  39997. }
  39998. } else {
  39999. saveOldStyle(sector);
  40000. // Transition animation from the old shape
  40001. updateProps(sector, {
  40002. shape: sectorShape
  40003. }, seriesModel, idx);
  40004. }
  40005. sector.useStyle(data.getItemVisual(idx, 'style'));
  40006. setStatesStylesFromModel(sector, itemModel);
  40007. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  40008. var offset = seriesModel.get('selectedOffset');
  40009. var dx = Math.cos(midAngle) * offset;
  40010. var dy = Math.sin(midAngle) * offset;
  40011. var cursorStyle = itemModel.getShallow('cursor');
  40012. cursorStyle && sector.attr('cursor', cursorStyle);
  40013. this._updateLabel(seriesModel, data, idx);
  40014. sector.ensureState('emphasis').shape = extend({
  40015. r: layout.r + (emphasisModel.get('scale') ? emphasisModel.get('scaleSize') || 0 : 0)
  40016. }, getSectorCornerRadius(emphasisModel.getModel('itemStyle'), layout));
  40017. extend(sector.ensureState('select'), {
  40018. x: dx,
  40019. y: dy,
  40020. shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']), layout)
  40021. });
  40022. extend(sector.ensureState('blur'), {
  40023. shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']), layout)
  40024. });
  40025. var labelLine = sector.getTextGuideLine();
  40026. var labelText = sector.getTextContent();
  40027. labelLine && extend(labelLine.ensureState('select'), {
  40028. x: dx,
  40029. y: dy
  40030. });
  40031. // TODO: needs dx, dy in zrender?
  40032. extend(labelText.ensureState('select'), {
  40033. x: dx,
  40034. y: dy
  40035. });
  40036. toggleHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  40037. };
  40038. PiePiece.prototype._updateLabel = function (seriesModel, data, idx) {
  40039. var sector = this;
  40040. var itemModel = data.getItemModel(idx);
  40041. var labelLineModel = itemModel.getModel('labelLine');
  40042. var style = data.getItemVisual(idx, 'style');
  40043. var visualColor = style && style.fill;
  40044. var visualOpacity = style && style.opacity;
  40045. setLabelStyle(sector, getLabelStatesModels(itemModel), {
  40046. labelFetcher: data.hostModel,
  40047. labelDataIndex: idx,
  40048. inheritColor: visualColor,
  40049. defaultOpacity: visualOpacity,
  40050. defaultText: seriesModel.getFormattedLabel(idx, 'normal') || data.getName(idx)
  40051. });
  40052. var labelText = sector.getTextContent();
  40053. // Set textConfig on sector.
  40054. sector.setTextConfig({
  40055. // reset position, rotation
  40056. position: null,
  40057. rotation: null
  40058. });
  40059. // Make sure update style on labelText after setLabelStyle.
  40060. // Because setLabelStyle will replace a new style on it.
  40061. labelText.attr({
  40062. z2: 10
  40063. });
  40064. var labelPosition = itemModel.get(['label', 'position']);
  40065. if (labelPosition !== 'outside' && labelPosition !== 'outer') {
  40066. sector.removeTextGuideLine();
  40067. } else {
  40068. var polyline = this.getTextGuideLine();
  40069. if (!polyline) {
  40070. polyline = new Polyline();
  40071. this.setTextGuideLine(polyline);
  40072. }
  40073. // Default use item visual color
  40074. setLabelLineStyle(this, getLabelLineStatesModels(itemModel), {
  40075. stroke: visualColor,
  40076. opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1)
  40077. });
  40078. }
  40079. };
  40080. return PiePiece;
  40081. }(Sector);
  40082. // Pie view
  40083. var PieView = /** @class */function (_super) {
  40084. __extends(PieView, _super);
  40085. function PieView() {
  40086. var _this = _super !== null && _super.apply(this, arguments) || this;
  40087. _this.ignoreLabelLineUpdate = true;
  40088. return _this;
  40089. }
  40090. PieView.prototype.render = function (seriesModel, ecModel, api, payload) {
  40091. var data = seriesModel.getData();
  40092. var oldData = this._data;
  40093. var group = this.group;
  40094. var startAngle;
  40095. // First render
  40096. if (!oldData && data.count() > 0) {
  40097. var shape = data.getItemLayout(0);
  40098. for (var s = 1; isNaN(shape && shape.startAngle) && s < data.count(); ++s) {
  40099. shape = data.getItemLayout(s);
  40100. }
  40101. if (shape) {
  40102. startAngle = shape.startAngle;
  40103. }
  40104. }
  40105. // remove empty-circle if it exists
  40106. if (this._emptyCircleSector) {
  40107. group.remove(this._emptyCircleSector);
  40108. }
  40109. // when all data are filtered, show lightgray empty circle
  40110. if (data.count() === 0 && seriesModel.get('showEmptyCircle')) {
  40111. var layoutData = getSeriesLayoutData(seriesModel);
  40112. var sector = new Sector({
  40113. shape: clone(layoutData)
  40114. });
  40115. sector.useStyle(seriesModel.getModel('emptyCircleStyle').getItemStyle());
  40116. this._emptyCircleSector = sector;
  40117. group.add(sector);
  40118. }
  40119. data.diff(oldData).add(function (idx) {
  40120. var piePiece = new PiePiece(data, idx, startAngle);
  40121. data.setItemGraphicEl(idx, piePiece);
  40122. group.add(piePiece);
  40123. }).update(function (newIdx, oldIdx) {
  40124. var piePiece = oldData.getItemGraphicEl(oldIdx);
  40125. piePiece.updateData(data, newIdx, startAngle);
  40126. piePiece.off('click');
  40127. group.add(piePiece);
  40128. data.setItemGraphicEl(newIdx, piePiece);
  40129. }).remove(function (idx) {
  40130. var piePiece = oldData.getItemGraphicEl(idx);
  40131. removeElementWithFadeOut(piePiece, seriesModel, idx);
  40132. }).execute();
  40133. pieLabelLayout(seriesModel);
  40134. // Always use initial animation.
  40135. if (seriesModel.get('animationTypeUpdate') !== 'expansion') {
  40136. this._data = data;
  40137. }
  40138. };
  40139. PieView.prototype.dispose = function () {};
  40140. PieView.prototype.containPoint = function (point, seriesModel) {
  40141. var data = seriesModel.getData();
  40142. var itemLayout = data.getItemLayout(0);
  40143. if (itemLayout) {
  40144. var dx = point[0] - itemLayout.cx;
  40145. var dy = point[1] - itemLayout.cy;
  40146. var radius = Math.sqrt(dx * dx + dy * dy);
  40147. return radius <= itemLayout.r && radius >= itemLayout.r0;
  40148. }
  40149. };
  40150. PieView.type = 'pie';
  40151. return PieView;
  40152. }(ChartView);
  40153. /**
  40154. * [Usage]:
  40155. * (1)
  40156. * createListSimply(seriesModel, ['value']);
  40157. * (2)
  40158. * createListSimply(seriesModel, {
  40159. * coordDimensions: ['value'],
  40160. * dimensionsCount: 5
  40161. * });
  40162. */
  40163. function createSeriesDataSimply(seriesModel, opt, nameList) {
  40164. opt = isArray(opt) && {
  40165. coordDimensions: opt
  40166. } || extend({
  40167. encodeDefine: seriesModel.getEncode()
  40168. }, opt);
  40169. var source = seriesModel.getSource();
  40170. var dimensions = prepareSeriesDataSchema(source, opt).dimensions;
  40171. var list = new SeriesData(dimensions, seriesModel);
  40172. list.initData(source, nameList);
  40173. return list;
  40174. }
  40175. /*
  40176. * Licensed to the Apache Software Foundation (ASF) under one
  40177. * or more contributor license agreements. See the NOTICE file
  40178. * distributed with this work for additional information
  40179. * regarding copyright ownership. The ASF licenses this file
  40180. * to you under the Apache License, Version 2.0 (the
  40181. * "License"); you may not use this file except in compliance
  40182. * with the License. You may obtain a copy of the License at
  40183. *
  40184. * http://www.apache.org/licenses/LICENSE-2.0
  40185. *
  40186. * Unless required by applicable law or agreed to in writing,
  40187. * software distributed under the License is distributed on an
  40188. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40189. * KIND, either express or implied. See the License for the
  40190. * specific language governing permissions and limitations
  40191. * under the License.
  40192. */
  40193. /**
  40194. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40195. */
  40196. /*
  40197. * Licensed to the Apache Software Foundation (ASF) under one
  40198. * or more contributor license agreements. See the NOTICE file
  40199. * distributed with this work for additional information
  40200. * regarding copyright ownership. The ASF licenses this file
  40201. * to you under the Apache License, Version 2.0 (the
  40202. * "License"); you may not use this file except in compliance
  40203. * with the License. You may obtain a copy of the License at
  40204. *
  40205. * http://www.apache.org/licenses/LICENSE-2.0
  40206. *
  40207. * Unless required by applicable law or agreed to in writing,
  40208. * software distributed under the License is distributed on an
  40209. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40210. * KIND, either express or implied. See the License for the
  40211. * specific language governing permissions and limitations
  40212. * under the License.
  40213. */
  40214. /**
  40215. * LegendVisualProvider is an bridge that pick encoded color from data and
  40216. * provide to the legend component.
  40217. */
  40218. var LegendVisualProvider = /** @class */function () {
  40219. function LegendVisualProvider(
  40220. // Function to get data after filtered. It stores all the encoding info
  40221. getDataWithEncodedVisual,
  40222. // Function to get raw data before filtered.
  40223. getRawData) {
  40224. this._getDataWithEncodedVisual = getDataWithEncodedVisual;
  40225. this._getRawData = getRawData;
  40226. }
  40227. LegendVisualProvider.prototype.getAllNames = function () {
  40228. var rawData = this._getRawData();
  40229. // We find the name from the raw data. In case it's filtered by the legend component.
  40230. // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
  40231. return rawData.mapArray(rawData.getName);
  40232. };
  40233. LegendVisualProvider.prototype.containName = function (name) {
  40234. var rawData = this._getRawData();
  40235. return rawData.indexOfName(name) >= 0;
  40236. };
  40237. LegendVisualProvider.prototype.indexOfName = function (name) {
  40238. // Only get data when necessary.
  40239. // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
  40240. // Invoking Series#getData immediately will throw an error.
  40241. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  40242. return dataWithEncodedVisual.indexOfName(name);
  40243. };
  40244. LegendVisualProvider.prototype.getItemVisual = function (dataIndex, key) {
  40245. // Get encoded visual properties from final filtered data.
  40246. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  40247. return dataWithEncodedVisual.getItemVisual(dataIndex, key);
  40248. };
  40249. return LegendVisualProvider;
  40250. }();
  40251. var innerData = makeInner();
  40252. var PieSeriesModel = /** @class */function (_super) {
  40253. __extends(PieSeriesModel, _super);
  40254. function PieSeriesModel() {
  40255. return _super !== null && _super.apply(this, arguments) || this;
  40256. }
  40257. /**
  40258. * @overwrite
  40259. */
  40260. PieSeriesModel.prototype.init = function (option) {
  40261. _super.prototype.init.apply(this, arguments);
  40262. // Enable legend selection for each data item
  40263. // Use a function instead of direct access because data reference may changed
  40264. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  40265. this._defaultLabelLine(option);
  40266. };
  40267. /**
  40268. * @overwrite
  40269. */
  40270. PieSeriesModel.prototype.mergeOption = function () {
  40271. _super.prototype.mergeOption.apply(this, arguments);
  40272. };
  40273. /**
  40274. * @overwrite
  40275. */
  40276. PieSeriesModel.prototype.getInitialData = function () {
  40277. return createSeriesDataSimply(this, {
  40278. coordDimensions: ['value'],
  40279. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  40280. });
  40281. };
  40282. /**
  40283. * @overwrite
  40284. */
  40285. PieSeriesModel.prototype.getDataParams = function (dataIndex) {
  40286. var data = this.getData();
  40287. // update seats when data is changed
  40288. var dataInner = innerData(data);
  40289. var seats = dataInner.seats;
  40290. if (!seats) {
  40291. var valueList_1 = [];
  40292. data.each(data.mapDimension('value'), function (value) {
  40293. valueList_1.push(value);
  40294. });
  40295. seats = dataInner.seats = getPercentSeats(valueList_1, data.hostModel.get('percentPrecision'));
  40296. }
  40297. var params = _super.prototype.getDataParams.call(this, dataIndex);
  40298. // seats may be empty when sum is 0
  40299. params.percent = seats[dataIndex] || 0;
  40300. params.$vars.push('percent');
  40301. return params;
  40302. };
  40303. PieSeriesModel.prototype._defaultLabelLine = function (option) {
  40304. // Extend labelLine emphasis
  40305. defaultEmphasis(option, 'labelLine', ['show']);
  40306. var labelLineNormalOpt = option.labelLine;
  40307. var labelLineEmphasisOpt = option.emphasis.labelLine;
  40308. // Not show label line if `label.normal.show = false`
  40309. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  40310. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  40311. };
  40312. PieSeriesModel.type = 'series.pie';
  40313. PieSeriesModel.defaultOption = {
  40314. // zlevel: 0,
  40315. z: 2,
  40316. legendHoverLink: true,
  40317. colorBy: 'data',
  40318. // 默认全局居中
  40319. center: ['50%', '50%'],
  40320. radius: [0, '50%'],
  40321. // 默认顺时针
  40322. clockwise: true,
  40323. startAngle: 90,
  40324. endAngle: 'auto',
  40325. padAngle: 0,
  40326. // 最小角度改为0
  40327. minAngle: 0,
  40328. // If the angle of a sector less than `minShowLabelAngle`,
  40329. // the label will not be displayed.
  40330. minShowLabelAngle: 0,
  40331. // 选中时扇区偏移量
  40332. selectedOffset: 10,
  40333. // 选择模式,默认关闭,可选single,multiple
  40334. // selectedMode: false,
  40335. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  40336. // roseType: null,
  40337. percentPrecision: 2,
  40338. // If still show when all data zero.
  40339. stillShowZeroSum: true,
  40340. // cursor: null,
  40341. coordinateSystemUsage: 'box',
  40342. left: 0,
  40343. top: 0,
  40344. right: 0,
  40345. bottom: 0,
  40346. width: null,
  40347. height: null,
  40348. label: {
  40349. // color: 'inherit',
  40350. // If rotate around circle
  40351. rotate: 0,
  40352. show: true,
  40353. overflow: 'truncate',
  40354. // 'outer', 'inside', 'center'
  40355. position: 'outer',
  40356. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  40357. alignTo: 'none',
  40358. // Closest distance between label and chart edge.
  40359. // Works only position is 'outer' and alignTo is 'edge'.
  40360. edgeDistance: '25%',
  40361. // Works only position is 'outer' and alignTo is not 'edge'.
  40362. // The default `bleedMargin` is auto determined according to view rect size.
  40363. // bleedMargin: 10,
  40364. // Distance between text and label line.
  40365. distanceToLabelLine: 5
  40366. // formatter: 标签文本格式器,同 tooltip.formatter,不支持异步回调
  40367. // 默认使用全局文本样式,详见 textStyle
  40368. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  40369. },
  40370. // Enabled when label.normal.position is 'outer'
  40371. labelLine: {
  40372. show: true,
  40373. // 引导线两段中的第一段长度
  40374. length: 15,
  40375. // 引导线两段中的第二段长度
  40376. length2: 30,
  40377. smooth: false,
  40378. minTurnAngle: 90,
  40379. maxSurfaceAngle: 90,
  40380. lineStyle: {
  40381. // color: 各异,
  40382. width: 1,
  40383. type: 'solid'
  40384. }
  40385. },
  40386. itemStyle: {
  40387. borderWidth: 1,
  40388. borderJoin: 'round'
  40389. },
  40390. showEmptyCircle: true,
  40391. emptyCircleStyle: {
  40392. color: 'lightgray',
  40393. opacity: 1
  40394. },
  40395. labelLayout: {
  40396. // Hide the overlapped label.
  40397. hideOverlap: true
  40398. },
  40399. emphasis: {
  40400. scale: true,
  40401. scaleSize: 5
  40402. },
  40403. // If use strategy to avoid label overlapping
  40404. avoidLabelOverlap: true,
  40405. // Animation type. Valid values: expansion, scale
  40406. animationType: 'expansion',
  40407. animationDuration: 1000,
  40408. // Animation type when update. Valid values: transition, expansion
  40409. animationTypeUpdate: 'transition',
  40410. animationEasingUpdate: 'cubicInOut',
  40411. animationDurationUpdate: 500,
  40412. animationEasing: 'cubicInOut'
  40413. };
  40414. return PieSeriesModel;
  40415. }(SeriesModel);
  40416. registerLayOutOnCoordSysUsage({
  40417. fullType: PieSeriesModel.type,
  40418. getCoord2: function (model) {
  40419. // Not able to validate `center` type here.
  40420. // But percentage center, such as '12%', is not allowed in this case.
  40421. return model.getShallow('center');
  40422. }
  40423. });
  40424. function negativeDataFilter(seriesType) {
  40425. return {
  40426. seriesType: seriesType,
  40427. reset: function (seriesModel, ecModel) {
  40428. var data = seriesModel.getData();
  40429. data.filterSelf(function (idx) {
  40430. // handle negative value condition
  40431. var valueDim = data.mapDimension('value');
  40432. var curValue = data.get(valueDim, idx);
  40433. if (isNumber(curValue) && !isNaN(curValue) && curValue < 0) {
  40434. return false;
  40435. }
  40436. return true;
  40437. });
  40438. }
  40439. };
  40440. }
  40441. function install$3(registers) {
  40442. registers.registerChartView(PieView);
  40443. registers.registerSeriesModel(PieSeriesModel);
  40444. createLegacyDataSelectAction('pie', registers.registerAction);
  40445. registers.registerLayout(curry(pieLayout, 'pie'));
  40446. registers.registerProcessor(dataFilter('pie'));
  40447. registers.registerProcessor(negativeDataFilter('pie'));
  40448. }
  40449. // For backward compatibility, do not use a margin. Although the labels might touch the edge of
  40450. // the canvas, the chart canvas probably does not have an border or a different background color within a page.
  40451. var OUTER_BOUNDS_DEFAULT = {
  40452. left: 0,
  40453. right: 0,
  40454. top: 0,
  40455. bottom: 0
  40456. };
  40457. var OUTER_BOUNDS_CLAMP_DEFAULT = ['25%', '25%'];
  40458. var GridModel = /** @class */function (_super) {
  40459. __extends(GridModel, _super);
  40460. function GridModel() {
  40461. return _super !== null && _super.apply(this, arguments) || this;
  40462. }
  40463. GridModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  40464. var outerBoundsCp = getLayoutParams(option.outerBounds);
  40465. _super.prototype.mergeDefaultAndTheme.apply(this, arguments);
  40466. if (outerBoundsCp && option.outerBounds) {
  40467. mergeLayoutParam(option.outerBounds, outerBoundsCp);
  40468. }
  40469. };
  40470. GridModel.prototype.mergeOption = function (newOption, ecModel) {
  40471. _super.prototype.mergeOption.apply(this, arguments);
  40472. if (this.option.outerBounds && newOption.outerBounds) {
  40473. mergeLayoutParam(this.option.outerBounds, newOption.outerBounds);
  40474. }
  40475. };
  40476. GridModel.type = 'grid';
  40477. GridModel.dependencies = ['xAxis', 'yAxis'];
  40478. GridModel.layoutMode = 'box';
  40479. GridModel.defaultOption = {
  40480. show: false,
  40481. // zlevel: 0,
  40482. z: 0,
  40483. left: '15%',
  40484. top: 65,
  40485. right: '10%',
  40486. bottom: 80,
  40487. // If grid size contain label
  40488. containLabel: false,
  40489. outerBoundsMode: 'auto',
  40490. outerBounds: OUTER_BOUNDS_DEFAULT,
  40491. outerBoundsContain: 'all',
  40492. outerBoundsClampWidth: OUTER_BOUNDS_CLAMP_DEFAULT[0],
  40493. outerBoundsClampHeight: OUTER_BOUNDS_CLAMP_DEFAULT[1],
  40494. // width: {totalWidth} - left - right,
  40495. // height: {totalHeight} - top - bottom,
  40496. backgroundColor: tokens.color.transparent,
  40497. borderWidth: 1,
  40498. borderColor: tokens.color.neutral30
  40499. };
  40500. return GridModel;
  40501. }(ComponentModel);
  40502. var CartesianAxisModel = /** @class */function (_super) {
  40503. __extends(CartesianAxisModel, _super);
  40504. function CartesianAxisModel() {
  40505. return _super !== null && _super.apply(this, arguments) || this;
  40506. }
  40507. CartesianAxisModel.prototype.getCoordSysModel = function () {
  40508. return this.getReferringComponents('grid', SINGLE_REFERRING).models[0];
  40509. };
  40510. CartesianAxisModel.type = 'cartesian2dAxis';
  40511. return CartesianAxisModel;
  40512. }(ComponentModel);
  40513. mixin(CartesianAxisModel, AxisModelCommonMixin);
  40514. var defaultOption = {
  40515. show: true,
  40516. // zlevel: 0,
  40517. z: 0,
  40518. // Inverse the axis.
  40519. inverse: false,
  40520. // Axis name displayed.
  40521. name: '',
  40522. // 'start' | 'middle' | 'end'
  40523. nameLocation: 'end',
  40524. // By degree. By default auto rotate by nameLocation.
  40525. nameRotate: null,
  40526. nameTruncate: {
  40527. maxWidth: null,
  40528. ellipsis: '...',
  40529. placeholder: '.'
  40530. },
  40531. // Use global text style by default.
  40532. nameTextStyle: {
  40533. // textMargin: never, // The default value will be specified based on `nameLocation`.
  40534. },
  40535. // The gap between axisName and axisLine.
  40536. nameGap: 15,
  40537. // Default `false` to support tooltip.
  40538. silent: false,
  40539. // Default `false` to avoid legacy user event listener fail.
  40540. triggerEvent: false,
  40541. tooltip: {
  40542. show: false
  40543. },
  40544. axisPointer: {},
  40545. axisLine: {
  40546. show: true,
  40547. onZero: true,
  40548. onZeroAxisIndex: null,
  40549. lineStyle: {
  40550. color: tokens.color.axisLine,
  40551. width: 1,
  40552. type: 'solid'
  40553. },
  40554. // The arrow at both ends the the axis.
  40555. symbol: ['none', 'none'],
  40556. symbolSize: [10, 15],
  40557. breakLine: true
  40558. },
  40559. axisTick: {
  40560. show: true,
  40561. // Whether axisTick is inside the grid or outside the grid.
  40562. inside: false,
  40563. // The length of axisTick.
  40564. length: 5,
  40565. lineStyle: {
  40566. width: 1
  40567. }
  40568. },
  40569. axisLabel: {
  40570. show: true,
  40571. // Whether axisLabel is inside the grid or outside the grid.
  40572. inside: false,
  40573. rotate: 0,
  40574. // true | false | null/undefined (auto)
  40575. showMinLabel: null,
  40576. // true | false | null/undefined (auto)
  40577. showMaxLabel: null,
  40578. margin: 8,
  40579. // formatter: null,
  40580. fontSize: 12,
  40581. color: tokens.color.axisLabel,
  40582. // In scenarios like axis labels, when labels text's progression direction matches the label
  40583. // layout direction (e.g., when all letters are in a single line), extra start/end margin is
  40584. // needed to prevent the text from appearing visually joined. In the other case, when lables
  40585. // are stacked (e.g., having rotation or horizontal labels on yAxis), the layout needs to be
  40586. // compact, so NO extra top/bottom margin should be applied.
  40587. textMargin: [0, 3]
  40588. },
  40589. splitLine: {
  40590. show: true,
  40591. showMinLine: true,
  40592. showMaxLine: true,
  40593. lineStyle: {
  40594. color: tokens.color.axisSplitLine,
  40595. width: 1,
  40596. type: 'solid'
  40597. }
  40598. },
  40599. splitArea: {
  40600. show: false,
  40601. areaStyle: {
  40602. color: [tokens.color.backgroundTint, tokens.color.backgroundTransparent]
  40603. }
  40604. },
  40605. breakArea: {
  40606. show: true,
  40607. itemStyle: {
  40608. color: tokens.color.neutral00,
  40609. // Break border color should be darker than the splitLine
  40610. // because it has opacity and should be more prominent
  40611. borderColor: tokens.color.border,
  40612. borderWidth: 1,
  40613. borderType: [3, 3],
  40614. opacity: 0.6
  40615. },
  40616. zigzagAmplitude: 4,
  40617. zigzagMinSpan: 4,
  40618. zigzagMaxSpan: 20,
  40619. zigzagZ: 100,
  40620. expandOnClick: true
  40621. },
  40622. breakLabelLayout: {
  40623. moveOverlap: 'auto'
  40624. }
  40625. };
  40626. var categoryAxis = merge({
  40627. // The gap at both ends of the axis. For categoryAxis, boolean.
  40628. boundaryGap: true,
  40629. // Set false to faster category collection.
  40630. deduplication: null,
  40631. jitter: 0,
  40632. jitterOverlap: true,
  40633. jitterMargin: 2,
  40634. // splitArea: {
  40635. // show: false
  40636. // },
  40637. splitLine: {
  40638. show: false
  40639. },
  40640. axisTick: {
  40641. // If tick is align with label when boundaryGap is true
  40642. alignWithLabel: false,
  40643. interval: 'auto',
  40644. show: 'auto'
  40645. },
  40646. axisLabel: {
  40647. interval: 'auto'
  40648. }
  40649. }, defaultOption);
  40650. var valueAxis = merge({
  40651. boundaryGap: [0, 0],
  40652. axisLine: {
  40653. // Not shown when other axis is categoryAxis in cartesian
  40654. show: 'auto'
  40655. },
  40656. axisTick: {
  40657. // Not shown when other axis is categoryAxis in cartesian
  40658. show: 'auto'
  40659. },
  40660. // TODO
  40661. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  40662. splitNumber: 5,
  40663. minorTick: {
  40664. // Minor tick, not available for cateogry axis.
  40665. show: false,
  40666. // Split number of minor ticks. The value should be in range of (0, 100)
  40667. splitNumber: 5,
  40668. // Length of minor tick
  40669. length: 3,
  40670. // Line style
  40671. lineStyle: {
  40672. // Default to be same with axisTick
  40673. }
  40674. },
  40675. minorSplitLine: {
  40676. show: false,
  40677. lineStyle: {
  40678. color: tokens.color.axisMinorSplitLine,
  40679. width: 1
  40680. }
  40681. }
  40682. }, defaultOption);
  40683. var timeAxis = merge({
  40684. splitNumber: 6,
  40685. axisLabel: {
  40686. // To eliminate labels that are not nice
  40687. showMinLabel: false,
  40688. showMaxLabel: false,
  40689. rich: {
  40690. primary: {
  40691. fontWeight: 'bold'
  40692. }
  40693. }
  40694. },
  40695. splitLine: {
  40696. show: false
  40697. }
  40698. }, valueAxis);
  40699. var logAxis = defaults({
  40700. logBase: 10
  40701. }, valueAxis);
  40702. var axisDefault = {
  40703. category: categoryAxis,
  40704. value: valueAxis,
  40705. time: timeAxis,
  40706. log: logAxis
  40707. };
  40708. /*
  40709. * Licensed to the Apache Software Foundation (ASF) under one
  40710. * or more contributor license agreements. See the NOTICE file
  40711. * distributed with this work for additional information
  40712. * regarding copyright ownership. The ASF licenses this file
  40713. * to you under the Apache License, Version 2.0 (the
  40714. * "License"); you may not use this file except in compliance
  40715. * with the License. You may obtain a copy of the License at
  40716. *
  40717. * http://www.apache.org/licenses/LICENSE-2.0
  40718. *
  40719. * Unless required by applicable law or agreed to in writing,
  40720. * software distributed under the License is distributed on an
  40721. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40722. * KIND, either express or implied. See the License for the
  40723. * specific language governing permissions and limitations
  40724. * under the License.
  40725. */
  40726. /**
  40727. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40728. */
  40729. /*
  40730. * Licensed to the Apache Software Foundation (ASF) under one
  40731. * or more contributor license agreements. See the NOTICE file
  40732. * distributed with this work for additional information
  40733. * regarding copyright ownership. The ASF licenses this file
  40734. * to you under the Apache License, Version 2.0 (the
  40735. * "License"); you may not use this file except in compliance
  40736. * with the License. You may obtain a copy of the License at
  40737. *
  40738. * http://www.apache.org/licenses/LICENSE-2.0
  40739. *
  40740. * Unless required by applicable law or agreed to in writing,
  40741. * software distributed under the License is distributed on an
  40742. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40743. * KIND, either express or implied. See the License for the
  40744. * specific language governing permissions and limitations
  40745. * under the License.
  40746. */
  40747. var AXIS_TYPES = {
  40748. value: 1,
  40749. category: 1,
  40750. time: 1,
  40751. log: 1
  40752. };
  40753. /*
  40754. * Licensed to the Apache Software Foundation (ASF) under one
  40755. * or more contributor license agreements. See the NOTICE file
  40756. * distributed with this work for additional information
  40757. * regarding copyright ownership. The ASF licenses this file
  40758. * to you under the Apache License, Version 2.0 (the
  40759. * "License"); you may not use this file except in compliance
  40760. * with the License. You may obtain a copy of the License at
  40761. *
  40762. * http://www.apache.org/licenses/LICENSE-2.0
  40763. *
  40764. * Unless required by applicable law or agreed to in writing,
  40765. * software distributed under the License is distributed on an
  40766. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40767. * KIND, either express or implied. See the License for the
  40768. * specific language governing permissions and limitations
  40769. * under the License.
  40770. */
  40771. /**
  40772. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40773. */
  40774. /*
  40775. * Licensed to the Apache Software Foundation (ASF) under one
  40776. * or more contributor license agreements. See the NOTICE file
  40777. * distributed with this work for additional information
  40778. * regarding copyright ownership. The ASF licenses this file
  40779. * to you under the Apache License, Version 2.0 (the
  40780. * "License"); you may not use this file except in compliance
  40781. * with the License. You may obtain a copy of the License at
  40782. *
  40783. * http://www.apache.org/licenses/LICENSE-2.0
  40784. *
  40785. * Unless required by applicable law or agreed to in writing,
  40786. * software distributed under the License is distributed on an
  40787. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40788. * KIND, either express or implied. See the License for the
  40789. * specific language governing permissions and limitations
  40790. * under the License.
  40791. */
  40792. var _impl$1 = null;
  40793. function getAxisBreakHelper() {
  40794. return _impl$1;
  40795. }
  40796. /**
  40797. * Generate sub axis model class
  40798. * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
  40799. */
  40800. function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
  40801. each(AXIS_TYPES, function (v, axisType) {
  40802. var defaultOption = merge(merge({}, axisDefault[axisType], true), extraDefaultOption, true);
  40803. var AxisModel = /** @class */function (_super) {
  40804. __extends(AxisModel, _super);
  40805. function AxisModel() {
  40806. var _this = _super !== null && _super.apply(this, arguments) || this;
  40807. _this.type = axisName + 'Axis.' + axisType;
  40808. return _this;
  40809. }
  40810. AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  40811. var layoutMode = fetchLayoutMode(this);
  40812. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  40813. var themeModel = ecModel.getTheme();
  40814. merge(option, themeModel.get(axisType + 'Axis'));
  40815. merge(option, this.getDefaultOption());
  40816. option.type = getAxisType(option);
  40817. if (layoutMode) {
  40818. mergeLayoutParam(option, inputPositionParams, layoutMode);
  40819. }
  40820. };
  40821. AxisModel.prototype.optionUpdated = function () {
  40822. var thisOption = this.option;
  40823. if (thisOption.type === 'category') {
  40824. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  40825. }
  40826. };
  40827. /**
  40828. * Should not be called before all of 'getInitailData' finished.
  40829. * Because categories are collected during initializing data.
  40830. */
  40831. AxisModel.prototype.getCategories = function (rawData) {
  40832. var option = this.option;
  40833. // FIXME
  40834. // warning if called before all of 'getInitailData' finished.
  40835. if (option.type === 'category') {
  40836. if (rawData) {
  40837. return option.data;
  40838. }
  40839. return this.__ordinalMeta.categories;
  40840. }
  40841. };
  40842. AxisModel.prototype.getOrdinalMeta = function () {
  40843. return this.__ordinalMeta;
  40844. };
  40845. AxisModel.prototype.updateAxisBreaks = function (payload) {
  40846. return {
  40847. breaks: []
  40848. };
  40849. };
  40850. AxisModel.type = axisName + 'Axis.' + axisType;
  40851. AxisModel.defaultOption = defaultOption;
  40852. return AxisModel;
  40853. }(BaseAxisModelClass);
  40854. registers.registerComponentModel(AxisModel);
  40855. });
  40856. registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
  40857. }
  40858. function getAxisType(option) {
  40859. // Default axis with data is category axis
  40860. return option.type || (option.data ? 'category' : 'value');
  40861. }
  40862. var Cartesian = /** @class */function () {
  40863. function Cartesian(name) {
  40864. this.type = 'cartesian';
  40865. this._dimList = [];
  40866. this._axes = {};
  40867. this.name = name || '';
  40868. }
  40869. Cartesian.prototype.getAxis = function (dim) {
  40870. return this._axes[dim];
  40871. };
  40872. Cartesian.prototype.getAxes = function () {
  40873. return map(this._dimList, function (dim) {
  40874. return this._axes[dim];
  40875. }, this);
  40876. };
  40877. Cartesian.prototype.getAxesByScale = function (scaleType) {
  40878. scaleType = scaleType.toLowerCase();
  40879. return filter(this.getAxes(), function (axis) {
  40880. return axis.scale.type === scaleType;
  40881. });
  40882. };
  40883. Cartesian.prototype.addAxis = function (axis) {
  40884. var dim = axis.dim;
  40885. this._axes[dim] = axis;
  40886. this._dimList.push(dim);
  40887. };
  40888. return Cartesian;
  40889. }();
  40890. var cartesian2DDimensions = ['x', 'y'];
  40891. function canCalculateAffineTransform(scale) {
  40892. return (scale.type === 'interval' || scale.type === 'time') && !scale.hasBreaks();
  40893. }
  40894. var Cartesian2D = /** @class */function (_super) {
  40895. __extends(Cartesian2D, _super);
  40896. function Cartesian2D() {
  40897. var _this = _super !== null && _super.apply(this, arguments) || this;
  40898. _this.type = 'cartesian2d';
  40899. _this.dimensions = cartesian2DDimensions;
  40900. return _this;
  40901. }
  40902. /**
  40903. * Calculate an affine transform matrix if two axes are time or value.
  40904. * It's mainly for accelartion on the large time series data.
  40905. */
  40906. Cartesian2D.prototype.calcAffineTransform = function () {
  40907. this._transform = this._invTransform = null;
  40908. var xAxisScale = this.getAxis('x').scale;
  40909. var yAxisScale = this.getAxis('y').scale;
  40910. if (!canCalculateAffineTransform(xAxisScale) || !canCalculateAffineTransform(yAxisScale)) {
  40911. return;
  40912. }
  40913. var xScaleExtent = xAxisScale.getExtent();
  40914. var yScaleExtent = yAxisScale.getExtent();
  40915. var start = this.dataToPoint([xScaleExtent[0], yScaleExtent[0]]);
  40916. var end = this.dataToPoint([xScaleExtent[1], yScaleExtent[1]]);
  40917. var xScaleSpan = xScaleExtent[1] - xScaleExtent[0];
  40918. var yScaleSpan = yScaleExtent[1] - yScaleExtent[0];
  40919. if (!xScaleSpan || !yScaleSpan) {
  40920. return;
  40921. }
  40922. // Accelerate data to point calculation on the special large time series data.
  40923. var scaleX = (end[0] - start[0]) / xScaleSpan;
  40924. var scaleY = (end[1] - start[1]) / yScaleSpan;
  40925. var translateX = start[0] - xScaleExtent[0] * scaleX;
  40926. var translateY = start[1] - yScaleExtent[0] * scaleY;
  40927. var m = this._transform = [scaleX, 0, 0, scaleY, translateX, translateY];
  40928. this._invTransform = invert([], m);
  40929. };
  40930. /**
  40931. * Base axis will be used on stacking.
  40932. */
  40933. Cartesian2D.prototype.getBaseAxis = function () {
  40934. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
  40935. };
  40936. Cartesian2D.prototype.containPoint = function (point) {
  40937. var axisX = this.getAxis('x');
  40938. var axisY = this.getAxis('y');
  40939. return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
  40940. };
  40941. Cartesian2D.prototype.containData = function (data) {
  40942. return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
  40943. };
  40944. Cartesian2D.prototype.containZone = function (data1, data2) {
  40945. var zoneDiag1 = this.dataToPoint(data1);
  40946. var zoneDiag2 = this.dataToPoint(data2);
  40947. var area = this.getArea();
  40948. var zone = new BoundingRect(zoneDiag1[0], zoneDiag1[1], zoneDiag2[0] - zoneDiag1[0], zoneDiag2[1] - zoneDiag1[1]);
  40949. return area.intersect(zone);
  40950. };
  40951. Cartesian2D.prototype.dataToPoint = function (data, clamp, out) {
  40952. out = out || [];
  40953. var xVal = data[0];
  40954. var yVal = data[1];
  40955. // [CAVEAT]: Do not add time consuming operation within and before fast path.
  40956. // Fast path.
  40957. if (this._transform
  40958. // It's supported that if data is like `[Inifity, 123]`, where only Y pixel calculated.
  40959. && xVal != null && isFinite(xVal) && yVal != null && isFinite(yVal)) {
  40960. return applyTransform(out, data, this._transform);
  40961. }
  40962. var xAxis = this.getAxis('x');
  40963. var yAxis = this.getAxis('y');
  40964. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(xVal, clamp));
  40965. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(yVal, clamp));
  40966. return out;
  40967. };
  40968. Cartesian2D.prototype.clampData = function (data, out) {
  40969. var xScale = this.getAxis('x').scale;
  40970. var yScale = this.getAxis('y').scale;
  40971. var xAxisExtent = xScale.getExtent();
  40972. var yAxisExtent = yScale.getExtent();
  40973. var x = xScale.parse(data[0]);
  40974. var y = yScale.parse(data[1]);
  40975. out = out || [];
  40976. out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
  40977. out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
  40978. return out;
  40979. };
  40980. Cartesian2D.prototype.pointToData = function (point, clamp, out) {
  40981. out = out || [];
  40982. if (this._invTransform) {
  40983. return applyTransform(out, point, this._invTransform);
  40984. }
  40985. var xAxis = this.getAxis('x');
  40986. var yAxis = this.getAxis('y');
  40987. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp);
  40988. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp);
  40989. return out;
  40990. };
  40991. Cartesian2D.prototype.getOtherAxis = function (axis) {
  40992. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  40993. };
  40994. /**
  40995. * Get rect area of cartesian.
  40996. * Area will have a contain function to determine if a point is in the coordinate system.
  40997. */
  40998. Cartesian2D.prototype.getArea = function (tolerance) {
  40999. tolerance = tolerance || 0;
  41000. var xExtent = this.getAxis('x').getGlobalExtent();
  41001. var yExtent = this.getAxis('y').getGlobalExtent();
  41002. var x = Math.min(xExtent[0], xExtent[1]) - tolerance;
  41003. var y = Math.min(yExtent[0], yExtent[1]) - tolerance;
  41004. var width = Math.max(xExtent[0], xExtent[1]) - x + tolerance;
  41005. var height = Math.max(yExtent[0], yExtent[1]) - y + tolerance;
  41006. return new BoundingRect(x, y, width, height);
  41007. };
  41008. return Cartesian2D;
  41009. }(Cartesian);
  41010. var Axis2D = /** @class */function (_super) {
  41011. __extends(Axis2D, _super);
  41012. function Axis2D(dim, scale, coordExtent, axisType, position) {
  41013. var _this = _super.call(this, dim, scale, coordExtent) || this;
  41014. /**
  41015. * Index of axis, can be used as key
  41016. * Injected outside.
  41017. */
  41018. _this.index = 0;
  41019. _this.type = axisType || 'value';
  41020. _this.position = position || 'bottom';
  41021. return _this;
  41022. }
  41023. Axis2D.prototype.isHorizontal = function () {
  41024. var position = this.position;
  41025. return position === 'top' || position === 'bottom';
  41026. };
  41027. /**
  41028. * Each item cooresponds to this.getExtent(), which
  41029. * means globalExtent[0] may greater than globalExtent[1],
  41030. * unless `asc` is input.
  41031. *
  41032. * @param {boolean} [asc]
  41033. * @return {Array.<number>}
  41034. */
  41035. Axis2D.prototype.getGlobalExtent = function (asc) {
  41036. var ret = this.getExtent();
  41037. ret[0] = this.toGlobalCoord(ret[0]);
  41038. ret[1] = this.toGlobalCoord(ret[1]);
  41039. asc && ret[0] > ret[1] && ret.reverse();
  41040. return ret;
  41041. };
  41042. Axis2D.prototype.pointToData = function (point, clamp) {
  41043. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  41044. };
  41045. /**
  41046. * Set ordinalSortInfo
  41047. * @param info new OrdinalSortInfo
  41048. */
  41049. Axis2D.prototype.setCategorySortInfo = function (info) {
  41050. if (this.type !== 'category') {
  41051. return false;
  41052. }
  41053. this.model.option.categorySortInfo = info;
  41054. this.scale.setSortInfo(info);
  41055. };
  41056. return Axis2D;
  41057. }(Axis);
  41058. var AXIS_BREAK_EXPAND_ACTION_TYPE = 'expandAxisBreak';
  41059. var PI$4 = Math.PI;
  41060. var DEFAULT_CENTER_NAME_MARGIN_LEVELS = [[1, 2, 1, 2], [5, 3, 5, 3], [8, 3, 8, 3]];
  41061. var DEFAULT_ENDS_NAME_MARGIN_LEVELS = [[0, 1, 0, 1], [0, 3, 0, 3], [0, 3, 0, 3]];
  41062. var getLabelInner = makeInner();
  41063. var getTickInner = makeInner();
  41064. /**
  41065. * A context shared by difference axisBuilder instances.
  41066. * For cross-axes overlap resolving.
  41067. *
  41068. * Lifecycle constraint: should not over a pass of ec main process.
  41069. * If model is changed, the context must be disposed.
  41070. *
  41071. * @see AxisBuilderLocalContext
  41072. */
  41073. var AxisBuilderSharedContext = /** @class */function () {
  41074. function AxisBuilderSharedContext(resolveAxisNameOverlap) {
  41075. /**
  41076. * [CAUTION] Do not modify this data structure outside this class.
  41077. */
  41078. this.recordMap = {};
  41079. this.resolveAxisNameOverlap = resolveAxisNameOverlap;
  41080. }
  41081. AxisBuilderSharedContext.prototype.ensureRecord = function (axisModel) {
  41082. var dim = axisModel.axis.dim;
  41083. var idx = axisModel.componentIndex;
  41084. var recordMap = this.recordMap;
  41085. var records = recordMap[dim] || (recordMap[dim] = []);
  41086. return records[idx] || (records[idx] = {
  41087. ready: {}
  41088. });
  41089. };
  41090. return AxisBuilderSharedContext;
  41091. }();
  41092. /**
  41093. * [CAUTION]
  41094. * 1. The call of this function must be after axisLabel overlap handlings
  41095. * (such as `hideOverlap`, `fixMinMaxLabelShow`) and after transform calculating.
  41096. * 2. Can be called multiple times and should be idempotent.
  41097. */
  41098. function resetOverlapRecordToShared(cfg, shared, axisModel, labelLayoutList) {
  41099. var axis = axisModel.axis;
  41100. var record = shared.ensureRecord(axisModel);
  41101. var labelInfoList = [];
  41102. var stOccupiedRect;
  41103. var useStOccupiedRect = hasAxisName(cfg.axisName) && isNameLocationCenter(cfg.nameLocation);
  41104. each(labelLayoutList, function (layout) {
  41105. var layoutInfo = ensureLabelLayoutWithGeometry(layout);
  41106. if (!layoutInfo || layoutInfo.label.ignore) {
  41107. return;
  41108. }
  41109. labelInfoList.push(layoutInfo);
  41110. var transGroup = record.transGroup;
  41111. if (useStOccupiedRect) {
  41112. // Transform to "standard axis" for creating stOccupiedRect (the label rects union).
  41113. transGroup.transform ? invert(_stTransTmp, transGroup.transform) : identity(_stTransTmp);
  41114. if (layoutInfo.transform) {
  41115. mul$1(_stTransTmp, _stTransTmp, layoutInfo.transform);
  41116. }
  41117. BoundingRect.copy(_stLabelRectTmp, layoutInfo.localRect);
  41118. _stLabelRectTmp.applyTransform(_stTransTmp);
  41119. stOccupiedRect ? stOccupiedRect.union(_stLabelRectTmp) : BoundingRect.copy(stOccupiedRect = new BoundingRect(0, 0, 0, 0), _stLabelRectTmp);
  41120. }
  41121. });
  41122. var sortByDim = Math.abs(record.dirVec.x) > 0.1 ? 'x' : 'y';
  41123. var sortByValue = record.transGroup[sortByDim];
  41124. labelInfoList.sort(function (info1, info2) {
  41125. return Math.abs(info1.label[sortByDim] - sortByValue) - Math.abs(info2.label[sortByDim] - sortByValue);
  41126. });
  41127. if (useStOccupiedRect && stOccupiedRect) {
  41128. var extent = axis.getExtent();
  41129. var axisLineX = Math.min(extent[0], extent[1]);
  41130. var axisLineWidth = Math.max(extent[0], extent[1]) - axisLineX;
  41131. // If `nameLocation` is 'middle', enlarge axis labels boundingRect to axisLine to avoid bad
  41132. // case like that axis name is placed in the gap between axis labels and axis line.
  41133. // If only one label exists, the entire band should be occupied for
  41134. // visual consistency, so extent it to [0, canvas width].
  41135. stOccupiedRect.union(new BoundingRect(axisLineX, 0, axisLineWidth, 1));
  41136. }
  41137. record.stOccupiedRect = stOccupiedRect;
  41138. record.labelInfoList = labelInfoList;
  41139. }
  41140. var _stTransTmp = create$1();
  41141. var _stLabelRectTmp = new BoundingRect(0, 0, 0, 0);
  41142. /**
  41143. * The default resolver does not involve other axes within the same coordinate system.
  41144. */
  41145. var resolveAxisNameOverlapDefault = function (cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord) {
  41146. if (isNameLocationCenter(cfg.nameLocation)) {
  41147. var stOccupiedRect = thisRecord.stOccupiedRect;
  41148. if (stOccupiedRect) {
  41149. moveIfOverlap(computeLabelGeometry2({}, stOccupiedRect, thisRecord.transGroup.transform), nameLayoutInfo, nameMoveDirVec);
  41150. }
  41151. } else {
  41152. moveIfOverlapByLinearLabels(thisRecord.labelInfoList, thisRecord.dirVec, nameLayoutInfo, nameMoveDirVec);
  41153. }
  41154. };
  41155. // [NOTICE] not consider ignore.
  41156. function moveIfOverlap(basedLayoutInfo, movableLayoutInfo, moveDirVec) {
  41157. var mtv = new Point();
  41158. if (labelIntersect(basedLayoutInfo, movableLayoutInfo, mtv, {
  41159. direction: Math.atan2(moveDirVec.y, moveDirVec.x),
  41160. bidirectional: false,
  41161. touchThreshold: 0.05
  41162. })) {
  41163. labelLayoutApplyTranslation(movableLayoutInfo, mtv);
  41164. }
  41165. }
  41166. function moveIfOverlapByLinearLabels(baseLayoutInfoList, baseDirVec, movableLayoutInfo, moveDirVec) {
  41167. // Detect and move from far to close.
  41168. var sameDir = Point.dot(moveDirVec, baseDirVec) >= 0;
  41169. for (var idx = 0, len = baseLayoutInfoList.length; idx < len; idx++) {
  41170. var labelInfo = baseLayoutInfoList[sameDir ? idx : len - 1 - idx];
  41171. if (!labelInfo.label.ignore) {
  41172. moveIfOverlap(labelInfo, movableLayoutInfo, moveDirVec);
  41173. }
  41174. }
  41175. }
  41176. /**
  41177. * @caution
  41178. * - Ensure it is called after the data processing stage finished.
  41179. * - It might be called before `CahrtView#render`, sush as called at `CoordinateSystem#update`,
  41180. * thus ensure the result the same whenever it is called.
  41181. *
  41182. * A builder for a straight-line axis.
  41183. *
  41184. * A final axis is translated and rotated from a "standard axis".
  41185. * So opt.position and opt.rotation is required.
  41186. *
  41187. * A "standard axis" is the axis [0,0]-->[abs(axisExtent[1]-axisExtent[0]),0]
  41188. * for example: [0,0]-->[50,0]
  41189. */
  41190. var AxisBuilder = /** @class */function () {
  41191. /**
  41192. * [CAUTION]: axisModel.axis.extent/scale must be ready to use.
  41193. */
  41194. function AxisBuilder(axisModel, api, opt, shared) {
  41195. this.group = new Group();
  41196. this._axisModel = axisModel;
  41197. this._api = api;
  41198. this._local = {};
  41199. this._shared = shared || new AxisBuilderSharedContext(resolveAxisNameOverlapDefault);
  41200. this._resetCfgDetermined(opt);
  41201. }
  41202. /**
  41203. * Regarding axis label related configurations, only the change of label.x/y is supported; other
  41204. * changes are not necessary and not performant. To be specific, only `axis.position`
  41205. * (and consequently `labelOffset`) and `axis.extent` can be changed, and assume everything in
  41206. * `axisModel` are not changed.
  41207. * Axis line related configurations can be changed since this method can only be called
  41208. * before they are created.
  41209. */
  41210. AxisBuilder.prototype.updateCfg = function (opt) {
  41211. if ("development" !== 'production') {
  41212. var ready = this._shared.ensureRecord(this._axisModel).ready;
  41213. // After that, changing cfg is not supported; avoid unnecessary complexity.
  41214. assert(!ready.axisLine && !ready.axisTickLabelDetermine);
  41215. // Have to be called again if cfg changed.
  41216. ready.axisName = ready.axisTickLabelEstimate = false;
  41217. }
  41218. var raw = this._cfg.raw;
  41219. raw.position = opt.position;
  41220. raw.labelOffset = opt.labelOffset;
  41221. this._resetCfgDetermined(raw);
  41222. };
  41223. /**
  41224. * [CAUTION] For debug usage. Never change it outside!
  41225. */
  41226. AxisBuilder.prototype.__getRawCfg = function () {
  41227. return this._cfg.raw;
  41228. };
  41229. AxisBuilder.prototype._resetCfgDetermined = function (raw) {
  41230. var axisModel = this._axisModel;
  41231. // FIXME:
  41232. // Currently there is no uniformed way to set default values if an option
  41233. // is specified null/undefined by user (intentionally or unintentionally),
  41234. // e.g. null/undefined is not a illegal value for `nameLocation`.
  41235. // Try to use `getDefaultOption` to address it. But radar has no `getDefaultOption`.
  41236. var axisModelDefaultOption = axisModel.getDefaultOption ? axisModel.getDefaultOption() : {};
  41237. // Default value
  41238. var axisName = retrieve2(raw.axisName, axisModel.get('name'));
  41239. var nameMoveOverlapOption = axisModel.get('nameMoveOverlap');
  41240. if (nameMoveOverlapOption == null || nameMoveOverlapOption === 'auto') {
  41241. nameMoveOverlapOption = retrieve2(raw.defaultNameMoveOverlap, true);
  41242. }
  41243. var cfg = {
  41244. raw: raw,
  41245. position: raw.position,
  41246. rotation: raw.rotation,
  41247. nameDirection: retrieve2(raw.nameDirection, 1),
  41248. tickDirection: retrieve2(raw.tickDirection, 1),
  41249. labelDirection: retrieve2(raw.labelDirection, 1),
  41250. labelOffset: retrieve2(raw.labelOffset, 0),
  41251. silent: retrieve2(raw.silent, true),
  41252. axisName: axisName,
  41253. nameLocation: retrieve3(axisModel.get('nameLocation'), axisModelDefaultOption.nameLocation, 'end'),
  41254. shouldNameMoveOverlap: hasAxisName(axisName) && nameMoveOverlapOption,
  41255. optionHideOverlap: axisModel.get(['axisLabel', 'hideOverlap']),
  41256. showMinorTicks: axisModel.get(['minorTick', 'show'])
  41257. };
  41258. if ("development" !== 'production') {
  41259. assert(cfg.position != null);
  41260. assert(cfg.rotation != null);
  41261. }
  41262. this._cfg = cfg;
  41263. // FIXME Not use a separate text group?
  41264. var transformGroup = new Group({
  41265. x: cfg.position[0],
  41266. y: cfg.position[1],
  41267. rotation: cfg.rotation
  41268. });
  41269. transformGroup.updateTransform();
  41270. this._transformGroup = transformGroup;
  41271. var record = this._shared.ensureRecord(axisModel);
  41272. record.transGroup = this._transformGroup;
  41273. record.dirVec = new Point(Math.cos(-cfg.rotation), Math.sin(-cfg.rotation));
  41274. };
  41275. AxisBuilder.prototype.build = function (axisPartNameMap, extraParams) {
  41276. var _this = this;
  41277. if (!axisPartNameMap) {
  41278. axisPartNameMap = {
  41279. axisLine: true,
  41280. axisTickLabelEstimate: false,
  41281. axisTickLabelDetermine: true,
  41282. axisName: true
  41283. };
  41284. }
  41285. each(AXIS_BUILDER_AXIS_PART_NAMES, function (partName) {
  41286. if (axisPartNameMap[partName]) {
  41287. builders[partName](_this._cfg, _this._local, _this._shared, _this._axisModel, _this.group, _this._transformGroup, _this._api, extraParams || {});
  41288. }
  41289. });
  41290. return this;
  41291. };
  41292. /**
  41293. * Currently only get text align/verticalAlign by rotation.
  41294. * NO `position` is involved, otherwise it have to be performed for each `updateAxisLabelChangableProps`.
  41295. */
  41296. AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  41297. var rotationDiff = remRadian(textRotation - axisRotation);
  41298. var textAlign;
  41299. var textVerticalAlign;
  41300. if (isRadianAroundZero(rotationDiff)) {
  41301. // Label is parallel with axis line.
  41302. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  41303. textAlign = 'center';
  41304. } else if (isRadianAroundZero(rotationDiff - PI$4)) {
  41305. // Label is inverse parallel with axis line.
  41306. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  41307. textAlign = 'center';
  41308. } else {
  41309. textVerticalAlign = 'middle';
  41310. if (rotationDiff > 0 && rotationDiff < PI$4) {
  41311. textAlign = direction > 0 ? 'right' : 'left';
  41312. } else {
  41313. textAlign = direction > 0 ? 'left' : 'right';
  41314. }
  41315. }
  41316. return {
  41317. rotation: rotationDiff,
  41318. textAlign: textAlign,
  41319. textVerticalAlign: textVerticalAlign
  41320. };
  41321. };
  41322. AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  41323. var eventData = {
  41324. componentType: axisModel.mainType,
  41325. componentIndex: axisModel.componentIndex
  41326. };
  41327. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  41328. return eventData;
  41329. };
  41330. AxisBuilder.isLabelSilent = function (axisModel) {
  41331. var tooltipOpt = axisModel.get('tooltip');
  41332. return axisModel.get('silent')
  41333. // Consider mouse cursor, add these restrictions.
  41334. || !(axisModel.get('triggerEvent') || tooltipOpt && tooltipOpt.show);
  41335. };
  41336. return AxisBuilder;
  41337. }();
  41338. // Sorted by dependency order.
  41339. var AXIS_BUILDER_AXIS_PART_NAMES = ['axisLine', 'axisTickLabelEstimate', 'axisTickLabelDetermine', 'axisName'];
  41340. var builders = {
  41341. axisLine: function (cfg, local, shared, axisModel, group, transformGroup, api) {
  41342. if ("development" !== 'production') {
  41343. var ready = shared.ensureRecord(axisModel).ready;
  41344. assert(!ready.axisLine);
  41345. ready.axisLine = true;
  41346. }
  41347. var shown = axisModel.get(['axisLine', 'show']);
  41348. if (shown === 'auto') {
  41349. shown = true;
  41350. if (cfg.raw.axisLineAutoShow != null) {
  41351. shown = !!cfg.raw.axisLineAutoShow;
  41352. }
  41353. }
  41354. if (!shown) {
  41355. return;
  41356. }
  41357. var extent = axisModel.axis.getExtent();
  41358. var matrix = transformGroup.transform;
  41359. var pt1 = [extent[0], 0];
  41360. var pt2 = [extent[1], 0];
  41361. var inverse = pt1[0] > pt2[0];
  41362. if (matrix) {
  41363. applyTransform(pt1, pt1, matrix);
  41364. applyTransform(pt2, pt2, matrix);
  41365. }
  41366. var lineStyle = extend({
  41367. lineCap: 'round'
  41368. }, axisModel.getModel(['axisLine', 'lineStyle']).getLineStyle());
  41369. var pathBaseProp = {
  41370. strokeContainThreshold: cfg.raw.strokeContainThreshold || 5,
  41371. silent: true,
  41372. z2: 1,
  41373. style: lineStyle
  41374. };
  41375. if (axisModel.get(['axisLine', 'breakLine']) && axisModel.axis.scale.hasBreaks()) {
  41376. getAxisBreakHelper().buildAxisBreakLine(axisModel, group, transformGroup, pathBaseProp);
  41377. } else {
  41378. var line = new Line(extend({
  41379. shape: {
  41380. x1: pt1[0],
  41381. y1: pt1[1],
  41382. x2: pt2[0],
  41383. y2: pt2[1]
  41384. }
  41385. }, pathBaseProp));
  41386. subPixelOptimizeLine$1(line.shape, line.style.lineWidth);
  41387. line.anid = 'line';
  41388. group.add(line);
  41389. }
  41390. var arrows = axisModel.get(['axisLine', 'symbol']);
  41391. if (arrows != null) {
  41392. var arrowSize = axisModel.get(['axisLine', 'symbolSize']);
  41393. if (isString(arrows)) {
  41394. // Use the same arrow for start and end point
  41395. arrows = [arrows, arrows];
  41396. }
  41397. if (isString(arrowSize) || isNumber(arrowSize)) {
  41398. // Use the same size for width and height
  41399. arrowSize = [arrowSize, arrowSize];
  41400. }
  41401. var arrowOffset = normalizeSymbolOffset(axisModel.get(['axisLine', 'symbolOffset']) || 0, arrowSize);
  41402. var symbolWidth_1 = arrowSize[0];
  41403. var symbolHeight_1 = arrowSize[1];
  41404. each([{
  41405. rotate: cfg.rotation + Math.PI / 2,
  41406. offset: arrowOffset[0],
  41407. r: 0
  41408. }, {
  41409. rotate: cfg.rotation - Math.PI / 2,
  41410. offset: arrowOffset[1],
  41411. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  41412. }], function (point, index) {
  41413. if (arrows[index] !== 'none' && arrows[index] != null) {
  41414. var symbol = createSymbol(arrows[index], -symbolWidth_1 / 2, -symbolHeight_1 / 2, symbolWidth_1, symbolHeight_1, lineStyle.stroke, true);
  41415. // Calculate arrow position with offset
  41416. var r = point.r + point.offset;
  41417. var pt = inverse ? pt2 : pt1;
  41418. symbol.attr({
  41419. rotation: point.rotate,
  41420. x: pt[0] + r * Math.cos(cfg.rotation),
  41421. y: pt[1] - r * Math.sin(cfg.rotation),
  41422. silent: true,
  41423. z2: 11
  41424. });
  41425. group.add(symbol);
  41426. }
  41427. });
  41428. }
  41429. },
  41430. /**
  41431. * [CAUTION] This method can be called multiple times, following the change due to `resetCfg` called
  41432. * in size measurement. Thus this method should be idempotent, and should be performant.
  41433. */
  41434. axisTickLabelEstimate: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  41435. if ("development" !== 'production') {
  41436. var ready = shared.ensureRecord(axisModel).ready;
  41437. assert(!ready.axisTickLabelDetermine);
  41438. ready.axisTickLabelEstimate = true;
  41439. }
  41440. var needCallLayout = dealLastTickLabelResultReusable(local, group, extraParams);
  41441. if (needCallLayout) {
  41442. layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, AxisTickLabelComputingKind.estimate);
  41443. }
  41444. },
  41445. /**
  41446. * Finish axis tick label build.
  41447. * Can be only called once.
  41448. */
  41449. axisTickLabelDetermine: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  41450. if ("development" !== 'production') {
  41451. var ready = shared.ensureRecord(axisModel).ready;
  41452. ready.axisTickLabelDetermine = true;
  41453. }
  41454. var needCallLayout = dealLastTickLabelResultReusable(local, group, extraParams);
  41455. if (needCallLayout) {
  41456. layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, AxisTickLabelComputingKind.determine);
  41457. }
  41458. var ticksEls = buildAxisMajorTicks(cfg, group, transformGroup, axisModel);
  41459. syncLabelIgnoreToMajorTicks(cfg, local.labelLayoutList, ticksEls);
  41460. buildAxisMinorTicks(cfg, group, transformGroup, axisModel, cfg.tickDirection);
  41461. },
  41462. /**
  41463. * [CAUTION] This method can be called multiple times, following the change due to `resetCfg` called
  41464. * in size measurement. Thus this method should be idempotent, and should be performant.
  41465. */
  41466. axisName: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  41467. var sharedRecord = shared.ensureRecord(axisModel);
  41468. if ("development" !== 'production') {
  41469. var ready = sharedRecord.ready;
  41470. assert(ready.axisTickLabelEstimate || ready.axisTickLabelDetermine);
  41471. ready.axisName = true;
  41472. }
  41473. // Remove the existing name result created in estimation phase.
  41474. if (local.nameEl) {
  41475. group.remove(local.nameEl);
  41476. local.nameEl = sharedRecord.nameLayout = sharedRecord.nameLocation = null;
  41477. }
  41478. var name = cfg.axisName;
  41479. if (!hasAxisName(name)) {
  41480. return;
  41481. }
  41482. var nameLocation = cfg.nameLocation;
  41483. var nameDirection = cfg.nameDirection;
  41484. var textStyleModel = axisModel.getModel('nameTextStyle');
  41485. var gap = axisModel.get('nameGap') || 0;
  41486. var extent = axisModel.axis.getExtent();
  41487. var gapStartEndSignal = axisModel.axis.inverse ? -1 : 1;
  41488. var pos = new Point(0, 0);
  41489. var nameMoveDirVec = new Point(0, 0);
  41490. if (nameLocation === 'start') {
  41491. pos.x = extent[0] - gapStartEndSignal * gap;
  41492. nameMoveDirVec.x = -gapStartEndSignal;
  41493. } else if (nameLocation === 'end') {
  41494. pos.x = extent[1] + gapStartEndSignal * gap;
  41495. nameMoveDirVec.x = gapStartEndSignal;
  41496. } else {
  41497. // 'middle' or 'center'
  41498. pos.x = (extent[0] + extent[1]) / 2;
  41499. pos.y = cfg.labelOffset + nameDirection * gap;
  41500. nameMoveDirVec.y = nameDirection;
  41501. }
  41502. var mt = create$1();
  41503. nameMoveDirVec.transform(rotate(mt, mt, cfg.rotation));
  41504. var nameRotation = axisModel.get('nameRotate');
  41505. if (nameRotation != null) {
  41506. nameRotation = nameRotation * PI$4 / 180; // To radian.
  41507. }
  41508. var labelLayout;
  41509. var axisNameAvailableWidth;
  41510. if (isNameLocationCenter(nameLocation)) {
  41511. labelLayout = AxisBuilder.innerTextLayout(cfg.rotation, nameRotation != null ? nameRotation : cfg.rotation,
  41512. // Adapt to axis.
  41513. nameDirection);
  41514. } else {
  41515. labelLayout = endTextLayout(cfg.rotation, nameLocation, nameRotation || 0, extent);
  41516. axisNameAvailableWidth = cfg.raw.axisNameAvailableWidth;
  41517. if (axisNameAvailableWidth != null) {
  41518. axisNameAvailableWidth = Math.abs(axisNameAvailableWidth / Math.sin(labelLayout.rotation));
  41519. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  41520. }
  41521. }
  41522. var textFont = textStyleModel.getFont();
  41523. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  41524. var ellipsis = truncateOpt.ellipsis;
  41525. var maxWidth = retrieve(cfg.raw.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth);
  41526. var nameMarginLevel = extraParams.nameMarginLevel || 0;
  41527. var textEl = new ZRText({
  41528. x: pos.x,
  41529. y: pos.y,
  41530. rotation: labelLayout.rotation,
  41531. silent: AxisBuilder.isLabelSilent(axisModel),
  41532. style: createTextStyle(textStyleModel, {
  41533. text: name,
  41534. font: textFont,
  41535. overflow: 'truncate',
  41536. width: maxWidth,
  41537. ellipsis: ellipsis,
  41538. fill: textStyleModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']),
  41539. align: textStyleModel.get('align') || labelLayout.textAlign,
  41540. verticalAlign: textStyleModel.get('verticalAlign') || labelLayout.textVerticalAlign
  41541. }),
  41542. z2: 1
  41543. });
  41544. setTooltipConfig({
  41545. el: textEl,
  41546. componentModel: axisModel,
  41547. itemName: name
  41548. });
  41549. textEl.__fullText = name;
  41550. // Id for animation
  41551. textEl.anid = 'name';
  41552. if (axisModel.get('triggerEvent')) {
  41553. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  41554. eventData.targetType = 'axisName';
  41555. eventData.name = name;
  41556. getECData(textEl).eventData = eventData;
  41557. }
  41558. transformGroup.add(textEl);
  41559. textEl.updateTransform();
  41560. local.nameEl = textEl;
  41561. var nameLayout = sharedRecord.nameLayout = ensureLabelLayoutWithGeometry({
  41562. label: textEl,
  41563. priority: textEl.z2,
  41564. defaultAttr: {
  41565. ignore: textEl.ignore
  41566. },
  41567. marginDefault: isNameLocationCenter(nameLocation)
  41568. // Make axis name visually far from axis labels.
  41569. // (but not too aggressive, consider multiple small charts)
  41570. ? DEFAULT_CENTER_NAME_MARGIN_LEVELS[nameMarginLevel]
  41571. // top/button margin is set to `0` to inserted the xAxis name into the indention
  41572. // above the axis labels to save space. (see example below.)
  41573. : DEFAULT_ENDS_NAME_MARGIN_LEVELS[nameMarginLevel]
  41574. });
  41575. sharedRecord.nameLocation = nameLocation;
  41576. group.add(textEl);
  41577. textEl.decomposeTransform();
  41578. if (cfg.shouldNameMoveOverlap && nameLayout) {
  41579. var record = shared.ensureRecord(axisModel);
  41580. if ("development" !== 'production') {
  41581. assert(record.labelInfoList);
  41582. }
  41583. shared.resolveAxisNameOverlap(cfg, shared, axisModel, nameLayout, nameMoveDirVec, record);
  41584. }
  41585. }
  41586. };
  41587. function layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, kind) {
  41588. if (!axisLabelBuildResultExists(local)) {
  41589. buildAxisLabel(cfg, local, group, kind, axisModel, api);
  41590. }
  41591. var labelLayoutList = local.labelLayoutList;
  41592. updateAxisLabelChangableProps(cfg, axisModel, labelLayoutList, transformGroup);
  41593. adjustBreakLabels(axisModel, cfg.rotation);
  41594. var optionHideOverlap = cfg.optionHideOverlap;
  41595. fixMinMaxLabelShow(axisModel, labelLayoutList, optionHideOverlap);
  41596. if (optionHideOverlap) {
  41597. // This bit fixes the label overlap issue for the time chart.
  41598. // See https://github.com/apache/echarts/issues/14266 for more.
  41599. hideOverlap(
  41600. // Filter the already ignored labels by the previous overlap resolving methods.
  41601. filter(labelLayoutList, function (layout) {
  41602. return layout && !layout.label.ignore;
  41603. }));
  41604. }
  41605. // Always call it even this axis has no name, since it serves in overlapping detection
  41606. // and grid outerBounds on other axis.
  41607. resetOverlapRecordToShared(cfg, shared, axisModel, labelLayoutList);
  41608. }
  41609. function endTextLayout(rotation, textPosition, textRotate, extent) {
  41610. var rotationDiff = remRadian(textRotate - rotation);
  41611. var textAlign;
  41612. var textVerticalAlign;
  41613. var inverse = extent[0] > extent[1];
  41614. var onLeft = textPosition === 'start' && !inverse || textPosition !== 'start' && inverse;
  41615. if (isRadianAroundZero(rotationDiff - PI$4 / 2)) {
  41616. textVerticalAlign = onLeft ? 'bottom' : 'top';
  41617. textAlign = 'center';
  41618. } else if (isRadianAroundZero(rotationDiff - PI$4 * 1.5)) {
  41619. textVerticalAlign = onLeft ? 'top' : 'bottom';
  41620. textAlign = 'center';
  41621. } else {
  41622. textVerticalAlign = 'middle';
  41623. if (rotationDiff < PI$4 * 1.5 && rotationDiff > PI$4 / 2) {
  41624. textAlign = onLeft ? 'left' : 'right';
  41625. } else {
  41626. textAlign = onLeft ? 'right' : 'left';
  41627. }
  41628. }
  41629. return {
  41630. rotation: rotationDiff,
  41631. textAlign: textAlign,
  41632. textVerticalAlign: textVerticalAlign
  41633. };
  41634. }
  41635. /**
  41636. * Assume `labelLayoutList` has no `label.ignore: true`.
  41637. * Assume `labelLayoutList` have been sorted by value ascending order.
  41638. */
  41639. function fixMinMaxLabelShow(axisModel, labelLayoutList, optionHideOverlap) {
  41640. if (shouldShowAllLabels(axisModel.axis)) {
  41641. return;
  41642. }
  41643. // FIXME
  41644. // Have not consider onBand yet, where tick els is more than label els.
  41645. // Assert no ignore in labels.
  41646. function deal(showMinMaxLabel, outmostLabelIdx, innerLabelIdx) {
  41647. var outmostLabelLayout = ensureLabelLayoutWithGeometry(labelLayoutList[outmostLabelIdx]);
  41648. var innerLabelLayout = ensureLabelLayoutWithGeometry(labelLayoutList[innerLabelIdx]);
  41649. if (!outmostLabelLayout || !innerLabelLayout) {
  41650. return;
  41651. }
  41652. if (showMinMaxLabel === false || outmostLabelLayout.suggestIgnore) {
  41653. ignoreEl(outmostLabelLayout.label);
  41654. return;
  41655. }
  41656. if (innerLabelLayout.suggestIgnore) {
  41657. ignoreEl(innerLabelLayout.label);
  41658. return;
  41659. }
  41660. // PENDING: Originally we thought `optionHideOverlap === false` means do not hide anything,
  41661. // since currently the bounding rect of text might not accurate enough and might slightly bigger,
  41662. // which causes false positive. But `optionHideOverlap: null/undfined` is falsy and likely
  41663. // be treated as false.
  41664. // In most fonts the glyph does not reach the boundary of the bounding rect.
  41665. // This is needed to avoid too aggressive to hide two elements that meet at the edge
  41666. // due to compact layout by the same bounding rect or OBB.
  41667. var touchThreshold = 0.1;
  41668. // This treatment is for backward compatibility. And `!optionHideOverlap` implies that
  41669. // the user accepts the visual touch between adjacent labels, thus "hide min/max label"
  41670. // should be conservative, since the space might be sufficient in this case.
  41671. if (!optionHideOverlap) {
  41672. var marginForce = [0, 0, 0, 0];
  41673. // Make a copy to apply `ignoreMargin`.
  41674. outmostLabelLayout = newLabelLayoutWithGeometry({
  41675. marginForce: marginForce
  41676. }, outmostLabelLayout);
  41677. innerLabelLayout = newLabelLayoutWithGeometry({
  41678. marginForce: marginForce
  41679. }, innerLabelLayout);
  41680. }
  41681. if (labelIntersect(outmostLabelLayout, innerLabelLayout, null, {
  41682. touchThreshold: touchThreshold
  41683. })) {
  41684. if (showMinMaxLabel) {
  41685. ignoreEl(innerLabelLayout.label);
  41686. } else {
  41687. ignoreEl(outmostLabelLayout.label);
  41688. }
  41689. }
  41690. }
  41691. // If min or max are user set, we need to check
  41692. // If the tick on min(max) are overlap on their neighbour tick
  41693. // If they are overlapped, we need to hide the min(max) tick label
  41694. var showMinLabel = axisModel.get(['axisLabel', 'showMinLabel']);
  41695. var showMaxLabel = axisModel.get(['axisLabel', 'showMaxLabel']);
  41696. var labelsLen = labelLayoutList.length;
  41697. deal(showMinLabel, 0, 1);
  41698. deal(showMaxLabel, labelsLen - 1, labelsLen - 2);
  41699. }
  41700. // PENDING: Is it necessary to display a tick while the corresponding label is ignored?
  41701. function syncLabelIgnoreToMajorTicks(cfg, labelLayoutList, tickEls) {
  41702. if (cfg.showMinorTicks) {
  41703. // It probably unreaasonable to hide major ticks when show minor ticks.
  41704. return;
  41705. }
  41706. each(labelLayoutList, function (labelLayout) {
  41707. if (labelLayout && labelLayout.label.ignore) {
  41708. for (var idx = 0; idx < tickEls.length; idx++) {
  41709. var tickEl = tickEls[idx];
  41710. // Assume small array, linear search is fine for performance.
  41711. // PENDING: measure?
  41712. var tickInner = getTickInner(tickEl);
  41713. var labelInner = getLabelInner(labelLayout.label);
  41714. if (tickInner.tickValue != null && !tickInner.onBand && tickInner.tickValue === labelInner.tickValue) {
  41715. ignoreEl(tickEl);
  41716. return;
  41717. }
  41718. }
  41719. }
  41720. });
  41721. }
  41722. function ignoreEl(el) {
  41723. el && (el.ignore = true);
  41724. }
  41725. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, anidPrefix) {
  41726. var tickEls = [];
  41727. var pt1 = [];
  41728. var pt2 = [];
  41729. for (var i = 0; i < ticksCoords.length; i++) {
  41730. var tickCoord = ticksCoords[i].coord;
  41731. pt1[0] = tickCoord;
  41732. pt1[1] = 0;
  41733. pt2[0] = tickCoord;
  41734. pt2[1] = tickEndCoord;
  41735. if (tickTransform) {
  41736. applyTransform(pt1, pt1, tickTransform);
  41737. applyTransform(pt2, pt2, tickTransform);
  41738. }
  41739. // Tick line, Not use group transform to have better line draw
  41740. var tickEl = new Line({
  41741. shape: {
  41742. x1: pt1[0],
  41743. y1: pt1[1],
  41744. x2: pt2[0],
  41745. y2: pt2[1]
  41746. },
  41747. style: tickLineStyle,
  41748. z2: 2,
  41749. autoBatch: true,
  41750. silent: true
  41751. });
  41752. subPixelOptimizeLine$1(tickEl.shape, tickEl.style.lineWidth);
  41753. tickEl.anid = anidPrefix + '_' + ticksCoords[i].tickValue;
  41754. tickEls.push(tickEl);
  41755. var inner = getTickInner(tickEl);
  41756. inner.onBand = !!ticksCoords[i].onBand;
  41757. inner.tickValue = ticksCoords[i].tickValue;
  41758. }
  41759. return tickEls;
  41760. }
  41761. function buildAxisMajorTicks(cfg, group, transformGroup, axisModel) {
  41762. var axis = axisModel.axis;
  41763. var tickModel = axisModel.getModel('axisTick');
  41764. var shown = tickModel.get('show');
  41765. if (shown === 'auto') {
  41766. shown = true;
  41767. if (cfg.raw.axisTickAutoShow != null) {
  41768. shown = !!cfg.raw.axisTickAutoShow;
  41769. }
  41770. }
  41771. if (!shown || axis.scale.isBlank()) {
  41772. return [];
  41773. }
  41774. var lineStyleModel = tickModel.getModel('lineStyle');
  41775. var tickEndCoord = cfg.tickDirection * tickModel.get('length');
  41776. var ticksCoords = axis.getTicksCoords();
  41777. var ticksEls = createTicks(ticksCoords, transformGroup.transform, tickEndCoord, defaults(lineStyleModel.getLineStyle(), {
  41778. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  41779. }), 'ticks');
  41780. for (var i = 0; i < ticksEls.length; i++) {
  41781. group.add(ticksEls[i]);
  41782. }
  41783. return ticksEls;
  41784. }
  41785. function buildAxisMinorTicks(cfg, group, transformGroup, axisModel, tickDirection) {
  41786. var axis = axisModel.axis;
  41787. var minorTickModel = axisModel.getModel('minorTick');
  41788. if (!cfg.showMinorTicks || axis.scale.isBlank()) {
  41789. return;
  41790. }
  41791. var minorTicksCoords = axis.getMinorTicksCoords();
  41792. if (!minorTicksCoords.length) {
  41793. return;
  41794. }
  41795. var lineStyleModel = minorTickModel.getModel('lineStyle');
  41796. var tickEndCoord = tickDirection * minorTickModel.get('length');
  41797. var minorTickLineStyle = defaults(lineStyleModel.getLineStyle(), defaults(axisModel.getModel('axisTick').getLineStyle(), {
  41798. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  41799. }));
  41800. for (var i = 0; i < minorTicksCoords.length; i++) {
  41801. var minorTicksEls = createTicks(minorTicksCoords[i], transformGroup.transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i);
  41802. for (var k = 0; k < minorTicksEls.length; k++) {
  41803. group.add(minorTicksEls[k]);
  41804. }
  41805. }
  41806. }
  41807. // Return whether need to call `layOutAxisTickLabel` again.
  41808. function dealLastTickLabelResultReusable(local, group, extraParams) {
  41809. if (axisLabelBuildResultExists(local)) {
  41810. var axisLabelsCreationContext = local.axisLabelsCreationContext;
  41811. if ("development" !== 'production') {
  41812. assert(local.labelGroup && axisLabelsCreationContext);
  41813. }
  41814. var noPxChangeTryDetermine = axisLabelsCreationContext.out.noPxChangeTryDetermine;
  41815. if (extraParams.noPxChange) {
  41816. var canDetermine = true;
  41817. for (var idx = 0; idx < noPxChangeTryDetermine.length; idx++) {
  41818. canDetermine = canDetermine && noPxChangeTryDetermine[idx]();
  41819. }
  41820. if (canDetermine) {
  41821. return false;
  41822. }
  41823. }
  41824. if (noPxChangeTryDetermine.length) {
  41825. // Remove the result of `buildAxisLabel`
  41826. group.remove(local.labelGroup);
  41827. axisLabelBuildResultSet(local, null, null, null);
  41828. }
  41829. }
  41830. return true;
  41831. }
  41832. function buildAxisLabel(cfg, local, group, kind, axisModel, api) {
  41833. var axis = axisModel.axis;
  41834. var show = retrieve(cfg.raw.axisLabelShow, axisModel.get(['axisLabel', 'show']));
  41835. var labelGroup = new Group();
  41836. group.add(labelGroup);
  41837. var axisLabelCreationCtx = createAxisLabelsComputingContext(kind);
  41838. if (!show || axis.scale.isBlank()) {
  41839. axisLabelBuildResultSet(local, [], labelGroup, axisLabelCreationCtx);
  41840. return;
  41841. }
  41842. var labelModel = axisModel.getModel('axisLabel');
  41843. var labels = axis.getViewLabels(axisLabelCreationCtx);
  41844. // Special label rotate.
  41845. var labelRotation = (retrieve(cfg.raw.labelRotate, labelModel.get('rotate')) || 0) * PI$4 / 180;
  41846. var labelLayout = AxisBuilder.innerTextLayout(cfg.rotation, labelRotation, cfg.labelDirection);
  41847. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  41848. var labelEls = [];
  41849. var triggerEvent = axisModel.get('triggerEvent');
  41850. var z2Min = Infinity;
  41851. var z2Max = -Infinity;
  41852. each(labels, function (labelItem, index) {
  41853. var _a;
  41854. var tickValue = axis.scale.type === 'ordinal' ? axis.scale.getRawOrdinalNumber(labelItem.tickValue) : labelItem.tickValue;
  41855. var formattedLabel = labelItem.formattedLabel;
  41856. var rawLabel = labelItem.rawLabel;
  41857. var itemLabelModel = labelModel;
  41858. if (rawCategoryData && rawCategoryData[tickValue]) {
  41859. var rawCategoryItem = rawCategoryData[tickValue];
  41860. if (isObject(rawCategoryItem) && rawCategoryItem.textStyle) {
  41861. itemLabelModel = new Model(rawCategoryItem.textStyle, labelModel, axisModel.ecModel);
  41862. }
  41863. }
  41864. var textColor = itemLabelModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']);
  41865. var align = itemLabelModel.getShallow('align', true) || labelLayout.textAlign;
  41866. var alignMin = retrieve2(itemLabelModel.getShallow('alignMinLabel', true), align);
  41867. var alignMax = retrieve2(itemLabelModel.getShallow('alignMaxLabel', true), align);
  41868. var verticalAlign = itemLabelModel.getShallow('verticalAlign', true) || itemLabelModel.getShallow('baseline', true) || labelLayout.textVerticalAlign;
  41869. var verticalAlignMin = retrieve2(itemLabelModel.getShallow('verticalAlignMinLabel', true), verticalAlign);
  41870. var verticalAlignMax = retrieve2(itemLabelModel.getShallow('verticalAlignMaxLabel', true), verticalAlign);
  41871. var z2 = 10 + (((_a = labelItem.time) === null || _a === void 0 ? void 0 : _a.level) || 0);
  41872. z2Min = Math.min(z2Min, z2);
  41873. z2Max = Math.max(z2Max, z2);
  41874. var textEl = new ZRText({
  41875. // --- transform props start ---
  41876. // All of the transform props MUST not be set here, but should be set in
  41877. // `updateAxisLabelChangableProps`, because they may change in estimation,
  41878. // and need to calculate based on global coord sys by `decomposeTransform`.
  41879. x: 0,
  41880. y: 0,
  41881. rotation: 0,
  41882. // --- transform props end ---
  41883. silent: AxisBuilder.isLabelSilent(axisModel),
  41884. z2: z2,
  41885. style: createTextStyle(itemLabelModel, {
  41886. text: formattedLabel,
  41887. align: index === 0 ? alignMin : index === labels.length - 1 ? alignMax : align,
  41888. verticalAlign: index === 0 ? verticalAlignMin : index === labels.length - 1 ? verticalAlignMax : verticalAlign,
  41889. fill: isFunction(textColor) ? textColor(
  41890. // (1) In category axis with data zoom, tick is not the original
  41891. // index of axis.data. So tick should not be exposed to user
  41892. // in category axis.
  41893. // (2) Compatible with previous version, which always use formatted label as
  41894. // input. But in interval scale the formatted label is like '223,445', which
  41895. // maked user replace ','. So we modify it to return original val but remain
  41896. // it as 'string' to avoid error in replacing.
  41897. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue, index) : textColor
  41898. })
  41899. });
  41900. textEl.anid = 'label_' + tickValue;
  41901. var inner = getLabelInner(textEl);
  41902. inner["break"] = labelItem["break"];
  41903. inner.tickValue = tickValue;
  41904. inner.layoutRotation = labelLayout.rotation;
  41905. setTooltipConfig({
  41906. el: textEl,
  41907. componentModel: axisModel,
  41908. itemName: formattedLabel,
  41909. formatterParamsExtra: {
  41910. isTruncated: function () {
  41911. return textEl.isTruncated;
  41912. },
  41913. value: rawLabel,
  41914. tickIndex: index
  41915. }
  41916. });
  41917. // Pack data for mouse event
  41918. if (triggerEvent) {
  41919. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  41920. eventData.targetType = 'axisLabel';
  41921. eventData.value = rawLabel;
  41922. eventData.tickIndex = index;
  41923. if (labelItem["break"]) {
  41924. eventData["break"] = {
  41925. // type: labelItem.break.type,
  41926. start: labelItem["break"].parsedBreak.vmin,
  41927. end: labelItem["break"].parsedBreak.vmax
  41928. };
  41929. }
  41930. if (axis.type === 'category') {
  41931. eventData.dataIndex = tickValue;
  41932. }
  41933. getECData(textEl).eventData = eventData;
  41934. if (labelItem["break"]) {
  41935. addBreakEventHandler(axisModel, api, textEl, labelItem["break"]);
  41936. }
  41937. }
  41938. labelEls.push(textEl);
  41939. labelGroup.add(textEl);
  41940. });
  41941. var labelLayoutList = map(labelEls, function (label) {
  41942. return {
  41943. label: label,
  41944. priority: getLabelInner(label)["break"] ? label.z2 + (z2Max - z2Min + 1) // Make break labels be highest priority.
  41945. : label.z2,
  41946. defaultAttr: {
  41947. ignore: label.ignore
  41948. }
  41949. };
  41950. });
  41951. axisLabelBuildResultSet(local, labelLayoutList, labelGroup, axisLabelCreationCtx);
  41952. }
  41953. // Indicate that `layOutAxisTickLabel` has been called.
  41954. function axisLabelBuildResultExists(local) {
  41955. return !!local.labelLayoutList;
  41956. }
  41957. function axisLabelBuildResultSet(local, labelLayoutList, labelGroup, axisLabelsCreationContext) {
  41958. // Ensure the same lifetime.
  41959. local.labelLayoutList = labelLayoutList;
  41960. local.labelGroup = labelGroup;
  41961. local.axisLabelsCreationContext = axisLabelsCreationContext;
  41962. }
  41963. function updateAxisLabelChangableProps(cfg, axisModel, labelLayoutList, transformGroup) {
  41964. var labelMargin = axisModel.get(['axisLabel', 'margin']);
  41965. each(labelLayoutList, function (layout, idx) {
  41966. var geometry = ensureLabelLayoutWithGeometry(layout);
  41967. if (!geometry) {
  41968. return;
  41969. }
  41970. var labelEl = geometry.label;
  41971. var inner = getLabelInner(labelEl);
  41972. // See the comment in `suggestIgnore`.
  41973. geometry.suggestIgnore = labelEl.ignore;
  41974. // Currently no `ignore:true` is set in `buildAxisLabel`
  41975. // But `ignore:true` may be set subsequently for overlap handling, thus reset it here.
  41976. labelEl.ignore = false;
  41977. copyTransform(_tmpLayoutEl, _tmpLayoutElReset);
  41978. _tmpLayoutEl.x = axisModel.axis.dataToCoord(inner.tickValue);
  41979. _tmpLayoutEl.y = cfg.labelOffset + cfg.labelDirection * labelMargin;
  41980. _tmpLayoutEl.rotation = inner.layoutRotation;
  41981. transformGroup.add(_tmpLayoutEl);
  41982. _tmpLayoutEl.updateTransform();
  41983. transformGroup.remove(_tmpLayoutEl);
  41984. _tmpLayoutEl.decomposeTransform();
  41985. copyTransform(labelEl, _tmpLayoutEl);
  41986. labelEl.markRedraw();
  41987. setLabelLayoutDirty(geometry, true);
  41988. ensureLabelLayoutWithGeometry(geometry);
  41989. });
  41990. }
  41991. var _tmpLayoutEl = new Rect();
  41992. var _tmpLayoutElReset = new Rect();
  41993. function hasAxisName(axisName) {
  41994. return !!axisName;
  41995. }
  41996. function addBreakEventHandler(axisModel, api, textEl, visualBreak) {
  41997. textEl.on('click', function (params) {
  41998. var payload = {
  41999. type: AXIS_BREAK_EXPAND_ACTION_TYPE,
  42000. breaks: [{
  42001. start: visualBreak.parsedBreak.breakOption.start,
  42002. end: visualBreak.parsedBreak.breakOption.end
  42003. }]
  42004. };
  42005. payload[axisModel.axis.dim + "AxisIndex"] = axisModel.componentIndex;
  42006. api.dispatchAction(payload);
  42007. });
  42008. }
  42009. function adjustBreakLabels(axisModel, axisRotation, labelLayoutList) {
  42010. {
  42011. return;
  42012. }
  42013. }
  42014. /**
  42015. * [__CAUTION__]
  42016. * MUST guarantee: if only the input `rect` and `axis.extent` changed,
  42017. * only `layout.position` changes.
  42018. * This character is replied on `grid.contain` calculation in `AxisBuilder`.
  42019. * @see updateCartesianAxisViewCommonPartBuilder
  42020. *
  42021. * Can only be called after coordinate system creation stage.
  42022. * (Can be called before coordinate system update stage).
  42023. */
  42024. function layout$1(rect, axisModel, opt) {
  42025. opt = opt || {};
  42026. var axis = axisModel.axis;
  42027. var layout = {};
  42028. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  42029. var rawAxisPosition = axis.position;
  42030. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  42031. var axisDim = axis.dim;
  42032. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  42033. var idx = {
  42034. left: 0,
  42035. right: 1,
  42036. top: 0,
  42037. bottom: 1,
  42038. onZero: 2
  42039. };
  42040. var axisOffset = axisModel.get('offset') || 0;
  42041. var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  42042. if (otherAxisOnZeroOf) {
  42043. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  42044. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  42045. }
  42046. // Axis position
  42047. layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]];
  42048. // Axis rotation
  42049. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  42050. // Tick and label direction, x y is axisDim
  42051. var dirMap = {
  42052. top: -1,
  42053. bottom: 1,
  42054. left: -1,
  42055. right: 1
  42056. };
  42057. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  42058. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  42059. if (axisModel.get(['axisTick', 'inside'])) {
  42060. layout.tickDirection = -layout.tickDirection;
  42061. }
  42062. if (retrieve(opt.labelInside, axisModel.get(['axisLabel', 'inside']))) {
  42063. layout.labelDirection = -layout.labelDirection;
  42064. }
  42065. // Special label rotation
  42066. var labelRotate = axisModel.get(['axisLabel', 'rotate']);
  42067. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  42068. // Over splitLine and splitArea
  42069. layout.z2 = 1;
  42070. return layout;
  42071. }
  42072. /**
  42073. * Note: If pie (or other similar series) use cartesian2d, here
  42074. * option `seriesModel.get('coordinateSystem') === 'cartesian2d'`
  42075. * and `seriesModel.coordinateSystem !== cartesian2dCoordSysInstance`
  42076. * and `seriesModel.boxCoordinateSystem === cartesian2dCoordSysInstance`,
  42077. * the logic below is probably wrong, therefore skip it temporarily.
  42078. */
  42079. function isCartesian2DInjectedAsDataCoordSys(seriesModel) {
  42080. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  42081. }
  42082. function findAxisModels(seriesModel) {
  42083. var axisModelMap = {
  42084. xAxisModel: null,
  42085. yAxisModel: null
  42086. };
  42087. each(axisModelMap, function (v, key) {
  42088. var axisType = key.replace(/Model$/, '');
  42089. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  42090. if ("development" !== 'production') {
  42091. if (!axisModel) {
  42092. throw new Error(axisType + ' "' + retrieve3(seriesModel.get(axisType + 'Index'), seriesModel.get(axisType + 'Id'), 0) + '" not found');
  42093. }
  42094. }
  42095. axisModelMap[key] = axisModel;
  42096. });
  42097. return axisModelMap;
  42098. }
  42099. function createCartesianAxisViewCommonPartBuilder(gridRect, cartesians, axisModel, api, ctx, defaultNameMoveOverlap) {
  42100. var layoutResult = layout$1(gridRect, axisModel);
  42101. var axisLineAutoShow = false;
  42102. var axisTickAutoShow = false;
  42103. // Not show axisTick or axisLine if other axis is category / time
  42104. for (var i = 0; i < cartesians.length; i++) {
  42105. if (isIntervalOrLogScale(cartesians[i].getOtherAxis(axisModel.axis).scale)) {
  42106. // Still show axis tick or axisLine if other axis is value / log
  42107. axisLineAutoShow = axisTickAutoShow = true;
  42108. if (axisModel.axis.type === 'category' && axisModel.axis.onBand) {
  42109. axisTickAutoShow = false;
  42110. }
  42111. }
  42112. }
  42113. layoutResult.axisLineAutoShow = axisLineAutoShow;
  42114. layoutResult.axisTickAutoShow = axisTickAutoShow;
  42115. layoutResult.defaultNameMoveOverlap = defaultNameMoveOverlap;
  42116. return new AxisBuilder(axisModel, api, layoutResult, ctx);
  42117. }
  42118. function updateCartesianAxisViewCommonPartBuilder(axisBuilder, gridRect, axisModel) {
  42119. var newRaw = layout$1(gridRect, axisModel);
  42120. if ("development" !== 'production') {
  42121. var oldRaw_1 = axisBuilder.__getRawCfg();
  42122. each(keys(newRaw), function (prop) {
  42123. if (prop !== 'position' && prop !== 'labelOffset') {
  42124. assert(newRaw[prop] === oldRaw_1[prop]);
  42125. }
  42126. });
  42127. }
  42128. axisBuilder.updateCfg(newRaw);
  42129. }
  42130. function alignScaleTicks(scale, axisModel, alignToScale) {
  42131. var _a;
  42132. var intervalScaleProto = IntervalScale.prototype;
  42133. // NOTE: There is a precondition for log scale here:
  42134. // In log scale we store _interval and _extent of exponent value.
  42135. // So if we use the method of InternalScale to set/get these data.
  42136. // It process the exponent value, which is linear and what we want here.
  42137. var alignToTicks = intervalScaleProto.getTicks.call(alignToScale);
  42138. var alignToNicedTicks = intervalScaleProto.getTicks.call(alignToScale, {
  42139. expandToNicedExtent: true
  42140. });
  42141. var alignToSplitNumber = alignToTicks.length - 1;
  42142. var alignToInterval = intervalScaleProto.getInterval.call(alignToScale);
  42143. var scaleExtent = getScaleExtent(scale, axisModel);
  42144. var rawExtent = scaleExtent.extent;
  42145. var isMinFixed = scaleExtent.fixMin;
  42146. var isMaxFixed = scaleExtent.fixMax;
  42147. if (scale.type === 'log') {
  42148. rawExtent = logTransform(scale.base, rawExtent, true);
  42149. }
  42150. scale.setBreaksFromOption(retrieveAxisBreaksOption(axisModel));
  42151. scale.setExtent(rawExtent[0], rawExtent[1]);
  42152. scale.calcNiceExtent({
  42153. splitNumber: alignToSplitNumber,
  42154. fixMin: isMinFixed,
  42155. fixMax: isMaxFixed
  42156. });
  42157. var extent = intervalScaleProto.getExtent.call(scale);
  42158. // Need to update the rawExtent.
  42159. // Because value in rawExtent may be not parsed. e.g. 'dataMin', 'dataMax'
  42160. if (isMinFixed) {
  42161. rawExtent[0] = extent[0];
  42162. }
  42163. if (isMaxFixed) {
  42164. rawExtent[1] = extent[1];
  42165. }
  42166. var interval = intervalScaleProto.getInterval.call(scale);
  42167. var min = rawExtent[0];
  42168. var max = rawExtent[1];
  42169. if (isMinFixed && isMaxFixed) {
  42170. // User set min, max, divide to get new interval
  42171. interval = (max - min) / alignToSplitNumber;
  42172. } else if (isMinFixed) {
  42173. max = rawExtent[0] + interval * alignToSplitNumber;
  42174. // User set min, expand extent on the other side
  42175. while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1])) {
  42176. interval = increaseInterval(interval);
  42177. max = rawExtent[0] + interval * alignToSplitNumber;
  42178. }
  42179. } else if (isMaxFixed) {
  42180. // User set max, expand extent on the other side
  42181. min = rawExtent[1] - interval * alignToSplitNumber;
  42182. while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0])) {
  42183. interval = increaseInterval(interval);
  42184. min = rawExtent[1] - interval * alignToSplitNumber;
  42185. }
  42186. } else {
  42187. var nicedSplitNumber = scale.getTicks().length - 1;
  42188. if (nicedSplitNumber > alignToSplitNumber) {
  42189. interval = increaseInterval(interval);
  42190. }
  42191. var range = interval * alignToSplitNumber;
  42192. max = Math.ceil(rawExtent[1] / interval) * interval;
  42193. min = round(max - range);
  42194. // Not change the result that crossing zero.
  42195. if (min < 0 && rawExtent[0] >= 0) {
  42196. min = 0;
  42197. max = round(range);
  42198. } else if (max > 0 && rawExtent[1] <= 0) {
  42199. max = 0;
  42200. min = -round(range);
  42201. }
  42202. }
  42203. // Adjust min, max based on the extent of alignTo. When min or max is set in alignTo scale
  42204. var t0 = (alignToTicks[0].value - alignToNicedTicks[0].value) / alignToInterval;
  42205. var t1 = (alignToTicks[alignToSplitNumber].value - alignToNicedTicks[alignToSplitNumber].value) / alignToInterval;
  42206. // NOTE: Must in setExtent -> setInterval -> setNiceExtent order.
  42207. intervalScaleProto.setExtent.call(scale, min + interval * t0, max + interval * t1);
  42208. intervalScaleProto.setInterval.call(scale, interval);
  42209. if (t0 || t1) {
  42210. intervalScaleProto.setNiceExtent.call(scale, min + interval, max - interval);
  42211. }
  42212. if ("development" !== 'production') {
  42213. var ticks = intervalScaleProto.getTicks.call(scale);
  42214. if (ticks[1] && (!isValueNice(interval) || getPrecisionSafe(ticks[1].value) > getPrecisionSafe(interval))) {
  42215. warn("The ticks may be not readable when set min: " + axisModel.get('min') + ", max: " + axisModel.get('max') + (" and alignTicks: true. (" + ((_a = axisModel.axis) === null || _a === void 0 ? void 0 : _a.dim) + "AxisIndex: " + axisModel.componentIndex + ")"), true);
  42216. }
  42217. }
  42218. }
  42219. // margin is [top, right, bottom, left]
  42220. var XY_TO_MARGIN_IDX = [[3, 1], [0, 2] // xyIdx 1 => 'y'
  42221. ];
  42222. var Grid = /** @class */function () {
  42223. function Grid(gridModel, ecModel, api) {
  42224. // FIXME:TS where used (different from registered type 'cartesian2d')?
  42225. this.type = 'grid';
  42226. this._coordsMap = {};
  42227. this._coordsList = [];
  42228. this._axesMap = {};
  42229. this._axesList = [];
  42230. this.axisPointerEnabled = true;
  42231. this.dimensions = cartesian2DDimensions;
  42232. this._initCartesian(gridModel, ecModel, api);
  42233. this.model = gridModel;
  42234. }
  42235. Grid.prototype.getRect = function () {
  42236. return this._rect;
  42237. };
  42238. Grid.prototype.update = function (ecModel, api) {
  42239. var axesMap = this._axesMap;
  42240. this._updateScale(ecModel, this.model);
  42241. function updateAxisTicks(axes) {
  42242. var alignTo;
  42243. // Axis is added in order of axisIndex.
  42244. var axesIndices = keys(axes);
  42245. var len = axesIndices.length;
  42246. if (!len) {
  42247. return;
  42248. }
  42249. var axisNeedsAlign = [];
  42250. // Process once and calculate the ticks for those don't use alignTicks.
  42251. for (var i = len - 1; i >= 0; i--) {
  42252. var idx = +axesIndices[i]; // Convert to number.
  42253. var axis = axes[idx];
  42254. var model = axis.model;
  42255. var scale = axis.scale;
  42256. if (
  42257. // Only value and log axis without interval support alignTicks.
  42258. isIntervalOrLogScale(scale) && model.get('alignTicks') && model.get('interval') == null) {
  42259. axisNeedsAlign.push(axis);
  42260. } else {
  42261. niceScaleExtent(scale, model);
  42262. if (isIntervalOrLogScale(scale)) {
  42263. // Can only align to interval or log axis.
  42264. alignTo = axis;
  42265. }
  42266. }
  42267. }
  42268. // All axes has set alignTicks. Pick the first one.
  42269. // PENDING. Should we find the axis that both set interval, min, max and align to this one?
  42270. if (axisNeedsAlign.length) {
  42271. if (!alignTo) {
  42272. alignTo = axisNeedsAlign.pop();
  42273. niceScaleExtent(alignTo.scale, alignTo.model);
  42274. }
  42275. each(axisNeedsAlign, function (axis) {
  42276. alignScaleTicks(axis.scale, axis.model, alignTo.scale);
  42277. });
  42278. }
  42279. }
  42280. updateAxisTicks(axesMap.x);
  42281. updateAxisTicks(axesMap.y);
  42282. // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  42283. var onZeroRecords = {};
  42284. each(axesMap.x, function (xAxis) {
  42285. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  42286. });
  42287. each(axesMap.y, function (yAxis) {
  42288. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  42289. });
  42290. // Resize again if containLabel is enabled
  42291. // FIXME It may cause getting wrong grid size in data processing stage
  42292. this.resize(this.model, api);
  42293. };
  42294. /**
  42295. * Resize the grid.
  42296. *
  42297. * [NOTE]
  42298. * If both "grid.containLabel/grid.contain" and pixel-required-data-processing (such as, "dataSampling")
  42299. * exist, circular dependency occurs in logic.
  42300. * The final compromised sequence is:
  42301. * 1. Calculate "axis.extent" (pixel extent) and AffineTransform based on only "grid layout options".
  42302. * Not accurate if "grid.containLabel/grid.contain" is required, but it is a compromise to avoid
  42303. * circular dependency.
  42304. * 2. Perform "series data processing" (where "dataSampling" requires "axis.extent").
  42305. * 3. Calculate "scale.extent" (data extent) based on "processed series data".
  42306. * 4. Modify "axis.extent" for "grid.containLabel/grid.contain":
  42307. * 4.1. Calculate "axis labels" based on "scale.extent".
  42308. * 4.2. Modify "axis.extent" by the bounding rects of "axis labels and names".
  42309. */
  42310. Grid.prototype.resize = function (gridModel, api, beforeDataProcessing) {
  42311. var layoutRef = createBoxLayoutReference(gridModel, api);
  42312. var gridRect = this._rect = getLayoutRect(gridModel.getBoxLayoutParams(), layoutRef.refContainer);
  42313. // PENDING: whether to support that if the input `coord` is out of the base coord sys,
  42314. // do not render anything. At present, the behavior is undefined.
  42315. var axesMap = this._axesMap;
  42316. var coordsList = this._coordsList;
  42317. var optionContainLabel = gridModel.get('containLabel'); // No `.get(, true)` for backward compat.
  42318. updateAllAxisExtentTransByGridRect(axesMap, gridRect);
  42319. if (!beforeDataProcessing) {
  42320. var axisBuilderSharedCtx = createAxisBiulders(gridRect, coordsList, axesMap, optionContainLabel, api);
  42321. var noPxChange = void 0;
  42322. if (optionContainLabel) {
  42323. {
  42324. if ("development" !== 'production') {
  42325. log('Specified `grid.containLabel` but no `use(LegacyGridContainLabel)`;' + 'use `grid.outerBounds` instead.', true);
  42326. }
  42327. noPxChange = layOutGridByOuterBounds(gridRect.clone(), 'axisLabel', null, gridRect, axesMap, axisBuilderSharedCtx, layoutRef);
  42328. }
  42329. } else {
  42330. var _a = prepareOuterBounds(gridModel, gridRect, layoutRef),
  42331. outerBoundsRect = _a.outerBoundsRect,
  42332. parsedOuterBoundsContain = _a.parsedOuterBoundsContain,
  42333. outerBoundsClamp = _a.outerBoundsClamp;
  42334. if (outerBoundsRect) {
  42335. // console.time('layOutGridByOuterBounds');
  42336. noPxChange = layOutGridByOuterBounds(outerBoundsRect, parsedOuterBoundsContain, outerBoundsClamp, gridRect, axesMap, axisBuilderSharedCtx, layoutRef);
  42337. // console.timeEnd('layOutGridByOuterBounds');
  42338. }
  42339. }
  42340. // console.time('buildAxesView_determine');
  42341. createOrUpdateAxesView(gridRect, axesMap, AxisTickLabelComputingKind.determine, null, noPxChange, layoutRef);
  42342. // console.timeEnd('buildAxesView_determine');
  42343. } // End of beforeDataProcessing
  42344. each(this._coordsList, function (coord) {
  42345. // Calculate affine matrix to accelerate the data to point transform.
  42346. // If all the axes scales are time or value.
  42347. coord.calcAffineTransform();
  42348. });
  42349. };
  42350. Grid.prototype.getAxis = function (dim, axisIndex) {
  42351. var axesMapOnDim = this._axesMap[dim];
  42352. if (axesMapOnDim != null) {
  42353. return axesMapOnDim[axisIndex || 0];
  42354. }
  42355. };
  42356. Grid.prototype.getAxes = function () {
  42357. return this._axesList.slice();
  42358. };
  42359. Grid.prototype.getCartesian = function (xAxisIndex, yAxisIndex) {
  42360. if (xAxisIndex != null && yAxisIndex != null) {
  42361. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  42362. return this._coordsMap[key];
  42363. }
  42364. if (isObject(xAxisIndex)) {
  42365. yAxisIndex = xAxisIndex.yAxisIndex;
  42366. xAxisIndex = xAxisIndex.xAxisIndex;
  42367. }
  42368. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  42369. if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
  42370. return coordList[i];
  42371. }
  42372. }
  42373. };
  42374. Grid.prototype.getCartesians = function () {
  42375. return this._coordsList.slice();
  42376. };
  42377. /**
  42378. * @implements
  42379. */
  42380. Grid.prototype.convertToPixel = function (ecModel, finder, value) {
  42381. var target = this._findConvertTarget(finder);
  42382. return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
  42383. };
  42384. /**
  42385. * @implements
  42386. */
  42387. Grid.prototype.convertFromPixel = function (ecModel, finder, value) {
  42388. var target = this._findConvertTarget(finder);
  42389. return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
  42390. };
  42391. Grid.prototype._findConvertTarget = function (finder) {
  42392. var seriesModel = finder.seriesModel;
  42393. var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  42394. var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  42395. var gridModel = finder.gridModel;
  42396. var coordsList = this._coordsList;
  42397. var cartesian;
  42398. var axis;
  42399. if (seriesModel) {
  42400. cartesian = seriesModel.coordinateSystem;
  42401. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  42402. } else if (xAxisModel && yAxisModel) {
  42403. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  42404. } else if (xAxisModel) {
  42405. axis = this.getAxis('x', xAxisModel.componentIndex);
  42406. } else if (yAxisModel) {
  42407. axis = this.getAxis('y', yAxisModel.componentIndex);
  42408. }
  42409. // Lowest priority.
  42410. else if (gridModel) {
  42411. var grid = gridModel.coordinateSystem;
  42412. if (grid === this) {
  42413. cartesian = this._coordsList[0];
  42414. }
  42415. }
  42416. return {
  42417. cartesian: cartesian,
  42418. axis: axis
  42419. };
  42420. };
  42421. /**
  42422. * @implements
  42423. */
  42424. Grid.prototype.containPoint = function (point) {
  42425. var coord = this._coordsList[0];
  42426. if (coord) {
  42427. return coord.containPoint(point);
  42428. }
  42429. };
  42430. /**
  42431. * Initialize cartesian coordinate systems
  42432. */
  42433. Grid.prototype._initCartesian = function (gridModel, ecModel, api) {
  42434. var _this = this;
  42435. var grid = this;
  42436. var axisPositionUsed = {
  42437. left: false,
  42438. right: false,
  42439. top: false,
  42440. bottom: false
  42441. };
  42442. var axesMap = {
  42443. x: {},
  42444. y: {}
  42445. };
  42446. var axesCount = {
  42447. x: 0,
  42448. y: 0
  42449. };
  42450. // Create axis
  42451. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  42452. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  42453. if (!axesCount.x || !axesCount.y) {
  42454. // Roll back when there no either x or y axis
  42455. this._axesMap = {};
  42456. this._axesList = [];
  42457. return;
  42458. }
  42459. this._axesMap = axesMap;
  42460. // Create cartesian2d
  42461. each(axesMap.x, function (xAxis, xAxisIndex) {
  42462. each(axesMap.y, function (yAxis, yAxisIndex) {
  42463. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  42464. var cartesian = new Cartesian2D(key);
  42465. cartesian.master = _this;
  42466. cartesian.model = gridModel;
  42467. _this._coordsMap[key] = cartesian;
  42468. _this._coordsList.push(cartesian);
  42469. cartesian.addAxis(xAxis);
  42470. cartesian.addAxis(yAxis);
  42471. });
  42472. });
  42473. function createAxisCreator(dimName) {
  42474. return function (axisModel, idx) {
  42475. if (!isAxisUsedInTheGrid(axisModel, gridModel)) {
  42476. return;
  42477. }
  42478. var axisPosition = axisModel.get('position');
  42479. if (dimName === 'x') {
  42480. // Fix position
  42481. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  42482. // Default bottom of X
  42483. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  42484. }
  42485. } else {
  42486. // Fix position
  42487. if (axisPosition !== 'left' && axisPosition !== 'right') {
  42488. // Default left of Y
  42489. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  42490. }
  42491. }
  42492. axisPositionUsed[axisPosition] = true;
  42493. var axis = new Axis2D(dimName, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
  42494. var isCategory = axis.type === 'category';
  42495. axis.onBand = isCategory && axisModel.get('boundaryGap');
  42496. axis.inverse = axisModel.get('inverse');
  42497. // Inject axis into axisModel
  42498. axisModel.axis = axis;
  42499. // Inject axisModel into axis
  42500. axis.model = axisModel;
  42501. // Inject grid info axis
  42502. axis.grid = grid;
  42503. // Index of axis, can be used as key
  42504. axis.index = idx;
  42505. grid._axesList.push(axis);
  42506. axesMap[dimName][idx] = axis;
  42507. axesCount[dimName]++;
  42508. };
  42509. }
  42510. };
  42511. /**
  42512. * Update cartesian properties from series.
  42513. */
  42514. Grid.prototype._updateScale = function (ecModel, gridModel) {
  42515. // Reset scale
  42516. each(this._axesList, function (axis) {
  42517. axis.scale.setExtent(Infinity, -Infinity);
  42518. if (axis.type === 'category') {
  42519. var categorySortInfo = axis.model.get('categorySortInfo');
  42520. axis.scale.setSortInfo(categorySortInfo);
  42521. }
  42522. });
  42523. ecModel.eachSeries(function (seriesModel) {
  42524. // If pie (or other similar series) use cartesian2d, the unionExtent logic below is
  42525. // wrong, therefore skip it temporarily. See also in `defaultAxisExtentFromData.ts`.
  42526. // TODO: support union extent in this case.
  42527. if (isCartesian2DInjectedAsDataCoordSys(seriesModel)) {
  42528. var axesModelMap = findAxisModels(seriesModel);
  42529. var xAxisModel = axesModelMap.xAxisModel;
  42530. var yAxisModel = axesModelMap.yAxisModel;
  42531. if (!isAxisUsedInTheGrid(xAxisModel, gridModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel)) {
  42532. return;
  42533. }
  42534. var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  42535. var data = seriesModel.getData();
  42536. var xAxis = cartesian.getAxis('x');
  42537. var yAxis = cartesian.getAxis('y');
  42538. unionExtent(data, xAxis);
  42539. unionExtent(data, yAxis);
  42540. }
  42541. }, this);
  42542. function unionExtent(data, axis) {
  42543. each(getDataDimensionsOnAxis(data, axis.dim), function (dim) {
  42544. axis.scale.unionExtentFromData(data, dim);
  42545. });
  42546. }
  42547. };
  42548. /**
  42549. * @param dim 'x' or 'y' or 'auto' or null/undefined
  42550. */
  42551. Grid.prototype.getTooltipAxes = function (dim) {
  42552. var baseAxes = [];
  42553. var otherAxes = [];
  42554. each(this.getCartesians(), function (cartesian) {
  42555. var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  42556. var otherAxis = cartesian.getOtherAxis(baseAxis);
  42557. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  42558. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  42559. });
  42560. return {
  42561. baseAxes: baseAxes,
  42562. otherAxes: otherAxes
  42563. };
  42564. };
  42565. Grid.create = function (ecModel, api) {
  42566. var grids = [];
  42567. ecModel.eachComponent('grid', function (gridModel, idx) {
  42568. var grid = new Grid(gridModel, ecModel, api);
  42569. grid.name = 'grid_' + idx;
  42570. // dataSampling requires axis extent, so resize
  42571. // should be performed in create stage.
  42572. grid.resize(gridModel, api, true);
  42573. gridModel.coordinateSystem = grid;
  42574. grids.push(grid);
  42575. });
  42576. // Inject the coordinateSystems into seriesModel
  42577. ecModel.eachSeries(function (seriesModel) {
  42578. injectCoordSysByOption({
  42579. targetModel: seriesModel,
  42580. coordSysType: 'cartesian2d',
  42581. coordSysProvider: coordSysProvider
  42582. });
  42583. function coordSysProvider() {
  42584. var axesModelMap = findAxisModels(seriesModel);
  42585. var xAxisModel = axesModelMap.xAxisModel;
  42586. var yAxisModel = axesModelMap.yAxisModel;
  42587. var gridModel = xAxisModel.getCoordSysModel();
  42588. if ("development" !== 'production') {
  42589. if (!gridModel) {
  42590. throw new Error('Grid "' + retrieve3(xAxisModel.get('gridIndex'), xAxisModel.get('gridId'), 0) + '" not found');
  42591. }
  42592. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  42593. throw new Error('xAxis and yAxis must use the same grid');
  42594. }
  42595. }
  42596. var grid = gridModel.coordinateSystem;
  42597. return grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  42598. }
  42599. });
  42600. return grids;
  42601. };
  42602. // For deciding which dimensions to use when creating list data
  42603. Grid.dimensions = cartesian2DDimensions;
  42604. return Grid;
  42605. }();
  42606. /**
  42607. * Check if the axis is used in the specified grid.
  42608. */
  42609. function isAxisUsedInTheGrid(axisModel, gridModel) {
  42610. return axisModel.getCoordSysModel() === gridModel;
  42611. }
  42612. function fixAxisOnZero(axesMap, otherAxisDim, axis,
  42613. // Key: see `getOnZeroRecordKey`
  42614. onZeroRecords) {
  42615. axis.getAxesOnZeroOf = function () {
  42616. // TODO: onZero of multiple axes.
  42617. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  42618. };
  42619. // onZero can not be enabled in these two situations:
  42620. // 1. When any other axis is a category axis.
  42621. // 2. When no axis is cross 0 point.
  42622. var otherAxes = axesMap[otherAxisDim];
  42623. var otherAxisOnZeroOf;
  42624. var axisModel = axis.model;
  42625. var onZero = axisModel.get(['axisLine', 'onZero']);
  42626. var onZeroAxisIndex = axisModel.get(['axisLine', 'onZeroAxisIndex']);
  42627. if (!onZero) {
  42628. return;
  42629. }
  42630. // If target axis is specified.
  42631. if (onZeroAxisIndex != null) {
  42632. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  42633. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  42634. }
  42635. } else {
  42636. // Find the first available other axis.
  42637. for (var idx in otherAxes) {
  42638. if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx])
  42639. // Consider that two Y axes on one value axis,
  42640. // if both onZero, the two Y axes overlap.
  42641. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
  42642. otherAxisOnZeroOf = otherAxes[idx];
  42643. break;
  42644. }
  42645. }
  42646. }
  42647. if (otherAxisOnZeroOf) {
  42648. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  42649. }
  42650. function getOnZeroRecordKey(axis) {
  42651. return axis.dim + '_' + axis.index;
  42652. }
  42653. }
  42654. function canOnZeroToAxis(axis) {
  42655. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  42656. }
  42657. function updateAxisTransform(axis, coordBase) {
  42658. var axisExtent = axis.getExtent();
  42659. var axisExtentSum = axisExtent[0] + axisExtent[1];
  42660. // Fast transform
  42661. axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
  42662. return coord + coordBase;
  42663. } : function (coord) {
  42664. return axisExtentSum - coord + coordBase;
  42665. };
  42666. axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
  42667. return coord - coordBase;
  42668. } : function (coord) {
  42669. return axisExtentSum - coord + coordBase;
  42670. };
  42671. }
  42672. function updateAllAxisExtentTransByGridRect(axesMap, gridRect) {
  42673. each(axesMap.x, function (axis) {
  42674. return updateAxisExtentTransByGridRect(axis, gridRect.x, gridRect.width);
  42675. });
  42676. each(axesMap.y, function (axis) {
  42677. return updateAxisExtentTransByGridRect(axis, gridRect.y, gridRect.height);
  42678. });
  42679. }
  42680. function updateAxisExtentTransByGridRect(axis, gridXY, gridWH) {
  42681. var extent = [0, gridWH];
  42682. var idx = axis.inverse ? 1 : 0;
  42683. axis.setExtent(extent[idx], extent[1 - idx]);
  42684. updateAxisTransform(axis, gridXY);
  42685. }
  42686. // Return noPxChange.
  42687. function layOutGridByOuterBounds(outerBoundsRect, outerBoundsContain, outerBoundsClamp, gridRect, axesMap, axisBuilderSharedCtx, layoutRef) {
  42688. if ("development" !== 'production') {
  42689. assert(outerBoundsContain === 'all' || outerBoundsContain === 'axisLabel');
  42690. }
  42691. // Assume `updateAllAxisExtentTransByGridRect` has been performed once before this call.
  42692. // [NOTE]:
  42693. // - The bounding rect of the axis elements might be sensitve to variations in `axis.extent` due to strategies
  42694. // like hideOverlap/moveOverlap. @see the comment in `LabelLayoutBase['suggestIgnore']`.
  42695. // - The final `gridRect` might be slightly smaller than the ideally expected result if labels are giant and
  42696. // get hidden due to overlapping. More iterations could improve precision, but not performant. We consider
  42697. // the current result acceptable, since no alignment among charts can be guaranteed when using this feature.
  42698. createOrUpdateAxesView(gridRect, axesMap, AxisTickLabelComputingKind.estimate, outerBoundsContain, false, layoutRef);
  42699. var margin = [0, 0, 0, 0];
  42700. fillLabelNameOverflowOnOneDimension(0);
  42701. fillLabelNameOverflowOnOneDimension(1);
  42702. // If axis is blank, no label can be used to detect overflow.
  42703. // gridRect itself should not overflow.
  42704. fillMarginOnOneDimension(gridRect, 0, NaN);
  42705. fillMarginOnOneDimension(gridRect, 1, NaN);
  42706. var noPxChange = find(margin, function (item) {
  42707. return item > 0;
  42708. }) == null;
  42709. expandOrShrinkRect(gridRect, margin, true, true, outerBoundsClamp);
  42710. updateAllAxisExtentTransByGridRect(axesMap, gridRect);
  42711. return noPxChange;
  42712. function fillLabelNameOverflowOnOneDimension(xyIdx) {
  42713. each(axesMap[XY$1[xyIdx]], function (axis) {
  42714. if (!shouldAxisShow(axis.model)) {
  42715. return;
  42716. }
  42717. // FIXME: zr Group.union may wrongly union (0, 0, 0, 0) and not performant.
  42718. // unionRect.union(axis.axisBuilder.group.getBoundingRect());
  42719. // If ussing Group.getBoundingRect to calculate shrink space, it is not strictly accurate when
  42720. // the outermost label is ignored and the secondary label is very long and contribute to the
  42721. // union extension:
  42722. // -|---|---|---|
  42723. // 1,000,000,000
  42724. // Therefore we calculate them one by one.
  42725. // Also considered axis may be blank or no labels.
  42726. var sharedRecord = axisBuilderSharedCtx.ensureRecord(axis.model);
  42727. var labelInfoList = sharedRecord.labelInfoList;
  42728. if (labelInfoList) {
  42729. for (var idx = 0; idx < labelInfoList.length; idx++) {
  42730. var labelInfo = labelInfoList[idx];
  42731. var proportion = axis.scale.normalize(getLabelInner(labelInfo.label).tickValue);
  42732. proportion = xyIdx === 1 ? 1 - proportion : proportion;
  42733. // xAxis use proportion on x, yAxis use proprotion on y, otherwise not.
  42734. fillMarginOnOneDimension(labelInfo.rect, xyIdx, proportion);
  42735. fillMarginOnOneDimension(labelInfo.rect, 1 - xyIdx, NaN);
  42736. }
  42737. }
  42738. var nameLayout = sharedRecord.nameLayout;
  42739. if (nameLayout) {
  42740. var proportion = isNameLocationCenter(sharedRecord.nameLocation) ? 0.5 : NaN;
  42741. fillMarginOnOneDimension(nameLayout.rect, xyIdx, proportion);
  42742. fillMarginOnOneDimension(nameLayout.rect, 1 - xyIdx, NaN);
  42743. }
  42744. });
  42745. }
  42746. function fillMarginOnOneDimension(itemRect, xyIdx, proportion // NaN mean no use proportion
  42747. ) {
  42748. var overflow1 = outerBoundsRect[XY$1[xyIdx]] - itemRect[XY$1[xyIdx]];
  42749. var overflow2 = itemRect[WH$1[xyIdx]] + itemRect[XY$1[xyIdx]] - (outerBoundsRect[WH$1[xyIdx]] + outerBoundsRect[XY$1[xyIdx]]);
  42750. overflow1 = applyProportion(overflow1, 1 - proportion);
  42751. overflow2 = applyProportion(overflow2, proportion);
  42752. var minIdx = XY_TO_MARGIN_IDX[xyIdx][0];
  42753. var maxIdx = XY_TO_MARGIN_IDX[xyIdx][1];
  42754. margin[minIdx] = mathMax$1(margin[minIdx], overflow1);
  42755. margin[maxIdx] = mathMax$1(margin[maxIdx], overflow2);
  42756. }
  42757. function applyProportion(overflow, proportion) {
  42758. // proportion is not likely to near zero. If so, give up shrink
  42759. if (overflow > 0 && !eqNaN(proportion) && proportion > 1e-4) {
  42760. overflow /= proportion;
  42761. }
  42762. return overflow;
  42763. }
  42764. }
  42765. function createAxisBiulders(gridRect, cartesians, axesMap, optionContainLabel, api) {
  42766. var axisBuilderSharedCtx = new AxisBuilderSharedContext(resolveAxisNameOverlapForGrid);
  42767. each(axesMap, function (axisList) {
  42768. return each(axisList, function (axis) {
  42769. if (shouldAxisShow(axis.model)) {
  42770. // See `AxisBaseOptionCommon['nameMoveOverlap']`.
  42771. var defaultNameMoveOverlap = !optionContainLabel;
  42772. axis.axisBuilder = createCartesianAxisViewCommonPartBuilder(gridRect, cartesians, axis.model, api, axisBuilderSharedCtx, defaultNameMoveOverlap);
  42773. }
  42774. });
  42775. });
  42776. return axisBuilderSharedCtx;
  42777. }
  42778. /**
  42779. * Promote the axis-elements-building from "view render" stage to "coordinate system resize" stage.
  42780. * This is aimed to resovle overlap across multiple axes, since currently it's hard to reconcile
  42781. * multiple axes in "view render" stage.
  42782. *
  42783. * [CAUTION] But this promotion assumes that the subsequent "visual mapping" stage does not affect
  42784. * this axis-elements-building; otherwise we have to refactor it again.
  42785. */
  42786. function createOrUpdateAxesView(gridRect, axesMap, kind, outerBoundsContain, noPxChange, layoutRef) {
  42787. var isDetermine = kind === AxisTickLabelComputingKind.determine;
  42788. each(axesMap, function (axisList) {
  42789. return each(axisList, function (axis) {
  42790. if (shouldAxisShow(axis.model)) {
  42791. updateCartesianAxisViewCommonPartBuilder(axis.axisBuilder, gridRect, axis.model);
  42792. axis.axisBuilder.build(isDetermine ? {
  42793. axisTickLabelDetermine: true
  42794. } : {
  42795. axisTickLabelEstimate: true
  42796. }, {
  42797. noPxChange: noPxChange
  42798. });
  42799. }
  42800. });
  42801. });
  42802. var nameMarginLevelMap = {
  42803. x: 0,
  42804. y: 0
  42805. };
  42806. calcNameMarginLevel(0);
  42807. calcNameMarginLevel(1);
  42808. function calcNameMarginLevel(xyIdx) {
  42809. nameMarginLevelMap[XY$1[1 - xyIdx]] = gridRect[WH$1[xyIdx]] <= layoutRef.refContainer[WH$1[xyIdx]] * 0.5 ? 0 : 1 - xyIdx === 1 ? 2 : 1;
  42810. }
  42811. each(axesMap, function (axisList, xy) {
  42812. return each(axisList, function (axis) {
  42813. if (shouldAxisShow(axis.model)) {
  42814. if (outerBoundsContain === 'all' || isDetermine) {
  42815. // To resolve overlap, `axisName` layout depends on `axisTickLabel` layout result
  42816. // (all of the axes of the same `grid`; consider multiple x or y axes).
  42817. axis.axisBuilder.build({
  42818. axisName: true
  42819. }, {
  42820. nameMarginLevel: nameMarginLevelMap[xy]
  42821. });
  42822. }
  42823. if (isDetermine) {
  42824. axis.axisBuilder.build({
  42825. axisLine: true
  42826. });
  42827. }
  42828. }
  42829. });
  42830. });
  42831. }
  42832. function prepareOuterBounds(gridModel, rawRridRect, layoutRef) {
  42833. var outerBoundsRect;
  42834. var optionOuterBoundsMode = gridModel.get('outerBoundsMode', true);
  42835. if (optionOuterBoundsMode === 'same') {
  42836. outerBoundsRect = rawRridRect.clone();
  42837. } else if (optionOuterBoundsMode == null || optionOuterBoundsMode === 'auto') {
  42838. outerBoundsRect = getLayoutRect(gridModel.get('outerBounds', true) || OUTER_BOUNDS_DEFAULT, layoutRef.refContainer);
  42839. } else if (optionOuterBoundsMode !== 'none') {
  42840. if ("development" !== 'production') {
  42841. error("Invalid grid[" + gridModel.componentIndex + "].outerBoundsMode.");
  42842. }
  42843. }
  42844. var optionOuterBoundsContain = gridModel.get('outerBoundsContain', true);
  42845. var parsedOuterBoundsContain;
  42846. if (optionOuterBoundsContain == null || optionOuterBoundsContain === 'auto') {
  42847. parsedOuterBoundsContain = 'all';
  42848. } else if (indexOf(['all', 'axisLabel'], optionOuterBoundsContain) < 0) {
  42849. if ("development" !== 'production') {
  42850. error("Invalid grid[" + gridModel.componentIndex + "].outerBoundsContain.");
  42851. }
  42852. parsedOuterBoundsContain = 'all';
  42853. } else {
  42854. parsedOuterBoundsContain = optionOuterBoundsContain;
  42855. }
  42856. var outerBoundsClamp = [parsePositionSizeOption(retrieve2(gridModel.get('outerBoundsClampWidth', true), OUTER_BOUNDS_CLAMP_DEFAULT[0]), rawRridRect.width), parsePositionSizeOption(retrieve2(gridModel.get('outerBoundsClampHeight', true), OUTER_BOUNDS_CLAMP_DEFAULT[1]), rawRridRect.height)];
  42857. return {
  42858. outerBoundsRect: outerBoundsRect,
  42859. parsedOuterBoundsContain: parsedOuterBoundsContain,
  42860. outerBoundsClamp: outerBoundsClamp
  42861. };
  42862. }
  42863. var resolveAxisNameOverlapForGrid = function (cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord) {
  42864. var perpendicularDim = axisModel.axis.dim === 'x' ? 'y' : 'x';
  42865. resolveAxisNameOverlapDefault(cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord);
  42866. // If nameLocation 'center', and there are multiple axes parallel to this axis, do not adjust by
  42867. // other axes, because the axis name should be close to its axis line as much as possible even
  42868. // if overlapping; otherwise it might cause misleading.
  42869. // If nameLocation 'center', do not adjust by perpendicular axes, since they are not likely to overlap.
  42870. // If nameLocation 'start'/'end', move name within the same direction to escape overlap with the
  42871. // perpendicular axes.
  42872. if (!isNameLocationCenter(cfg.nameLocation)) {
  42873. each(ctx.recordMap[perpendicularDim], function (perpenRecord) {
  42874. // perpendicular axis may be no name.
  42875. if (perpenRecord && perpenRecord.labelInfoList && perpenRecord.dirVec) {
  42876. moveIfOverlapByLinearLabels(perpenRecord.labelInfoList, perpenRecord.dirVec, nameLayoutInfo, nameMoveDirVec);
  42877. }
  42878. });
  42879. }
  42880. };
  42881. function fixValue(axisModel) {
  42882. var axisInfo = getAxisInfo(axisModel);
  42883. if (!axisInfo) {
  42884. return;
  42885. }
  42886. var axisPointerModel = axisInfo.axisPointerModel;
  42887. var scale = axisInfo.axis.scale;
  42888. var option = axisPointerModel.option;
  42889. var status = axisPointerModel.get('status');
  42890. var value = axisPointerModel.get('value');
  42891. // Parse init value for category and time axis.
  42892. if (value != null) {
  42893. value = scale.parse(value);
  42894. }
  42895. var useHandle = isHandleTrigger(axisPointerModel);
  42896. // If `handle` used, `axisPointer` will always be displayed, so value
  42897. // and status should be initialized.
  42898. if (status == null) {
  42899. option.status = useHandle ? 'show' : 'hide';
  42900. }
  42901. var extent = scale.getExtent().slice();
  42902. extent[0] > extent[1] && extent.reverse();
  42903. if (
  42904. // Pick a value on axis when initializing.
  42905. value == null
  42906. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  42907. // where we should re-pick a value to keep `handle` displaying normally.
  42908. || value > extent[1]) {
  42909. // Make handle displayed on the end of the axis when init, which looks better.
  42910. value = extent[1];
  42911. }
  42912. if (value < extent[0]) {
  42913. value = extent[0];
  42914. }
  42915. option.value = value;
  42916. if (useHandle) {
  42917. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  42918. }
  42919. }
  42920. function getAxisInfo(axisModel) {
  42921. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  42922. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  42923. }
  42924. function getAxisPointerModel(axisModel) {
  42925. var axisInfo = getAxisInfo(axisModel);
  42926. return axisInfo && axisInfo.axisPointerModel;
  42927. }
  42928. function isHandleTrigger(axisPointerModel) {
  42929. return !!axisPointerModel.get(['handle', 'show']);
  42930. }
  42931. /**
  42932. * @param {module:echarts/model/Model} model
  42933. * @return {string} unique key
  42934. */
  42935. function makeKey(model) {
  42936. return model.type + '||' + model.id;
  42937. }
  42938. var axisPointerClazz = {};
  42939. /**
  42940. * Base class of AxisView.
  42941. */
  42942. var AxisView = /** @class */function (_super) {
  42943. __extends(AxisView, _super);
  42944. function AxisView() {
  42945. var _this = _super !== null && _super.apply(this, arguments) || this;
  42946. _this.type = AxisView.type;
  42947. return _this;
  42948. }
  42949. /**
  42950. * @override
  42951. */
  42952. AxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  42953. // FIXME
  42954. // This process should proformed after coordinate systems updated
  42955. // (axis scale updated), and should be performed each time update.
  42956. // So put it here temporarily, although it is not appropriate to
  42957. // put a model-writing procedure in `view`.
  42958. this.axisPointerClass && fixValue(axisModel);
  42959. _super.prototype.render.apply(this, arguments);
  42960. this._doUpdateAxisPointerClass(axisModel, api, true);
  42961. };
  42962. /**
  42963. * Action handler.
  42964. */
  42965. AxisView.prototype.updateAxisPointer = function (axisModel, ecModel, api, payload) {
  42966. this._doUpdateAxisPointerClass(axisModel, api, false);
  42967. };
  42968. /**
  42969. * @override
  42970. */
  42971. AxisView.prototype.remove = function (ecModel, api) {
  42972. var axisPointer = this._axisPointer;
  42973. axisPointer && axisPointer.remove(api);
  42974. };
  42975. /**
  42976. * @override
  42977. */
  42978. AxisView.prototype.dispose = function (ecModel, api) {
  42979. this._disposeAxisPointer(api);
  42980. _super.prototype.dispose.apply(this, arguments);
  42981. };
  42982. AxisView.prototype._doUpdateAxisPointerClass = function (axisModel, api, forceRender) {
  42983. var Clazz = AxisView.getAxisPointerClass(this.axisPointerClass);
  42984. if (!Clazz) {
  42985. return;
  42986. }
  42987. var axisPointerModel = getAxisPointerModel(axisModel);
  42988. axisPointerModel ? (this._axisPointer || (this._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : this._disposeAxisPointer(api);
  42989. };
  42990. AxisView.prototype._disposeAxisPointer = function (api) {
  42991. this._axisPointer && this._axisPointer.dispose(api);
  42992. this._axisPointer = null;
  42993. };
  42994. AxisView.registerAxisPointerClass = function (type, clazz) {
  42995. if ("development" !== 'production') {
  42996. if (axisPointerClazz[type]) {
  42997. throw new Error('axisPointer ' + type + ' exists');
  42998. }
  42999. }
  43000. axisPointerClazz[type] = clazz;
  43001. };
  43002. AxisView.getAxisPointerClass = function (type) {
  43003. return type && axisPointerClazz[type];
  43004. };
  43005. AxisView.type = 'axis';
  43006. return AxisView;
  43007. }(ComponentView);
  43008. var inner$5 = makeInner();
  43009. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  43010. var axis = axisModel.axis;
  43011. if (axis.scale.isBlank()) {
  43012. return;
  43013. }
  43014. // TODO: TYPE
  43015. var splitAreaModel = axisModel.getModel('splitArea');
  43016. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  43017. var areaColors = areaStyleModel.get('color');
  43018. var gridRect = gridModel.coordinateSystem.getRect();
  43019. var ticksCoords = axis.getTicksCoords({
  43020. tickModel: splitAreaModel,
  43021. clamp: true,
  43022. breakTicks: 'none',
  43023. pruneByBreak: 'preserve_extent_bound'
  43024. });
  43025. if (!ticksCoords.length) {
  43026. return;
  43027. }
  43028. // For Making appropriate splitArea animation, the color and anid
  43029. // should be corresponding to previous one if possible.
  43030. var areaColorsLen = areaColors.length;
  43031. var lastSplitAreaColors = inner$5(axisView).splitAreaColors;
  43032. var newSplitAreaColors = createHashMap();
  43033. var colorIndex = 0;
  43034. if (lastSplitAreaColors) {
  43035. for (var i = 0; i < ticksCoords.length; i++) {
  43036. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  43037. if (cIndex != null) {
  43038. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  43039. break;
  43040. }
  43041. }
  43042. }
  43043. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  43044. var areaStyle = areaStyleModel.getAreaStyle();
  43045. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  43046. for (var i = 1; i < ticksCoords.length; i++) {
  43047. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  43048. var x = void 0;
  43049. var y = void 0;
  43050. var width = void 0;
  43051. var height = void 0;
  43052. if (axis.isHorizontal()) {
  43053. x = prev;
  43054. y = gridRect.y;
  43055. width = tickCoord - x;
  43056. height = gridRect.height;
  43057. prev = x + width;
  43058. } else {
  43059. x = gridRect.x;
  43060. y = prev;
  43061. width = gridRect.width;
  43062. height = tickCoord - y;
  43063. prev = y + height;
  43064. }
  43065. var tickValue = ticksCoords[i - 1].tickValue;
  43066. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  43067. axisGroup.add(new Rect({
  43068. anid: tickValue != null ? 'area_' + tickValue : null,
  43069. shape: {
  43070. x: x,
  43071. y: y,
  43072. width: width,
  43073. height: height
  43074. },
  43075. style: defaults({
  43076. fill: areaColors[colorIndex]
  43077. }, areaStyle),
  43078. autoBatch: true,
  43079. silent: true
  43080. }));
  43081. colorIndex = (colorIndex + 1) % areaColorsLen;
  43082. }
  43083. inner$5(axisView).splitAreaColors = newSplitAreaColors;
  43084. }
  43085. function rectCoordAxisHandleRemove(axisView) {
  43086. inner$5(axisView).splitAreaColors = null;
  43087. }
  43088. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine', 'breakArea'];
  43089. var CartesianAxisView = /** @class */function (_super) {
  43090. __extends(CartesianAxisView, _super);
  43091. function CartesianAxisView() {
  43092. var _this = _super !== null && _super.apply(this, arguments) || this;
  43093. _this.type = CartesianAxisView.type;
  43094. _this.axisPointerClass = 'CartesianAxisPointer';
  43095. return _this;
  43096. }
  43097. /**
  43098. * @override
  43099. */
  43100. CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  43101. this.group.removeAll();
  43102. var oldAxisGroup = this._axisGroup;
  43103. this._axisGroup = new Group();
  43104. this.group.add(this._axisGroup);
  43105. if (!shouldAxisShow(axisModel)) {
  43106. return;
  43107. }
  43108. this._axisGroup.add(axisModel.axis.axisBuilder.group);
  43109. each(selfBuilderAttrs, function (name) {
  43110. if (axisModel.get([name, 'show'])) {
  43111. axisElementBuilders[name](this, this._axisGroup, axisModel, axisModel.getCoordSysModel(), api);
  43112. }
  43113. }, this);
  43114. // THIS is a special case for bar racing chart.
  43115. // Update the axis label from the natural initial layout to
  43116. // sorted layout should has no animation.
  43117. var isInitialSortFromBarRacing = payload && payload.type === 'changeAxisOrder' && payload.isInitSort;
  43118. if (!isInitialSortFromBarRacing) {
  43119. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  43120. }
  43121. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  43122. };
  43123. CartesianAxisView.prototype.remove = function () {
  43124. rectCoordAxisHandleRemove(this);
  43125. };
  43126. CartesianAxisView.type = 'cartesianAxis';
  43127. return CartesianAxisView;
  43128. }(AxisView);
  43129. var axisElementBuilders = {
  43130. splitLine: function (axisView, axisGroup, axisModel, gridModel, api) {
  43131. var axis = axisModel.axis;
  43132. if (axis.scale.isBlank()) {
  43133. return;
  43134. }
  43135. var splitLineModel = axisModel.getModel('splitLine');
  43136. var lineStyleModel = splitLineModel.getModel('lineStyle');
  43137. var lineColors = lineStyleModel.get('color');
  43138. var showMinLine = splitLineModel.get('showMinLine') !== false;
  43139. var showMaxLine = splitLineModel.get('showMaxLine') !== false;
  43140. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  43141. var gridRect = gridModel.coordinateSystem.getRect();
  43142. var isHorizontal = axis.isHorizontal();
  43143. var lineCount = 0;
  43144. var ticksCoords = axis.getTicksCoords({
  43145. tickModel: splitLineModel,
  43146. breakTicks: 'none',
  43147. pruneByBreak: 'preserve_extent_bound'
  43148. });
  43149. var p1 = [];
  43150. var p2 = [];
  43151. var lineStyle = lineStyleModel.getLineStyle();
  43152. for (var i = 0; i < ticksCoords.length; i++) {
  43153. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  43154. if (i === 0 && !showMinLine || i === ticksCoords.length - 1 && !showMaxLine) {
  43155. continue;
  43156. }
  43157. var tickValue = ticksCoords[i].tickValue;
  43158. if (isHorizontal) {
  43159. p1[0] = tickCoord;
  43160. p1[1] = gridRect.y;
  43161. p2[0] = tickCoord;
  43162. p2[1] = gridRect.y + gridRect.height;
  43163. } else {
  43164. p1[0] = gridRect.x;
  43165. p1[1] = tickCoord;
  43166. p2[0] = gridRect.x + gridRect.width;
  43167. p2[1] = tickCoord;
  43168. }
  43169. var colorIndex = lineCount++ % lineColors.length;
  43170. var line = new Line({
  43171. anid: tickValue != null ? 'line_' + tickValue : null,
  43172. autoBatch: true,
  43173. shape: {
  43174. x1: p1[0],
  43175. y1: p1[1],
  43176. x2: p2[0],
  43177. y2: p2[1]
  43178. },
  43179. style: defaults({
  43180. stroke: lineColors[colorIndex]
  43181. }, lineStyle),
  43182. silent: true
  43183. });
  43184. subPixelOptimizeLine$1(line.shape, lineStyle.lineWidth);
  43185. axisGroup.add(line);
  43186. }
  43187. },
  43188. minorSplitLine: function (axisView, axisGroup, axisModel, gridModel, api) {
  43189. var axis = axisModel.axis;
  43190. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  43191. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  43192. var gridRect = gridModel.coordinateSystem.getRect();
  43193. var isHorizontal = axis.isHorizontal();
  43194. var minorTicksCoords = axis.getMinorTicksCoords();
  43195. if (!minorTicksCoords.length) {
  43196. return;
  43197. }
  43198. var p1 = [];
  43199. var p2 = [];
  43200. var lineStyle = lineStyleModel.getLineStyle();
  43201. for (var i = 0; i < minorTicksCoords.length; i++) {
  43202. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  43203. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  43204. if (isHorizontal) {
  43205. p1[0] = tickCoord;
  43206. p1[1] = gridRect.y;
  43207. p2[0] = tickCoord;
  43208. p2[1] = gridRect.y + gridRect.height;
  43209. } else {
  43210. p1[0] = gridRect.x;
  43211. p1[1] = tickCoord;
  43212. p2[0] = gridRect.x + gridRect.width;
  43213. p2[1] = tickCoord;
  43214. }
  43215. var line = new Line({
  43216. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  43217. autoBatch: true,
  43218. shape: {
  43219. x1: p1[0],
  43220. y1: p1[1],
  43221. x2: p2[0],
  43222. y2: p2[1]
  43223. },
  43224. style: lineStyle,
  43225. silent: true
  43226. });
  43227. subPixelOptimizeLine$1(line.shape, lineStyle.lineWidth);
  43228. axisGroup.add(line);
  43229. }
  43230. }
  43231. },
  43232. splitArea: function (axisView, axisGroup, axisModel, gridModel, api) {
  43233. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
  43234. },
  43235. breakArea: function (axisView, axisGroup, axisModel, gridModel, api) {
  43236. var scale = axisModel.axis.scale;
  43237. }
  43238. };
  43239. var CartesianXAxisView = /** @class */function (_super) {
  43240. __extends(CartesianXAxisView, _super);
  43241. function CartesianXAxisView() {
  43242. var _this = _super !== null && _super.apply(this, arguments) || this;
  43243. _this.type = CartesianXAxisView.type;
  43244. return _this;
  43245. }
  43246. CartesianXAxisView.type = 'xAxis';
  43247. return CartesianXAxisView;
  43248. }(CartesianAxisView);
  43249. var CartesianYAxisView = /** @class */function (_super) {
  43250. __extends(CartesianYAxisView, _super);
  43251. function CartesianYAxisView() {
  43252. var _this = _super !== null && _super.apply(this, arguments) || this;
  43253. _this.type = CartesianXAxisView.type;
  43254. return _this;
  43255. }
  43256. CartesianYAxisView.type = 'yAxis';
  43257. return CartesianYAxisView;
  43258. }(CartesianAxisView);
  43259. // Grid view
  43260. var GridView = /** @class */function (_super) {
  43261. __extends(GridView, _super);
  43262. function GridView() {
  43263. var _this = _super !== null && _super.apply(this, arguments) || this;
  43264. _this.type = 'grid';
  43265. return _this;
  43266. }
  43267. GridView.prototype.render = function (gridModel, ecModel) {
  43268. this.group.removeAll();
  43269. if (gridModel.get('show')) {
  43270. this.group.add(new Rect({
  43271. shape: gridModel.coordinateSystem.getRect(),
  43272. style: defaults({
  43273. fill: gridModel.get('backgroundColor')
  43274. }, gridModel.getItemStyle()),
  43275. silent: true,
  43276. z2: -1
  43277. }));
  43278. }
  43279. };
  43280. GridView.type = 'grid';
  43281. return GridView;
  43282. }(ComponentView);
  43283. var extraOption = {
  43284. // gridIndex: 0,
  43285. // gridId: '',
  43286. offset: 0
  43287. };
  43288. function install$4(registers) {
  43289. registers.registerComponentView(GridView);
  43290. registers.registerComponentModel(GridModel);
  43291. registers.registerCoordinateSystem('cartesian2d', Grid);
  43292. axisModelCreator(registers, 'x', CartesianAxisModel, extraOption);
  43293. axisModelCreator(registers, 'y', CartesianAxisModel, extraOption);
  43294. registers.registerComponentView(CartesianXAxisView);
  43295. registers.registerComponentView(CartesianYAxisView);
  43296. registers.registerPreprocessor(function (option) {
  43297. // Only create grid when need
  43298. if (option.xAxis && option.yAxis && !option.grid) {
  43299. option.grid = {};
  43300. }
  43301. });
  43302. }
  43303. var DEFAULT_OPTION = {
  43304. label: {
  43305. enabled: true
  43306. },
  43307. decal: {
  43308. show: false
  43309. }
  43310. };
  43311. var inner$6 = makeInner();
  43312. var decalPaletteScope = {};
  43313. function ariaVisual(ecModel, api) {
  43314. var ariaModel = ecModel.getModel('aria');
  43315. // See "area enabled" detection code in `GlobalModel.ts`.
  43316. if (!ariaModel.get('enabled')) {
  43317. return;
  43318. }
  43319. var defaultOption = clone(DEFAULT_OPTION);
  43320. merge(defaultOption.label, ecModel.getLocaleModel().get('aria'), false);
  43321. merge(ariaModel.option, defaultOption, false);
  43322. setDecal();
  43323. setLabel();
  43324. function setDecal() {
  43325. var decalModel = ariaModel.getModel('decal');
  43326. var useDecal = decalModel.get('show');
  43327. if (useDecal) {
  43328. // Each type of series use one scope.
  43329. // Pie and funnel are using different scopes.
  43330. var paletteScopeGroupByType_1 = createHashMap();
  43331. ecModel.eachSeries(function (seriesModel) {
  43332. if (seriesModel.isColorBySeries()) {
  43333. return;
  43334. }
  43335. var decalScope = paletteScopeGroupByType_1.get(seriesModel.type);
  43336. if (!decalScope) {
  43337. decalScope = {};
  43338. paletteScopeGroupByType_1.set(seriesModel.type, decalScope);
  43339. }
  43340. inner$6(seriesModel).scope = decalScope;
  43341. });
  43342. ecModel.eachRawSeries(function (seriesModel) {
  43343. if (ecModel.isSeriesFiltered(seriesModel)) {
  43344. return;
  43345. }
  43346. if (isFunction(seriesModel.enableAriaDecal)) {
  43347. // Let series define how to use decal palette on data
  43348. seriesModel.enableAriaDecal();
  43349. return;
  43350. }
  43351. var data = seriesModel.getData();
  43352. if (!seriesModel.isColorBySeries()) {
  43353. var dataAll_1 = seriesModel.getRawData();
  43354. var idxMap_1 = {};
  43355. var decalScope_1 = inner$6(seriesModel).scope;
  43356. data.each(function (idx) {
  43357. var rawIdx = data.getRawIndex(idx);
  43358. idxMap_1[rawIdx] = idx;
  43359. });
  43360. var dataCount_1 = dataAll_1.count();
  43361. dataAll_1.each(function (rawIdx) {
  43362. var idx = idxMap_1[rawIdx];
  43363. var name = dataAll_1.getName(rawIdx) || rawIdx + '';
  43364. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, name, decalScope_1, dataCount_1);
  43365. var specifiedDecal = data.getItemVisual(idx, 'decal');
  43366. data.setItemVisual(idx, 'decal', mergeDecal(specifiedDecal, paletteDecal));
  43367. });
  43368. } else {
  43369. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, seriesModel.name, decalPaletteScope, ecModel.getSeriesCount());
  43370. var specifiedDecal = data.getVisual('decal');
  43371. data.setVisual('decal', mergeDecal(specifiedDecal, paletteDecal));
  43372. }
  43373. function mergeDecal(specifiedDecal, paletteDecal) {
  43374. // Merge decal from palette to decal from itemStyle.
  43375. // User do not need to specify all of the decal props.
  43376. var resultDecal = specifiedDecal ? extend(extend({}, paletteDecal), specifiedDecal) : paletteDecal;
  43377. resultDecal.dirty = true;
  43378. return resultDecal;
  43379. }
  43380. });
  43381. }
  43382. }
  43383. function setLabel() {
  43384. var dom = api.getZr().dom;
  43385. // TODO: support for SSR
  43386. if (!dom) {
  43387. return;
  43388. }
  43389. var labelLocale = ecModel.getLocaleModel().get('aria');
  43390. var labelModel = ariaModel.getModel('label');
  43391. labelModel.option = defaults(labelModel.option, labelLocale);
  43392. if (!labelModel.get('enabled')) {
  43393. return;
  43394. }
  43395. dom.setAttribute('role', 'img');
  43396. if (labelModel.get('description')) {
  43397. dom.setAttribute('aria-label', labelModel.get('description'));
  43398. return;
  43399. }
  43400. var seriesCnt = ecModel.getSeriesCount();
  43401. var maxDataCnt = labelModel.get(['data', 'maxCount']) || 10;
  43402. var maxSeriesCnt = labelModel.get(['series', 'maxCount']) || 10;
  43403. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  43404. var ariaLabel;
  43405. if (seriesCnt < 1) {
  43406. // No series, no aria label
  43407. return;
  43408. } else {
  43409. var title = getTitle();
  43410. if (title) {
  43411. var withTitle = labelModel.get(['general', 'withTitle']);
  43412. ariaLabel = replace(withTitle, {
  43413. title: title
  43414. });
  43415. } else {
  43416. ariaLabel = labelModel.get(['general', 'withoutTitle']);
  43417. }
  43418. var seriesLabels_1 = [];
  43419. var prefix = seriesCnt > 1 ? labelModel.get(['series', 'multiple', 'prefix']) : labelModel.get(['series', 'single', 'prefix']);
  43420. ariaLabel += replace(prefix, {
  43421. seriesCount: seriesCnt
  43422. });
  43423. ecModel.eachSeries(function (seriesModel, idx) {
  43424. if (idx < displaySeriesCnt) {
  43425. var seriesLabel = void 0;
  43426. var seriesName = seriesModel.get('name');
  43427. var withName = seriesName ? 'withName' : 'withoutName';
  43428. seriesLabel = seriesCnt > 1 ? labelModel.get(['series', 'multiple', withName]) : labelModel.get(['series', 'single', withName]);
  43429. seriesLabel = replace(seriesLabel, {
  43430. seriesId: seriesModel.seriesIndex,
  43431. seriesName: seriesModel.get('name'),
  43432. seriesType: getSeriesTypeName(seriesModel.subType)
  43433. });
  43434. var data = seriesModel.getData();
  43435. if (data.count() > maxDataCnt) {
  43436. // Show part of data
  43437. var partialLabel = labelModel.get(['data', 'partialData']);
  43438. seriesLabel += replace(partialLabel, {
  43439. displayCnt: maxDataCnt
  43440. });
  43441. } else {
  43442. seriesLabel += labelModel.get(['data', 'allData']);
  43443. }
  43444. var middleSeparator_1 = labelModel.get(['data', 'separator', 'middle']);
  43445. var endSeparator_1 = labelModel.get(['data', 'separator', 'end']);
  43446. var excludeDimensionId_1 = labelModel.get(['data', 'excludeDimensionId']);
  43447. var dataLabels = [];
  43448. for (var i = 0; i < data.count(); i++) {
  43449. if (i < maxDataCnt) {
  43450. var name_1 = data.getName(i);
  43451. var value = !excludeDimensionId_1 ? data.getValues(i) : filter(data.getValues(i), function (v, j) {
  43452. return indexOf(excludeDimensionId_1, j) === -1;
  43453. });
  43454. var dataLabel = labelModel.get(['data', name_1 ? 'withName' : 'withoutName']);
  43455. dataLabels.push(replace(dataLabel, {
  43456. name: name_1,
  43457. value: value.join(middleSeparator_1)
  43458. }));
  43459. }
  43460. }
  43461. seriesLabel += dataLabels.join(middleSeparator_1) + endSeparator_1;
  43462. seriesLabels_1.push(seriesLabel);
  43463. }
  43464. });
  43465. var separatorModel = labelModel.getModel(['series', 'multiple', 'separator']);
  43466. var middleSeparator = separatorModel.get('middle');
  43467. var endSeparator = separatorModel.get('end');
  43468. ariaLabel += seriesLabels_1.join(middleSeparator) + endSeparator;
  43469. dom.setAttribute('aria-label', ariaLabel);
  43470. }
  43471. }
  43472. function replace(str, keyValues) {
  43473. if (!isString(str)) {
  43474. return str;
  43475. }
  43476. var result = str;
  43477. each(keyValues, function (value, key) {
  43478. result = result.replace(new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'), value);
  43479. });
  43480. return result;
  43481. }
  43482. function getTitle() {
  43483. var title = ecModel.get('title');
  43484. if (title && title.length) {
  43485. title = title[0];
  43486. }
  43487. return title && title.text;
  43488. }
  43489. function getSeriesTypeName(type) {
  43490. var typeNames = ecModel.getLocaleModel().get(['series', 'typeNames']);
  43491. return typeNames[type] || typeNames.chart;
  43492. }
  43493. }
  43494. function ariaPreprocessor(option) {
  43495. if (!option || !option.aria) {
  43496. return;
  43497. }
  43498. var aria = option.aria;
  43499. // aria.show is deprecated and should use aria.enabled instead
  43500. if (aria.show != null) {
  43501. aria.enabled = aria.show;
  43502. }
  43503. aria.label = aria.label || {};
  43504. // move description, general, series, data to be under aria.label
  43505. each(['description', 'general', 'series', 'data'], function (name) {
  43506. if (aria[name] != null) {
  43507. aria.label[name] = aria[name];
  43508. }
  43509. });
  43510. }
  43511. function install$5(registers) {
  43512. registers.registerPreprocessor(ariaPreprocessor);
  43513. registers.registerVisual(registers.PRIORITY.VISUAL.ARIA, ariaVisual);
  43514. }
  43515. var DatasetModel = /** @class */function (_super) {
  43516. __extends(DatasetModel, _super);
  43517. function DatasetModel() {
  43518. var _this = _super !== null && _super.apply(this, arguments) || this;
  43519. _this.type = 'dataset';
  43520. return _this;
  43521. }
  43522. DatasetModel.prototype.init = function (option, parentModel, ecModel) {
  43523. _super.prototype.init.call(this, option, parentModel, ecModel);
  43524. this._sourceManager = new SourceManager(this);
  43525. disableTransformOptionMerge(this);
  43526. };
  43527. DatasetModel.prototype.mergeOption = function (newOption, ecModel) {
  43528. _super.prototype.mergeOption.call(this, newOption, ecModel);
  43529. disableTransformOptionMerge(this);
  43530. };
  43531. DatasetModel.prototype.optionUpdated = function () {
  43532. this._sourceManager.dirty();
  43533. };
  43534. DatasetModel.prototype.getSourceManager = function () {
  43535. return this._sourceManager;
  43536. };
  43537. DatasetModel.type = 'dataset';
  43538. DatasetModel.defaultOption = {
  43539. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN
  43540. };
  43541. return DatasetModel;
  43542. }(ComponentModel);
  43543. var DatasetView = /** @class */function (_super) {
  43544. __extends(DatasetView, _super);
  43545. function DatasetView() {
  43546. var _this = _super !== null && _super.apply(this, arguments) || this;
  43547. _this.type = 'dataset';
  43548. return _this;
  43549. }
  43550. DatasetView.type = 'dataset';
  43551. return DatasetView;
  43552. }(ComponentView);
  43553. function install$6(registers) {
  43554. registers.registerComponentModel(DatasetModel);
  43555. registers.registerComponentView(DatasetView);
  43556. }
  43557. use([install]);
  43558. use([install$1, install$2, install$3]);
  43559. use([install$4, install$5, install$6]);
  43560. exports.Axis = Axis;
  43561. exports.ChartView = ChartView;
  43562. exports.ComponentModel = ComponentModel;
  43563. exports.ComponentView = ComponentView;
  43564. exports.List = SeriesData;
  43565. exports.Model = Model;
  43566. exports.PRIORITY = PRIORITY;
  43567. exports.SeriesModel = SeriesModel;
  43568. exports.color = color;
  43569. exports.connect = connect;
  43570. exports.dataTool = dataTool;
  43571. exports.dependencies = dependencies;
  43572. exports.disConnect = disConnect;
  43573. exports.disconnect = disconnect;
  43574. exports.dispose = dispose$1;
  43575. exports.env = env;
  43576. exports.extendChartView = extendChartView;
  43577. exports.extendComponentModel = extendComponentModel;
  43578. exports.extendComponentView = extendComponentView;
  43579. exports.extendSeriesModel = extendSeriesModel;
  43580. exports.format = format$1;
  43581. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  43582. exports.getInstanceByDom = getInstanceByDom;
  43583. exports.getInstanceById = getInstanceById;
  43584. exports.getMap = getMap;
  43585. exports.graphic = graphic;
  43586. exports.helper = helper;
  43587. exports.init = init$1;
  43588. exports.innerDrawElementOnCanvas = brushSingle;
  43589. exports.matrix = matrix;
  43590. exports.number = number;
  43591. exports.parseGeoJSON = parseGeoJSON;
  43592. exports.parseGeoJson = parseGeoJSON;
  43593. exports.registerAction = registerAction;
  43594. exports.registerCoordinateSystem = registerCoordinateSystem;
  43595. exports.registerCustomSeries = registerCustomSeries;
  43596. exports.registerLayout = registerLayout;
  43597. exports.registerLoading = registerLoading;
  43598. exports.registerLocale = registerLocale;
  43599. exports.registerMap = registerMap;
  43600. exports.registerPostInit = registerPostInit;
  43601. exports.registerPostUpdate = registerPostUpdate;
  43602. exports.registerPreprocessor = registerPreprocessor;
  43603. exports.registerProcessor = registerProcessor;
  43604. exports.registerTheme = registerTheme;
  43605. exports.registerTransform = registerTransform;
  43606. exports.registerUpdateLifecycle = registerUpdateLifecycle;
  43607. exports.registerVisual = registerVisual;
  43608. exports.setCanvasCreator = setCanvasCreator;
  43609. exports.setPlatformAPI = setPlatformAPI;
  43610. exports.throttle = throttle;
  43611. exports.time = time;
  43612. exports.use = use;
  43613. exports.util = util$1;
  43614. exports.vector = vector;
  43615. exports.version = version$1;
  43616. exports.zrUtil = util;
  43617. exports.zrender = zrender;
  43618. Object.defineProperty(exports, '__esModule', { value: true });
  43619. })));
  43620. //# sourceMappingURL=echarts.simple.js.map