echarts.common.js 2.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837618386183961840618416184261843618446184561846618476184861849618506185161852618536185461855618566185761858618596186061861618626186361864618656186661867618686186961870618716187261873618746187561876618776187861879618806188161882618836188461885618866188761888618896189061891618926189361894618956189661897618986189961900619016190261903619046190561906619076190861909619106191161912619136191461915619166191761918619196192061921619226192361924619256192661927619286192961930619316193261933619346193561936619376193861939619406194161942
  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 __assign = function() {
  51. __assign = Object.assign || function __assign(t) {
  52. for (var s, i = 1, n = arguments.length; i < n; i++) {
  53. s = arguments[i];
  54. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  55. }
  56. return t;
  57. };
  58. return __assign.apply(this, arguments);
  59. };
  60. function __spreadArray(to, from, pack) {
  61. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  62. if (ar || !(i in from)) {
  63. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  64. ar[i] = from[i];
  65. }
  66. }
  67. return to.concat(ar || from);
  68. }
  69. var Browser = (function () {
  70. function Browser() {
  71. this.firefox = false;
  72. this.ie = false;
  73. this.edge = false;
  74. this.newEdge = false;
  75. this.weChat = false;
  76. }
  77. return Browser;
  78. }());
  79. var Env = (function () {
  80. function Env() {
  81. this.browser = new Browser();
  82. this.node = false;
  83. this.wxa = false;
  84. this.worker = false;
  85. this.canvasSupported = false;
  86. this.svgSupported = false;
  87. this.touchEventsSupported = false;
  88. this.pointerEventsSupported = false;
  89. this.domSupported = false;
  90. this.transformSupported = false;
  91. this.transform3dSupported = false;
  92. }
  93. return Env;
  94. }());
  95. var env = new Env();
  96. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  97. env.wxa = true;
  98. env.canvasSupported = true;
  99. env.touchEventsSupported = true;
  100. }
  101. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  102. env.worker = true;
  103. env.canvasSupported = true;
  104. }
  105. else if (typeof navigator === 'undefined') {
  106. env.node = true;
  107. env.canvasSupported = true;
  108. env.svgSupported = true;
  109. }
  110. else {
  111. detect(navigator.userAgent, env);
  112. }
  113. function detect(ua, env) {
  114. var browser = env.browser;
  115. var firefox = ua.match(/Firefox\/([\d.]+)/);
  116. var ie = ua.match(/MSIE\s([\d.]+)/)
  117. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  118. var edge = ua.match(/Edge?\/([\d.]+)/);
  119. var weChat = (/micromessenger/i).test(ua);
  120. if (firefox) {
  121. browser.firefox = true;
  122. browser.version = firefox[1];
  123. }
  124. if (ie) {
  125. browser.ie = true;
  126. browser.version = ie[1];
  127. }
  128. if (edge) {
  129. browser.edge = true;
  130. browser.version = edge[1];
  131. browser.newEdge = +edge[1].split('.')[0] > 18;
  132. }
  133. if (weChat) {
  134. browser.weChat = true;
  135. }
  136. env.canvasSupported = !!document.createElement('canvas').getContext;
  137. env.svgSupported = typeof SVGRect !== 'undefined';
  138. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  139. env.pointerEventsSupported = 'onpointerdown' in window
  140. && (browser.edge || (browser.ie && +browser.version >= 11));
  141. env.domSupported = typeof document !== 'undefined';
  142. var style = document.documentElement.style;
  143. env.transform3dSupported = ((browser.ie && 'transition' in style)
  144. || browser.edge
  145. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  146. || 'MozPerspective' in style)
  147. && !('OTransition' in style);
  148. env.transformSupported = env.transform3dSupported
  149. || (browser.ie && +browser.version >= 9);
  150. }
  151. var BUILTIN_OBJECT = {
  152. '[object Function]': true,
  153. '[object RegExp]': true,
  154. '[object Date]': true,
  155. '[object Error]': true,
  156. '[object CanvasGradient]': true,
  157. '[object CanvasPattern]': true,
  158. '[object Image]': true,
  159. '[object Canvas]': true
  160. };
  161. var TYPED_ARRAY = {
  162. '[object Int8Array]': true,
  163. '[object Uint8Array]': true,
  164. '[object Uint8ClampedArray]': true,
  165. '[object Int16Array]': true,
  166. '[object Uint16Array]': true,
  167. '[object Int32Array]': true,
  168. '[object Uint32Array]': true,
  169. '[object Float32Array]': true,
  170. '[object Float64Array]': true
  171. };
  172. var objToString = Object.prototype.toString;
  173. var arrayProto = Array.prototype;
  174. var nativeForEach = arrayProto.forEach;
  175. var nativeFilter = arrayProto.filter;
  176. var nativeSlice = arrayProto.slice;
  177. var nativeMap = arrayProto.map;
  178. var ctorFunction = function () { }.constructor;
  179. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  180. var protoKey = '__proto__';
  181. var methods = {};
  182. function $override(name, fn) {
  183. methods[name] = fn;
  184. }
  185. var idStart = 0x0907;
  186. function guid() {
  187. return idStart++;
  188. }
  189. function logError() {
  190. var args = [];
  191. for (var _i = 0; _i < arguments.length; _i++) {
  192. args[_i] = arguments[_i];
  193. }
  194. if (typeof console !== 'undefined') {
  195. console.error.apply(console, args);
  196. }
  197. }
  198. function clone(source) {
  199. if (source == null || typeof source !== 'object') {
  200. return source;
  201. }
  202. var result = source;
  203. var typeStr = objToString.call(source);
  204. if (typeStr === '[object Array]') {
  205. if (!isPrimitive(source)) {
  206. result = [];
  207. for (var i = 0, len = source.length; i < len; i++) {
  208. result[i] = clone(source[i]);
  209. }
  210. }
  211. }
  212. else if (TYPED_ARRAY[typeStr]) {
  213. if (!isPrimitive(source)) {
  214. var Ctor = source.constructor;
  215. if (Ctor.from) {
  216. result = Ctor.from(source);
  217. }
  218. else {
  219. result = new Ctor(source.length);
  220. for (var i = 0, len = source.length; i < len; i++) {
  221. result[i] = clone(source[i]);
  222. }
  223. }
  224. }
  225. }
  226. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  227. result = {};
  228. for (var key in source) {
  229. if (source.hasOwnProperty(key) && key !== protoKey) {
  230. result[key] = clone(source[key]);
  231. }
  232. }
  233. }
  234. return result;
  235. }
  236. function merge(target, source, overwrite) {
  237. if (!isObject(source) || !isObject(target)) {
  238. return overwrite ? clone(source) : target;
  239. }
  240. for (var key in source) {
  241. if (source.hasOwnProperty(key) && key !== protoKey) {
  242. var targetProp = target[key];
  243. var sourceProp = source[key];
  244. if (isObject(sourceProp)
  245. && isObject(targetProp)
  246. && !isArray(sourceProp)
  247. && !isArray(targetProp)
  248. && !isDom(sourceProp)
  249. && !isDom(targetProp)
  250. && !isBuiltInObject(sourceProp)
  251. && !isBuiltInObject(targetProp)
  252. && !isPrimitive(sourceProp)
  253. && !isPrimitive(targetProp)) {
  254. merge(targetProp, sourceProp, overwrite);
  255. }
  256. else if (overwrite || !(key in target)) {
  257. target[key] = clone(source[key]);
  258. }
  259. }
  260. }
  261. return target;
  262. }
  263. function mergeAll(targetAndSources, overwrite) {
  264. var result = targetAndSources[0];
  265. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  266. result = merge(result, targetAndSources[i], overwrite);
  267. }
  268. return result;
  269. }
  270. function extend(target, source) {
  271. if (Object.assign) {
  272. Object.assign(target, source);
  273. }
  274. else {
  275. for (var key in source) {
  276. if (source.hasOwnProperty(key) && key !== protoKey) {
  277. target[key] = source[key];
  278. }
  279. }
  280. }
  281. return target;
  282. }
  283. function defaults(target, source, overlay) {
  284. var keysArr = keys(source);
  285. for (var i = 0; i < keysArr.length; i++) {
  286. var key = keysArr[i];
  287. if ((overlay ? source[key] != null : target[key] == null)) {
  288. target[key] = source[key];
  289. }
  290. }
  291. return target;
  292. }
  293. var createCanvas = function () {
  294. return methods.createCanvas();
  295. };
  296. methods.createCanvas = function () {
  297. return document.createElement('canvas');
  298. };
  299. function indexOf(array, value) {
  300. if (array) {
  301. if (array.indexOf) {
  302. return array.indexOf(value);
  303. }
  304. for (var i = 0, len = array.length; i < len; i++) {
  305. if (array[i] === value) {
  306. return i;
  307. }
  308. }
  309. }
  310. return -1;
  311. }
  312. function inherits(clazz, baseClazz) {
  313. var clazzPrototype = clazz.prototype;
  314. function F() { }
  315. F.prototype = baseClazz.prototype;
  316. clazz.prototype = new F();
  317. for (var prop in clazzPrototype) {
  318. if (clazzPrototype.hasOwnProperty(prop)) {
  319. clazz.prototype[prop] = clazzPrototype[prop];
  320. }
  321. }
  322. clazz.prototype.constructor = clazz;
  323. clazz.superClass = baseClazz;
  324. }
  325. function mixin(target, source, override) {
  326. target = 'prototype' in target ? target.prototype : target;
  327. source = 'prototype' in source ? source.prototype : source;
  328. if (Object.getOwnPropertyNames) {
  329. var keyList = Object.getOwnPropertyNames(source);
  330. for (var i = 0; i < keyList.length; i++) {
  331. var key = keyList[i];
  332. if (key !== 'constructor') {
  333. if ((override ? source[key] != null : target[key] == null)) {
  334. target[key] = source[key];
  335. }
  336. }
  337. }
  338. }
  339. else {
  340. defaults(target, source, override);
  341. }
  342. }
  343. function isArrayLike(data) {
  344. if (!data) {
  345. return false;
  346. }
  347. if (typeof data === 'string') {
  348. return false;
  349. }
  350. return typeof data.length === 'number';
  351. }
  352. function each(arr, cb, context) {
  353. if (!(arr && cb)) {
  354. return;
  355. }
  356. if (arr.forEach && arr.forEach === nativeForEach) {
  357. arr.forEach(cb, context);
  358. }
  359. else if (arr.length === +arr.length) {
  360. for (var i = 0, len = arr.length; i < len; i++) {
  361. cb.call(context, arr[i], i, arr);
  362. }
  363. }
  364. else {
  365. for (var key in arr) {
  366. if (arr.hasOwnProperty(key)) {
  367. cb.call(context, arr[key], key, arr);
  368. }
  369. }
  370. }
  371. }
  372. function map(arr, cb, context) {
  373. if (!arr) {
  374. return [];
  375. }
  376. if (!cb) {
  377. return slice(arr);
  378. }
  379. if (arr.map && arr.map === nativeMap) {
  380. return arr.map(cb, context);
  381. }
  382. else {
  383. var result = [];
  384. for (var i = 0, len = arr.length; i < len; i++) {
  385. result.push(cb.call(context, arr[i], i, arr));
  386. }
  387. return result;
  388. }
  389. }
  390. function reduce(arr, cb, memo, context) {
  391. if (!(arr && cb)) {
  392. return;
  393. }
  394. for (var i = 0, len = arr.length; i < len; i++) {
  395. memo = cb.call(context, memo, arr[i], i, arr);
  396. }
  397. return memo;
  398. }
  399. function filter(arr, cb, context) {
  400. if (!arr) {
  401. return [];
  402. }
  403. if (!cb) {
  404. return slice(arr);
  405. }
  406. if (arr.filter && arr.filter === nativeFilter) {
  407. return arr.filter(cb, context);
  408. }
  409. else {
  410. var result = [];
  411. for (var i = 0, len = arr.length; i < len; i++) {
  412. if (cb.call(context, arr[i], i, arr)) {
  413. result.push(arr[i]);
  414. }
  415. }
  416. return result;
  417. }
  418. }
  419. function find(arr, cb, context) {
  420. if (!(arr && cb)) {
  421. return;
  422. }
  423. for (var i = 0, len = arr.length; i < len; i++) {
  424. if (cb.call(context, arr[i], i, arr)) {
  425. return arr[i];
  426. }
  427. }
  428. }
  429. function keys(obj) {
  430. if (!obj) {
  431. return [];
  432. }
  433. if (Object.keys) {
  434. return Object.keys(obj);
  435. }
  436. var keyList = [];
  437. for (var key in obj) {
  438. if (obj.hasOwnProperty(key)) {
  439. keyList.push(key);
  440. }
  441. }
  442. return keyList;
  443. }
  444. function bindPolyfill(func, context) {
  445. var args = [];
  446. for (var _i = 2; _i < arguments.length; _i++) {
  447. args[_i - 2] = arguments[_i];
  448. }
  449. return function () {
  450. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  451. };
  452. }
  453. var bind = (protoFunction && isFunction(protoFunction.bind))
  454. ? protoFunction.call.bind(protoFunction.bind)
  455. : bindPolyfill;
  456. function curry(func) {
  457. var args = [];
  458. for (var _i = 1; _i < arguments.length; _i++) {
  459. args[_i - 1] = arguments[_i];
  460. }
  461. return function () {
  462. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  463. };
  464. }
  465. function isArray(value) {
  466. if (Array.isArray) {
  467. return Array.isArray(value);
  468. }
  469. return objToString.call(value) === '[object Array]';
  470. }
  471. function isFunction(value) {
  472. return typeof value === 'function';
  473. }
  474. function isString(value) {
  475. return typeof value === 'string';
  476. }
  477. function isStringSafe(value) {
  478. return objToString.call(value) === '[object String]';
  479. }
  480. function isNumber(value) {
  481. return typeof value === 'number';
  482. }
  483. function isObject(value) {
  484. var type = typeof value;
  485. return type === 'function' || (!!value && type === 'object');
  486. }
  487. function isBuiltInObject(value) {
  488. return !!BUILTIN_OBJECT[objToString.call(value)];
  489. }
  490. function isTypedArray(value) {
  491. return !!TYPED_ARRAY[objToString.call(value)];
  492. }
  493. function isDom(value) {
  494. return typeof value === 'object'
  495. && typeof value.nodeType === 'number'
  496. && typeof value.ownerDocument === 'object';
  497. }
  498. function isGradientObject(value) {
  499. return value.colorStops != null;
  500. }
  501. function isImagePatternObject(value) {
  502. return value.image != null;
  503. }
  504. function isRegExp(value) {
  505. return objToString.call(value) === '[object RegExp]';
  506. }
  507. function eqNaN(value) {
  508. return value !== value;
  509. }
  510. function retrieve() {
  511. var args = [];
  512. for (var _i = 0; _i < arguments.length; _i++) {
  513. args[_i] = arguments[_i];
  514. }
  515. for (var i = 0, len = args.length; i < len; i++) {
  516. if (args[i] != null) {
  517. return args[i];
  518. }
  519. }
  520. }
  521. function retrieve2(value0, value1) {
  522. return value0 != null
  523. ? value0
  524. : value1;
  525. }
  526. function retrieve3(value0, value1, value2) {
  527. return value0 != null
  528. ? value0
  529. : value1 != null
  530. ? value1
  531. : value2;
  532. }
  533. function slice(arr) {
  534. var args = [];
  535. for (var _i = 1; _i < arguments.length; _i++) {
  536. args[_i - 1] = arguments[_i];
  537. }
  538. return nativeSlice.apply(arr, args);
  539. }
  540. function normalizeCssArray(val) {
  541. if (typeof (val) === 'number') {
  542. return [val, val, val, val];
  543. }
  544. var len = val.length;
  545. if (len === 2) {
  546. return [val[0], val[1], val[0], val[1]];
  547. }
  548. else if (len === 3) {
  549. return [val[0], val[1], val[2], val[1]];
  550. }
  551. return val;
  552. }
  553. function assert(condition, message) {
  554. if (!condition) {
  555. throw new Error(message);
  556. }
  557. }
  558. function trim(str) {
  559. if (str == null) {
  560. return null;
  561. }
  562. else if (typeof str.trim === 'function') {
  563. return str.trim();
  564. }
  565. else {
  566. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  567. }
  568. }
  569. var primitiveKey = '__ec_primitive__';
  570. function setAsPrimitive(obj) {
  571. obj[primitiveKey] = true;
  572. }
  573. function isPrimitive(obj) {
  574. return obj[primitiveKey];
  575. }
  576. var HashMap = (function () {
  577. function HashMap(obj) {
  578. this.data = {};
  579. var isArr = isArray(obj);
  580. this.data = {};
  581. var thisMap = this;
  582. (obj instanceof HashMap)
  583. ? obj.each(visit)
  584. : (obj && each(obj, visit));
  585. function visit(value, key) {
  586. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  587. }
  588. }
  589. HashMap.prototype.get = function (key) {
  590. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  591. };
  592. HashMap.prototype.set = function (key, value) {
  593. return (this.data[key] = value);
  594. };
  595. HashMap.prototype.each = function (cb, context) {
  596. for (var key in this.data) {
  597. if (this.data.hasOwnProperty(key)) {
  598. cb.call(context, this.data[key], key);
  599. }
  600. }
  601. };
  602. HashMap.prototype.keys = function () {
  603. return keys(this.data);
  604. };
  605. HashMap.prototype.removeKey = function (key) {
  606. delete this.data[key];
  607. };
  608. return HashMap;
  609. }());
  610. function createHashMap(obj) {
  611. return new HashMap(obj);
  612. }
  613. function concatArray(a, b) {
  614. var newArray = new a.constructor(a.length + b.length);
  615. for (var i = 0; i < a.length; i++) {
  616. newArray[i] = a[i];
  617. }
  618. var offset = a.length;
  619. for (var i = 0; i < b.length; i++) {
  620. newArray[i + offset] = b[i];
  621. }
  622. return newArray;
  623. }
  624. function createObject(proto, properties) {
  625. var obj;
  626. if (Object.create) {
  627. obj = Object.create(proto);
  628. }
  629. else {
  630. var StyleCtor = function () { };
  631. StyleCtor.prototype = proto;
  632. obj = new StyleCtor();
  633. }
  634. if (properties) {
  635. extend(obj, properties);
  636. }
  637. return obj;
  638. }
  639. function hasOwn(own, prop) {
  640. return own.hasOwnProperty(prop);
  641. }
  642. function noop() { }
  643. var util = /*#__PURE__*/Object.freeze({
  644. __proto__: null,
  645. $override: $override,
  646. guid: guid,
  647. logError: logError,
  648. clone: clone,
  649. merge: merge,
  650. mergeAll: mergeAll,
  651. extend: extend,
  652. defaults: defaults,
  653. createCanvas: createCanvas,
  654. indexOf: indexOf,
  655. inherits: inherits,
  656. mixin: mixin,
  657. isArrayLike: isArrayLike,
  658. each: each,
  659. map: map,
  660. reduce: reduce,
  661. filter: filter,
  662. find: find,
  663. keys: keys,
  664. bind: bind,
  665. curry: curry,
  666. isArray: isArray,
  667. isFunction: isFunction,
  668. isString: isString,
  669. isStringSafe: isStringSafe,
  670. isNumber: isNumber,
  671. isObject: isObject,
  672. isBuiltInObject: isBuiltInObject,
  673. isTypedArray: isTypedArray,
  674. isDom: isDom,
  675. isGradientObject: isGradientObject,
  676. isImagePatternObject: isImagePatternObject,
  677. isRegExp: isRegExp,
  678. eqNaN: eqNaN,
  679. retrieve: retrieve,
  680. retrieve2: retrieve2,
  681. retrieve3: retrieve3,
  682. slice: slice,
  683. normalizeCssArray: normalizeCssArray,
  684. assert: assert,
  685. trim: trim,
  686. setAsPrimitive: setAsPrimitive,
  687. isPrimitive: isPrimitive,
  688. HashMap: HashMap,
  689. createHashMap: createHashMap,
  690. concatArray: concatArray,
  691. createObject: createObject,
  692. hasOwn: hasOwn,
  693. noop: noop
  694. });
  695. function create(x, y) {
  696. if (x == null) {
  697. x = 0;
  698. }
  699. if (y == null) {
  700. y = 0;
  701. }
  702. return [x, y];
  703. }
  704. function copy(out, v) {
  705. out[0] = v[0];
  706. out[1] = v[1];
  707. return out;
  708. }
  709. function clone$1(v) {
  710. return [v[0], v[1]];
  711. }
  712. function set(out, a, b) {
  713. out[0] = a;
  714. out[1] = b;
  715. return out;
  716. }
  717. function add(out, v1, v2) {
  718. out[0] = v1[0] + v2[0];
  719. out[1] = v1[1] + v2[1];
  720. return out;
  721. }
  722. function scaleAndAdd(out, v1, v2, a) {
  723. out[0] = v1[0] + v2[0] * a;
  724. out[1] = v1[1] + v2[1] * a;
  725. return out;
  726. }
  727. function sub(out, v1, v2) {
  728. out[0] = v1[0] - v2[0];
  729. out[1] = v1[1] - v2[1];
  730. return out;
  731. }
  732. function len(v) {
  733. return Math.sqrt(lenSquare(v));
  734. }
  735. var length = len;
  736. function lenSquare(v) {
  737. return v[0] * v[0] + v[1] * v[1];
  738. }
  739. var lengthSquare = lenSquare;
  740. function mul(out, v1, v2) {
  741. out[0] = v1[0] * v2[0];
  742. out[1] = v1[1] * v2[1];
  743. return out;
  744. }
  745. function div(out, v1, v2) {
  746. out[0] = v1[0] / v2[0];
  747. out[1] = v1[1] / v2[1];
  748. return out;
  749. }
  750. function dot(v1, v2) {
  751. return v1[0] * v2[0] + v1[1] * v2[1];
  752. }
  753. function scale(out, v, s) {
  754. out[0] = v[0] * s;
  755. out[1] = v[1] * s;
  756. return out;
  757. }
  758. function normalize(out, v) {
  759. var d = len(v);
  760. if (d === 0) {
  761. out[0] = 0;
  762. out[1] = 0;
  763. }
  764. else {
  765. out[0] = v[0] / d;
  766. out[1] = v[1] / d;
  767. }
  768. return out;
  769. }
  770. function distance(v1, v2) {
  771. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  772. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  773. }
  774. var dist = distance;
  775. function distanceSquare(v1, v2) {
  776. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  777. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  778. }
  779. var distSquare = distanceSquare;
  780. function negate(out, v) {
  781. out[0] = -v[0];
  782. out[1] = -v[1];
  783. return out;
  784. }
  785. function lerp(out, v1, v2, t) {
  786. out[0] = v1[0] + t * (v2[0] - v1[0]);
  787. out[1] = v1[1] + t * (v2[1] - v1[1]);
  788. return out;
  789. }
  790. function applyTransform(out, v, m) {
  791. var x = v[0];
  792. var y = v[1];
  793. out[0] = m[0] * x + m[2] * y + m[4];
  794. out[1] = m[1] * x + m[3] * y + m[5];
  795. return out;
  796. }
  797. function min(out, v1, v2) {
  798. out[0] = Math.min(v1[0], v2[0]);
  799. out[1] = Math.min(v1[1], v2[1]);
  800. return out;
  801. }
  802. function max(out, v1, v2) {
  803. out[0] = Math.max(v1[0], v2[0]);
  804. out[1] = Math.max(v1[1], v2[1]);
  805. return out;
  806. }
  807. var vector = /*#__PURE__*/Object.freeze({
  808. __proto__: null,
  809. create: create,
  810. copy: copy,
  811. clone: clone$1,
  812. set: set,
  813. add: add,
  814. scaleAndAdd: scaleAndAdd,
  815. sub: sub,
  816. len: len,
  817. length: length,
  818. lenSquare: lenSquare,
  819. lengthSquare: lengthSquare,
  820. mul: mul,
  821. div: div,
  822. dot: dot,
  823. scale: scale,
  824. normalize: normalize,
  825. distance: distance,
  826. dist: dist,
  827. distanceSquare: distanceSquare,
  828. distSquare: distSquare,
  829. negate: negate,
  830. lerp: lerp,
  831. applyTransform: applyTransform,
  832. min: min,
  833. max: max
  834. });
  835. var Param = (function () {
  836. function Param(target, e) {
  837. this.target = target;
  838. this.topTarget = e && e.topTarget;
  839. }
  840. return Param;
  841. }());
  842. var Draggable = (function () {
  843. function Draggable(handler) {
  844. this.handler = handler;
  845. handler.on('mousedown', this._dragStart, this);
  846. handler.on('mousemove', this._drag, this);
  847. handler.on('mouseup', this._dragEnd, this);
  848. }
  849. Draggable.prototype._dragStart = function (e) {
  850. var draggingTarget = e.target;
  851. while (draggingTarget && !draggingTarget.draggable) {
  852. draggingTarget = draggingTarget.parent;
  853. }
  854. if (draggingTarget) {
  855. this._draggingTarget = draggingTarget;
  856. draggingTarget.dragging = true;
  857. this._x = e.offsetX;
  858. this._y = e.offsetY;
  859. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  860. }
  861. };
  862. Draggable.prototype._drag = function (e) {
  863. var draggingTarget = this._draggingTarget;
  864. if (draggingTarget) {
  865. var x = e.offsetX;
  866. var y = e.offsetY;
  867. var dx = x - this._x;
  868. var dy = y - this._y;
  869. this._x = x;
  870. this._y = y;
  871. draggingTarget.drift(dx, dy, e);
  872. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  873. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  874. var lastDropTarget = this._dropTarget;
  875. this._dropTarget = dropTarget;
  876. if (draggingTarget !== dropTarget) {
  877. if (lastDropTarget && dropTarget !== lastDropTarget) {
  878. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  879. }
  880. if (dropTarget && dropTarget !== lastDropTarget) {
  881. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  882. }
  883. }
  884. }
  885. };
  886. Draggable.prototype._dragEnd = function (e) {
  887. var draggingTarget = this._draggingTarget;
  888. if (draggingTarget) {
  889. draggingTarget.dragging = false;
  890. }
  891. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  892. if (this._dropTarget) {
  893. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  894. }
  895. this._draggingTarget = null;
  896. this._dropTarget = null;
  897. };
  898. return Draggable;
  899. }());
  900. var Eventful = (function () {
  901. function Eventful(eventProcessors) {
  902. if (eventProcessors) {
  903. this._$eventProcessor = eventProcessors;
  904. }
  905. }
  906. Eventful.prototype.on = function (event, query, handler, context) {
  907. if (!this._$handlers) {
  908. this._$handlers = {};
  909. }
  910. var _h = this._$handlers;
  911. if (typeof query === 'function') {
  912. context = handler;
  913. handler = query;
  914. query = null;
  915. }
  916. if (!handler || !event) {
  917. return this;
  918. }
  919. var eventProcessor = this._$eventProcessor;
  920. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  921. query = eventProcessor.normalizeQuery(query);
  922. }
  923. if (!_h[event]) {
  924. _h[event] = [];
  925. }
  926. for (var i = 0; i < _h[event].length; i++) {
  927. if (_h[event][i].h === handler) {
  928. return this;
  929. }
  930. }
  931. var wrap = {
  932. h: handler,
  933. query: query,
  934. ctx: (context || this),
  935. callAtLast: handler.zrEventfulCallAtLast
  936. };
  937. var lastIndex = _h[event].length - 1;
  938. var lastWrap = _h[event][lastIndex];
  939. (lastWrap && lastWrap.callAtLast)
  940. ? _h[event].splice(lastIndex, 0, wrap)
  941. : _h[event].push(wrap);
  942. return this;
  943. };
  944. Eventful.prototype.isSilent = function (eventName) {
  945. var _h = this._$handlers;
  946. return !_h || !_h[eventName] || !_h[eventName].length;
  947. };
  948. Eventful.prototype.off = function (eventType, handler) {
  949. var _h = this._$handlers;
  950. if (!_h) {
  951. return this;
  952. }
  953. if (!eventType) {
  954. this._$handlers = {};
  955. return this;
  956. }
  957. if (handler) {
  958. if (_h[eventType]) {
  959. var newList = [];
  960. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  961. if (_h[eventType][i].h !== handler) {
  962. newList.push(_h[eventType][i]);
  963. }
  964. }
  965. _h[eventType] = newList;
  966. }
  967. if (_h[eventType] && _h[eventType].length === 0) {
  968. delete _h[eventType];
  969. }
  970. }
  971. else {
  972. delete _h[eventType];
  973. }
  974. return this;
  975. };
  976. Eventful.prototype.trigger = function (eventType) {
  977. var args = [];
  978. for (var _i = 1; _i < arguments.length; _i++) {
  979. args[_i - 1] = arguments[_i];
  980. }
  981. if (!this._$handlers) {
  982. return this;
  983. }
  984. var _h = this._$handlers[eventType];
  985. var eventProcessor = this._$eventProcessor;
  986. if (_h) {
  987. var argLen = args.length;
  988. var len = _h.length;
  989. for (var i = 0; i < len; i++) {
  990. var hItem = _h[i];
  991. if (eventProcessor
  992. && eventProcessor.filter
  993. && hItem.query != null
  994. && !eventProcessor.filter(eventType, hItem.query)) {
  995. continue;
  996. }
  997. switch (argLen) {
  998. case 0:
  999. hItem.h.call(hItem.ctx);
  1000. break;
  1001. case 1:
  1002. hItem.h.call(hItem.ctx, args[0]);
  1003. break;
  1004. case 2:
  1005. hItem.h.call(hItem.ctx, args[0], args[1]);
  1006. break;
  1007. default:
  1008. hItem.h.apply(hItem.ctx, args);
  1009. break;
  1010. }
  1011. }
  1012. }
  1013. eventProcessor && eventProcessor.afterTrigger
  1014. && eventProcessor.afterTrigger(eventType);
  1015. return this;
  1016. };
  1017. Eventful.prototype.triggerWithContext = function (type) {
  1018. var args = [];
  1019. for (var _i = 1; _i < arguments.length; _i++) {
  1020. args[_i - 1] = arguments[_i];
  1021. }
  1022. if (!this._$handlers) {
  1023. return this;
  1024. }
  1025. var _h = this._$handlers[type];
  1026. var eventProcessor = this._$eventProcessor;
  1027. if (_h) {
  1028. var argLen = args.length;
  1029. var ctx = args[argLen - 1];
  1030. var len = _h.length;
  1031. for (var i = 0; i < len; i++) {
  1032. var hItem = _h[i];
  1033. if (eventProcessor
  1034. && eventProcessor.filter
  1035. && hItem.query != null
  1036. && !eventProcessor.filter(type, hItem.query)) {
  1037. continue;
  1038. }
  1039. switch (argLen) {
  1040. case 0:
  1041. hItem.h.call(ctx);
  1042. break;
  1043. case 1:
  1044. hItem.h.call(ctx, args[0]);
  1045. break;
  1046. case 2:
  1047. hItem.h.call(ctx, args[0], args[1]);
  1048. break;
  1049. default:
  1050. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. eventProcessor && eventProcessor.afterTrigger
  1056. && eventProcessor.afterTrigger(type);
  1057. return this;
  1058. };
  1059. return Eventful;
  1060. }());
  1061. var LN2 = Math.log(2);
  1062. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1063. var cacheKey = rowMask + '-' + colMask;
  1064. var fullRank = rows.length;
  1065. if (detCache.hasOwnProperty(cacheKey)) {
  1066. return detCache[cacheKey];
  1067. }
  1068. if (rank === 1) {
  1069. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1070. return rows[rowStart][colStart];
  1071. }
  1072. var subRowMask = rowMask | (1 << rowStart);
  1073. var subRowStart = rowStart + 1;
  1074. while (rowMask & (1 << subRowStart)) {
  1075. subRowStart++;
  1076. }
  1077. var sum = 0;
  1078. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1079. var colTag = 1 << j;
  1080. if (!(colTag & colMask)) {
  1081. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1082. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1083. colLocalIdx++;
  1084. }
  1085. }
  1086. detCache[cacheKey] = sum;
  1087. return sum;
  1088. }
  1089. function buildTransformer(src, dest) {
  1090. var mA = [
  1091. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1092. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1093. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1094. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1095. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1096. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1097. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1098. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1099. ];
  1100. var detCache = {};
  1101. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1102. if (det === 0) {
  1103. return;
  1104. }
  1105. var vh = [];
  1106. for (var i = 0; i < 8; i++) {
  1107. for (var j = 0; j < 8; j++) {
  1108. vh[j] == null && (vh[j] = 0);
  1109. vh[j] += ((i + j) % 2 ? -1 : 1)
  1110. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1111. / det * dest[i];
  1112. }
  1113. }
  1114. return function (out, srcPointX, srcPointY) {
  1115. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1116. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1117. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1118. };
  1119. }
  1120. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1121. var _calcOut = [];
  1122. function transformLocalCoord(out, elFrom, elTarget, inX, inY) {
  1123. return transformCoordWithViewport(_calcOut, elFrom, inX, inY, true)
  1124. && transformCoordWithViewport(out, elTarget, _calcOut[0], _calcOut[1]);
  1125. }
  1126. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1127. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1128. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1129. var markers = prepareCoordMarkers(el, saved);
  1130. var transformer = preparePointerTransformer(markers, saved, inverse);
  1131. if (transformer) {
  1132. transformer(out, inX, inY);
  1133. return true;
  1134. }
  1135. }
  1136. return false;
  1137. }
  1138. function prepareCoordMarkers(el, saved) {
  1139. var markers = saved.markers;
  1140. if (markers) {
  1141. return markers;
  1142. }
  1143. markers = saved.markers = [];
  1144. var propLR = ['left', 'right'];
  1145. var propTB = ['top', 'bottom'];
  1146. for (var i = 0; i < 4; i++) {
  1147. var marker = document.createElement('div');
  1148. var stl = marker.style;
  1149. var idxLR = i % 2;
  1150. var idxTB = (i >> 1) % 2;
  1151. stl.cssText = [
  1152. 'position: absolute',
  1153. 'visibility: hidden',
  1154. 'padding: 0',
  1155. 'margin: 0',
  1156. 'border-width: 0',
  1157. 'user-select: none',
  1158. 'width:0',
  1159. 'height:0',
  1160. propLR[idxLR] + ':0',
  1161. propTB[idxTB] + ':0',
  1162. propLR[1 - idxLR] + ':auto',
  1163. propTB[1 - idxTB] + ':auto',
  1164. ''
  1165. ].join('!important;');
  1166. el.appendChild(marker);
  1167. markers.push(marker);
  1168. }
  1169. return markers;
  1170. }
  1171. function preparePointerTransformer(markers, saved, inverse) {
  1172. var transformerName = inverse ? 'invTrans' : 'trans';
  1173. var transformer = saved[transformerName];
  1174. var oldSrcCoords = saved.srcCoords;
  1175. var srcCoords = [];
  1176. var destCoords = [];
  1177. var oldCoordTheSame = true;
  1178. for (var i = 0; i < 4; i++) {
  1179. var rect = markers[i].getBoundingClientRect();
  1180. var ii = 2 * i;
  1181. var x = rect.left;
  1182. var y = rect.top;
  1183. srcCoords.push(x, y);
  1184. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1185. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1186. }
  1187. return (oldCoordTheSame && transformer)
  1188. ? transformer
  1189. : (saved.srcCoords = srcCoords,
  1190. saved[transformerName] = inverse
  1191. ? buildTransformer(destCoords, srcCoords)
  1192. : buildTransformer(srcCoords, destCoords));
  1193. }
  1194. function isCanvasEl(el) {
  1195. return el.nodeName.toUpperCase() === 'CANVAS';
  1196. }
  1197. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  1198. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1199. var _calcOut$1 = [];
  1200. function clientToLocal(el, e, out, calculate) {
  1201. out = out || {};
  1202. if (calculate || !env.canvasSupported) {
  1203. calculateZrXY(el, e, out);
  1204. }
  1205. else if (env.browser.firefox
  1206. && env.browser.version < '39'
  1207. && e.layerX != null
  1208. && e.layerX !== e.offsetX) {
  1209. out.zrX = e.layerX;
  1210. out.zrY = e.layerY;
  1211. }
  1212. else if (e.offsetX != null) {
  1213. out.zrX = e.offsetX;
  1214. out.zrY = e.offsetY;
  1215. }
  1216. else {
  1217. calculateZrXY(el, e, out);
  1218. }
  1219. return out;
  1220. }
  1221. function calculateZrXY(el, e, out) {
  1222. if (env.domSupported && el.getBoundingClientRect) {
  1223. var ex = e.clientX;
  1224. var ey = e.clientY;
  1225. if (isCanvasEl(el)) {
  1226. var box = el.getBoundingClientRect();
  1227. out.zrX = ex - box.left;
  1228. out.zrY = ey - box.top;
  1229. return;
  1230. }
  1231. else {
  1232. if (transformCoordWithViewport(_calcOut$1, el, ex, ey)) {
  1233. out.zrX = _calcOut$1[0];
  1234. out.zrY = _calcOut$1[1];
  1235. return;
  1236. }
  1237. }
  1238. }
  1239. out.zrX = out.zrY = 0;
  1240. }
  1241. function getNativeEvent(e) {
  1242. return e
  1243. || window.event;
  1244. }
  1245. function normalizeEvent(el, e, calculate) {
  1246. e = getNativeEvent(e);
  1247. if (e.zrX != null) {
  1248. return e;
  1249. }
  1250. var eventType = e.type;
  1251. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1252. if (!isTouch) {
  1253. clientToLocal(el, e, e, calculate);
  1254. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1255. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1256. }
  1257. else {
  1258. var touch = eventType !== 'touchend'
  1259. ? e.targetTouches[0]
  1260. : e.changedTouches[0];
  1261. touch && clientToLocal(el, touch, e, calculate);
  1262. }
  1263. var button = e.button;
  1264. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1265. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1266. }
  1267. return e;
  1268. }
  1269. function getWheelDeltaMayPolyfill(e) {
  1270. var rawWheelDelta = e.wheelDelta;
  1271. if (rawWheelDelta) {
  1272. return rawWheelDelta;
  1273. }
  1274. var deltaX = e.deltaX;
  1275. var deltaY = e.deltaY;
  1276. if (deltaX == null || deltaY == null) {
  1277. return rawWheelDelta;
  1278. }
  1279. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1280. var sign = deltaY > 0 ? -1
  1281. : deltaY < 0 ? 1
  1282. : deltaX > 0 ? -1
  1283. : 1;
  1284. return 3 * delta * sign;
  1285. }
  1286. function addEventListener(el, name, handler, opt) {
  1287. if (isDomLevel2) {
  1288. el.addEventListener(name, handler, opt);
  1289. }
  1290. else {
  1291. el.attachEvent('on' + name, handler);
  1292. }
  1293. }
  1294. function removeEventListener(el, name, handler, opt) {
  1295. if (isDomLevel2) {
  1296. el.removeEventListener(name, handler, opt);
  1297. }
  1298. else {
  1299. el.detachEvent('on' + name, handler);
  1300. }
  1301. }
  1302. var stop = isDomLevel2
  1303. ? function (e) {
  1304. e.preventDefault();
  1305. e.stopPropagation();
  1306. e.cancelBubble = true;
  1307. }
  1308. : function (e) {
  1309. e.returnValue = false;
  1310. e.cancelBubble = true;
  1311. };
  1312. function isMiddleOrRightButtonOnMouseUpDown(e) {
  1313. return e.which === 2 || e.which === 3;
  1314. }
  1315. var GestureMgr = (function () {
  1316. function GestureMgr() {
  1317. this._track = [];
  1318. }
  1319. GestureMgr.prototype.recognize = function (event, target, root) {
  1320. this._doTrack(event, target, root);
  1321. return this._recognize(event);
  1322. };
  1323. GestureMgr.prototype.clear = function () {
  1324. this._track.length = 0;
  1325. return this;
  1326. };
  1327. GestureMgr.prototype._doTrack = function (event, target, root) {
  1328. var touches = event.touches;
  1329. if (!touches) {
  1330. return;
  1331. }
  1332. var trackItem = {
  1333. points: [],
  1334. touches: [],
  1335. target: target,
  1336. event: event
  1337. };
  1338. for (var i = 0, len = touches.length; i < len; i++) {
  1339. var touch = touches[i];
  1340. var pos = clientToLocal(root, touch, {});
  1341. trackItem.points.push([pos.zrX, pos.zrY]);
  1342. trackItem.touches.push(touch);
  1343. }
  1344. this._track.push(trackItem);
  1345. };
  1346. GestureMgr.prototype._recognize = function (event) {
  1347. for (var eventName in recognizers) {
  1348. if (recognizers.hasOwnProperty(eventName)) {
  1349. var gestureInfo = recognizers[eventName](this._track, event);
  1350. if (gestureInfo) {
  1351. return gestureInfo;
  1352. }
  1353. }
  1354. }
  1355. };
  1356. return GestureMgr;
  1357. }());
  1358. function dist$1(pointPair) {
  1359. var dx = pointPair[1][0] - pointPair[0][0];
  1360. var dy = pointPair[1][1] - pointPair[0][1];
  1361. return Math.sqrt(dx * dx + dy * dy);
  1362. }
  1363. function center(pointPair) {
  1364. return [
  1365. (pointPair[0][0] + pointPair[1][0]) / 2,
  1366. (pointPair[0][1] + pointPair[1][1]) / 2
  1367. ];
  1368. }
  1369. var recognizers = {
  1370. pinch: function (tracks, event) {
  1371. var trackLen = tracks.length;
  1372. if (!trackLen) {
  1373. return;
  1374. }
  1375. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1376. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1377. if (pinchPre
  1378. && pinchPre.length > 1
  1379. && pinchEnd
  1380. && pinchEnd.length > 1) {
  1381. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1382. !isFinite(pinchScale) && (pinchScale = 1);
  1383. event.pinchScale = pinchScale;
  1384. var pinchCenter = center(pinchEnd);
  1385. event.pinchX = pinchCenter[0];
  1386. event.pinchY = pinchCenter[1];
  1387. return {
  1388. type: 'pinch',
  1389. target: tracks[0].target,
  1390. event: event
  1391. };
  1392. }
  1393. }
  1394. };
  1395. var SILENT = 'silent';
  1396. function makeEventPacket(eveType, targetInfo, event) {
  1397. return {
  1398. type: eveType,
  1399. event: event,
  1400. target: targetInfo.target,
  1401. topTarget: targetInfo.topTarget,
  1402. cancelBubble: false,
  1403. offsetX: event.zrX,
  1404. offsetY: event.zrY,
  1405. gestureEvent: event.gestureEvent,
  1406. pinchX: event.pinchX,
  1407. pinchY: event.pinchY,
  1408. pinchScale: event.pinchScale,
  1409. wheelDelta: event.zrDelta,
  1410. zrByTouch: event.zrByTouch,
  1411. which: event.which,
  1412. stop: stopEvent
  1413. };
  1414. }
  1415. function stopEvent() {
  1416. stop(this.event);
  1417. }
  1418. var EmptyProxy = (function (_super) {
  1419. __extends(EmptyProxy, _super);
  1420. function EmptyProxy() {
  1421. var _this = _super !== null && _super.apply(this, arguments) || this;
  1422. _this.handler = null;
  1423. return _this;
  1424. }
  1425. EmptyProxy.prototype.dispose = function () { };
  1426. EmptyProxy.prototype.setCursor = function () { };
  1427. return EmptyProxy;
  1428. }(Eventful));
  1429. var HoveredResult = (function () {
  1430. function HoveredResult(x, y) {
  1431. this.x = x;
  1432. this.y = y;
  1433. }
  1434. return HoveredResult;
  1435. }());
  1436. var handlerNames = [
  1437. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1438. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1439. ];
  1440. var Handler = (function (_super) {
  1441. __extends(Handler, _super);
  1442. function Handler(storage, painter, proxy, painterRoot) {
  1443. var _this = _super.call(this) || this;
  1444. _this._hovered = new HoveredResult(0, 0);
  1445. _this.storage = storage;
  1446. _this.painter = painter;
  1447. _this.painterRoot = painterRoot;
  1448. proxy = proxy || new EmptyProxy();
  1449. _this.proxy = null;
  1450. _this.setHandlerProxy(proxy);
  1451. _this._draggingMgr = new Draggable(_this);
  1452. return _this;
  1453. }
  1454. Handler.prototype.setHandlerProxy = function (proxy) {
  1455. if (this.proxy) {
  1456. this.proxy.dispose();
  1457. }
  1458. if (proxy) {
  1459. each(handlerNames, function (name) {
  1460. proxy.on && proxy.on(name, this[name], this);
  1461. }, this);
  1462. proxy.handler = this;
  1463. }
  1464. this.proxy = proxy;
  1465. };
  1466. Handler.prototype.mousemove = function (event) {
  1467. var x = event.zrX;
  1468. var y = event.zrY;
  1469. var isOutside = isOutsideBoundary(this, x, y);
  1470. var lastHovered = this._hovered;
  1471. var lastHoveredTarget = lastHovered.target;
  1472. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1473. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1474. lastHoveredTarget = lastHovered.target;
  1475. }
  1476. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  1477. var hoveredTarget = hovered.target;
  1478. var proxy = this.proxy;
  1479. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  1480. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1481. this.dispatchToElement(lastHovered, 'mouseout', event);
  1482. }
  1483. this.dispatchToElement(hovered, 'mousemove', event);
  1484. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1485. this.dispatchToElement(hovered, 'mouseover', event);
  1486. }
  1487. };
  1488. Handler.prototype.mouseout = function (event) {
  1489. var eventControl = event.zrEventControl;
  1490. if (eventControl !== 'only_globalout') {
  1491. this.dispatchToElement(this._hovered, 'mouseout', event);
  1492. }
  1493. if (eventControl !== 'no_globalout') {
  1494. this.trigger('globalout', { type: 'globalout', event: event });
  1495. }
  1496. };
  1497. Handler.prototype.resize = function () {
  1498. this._hovered = new HoveredResult(0, 0);
  1499. };
  1500. Handler.prototype.dispatch = function (eventName, eventArgs) {
  1501. var handler = this[eventName];
  1502. handler && handler.call(this, eventArgs);
  1503. };
  1504. Handler.prototype.dispose = function () {
  1505. this.proxy.dispose();
  1506. this.storage = null;
  1507. this.proxy = null;
  1508. this.painter = null;
  1509. };
  1510. Handler.prototype.setCursorStyle = function (cursorStyle) {
  1511. var proxy = this.proxy;
  1512. proxy.setCursor && proxy.setCursor(cursorStyle);
  1513. };
  1514. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  1515. targetInfo = targetInfo || {};
  1516. var el = targetInfo.target;
  1517. if (el && el.silent) {
  1518. return;
  1519. }
  1520. var eventKey = ('on' + eventName);
  1521. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  1522. while (el) {
  1523. el[eventKey]
  1524. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  1525. el.trigger(eventName, eventPacket);
  1526. el = el.__hostTarget ? el.__hostTarget : el.parent;
  1527. if (eventPacket.cancelBubble) {
  1528. break;
  1529. }
  1530. }
  1531. if (!eventPacket.cancelBubble) {
  1532. this.trigger(eventName, eventPacket);
  1533. if (this.painter && this.painter.eachOtherLayer) {
  1534. this.painter.eachOtherLayer(function (layer) {
  1535. if (typeof (layer[eventKey]) === 'function') {
  1536. layer[eventKey].call(layer, eventPacket);
  1537. }
  1538. if (layer.trigger) {
  1539. layer.trigger(eventName, eventPacket);
  1540. }
  1541. });
  1542. }
  1543. }
  1544. };
  1545. Handler.prototype.findHover = function (x, y, exclude) {
  1546. var list = this.storage.getDisplayList();
  1547. var out = new HoveredResult(x, y);
  1548. for (var i = list.length - 1; i >= 0; i--) {
  1549. var hoverCheckResult = void 0;
  1550. if (list[i] !== exclude
  1551. && !list[i].ignore
  1552. && (hoverCheckResult = isHover(list[i], x, y))) {
  1553. !out.topTarget && (out.topTarget = list[i]);
  1554. if (hoverCheckResult !== SILENT) {
  1555. out.target = list[i];
  1556. break;
  1557. }
  1558. }
  1559. }
  1560. return out;
  1561. };
  1562. Handler.prototype.processGesture = function (event, stage) {
  1563. if (!this._gestureMgr) {
  1564. this._gestureMgr = new GestureMgr();
  1565. }
  1566. var gestureMgr = this._gestureMgr;
  1567. stage === 'start' && gestureMgr.clear();
  1568. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  1569. stage === 'end' && gestureMgr.clear();
  1570. if (gestureInfo) {
  1571. var type = gestureInfo.type;
  1572. event.gestureEvent = type;
  1573. var res = new HoveredResult();
  1574. res.target = gestureInfo.target;
  1575. this.dispatchToElement(res, type, gestureInfo.event);
  1576. }
  1577. };
  1578. return Handler;
  1579. }(Eventful));
  1580. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  1581. Handler.prototype[name] = function (event) {
  1582. var x = event.zrX;
  1583. var y = event.zrY;
  1584. var isOutside = isOutsideBoundary(this, x, y);
  1585. var hovered;
  1586. var hoveredTarget;
  1587. if (name !== 'mouseup' || !isOutside) {
  1588. hovered = this.findHover(x, y);
  1589. hoveredTarget = hovered.target;
  1590. }
  1591. if (name === 'mousedown') {
  1592. this._downEl = hoveredTarget;
  1593. this._downPoint = [event.zrX, event.zrY];
  1594. this._upEl = hoveredTarget;
  1595. }
  1596. else if (name === 'mouseup') {
  1597. this._upEl = hoveredTarget;
  1598. }
  1599. else if (name === 'click') {
  1600. if (this._downEl !== this._upEl
  1601. || !this._downPoint
  1602. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  1603. return;
  1604. }
  1605. this._downPoint = null;
  1606. }
  1607. this.dispatchToElement(hovered, name, event);
  1608. };
  1609. });
  1610. function isHover(displayable, x, y) {
  1611. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  1612. var el = displayable;
  1613. var isSilent = void 0;
  1614. var ignoreClip = false;
  1615. while (el) {
  1616. if (el.ignoreClip) {
  1617. ignoreClip = true;
  1618. }
  1619. if (!ignoreClip) {
  1620. var clipPath = el.getClipPath();
  1621. if (clipPath && !clipPath.contain(x, y)) {
  1622. return false;
  1623. }
  1624. if (el.silent) {
  1625. isSilent = true;
  1626. }
  1627. }
  1628. var hostEl = el.__hostTarget;
  1629. el = hostEl ? hostEl : el.parent;
  1630. }
  1631. return isSilent ? SILENT : true;
  1632. }
  1633. return false;
  1634. }
  1635. function isOutsideBoundary(handlerInstance, x, y) {
  1636. var painter = handlerInstance.painter;
  1637. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  1638. }
  1639. var DEFAULT_MIN_MERGE = 32;
  1640. var DEFAULT_MIN_GALLOPING = 7;
  1641. function minRunLength(n) {
  1642. var r = 0;
  1643. while (n >= DEFAULT_MIN_MERGE) {
  1644. r |= n & 1;
  1645. n >>= 1;
  1646. }
  1647. return n + r;
  1648. }
  1649. function makeAscendingRun(array, lo, hi, compare) {
  1650. var runHi = lo + 1;
  1651. if (runHi === hi) {
  1652. return 1;
  1653. }
  1654. if (compare(array[runHi++], array[lo]) < 0) {
  1655. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  1656. runHi++;
  1657. }
  1658. reverseRun(array, lo, runHi);
  1659. }
  1660. else {
  1661. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  1662. runHi++;
  1663. }
  1664. }
  1665. return runHi - lo;
  1666. }
  1667. function reverseRun(array, lo, hi) {
  1668. hi--;
  1669. while (lo < hi) {
  1670. var t = array[lo];
  1671. array[lo++] = array[hi];
  1672. array[hi--] = t;
  1673. }
  1674. }
  1675. function binaryInsertionSort(array, lo, hi, start, compare) {
  1676. if (start === lo) {
  1677. start++;
  1678. }
  1679. for (; start < hi; start++) {
  1680. var pivot = array[start];
  1681. var left = lo;
  1682. var right = start;
  1683. var mid;
  1684. while (left < right) {
  1685. mid = left + right >>> 1;
  1686. if (compare(pivot, array[mid]) < 0) {
  1687. right = mid;
  1688. }
  1689. else {
  1690. left = mid + 1;
  1691. }
  1692. }
  1693. var n = start - left;
  1694. switch (n) {
  1695. case 3:
  1696. array[left + 3] = array[left + 2];
  1697. case 2:
  1698. array[left + 2] = array[left + 1];
  1699. case 1:
  1700. array[left + 1] = array[left];
  1701. break;
  1702. default:
  1703. while (n > 0) {
  1704. array[left + n] = array[left + n - 1];
  1705. n--;
  1706. }
  1707. }
  1708. array[left] = pivot;
  1709. }
  1710. }
  1711. function gallopLeft(value, array, start, length, hint, compare) {
  1712. var lastOffset = 0;
  1713. var maxOffset = 0;
  1714. var offset = 1;
  1715. if (compare(value, array[start + hint]) > 0) {
  1716. maxOffset = length - hint;
  1717. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  1718. lastOffset = offset;
  1719. offset = (offset << 1) + 1;
  1720. if (offset <= 0) {
  1721. offset = maxOffset;
  1722. }
  1723. }
  1724. if (offset > maxOffset) {
  1725. offset = maxOffset;
  1726. }
  1727. lastOffset += hint;
  1728. offset += hint;
  1729. }
  1730. else {
  1731. maxOffset = hint + 1;
  1732. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  1733. lastOffset = offset;
  1734. offset = (offset << 1) + 1;
  1735. if (offset <= 0) {
  1736. offset = maxOffset;
  1737. }
  1738. }
  1739. if (offset > maxOffset) {
  1740. offset = maxOffset;
  1741. }
  1742. var tmp = lastOffset;
  1743. lastOffset = hint - offset;
  1744. offset = hint - tmp;
  1745. }
  1746. lastOffset++;
  1747. while (lastOffset < offset) {
  1748. var m = lastOffset + (offset - lastOffset >>> 1);
  1749. if (compare(value, array[start + m]) > 0) {
  1750. lastOffset = m + 1;
  1751. }
  1752. else {
  1753. offset = m;
  1754. }
  1755. }
  1756. return offset;
  1757. }
  1758. function gallopRight(value, array, start, length, hint, compare) {
  1759. var lastOffset = 0;
  1760. var maxOffset = 0;
  1761. var offset = 1;
  1762. if (compare(value, array[start + hint]) < 0) {
  1763. maxOffset = hint + 1;
  1764. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  1765. lastOffset = offset;
  1766. offset = (offset << 1) + 1;
  1767. if (offset <= 0) {
  1768. offset = maxOffset;
  1769. }
  1770. }
  1771. if (offset > maxOffset) {
  1772. offset = maxOffset;
  1773. }
  1774. var tmp = lastOffset;
  1775. lastOffset = hint - offset;
  1776. offset = hint - tmp;
  1777. }
  1778. else {
  1779. maxOffset = length - hint;
  1780. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  1781. lastOffset = offset;
  1782. offset = (offset << 1) + 1;
  1783. if (offset <= 0) {
  1784. offset = maxOffset;
  1785. }
  1786. }
  1787. if (offset > maxOffset) {
  1788. offset = maxOffset;
  1789. }
  1790. lastOffset += hint;
  1791. offset += hint;
  1792. }
  1793. lastOffset++;
  1794. while (lastOffset < offset) {
  1795. var m = lastOffset + (offset - lastOffset >>> 1);
  1796. if (compare(value, array[start + m]) < 0) {
  1797. offset = m;
  1798. }
  1799. else {
  1800. lastOffset = m + 1;
  1801. }
  1802. }
  1803. return offset;
  1804. }
  1805. function TimSort(array, compare) {
  1806. var minGallop = DEFAULT_MIN_GALLOPING;
  1807. var length = 0;
  1808. var runStart;
  1809. var runLength;
  1810. var stackSize = 0;
  1811. length = array.length;
  1812. var tmp = [];
  1813. runStart = [];
  1814. runLength = [];
  1815. function pushRun(_runStart, _runLength) {
  1816. runStart[stackSize] = _runStart;
  1817. runLength[stackSize] = _runLength;
  1818. stackSize += 1;
  1819. }
  1820. function mergeRuns() {
  1821. while (stackSize > 1) {
  1822. var n = stackSize - 2;
  1823. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  1824. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  1825. if (runLength[n - 1] < runLength[n + 1]) {
  1826. n--;
  1827. }
  1828. }
  1829. else if (runLength[n] > runLength[n + 1]) {
  1830. break;
  1831. }
  1832. mergeAt(n);
  1833. }
  1834. }
  1835. function forceMergeRuns() {
  1836. while (stackSize > 1) {
  1837. var n = stackSize - 2;
  1838. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  1839. n--;
  1840. }
  1841. mergeAt(n);
  1842. }
  1843. }
  1844. function mergeAt(i) {
  1845. var start1 = runStart[i];
  1846. var length1 = runLength[i];
  1847. var start2 = runStart[i + 1];
  1848. var length2 = runLength[i + 1];
  1849. runLength[i] = length1 + length2;
  1850. if (i === stackSize - 3) {
  1851. runStart[i + 1] = runStart[i + 2];
  1852. runLength[i + 1] = runLength[i + 2];
  1853. }
  1854. stackSize--;
  1855. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  1856. start1 += k;
  1857. length1 -= k;
  1858. if (length1 === 0) {
  1859. return;
  1860. }
  1861. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  1862. if (length2 === 0) {
  1863. return;
  1864. }
  1865. if (length1 <= length2) {
  1866. mergeLow(start1, length1, start2, length2);
  1867. }
  1868. else {
  1869. mergeHigh(start1, length1, start2, length2);
  1870. }
  1871. }
  1872. function mergeLow(start1, length1, start2, length2) {
  1873. var i = 0;
  1874. for (i = 0; i < length1; i++) {
  1875. tmp[i] = array[start1 + i];
  1876. }
  1877. var cursor1 = 0;
  1878. var cursor2 = start2;
  1879. var dest = start1;
  1880. array[dest++] = array[cursor2++];
  1881. if (--length2 === 0) {
  1882. for (i = 0; i < length1; i++) {
  1883. array[dest + i] = tmp[cursor1 + i];
  1884. }
  1885. return;
  1886. }
  1887. if (length1 === 1) {
  1888. for (i = 0; i < length2; i++) {
  1889. array[dest + i] = array[cursor2 + i];
  1890. }
  1891. array[dest + length2] = tmp[cursor1];
  1892. return;
  1893. }
  1894. var _minGallop = minGallop;
  1895. var count1;
  1896. var count2;
  1897. var exit;
  1898. while (1) {
  1899. count1 = 0;
  1900. count2 = 0;
  1901. exit = false;
  1902. do {
  1903. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  1904. array[dest++] = array[cursor2++];
  1905. count2++;
  1906. count1 = 0;
  1907. if (--length2 === 0) {
  1908. exit = true;
  1909. break;
  1910. }
  1911. }
  1912. else {
  1913. array[dest++] = tmp[cursor1++];
  1914. count1++;
  1915. count2 = 0;
  1916. if (--length1 === 1) {
  1917. exit = true;
  1918. break;
  1919. }
  1920. }
  1921. } while ((count1 | count2) < _minGallop);
  1922. if (exit) {
  1923. break;
  1924. }
  1925. do {
  1926. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  1927. if (count1 !== 0) {
  1928. for (i = 0; i < count1; i++) {
  1929. array[dest + i] = tmp[cursor1 + i];
  1930. }
  1931. dest += count1;
  1932. cursor1 += count1;
  1933. length1 -= count1;
  1934. if (length1 <= 1) {
  1935. exit = true;
  1936. break;
  1937. }
  1938. }
  1939. array[dest++] = array[cursor2++];
  1940. if (--length2 === 0) {
  1941. exit = true;
  1942. break;
  1943. }
  1944. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  1945. if (count2 !== 0) {
  1946. for (i = 0; i < count2; i++) {
  1947. array[dest + i] = array[cursor2 + i];
  1948. }
  1949. dest += count2;
  1950. cursor2 += count2;
  1951. length2 -= count2;
  1952. if (length2 === 0) {
  1953. exit = true;
  1954. break;
  1955. }
  1956. }
  1957. array[dest++] = tmp[cursor1++];
  1958. if (--length1 === 1) {
  1959. exit = true;
  1960. break;
  1961. }
  1962. _minGallop--;
  1963. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  1964. if (exit) {
  1965. break;
  1966. }
  1967. if (_minGallop < 0) {
  1968. _minGallop = 0;
  1969. }
  1970. _minGallop += 2;
  1971. }
  1972. minGallop = _minGallop;
  1973. minGallop < 1 && (minGallop = 1);
  1974. if (length1 === 1) {
  1975. for (i = 0; i < length2; i++) {
  1976. array[dest + i] = array[cursor2 + i];
  1977. }
  1978. array[dest + length2] = tmp[cursor1];
  1979. }
  1980. else if (length1 === 0) {
  1981. throw new Error();
  1982. }
  1983. else {
  1984. for (i = 0; i < length1; i++) {
  1985. array[dest + i] = tmp[cursor1 + i];
  1986. }
  1987. }
  1988. }
  1989. function mergeHigh(start1, length1, start2, length2) {
  1990. var i = 0;
  1991. for (i = 0; i < length2; i++) {
  1992. tmp[i] = array[start2 + i];
  1993. }
  1994. var cursor1 = start1 + length1 - 1;
  1995. var cursor2 = length2 - 1;
  1996. var dest = start2 + length2 - 1;
  1997. var customCursor = 0;
  1998. var customDest = 0;
  1999. array[dest--] = array[cursor1--];
  2000. if (--length1 === 0) {
  2001. customCursor = dest - (length2 - 1);
  2002. for (i = 0; i < length2; i++) {
  2003. array[customCursor + i] = tmp[i];
  2004. }
  2005. return;
  2006. }
  2007. if (length2 === 1) {
  2008. dest -= length1;
  2009. cursor1 -= length1;
  2010. customDest = dest + 1;
  2011. customCursor = cursor1 + 1;
  2012. for (i = length1 - 1; i >= 0; i--) {
  2013. array[customDest + i] = array[customCursor + i];
  2014. }
  2015. array[dest] = tmp[cursor2];
  2016. return;
  2017. }
  2018. var _minGallop = minGallop;
  2019. while (true) {
  2020. var count1 = 0;
  2021. var count2 = 0;
  2022. var exit = false;
  2023. do {
  2024. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2025. array[dest--] = array[cursor1--];
  2026. count1++;
  2027. count2 = 0;
  2028. if (--length1 === 0) {
  2029. exit = true;
  2030. break;
  2031. }
  2032. }
  2033. else {
  2034. array[dest--] = tmp[cursor2--];
  2035. count2++;
  2036. count1 = 0;
  2037. if (--length2 === 1) {
  2038. exit = true;
  2039. break;
  2040. }
  2041. }
  2042. } while ((count1 | count2) < _minGallop);
  2043. if (exit) {
  2044. break;
  2045. }
  2046. do {
  2047. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2048. if (count1 !== 0) {
  2049. dest -= count1;
  2050. cursor1 -= count1;
  2051. length1 -= count1;
  2052. customDest = dest + 1;
  2053. customCursor = cursor1 + 1;
  2054. for (i = count1 - 1; i >= 0; i--) {
  2055. array[customDest + i] = array[customCursor + i];
  2056. }
  2057. if (length1 === 0) {
  2058. exit = true;
  2059. break;
  2060. }
  2061. }
  2062. array[dest--] = tmp[cursor2--];
  2063. if (--length2 === 1) {
  2064. exit = true;
  2065. break;
  2066. }
  2067. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2068. if (count2 !== 0) {
  2069. dest -= count2;
  2070. cursor2 -= count2;
  2071. length2 -= count2;
  2072. customDest = dest + 1;
  2073. customCursor = cursor2 + 1;
  2074. for (i = 0; i < count2; i++) {
  2075. array[customDest + i] = tmp[customCursor + i];
  2076. }
  2077. if (length2 <= 1) {
  2078. exit = true;
  2079. break;
  2080. }
  2081. }
  2082. array[dest--] = array[cursor1--];
  2083. if (--length1 === 0) {
  2084. exit = true;
  2085. break;
  2086. }
  2087. _minGallop--;
  2088. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2089. if (exit) {
  2090. break;
  2091. }
  2092. if (_minGallop < 0) {
  2093. _minGallop = 0;
  2094. }
  2095. _minGallop += 2;
  2096. }
  2097. minGallop = _minGallop;
  2098. if (minGallop < 1) {
  2099. minGallop = 1;
  2100. }
  2101. if (length2 === 1) {
  2102. dest -= length1;
  2103. cursor1 -= length1;
  2104. customDest = dest + 1;
  2105. customCursor = cursor1 + 1;
  2106. for (i = length1 - 1; i >= 0; i--) {
  2107. array[customDest + i] = array[customCursor + i];
  2108. }
  2109. array[dest] = tmp[cursor2];
  2110. }
  2111. else if (length2 === 0) {
  2112. throw new Error();
  2113. }
  2114. else {
  2115. customCursor = dest - (length2 - 1);
  2116. for (i = 0; i < length2; i++) {
  2117. array[customCursor + i] = tmp[i];
  2118. }
  2119. }
  2120. }
  2121. return {
  2122. mergeRuns: mergeRuns,
  2123. forceMergeRuns: forceMergeRuns,
  2124. pushRun: pushRun
  2125. };
  2126. }
  2127. function sort(array, compare, lo, hi) {
  2128. if (!lo) {
  2129. lo = 0;
  2130. }
  2131. if (!hi) {
  2132. hi = array.length;
  2133. }
  2134. var remaining = hi - lo;
  2135. if (remaining < 2) {
  2136. return;
  2137. }
  2138. var runLength = 0;
  2139. if (remaining < DEFAULT_MIN_MERGE) {
  2140. runLength = makeAscendingRun(array, lo, hi, compare);
  2141. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2142. return;
  2143. }
  2144. var ts = TimSort(array, compare);
  2145. var minRun = minRunLength(remaining);
  2146. do {
  2147. runLength = makeAscendingRun(array, lo, hi, compare);
  2148. if (runLength < minRun) {
  2149. var force = remaining;
  2150. if (force > minRun) {
  2151. force = minRun;
  2152. }
  2153. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2154. runLength = force;
  2155. }
  2156. ts.pushRun(lo, runLength);
  2157. ts.mergeRuns();
  2158. remaining -= runLength;
  2159. lo += runLength;
  2160. } while (remaining !== 0);
  2161. ts.forceMergeRuns();
  2162. }
  2163. var REDRAW_BIT = 1;
  2164. var STYLE_CHANGED_BIT = 2;
  2165. var SHAPE_CHANGED_BIT = 4;
  2166. var invalidZErrorLogged = false;
  2167. function logInvalidZError() {
  2168. if (invalidZErrorLogged) {
  2169. return;
  2170. }
  2171. invalidZErrorLogged = true;
  2172. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2173. }
  2174. function shapeCompareFunc(a, b) {
  2175. if (a.zlevel === b.zlevel) {
  2176. if (a.z === b.z) {
  2177. return a.z2 - b.z2;
  2178. }
  2179. return a.z - b.z;
  2180. }
  2181. return a.zlevel - b.zlevel;
  2182. }
  2183. var Storage = (function () {
  2184. function Storage() {
  2185. this._roots = [];
  2186. this._displayList = [];
  2187. this._displayListLen = 0;
  2188. this.displayableSortFunc = shapeCompareFunc;
  2189. }
  2190. Storage.prototype.traverse = function (cb, context) {
  2191. for (var i = 0; i < this._roots.length; i++) {
  2192. this._roots[i].traverse(cb, context);
  2193. }
  2194. };
  2195. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2196. includeIgnore = includeIgnore || false;
  2197. var displayList = this._displayList;
  2198. if (update || !displayList.length) {
  2199. this.updateDisplayList(includeIgnore);
  2200. }
  2201. return displayList;
  2202. };
  2203. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2204. this._displayListLen = 0;
  2205. var roots = this._roots;
  2206. var displayList = this._displayList;
  2207. for (var i = 0, len = roots.length; i < len; i++) {
  2208. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2209. }
  2210. displayList.length = this._displayListLen;
  2211. env.canvasSupported && sort(displayList, shapeCompareFunc);
  2212. };
  2213. Storage.prototype._updateAndAddDisplayable = function (el, clipPaths, includeIgnore) {
  2214. if (el.ignore && !includeIgnore) {
  2215. return;
  2216. }
  2217. el.beforeUpdate();
  2218. el.update();
  2219. el.afterUpdate();
  2220. var userSetClipPath = el.getClipPath();
  2221. if (el.ignoreClip) {
  2222. clipPaths = null;
  2223. }
  2224. else if (userSetClipPath) {
  2225. if (clipPaths) {
  2226. clipPaths = clipPaths.slice();
  2227. }
  2228. else {
  2229. clipPaths = [];
  2230. }
  2231. var currentClipPath = userSetClipPath;
  2232. var parentClipPath = el;
  2233. while (currentClipPath) {
  2234. currentClipPath.parent = parentClipPath;
  2235. currentClipPath.updateTransform();
  2236. clipPaths.push(currentClipPath);
  2237. parentClipPath = currentClipPath;
  2238. currentClipPath = currentClipPath.getClipPath();
  2239. }
  2240. }
  2241. if (el.childrenRef) {
  2242. var children = el.childrenRef();
  2243. for (var i = 0; i < children.length; i++) {
  2244. var child = children[i];
  2245. if (el.__dirty) {
  2246. child.__dirty |= REDRAW_BIT;
  2247. }
  2248. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  2249. }
  2250. el.__dirty = 0;
  2251. }
  2252. else {
  2253. var disp = el;
  2254. if (clipPaths && clipPaths.length) {
  2255. disp.__clipPaths = clipPaths;
  2256. }
  2257. else if (disp.__clipPaths && disp.__clipPaths.length > 0) {
  2258. disp.__clipPaths = [];
  2259. }
  2260. if (isNaN(disp.z)) {
  2261. logInvalidZError();
  2262. disp.z = 0;
  2263. }
  2264. if (isNaN(disp.z2)) {
  2265. logInvalidZError();
  2266. disp.z2 = 0;
  2267. }
  2268. if (isNaN(disp.zlevel)) {
  2269. logInvalidZError();
  2270. disp.zlevel = 0;
  2271. }
  2272. this._displayList[this._displayListLen++] = disp;
  2273. }
  2274. var decalEl = el.getDecalElement && el.getDecalElement();
  2275. if (decalEl) {
  2276. this._updateAndAddDisplayable(decalEl, clipPaths, includeIgnore);
  2277. }
  2278. var textGuide = el.getTextGuideLine();
  2279. if (textGuide) {
  2280. this._updateAndAddDisplayable(textGuide, clipPaths, includeIgnore);
  2281. }
  2282. var textEl = el.getTextContent();
  2283. if (textEl) {
  2284. this._updateAndAddDisplayable(textEl, clipPaths, includeIgnore);
  2285. }
  2286. };
  2287. Storage.prototype.addRoot = function (el) {
  2288. if (el.__zr && el.__zr.storage === this) {
  2289. return;
  2290. }
  2291. this._roots.push(el);
  2292. };
  2293. Storage.prototype.delRoot = function (el) {
  2294. if (el instanceof Array) {
  2295. for (var i = 0, l = el.length; i < l; i++) {
  2296. this.delRoot(el[i]);
  2297. }
  2298. return;
  2299. }
  2300. var idx = indexOf(this._roots, el);
  2301. if (idx >= 0) {
  2302. this._roots.splice(idx, 1);
  2303. }
  2304. };
  2305. Storage.prototype.delAllRoots = function () {
  2306. this._roots = [];
  2307. this._displayList = [];
  2308. this._displayListLen = 0;
  2309. return;
  2310. };
  2311. Storage.prototype.getRoots = function () {
  2312. return this._roots;
  2313. };
  2314. Storage.prototype.dispose = function () {
  2315. this._displayList = null;
  2316. this._roots = null;
  2317. };
  2318. return Storage;
  2319. }());
  2320. var requestAnimationFrame;
  2321. requestAnimationFrame = (typeof window !== 'undefined'
  2322. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  2323. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  2324. || window.mozRequestAnimationFrame
  2325. || window.webkitRequestAnimationFrame)) || function (func) {
  2326. return setTimeout(func, 16);
  2327. };
  2328. var requestAnimationFrame$1 = requestAnimationFrame;
  2329. var easing = {
  2330. linear: function (k) {
  2331. return k;
  2332. },
  2333. quadraticIn: function (k) {
  2334. return k * k;
  2335. },
  2336. quadraticOut: function (k) {
  2337. return k * (2 - k);
  2338. },
  2339. quadraticInOut: function (k) {
  2340. if ((k *= 2) < 1) {
  2341. return 0.5 * k * k;
  2342. }
  2343. return -0.5 * (--k * (k - 2) - 1);
  2344. },
  2345. cubicIn: function (k) {
  2346. return k * k * k;
  2347. },
  2348. cubicOut: function (k) {
  2349. return --k * k * k + 1;
  2350. },
  2351. cubicInOut: function (k) {
  2352. if ((k *= 2) < 1) {
  2353. return 0.5 * k * k * k;
  2354. }
  2355. return 0.5 * ((k -= 2) * k * k + 2);
  2356. },
  2357. quarticIn: function (k) {
  2358. return k * k * k * k;
  2359. },
  2360. quarticOut: function (k) {
  2361. return 1 - (--k * k * k * k);
  2362. },
  2363. quarticInOut: function (k) {
  2364. if ((k *= 2) < 1) {
  2365. return 0.5 * k * k * k * k;
  2366. }
  2367. return -0.5 * ((k -= 2) * k * k * k - 2);
  2368. },
  2369. quinticIn: function (k) {
  2370. return k * k * k * k * k;
  2371. },
  2372. quinticOut: function (k) {
  2373. return --k * k * k * k * k + 1;
  2374. },
  2375. quinticInOut: function (k) {
  2376. if ((k *= 2) < 1) {
  2377. return 0.5 * k * k * k * k * k;
  2378. }
  2379. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2380. },
  2381. sinusoidalIn: function (k) {
  2382. return 1 - Math.cos(k * Math.PI / 2);
  2383. },
  2384. sinusoidalOut: function (k) {
  2385. return Math.sin(k * Math.PI / 2);
  2386. },
  2387. sinusoidalInOut: function (k) {
  2388. return 0.5 * (1 - Math.cos(Math.PI * k));
  2389. },
  2390. exponentialIn: function (k) {
  2391. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2392. },
  2393. exponentialOut: function (k) {
  2394. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2395. },
  2396. exponentialInOut: function (k) {
  2397. if (k === 0) {
  2398. return 0;
  2399. }
  2400. if (k === 1) {
  2401. return 1;
  2402. }
  2403. if ((k *= 2) < 1) {
  2404. return 0.5 * Math.pow(1024, k - 1);
  2405. }
  2406. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2407. },
  2408. circularIn: function (k) {
  2409. return 1 - Math.sqrt(1 - k * k);
  2410. },
  2411. circularOut: function (k) {
  2412. return Math.sqrt(1 - (--k * k));
  2413. },
  2414. circularInOut: function (k) {
  2415. if ((k *= 2) < 1) {
  2416. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2417. }
  2418. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2419. },
  2420. elasticIn: function (k) {
  2421. var s;
  2422. var a = 0.1;
  2423. var p = 0.4;
  2424. if (k === 0) {
  2425. return 0;
  2426. }
  2427. if (k === 1) {
  2428. return 1;
  2429. }
  2430. if (!a || a < 1) {
  2431. a = 1;
  2432. s = p / 4;
  2433. }
  2434. else {
  2435. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2436. }
  2437. return -(a * Math.pow(2, 10 * (k -= 1))
  2438. * Math.sin((k - s) * (2 * Math.PI) / p));
  2439. },
  2440. elasticOut: function (k) {
  2441. var s;
  2442. var a = 0.1;
  2443. var p = 0.4;
  2444. if (k === 0) {
  2445. return 0;
  2446. }
  2447. if (k === 1) {
  2448. return 1;
  2449. }
  2450. if (!a || a < 1) {
  2451. a = 1;
  2452. s = p / 4;
  2453. }
  2454. else {
  2455. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2456. }
  2457. return (a * Math.pow(2, -10 * k)
  2458. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2459. },
  2460. elasticInOut: function (k) {
  2461. var s;
  2462. var a = 0.1;
  2463. var p = 0.4;
  2464. if (k === 0) {
  2465. return 0;
  2466. }
  2467. if (k === 1) {
  2468. return 1;
  2469. }
  2470. if (!a || a < 1) {
  2471. a = 1;
  2472. s = p / 4;
  2473. }
  2474. else {
  2475. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2476. }
  2477. if ((k *= 2) < 1) {
  2478. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2479. * Math.sin((k - s) * (2 * Math.PI) / p));
  2480. }
  2481. return a * Math.pow(2, -10 * (k -= 1))
  2482. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2483. },
  2484. backIn: function (k) {
  2485. var s = 1.70158;
  2486. return k * k * ((s + 1) * k - s);
  2487. },
  2488. backOut: function (k) {
  2489. var s = 1.70158;
  2490. return --k * k * ((s + 1) * k + s) + 1;
  2491. },
  2492. backInOut: function (k) {
  2493. var s = 1.70158 * 1.525;
  2494. if ((k *= 2) < 1) {
  2495. return 0.5 * (k * k * ((s + 1) * k - s));
  2496. }
  2497. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2498. },
  2499. bounceIn: function (k) {
  2500. return 1 - easing.bounceOut(1 - k);
  2501. },
  2502. bounceOut: function (k) {
  2503. if (k < (1 / 2.75)) {
  2504. return 7.5625 * k * k;
  2505. }
  2506. else if (k < (2 / 2.75)) {
  2507. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  2508. }
  2509. else if (k < (2.5 / 2.75)) {
  2510. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  2511. }
  2512. else {
  2513. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  2514. }
  2515. },
  2516. bounceInOut: function (k) {
  2517. if (k < 0.5) {
  2518. return easing.bounceIn(k * 2) * 0.5;
  2519. }
  2520. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2521. }
  2522. };
  2523. var Clip = (function () {
  2524. function Clip(opts) {
  2525. this._initialized = false;
  2526. this._startTime = 0;
  2527. this._pausedTime = 0;
  2528. this._paused = false;
  2529. this._life = opts.life || 1000;
  2530. this._delay = opts.delay || 0;
  2531. this.loop = opts.loop == null ? false : opts.loop;
  2532. this.gap = opts.gap || 0;
  2533. this.easing = opts.easing || 'linear';
  2534. this.onframe = opts.onframe;
  2535. this.ondestroy = opts.ondestroy;
  2536. this.onrestart = opts.onrestart;
  2537. }
  2538. Clip.prototype.step = function (globalTime, deltaTime) {
  2539. if (!this._initialized) {
  2540. this._startTime = globalTime + this._delay;
  2541. this._initialized = true;
  2542. }
  2543. if (this._paused) {
  2544. this._pausedTime += deltaTime;
  2545. return;
  2546. }
  2547. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  2548. if (percent < 0) {
  2549. percent = 0;
  2550. }
  2551. percent = Math.min(percent, 1);
  2552. var easing$1 = this.easing;
  2553. var easingFunc = typeof easing$1 === 'string'
  2554. ? easing[easing$1] : easing$1;
  2555. var schedule = typeof easingFunc === 'function'
  2556. ? easingFunc(percent)
  2557. : percent;
  2558. this.onframe && this.onframe(schedule);
  2559. if (percent === 1) {
  2560. if (this.loop) {
  2561. this._restart(globalTime);
  2562. this.onrestart && this.onrestart();
  2563. }
  2564. else {
  2565. return true;
  2566. }
  2567. }
  2568. return false;
  2569. };
  2570. Clip.prototype._restart = function (globalTime) {
  2571. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  2572. this._startTime = globalTime - remainder + this.gap;
  2573. this._pausedTime = 0;
  2574. };
  2575. Clip.prototype.pause = function () {
  2576. this._paused = true;
  2577. };
  2578. Clip.prototype.resume = function () {
  2579. this._paused = false;
  2580. };
  2581. return Clip;
  2582. }());
  2583. var Entry = (function () {
  2584. function Entry(val) {
  2585. this.value = val;
  2586. }
  2587. return Entry;
  2588. }());
  2589. var LinkedList = (function () {
  2590. function LinkedList() {
  2591. this._len = 0;
  2592. }
  2593. LinkedList.prototype.insert = function (val) {
  2594. var entry = new Entry(val);
  2595. this.insertEntry(entry);
  2596. return entry;
  2597. };
  2598. LinkedList.prototype.insertEntry = function (entry) {
  2599. if (!this.head) {
  2600. this.head = this.tail = entry;
  2601. }
  2602. else {
  2603. this.tail.next = entry;
  2604. entry.prev = this.tail;
  2605. entry.next = null;
  2606. this.tail = entry;
  2607. }
  2608. this._len++;
  2609. };
  2610. LinkedList.prototype.remove = function (entry) {
  2611. var prev = entry.prev;
  2612. var next = entry.next;
  2613. if (prev) {
  2614. prev.next = next;
  2615. }
  2616. else {
  2617. this.head = next;
  2618. }
  2619. if (next) {
  2620. next.prev = prev;
  2621. }
  2622. else {
  2623. this.tail = prev;
  2624. }
  2625. entry.next = entry.prev = null;
  2626. this._len--;
  2627. };
  2628. LinkedList.prototype.len = function () {
  2629. return this._len;
  2630. };
  2631. LinkedList.prototype.clear = function () {
  2632. this.head = this.tail = null;
  2633. this._len = 0;
  2634. };
  2635. return LinkedList;
  2636. }());
  2637. var LRU = (function () {
  2638. function LRU(maxSize) {
  2639. this._list = new LinkedList();
  2640. this._maxSize = 10;
  2641. this._map = {};
  2642. this._maxSize = maxSize;
  2643. }
  2644. LRU.prototype.put = function (key, value) {
  2645. var list = this._list;
  2646. var map = this._map;
  2647. var removed = null;
  2648. if (map[key] == null) {
  2649. var len = list.len();
  2650. var entry = this._lastRemovedEntry;
  2651. if (len >= this._maxSize && len > 0) {
  2652. var leastUsedEntry = list.head;
  2653. list.remove(leastUsedEntry);
  2654. delete map[leastUsedEntry.key];
  2655. removed = leastUsedEntry.value;
  2656. this._lastRemovedEntry = leastUsedEntry;
  2657. }
  2658. if (entry) {
  2659. entry.value = value;
  2660. }
  2661. else {
  2662. entry = new Entry(value);
  2663. }
  2664. entry.key = key;
  2665. list.insertEntry(entry);
  2666. map[key] = entry;
  2667. }
  2668. return removed;
  2669. };
  2670. LRU.prototype.get = function (key) {
  2671. var entry = this._map[key];
  2672. var list = this._list;
  2673. if (entry != null) {
  2674. if (entry !== list.tail) {
  2675. list.remove(entry);
  2676. list.insertEntry(entry);
  2677. }
  2678. return entry.value;
  2679. }
  2680. };
  2681. LRU.prototype.clear = function () {
  2682. this._list.clear();
  2683. this._map = {};
  2684. };
  2685. LRU.prototype.len = function () {
  2686. return this._list.len();
  2687. };
  2688. return LRU;
  2689. }());
  2690. var kCSSColorTable = {
  2691. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  2692. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  2693. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  2694. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  2695. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  2696. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  2697. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  2698. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  2699. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  2700. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  2701. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  2702. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  2703. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  2704. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  2705. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  2706. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  2707. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  2708. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  2709. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  2710. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  2711. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  2712. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  2713. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  2714. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  2715. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  2716. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  2717. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  2718. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  2719. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  2720. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  2721. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  2722. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  2723. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  2724. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  2725. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  2726. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  2727. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  2728. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  2729. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  2730. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  2731. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  2732. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  2733. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  2734. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  2735. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  2736. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  2737. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  2738. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  2739. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  2740. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  2741. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  2742. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  2743. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  2744. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  2745. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  2746. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  2747. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  2748. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  2749. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  2750. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  2751. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  2752. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  2753. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  2754. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  2755. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  2756. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  2757. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  2758. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  2759. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  2760. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  2761. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  2762. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  2763. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  2764. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  2765. };
  2766. function clampCssByte(i) {
  2767. i = Math.round(i);
  2768. return i < 0 ? 0 : i > 255 ? 255 : i;
  2769. }
  2770. function clampCssAngle(i) {
  2771. i = Math.round(i);
  2772. return i < 0 ? 0 : i > 360 ? 360 : i;
  2773. }
  2774. function clampCssFloat(f) {
  2775. return f < 0 ? 0 : f > 1 ? 1 : f;
  2776. }
  2777. function parseCssInt(val) {
  2778. var str = val;
  2779. if (str.length && str.charAt(str.length - 1) === '%') {
  2780. return clampCssByte(parseFloat(str) / 100 * 255);
  2781. }
  2782. return clampCssByte(parseInt(str, 10));
  2783. }
  2784. function parseCssFloat(val) {
  2785. var str = val;
  2786. if (str.length && str.charAt(str.length - 1) === '%') {
  2787. return clampCssFloat(parseFloat(str) / 100);
  2788. }
  2789. return clampCssFloat(parseFloat(str));
  2790. }
  2791. function cssHueToRgb(m1, m2, h) {
  2792. if (h < 0) {
  2793. h += 1;
  2794. }
  2795. else if (h > 1) {
  2796. h -= 1;
  2797. }
  2798. if (h * 6 < 1) {
  2799. return m1 + (m2 - m1) * h * 6;
  2800. }
  2801. if (h * 2 < 1) {
  2802. return m2;
  2803. }
  2804. if (h * 3 < 2) {
  2805. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  2806. }
  2807. return m1;
  2808. }
  2809. function lerpNumber(a, b, p) {
  2810. return a + (b - a) * p;
  2811. }
  2812. function setRgba(out, r, g, b, a) {
  2813. out[0] = r;
  2814. out[1] = g;
  2815. out[2] = b;
  2816. out[3] = a;
  2817. return out;
  2818. }
  2819. function copyRgba(out, a) {
  2820. out[0] = a[0];
  2821. out[1] = a[1];
  2822. out[2] = a[2];
  2823. out[3] = a[3];
  2824. return out;
  2825. }
  2826. var colorCache = new LRU(20);
  2827. var lastRemovedArr = null;
  2828. function putToCache(colorStr, rgbaArr) {
  2829. if (lastRemovedArr) {
  2830. copyRgba(lastRemovedArr, rgbaArr);
  2831. }
  2832. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  2833. }
  2834. function parse(colorStr, rgbaArr) {
  2835. if (!colorStr) {
  2836. return;
  2837. }
  2838. rgbaArr = rgbaArr || [];
  2839. var cached = colorCache.get(colorStr);
  2840. if (cached) {
  2841. return copyRgba(rgbaArr, cached);
  2842. }
  2843. colorStr = colorStr + '';
  2844. var str = colorStr.replace(/ /g, '').toLowerCase();
  2845. if (str in kCSSColorTable) {
  2846. copyRgba(rgbaArr, kCSSColorTable[str]);
  2847. putToCache(colorStr, rgbaArr);
  2848. return rgbaArr;
  2849. }
  2850. var strLen = str.length;
  2851. if (str.charAt(0) === '#') {
  2852. if (strLen === 4 || strLen === 5) {
  2853. var iv = parseInt(str.slice(1, 4), 16);
  2854. if (!(iv >= 0 && iv <= 0xfff)) {
  2855. setRgba(rgbaArr, 0, 0, 0, 1);
  2856. return;
  2857. }
  2858. 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);
  2859. putToCache(colorStr, rgbaArr);
  2860. return rgbaArr;
  2861. }
  2862. else if (strLen === 7 || strLen === 9) {
  2863. var iv = parseInt(str.slice(1, 7), 16);
  2864. if (!(iv >= 0 && iv <= 0xffffff)) {
  2865. setRgba(rgbaArr, 0, 0, 0, 1);
  2866. return;
  2867. }
  2868. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  2869. putToCache(colorStr, rgbaArr);
  2870. return rgbaArr;
  2871. }
  2872. return;
  2873. }
  2874. var op = str.indexOf('(');
  2875. var ep = str.indexOf(')');
  2876. if (op !== -1 && ep + 1 === strLen) {
  2877. var fname = str.substr(0, op);
  2878. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  2879. var alpha = 1;
  2880. switch (fname) {
  2881. case 'rgba':
  2882. if (params.length !== 4) {
  2883. return params.length === 3
  2884. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  2885. : setRgba(rgbaArr, 0, 0, 0, 1);
  2886. }
  2887. alpha = parseCssFloat(params.pop());
  2888. case 'rgb':
  2889. if (params.length !== 3) {
  2890. setRgba(rgbaArr, 0, 0, 0, 1);
  2891. return;
  2892. }
  2893. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), alpha);
  2894. putToCache(colorStr, rgbaArr);
  2895. return rgbaArr;
  2896. case 'hsla':
  2897. if (params.length !== 4) {
  2898. setRgba(rgbaArr, 0, 0, 0, 1);
  2899. return;
  2900. }
  2901. params[3] = parseCssFloat(params[3]);
  2902. hsla2rgba(params, rgbaArr);
  2903. putToCache(colorStr, rgbaArr);
  2904. return rgbaArr;
  2905. case 'hsl':
  2906. if (params.length !== 3) {
  2907. setRgba(rgbaArr, 0, 0, 0, 1);
  2908. return;
  2909. }
  2910. hsla2rgba(params, rgbaArr);
  2911. putToCache(colorStr, rgbaArr);
  2912. return rgbaArr;
  2913. default:
  2914. return;
  2915. }
  2916. }
  2917. setRgba(rgbaArr, 0, 0, 0, 1);
  2918. return;
  2919. }
  2920. function hsla2rgba(hsla, rgba) {
  2921. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  2922. var s = parseCssFloat(hsla[1]);
  2923. var l = parseCssFloat(hsla[2]);
  2924. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  2925. var m1 = l * 2 - m2;
  2926. rgba = rgba || [];
  2927. 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);
  2928. if (hsla.length === 4) {
  2929. rgba[3] = hsla[3];
  2930. }
  2931. return rgba;
  2932. }
  2933. function rgba2hsla(rgba) {
  2934. if (!rgba) {
  2935. return;
  2936. }
  2937. var R = rgba[0] / 255;
  2938. var G = rgba[1] / 255;
  2939. var B = rgba[2] / 255;
  2940. var vMin = Math.min(R, G, B);
  2941. var vMax = Math.max(R, G, B);
  2942. var delta = vMax - vMin;
  2943. var L = (vMax + vMin) / 2;
  2944. var H;
  2945. var S;
  2946. if (delta === 0) {
  2947. H = 0;
  2948. S = 0;
  2949. }
  2950. else {
  2951. if (L < 0.5) {
  2952. S = delta / (vMax + vMin);
  2953. }
  2954. else {
  2955. S = delta / (2 - vMax - vMin);
  2956. }
  2957. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  2958. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  2959. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  2960. if (R === vMax) {
  2961. H = deltaB - deltaG;
  2962. }
  2963. else if (G === vMax) {
  2964. H = (1 / 3) + deltaR - deltaB;
  2965. }
  2966. else if (B === vMax) {
  2967. H = (2 / 3) + deltaG - deltaR;
  2968. }
  2969. if (H < 0) {
  2970. H += 1;
  2971. }
  2972. if (H > 1) {
  2973. H -= 1;
  2974. }
  2975. }
  2976. var hsla = [H * 360, S, L];
  2977. if (rgba[3] != null) {
  2978. hsla.push(rgba[3]);
  2979. }
  2980. return hsla;
  2981. }
  2982. function lift(color, level) {
  2983. var colorArr = parse(color);
  2984. if (colorArr) {
  2985. for (var i = 0; i < 3; i++) {
  2986. if (level < 0) {
  2987. colorArr[i] = colorArr[i] * (1 - level) | 0;
  2988. }
  2989. else {
  2990. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  2991. }
  2992. if (colorArr[i] > 255) {
  2993. colorArr[i] = 255;
  2994. }
  2995. else if (colorArr[i] < 0) {
  2996. colorArr[i] = 0;
  2997. }
  2998. }
  2999. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3000. }
  3001. }
  3002. function toHex(color) {
  3003. var colorArr = parse(color);
  3004. if (colorArr) {
  3005. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3006. }
  3007. }
  3008. function fastLerp(normalizedValue, colors, out) {
  3009. if (!(colors && colors.length)
  3010. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3011. return;
  3012. }
  3013. out = out || [];
  3014. var value = normalizedValue * (colors.length - 1);
  3015. var leftIndex = Math.floor(value);
  3016. var rightIndex = Math.ceil(value);
  3017. var leftColor = colors[leftIndex];
  3018. var rightColor = colors[rightIndex];
  3019. var dv = value - leftIndex;
  3020. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3021. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3022. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3023. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3024. return out;
  3025. }
  3026. var fastMapToColor = fastLerp;
  3027. function lerp$1(normalizedValue, colors, fullOutput) {
  3028. if (!(colors && colors.length)
  3029. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3030. return;
  3031. }
  3032. var value = normalizedValue * (colors.length - 1);
  3033. var leftIndex = Math.floor(value);
  3034. var rightIndex = Math.ceil(value);
  3035. var leftColor = parse(colors[leftIndex]);
  3036. var rightColor = parse(colors[rightIndex]);
  3037. var dv = value - leftIndex;
  3038. var color = stringify([
  3039. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3040. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3041. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3042. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3043. ], 'rgba');
  3044. return fullOutput
  3045. ? {
  3046. color: color,
  3047. leftIndex: leftIndex,
  3048. rightIndex: rightIndex,
  3049. value: value
  3050. }
  3051. : color;
  3052. }
  3053. var mapToColor = lerp$1;
  3054. function modifyHSL(color, h, s, l) {
  3055. var colorArr = parse(color);
  3056. if (color) {
  3057. colorArr = rgba2hsla(colorArr);
  3058. h != null && (colorArr[0] = clampCssAngle(h));
  3059. s != null && (colorArr[1] = parseCssFloat(s));
  3060. l != null && (colorArr[2] = parseCssFloat(l));
  3061. return stringify(hsla2rgba(colorArr), 'rgba');
  3062. }
  3063. }
  3064. function modifyAlpha(color, alpha) {
  3065. var colorArr = parse(color);
  3066. if (colorArr && alpha != null) {
  3067. colorArr[3] = clampCssFloat(alpha);
  3068. return stringify(colorArr, 'rgba');
  3069. }
  3070. }
  3071. function stringify(arrColor, type) {
  3072. if (!arrColor || !arrColor.length) {
  3073. return;
  3074. }
  3075. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3076. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3077. colorStr += ',' + arrColor[3];
  3078. }
  3079. return type + '(' + colorStr + ')';
  3080. }
  3081. function lum(color, backgroundLum) {
  3082. var arr = parse(color);
  3083. return arr
  3084. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  3085. + (1 - arr[3]) * backgroundLum
  3086. : 0;
  3087. }
  3088. function random() {
  3089. var r = Math.round(Math.random() * 255);
  3090. var g = Math.round(Math.random() * 255);
  3091. var b = Math.round(Math.random() * 255);
  3092. return 'rgb(' + r + ',' + g + ',' + b + ')';
  3093. }
  3094. var color = /*#__PURE__*/Object.freeze({
  3095. __proto__: null,
  3096. parse: parse,
  3097. lift: lift,
  3098. toHex: toHex,
  3099. fastLerp: fastLerp,
  3100. fastMapToColor: fastMapToColor,
  3101. lerp: lerp$1,
  3102. mapToColor: mapToColor,
  3103. modifyHSL: modifyHSL,
  3104. modifyAlpha: modifyAlpha,
  3105. stringify: stringify,
  3106. lum: lum,
  3107. random: random
  3108. });
  3109. var arraySlice = Array.prototype.slice;
  3110. function interpolateNumber(p0, p1, percent) {
  3111. return (p1 - p0) * percent + p0;
  3112. }
  3113. function step(p0, p1, percent) {
  3114. return percent > 0.5 ? p1 : p0;
  3115. }
  3116. function interpolate1DArray(out, p0, p1, percent) {
  3117. var len = p0.length;
  3118. for (var i = 0; i < len; i++) {
  3119. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3120. }
  3121. }
  3122. function interpolate2DArray(out, p0, p1, percent) {
  3123. var len = p0.length;
  3124. var len2 = len && p0[0].length;
  3125. for (var i = 0; i < len; i++) {
  3126. if (!out[i]) {
  3127. out[i] = [];
  3128. }
  3129. for (var j = 0; j < len2; j++) {
  3130. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  3131. }
  3132. }
  3133. }
  3134. function add1DArray(out, p0, p1, sign) {
  3135. var len = p0.length;
  3136. for (var i = 0; i < len; i++) {
  3137. out[i] = p0[i] + p1[i] * sign;
  3138. }
  3139. return out;
  3140. }
  3141. function add2DArray(out, p0, p1, sign) {
  3142. var len = p0.length;
  3143. var len2 = len && p0[0].length;
  3144. for (var i = 0; i < len; i++) {
  3145. if (!out[i]) {
  3146. out[i] = [];
  3147. }
  3148. for (var j = 0; j < len2; j++) {
  3149. out[i][j] = p0[i][j] + p1[i][j] * sign;
  3150. }
  3151. }
  3152. return out;
  3153. }
  3154. function fillArray(val0, val1, arrDim) {
  3155. var arr0 = val0;
  3156. var arr1 = val1;
  3157. if (!arr0.push || !arr1.push) {
  3158. return;
  3159. }
  3160. var arr0Len = arr0.length;
  3161. var arr1Len = arr1.length;
  3162. if (arr0Len !== arr1Len) {
  3163. var isPreviousLarger = arr0Len > arr1Len;
  3164. if (isPreviousLarger) {
  3165. arr0.length = arr1Len;
  3166. }
  3167. else {
  3168. for (var i = arr0Len; i < arr1Len; i++) {
  3169. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  3170. }
  3171. }
  3172. }
  3173. var len2 = arr0[0] && arr0[0].length;
  3174. for (var i = 0; i < arr0.length; i++) {
  3175. if (arrDim === 1) {
  3176. if (isNaN(arr0[i])) {
  3177. arr0[i] = arr1[i];
  3178. }
  3179. }
  3180. else {
  3181. for (var j = 0; j < len2; j++) {
  3182. if (isNaN(arr0[i][j])) {
  3183. arr0[i][j] = arr1[i][j];
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. function is1DArraySame(arr0, arr1) {
  3190. var len = arr0.length;
  3191. if (len !== arr1.length) {
  3192. return false;
  3193. }
  3194. for (var i = 0; i < len; i++) {
  3195. if (arr0[i] !== arr1[i]) {
  3196. return false;
  3197. }
  3198. }
  3199. return true;
  3200. }
  3201. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3202. var v0 = (p2 - p0) * 0.5;
  3203. var v1 = (p3 - p1) * 0.5;
  3204. return (2 * (p1 - p2) + v0 + v1) * t3
  3205. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  3206. + v0 * t + p1;
  3207. }
  3208. function catmullRomInterpolate1DArray(out, p0, p1, p2, p3, t, t2, t3) {
  3209. var len = p0.length;
  3210. for (var i = 0; i < len; i++) {
  3211. out[i] = catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  3212. }
  3213. }
  3214. function catmullRomInterpolate2DArray(out, p0, p1, p2, p3, t, t2, t3) {
  3215. var len = p0.length;
  3216. var len2 = p0[0].length;
  3217. for (var i = 0; i < len; i++) {
  3218. if (!out[i]) {
  3219. out[1] = [];
  3220. }
  3221. for (var j = 0; j < len2; j++) {
  3222. out[i][j] = catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  3223. }
  3224. }
  3225. }
  3226. function cloneValue(value) {
  3227. if (isArrayLike(value)) {
  3228. var len = value.length;
  3229. if (isArrayLike(value[0])) {
  3230. var ret = [];
  3231. for (var i = 0; i < len; i++) {
  3232. ret.push(arraySlice.call(value[i]));
  3233. }
  3234. return ret;
  3235. }
  3236. return arraySlice.call(value);
  3237. }
  3238. return value;
  3239. }
  3240. function rgba2String(rgba) {
  3241. rgba[0] = Math.floor(rgba[0]);
  3242. rgba[1] = Math.floor(rgba[1]);
  3243. rgba[2] = Math.floor(rgba[2]);
  3244. return 'rgba(' + rgba.join(',') + ')';
  3245. }
  3246. function guessArrayDim(value) {
  3247. return isArrayLike(value && value[0]) ? 2 : 1;
  3248. }
  3249. var tmpRgba = [0, 0, 0, 0];
  3250. var Track = (function () {
  3251. function Track(propName) {
  3252. this.keyframes = [];
  3253. this.maxTime = 0;
  3254. this.arrDim = 0;
  3255. this.interpolable = true;
  3256. this._needsSort = false;
  3257. this._isAllValueEqual = true;
  3258. this._lastFrame = 0;
  3259. this._lastFramePercent = 0;
  3260. this.propName = propName;
  3261. }
  3262. Track.prototype.isFinished = function () {
  3263. return this._finished;
  3264. };
  3265. Track.prototype.setFinished = function () {
  3266. this._finished = true;
  3267. if (this._additiveTrack) {
  3268. this._additiveTrack.setFinished();
  3269. }
  3270. };
  3271. Track.prototype.needsAnimate = function () {
  3272. return !this._isAllValueEqual
  3273. && this.keyframes.length >= 2
  3274. && this.interpolable
  3275. && this.maxTime > 0;
  3276. };
  3277. Track.prototype.getAdditiveTrack = function () {
  3278. return this._additiveTrack;
  3279. };
  3280. Track.prototype.addKeyframe = function (time, value) {
  3281. if (time >= this.maxTime) {
  3282. this.maxTime = time;
  3283. }
  3284. else {
  3285. this._needsSort = true;
  3286. }
  3287. var keyframes = this.keyframes;
  3288. var len = keyframes.length;
  3289. if (this.interpolable) {
  3290. if (isArrayLike(value)) {
  3291. var arrayDim = guessArrayDim(value);
  3292. if (len > 0 && this.arrDim !== arrayDim) {
  3293. this.interpolable = false;
  3294. return;
  3295. }
  3296. if (arrayDim === 1 && typeof value[0] !== 'number'
  3297. || arrayDim === 2 && typeof value[0][0] !== 'number') {
  3298. this.interpolable = false;
  3299. return;
  3300. }
  3301. if (len > 0) {
  3302. var lastFrame = keyframes[len - 1];
  3303. if (this._isAllValueEqual) {
  3304. if (arrayDim === 1) {
  3305. if (!is1DArraySame(value, lastFrame.value)) {
  3306. this._isAllValueEqual = false;
  3307. }
  3308. }
  3309. else {
  3310. this._isAllValueEqual = false;
  3311. }
  3312. }
  3313. }
  3314. this.arrDim = arrayDim;
  3315. }
  3316. else {
  3317. if (this.arrDim > 0) {
  3318. this.interpolable = false;
  3319. return;
  3320. }
  3321. if (typeof value === 'string') {
  3322. var colorArray = parse(value);
  3323. if (colorArray) {
  3324. value = colorArray;
  3325. this.isValueColor = true;
  3326. }
  3327. else {
  3328. this.interpolable = false;
  3329. }
  3330. }
  3331. else if (typeof value !== 'number' || isNaN(value)) {
  3332. this.interpolable = false;
  3333. return;
  3334. }
  3335. if (this._isAllValueEqual && len > 0) {
  3336. var lastFrame = keyframes[len - 1];
  3337. if (this.isValueColor && !is1DArraySame(lastFrame.value, value)) {
  3338. this._isAllValueEqual = false;
  3339. }
  3340. else if (lastFrame.value !== value) {
  3341. this._isAllValueEqual = false;
  3342. }
  3343. }
  3344. }
  3345. }
  3346. var kf = {
  3347. time: time,
  3348. value: value,
  3349. percent: 0
  3350. };
  3351. this.keyframes.push(kf);
  3352. return kf;
  3353. };
  3354. Track.prototype.prepare = function (additiveTrack) {
  3355. var kfs = this.keyframes;
  3356. if (this._needsSort) {
  3357. kfs.sort(function (a, b) {
  3358. return a.time - b.time;
  3359. });
  3360. }
  3361. var arrDim = this.arrDim;
  3362. var kfsLen = kfs.length;
  3363. var lastKf = kfs[kfsLen - 1];
  3364. for (var i = 0; i < kfsLen; i++) {
  3365. kfs[i].percent = kfs[i].time / this.maxTime;
  3366. if (arrDim > 0 && i !== kfsLen - 1) {
  3367. fillArray(kfs[i].value, lastKf.value, arrDim);
  3368. }
  3369. }
  3370. if (additiveTrack
  3371. && this.needsAnimate()
  3372. && additiveTrack.needsAnimate()
  3373. && arrDim === additiveTrack.arrDim
  3374. && this.isValueColor === additiveTrack.isValueColor
  3375. && !additiveTrack._finished) {
  3376. this._additiveTrack = additiveTrack;
  3377. var startValue = kfs[0].value;
  3378. for (var i = 0; i < kfsLen; i++) {
  3379. if (arrDim === 0) {
  3380. if (this.isValueColor) {
  3381. kfs[i].additiveValue =
  3382. add1DArray([], kfs[i].value, startValue, -1);
  3383. }
  3384. else {
  3385. kfs[i].additiveValue = kfs[i].value - startValue;
  3386. }
  3387. }
  3388. else if (arrDim === 1) {
  3389. kfs[i].additiveValue = add1DArray([], kfs[i].value, startValue, -1);
  3390. }
  3391. else if (arrDim === 2) {
  3392. kfs[i].additiveValue = add2DArray([], kfs[i].value, startValue, -1);
  3393. }
  3394. }
  3395. }
  3396. };
  3397. Track.prototype.step = function (target, percent) {
  3398. if (this._finished) {
  3399. return;
  3400. }
  3401. if (this._additiveTrack && this._additiveTrack._finished) {
  3402. this._additiveTrack = null;
  3403. }
  3404. var isAdditive = this._additiveTrack != null;
  3405. var valueKey = isAdditive ? 'additiveValue' : 'value';
  3406. var keyframes = this.keyframes;
  3407. var kfsNum = this.keyframes.length;
  3408. var propName = this.propName;
  3409. var arrDim = this.arrDim;
  3410. var isValueColor = this.isValueColor;
  3411. var frameIdx;
  3412. if (percent < 0) {
  3413. frameIdx = 0;
  3414. }
  3415. else if (percent < this._lastFramePercent) {
  3416. var start = Math.min(this._lastFrame + 1, kfsNum - 1);
  3417. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  3418. if (keyframes[frameIdx].percent <= percent) {
  3419. break;
  3420. }
  3421. }
  3422. frameIdx = Math.min(frameIdx, kfsNum - 2);
  3423. }
  3424. else {
  3425. for (frameIdx = this._lastFrame; frameIdx < kfsNum; frameIdx++) {
  3426. if (keyframes[frameIdx].percent > percent) {
  3427. break;
  3428. }
  3429. }
  3430. frameIdx = Math.min(frameIdx - 1, kfsNum - 2);
  3431. }
  3432. var nextFrame = keyframes[frameIdx + 1];
  3433. var frame = keyframes[frameIdx];
  3434. if (!(frame && nextFrame)) {
  3435. return;
  3436. }
  3437. this._lastFrame = frameIdx;
  3438. this._lastFramePercent = percent;
  3439. var range = (nextFrame.percent - frame.percent);
  3440. if (range === 0) {
  3441. return;
  3442. }
  3443. var w = (percent - frame.percent) / range;
  3444. var targetArr = isAdditive ? this._additiveValue
  3445. : (isValueColor ? tmpRgba : target[propName]);
  3446. if ((arrDim > 0 || isValueColor) && !targetArr) {
  3447. targetArr = this._additiveValue = [];
  3448. }
  3449. if (this.useSpline) {
  3450. var p1 = keyframes[frameIdx][valueKey];
  3451. var p0 = keyframes[frameIdx === 0 ? frameIdx : frameIdx - 1][valueKey];
  3452. var p2 = keyframes[frameIdx > kfsNum - 2 ? kfsNum - 1 : frameIdx + 1][valueKey];
  3453. var p3 = keyframes[frameIdx > kfsNum - 3 ? kfsNum - 1 : frameIdx + 2][valueKey];
  3454. if (arrDim > 0) {
  3455. arrDim === 1
  3456. ? catmullRomInterpolate1DArray(targetArr, p0, p1, p2, p3, w, w * w, w * w * w)
  3457. : catmullRomInterpolate2DArray(targetArr, p0, p1, p2, p3, w, w * w, w * w * w);
  3458. }
  3459. else if (isValueColor) {
  3460. catmullRomInterpolate1DArray(targetArr, p0, p1, p2, p3, w, w * w, w * w * w);
  3461. if (!isAdditive) {
  3462. target[propName] = rgba2String(targetArr);
  3463. }
  3464. }
  3465. else {
  3466. var value = void 0;
  3467. if (!this.interpolable) {
  3468. value = p2;
  3469. }
  3470. else {
  3471. value = catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  3472. }
  3473. if (isAdditive) {
  3474. this._additiveValue = value;
  3475. }
  3476. else {
  3477. target[propName] = value;
  3478. }
  3479. }
  3480. }
  3481. else {
  3482. if (arrDim > 0) {
  3483. arrDim === 1
  3484. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  3485. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  3486. }
  3487. else if (isValueColor) {
  3488. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  3489. if (!isAdditive) {
  3490. target[propName] = rgba2String(targetArr);
  3491. }
  3492. }
  3493. else {
  3494. var value = void 0;
  3495. if (!this.interpolable) {
  3496. value = step(frame[valueKey], nextFrame[valueKey], w);
  3497. }
  3498. else {
  3499. value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  3500. }
  3501. if (isAdditive) {
  3502. this._additiveValue = value;
  3503. }
  3504. else {
  3505. target[propName] = value;
  3506. }
  3507. }
  3508. }
  3509. if (isAdditive) {
  3510. this._addToTarget(target);
  3511. }
  3512. };
  3513. Track.prototype._addToTarget = function (target) {
  3514. var arrDim = this.arrDim;
  3515. var propName = this.propName;
  3516. var additiveValue = this._additiveValue;
  3517. if (arrDim === 0) {
  3518. if (this.isValueColor) {
  3519. parse(target[propName], tmpRgba);
  3520. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  3521. target[propName] = rgba2String(tmpRgba);
  3522. }
  3523. else {
  3524. target[propName] = target[propName] + additiveValue;
  3525. }
  3526. }
  3527. else if (arrDim === 1) {
  3528. add1DArray(target[propName], target[propName], additiveValue, 1);
  3529. }
  3530. else if (arrDim === 2) {
  3531. add2DArray(target[propName], target[propName], additiveValue, 1);
  3532. }
  3533. };
  3534. return Track;
  3535. }());
  3536. var Animator = (function () {
  3537. function Animator(target, loop, additiveTo) {
  3538. this._tracks = {};
  3539. this._trackKeys = [];
  3540. this._delay = 0;
  3541. this._maxTime = 0;
  3542. this._paused = false;
  3543. this._started = 0;
  3544. this._clip = null;
  3545. this._target = target;
  3546. this._loop = loop;
  3547. if (loop && additiveTo) {
  3548. logError('Can\' use additive animation on looped animation.');
  3549. return;
  3550. }
  3551. this._additiveAnimators = additiveTo;
  3552. }
  3553. Animator.prototype.getTarget = function () {
  3554. return this._target;
  3555. };
  3556. Animator.prototype.changeTarget = function (target) {
  3557. this._target = target;
  3558. };
  3559. Animator.prototype.when = function (time, props) {
  3560. return this.whenWithKeys(time, props, keys(props));
  3561. };
  3562. Animator.prototype.whenWithKeys = function (time, props, propNames) {
  3563. var tracks = this._tracks;
  3564. for (var i = 0; i < propNames.length; i++) {
  3565. var propName = propNames[i];
  3566. var track = tracks[propName];
  3567. if (!track) {
  3568. track = tracks[propName] = new Track(propName);
  3569. var initialValue = void 0;
  3570. var additiveTrack = this._getAdditiveTrack(propName);
  3571. if (additiveTrack) {
  3572. var lastFinalKf = additiveTrack.keyframes[additiveTrack.keyframes.length - 1];
  3573. initialValue = lastFinalKf && lastFinalKf.value;
  3574. if (additiveTrack.isValueColor && initialValue) {
  3575. initialValue = rgba2String(initialValue);
  3576. }
  3577. }
  3578. else {
  3579. initialValue = this._target[propName];
  3580. }
  3581. if (initialValue == null) {
  3582. continue;
  3583. }
  3584. if (time !== 0) {
  3585. track.addKeyframe(0, cloneValue(initialValue));
  3586. }
  3587. this._trackKeys.push(propName);
  3588. }
  3589. track.addKeyframe(time, cloneValue(props[propName]));
  3590. }
  3591. this._maxTime = Math.max(this._maxTime, time);
  3592. return this;
  3593. };
  3594. Animator.prototype.pause = function () {
  3595. this._clip.pause();
  3596. this._paused = true;
  3597. };
  3598. Animator.prototype.resume = function () {
  3599. this._clip.resume();
  3600. this._paused = false;
  3601. };
  3602. Animator.prototype.isPaused = function () {
  3603. return !!this._paused;
  3604. };
  3605. Animator.prototype._doneCallback = function () {
  3606. this._setTracksFinished();
  3607. this._clip = null;
  3608. var doneList = this._doneCbs;
  3609. if (doneList) {
  3610. var len = doneList.length;
  3611. for (var i = 0; i < len; i++) {
  3612. doneList[i].call(this);
  3613. }
  3614. }
  3615. };
  3616. Animator.prototype._abortedCallback = function () {
  3617. this._setTracksFinished();
  3618. var animation = this.animation;
  3619. var abortedList = this._abortedCbs;
  3620. if (animation) {
  3621. animation.removeClip(this._clip);
  3622. }
  3623. this._clip = null;
  3624. if (abortedList) {
  3625. for (var i = 0; i < abortedList.length; i++) {
  3626. abortedList[i].call(this);
  3627. }
  3628. }
  3629. };
  3630. Animator.prototype._setTracksFinished = function () {
  3631. var tracks = this._tracks;
  3632. var tracksKeys = this._trackKeys;
  3633. for (var i = 0; i < tracksKeys.length; i++) {
  3634. tracks[tracksKeys[i]].setFinished();
  3635. }
  3636. };
  3637. Animator.prototype._getAdditiveTrack = function (trackName) {
  3638. var additiveTrack;
  3639. var additiveAnimators = this._additiveAnimators;
  3640. if (additiveAnimators) {
  3641. for (var i = 0; i < additiveAnimators.length; i++) {
  3642. var track = additiveAnimators[i].getTrack(trackName);
  3643. if (track) {
  3644. additiveTrack = track;
  3645. }
  3646. }
  3647. }
  3648. return additiveTrack;
  3649. };
  3650. Animator.prototype.start = function (easing, forceAnimate) {
  3651. if (this._started > 0) {
  3652. return;
  3653. }
  3654. this._started = 1;
  3655. var self = this;
  3656. var tracks = [];
  3657. for (var i = 0; i < this._trackKeys.length; i++) {
  3658. var propName = this._trackKeys[i];
  3659. var track = this._tracks[propName];
  3660. var additiveTrack = this._getAdditiveTrack(propName);
  3661. var kfs = track.keyframes;
  3662. track.prepare(additiveTrack);
  3663. if (track.needsAnimate()) {
  3664. tracks.push(track);
  3665. }
  3666. else if (!track.interpolable) {
  3667. var lastKf = kfs[kfs.length - 1];
  3668. if (lastKf) {
  3669. self._target[track.propName] = lastKf.value;
  3670. }
  3671. }
  3672. }
  3673. if (tracks.length || forceAnimate) {
  3674. var clip = new Clip({
  3675. life: this._maxTime,
  3676. loop: this._loop,
  3677. delay: this._delay,
  3678. onframe: function (percent) {
  3679. self._started = 2;
  3680. var additiveAnimators = self._additiveAnimators;
  3681. if (additiveAnimators) {
  3682. var stillHasAdditiveAnimator = false;
  3683. for (var i = 0; i < additiveAnimators.length; i++) {
  3684. if (additiveAnimators[i]._clip) {
  3685. stillHasAdditiveAnimator = true;
  3686. break;
  3687. }
  3688. }
  3689. if (!stillHasAdditiveAnimator) {
  3690. self._additiveAnimators = null;
  3691. }
  3692. }
  3693. for (var i = 0; i < tracks.length; i++) {
  3694. tracks[i].step(self._target, percent);
  3695. }
  3696. var onframeList = self._onframeCbs;
  3697. if (onframeList) {
  3698. for (var i = 0; i < onframeList.length; i++) {
  3699. onframeList[i](self._target, percent);
  3700. }
  3701. }
  3702. },
  3703. ondestroy: function () {
  3704. self._doneCallback();
  3705. }
  3706. });
  3707. this._clip = clip;
  3708. if (this.animation) {
  3709. this.animation.addClip(clip);
  3710. }
  3711. if (easing && easing !== 'spline') {
  3712. clip.easing = easing;
  3713. }
  3714. }
  3715. else {
  3716. this._doneCallback();
  3717. }
  3718. return this;
  3719. };
  3720. Animator.prototype.stop = function (forwardToLast) {
  3721. if (!this._clip) {
  3722. return;
  3723. }
  3724. var clip = this._clip;
  3725. if (forwardToLast) {
  3726. clip.onframe(1);
  3727. }
  3728. this._abortedCallback();
  3729. };
  3730. Animator.prototype.delay = function (time) {
  3731. this._delay = time;
  3732. return this;
  3733. };
  3734. Animator.prototype.during = function (cb) {
  3735. if (cb) {
  3736. if (!this._onframeCbs) {
  3737. this._onframeCbs = [];
  3738. }
  3739. this._onframeCbs.push(cb);
  3740. }
  3741. return this;
  3742. };
  3743. Animator.prototype.done = function (cb) {
  3744. if (cb) {
  3745. if (!this._doneCbs) {
  3746. this._doneCbs = [];
  3747. }
  3748. this._doneCbs.push(cb);
  3749. }
  3750. return this;
  3751. };
  3752. Animator.prototype.aborted = function (cb) {
  3753. if (cb) {
  3754. if (!this._abortedCbs) {
  3755. this._abortedCbs = [];
  3756. }
  3757. this._abortedCbs.push(cb);
  3758. }
  3759. return this;
  3760. };
  3761. Animator.prototype.getClip = function () {
  3762. return this._clip;
  3763. };
  3764. Animator.prototype.getTrack = function (propName) {
  3765. return this._tracks[propName];
  3766. };
  3767. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  3768. if (!propNames.length || !this._clip) {
  3769. return true;
  3770. }
  3771. var tracks = this._tracks;
  3772. var tracksKeys = this._trackKeys;
  3773. for (var i = 0; i < propNames.length; i++) {
  3774. var track = tracks[propNames[i]];
  3775. if (track) {
  3776. if (forwardToLast) {
  3777. track.step(this._target, 1);
  3778. }
  3779. else if (this._started === 1) {
  3780. track.step(this._target, 0);
  3781. }
  3782. track.setFinished();
  3783. }
  3784. }
  3785. var allAborted = true;
  3786. for (var i = 0; i < tracksKeys.length; i++) {
  3787. if (!tracks[tracksKeys[i]].isFinished()) {
  3788. allAborted = false;
  3789. break;
  3790. }
  3791. }
  3792. if (allAborted) {
  3793. this._abortedCallback();
  3794. }
  3795. return allAborted;
  3796. };
  3797. Animator.prototype.saveFinalToTarget = function (target, trackKeys) {
  3798. if (!target) {
  3799. return;
  3800. }
  3801. trackKeys = trackKeys || this._trackKeys;
  3802. for (var i = 0; i < trackKeys.length; i++) {
  3803. var propName = trackKeys[i];
  3804. var track = this._tracks[propName];
  3805. if (!track || track.isFinished()) {
  3806. continue;
  3807. }
  3808. var kfs = track.keyframes;
  3809. var lastKf = kfs[kfs.length - 1];
  3810. if (lastKf) {
  3811. var val = cloneValue(lastKf.value);
  3812. if (track.isValueColor) {
  3813. val = rgba2String(val);
  3814. }
  3815. target[propName] = val;
  3816. }
  3817. }
  3818. };
  3819. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  3820. trackKeys = trackKeys || keys(finalProps);
  3821. for (var i = 0; i < trackKeys.length; i++) {
  3822. var propName = trackKeys[i];
  3823. var track = this._tracks[propName];
  3824. if (!track) {
  3825. continue;
  3826. }
  3827. var kfs = track.keyframes;
  3828. if (kfs.length > 1) {
  3829. var lastKf = kfs.pop();
  3830. track.addKeyframe(lastKf.time, finalProps[propName]);
  3831. track.prepare(track.getAdditiveTrack());
  3832. }
  3833. }
  3834. };
  3835. return Animator;
  3836. }());
  3837. var Animation = (function (_super) {
  3838. __extends(Animation, _super);
  3839. function Animation(opts) {
  3840. var _this = _super.call(this) || this;
  3841. _this._running = false;
  3842. _this._time = 0;
  3843. _this._pausedTime = 0;
  3844. _this._pauseStart = 0;
  3845. _this._paused = false;
  3846. opts = opts || {};
  3847. _this.stage = opts.stage || {};
  3848. _this.onframe = opts.onframe || function () { };
  3849. return _this;
  3850. }
  3851. Animation.prototype.addClip = function (clip) {
  3852. if (clip.animation) {
  3853. this.removeClip(clip);
  3854. }
  3855. if (!this._clipsHead) {
  3856. this._clipsHead = this._clipsTail = clip;
  3857. }
  3858. else {
  3859. this._clipsTail.next = clip;
  3860. clip.prev = this._clipsTail;
  3861. clip.next = null;
  3862. this._clipsTail = clip;
  3863. }
  3864. clip.animation = this;
  3865. };
  3866. Animation.prototype.addAnimator = function (animator) {
  3867. animator.animation = this;
  3868. var clip = animator.getClip();
  3869. if (clip) {
  3870. this.addClip(clip);
  3871. }
  3872. };
  3873. Animation.prototype.removeClip = function (clip) {
  3874. if (!clip.animation) {
  3875. return;
  3876. }
  3877. var prev = clip.prev;
  3878. var next = clip.next;
  3879. if (prev) {
  3880. prev.next = next;
  3881. }
  3882. else {
  3883. this._clipsHead = next;
  3884. }
  3885. if (next) {
  3886. next.prev = prev;
  3887. }
  3888. else {
  3889. this._clipsTail = prev;
  3890. }
  3891. clip.next = clip.prev = clip.animation = null;
  3892. };
  3893. Animation.prototype.removeAnimator = function (animator) {
  3894. var clip = animator.getClip();
  3895. if (clip) {
  3896. this.removeClip(clip);
  3897. }
  3898. animator.animation = null;
  3899. };
  3900. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  3901. var time = new Date().getTime() - this._pausedTime;
  3902. var delta = time - this._time;
  3903. var clip = this._clipsHead;
  3904. while (clip) {
  3905. var nextClip = clip.next;
  3906. var finished = clip.step(time, delta);
  3907. if (finished) {
  3908. clip.ondestroy && clip.ondestroy();
  3909. this.removeClip(clip);
  3910. clip = nextClip;
  3911. }
  3912. else {
  3913. clip = nextClip;
  3914. }
  3915. }
  3916. this._time = time;
  3917. if (!notTriggerFrameAndStageUpdate) {
  3918. this.onframe(delta);
  3919. this.trigger('frame', delta);
  3920. this.stage.update && this.stage.update();
  3921. }
  3922. };
  3923. Animation.prototype._startLoop = function () {
  3924. var self = this;
  3925. this._running = true;
  3926. function step() {
  3927. if (self._running) {
  3928. requestAnimationFrame$1(step);
  3929. !self._paused && self.update();
  3930. }
  3931. }
  3932. requestAnimationFrame$1(step);
  3933. };
  3934. Animation.prototype.start = function () {
  3935. if (this._running) {
  3936. return;
  3937. }
  3938. this._time = new Date().getTime();
  3939. this._pausedTime = 0;
  3940. this._startLoop();
  3941. };
  3942. Animation.prototype.stop = function () {
  3943. this._running = false;
  3944. };
  3945. Animation.prototype.pause = function () {
  3946. if (!this._paused) {
  3947. this._pauseStart = new Date().getTime();
  3948. this._paused = true;
  3949. }
  3950. };
  3951. Animation.prototype.resume = function () {
  3952. if (this._paused) {
  3953. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  3954. this._paused = false;
  3955. }
  3956. };
  3957. Animation.prototype.clear = function () {
  3958. var clip = this._clipsHead;
  3959. while (clip) {
  3960. var nextClip = clip.next;
  3961. clip.prev = clip.next = clip.animation = null;
  3962. clip = nextClip;
  3963. }
  3964. this._clipsHead = this._clipsTail = null;
  3965. };
  3966. Animation.prototype.isFinished = function () {
  3967. return this._clipsHead == null;
  3968. };
  3969. Animation.prototype.animate = function (target, options) {
  3970. options = options || {};
  3971. this.start();
  3972. var animator = new Animator(target, options.loop);
  3973. this.addAnimator(animator);
  3974. return animator;
  3975. };
  3976. return Animation;
  3977. }(Eventful));
  3978. var TOUCH_CLICK_DELAY = 300;
  3979. var globalEventSupported = env.domSupported;
  3980. var localNativeListenerNames = (function () {
  3981. var mouseHandlerNames = [
  3982. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  3983. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  3984. ];
  3985. var touchHandlerNames = [
  3986. 'touchstart', 'touchend', 'touchmove'
  3987. ];
  3988. var pointerEventNameMap = {
  3989. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  3990. };
  3991. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  3992. var nm = name.replace('mouse', 'pointer');
  3993. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  3994. });
  3995. return {
  3996. mouse: mouseHandlerNames,
  3997. touch: touchHandlerNames,
  3998. pointer: pointerHandlerNames
  3999. };
  4000. })();
  4001. var globalNativeListenerNames = {
  4002. mouse: ['mousemove', 'mouseup'],
  4003. pointer: ['pointermove', 'pointerup']
  4004. };
  4005. var wheelEventSupported = false;
  4006. function isPointerFromTouch(event) {
  4007. var pointerType = event.pointerType;
  4008. return pointerType === 'pen' || pointerType === 'touch';
  4009. }
  4010. function setTouchTimer(scope) {
  4011. scope.touching = true;
  4012. if (scope.touchTimer != null) {
  4013. clearTimeout(scope.touchTimer);
  4014. scope.touchTimer = null;
  4015. }
  4016. scope.touchTimer = setTimeout(function () {
  4017. scope.touching = false;
  4018. scope.touchTimer = null;
  4019. }, 700);
  4020. }
  4021. function markTouch(event) {
  4022. event && (event.zrByTouch = true);
  4023. }
  4024. function normalizeGlobalEvent(instance, event) {
  4025. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  4026. }
  4027. function isLocalEl(instance, el) {
  4028. var elTmp = el;
  4029. var isLocal = false;
  4030. while (elTmp && elTmp.nodeType !== 9
  4031. && !(isLocal = elTmp.domBelongToZr
  4032. || (elTmp !== el && elTmp === instance.painterRoot))) {
  4033. elTmp = elTmp.parentNode;
  4034. }
  4035. return isLocal;
  4036. }
  4037. var FakeGlobalEvent = (function () {
  4038. function FakeGlobalEvent(instance, event) {
  4039. this.stopPropagation = noop;
  4040. this.stopImmediatePropagation = noop;
  4041. this.preventDefault = noop;
  4042. this.type = event.type;
  4043. this.target = this.currentTarget = instance.dom;
  4044. this.pointerType = event.pointerType;
  4045. this.clientX = event.clientX;
  4046. this.clientY = event.clientY;
  4047. }
  4048. return FakeGlobalEvent;
  4049. }());
  4050. var localDOMHandlers = {
  4051. mousedown: function (event) {
  4052. event = normalizeEvent(this.dom, event);
  4053. this.__mayPointerCapture = [event.zrX, event.zrY];
  4054. this.trigger('mousedown', event);
  4055. },
  4056. mousemove: function (event) {
  4057. event = normalizeEvent(this.dom, event);
  4058. var downPoint = this.__mayPointerCapture;
  4059. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  4060. this.__togglePointerCapture(true);
  4061. }
  4062. this.trigger('mousemove', event);
  4063. },
  4064. mouseup: function (event) {
  4065. event = normalizeEvent(this.dom, event);
  4066. this.__togglePointerCapture(false);
  4067. this.trigger('mouseup', event);
  4068. },
  4069. mouseout: function (event) {
  4070. event = normalizeEvent(this.dom, event);
  4071. var element = event.toElement || event.relatedTarget;
  4072. if (!isLocalEl(this, element)) {
  4073. if (this.__pointerCapturing) {
  4074. event.zrEventControl = 'no_globalout';
  4075. }
  4076. this.trigger('mouseout', event);
  4077. }
  4078. },
  4079. wheel: function (event) {
  4080. wheelEventSupported = true;
  4081. event = normalizeEvent(this.dom, event);
  4082. this.trigger('mousewheel', event);
  4083. },
  4084. mousewheel: function (event) {
  4085. if (wheelEventSupported) {
  4086. return;
  4087. }
  4088. event = normalizeEvent(this.dom, event);
  4089. this.trigger('mousewheel', event);
  4090. },
  4091. touchstart: function (event) {
  4092. event = normalizeEvent(this.dom, event);
  4093. markTouch(event);
  4094. this.__lastTouchMoment = new Date();
  4095. this.handler.processGesture(event, 'start');
  4096. localDOMHandlers.mousemove.call(this, event);
  4097. localDOMHandlers.mousedown.call(this, event);
  4098. },
  4099. touchmove: function (event) {
  4100. event = normalizeEvent(this.dom, event);
  4101. markTouch(event);
  4102. this.handler.processGesture(event, 'change');
  4103. localDOMHandlers.mousemove.call(this, event);
  4104. },
  4105. touchend: function (event) {
  4106. event = normalizeEvent(this.dom, event);
  4107. markTouch(event);
  4108. this.handler.processGesture(event, 'end');
  4109. localDOMHandlers.mouseup.call(this, event);
  4110. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  4111. localDOMHandlers.click.call(this, event);
  4112. }
  4113. },
  4114. pointerdown: function (event) {
  4115. localDOMHandlers.mousedown.call(this, event);
  4116. },
  4117. pointermove: function (event) {
  4118. if (!isPointerFromTouch(event)) {
  4119. localDOMHandlers.mousemove.call(this, event);
  4120. }
  4121. },
  4122. pointerup: function (event) {
  4123. localDOMHandlers.mouseup.call(this, event);
  4124. },
  4125. pointerout: function (event) {
  4126. if (!isPointerFromTouch(event)) {
  4127. localDOMHandlers.mouseout.call(this, event);
  4128. }
  4129. }
  4130. };
  4131. each(['click', 'dblclick', 'contextmenu'], function (name) {
  4132. localDOMHandlers[name] = function (event) {
  4133. event = normalizeEvent(this.dom, event);
  4134. this.trigger(name, event);
  4135. };
  4136. });
  4137. var globalDOMHandlers = {
  4138. pointermove: function (event) {
  4139. if (!isPointerFromTouch(event)) {
  4140. globalDOMHandlers.mousemove.call(this, event);
  4141. }
  4142. },
  4143. pointerup: function (event) {
  4144. globalDOMHandlers.mouseup.call(this, event);
  4145. },
  4146. mousemove: function (event) {
  4147. this.trigger('mousemove', event);
  4148. },
  4149. mouseup: function (event) {
  4150. var pointerCaptureReleasing = this.__pointerCapturing;
  4151. this.__togglePointerCapture(false);
  4152. this.trigger('mouseup', event);
  4153. if (pointerCaptureReleasing) {
  4154. event.zrEventControl = 'only_globalout';
  4155. this.trigger('mouseout', event);
  4156. }
  4157. }
  4158. };
  4159. function mountLocalDOMEventListeners(instance, scope) {
  4160. var domHandlers = scope.domHandlers;
  4161. if (env.pointerEventsSupported) {
  4162. each(localNativeListenerNames.pointer, function (nativeEventName) {
  4163. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  4164. domHandlers[nativeEventName].call(instance, event);
  4165. });
  4166. });
  4167. }
  4168. else {
  4169. if (env.touchEventsSupported) {
  4170. each(localNativeListenerNames.touch, function (nativeEventName) {
  4171. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  4172. domHandlers[nativeEventName].call(instance, event);
  4173. setTouchTimer(scope);
  4174. });
  4175. });
  4176. }
  4177. each(localNativeListenerNames.mouse, function (nativeEventName) {
  4178. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  4179. event = getNativeEvent(event);
  4180. if (!scope.touching) {
  4181. domHandlers[nativeEventName].call(instance, event);
  4182. }
  4183. });
  4184. });
  4185. }
  4186. }
  4187. function mountGlobalDOMEventListeners(instance, scope) {
  4188. if (env.pointerEventsSupported) {
  4189. each(globalNativeListenerNames.pointer, mount);
  4190. }
  4191. else if (!env.touchEventsSupported) {
  4192. each(globalNativeListenerNames.mouse, mount);
  4193. }
  4194. function mount(nativeEventName) {
  4195. function nativeEventListener(event) {
  4196. event = getNativeEvent(event);
  4197. if (!isLocalEl(instance, event.target)) {
  4198. event = normalizeGlobalEvent(instance, event);
  4199. scope.domHandlers[nativeEventName].call(instance, event);
  4200. }
  4201. }
  4202. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  4203. }
  4204. }
  4205. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  4206. scope.mounted[nativeEventName] = listener;
  4207. scope.listenerOpts[nativeEventName] = opt;
  4208. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  4209. }
  4210. function unmountDOMEventListeners(scope) {
  4211. var mounted = scope.mounted;
  4212. for (var nativeEventName in mounted) {
  4213. if (mounted.hasOwnProperty(nativeEventName)) {
  4214. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  4215. }
  4216. }
  4217. scope.mounted = {};
  4218. }
  4219. var DOMHandlerScope = (function () {
  4220. function DOMHandlerScope(domTarget, domHandlers) {
  4221. this.mounted = {};
  4222. this.listenerOpts = {};
  4223. this.touching = false;
  4224. this.domTarget = domTarget;
  4225. this.domHandlers = domHandlers;
  4226. }
  4227. return DOMHandlerScope;
  4228. }());
  4229. var HandlerDomProxy = (function (_super) {
  4230. __extends(HandlerDomProxy, _super);
  4231. function HandlerDomProxy(dom, painterRoot) {
  4232. var _this = _super.call(this) || this;
  4233. _this.__pointerCapturing = false;
  4234. _this.dom = dom;
  4235. _this.painterRoot = painterRoot;
  4236. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  4237. if (globalEventSupported) {
  4238. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  4239. }
  4240. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  4241. return _this;
  4242. }
  4243. HandlerDomProxy.prototype.dispose = function () {
  4244. unmountDOMEventListeners(this._localHandlerScope);
  4245. if (globalEventSupported) {
  4246. unmountDOMEventListeners(this._globalHandlerScope);
  4247. }
  4248. };
  4249. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  4250. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  4251. };
  4252. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  4253. this.__mayPointerCapture = null;
  4254. if (globalEventSupported
  4255. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  4256. this.__pointerCapturing = isPointerCapturing;
  4257. var globalHandlerScope = this._globalHandlerScope;
  4258. isPointerCapturing
  4259. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  4260. : unmountDOMEventListeners(globalHandlerScope);
  4261. }
  4262. };
  4263. return HandlerDomProxy;
  4264. }(Eventful));
  4265. var dpr = 1;
  4266. if (typeof window !== 'undefined') {
  4267. dpr = Math.max(window.devicePixelRatio
  4268. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  4269. || 1, 1);
  4270. }
  4271. var devicePixelRatio = dpr;
  4272. var DARK_MODE_THRESHOLD = 0.4;
  4273. var DARK_LABEL_COLOR = '#333';
  4274. var LIGHT_LABEL_COLOR = '#ccc';
  4275. var LIGHTER_LABEL_COLOR = '#eee';
  4276. function create$1() {
  4277. return [1, 0, 0, 1, 0, 0];
  4278. }
  4279. function identity(out) {
  4280. out[0] = 1;
  4281. out[1] = 0;
  4282. out[2] = 0;
  4283. out[3] = 1;
  4284. out[4] = 0;
  4285. out[5] = 0;
  4286. return out;
  4287. }
  4288. function copy$1(out, m) {
  4289. out[0] = m[0];
  4290. out[1] = m[1];
  4291. out[2] = m[2];
  4292. out[3] = m[3];
  4293. out[4] = m[4];
  4294. out[5] = m[5];
  4295. return out;
  4296. }
  4297. function mul$1(out, m1, m2) {
  4298. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  4299. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  4300. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  4301. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  4302. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  4303. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  4304. out[0] = out0;
  4305. out[1] = out1;
  4306. out[2] = out2;
  4307. out[3] = out3;
  4308. out[4] = out4;
  4309. out[5] = out5;
  4310. return out;
  4311. }
  4312. function translate(out, a, v) {
  4313. out[0] = a[0];
  4314. out[1] = a[1];
  4315. out[2] = a[2];
  4316. out[3] = a[3];
  4317. out[4] = a[4] + v[0];
  4318. out[5] = a[5] + v[1];
  4319. return out;
  4320. }
  4321. function rotate(out, a, rad) {
  4322. var aa = a[0];
  4323. var ac = a[2];
  4324. var atx = a[4];
  4325. var ab = a[1];
  4326. var ad = a[3];
  4327. var aty = a[5];
  4328. var st = Math.sin(rad);
  4329. var ct = Math.cos(rad);
  4330. out[0] = aa * ct + ab * st;
  4331. out[1] = -aa * st + ab * ct;
  4332. out[2] = ac * ct + ad * st;
  4333. out[3] = -ac * st + ct * ad;
  4334. out[4] = ct * atx + st * aty;
  4335. out[5] = ct * aty - st * atx;
  4336. return out;
  4337. }
  4338. function scale$1(out, a, v) {
  4339. var vx = v[0];
  4340. var vy = v[1];
  4341. out[0] = a[0] * vx;
  4342. out[1] = a[1] * vy;
  4343. out[2] = a[2] * vx;
  4344. out[3] = a[3] * vy;
  4345. out[4] = a[4] * vx;
  4346. out[5] = a[5] * vy;
  4347. return out;
  4348. }
  4349. function invert(out, a) {
  4350. var aa = a[0];
  4351. var ac = a[2];
  4352. var atx = a[4];
  4353. var ab = a[1];
  4354. var ad = a[3];
  4355. var aty = a[5];
  4356. var det = aa * ad - ab * ac;
  4357. if (!det) {
  4358. return null;
  4359. }
  4360. det = 1.0 / det;
  4361. out[0] = ad * det;
  4362. out[1] = -ab * det;
  4363. out[2] = -ac * det;
  4364. out[3] = aa * det;
  4365. out[4] = (ac * aty - ad * atx) * det;
  4366. out[5] = (ab * atx - aa * aty) * det;
  4367. return out;
  4368. }
  4369. function clone$2(a) {
  4370. var b = create$1();
  4371. copy$1(b, a);
  4372. return b;
  4373. }
  4374. var matrix = /*#__PURE__*/Object.freeze({
  4375. __proto__: null,
  4376. create: create$1,
  4377. identity: identity,
  4378. copy: copy$1,
  4379. mul: mul$1,
  4380. translate: translate,
  4381. rotate: rotate,
  4382. scale: scale$1,
  4383. invert: invert,
  4384. clone: clone$2
  4385. });
  4386. var mIdentity = identity;
  4387. var EPSILON = 5e-5;
  4388. function isNotAroundZero(val) {
  4389. return val > EPSILON || val < -EPSILON;
  4390. }
  4391. var scaleTmp = [];
  4392. var tmpTransform = [];
  4393. var originTransform = create$1();
  4394. var abs = Math.abs;
  4395. var Transformable = (function () {
  4396. function Transformable() {
  4397. }
  4398. Transformable.prototype.getLocalTransform = function (m) {
  4399. return Transformable.getLocalTransform(this, m);
  4400. };
  4401. Transformable.prototype.setPosition = function (arr) {
  4402. this.x = arr[0];
  4403. this.y = arr[1];
  4404. };
  4405. Transformable.prototype.setScale = function (arr) {
  4406. this.scaleX = arr[0];
  4407. this.scaleY = arr[1];
  4408. };
  4409. Transformable.prototype.setSkew = function (arr) {
  4410. this.skewX = arr[0];
  4411. this.skewY = arr[1];
  4412. };
  4413. Transformable.prototype.setOrigin = function (arr) {
  4414. this.originX = arr[0];
  4415. this.originY = arr[1];
  4416. };
  4417. Transformable.prototype.needLocalTransform = function () {
  4418. return isNotAroundZero(this.rotation)
  4419. || isNotAroundZero(this.x)
  4420. || isNotAroundZero(this.y)
  4421. || isNotAroundZero(this.scaleX - 1)
  4422. || isNotAroundZero(this.scaleY - 1);
  4423. };
  4424. Transformable.prototype.updateTransform = function () {
  4425. var parentTransform = this.parent && this.parent.transform;
  4426. var needLocalTransform = this.needLocalTransform();
  4427. var m = this.transform;
  4428. if (!(needLocalTransform || parentTransform)) {
  4429. m && mIdentity(m);
  4430. return;
  4431. }
  4432. m = m || create$1();
  4433. if (needLocalTransform) {
  4434. this.getLocalTransform(m);
  4435. }
  4436. else {
  4437. mIdentity(m);
  4438. }
  4439. if (parentTransform) {
  4440. if (needLocalTransform) {
  4441. mul$1(m, parentTransform, m);
  4442. }
  4443. else {
  4444. copy$1(m, parentTransform);
  4445. }
  4446. }
  4447. this.transform = m;
  4448. this._resolveGlobalScaleRatio(m);
  4449. };
  4450. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  4451. var globalScaleRatio = this.globalScaleRatio;
  4452. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  4453. this.getGlobalScale(scaleTmp);
  4454. var relX = scaleTmp[0] < 0 ? -1 : 1;
  4455. var relY = scaleTmp[1] < 0 ? -1 : 1;
  4456. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  4457. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  4458. m[0] *= sx;
  4459. m[1] *= sx;
  4460. m[2] *= sy;
  4461. m[3] *= sy;
  4462. }
  4463. this.invTransform = this.invTransform || create$1();
  4464. invert(this.invTransform, m);
  4465. };
  4466. Transformable.prototype.getComputedTransform = function () {
  4467. var transformNode = this;
  4468. var ancestors = [];
  4469. while (transformNode) {
  4470. ancestors.push(transformNode);
  4471. transformNode = transformNode.parent;
  4472. }
  4473. while (transformNode = ancestors.pop()) {
  4474. transformNode.updateTransform();
  4475. }
  4476. return this.transform;
  4477. };
  4478. Transformable.prototype.setLocalTransform = function (m) {
  4479. if (!m) {
  4480. return;
  4481. }
  4482. var sx = m[0] * m[0] + m[1] * m[1];
  4483. var sy = m[2] * m[2] + m[3] * m[3];
  4484. var rotation = Math.atan2(m[1], m[0]);
  4485. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  4486. sy = Math.sqrt(sy) * Math.cos(shearX);
  4487. sx = Math.sqrt(sx);
  4488. this.skewX = shearX;
  4489. this.skewY = 0;
  4490. this.rotation = -rotation;
  4491. this.x = +m[4];
  4492. this.y = +m[5];
  4493. this.scaleX = sx;
  4494. this.scaleY = sy;
  4495. this.originX = 0;
  4496. this.originY = 0;
  4497. };
  4498. Transformable.prototype.decomposeTransform = function () {
  4499. if (!this.transform) {
  4500. return;
  4501. }
  4502. var parent = this.parent;
  4503. var m = this.transform;
  4504. if (parent && parent.transform) {
  4505. mul$1(tmpTransform, parent.invTransform, m);
  4506. m = tmpTransform;
  4507. }
  4508. var ox = this.originX;
  4509. var oy = this.originY;
  4510. if (ox || oy) {
  4511. originTransform[4] = ox;
  4512. originTransform[5] = oy;
  4513. mul$1(tmpTransform, m, originTransform);
  4514. tmpTransform[4] -= ox;
  4515. tmpTransform[5] -= oy;
  4516. m = tmpTransform;
  4517. }
  4518. this.setLocalTransform(m);
  4519. };
  4520. Transformable.prototype.getGlobalScale = function (out) {
  4521. var m = this.transform;
  4522. out = out || [];
  4523. if (!m) {
  4524. out[0] = 1;
  4525. out[1] = 1;
  4526. return out;
  4527. }
  4528. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  4529. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  4530. if (m[0] < 0) {
  4531. out[0] = -out[0];
  4532. }
  4533. if (m[3] < 0) {
  4534. out[1] = -out[1];
  4535. }
  4536. return out;
  4537. };
  4538. Transformable.prototype.transformCoordToLocal = function (x, y) {
  4539. var v2 = [x, y];
  4540. var invTransform = this.invTransform;
  4541. if (invTransform) {
  4542. applyTransform(v2, v2, invTransform);
  4543. }
  4544. return v2;
  4545. };
  4546. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  4547. var v2 = [x, y];
  4548. var transform = this.transform;
  4549. if (transform) {
  4550. applyTransform(v2, v2, transform);
  4551. }
  4552. return v2;
  4553. };
  4554. Transformable.prototype.getLineScale = function () {
  4555. var m = this.transform;
  4556. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  4557. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  4558. : 1;
  4559. };
  4560. Transformable.prototype.copyTransform = function (source) {
  4561. var target = this;
  4562. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  4563. var propName = TRANSFORMABLE_PROPS[i];
  4564. target[propName] = source[propName];
  4565. }
  4566. };
  4567. Transformable.getLocalTransform = function (target, m) {
  4568. m = m || [];
  4569. var ox = target.originX || 0;
  4570. var oy = target.originY || 0;
  4571. var sx = target.scaleX;
  4572. var sy = target.scaleY;
  4573. var rotation = target.rotation || 0;
  4574. var x = target.x;
  4575. var y = target.y;
  4576. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  4577. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  4578. if (ox || oy) {
  4579. m[4] = -ox * sx - skewX * oy * sy;
  4580. m[5] = -oy * sy - skewY * ox * sx;
  4581. }
  4582. else {
  4583. m[4] = m[5] = 0;
  4584. }
  4585. m[0] = sx;
  4586. m[3] = sy;
  4587. m[1] = skewY * sx;
  4588. m[2] = skewX * sy;
  4589. rotation && rotate(m, m, rotation);
  4590. m[4] += ox + x;
  4591. m[5] += oy + y;
  4592. return m;
  4593. };
  4594. Transformable.initDefaultProps = (function () {
  4595. var proto = Transformable.prototype;
  4596. proto.x = 0;
  4597. proto.y = 0;
  4598. proto.scaleX = 1;
  4599. proto.scaleY = 1;
  4600. proto.originX = 0;
  4601. proto.originY = 0;
  4602. proto.skewX = 0;
  4603. proto.skewY = 0;
  4604. proto.rotation = 0;
  4605. proto.globalScaleRatio = 1;
  4606. })();
  4607. return Transformable;
  4608. }());
  4609. var TRANSFORMABLE_PROPS = [
  4610. 'x', 'y', 'originX', 'originY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  4611. ];
  4612. var Point = (function () {
  4613. function Point(x, y) {
  4614. this.x = x || 0;
  4615. this.y = y || 0;
  4616. }
  4617. Point.prototype.copy = function (other) {
  4618. this.x = other.x;
  4619. this.y = other.y;
  4620. return this;
  4621. };
  4622. Point.prototype.clone = function () {
  4623. return new Point(this.x, this.y);
  4624. };
  4625. Point.prototype.set = function (x, y) {
  4626. this.x = x;
  4627. this.y = y;
  4628. return this;
  4629. };
  4630. Point.prototype.equal = function (other) {
  4631. return other.x === this.x && other.y === this.y;
  4632. };
  4633. Point.prototype.add = function (other) {
  4634. this.x += other.x;
  4635. this.y += other.y;
  4636. return this;
  4637. };
  4638. Point.prototype.scale = function (scalar) {
  4639. this.x *= scalar;
  4640. this.y *= scalar;
  4641. };
  4642. Point.prototype.scaleAndAdd = function (other, scalar) {
  4643. this.x += other.x * scalar;
  4644. this.y += other.y * scalar;
  4645. };
  4646. Point.prototype.sub = function (other) {
  4647. this.x -= other.x;
  4648. this.y -= other.y;
  4649. return this;
  4650. };
  4651. Point.prototype.dot = function (other) {
  4652. return this.x * other.x + this.y * other.y;
  4653. };
  4654. Point.prototype.len = function () {
  4655. return Math.sqrt(this.x * this.x + this.y * this.y);
  4656. };
  4657. Point.prototype.lenSquare = function () {
  4658. return this.x * this.x + this.y * this.y;
  4659. };
  4660. Point.prototype.normalize = function () {
  4661. var len = this.len();
  4662. this.x /= len;
  4663. this.y /= len;
  4664. return this;
  4665. };
  4666. Point.prototype.distance = function (other) {
  4667. var dx = this.x - other.x;
  4668. var dy = this.y - other.y;
  4669. return Math.sqrt(dx * dx + dy * dy);
  4670. };
  4671. Point.prototype.distanceSquare = function (other) {
  4672. var dx = this.x - other.x;
  4673. var dy = this.y - other.y;
  4674. return dx * dx + dy * dy;
  4675. };
  4676. Point.prototype.negate = function () {
  4677. this.x = -this.x;
  4678. this.y = -this.y;
  4679. return this;
  4680. };
  4681. Point.prototype.transform = function (m) {
  4682. if (!m) {
  4683. return;
  4684. }
  4685. var x = this.x;
  4686. var y = this.y;
  4687. this.x = m[0] * x + m[2] * y + m[4];
  4688. this.y = m[1] * x + m[3] * y + m[5];
  4689. return this;
  4690. };
  4691. Point.prototype.toArray = function (out) {
  4692. out[0] = this.x;
  4693. out[1] = this.y;
  4694. return out;
  4695. };
  4696. Point.prototype.fromArray = function (input) {
  4697. this.x = input[0];
  4698. this.y = input[1];
  4699. };
  4700. Point.set = function (p, x, y) {
  4701. p.x = x;
  4702. p.y = y;
  4703. };
  4704. Point.copy = function (p, p2) {
  4705. p.x = p2.x;
  4706. p.y = p2.y;
  4707. };
  4708. Point.len = function (p) {
  4709. return Math.sqrt(p.x * p.x + p.y * p.y);
  4710. };
  4711. Point.lenSquare = function (p) {
  4712. return p.x * p.x + p.y * p.y;
  4713. };
  4714. Point.dot = function (p0, p1) {
  4715. return p0.x * p1.x + p0.y * p1.y;
  4716. };
  4717. Point.add = function (out, p0, p1) {
  4718. out.x = p0.x + p1.x;
  4719. out.y = p0.y + p1.y;
  4720. };
  4721. Point.sub = function (out, p0, p1) {
  4722. out.x = p0.x - p1.x;
  4723. out.y = p0.y - p1.y;
  4724. };
  4725. Point.scale = function (out, p0, scalar) {
  4726. out.x = p0.x * scalar;
  4727. out.y = p0.y * scalar;
  4728. };
  4729. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  4730. out.x = p0.x + p1.x * scalar;
  4731. out.y = p0.y + p1.y * scalar;
  4732. };
  4733. Point.lerp = function (out, p0, p1, t) {
  4734. var onet = 1 - t;
  4735. out.x = onet * p0.x + t * p1.x;
  4736. out.y = onet * p0.y + t * p1.y;
  4737. };
  4738. return Point;
  4739. }());
  4740. var mathMin = Math.min;
  4741. var mathMax = Math.max;
  4742. var lt = new Point();
  4743. var rb = new Point();
  4744. var lb = new Point();
  4745. var rt = new Point();
  4746. var minTv = new Point();
  4747. var maxTv = new Point();
  4748. var BoundingRect = (function () {
  4749. function BoundingRect(x, y, width, height) {
  4750. if (width < 0) {
  4751. x = x + width;
  4752. width = -width;
  4753. }
  4754. if (height < 0) {
  4755. y = y + height;
  4756. height = -height;
  4757. }
  4758. this.x = x;
  4759. this.y = y;
  4760. this.width = width;
  4761. this.height = height;
  4762. }
  4763. BoundingRect.prototype.union = function (other) {
  4764. var x = mathMin(other.x, this.x);
  4765. var y = mathMin(other.y, this.y);
  4766. if (isFinite(this.x) && isFinite(this.width)) {
  4767. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  4768. }
  4769. else {
  4770. this.width = other.width;
  4771. }
  4772. if (isFinite(this.y) && isFinite(this.height)) {
  4773. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  4774. }
  4775. else {
  4776. this.height = other.height;
  4777. }
  4778. this.x = x;
  4779. this.y = y;
  4780. };
  4781. BoundingRect.prototype.applyTransform = function (m) {
  4782. BoundingRect.applyTransform(this, this, m);
  4783. };
  4784. BoundingRect.prototype.calculateTransform = function (b) {
  4785. var a = this;
  4786. var sx = b.width / a.width;
  4787. var sy = b.height / a.height;
  4788. var m = create$1();
  4789. translate(m, m, [-a.x, -a.y]);
  4790. scale$1(m, m, [sx, sy]);
  4791. translate(m, m, [b.x, b.y]);
  4792. return m;
  4793. };
  4794. BoundingRect.prototype.intersect = function (b, mtv) {
  4795. if (!b) {
  4796. return false;
  4797. }
  4798. if (!(b instanceof BoundingRect)) {
  4799. b = BoundingRect.create(b);
  4800. }
  4801. var a = this;
  4802. var ax0 = a.x;
  4803. var ax1 = a.x + a.width;
  4804. var ay0 = a.y;
  4805. var ay1 = a.y + a.height;
  4806. var bx0 = b.x;
  4807. var bx1 = b.x + b.width;
  4808. var by0 = b.y;
  4809. var by1 = b.y + b.height;
  4810. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4811. if (mtv) {
  4812. var dMin = Infinity;
  4813. var dMax = 0;
  4814. var d0 = Math.abs(ax1 - bx0);
  4815. var d1 = Math.abs(bx1 - ax0);
  4816. var d2 = Math.abs(ay1 - by0);
  4817. var d3 = Math.abs(by1 - ay0);
  4818. var dx = Math.min(d0, d1);
  4819. var dy = Math.min(d2, d3);
  4820. if (ax1 < bx0 || bx1 < ax0) {
  4821. if (dx > dMax) {
  4822. dMax = dx;
  4823. if (d0 < d1) {
  4824. Point.set(maxTv, -d0, 0);
  4825. }
  4826. else {
  4827. Point.set(maxTv, d1, 0);
  4828. }
  4829. }
  4830. }
  4831. else {
  4832. if (dx < dMin) {
  4833. dMin = dx;
  4834. if (d0 < d1) {
  4835. Point.set(minTv, d0, 0);
  4836. }
  4837. else {
  4838. Point.set(minTv, -d1, 0);
  4839. }
  4840. }
  4841. }
  4842. if (ay1 < by0 || by1 < ay0) {
  4843. if (dy > dMax) {
  4844. dMax = dy;
  4845. if (d2 < d3) {
  4846. Point.set(maxTv, 0, -d2);
  4847. }
  4848. else {
  4849. Point.set(maxTv, 0, d3);
  4850. }
  4851. }
  4852. }
  4853. else {
  4854. if (dx < dMin) {
  4855. dMin = dx;
  4856. if (d2 < d3) {
  4857. Point.set(minTv, 0, d2);
  4858. }
  4859. else {
  4860. Point.set(minTv, 0, -d3);
  4861. }
  4862. }
  4863. }
  4864. }
  4865. if (mtv) {
  4866. Point.copy(mtv, overlap ? minTv : maxTv);
  4867. }
  4868. return overlap;
  4869. };
  4870. BoundingRect.prototype.contain = function (x, y) {
  4871. var rect = this;
  4872. return x >= rect.x
  4873. && x <= (rect.x + rect.width)
  4874. && y >= rect.y
  4875. && y <= (rect.y + rect.height);
  4876. };
  4877. BoundingRect.prototype.clone = function () {
  4878. return new BoundingRect(this.x, this.y, this.width, this.height);
  4879. };
  4880. BoundingRect.prototype.copy = function (other) {
  4881. BoundingRect.copy(this, other);
  4882. };
  4883. BoundingRect.prototype.plain = function () {
  4884. return {
  4885. x: this.x,
  4886. y: this.y,
  4887. width: this.width,
  4888. height: this.height
  4889. };
  4890. };
  4891. BoundingRect.prototype.isFinite = function () {
  4892. return isFinite(this.x)
  4893. && isFinite(this.y)
  4894. && isFinite(this.width)
  4895. && isFinite(this.height);
  4896. };
  4897. BoundingRect.prototype.isZero = function () {
  4898. return this.width === 0 || this.height === 0;
  4899. };
  4900. BoundingRect.create = function (rect) {
  4901. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4902. };
  4903. BoundingRect.copy = function (target, source) {
  4904. target.x = source.x;
  4905. target.y = source.y;
  4906. target.width = source.width;
  4907. target.height = source.height;
  4908. };
  4909. BoundingRect.applyTransform = function (target, source, m) {
  4910. if (!m) {
  4911. if (target !== source) {
  4912. BoundingRect.copy(target, source);
  4913. }
  4914. return;
  4915. }
  4916. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  4917. var sx = m[0];
  4918. var sy = m[3];
  4919. var tx = m[4];
  4920. var ty = m[5];
  4921. target.x = source.x * sx + tx;
  4922. target.y = source.y * sy + ty;
  4923. target.width = source.width * sx;
  4924. target.height = source.height * sy;
  4925. if (target.width < 0) {
  4926. target.x += target.width;
  4927. target.width = -target.width;
  4928. }
  4929. if (target.height < 0) {
  4930. target.y += target.height;
  4931. target.height = -target.height;
  4932. }
  4933. return;
  4934. }
  4935. lt.x = lb.x = source.x;
  4936. lt.y = rt.y = source.y;
  4937. rb.x = rt.x = source.x + source.width;
  4938. rb.y = lb.y = source.y + source.height;
  4939. lt.transform(m);
  4940. rt.transform(m);
  4941. rb.transform(m);
  4942. lb.transform(m);
  4943. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  4944. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  4945. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  4946. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  4947. target.width = maxX - target.x;
  4948. target.height = maxY - target.y;
  4949. };
  4950. return BoundingRect;
  4951. }());
  4952. var textWidthCache = {};
  4953. var DEFAULT_FONT = '12px sans-serif';
  4954. var _ctx;
  4955. var _cachedFont;
  4956. function defaultMeasureText(text, font) {
  4957. if (!_ctx) {
  4958. _ctx = createCanvas().getContext('2d');
  4959. }
  4960. if (_cachedFont !== font) {
  4961. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  4962. }
  4963. return _ctx.measureText(text);
  4964. }
  4965. var methods$1 = {
  4966. measureText: defaultMeasureText
  4967. };
  4968. function getWidth(text, font) {
  4969. font = font || DEFAULT_FONT;
  4970. var cacheOfFont = textWidthCache[font];
  4971. if (!cacheOfFont) {
  4972. cacheOfFont = textWidthCache[font] = new LRU(500);
  4973. }
  4974. var width = cacheOfFont.get(text);
  4975. if (width == null) {
  4976. width = methods$1.measureText(text, font).width;
  4977. cacheOfFont.put(text, width);
  4978. }
  4979. return width;
  4980. }
  4981. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  4982. var width = getWidth(text, font);
  4983. var height = getLineHeight(font);
  4984. var x = adjustTextX(0, width, textAlign);
  4985. var y = adjustTextY(0, height, textBaseline);
  4986. var rect = new BoundingRect(x, y, width, height);
  4987. return rect;
  4988. }
  4989. function getBoundingRect(text, font, textAlign, textBaseline) {
  4990. var textLines = ((text || '') + '').split('\n');
  4991. var len = textLines.length;
  4992. if (len === 1) {
  4993. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  4994. }
  4995. else {
  4996. var uniondRect = new BoundingRect(0, 0, 0, 0);
  4997. for (var i = 0; i < textLines.length; i++) {
  4998. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  4999. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5000. }
  5001. return uniondRect;
  5002. }
  5003. }
  5004. function adjustTextX(x, width, textAlign) {
  5005. if (textAlign === 'right') {
  5006. x -= width;
  5007. }
  5008. else if (textAlign === 'center') {
  5009. x -= width / 2;
  5010. }
  5011. return x;
  5012. }
  5013. function adjustTextY(y, height, verticalAlign) {
  5014. if (verticalAlign === 'middle') {
  5015. y -= height / 2;
  5016. }
  5017. else if (verticalAlign === 'bottom') {
  5018. y -= height;
  5019. }
  5020. return y;
  5021. }
  5022. function getLineHeight(font) {
  5023. return getWidth('国', font);
  5024. }
  5025. function parsePercent(value, maxValue) {
  5026. if (typeof value === 'string') {
  5027. if (value.lastIndexOf('%') >= 0) {
  5028. return parseFloat(value) / 100 * maxValue;
  5029. }
  5030. return parseFloat(value);
  5031. }
  5032. return value;
  5033. }
  5034. function calculateTextPosition(out, opts, rect) {
  5035. var textPosition = opts.position || 'inside';
  5036. var distance = opts.distance != null ? opts.distance : 5;
  5037. var height = rect.height;
  5038. var width = rect.width;
  5039. var halfHeight = height / 2;
  5040. var x = rect.x;
  5041. var y = rect.y;
  5042. var textAlign = 'left';
  5043. var textVerticalAlign = 'top';
  5044. if (textPosition instanceof Array) {
  5045. x += parsePercent(textPosition[0], rect.width);
  5046. y += parsePercent(textPosition[1], rect.height);
  5047. textAlign = null;
  5048. textVerticalAlign = null;
  5049. }
  5050. else {
  5051. switch (textPosition) {
  5052. case 'left':
  5053. x -= distance;
  5054. y += halfHeight;
  5055. textAlign = 'right';
  5056. textVerticalAlign = 'middle';
  5057. break;
  5058. case 'right':
  5059. x += distance + width;
  5060. y += halfHeight;
  5061. textVerticalAlign = 'middle';
  5062. break;
  5063. case 'top':
  5064. x += width / 2;
  5065. y -= distance;
  5066. textAlign = 'center';
  5067. textVerticalAlign = 'bottom';
  5068. break;
  5069. case 'bottom':
  5070. x += width / 2;
  5071. y += height + distance;
  5072. textAlign = 'center';
  5073. break;
  5074. case 'inside':
  5075. x += width / 2;
  5076. y += halfHeight;
  5077. textAlign = 'center';
  5078. textVerticalAlign = 'middle';
  5079. break;
  5080. case 'insideLeft':
  5081. x += distance;
  5082. y += halfHeight;
  5083. textVerticalAlign = 'middle';
  5084. break;
  5085. case 'insideRight':
  5086. x += width - distance;
  5087. y += halfHeight;
  5088. textAlign = 'right';
  5089. textVerticalAlign = 'middle';
  5090. break;
  5091. case 'insideTop':
  5092. x += width / 2;
  5093. y += distance;
  5094. textAlign = 'center';
  5095. break;
  5096. case 'insideBottom':
  5097. x += width / 2;
  5098. y += height - distance;
  5099. textAlign = 'center';
  5100. textVerticalAlign = 'bottom';
  5101. break;
  5102. case 'insideTopLeft':
  5103. x += distance;
  5104. y += distance;
  5105. break;
  5106. case 'insideTopRight':
  5107. x += width - distance;
  5108. y += distance;
  5109. textAlign = 'right';
  5110. break;
  5111. case 'insideBottomLeft':
  5112. x += distance;
  5113. y += height - distance;
  5114. textVerticalAlign = 'bottom';
  5115. break;
  5116. case 'insideBottomRight':
  5117. x += width - distance;
  5118. y += height - distance;
  5119. textAlign = 'right';
  5120. textVerticalAlign = 'bottom';
  5121. break;
  5122. }
  5123. }
  5124. out = out || {};
  5125. out.x = x;
  5126. out.y = y;
  5127. out.align = textAlign;
  5128. out.verticalAlign = textVerticalAlign;
  5129. return out;
  5130. }
  5131. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5132. var PRIMARY_STATES_KEYS = ['x', 'y', 'scaleX', 'scaleY', 'originX', 'originY', 'rotation', 'ignore'];
  5133. var DEFAULT_ANIMATABLE_MAP = {
  5134. x: true,
  5135. y: true,
  5136. scaleX: true,
  5137. scaleY: true,
  5138. originX: true,
  5139. originY: true,
  5140. rotation: true,
  5141. ignore: false
  5142. };
  5143. var tmpTextPosCalcRes = {};
  5144. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5145. var Element = (function () {
  5146. function Element(props) {
  5147. this.id = guid();
  5148. this.animators = [];
  5149. this.currentStates = [];
  5150. this.states = {};
  5151. this._init(props);
  5152. }
  5153. Element.prototype._init = function (props) {
  5154. this.attr(props);
  5155. };
  5156. Element.prototype.drift = function (dx, dy, e) {
  5157. switch (this.draggable) {
  5158. case 'horizontal':
  5159. dy = 0;
  5160. break;
  5161. case 'vertical':
  5162. dx = 0;
  5163. break;
  5164. }
  5165. var m = this.transform;
  5166. if (!m) {
  5167. m = this.transform = [1, 0, 0, 1, 0, 0];
  5168. }
  5169. m[4] += dx;
  5170. m[5] += dy;
  5171. this.decomposeTransform();
  5172. this.markRedraw();
  5173. };
  5174. Element.prototype.beforeUpdate = function () { };
  5175. Element.prototype.afterUpdate = function () { };
  5176. Element.prototype.update = function () {
  5177. this.updateTransform();
  5178. if (this.__dirty) {
  5179. this.updateInnerText();
  5180. }
  5181. };
  5182. Element.prototype.updateInnerText = function (forceUpdate) {
  5183. var textEl = this._textContent;
  5184. if (textEl && (!textEl.ignore || forceUpdate)) {
  5185. if (!this.textConfig) {
  5186. this.textConfig = {};
  5187. }
  5188. var textConfig = this.textConfig;
  5189. var isLocal = textConfig.local;
  5190. var innerTransformable = textEl.innerTransformable;
  5191. var textAlign = void 0;
  5192. var textVerticalAlign = void 0;
  5193. var textStyleChanged = false;
  5194. innerTransformable.parent = isLocal ? this : null;
  5195. var innerOrigin = false;
  5196. innerTransformable.copyTransform(textEl);
  5197. if (textConfig.position != null) {
  5198. var layoutRect = tmpBoundingRect;
  5199. if (textConfig.layoutRect) {
  5200. layoutRect.copy(textConfig.layoutRect);
  5201. }
  5202. else {
  5203. layoutRect.copy(this.getBoundingRect());
  5204. }
  5205. if (!isLocal) {
  5206. layoutRect.applyTransform(this.transform);
  5207. }
  5208. if (this.calculateTextPosition) {
  5209. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5210. }
  5211. else {
  5212. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5213. }
  5214. innerTransformable.x = tmpTextPosCalcRes.x;
  5215. innerTransformable.y = tmpTextPosCalcRes.y;
  5216. textAlign = tmpTextPosCalcRes.align;
  5217. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5218. var textOrigin = textConfig.origin;
  5219. if (textOrigin && textConfig.rotation != null) {
  5220. var relOriginX = void 0;
  5221. var relOriginY = void 0;
  5222. if (textOrigin === 'center') {
  5223. relOriginX = layoutRect.width * 0.5;
  5224. relOriginY = layoutRect.height * 0.5;
  5225. }
  5226. else {
  5227. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5228. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5229. }
  5230. innerOrigin = true;
  5231. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5232. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5233. }
  5234. }
  5235. if (textConfig.rotation != null) {
  5236. innerTransformable.rotation = textConfig.rotation;
  5237. }
  5238. var textOffset = textConfig.offset;
  5239. if (textOffset) {
  5240. innerTransformable.x += textOffset[0];
  5241. innerTransformable.y += textOffset[1];
  5242. if (!innerOrigin) {
  5243. innerTransformable.originX = -textOffset[0];
  5244. innerTransformable.originY = -textOffset[1];
  5245. }
  5246. }
  5247. var isInside = textConfig.inside == null
  5248. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5249. : textConfig.inside;
  5250. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5251. var textFill = void 0;
  5252. var textStroke = void 0;
  5253. var autoStroke = void 0;
  5254. if (isInside && this.canBeInsideText()) {
  5255. textFill = textConfig.insideFill;
  5256. textStroke = textConfig.insideStroke;
  5257. if (textFill == null || textFill === 'auto') {
  5258. textFill = this.getInsideTextFill();
  5259. }
  5260. if (textStroke == null || textStroke === 'auto') {
  5261. textStroke = this.getInsideTextStroke(textFill);
  5262. autoStroke = true;
  5263. }
  5264. }
  5265. else {
  5266. textFill = textConfig.outsideFill;
  5267. textStroke = textConfig.outsideStroke;
  5268. if (textFill == null || textFill === 'auto') {
  5269. textFill = this.getOutsideFill();
  5270. }
  5271. if (textStroke == null || textStroke === 'auto') {
  5272. textStroke = this.getOutsideStroke(textFill);
  5273. autoStroke = true;
  5274. }
  5275. }
  5276. textFill = textFill || '#000';
  5277. if (textFill !== innerTextDefaultStyle.fill
  5278. || textStroke !== innerTextDefaultStyle.stroke
  5279. || autoStroke !== innerTextDefaultStyle.autoStroke
  5280. || textAlign !== innerTextDefaultStyle.align
  5281. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5282. textStyleChanged = true;
  5283. innerTextDefaultStyle.fill = textFill;
  5284. innerTextDefaultStyle.stroke = textStroke;
  5285. innerTextDefaultStyle.autoStroke = autoStroke;
  5286. innerTextDefaultStyle.align = textAlign;
  5287. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5288. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5289. }
  5290. textEl.__dirty |= REDRAW_BIT;
  5291. if (textStyleChanged) {
  5292. textEl.dirtyStyle(true);
  5293. }
  5294. }
  5295. };
  5296. Element.prototype.canBeInsideText = function () {
  5297. return true;
  5298. };
  5299. Element.prototype.getInsideTextFill = function () {
  5300. return '#fff';
  5301. };
  5302. Element.prototype.getInsideTextStroke = function (textFill) {
  5303. return '#000';
  5304. };
  5305. Element.prototype.getOutsideFill = function () {
  5306. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5307. };
  5308. Element.prototype.getOutsideStroke = function (textFill) {
  5309. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5310. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5311. if (!colorArr) {
  5312. colorArr = [255, 255, 255, 1];
  5313. }
  5314. var alpha = colorArr[3];
  5315. var isDark = this.__zr.isDarkMode();
  5316. for (var i = 0; i < 3; i++) {
  5317. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5318. }
  5319. colorArr[3] = 1;
  5320. return stringify(colorArr, 'rgba');
  5321. };
  5322. Element.prototype.traverse = function (cb, context) { };
  5323. Element.prototype.attrKV = function (key, value) {
  5324. if (key === 'textConfig') {
  5325. this.setTextConfig(value);
  5326. }
  5327. else if (key === 'textContent') {
  5328. this.setTextContent(value);
  5329. }
  5330. else if (key === 'clipPath') {
  5331. this.setClipPath(value);
  5332. }
  5333. else if (key === 'extra') {
  5334. this.extra = this.extra || {};
  5335. extend(this.extra, value);
  5336. }
  5337. else {
  5338. this[key] = value;
  5339. }
  5340. };
  5341. Element.prototype.hide = function () {
  5342. this.ignore = true;
  5343. this.markRedraw();
  5344. };
  5345. Element.prototype.show = function () {
  5346. this.ignore = false;
  5347. this.markRedraw();
  5348. };
  5349. Element.prototype.attr = function (keyOrObj, value) {
  5350. if (typeof keyOrObj === 'string') {
  5351. this.attrKV(keyOrObj, value);
  5352. }
  5353. else if (isObject(keyOrObj)) {
  5354. var obj = keyOrObj;
  5355. var keysArr = keys(obj);
  5356. for (var i = 0; i < keysArr.length; i++) {
  5357. var key = keysArr[i];
  5358. this.attrKV(key, keyOrObj[key]);
  5359. }
  5360. }
  5361. this.markRedraw();
  5362. return this;
  5363. };
  5364. Element.prototype.saveCurrentToNormalState = function (toState) {
  5365. this._innerSaveToNormal(toState);
  5366. var normalState = this._normalState;
  5367. for (var i = 0; i < this.animators.length; i++) {
  5368. var animator = this.animators[i];
  5369. var fromStateTransition = animator.__fromStateTransition;
  5370. if (fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  5371. continue;
  5372. }
  5373. var targetName = animator.targetName;
  5374. var target = targetName
  5375. ? normalState[targetName] : normalState;
  5376. animator.saveFinalToTarget(target);
  5377. }
  5378. };
  5379. Element.prototype._innerSaveToNormal = function (toState) {
  5380. var normalState = this._normalState;
  5381. if (!normalState) {
  5382. normalState = this._normalState = {};
  5383. }
  5384. if (toState.textConfig && !normalState.textConfig) {
  5385. normalState.textConfig = this.textConfig;
  5386. }
  5387. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  5388. };
  5389. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  5390. for (var i = 0; i < primaryKeys.length; i++) {
  5391. var key = primaryKeys[i];
  5392. if (toState[key] != null && !(key in normalState)) {
  5393. normalState[key] = this[key];
  5394. }
  5395. }
  5396. };
  5397. Element.prototype.hasState = function () {
  5398. return this.currentStates.length > 0;
  5399. };
  5400. Element.prototype.getState = function (name) {
  5401. return this.states[name];
  5402. };
  5403. Element.prototype.ensureState = function (name) {
  5404. var states = this.states;
  5405. if (!states[name]) {
  5406. states[name] = {};
  5407. }
  5408. return states[name];
  5409. };
  5410. Element.prototype.clearStates = function (noAnimation) {
  5411. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  5412. };
  5413. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  5414. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  5415. var hasStates = this.hasState();
  5416. if (!hasStates && toNormalState) {
  5417. return;
  5418. }
  5419. var currentStates = this.currentStates;
  5420. var animationCfg = this.stateTransition;
  5421. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  5422. return;
  5423. }
  5424. var state;
  5425. if (this.stateProxy && !toNormalState) {
  5426. state = this.stateProxy(stateName);
  5427. }
  5428. if (!state) {
  5429. state = (this.states && this.states[stateName]);
  5430. }
  5431. if (!state && !toNormalState) {
  5432. logError("State " + stateName + " not exists.");
  5433. return;
  5434. }
  5435. if (!toNormalState) {
  5436. this.saveCurrentToNormalState(state);
  5437. }
  5438. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  5439. if (useHoverLayer) {
  5440. this._toggleHoverLayerFlag(true);
  5441. }
  5442. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  5443. var textContent = this._textContent;
  5444. var textGuide = this._textGuide;
  5445. if (textContent) {
  5446. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  5447. }
  5448. if (textGuide) {
  5449. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  5450. }
  5451. if (toNormalState) {
  5452. this.currentStates = [];
  5453. this._normalState = {};
  5454. }
  5455. else {
  5456. if (!keepCurrentStates) {
  5457. this.currentStates = [stateName];
  5458. }
  5459. else {
  5460. this.currentStates.push(stateName);
  5461. }
  5462. }
  5463. this._updateAnimationTargets();
  5464. this.markRedraw();
  5465. if (!useHoverLayer && this.__inHover) {
  5466. this._toggleHoverLayerFlag(false);
  5467. this.__dirty &= ~REDRAW_BIT;
  5468. }
  5469. return state;
  5470. };
  5471. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  5472. if (!states.length) {
  5473. this.clearStates();
  5474. }
  5475. else {
  5476. var stateObjects = [];
  5477. var currentStates = this.currentStates;
  5478. var len = states.length;
  5479. var notChange = len === currentStates.length;
  5480. if (notChange) {
  5481. for (var i = 0; i < len; i++) {
  5482. if (states[i] !== currentStates[i]) {
  5483. notChange = false;
  5484. break;
  5485. }
  5486. }
  5487. }
  5488. if (notChange) {
  5489. return;
  5490. }
  5491. for (var i = 0; i < len; i++) {
  5492. var stateName = states[i];
  5493. var stateObj = void 0;
  5494. if (this.stateProxy) {
  5495. stateObj = this.stateProxy(stateName, states);
  5496. }
  5497. if (!stateObj) {
  5498. stateObj = this.states[stateName];
  5499. }
  5500. if (stateObj) {
  5501. stateObjects.push(stateObj);
  5502. }
  5503. }
  5504. var lastStateObj = stateObjects[len - 1];
  5505. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  5506. if (useHoverLayer) {
  5507. this._toggleHoverLayerFlag(true);
  5508. }
  5509. var mergedState = this._mergeStates(stateObjects);
  5510. var animationCfg = this.stateTransition;
  5511. this.saveCurrentToNormalState(mergedState);
  5512. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  5513. var textContent = this._textContent;
  5514. var textGuide = this._textGuide;
  5515. if (textContent) {
  5516. textContent.useStates(states, noAnimation, useHoverLayer);
  5517. }
  5518. if (textGuide) {
  5519. textGuide.useStates(states, noAnimation, useHoverLayer);
  5520. }
  5521. this._updateAnimationTargets();
  5522. this.currentStates = states.slice();
  5523. this.markRedraw();
  5524. if (!useHoverLayer && this.__inHover) {
  5525. this._toggleHoverLayerFlag(false);
  5526. this.__dirty &= ~REDRAW_BIT;
  5527. }
  5528. }
  5529. };
  5530. Element.prototype._updateAnimationTargets = function () {
  5531. for (var i = 0; i < this.animators.length; i++) {
  5532. var animator = this.animators[i];
  5533. if (animator.targetName) {
  5534. animator.changeTarget(this[animator.targetName]);
  5535. }
  5536. }
  5537. };
  5538. Element.prototype.removeState = function (state) {
  5539. var idx = indexOf(this.currentStates, state);
  5540. if (idx >= 0) {
  5541. var currentStates = this.currentStates.slice();
  5542. currentStates.splice(idx, 1);
  5543. this.useStates(currentStates);
  5544. }
  5545. };
  5546. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  5547. var currentStates = this.currentStates.slice();
  5548. var idx = indexOf(currentStates, oldState);
  5549. var newStateExists = indexOf(currentStates, newState) >= 0;
  5550. if (idx >= 0) {
  5551. if (!newStateExists) {
  5552. currentStates[idx] = newState;
  5553. }
  5554. else {
  5555. currentStates.splice(idx, 1);
  5556. }
  5557. }
  5558. else if (forceAdd && !newStateExists) {
  5559. currentStates.push(newState);
  5560. }
  5561. this.useStates(currentStates);
  5562. };
  5563. Element.prototype.toggleState = function (state, enable) {
  5564. if (enable) {
  5565. this.useState(state, true);
  5566. }
  5567. else {
  5568. this.removeState(state);
  5569. }
  5570. };
  5571. Element.prototype._mergeStates = function (states) {
  5572. var mergedState = {};
  5573. var mergedTextConfig;
  5574. for (var i = 0; i < states.length; i++) {
  5575. var state = states[i];
  5576. extend(mergedState, state);
  5577. if (state.textConfig) {
  5578. mergedTextConfig = mergedTextConfig || {};
  5579. extend(mergedTextConfig, state.textConfig);
  5580. }
  5581. }
  5582. if (mergedTextConfig) {
  5583. mergedState.textConfig = mergedTextConfig;
  5584. }
  5585. return mergedState;
  5586. };
  5587. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  5588. var needsRestoreToNormal = !(state && keepCurrentStates);
  5589. if (state && state.textConfig) {
  5590. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  5591. extend(this.textConfig, state.textConfig);
  5592. }
  5593. else if (needsRestoreToNormal) {
  5594. if (normalState.textConfig) {
  5595. this.textConfig = normalState.textConfig;
  5596. }
  5597. }
  5598. var transitionTarget = {};
  5599. var hasTransition = false;
  5600. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  5601. var key = PRIMARY_STATES_KEYS[i];
  5602. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  5603. if (state && state[key] != null) {
  5604. if (propNeedsTransition) {
  5605. hasTransition = true;
  5606. transitionTarget[key] = state[key];
  5607. }
  5608. else {
  5609. this[key] = state[key];
  5610. }
  5611. }
  5612. else if (needsRestoreToNormal) {
  5613. if (normalState[key] != null) {
  5614. if (propNeedsTransition) {
  5615. hasTransition = true;
  5616. transitionTarget[key] = normalState[key];
  5617. }
  5618. else {
  5619. this[key] = normalState[key];
  5620. }
  5621. }
  5622. }
  5623. }
  5624. if (!transition) {
  5625. for (var i = 0; i < this.animators.length; i++) {
  5626. var animator = this.animators[i];
  5627. var targetName = animator.targetName;
  5628. animator.__changeFinalValue(targetName
  5629. ? (state || normalState)[targetName]
  5630. : (state || normalState));
  5631. }
  5632. }
  5633. if (hasTransition) {
  5634. this._transitionState(stateName, transitionTarget, animationCfg);
  5635. }
  5636. };
  5637. Element.prototype._attachComponent = function (componentEl) {
  5638. if (componentEl.__zr && !componentEl.__hostTarget) {
  5639. throw new Error('Text element has been added to zrender.');
  5640. }
  5641. if (componentEl === this) {
  5642. throw new Error('Recursive component attachment.');
  5643. }
  5644. var zr = this.__zr;
  5645. if (zr) {
  5646. componentEl.addSelfToZr(zr);
  5647. }
  5648. componentEl.__zr = zr;
  5649. componentEl.__hostTarget = this;
  5650. };
  5651. Element.prototype._detachComponent = function (componentEl) {
  5652. if (componentEl.__zr) {
  5653. componentEl.removeSelfFromZr(componentEl.__zr);
  5654. }
  5655. componentEl.__zr = null;
  5656. componentEl.__hostTarget = null;
  5657. };
  5658. Element.prototype.getClipPath = function () {
  5659. return this._clipPath;
  5660. };
  5661. Element.prototype.setClipPath = function (clipPath) {
  5662. if (this._clipPath && this._clipPath !== clipPath) {
  5663. this.removeClipPath();
  5664. }
  5665. this._attachComponent(clipPath);
  5666. this._clipPath = clipPath;
  5667. this.markRedraw();
  5668. };
  5669. Element.prototype.removeClipPath = function () {
  5670. var clipPath = this._clipPath;
  5671. if (clipPath) {
  5672. this._detachComponent(clipPath);
  5673. this._clipPath = null;
  5674. this.markRedraw();
  5675. }
  5676. };
  5677. Element.prototype.getTextContent = function () {
  5678. return this._textContent;
  5679. };
  5680. Element.prototype.setTextContent = function (textEl) {
  5681. var previousTextContent = this._textContent;
  5682. if (previousTextContent === textEl) {
  5683. return;
  5684. }
  5685. if (previousTextContent && previousTextContent !== textEl) {
  5686. this.removeTextContent();
  5687. }
  5688. if (textEl.__zr && !textEl.__hostTarget) {
  5689. throw new Error('Text element has been added to zrender.');
  5690. }
  5691. textEl.innerTransformable = new Transformable();
  5692. this._attachComponent(textEl);
  5693. this._textContent = textEl;
  5694. this.markRedraw();
  5695. };
  5696. Element.prototype.setTextConfig = function (cfg) {
  5697. if (!this.textConfig) {
  5698. this.textConfig = {};
  5699. }
  5700. extend(this.textConfig, cfg);
  5701. this.markRedraw();
  5702. };
  5703. Element.prototype.removeTextConfig = function () {
  5704. this.textConfig = null;
  5705. this.markRedraw();
  5706. };
  5707. Element.prototype.removeTextContent = function () {
  5708. var textEl = this._textContent;
  5709. if (textEl) {
  5710. textEl.innerTransformable = null;
  5711. this._detachComponent(textEl);
  5712. this._textContent = null;
  5713. this._innerTextDefaultStyle = null;
  5714. this.markRedraw();
  5715. }
  5716. };
  5717. Element.prototype.getTextGuideLine = function () {
  5718. return this._textGuide;
  5719. };
  5720. Element.prototype.setTextGuideLine = function (guideLine) {
  5721. if (this._textGuide && this._textGuide !== guideLine) {
  5722. this.removeTextGuideLine();
  5723. }
  5724. this._attachComponent(guideLine);
  5725. this._textGuide = guideLine;
  5726. this.markRedraw();
  5727. };
  5728. Element.prototype.removeTextGuideLine = function () {
  5729. var textGuide = this._textGuide;
  5730. if (textGuide) {
  5731. this._detachComponent(textGuide);
  5732. this._textGuide = null;
  5733. this.markRedraw();
  5734. }
  5735. };
  5736. Element.prototype.markRedraw = function () {
  5737. this.__dirty |= REDRAW_BIT;
  5738. var zr = this.__zr;
  5739. if (zr) {
  5740. if (this.__inHover) {
  5741. zr.refreshHover();
  5742. }
  5743. else {
  5744. zr.refresh();
  5745. }
  5746. }
  5747. if (this.__hostTarget) {
  5748. this.__hostTarget.markRedraw();
  5749. }
  5750. };
  5751. Element.prototype.dirty = function () {
  5752. this.markRedraw();
  5753. };
  5754. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  5755. this.__inHover = inHover;
  5756. var textContent = this._textContent;
  5757. var textGuide = this._textGuide;
  5758. if (textContent) {
  5759. textContent.__inHover = inHover;
  5760. }
  5761. if (textGuide) {
  5762. textGuide.__inHover = inHover;
  5763. }
  5764. };
  5765. Element.prototype.addSelfToZr = function (zr) {
  5766. if (this.__zr === zr) {
  5767. return;
  5768. }
  5769. this.__zr = zr;
  5770. var animators = this.animators;
  5771. if (animators) {
  5772. for (var i = 0; i < animators.length; i++) {
  5773. zr.animation.addAnimator(animators[i]);
  5774. }
  5775. }
  5776. if (this._clipPath) {
  5777. this._clipPath.addSelfToZr(zr);
  5778. }
  5779. if (this._textContent) {
  5780. this._textContent.addSelfToZr(zr);
  5781. }
  5782. if (this._textGuide) {
  5783. this._textGuide.addSelfToZr(zr);
  5784. }
  5785. };
  5786. Element.prototype.removeSelfFromZr = function (zr) {
  5787. if (!this.__zr) {
  5788. return;
  5789. }
  5790. this.__zr = null;
  5791. var animators = this.animators;
  5792. if (animators) {
  5793. for (var i = 0; i < animators.length; i++) {
  5794. zr.animation.removeAnimator(animators[i]);
  5795. }
  5796. }
  5797. if (this._clipPath) {
  5798. this._clipPath.removeSelfFromZr(zr);
  5799. }
  5800. if (this._textContent) {
  5801. this._textContent.removeSelfFromZr(zr);
  5802. }
  5803. if (this._textGuide) {
  5804. this._textGuide.removeSelfFromZr(zr);
  5805. }
  5806. };
  5807. Element.prototype.animate = function (key, loop) {
  5808. var target = key ? this[key] : this;
  5809. if (!target) {
  5810. logError('Property "'
  5811. + key
  5812. + '" is not existed in element '
  5813. + this.id);
  5814. return;
  5815. }
  5816. var animator = new Animator(target, loop);
  5817. this.addAnimator(animator, key);
  5818. return animator;
  5819. };
  5820. Element.prototype.addAnimator = function (animator, key) {
  5821. var zr = this.__zr;
  5822. var el = this;
  5823. animator.during(function () {
  5824. el.updateDuringAnimation(key);
  5825. }).done(function () {
  5826. var animators = el.animators;
  5827. var idx = indexOf(animators, animator);
  5828. if (idx >= 0) {
  5829. animators.splice(idx, 1);
  5830. }
  5831. });
  5832. this.animators.push(animator);
  5833. if (zr) {
  5834. zr.animation.addAnimator(animator);
  5835. }
  5836. zr && zr.wakeUp();
  5837. };
  5838. Element.prototype.updateDuringAnimation = function (key) {
  5839. this.markRedraw();
  5840. };
  5841. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  5842. var animators = this.animators;
  5843. var len = animators.length;
  5844. var leftAnimators = [];
  5845. for (var i = 0; i < len; i++) {
  5846. var animator = animators[i];
  5847. if (!scope || scope === animator.scope) {
  5848. animator.stop(forwardToLast);
  5849. }
  5850. else {
  5851. leftAnimators.push(animator);
  5852. }
  5853. }
  5854. this.animators = leftAnimators;
  5855. return this;
  5856. };
  5857. Element.prototype.animateTo = function (target, cfg, animationProps) {
  5858. animateTo(this, target, cfg, animationProps);
  5859. };
  5860. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  5861. animateTo(this, target, cfg, animationProps, true);
  5862. };
  5863. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  5864. var animators = animateTo(this, target, cfg, animationProps);
  5865. for (var i = 0; i < animators.length; i++) {
  5866. animators[i].__fromStateTransition = stateName;
  5867. }
  5868. };
  5869. Element.prototype.getBoundingRect = function () {
  5870. return null;
  5871. };
  5872. Element.prototype.getPaintRect = function () {
  5873. return null;
  5874. };
  5875. Element.initDefaultProps = (function () {
  5876. var elProto = Element.prototype;
  5877. elProto.type = 'element';
  5878. elProto.name = '';
  5879. elProto.ignore = false;
  5880. elProto.silent = false;
  5881. elProto.isGroup = false;
  5882. elProto.draggable = false;
  5883. elProto.dragging = false;
  5884. elProto.ignoreClip = false;
  5885. elProto.__inHover = false;
  5886. elProto.__dirty = REDRAW_BIT;
  5887. var logs = {};
  5888. function logDeprecatedError(key, xKey, yKey) {
  5889. if (!logs[key + xKey + yKey]) {
  5890. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  5891. logs[key + xKey + yKey] = true;
  5892. }
  5893. }
  5894. function createLegacyProperty(key, privateKey, xKey, yKey) {
  5895. Object.defineProperty(elProto, key, {
  5896. get: function () {
  5897. logDeprecatedError(key, xKey, yKey);
  5898. if (!this[privateKey]) {
  5899. var pos = this[privateKey] = [];
  5900. enhanceArray(this, pos);
  5901. }
  5902. return this[privateKey];
  5903. },
  5904. set: function (pos) {
  5905. logDeprecatedError(key, xKey, yKey);
  5906. this[xKey] = pos[0];
  5907. this[yKey] = pos[1];
  5908. this[privateKey] = pos;
  5909. enhanceArray(this, pos);
  5910. }
  5911. });
  5912. function enhanceArray(self, pos) {
  5913. Object.defineProperty(pos, 0, {
  5914. get: function () {
  5915. return self[xKey];
  5916. },
  5917. set: function (val) {
  5918. self[xKey] = val;
  5919. }
  5920. });
  5921. Object.defineProperty(pos, 1, {
  5922. get: function () {
  5923. return self[yKey];
  5924. },
  5925. set: function (val) {
  5926. self[yKey] = val;
  5927. }
  5928. });
  5929. }
  5930. }
  5931. if (Object.defineProperty && (!env.browser.ie || env.browser.version > 8)) {
  5932. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  5933. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  5934. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  5935. }
  5936. })();
  5937. return Element;
  5938. }());
  5939. mixin(Element, Eventful);
  5940. mixin(Element, Transformable);
  5941. function animateTo(animatable, target, cfg, animationProps, reverse) {
  5942. cfg = cfg || {};
  5943. var animators = [];
  5944. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  5945. var finishCount = animators.length;
  5946. var doneHappened = false;
  5947. var cfgDone = cfg.done;
  5948. var cfgAborted = cfg.aborted;
  5949. var doneCb = function () {
  5950. doneHappened = true;
  5951. finishCount--;
  5952. if (finishCount <= 0) {
  5953. doneHappened
  5954. ? (cfgDone && cfgDone())
  5955. : (cfgAborted && cfgAborted());
  5956. }
  5957. };
  5958. var abortedCb = function () {
  5959. finishCount--;
  5960. if (finishCount <= 0) {
  5961. doneHappened
  5962. ? (cfgDone && cfgDone())
  5963. : (cfgAborted && cfgAborted());
  5964. }
  5965. };
  5966. if (!finishCount) {
  5967. cfgDone && cfgDone();
  5968. }
  5969. if (animators.length > 0 && cfg.during) {
  5970. animators[0].during(function (target, percent) {
  5971. cfg.during(percent);
  5972. });
  5973. }
  5974. for (var i = 0; i < animators.length; i++) {
  5975. var animator = animators[i];
  5976. if (doneCb) {
  5977. animator.done(doneCb);
  5978. }
  5979. if (abortedCb) {
  5980. animator.aborted(abortedCb);
  5981. }
  5982. animator.start(cfg.easing, cfg.force);
  5983. }
  5984. return animators;
  5985. }
  5986. function copyArrShallow(source, target, len) {
  5987. for (var i = 0; i < len; i++) {
  5988. source[i] = target[i];
  5989. }
  5990. }
  5991. function is2DArray(value) {
  5992. return isArrayLike(value[0]);
  5993. }
  5994. function copyValue(target, source, key) {
  5995. if (isArrayLike(source[key])) {
  5996. if (!isArrayLike(target[key])) {
  5997. target[key] = [];
  5998. }
  5999. if (isTypedArray(source[key])) {
  6000. var len = source[key].length;
  6001. if (target[key].length !== len) {
  6002. target[key] = new (source[key].constructor)(len);
  6003. copyArrShallow(target[key], source[key], len);
  6004. }
  6005. }
  6006. else {
  6007. var sourceArr = source[key];
  6008. var targetArr = target[key];
  6009. var len0 = sourceArr.length;
  6010. if (is2DArray(sourceArr)) {
  6011. var len1 = sourceArr[0].length;
  6012. for (var i = 0; i < len0; i++) {
  6013. if (!targetArr[i]) {
  6014. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6015. }
  6016. else {
  6017. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6018. }
  6019. }
  6020. }
  6021. else {
  6022. copyArrShallow(targetArr, sourceArr, len0);
  6023. }
  6024. targetArr.length = sourceArr.length;
  6025. }
  6026. }
  6027. else {
  6028. target[key] = source[key];
  6029. }
  6030. }
  6031. function animateToShallow(animatable, topKey, source, target, cfg, animationProps, animators, reverse) {
  6032. var animatableKeys = [];
  6033. var changedKeys = [];
  6034. var targetKeys = keys(target);
  6035. var duration = cfg.duration;
  6036. var delay = cfg.delay;
  6037. var additive = cfg.additive;
  6038. var setToFinal = cfg.setToFinal;
  6039. var animateAll = !isObject(animationProps);
  6040. for (var k = 0; k < targetKeys.length; k++) {
  6041. var innerKey = targetKeys[k];
  6042. if (source[innerKey] != null
  6043. && target[innerKey] != null
  6044. && (animateAll || animationProps[innerKey])) {
  6045. if (isObject(target[innerKey]) && !isArrayLike(target[innerKey])) {
  6046. if (topKey) {
  6047. if (!reverse) {
  6048. source[innerKey] = target[innerKey];
  6049. animatable.updateDuringAnimation(topKey);
  6050. }
  6051. continue;
  6052. }
  6053. animateToShallow(animatable, innerKey, source[innerKey], target[innerKey], cfg, animationProps && animationProps[innerKey], animators, reverse);
  6054. }
  6055. else {
  6056. animatableKeys.push(innerKey);
  6057. changedKeys.push(innerKey);
  6058. }
  6059. }
  6060. else if (!reverse) {
  6061. source[innerKey] = target[innerKey];
  6062. animatable.updateDuringAnimation(topKey);
  6063. changedKeys.push(innerKey);
  6064. }
  6065. }
  6066. var keyLen = animatableKeys.length;
  6067. if (keyLen > 0
  6068. || (cfg.force && !animators.length)) {
  6069. var existsAnimators = animatable.animators;
  6070. var existsAnimatorsOnSameTarget = [];
  6071. for (var i = 0; i < existsAnimators.length; i++) {
  6072. if (existsAnimators[i].targetName === topKey) {
  6073. existsAnimatorsOnSameTarget.push(existsAnimators[i]);
  6074. }
  6075. }
  6076. if (!additive && existsAnimatorsOnSameTarget.length) {
  6077. for (var i = 0; i < existsAnimatorsOnSameTarget.length; i++) {
  6078. var allAborted = existsAnimatorsOnSameTarget[i].stopTracks(changedKeys);
  6079. if (allAborted) {
  6080. var idx = indexOf(existsAnimators, existsAnimatorsOnSameTarget[i]);
  6081. existsAnimators.splice(idx, 1);
  6082. }
  6083. }
  6084. }
  6085. var revertedSource = void 0;
  6086. var reversedTarget = void 0;
  6087. var sourceClone = void 0;
  6088. if (reverse) {
  6089. reversedTarget = {};
  6090. if (setToFinal) {
  6091. revertedSource = {};
  6092. }
  6093. for (var i = 0; i < keyLen; i++) {
  6094. var innerKey = animatableKeys[i];
  6095. reversedTarget[innerKey] = source[innerKey];
  6096. if (setToFinal) {
  6097. revertedSource[innerKey] = target[innerKey];
  6098. }
  6099. else {
  6100. source[innerKey] = target[innerKey];
  6101. }
  6102. }
  6103. }
  6104. else if (setToFinal) {
  6105. sourceClone = {};
  6106. for (var i = 0; i < keyLen; i++) {
  6107. var innerKey = animatableKeys[i];
  6108. sourceClone[innerKey] = cloneValue(source[innerKey]);
  6109. copyValue(source, target, innerKey);
  6110. }
  6111. }
  6112. var animator = new Animator(source, false, additive ? existsAnimatorsOnSameTarget : null);
  6113. animator.targetName = topKey;
  6114. if (cfg.scope) {
  6115. animator.scope = cfg.scope;
  6116. }
  6117. if (setToFinal && revertedSource) {
  6118. animator.whenWithKeys(0, revertedSource, animatableKeys);
  6119. }
  6120. if (sourceClone) {
  6121. animator.whenWithKeys(0, sourceClone, animatableKeys);
  6122. }
  6123. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animatableKeys).delay(delay || 0);
  6124. animatable.addAnimator(animator, topKey);
  6125. animators.push(animator);
  6126. }
  6127. }
  6128. var Group = (function (_super) {
  6129. __extends(Group, _super);
  6130. function Group(opts) {
  6131. var _this = _super.call(this) || this;
  6132. _this.isGroup = true;
  6133. _this._children = [];
  6134. _this.attr(opts);
  6135. return _this;
  6136. }
  6137. Group.prototype.childrenRef = function () {
  6138. return this._children;
  6139. };
  6140. Group.prototype.children = function () {
  6141. return this._children.slice();
  6142. };
  6143. Group.prototype.childAt = function (idx) {
  6144. return this._children[idx];
  6145. };
  6146. Group.prototype.childOfName = function (name) {
  6147. var children = this._children;
  6148. for (var i = 0; i < children.length; i++) {
  6149. if (children[i].name === name) {
  6150. return children[i];
  6151. }
  6152. }
  6153. };
  6154. Group.prototype.childCount = function () {
  6155. return this._children.length;
  6156. };
  6157. Group.prototype.add = function (child) {
  6158. if (child) {
  6159. if (child !== this && child.parent !== this) {
  6160. this._children.push(child);
  6161. this._doAdd(child);
  6162. }
  6163. if (child.__hostTarget) {
  6164. throw 'This elemenet has been used as an attachment';
  6165. }
  6166. }
  6167. return this;
  6168. };
  6169. Group.prototype.addBefore = function (child, nextSibling) {
  6170. if (child && child !== this && child.parent !== this
  6171. && nextSibling && nextSibling.parent === this) {
  6172. var children = this._children;
  6173. var idx = children.indexOf(nextSibling);
  6174. if (idx >= 0) {
  6175. children.splice(idx, 0, child);
  6176. this._doAdd(child);
  6177. }
  6178. }
  6179. return this;
  6180. };
  6181. Group.prototype.replace = function (oldChild, newChild) {
  6182. var idx = indexOf(this._children, oldChild);
  6183. if (idx >= 0) {
  6184. this.replaceAt(newChild, idx);
  6185. }
  6186. return this;
  6187. };
  6188. Group.prototype.replaceAt = function (child, index) {
  6189. var children = this._children;
  6190. var old = children[index];
  6191. if (child && child !== this && child.parent !== this && child !== old) {
  6192. children[index] = child;
  6193. old.parent = null;
  6194. var zr = this.__zr;
  6195. if (zr) {
  6196. old.removeSelfFromZr(zr);
  6197. }
  6198. this._doAdd(child);
  6199. }
  6200. return this;
  6201. };
  6202. Group.prototype._doAdd = function (child) {
  6203. if (child.parent) {
  6204. child.parent.remove(child);
  6205. }
  6206. child.parent = this;
  6207. var zr = this.__zr;
  6208. if (zr && zr !== child.__zr) {
  6209. child.addSelfToZr(zr);
  6210. }
  6211. zr && zr.refresh();
  6212. };
  6213. Group.prototype.remove = function (child) {
  6214. var zr = this.__zr;
  6215. var children = this._children;
  6216. var idx = indexOf(children, child);
  6217. if (idx < 0) {
  6218. return this;
  6219. }
  6220. children.splice(idx, 1);
  6221. child.parent = null;
  6222. if (zr) {
  6223. child.removeSelfFromZr(zr);
  6224. }
  6225. zr && zr.refresh();
  6226. return this;
  6227. };
  6228. Group.prototype.removeAll = function () {
  6229. var children = this._children;
  6230. var zr = this.__zr;
  6231. for (var i = 0; i < children.length; i++) {
  6232. var child = children[i];
  6233. if (zr) {
  6234. child.removeSelfFromZr(zr);
  6235. }
  6236. child.parent = null;
  6237. }
  6238. children.length = 0;
  6239. return this;
  6240. };
  6241. Group.prototype.eachChild = function (cb, context) {
  6242. var children = this._children;
  6243. for (var i = 0; i < children.length; i++) {
  6244. var child = children[i];
  6245. cb.call(context, child, i);
  6246. }
  6247. return this;
  6248. };
  6249. Group.prototype.traverse = function (cb, context) {
  6250. for (var i = 0; i < this._children.length; i++) {
  6251. var child = this._children[i];
  6252. var stopped = cb.call(context, child);
  6253. if (child.isGroup && !stopped) {
  6254. child.traverse(cb, context);
  6255. }
  6256. }
  6257. return this;
  6258. };
  6259. Group.prototype.addSelfToZr = function (zr) {
  6260. _super.prototype.addSelfToZr.call(this, zr);
  6261. for (var i = 0; i < this._children.length; i++) {
  6262. var child = this._children[i];
  6263. child.addSelfToZr(zr);
  6264. }
  6265. };
  6266. Group.prototype.removeSelfFromZr = function (zr) {
  6267. _super.prototype.removeSelfFromZr.call(this, zr);
  6268. for (var i = 0; i < this._children.length; i++) {
  6269. var child = this._children[i];
  6270. child.removeSelfFromZr(zr);
  6271. }
  6272. };
  6273. Group.prototype.getBoundingRect = function (includeChildren) {
  6274. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6275. var children = includeChildren || this._children;
  6276. var tmpMat = [];
  6277. var rect = null;
  6278. for (var i = 0; i < children.length; i++) {
  6279. var child = children[i];
  6280. if (child.ignore || child.invisible) {
  6281. continue;
  6282. }
  6283. var childRect = child.getBoundingRect();
  6284. var transform = child.getLocalTransform(tmpMat);
  6285. if (transform) {
  6286. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6287. rect = rect || tmpRect.clone();
  6288. rect.union(tmpRect);
  6289. }
  6290. else {
  6291. rect = rect || childRect.clone();
  6292. rect.union(childRect);
  6293. }
  6294. }
  6295. return rect || tmpRect;
  6296. };
  6297. return Group;
  6298. }(Element));
  6299. Group.prototype.type = 'group';
  6300. /*!
  6301. * ZRender, a high performance 2d drawing library.
  6302. *
  6303. * Copyright (c) 2013, Baidu Inc.
  6304. * All rights reserved.
  6305. *
  6306. * LICENSE
  6307. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6308. */
  6309. var useVML = !env.canvasSupported;
  6310. var painterCtors = {};
  6311. var instances = {};
  6312. function delInstance(id) {
  6313. delete instances[id];
  6314. }
  6315. function isDarkMode(backgroundColor) {
  6316. if (!backgroundColor) {
  6317. return false;
  6318. }
  6319. if (typeof backgroundColor === 'string') {
  6320. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  6321. }
  6322. else if (backgroundColor.colorStops) {
  6323. var colorStops = backgroundColor.colorStops;
  6324. var totalLum = 0;
  6325. var len = colorStops.length;
  6326. for (var i = 0; i < len; i++) {
  6327. totalLum += lum(colorStops[i].color, 1);
  6328. }
  6329. totalLum /= len;
  6330. return totalLum < DARK_MODE_THRESHOLD;
  6331. }
  6332. return false;
  6333. }
  6334. var ZRender = (function () {
  6335. function ZRender(id, dom, opts) {
  6336. var _this = this;
  6337. this._sleepAfterStill = 10;
  6338. this._stillFrameAccum = 0;
  6339. this._needsRefresh = true;
  6340. this._needsRefreshHover = true;
  6341. this._darkMode = false;
  6342. opts = opts || {};
  6343. this.dom = dom;
  6344. this.id = id;
  6345. var storage = new Storage();
  6346. var rendererType = opts.renderer || 'canvas';
  6347. if (useVML) {
  6348. throw new Error('IE8 support has been dropped since 5.0');
  6349. }
  6350. if (!painterCtors[rendererType]) {
  6351. rendererType = keys(painterCtors)[0];
  6352. }
  6353. if (!painterCtors[rendererType]) {
  6354. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  6355. }
  6356. opts.useDirtyRect = opts.useDirtyRect == null
  6357. ? false
  6358. : opts.useDirtyRect;
  6359. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  6360. this.storage = storage;
  6361. this.painter = painter;
  6362. var handerProxy = (!env.node && !env.worker)
  6363. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  6364. : null;
  6365. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  6366. this.animation = new Animation({
  6367. stage: {
  6368. update: function () { return _this._flush(true); }
  6369. }
  6370. });
  6371. this.animation.start();
  6372. }
  6373. ZRender.prototype.add = function (el) {
  6374. if (!el) {
  6375. return;
  6376. }
  6377. this.storage.addRoot(el);
  6378. el.addSelfToZr(this);
  6379. this.refresh();
  6380. };
  6381. ZRender.prototype.remove = function (el) {
  6382. if (!el) {
  6383. return;
  6384. }
  6385. this.storage.delRoot(el);
  6386. el.removeSelfFromZr(this);
  6387. this.refresh();
  6388. };
  6389. ZRender.prototype.configLayer = function (zLevel, config) {
  6390. if (this.painter.configLayer) {
  6391. this.painter.configLayer(zLevel, config);
  6392. }
  6393. this.refresh();
  6394. };
  6395. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  6396. if (this.painter.setBackgroundColor) {
  6397. this.painter.setBackgroundColor(backgroundColor);
  6398. }
  6399. this.refresh();
  6400. this._backgroundColor = backgroundColor;
  6401. this._darkMode = isDarkMode(backgroundColor);
  6402. };
  6403. ZRender.prototype.getBackgroundColor = function () {
  6404. return this._backgroundColor;
  6405. };
  6406. ZRender.prototype.setDarkMode = function (darkMode) {
  6407. this._darkMode = darkMode;
  6408. };
  6409. ZRender.prototype.isDarkMode = function () {
  6410. return this._darkMode;
  6411. };
  6412. ZRender.prototype.refreshImmediately = function (fromInside) {
  6413. if (!fromInside) {
  6414. this.animation.update(true);
  6415. }
  6416. this._needsRefresh = false;
  6417. this.painter.refresh();
  6418. this._needsRefresh = false;
  6419. };
  6420. ZRender.prototype.refresh = function () {
  6421. this._needsRefresh = true;
  6422. this.animation.start();
  6423. };
  6424. ZRender.prototype.flush = function () {
  6425. this._flush(false);
  6426. };
  6427. ZRender.prototype._flush = function (fromInside) {
  6428. var triggerRendered;
  6429. var start = new Date().getTime();
  6430. if (this._needsRefresh) {
  6431. triggerRendered = true;
  6432. this.refreshImmediately(fromInside);
  6433. }
  6434. if (this._needsRefreshHover) {
  6435. triggerRendered = true;
  6436. this.refreshHoverImmediately();
  6437. }
  6438. var end = new Date().getTime();
  6439. if (triggerRendered) {
  6440. this._stillFrameAccum = 0;
  6441. this.trigger('rendered', {
  6442. elapsedTime: end - start
  6443. });
  6444. }
  6445. else if (this._sleepAfterStill > 0) {
  6446. this._stillFrameAccum++;
  6447. if (this._stillFrameAccum > this._sleepAfterStill) {
  6448. this.animation.stop();
  6449. }
  6450. }
  6451. };
  6452. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  6453. this._sleepAfterStill = stillFramesCount;
  6454. };
  6455. ZRender.prototype.wakeUp = function () {
  6456. this.animation.start();
  6457. this._stillFrameAccum = 0;
  6458. };
  6459. ZRender.prototype.addHover = function (el) {
  6460. };
  6461. ZRender.prototype.removeHover = function (el) {
  6462. };
  6463. ZRender.prototype.clearHover = function () {
  6464. };
  6465. ZRender.prototype.refreshHover = function () {
  6466. this._needsRefreshHover = true;
  6467. };
  6468. ZRender.prototype.refreshHoverImmediately = function () {
  6469. this._needsRefreshHover = false;
  6470. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  6471. this.painter.refreshHover();
  6472. }
  6473. };
  6474. ZRender.prototype.resize = function (opts) {
  6475. opts = opts || {};
  6476. this.painter.resize(opts.width, opts.height);
  6477. this.handler.resize();
  6478. };
  6479. ZRender.prototype.clearAnimation = function () {
  6480. this.animation.clear();
  6481. };
  6482. ZRender.prototype.getWidth = function () {
  6483. return this.painter.getWidth();
  6484. };
  6485. ZRender.prototype.getHeight = function () {
  6486. return this.painter.getHeight();
  6487. };
  6488. ZRender.prototype.pathToImage = function (e, dpr) {
  6489. if (this.painter.pathToImage) {
  6490. return this.painter.pathToImage(e, dpr);
  6491. }
  6492. };
  6493. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  6494. this.handler.setCursorStyle(cursorStyle);
  6495. };
  6496. ZRender.prototype.findHover = function (x, y) {
  6497. return this.handler.findHover(x, y);
  6498. };
  6499. ZRender.prototype.on = function (eventName, eventHandler, context) {
  6500. this.handler.on(eventName, eventHandler, context);
  6501. return this;
  6502. };
  6503. ZRender.prototype.off = function (eventName, eventHandler) {
  6504. this.handler.off(eventName, eventHandler);
  6505. };
  6506. ZRender.prototype.trigger = function (eventName, event) {
  6507. this.handler.trigger(eventName, event);
  6508. };
  6509. ZRender.prototype.clear = function () {
  6510. var roots = this.storage.getRoots();
  6511. for (var i = 0; i < roots.length; i++) {
  6512. if (roots[i] instanceof Group) {
  6513. roots[i].removeSelfFromZr(this);
  6514. }
  6515. }
  6516. this.storage.delAllRoots();
  6517. this.painter.clear();
  6518. };
  6519. ZRender.prototype.dispose = function () {
  6520. this.animation.stop();
  6521. this.clear();
  6522. this.storage.dispose();
  6523. this.painter.dispose();
  6524. this.handler.dispose();
  6525. this.animation =
  6526. this.storage =
  6527. this.painter =
  6528. this.handler = null;
  6529. delInstance(this.id);
  6530. };
  6531. return ZRender;
  6532. }());
  6533. function init(dom, opts) {
  6534. var zr = new ZRender(guid(), dom, opts);
  6535. instances[zr.id] = zr;
  6536. return zr;
  6537. }
  6538. function dispose(zr) {
  6539. zr.dispose();
  6540. }
  6541. function disposeAll() {
  6542. for (var key in instances) {
  6543. if (instances.hasOwnProperty(key)) {
  6544. instances[key].dispose();
  6545. }
  6546. }
  6547. instances = {};
  6548. }
  6549. function getInstance(id) {
  6550. return instances[id];
  6551. }
  6552. function registerPainter(name, Ctor) {
  6553. painterCtors[name] = Ctor;
  6554. }
  6555. var version = '5.2.1';
  6556. var zrender = /*#__PURE__*/Object.freeze({
  6557. __proto__: null,
  6558. init: init,
  6559. dispose: dispose,
  6560. disposeAll: disposeAll,
  6561. getInstance: getInstance,
  6562. registerPainter: registerPainter,
  6563. version: version
  6564. });
  6565. var RADIAN_EPSILON = 1e-4; // Although chrome already enlarge this number to 100 for `toFixed`, but
  6566. // we sill follow the spec for compatibility.
  6567. var ROUND_SUPPORTED_PRECISION_MAX = 20;
  6568. function _trim(str) {
  6569. return str.replace(/^\s+|\s+$/g, '');
  6570. }
  6571. /**
  6572. * Linear mapping a value from domain to range
  6573. * @param val
  6574. * @param domain Domain extent domain[0] can be bigger than domain[1]
  6575. * @param range Range extent range[0] can be bigger than range[1]
  6576. * @param clamp Default to be false
  6577. */
  6578. function linearMap(val, domain, range, clamp) {
  6579. var d0 = domain[0];
  6580. var d1 = domain[1];
  6581. var r0 = range[0];
  6582. var r1 = range[1];
  6583. var subDomain = d1 - d0;
  6584. var subRange = r1 - r0;
  6585. if (subDomain === 0) {
  6586. return subRange === 0 ? r0 : (r0 + r1) / 2;
  6587. } // Avoid accuracy problem in edge, such as
  6588. // 146.39 - 62.83 === 83.55999999999999.
  6589. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  6590. // It is a little verbose for efficiency considering this method
  6591. // is a hotspot.
  6592. if (clamp) {
  6593. if (subDomain > 0) {
  6594. if (val <= d0) {
  6595. return r0;
  6596. } else if (val >= d1) {
  6597. return r1;
  6598. }
  6599. } else {
  6600. if (val >= d0) {
  6601. return r0;
  6602. } else if (val <= d1) {
  6603. return r1;
  6604. }
  6605. }
  6606. } else {
  6607. if (val === d0) {
  6608. return r0;
  6609. }
  6610. if (val === d1) {
  6611. return r1;
  6612. }
  6613. }
  6614. return (val - d0) / subDomain * subRange + r0;
  6615. }
  6616. /**
  6617. * Convert a percent string to absolute number.
  6618. * Returns NaN if percent is not a valid string or number
  6619. */
  6620. function parsePercent$1(percent, all) {
  6621. switch (percent) {
  6622. case 'center':
  6623. case 'middle':
  6624. percent = '50%';
  6625. break;
  6626. case 'left':
  6627. case 'top':
  6628. percent = '0%';
  6629. break;
  6630. case 'right':
  6631. case 'bottom':
  6632. percent = '100%';
  6633. break;
  6634. }
  6635. if (typeof percent === 'string') {
  6636. if (_trim(percent).match(/%$/)) {
  6637. return parseFloat(percent) / 100 * all;
  6638. }
  6639. return parseFloat(percent);
  6640. }
  6641. return percent == null ? NaN : +percent;
  6642. }
  6643. function round(x, precision, returnStr) {
  6644. if (precision == null) {
  6645. precision = 10;
  6646. } // Avoid range error
  6647. precision = Math.min(Math.max(0, precision), ROUND_SUPPORTED_PRECISION_MAX); // PENDING: 1.005.toFixed(2) is '1.00' rather than '1.01'
  6648. x = (+x).toFixed(precision);
  6649. return returnStr ? x : +x;
  6650. }
  6651. /**
  6652. * Inplacd asc sort arr.
  6653. * The input arr will be modified.
  6654. */
  6655. function asc(arr) {
  6656. arr.sort(function (a, b) {
  6657. return a - b;
  6658. });
  6659. return arr;
  6660. }
  6661. /**
  6662. * Get precision.
  6663. */
  6664. function getPrecision(val) {
  6665. val = +val;
  6666. if (isNaN(val)) {
  6667. return 0;
  6668. } // It is much faster than methods converting number to string as follows
  6669. // let tmp = val.toString();
  6670. // return tmp.length - 1 - tmp.indexOf('.');
  6671. // especially when precision is low
  6672. // Notice:
  6673. // (1) If the loop count is over about 20, it is slower than `getPrecisionSafe`.
  6674. // (see https://jsbench.me/2vkpcekkvw/1)
  6675. // (2) If the val is less than for example 1e-15, the result may be incorrect.
  6676. // (see test/ut/spec/util/number.test.ts `getPrecision_equal_random`)
  6677. if (val > 1e-14) {
  6678. var e = 1;
  6679. for (var i = 0; i < 15; i++, e *= 10) {
  6680. if (Math.round(val * e) / e === val) {
  6681. return i;
  6682. }
  6683. }
  6684. }
  6685. return getPrecisionSafe(val);
  6686. }
  6687. /**
  6688. * Get precision with slow but safe method
  6689. */
  6690. function getPrecisionSafe(val) {
  6691. // toLowerCase for: '3.4E-12'
  6692. var str = val.toString().toLowerCase(); // Consider scientific notation: '3.4e-12' '3.4e+12'
  6693. var eIndex = str.indexOf('e');
  6694. var exp = eIndex > 0 ? +str.slice(eIndex + 1) : 0;
  6695. var significandPartLen = eIndex > 0 ? eIndex : str.length;
  6696. var dotIndex = str.indexOf('.');
  6697. var decimalPartLen = dotIndex < 0 ? 0 : significandPartLen - 1 - dotIndex;
  6698. return Math.max(0, decimalPartLen - exp);
  6699. }
  6700. /**
  6701. * Minimal dicernible data precisioin according to a single pixel.
  6702. */
  6703. function getPixelPrecision(dataExtent, pixelExtent) {
  6704. var log = Math.log;
  6705. var LN10 = Math.LN10;
  6706. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  6707. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); // toFixed() digits argument must be between 0 and 20.
  6708. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  6709. return !isFinite(precision) ? 20 : precision;
  6710. }
  6711. /**
  6712. * Get a data of given precision, assuring the sum of percentages
  6713. * in valueList is 1.
  6714. * The largest remainer method is used.
  6715. * https://en.wikipedia.org/wiki/Largest_remainder_method
  6716. *
  6717. * @param valueList a list of all data
  6718. * @param idx index of the data to be processed in valueList
  6719. * @param precision integer number showing digits of precision
  6720. * @return percent ranging from 0 to 100
  6721. */
  6722. function getPercentWithPrecision(valueList, idx, precision) {
  6723. if (!valueList[idx]) {
  6724. return 0;
  6725. }
  6726. var sum = reduce(valueList, function (acc, val) {
  6727. return acc + (isNaN(val) ? 0 : val);
  6728. }, 0);
  6729. if (sum === 0) {
  6730. return 0;
  6731. }
  6732. var digits = Math.pow(10, precision);
  6733. var votesPerQuota = map(valueList, function (val) {
  6734. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  6735. });
  6736. var targetSeats = digits * 100;
  6737. var seats = map(votesPerQuota, function (votes) {
  6738. // Assign automatic seats.
  6739. return Math.floor(votes);
  6740. });
  6741. var currentSum = reduce(seats, function (acc, val) {
  6742. return acc + val;
  6743. }, 0);
  6744. var remainder = map(votesPerQuota, function (votes, idx) {
  6745. return votes - seats[idx];
  6746. }); // Has remainding votes.
  6747. while (currentSum < targetSeats) {
  6748. // Find next largest remainder.
  6749. var max = Number.NEGATIVE_INFINITY;
  6750. var maxId = null;
  6751. for (var i = 0, len = remainder.length; i < len; ++i) {
  6752. if (remainder[i] > max) {
  6753. max = remainder[i];
  6754. maxId = i;
  6755. }
  6756. } // Add a vote to max remainder.
  6757. ++seats[maxId];
  6758. remainder[maxId] = 0;
  6759. ++currentSum;
  6760. }
  6761. return seats[idx] / digits;
  6762. }
  6763. /**
  6764. * Solve the floating point adding problem like 0.1 + 0.2 === 0.30000000000000004
  6765. * See <http://0.30000000000000004.com/>
  6766. */
  6767. function addSafe(val0, val1) {
  6768. var maxPrecision = Math.max(getPrecision(val0), getPrecision(val1)); // const multiplier = Math.pow(10, maxPrecision);
  6769. // return (Math.round(val0 * multiplier) + Math.round(val1 * multiplier)) / multiplier;
  6770. var sum = val0 + val1; // // PENDING: support more?
  6771. return maxPrecision > ROUND_SUPPORTED_PRECISION_MAX ? sum : round(sum, maxPrecision);
  6772. } // Number.MAX_SAFE_INTEGER, ie do not support.
  6773. var MAX_SAFE_INTEGER = 9007199254740991;
  6774. /**
  6775. * To 0 - 2 * PI, considering negative radian.
  6776. */
  6777. function remRadian(radian) {
  6778. var pi2 = Math.PI * 2;
  6779. return (radian % pi2 + pi2) % pi2;
  6780. }
  6781. /**
  6782. * @param {type} radian
  6783. * @return {boolean}
  6784. */
  6785. function isRadianAroundZero(val) {
  6786. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  6787. } // eslint-disable-next-line
  6788. 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
  6789. /**
  6790. * @param value valid type: number | string | Date, otherwise return `new Date(NaN)`
  6791. * These values can be accepted:
  6792. * + An instance of Date, represent a time in its own time zone.
  6793. * + Or string in a subset of ISO 8601, only including:
  6794. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  6795. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  6796. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  6797. * all of which will be treated as local time if time zone is not specified
  6798. * (see <https://momentjs.com/>).
  6799. * + Or other string format, including (all of which will be treated as loacal time):
  6800. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  6801. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  6802. * + a timestamp, which represent a time in UTC.
  6803. * @return date Never be null/undefined. If invalid, return `new Date(NaN)`.
  6804. */
  6805. function parseDate(value) {
  6806. if (value instanceof Date) {
  6807. return value;
  6808. } else if (typeof value === 'string') {
  6809. // Different browsers parse date in different way, so we parse it manually.
  6810. // Some other issues:
  6811. // new Date('1970-01-01') is UTC,
  6812. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  6813. // See issue #3623
  6814. var match = TIME_REG.exec(value);
  6815. if (!match) {
  6816. // return Invalid Date.
  6817. return new Date(NaN);
  6818. } // Use local time when no timezone offset specifed.
  6819. if (!match[8]) {
  6820. // match[n] can only be string or undefined.
  6821. // But take care of '12' + 1 => '121'.
  6822. 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);
  6823. } // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  6824. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  6825. // For example, system timezone is set as "Time Zone: America/Toronto",
  6826. // then these code will get different result:
  6827. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  6828. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  6829. // So we should not use `new Date`, but use `Date.UTC`.
  6830. else {
  6831. var hour = +match[4] || 0;
  6832. if (match[8].toUpperCase() !== 'Z') {
  6833. hour -= +match[8].slice(0, 3);
  6834. }
  6835. 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));
  6836. }
  6837. } else if (value == null) {
  6838. return new Date(NaN);
  6839. }
  6840. return new Date(Math.round(value));
  6841. }
  6842. /**
  6843. * Quantity of a number. e.g. 0.1, 1, 10, 100
  6844. *
  6845. * @param val
  6846. * @return
  6847. */
  6848. function quantity(val) {
  6849. return Math.pow(10, quantityExponent(val));
  6850. }
  6851. /**
  6852. * Exponent of the quantity of a number
  6853. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  6854. *
  6855. * @param val non-negative value
  6856. * @return
  6857. */
  6858. function quantityExponent(val) {
  6859. if (val === 0) {
  6860. return 0;
  6861. }
  6862. var exp = Math.floor(Math.log(val) / Math.LN10);
  6863. /**
  6864. * exp is expected to be the rounded-down result of the base-10 log of val.
  6865. * But due to the precision loss with Math.log(val), we need to restore it
  6866. * using 10^exp to make sure we can get val back from exp. #11249
  6867. */
  6868. if (val / Math.pow(10, exp) >= 10) {
  6869. exp++;
  6870. }
  6871. return exp;
  6872. }
  6873. /**
  6874. * find a “nice” number approximately equal to x. Round the number if round = true,
  6875. * take ceiling if round = false. The primary observation is that the “nicest”
  6876. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  6877. *
  6878. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  6879. *
  6880. * @param val Non-negative value.
  6881. * @param round
  6882. * @return Niced number
  6883. */
  6884. function nice(val, round) {
  6885. var exponent = quantityExponent(val);
  6886. var exp10 = Math.pow(10, exponent);
  6887. var f = val / exp10; // 1 <= f < 10
  6888. var nf;
  6889. if (round) {
  6890. if (f < 1.5) {
  6891. nf = 1;
  6892. } else if (f < 2.5) {
  6893. nf = 2;
  6894. } else if (f < 4) {
  6895. nf = 3;
  6896. } else if (f < 7) {
  6897. nf = 5;
  6898. } else {
  6899. nf = 10;
  6900. }
  6901. } else {
  6902. if (f < 1) {
  6903. nf = 1;
  6904. } else if (f < 2) {
  6905. nf = 2;
  6906. } else if (f < 3) {
  6907. nf = 3;
  6908. } else if (f < 5) {
  6909. nf = 5;
  6910. } else {
  6911. nf = 10;
  6912. }
  6913. }
  6914. val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  6915. // 20 is the uppper bound of toFixed.
  6916. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  6917. }
  6918. /**
  6919. * This code was copied from "d3.js"
  6920. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  6921. * See the license statement at the head of this file.
  6922. * @param ascArr
  6923. */
  6924. function quantile(ascArr, p) {
  6925. var H = (ascArr.length - 1) * p + 1;
  6926. var h = Math.floor(H);
  6927. var v = +ascArr[h - 1];
  6928. var e = H - h;
  6929. return e ? v + e * (ascArr[h] - v) : v;
  6930. }
  6931. /**
  6932. * Order intervals asc, and split them when overlap.
  6933. * expect(numberUtil.reformIntervals([
  6934. * {interval: [18, 62], close: [1, 1]},
  6935. * {interval: [-Infinity, -70], close: [0, 0]},
  6936. * {interval: [-70, -26], close: [1, 1]},
  6937. * {interval: [-26, 18], close: [1, 1]},
  6938. * {interval: [62, 150], close: [1, 1]},
  6939. * {interval: [106, 150], close: [1, 1]},
  6940. * {interval: [150, Infinity], close: [0, 0]}
  6941. * ])).toEqual([
  6942. * {interval: [-Infinity, -70], close: [0, 0]},
  6943. * {interval: [-70, -26], close: [1, 1]},
  6944. * {interval: [-26, 18], close: [0, 1]},
  6945. * {interval: [18, 62], close: [0, 1]},
  6946. * {interval: [62, 150], close: [0, 1]},
  6947. * {interval: [150, Infinity], close: [0, 0]}
  6948. * ]);
  6949. * @param list, where `close` mean open or close
  6950. * of the interval, and Infinity can be used.
  6951. * @return The origin list, which has been reformed.
  6952. */
  6953. function reformIntervals(list) {
  6954. list.sort(function (a, b) {
  6955. return littleThan(a, b, 0) ? -1 : 1;
  6956. });
  6957. var curr = -Infinity;
  6958. var currClose = 1;
  6959. for (var i = 0; i < list.length;) {
  6960. var interval = list[i].interval;
  6961. var close_1 = list[i].close;
  6962. for (var lg = 0; lg < 2; lg++) {
  6963. if (interval[lg] <= curr) {
  6964. interval[lg] = curr;
  6965. close_1[lg] = !lg ? 1 - currClose : 1;
  6966. }
  6967. curr = interval[lg];
  6968. currClose = close_1[lg];
  6969. }
  6970. if (interval[0] === interval[1] && close_1[0] * close_1[1] !== 1) {
  6971. list.splice(i, 1);
  6972. } else {
  6973. i++;
  6974. }
  6975. }
  6976. return list;
  6977. function littleThan(a, b, lg) {
  6978. 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));
  6979. }
  6980. }
  6981. /**
  6982. * [Numberic is defined as]:
  6983. * `parseFloat(val) == val`
  6984. * For example:
  6985. * numeric:
  6986. * typeof number except NaN, '-123', '123', '2e3', '-2e3', '011', 'Infinity', Infinity,
  6987. * and they rounded by white-spaces or line-terminal like ' -123 \n ' (see es spec)
  6988. * not-numeric:
  6989. * null, undefined, [], {}, true, false, 'NaN', NaN, '123ab',
  6990. * empty string, string with only white-spaces or line-terminal (see es spec),
  6991. * 0x12, '0x12', '-0x12', 012, '012', '-012',
  6992. * non-string, ...
  6993. *
  6994. * @test See full test cases in `test/ut/spec/util/number.js`.
  6995. * @return Must be a typeof number. If not numeric, return NaN.
  6996. */
  6997. function numericToNumber(val) {
  6998. var valFloat = parseFloat(val);
  6999. return valFloat == val // eslint-disable-line eqeqeq
  7000. && (valFloat !== 0 || typeof val !== 'string' || val.indexOf('x') <= 0) // For case ' 0x0 '.
  7001. ? valFloat : NaN;
  7002. }
  7003. /**
  7004. * Definition of "numeric": see `numericToNumber`.
  7005. */
  7006. function isNumeric(val) {
  7007. return !isNaN(numericToNumber(val));
  7008. }
  7009. /**
  7010. * Use random base to prevent users hard code depending on
  7011. * this auto generated marker id.
  7012. * @return An positive integer.
  7013. */
  7014. function getRandomIdBase() {
  7015. return Math.round(Math.random() * 9);
  7016. }
  7017. /**
  7018. * Get the greatest common dividor
  7019. *
  7020. * @param {number} a one number
  7021. * @param {number} b the other number
  7022. */
  7023. function getGreatestCommonDividor(a, b) {
  7024. if (b === 0) {
  7025. return a;
  7026. }
  7027. return getGreatestCommonDividor(b, a % b);
  7028. }
  7029. /**
  7030. * Get the least common multiple
  7031. *
  7032. * @param {number} a one number
  7033. * @param {number} b the other number
  7034. */
  7035. function getLeastCommonMultiple(a, b) {
  7036. if (a == null) {
  7037. return b;
  7038. }
  7039. if (b == null) {
  7040. return a;
  7041. }
  7042. return a * b / getGreatestCommonDividor(a, b);
  7043. }
  7044. var ECHARTS_PREFIX = '[ECharts] ';
  7045. var storedLogs = {};
  7046. var hasConsole = typeof console !== 'undefined' // eslint-disable-next-line
  7047. && console.warn && console.log;
  7048. function warn(str) {
  7049. if (hasConsole) {
  7050. console.warn(ECHARTS_PREFIX + str);
  7051. }
  7052. }
  7053. function error(str) {
  7054. if (hasConsole) {
  7055. console.error(ECHARTS_PREFIX + str);
  7056. }
  7057. }
  7058. function deprecateLog(str) {
  7059. if ("development" !== 'production') {
  7060. if (storedLogs[str]) {
  7061. // Not display duplicate message.
  7062. return;
  7063. }
  7064. if (hasConsole) {
  7065. storedLogs[str] = true;
  7066. console.warn(ECHARTS_PREFIX + 'DEPRECATED: ' + str);
  7067. }
  7068. }
  7069. }
  7070. function deprecateReplaceLog(oldOpt, newOpt, scope) {
  7071. if ("development" !== 'production') {
  7072. deprecateLog((scope ? "[" + scope + "]" : '') + (oldOpt + " is deprecated, use " + newOpt + " instead."));
  7073. }
  7074. }
  7075. function consoleLog() {
  7076. var args = [];
  7077. for (var _i = 0; _i < arguments.length; _i++) {
  7078. args[_i] = arguments[_i];
  7079. }
  7080. if ("development" !== 'production') {
  7081. /* eslint-disable no-console */
  7082. if (typeof console !== 'undefined' && console.log) {
  7083. console.log.apply(console, args);
  7084. }
  7085. /* eslint-enable no-console */
  7086. }
  7087. }
  7088. /**
  7089. * If in __DEV__ environment, get console printable message for users hint.
  7090. * Parameters are separated by ' '.
  7091. * @usuage
  7092. * makePrintable('This is an error on', someVar, someObj);
  7093. *
  7094. * @param hintInfo anything about the current execution context to hint users.
  7095. * @throws Error
  7096. */
  7097. function makePrintable() {
  7098. var hintInfo = [];
  7099. for (var _i = 0; _i < arguments.length; _i++) {
  7100. hintInfo[_i] = arguments[_i];
  7101. }
  7102. var msg = '';
  7103. if ("development" !== 'production') {
  7104. // Fuzzy stringify for print.
  7105. // This code only exist in dev environment.
  7106. var makePrintableStringIfPossible_1 = function (val) {
  7107. 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;
  7108. };
  7109. msg = map(hintInfo, function (arg) {
  7110. if (isString(arg)) {
  7111. // Print without quotation mark for some statement.
  7112. return arg;
  7113. } else {
  7114. var printableStr = makePrintableStringIfPossible_1(arg);
  7115. if (printableStr != null) {
  7116. return printableStr;
  7117. } else if (typeof JSON !== 'undefined' && JSON.stringify) {
  7118. try {
  7119. return JSON.stringify(arg, function (n, val) {
  7120. var printableStr = makePrintableStringIfPossible_1(val);
  7121. return printableStr == null ? val : printableStr;
  7122. }); // In most cases the info object is small, so do not line break.
  7123. } catch (err) {
  7124. return '?';
  7125. }
  7126. } else {
  7127. return '?';
  7128. }
  7129. }
  7130. }).join(' ');
  7131. }
  7132. return msg;
  7133. }
  7134. /**
  7135. * @throws Error
  7136. */
  7137. function throwError(msg) {
  7138. throw new Error(msg);
  7139. }
  7140. /**
  7141. * Make the name displayable. But we should
  7142. * make sure it is not duplicated with user
  7143. * specified name, so use '\0';
  7144. */
  7145. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  7146. var INTERNAL_COMPONENT_ID_PREFIX = '\0_ec_\0';
  7147. /**
  7148. * If value is not array, then translate it to array.
  7149. * @param {*} value
  7150. * @return {Array} [value] or value
  7151. */
  7152. function normalizeToArray(value) {
  7153. return value instanceof Array ? value : value == null ? [] : [value];
  7154. }
  7155. /**
  7156. * Sync default option between normal and emphasis like `position` and `show`
  7157. * In case some one will write code like
  7158. * label: {
  7159. * show: false,
  7160. * position: 'outside',
  7161. * fontSize: 18
  7162. * },
  7163. * emphasis: {
  7164. * label: { show: true }
  7165. * }
  7166. */
  7167. function defaultEmphasis(opt, key, subOpts) {
  7168. // Caution: performance sensitive.
  7169. if (opt) {
  7170. opt[key] = opt[key] || {};
  7171. opt.emphasis = opt.emphasis || {};
  7172. opt.emphasis[key] = opt.emphasis[key] || {}; // Default emphasis option from normal
  7173. for (var i = 0, len = subOpts.length; i < len; i++) {
  7174. var subOptName = subOpts[i];
  7175. if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
  7176. opt.emphasis[key][subOptName] = opt[key][subOptName];
  7177. }
  7178. }
  7179. }
  7180. }
  7181. 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']; // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  7182. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  7183. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  7184. // // FIXME: deprecated, check and remove it.
  7185. // 'textStyle'
  7186. // ]);
  7187. /**
  7188. * The method do not ensure performance.
  7189. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  7190. * This helper method retieves value from data.
  7191. */
  7192. function getDataItemValue(dataItem) {
  7193. return isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
  7194. }
  7195. /**
  7196. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  7197. * This helper method determine if dataItem has extra option besides value
  7198. */
  7199. function isDataItemOption(dataItem) {
  7200. return isObject(dataItem) && !(dataItem instanceof Array); // // markLine data can be array
  7201. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  7202. }
  7203. /**
  7204. * Mapping to existings for merge.
  7205. *
  7206. * Mode "normalMege":
  7207. * The mapping result (merge result) will keep the order of the existing
  7208. * component, rather than the order of new option. Because we should ensure
  7209. * some specified index reference (like xAxisIndex) keep work.
  7210. * And in most cases, "merge option" is used to update partial option but not
  7211. * be expected to change the order.
  7212. *
  7213. * Mode "replaceMege":
  7214. * (1) Only the id mapped components will be merged.
  7215. * (2) Other existing components (except internal compoonets) will be removed.
  7216. * (3) Other new options will be used to create new component.
  7217. * (4) The index of the existing compoents will not be modified.
  7218. * That means their might be "hole" after the removal.
  7219. * The new components are created first at those available index.
  7220. *
  7221. * Mode "replaceAll":
  7222. * This mode try to support that reproduce an echarts instance from another
  7223. * echarts instance (via `getOption`) in some simple cases.
  7224. * In this senario, the `result` index are exactly the consistent with the `newCmptOptions`,
  7225. * which ensures the compoennt index referring (like `xAxisIndex: ?`) corrent. That is,
  7226. * the "hole" in `newCmptOptions` will also be kept.
  7227. * On the contrary, other modes try best to eliminate holes.
  7228. * PENDING: This is an experimental mode yet.
  7229. *
  7230. * @return See the comment of <MappingResult>.
  7231. */
  7232. function mappingToExists(existings, newCmptOptions, mode) {
  7233. var isNormalMergeMode = mode === 'normalMerge';
  7234. var isReplaceMergeMode = mode === 'replaceMerge';
  7235. var isReplaceAllMode = mode === 'replaceAll';
  7236. existings = existings || [];
  7237. newCmptOptions = (newCmptOptions || []).slice();
  7238. var existingIdIdxMap = createHashMap(); // Validate id and name on user input option.
  7239. each(newCmptOptions, function (cmptOption, index) {
  7240. if (!isObject(cmptOption)) {
  7241. newCmptOptions[index] = null;
  7242. return;
  7243. }
  7244. if ("development" !== 'production') {
  7245. // There is some legacy case that name is set as `false`.
  7246. // But should work normally rather than throw error.
  7247. if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
  7248. warnInvalidateIdOrName(cmptOption.id);
  7249. }
  7250. if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
  7251. warnInvalidateIdOrName(cmptOption.name);
  7252. }
  7253. }
  7254. });
  7255. var result = prepareResult(existings, existingIdIdxMap, mode);
  7256. if (isNormalMergeMode || isReplaceMergeMode) {
  7257. mappingById(result, existings, existingIdIdxMap, newCmptOptions);
  7258. }
  7259. if (isNormalMergeMode) {
  7260. mappingByName(result, newCmptOptions);
  7261. }
  7262. if (isNormalMergeMode || isReplaceMergeMode) {
  7263. mappingByIndex(result, newCmptOptions, isReplaceMergeMode);
  7264. } else if (isReplaceAllMode) {
  7265. mappingInReplaceAllMode(result, newCmptOptions);
  7266. }
  7267. makeIdAndName(result); // The array `result` MUST NOT contain elided items, otherwise the
  7268. // forEach will ommit those items and result in incorrect result.
  7269. return result;
  7270. }
  7271. function prepareResult(existings, existingIdIdxMap, mode) {
  7272. var result = [];
  7273. if (mode === 'replaceAll') {
  7274. return result;
  7275. } // Do not use native `map` to in case that the array `existings`
  7276. // contains elided items, which will be ommited.
  7277. for (var index = 0; index < existings.length; index++) {
  7278. var existing = existings[index]; // Because of replaceMerge, `existing` may be null/undefined.
  7279. if (existing && existing.id != null) {
  7280. existingIdIdxMap.set(existing.id, index);
  7281. } // For non-internal-componnets:
  7282. // Mode "normalMerge": all existings kept.
  7283. // Mode "replaceMerge": all existing removed unless mapped by id.
  7284. // For internal-components:
  7285. // go with "replaceMerge" approach in both mode.
  7286. result.push({
  7287. existing: mode === 'replaceMerge' || isComponentIdInternal(existing) ? null : existing,
  7288. newOption: null,
  7289. keyInfo: null,
  7290. brandNew: null
  7291. });
  7292. }
  7293. return result;
  7294. }
  7295. function mappingById(result, existings, existingIdIdxMap, newCmptOptions) {
  7296. // Mapping by id if specified.
  7297. each(newCmptOptions, function (cmptOption, index) {
  7298. if (!cmptOption || cmptOption.id == null) {
  7299. return;
  7300. }
  7301. var optionId = makeComparableKey(cmptOption.id);
  7302. var existingIdx = existingIdIdxMap.get(optionId);
  7303. if (existingIdx != null) {
  7304. var resultItem = result[existingIdx];
  7305. assert(!resultItem.newOption, 'Duplicated option on id "' + optionId + '".');
  7306. resultItem.newOption = cmptOption; // In both mode, if id matched, new option will be merged to
  7307. // the existings rather than creating new component model.
  7308. resultItem.existing = existings[existingIdx];
  7309. newCmptOptions[index] = null;
  7310. }
  7311. });
  7312. }
  7313. function mappingByName(result, newCmptOptions) {
  7314. // Mapping by name if specified.
  7315. each(newCmptOptions, function (cmptOption, index) {
  7316. if (!cmptOption || cmptOption.name == null) {
  7317. return;
  7318. }
  7319. for (var i = 0; i < result.length; i++) {
  7320. var existing = result[i].existing;
  7321. if (!result[i].newOption // Consider name: two map to one.
  7322. // Can not match when both ids existing but different.
  7323. && existing && (existing.id == null || cmptOption.id == null) && !isComponentIdInternal(cmptOption) && !isComponentIdInternal(existing) && keyExistAndEqual('name', existing, cmptOption)) {
  7324. result[i].newOption = cmptOption;
  7325. newCmptOptions[index] = null;
  7326. return;
  7327. }
  7328. }
  7329. });
  7330. }
  7331. function mappingByIndex(result, newCmptOptions, brandNew) {
  7332. each(newCmptOptions, function (cmptOption) {
  7333. if (!cmptOption) {
  7334. return;
  7335. } // Find the first place that not mapped by id and not internal component (consider the "hole").
  7336. var resultItem;
  7337. var nextIdx = 0;
  7338. while ( // Be `!resultItem` only when `nextIdx >= result.length`.
  7339. (resultItem = result[nextIdx]) && ( // (1) Existing models that already have id should be able to mapped to. Because
  7340. // after mapping performed, model will always be assigned with an id if user not given.
  7341. // After that all models have id.
  7342. // (2) If new option has id, it can only set to a hole or append to the last. It should
  7343. // not be merged to the existings with different id. Because id should not be overwritten.
  7344. // (3) Name can be overwritten, because axis use name as 'show label text'.
  7345. resultItem.newOption || isComponentIdInternal(resultItem.existing) || // In mode "replaceMerge", here no not-mapped-non-internal-existing.
  7346. resultItem.existing && cmptOption.id != null && !keyExistAndEqual('id', cmptOption, resultItem.existing))) {
  7347. nextIdx++;
  7348. }
  7349. if (resultItem) {
  7350. resultItem.newOption = cmptOption;
  7351. resultItem.brandNew = brandNew;
  7352. } else {
  7353. result.push({
  7354. newOption: cmptOption,
  7355. brandNew: brandNew,
  7356. existing: null,
  7357. keyInfo: null
  7358. });
  7359. }
  7360. nextIdx++;
  7361. });
  7362. }
  7363. function mappingInReplaceAllMode(result, newCmptOptions) {
  7364. each(newCmptOptions, function (cmptOption) {
  7365. // The feature "reproduce" requires "hole" will also reproduced
  7366. // in case that compoennt index referring are broken.
  7367. result.push({
  7368. newOption: cmptOption,
  7369. brandNew: true,
  7370. existing: null,
  7371. keyInfo: null
  7372. });
  7373. });
  7374. }
  7375. /**
  7376. * Make id and name for mapping result (result of mappingToExists)
  7377. * into `keyInfo` field.
  7378. */
  7379. function makeIdAndName(mapResult) {
  7380. // We use this id to hash component models and view instances
  7381. // in echarts. id can be specified by user, or auto generated.
  7382. // The id generation rule ensures new view instance are able
  7383. // to mapped to old instance when setOption are called in
  7384. // no-merge mode. So we generate model id by name and plus
  7385. // type in view id.
  7386. // name can be duplicated among components, which is convenient
  7387. // to specify multi components (like series) by one name.
  7388. // Ensure that each id is distinct.
  7389. var idMap = createHashMap();
  7390. each(mapResult, function (item) {
  7391. var existing = item.existing;
  7392. existing && idMap.set(existing.id, item);
  7393. });
  7394. each(mapResult, function (item) {
  7395. var opt = item.newOption; // Force ensure id not duplicated.
  7396. assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  7397. opt && opt.id != null && idMap.set(opt.id, item);
  7398. !item.keyInfo && (item.keyInfo = {});
  7399. }); // Make name and id.
  7400. each(mapResult, function (item, index) {
  7401. var existing = item.existing;
  7402. var opt = item.newOption;
  7403. var keyInfo = item.keyInfo;
  7404. if (!isObject(opt)) {
  7405. return;
  7406. } // name can be overwitten. Consider case: axis.name = '20km'.
  7407. // But id generated by name will not be changed, which affect
  7408. // only in that case: setOption with 'not merge mode' and view
  7409. // instance will be recreated, which can be accepted.
  7410. keyInfo.name = opt.name != null ? makeComparableKey(opt.name) : existing ? existing.name // Avoid diffferent series has the same name,
  7411. // because name may be used like in color pallet.
  7412. : DUMMY_COMPONENT_NAME_PREFIX + index;
  7413. if (existing) {
  7414. keyInfo.id = makeComparableKey(existing.id);
  7415. } else if (opt.id != null) {
  7416. keyInfo.id = makeComparableKey(opt.id);
  7417. } else {
  7418. // Consider this situatoin:
  7419. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  7420. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  7421. // Series with the same name between optionA and optionB
  7422. // should be mapped.
  7423. var idNum = 0;
  7424. do {
  7425. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  7426. } while (idMap.get(keyInfo.id));
  7427. }
  7428. idMap.set(keyInfo.id, item);
  7429. });
  7430. }
  7431. function keyExistAndEqual(attr, obj1, obj2) {
  7432. var key1 = convertOptionIdName(obj1[attr], null);
  7433. var key2 = convertOptionIdName(obj2[attr], null); // See `MappingExistingItem`. `id` and `name` trade string equals to number.
  7434. return key1 != null && key2 != null && key1 === key2;
  7435. }
  7436. /**
  7437. * @return return null if not exist.
  7438. */
  7439. function makeComparableKey(val) {
  7440. if ("development" !== 'production') {
  7441. if (val == null) {
  7442. throw new Error();
  7443. }
  7444. }
  7445. return convertOptionIdName(val, '');
  7446. }
  7447. function convertOptionIdName(idOrName, defaultValue) {
  7448. if (idOrName == null) {
  7449. return defaultValue;
  7450. }
  7451. var type = typeof idOrName;
  7452. return type === 'string' ? idOrName : type === 'number' || isStringSafe(idOrName) ? idOrName + '' : defaultValue;
  7453. }
  7454. function warnInvalidateIdOrName(idOrName) {
  7455. if ("development" !== 'production') {
  7456. warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
  7457. }
  7458. }
  7459. function isValidIdOrName(idOrName) {
  7460. return isStringSafe(idOrName) || isNumeric(idOrName);
  7461. }
  7462. function isNameSpecified(componentModel) {
  7463. var name = componentModel.name; // Is specified when `indexOf` get -1 or > 0.
  7464. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  7465. }
  7466. /**
  7467. * @public
  7468. * @param {Object} cmptOption
  7469. * @return {boolean}
  7470. */
  7471. function isComponentIdInternal(cmptOption) {
  7472. return cmptOption && cmptOption.id != null && makeComparableKey(cmptOption.id).indexOf(INTERNAL_COMPONENT_ID_PREFIX) === 0;
  7473. }
  7474. function makeInternalComponentId(idSuffix) {
  7475. return INTERNAL_COMPONENT_ID_PREFIX + idSuffix;
  7476. }
  7477. function setComponentTypeToKeyInfo(mappingResult, mainType, componentModelCtor) {
  7478. // Set mainType and complete subType.
  7479. each(mappingResult, function (item) {
  7480. var newOption = item.newOption;
  7481. if (isObject(newOption)) {
  7482. item.keyInfo.mainType = mainType;
  7483. item.keyInfo.subType = determineSubType(mainType, newOption, item.existing, componentModelCtor);
  7484. }
  7485. });
  7486. }
  7487. function determineSubType(mainType, newCmptOption, existComponent, componentModelCtor) {
  7488. var subType = newCmptOption.type ? newCmptOption.type : existComponent ? existComponent.subType // Use determineSubType only when there is no existComponent.
  7489. : componentModelCtor.determineSubType(mainType, newCmptOption); // tooltip, markline, markpoint may always has no subType
  7490. return subType;
  7491. }
  7492. /**
  7493. * @param payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  7494. * each of which can be Array or primary type.
  7495. * @return dataIndex If not found, return undefined/null.
  7496. */
  7497. function queryDataIndex(data, payload) {
  7498. if (payload.dataIndexInside != null) {
  7499. return payload.dataIndexInside;
  7500. } else if (payload.dataIndex != null) {
  7501. return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
  7502. return data.indexOfRawIndex(value);
  7503. }) : data.indexOfRawIndex(payload.dataIndex);
  7504. } else if (payload.name != null) {
  7505. return isArray(payload.name) ? map(payload.name, function (value) {
  7506. return data.indexOfName(value);
  7507. }) : data.indexOfName(payload.name);
  7508. }
  7509. }
  7510. /**
  7511. * Enable property storage to any host object.
  7512. * Notice: Serialization is not supported.
  7513. *
  7514. * For example:
  7515. * let inner = zrUitl.makeInner();
  7516. *
  7517. * function some1(hostObj) {
  7518. * inner(hostObj).someProperty = 1212;
  7519. * ...
  7520. * }
  7521. * function some2() {
  7522. * let fields = inner(this);
  7523. * fields.someProperty1 = 1212;
  7524. * fields.someProperty2 = 'xx';
  7525. * ...
  7526. * }
  7527. *
  7528. * @return {Function}
  7529. */
  7530. function makeInner() {
  7531. var key = '__ec_inner_' + innerUniqueIndex++;
  7532. return function (hostObj) {
  7533. return hostObj[key] || (hostObj[key] = {});
  7534. };
  7535. }
  7536. var innerUniqueIndex = getRandomIdBase();
  7537. /**
  7538. * The same behavior as `component.getReferringComponents`.
  7539. */
  7540. function parseFinder(ecModel, finderInput, opt) {
  7541. var _a = preParseFinder(finderInput, opt),
  7542. mainTypeSpecified = _a.mainTypeSpecified,
  7543. queryOptionMap = _a.queryOptionMap,
  7544. others = _a.others;
  7545. var result = others;
  7546. var defaultMainType = opt ? opt.defaultMainType : null;
  7547. if (!mainTypeSpecified && defaultMainType) {
  7548. queryOptionMap.set(defaultMainType, {});
  7549. }
  7550. queryOptionMap.each(function (queryOption, mainType) {
  7551. var queryResult = queryReferringComponents(ecModel, mainType, queryOption, {
  7552. useDefault: defaultMainType === mainType,
  7553. enableAll: opt && opt.enableAll != null ? opt.enableAll : true,
  7554. enableNone: opt && opt.enableNone != null ? opt.enableNone : true
  7555. });
  7556. result[mainType + 'Models'] = queryResult.models;
  7557. result[mainType + 'Model'] = queryResult.models[0];
  7558. });
  7559. return result;
  7560. }
  7561. function preParseFinder(finderInput, opt) {
  7562. var finder;
  7563. if (isString(finderInput)) {
  7564. var obj = {};
  7565. obj[finderInput + 'Index'] = 0;
  7566. finder = obj;
  7567. } else {
  7568. finder = finderInput;
  7569. }
  7570. var queryOptionMap = createHashMap();
  7571. var others = {};
  7572. var mainTypeSpecified = false;
  7573. each(finder, function (value, key) {
  7574. // Exclude 'dataIndex' and other illgal keys.
  7575. if (key === 'dataIndex' || key === 'dataIndexInside') {
  7576. others[key] = value;
  7577. return;
  7578. }
  7579. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  7580. var mainType = parsedKey[1];
  7581. var queryType = (parsedKey[2] || '').toLowerCase();
  7582. if (!mainType || !queryType || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
  7583. return;
  7584. }
  7585. mainTypeSpecified = mainTypeSpecified || !!mainType;
  7586. var queryOption = queryOptionMap.get(mainType) || queryOptionMap.set(mainType, {});
  7587. queryOption[queryType] = value;
  7588. });
  7589. return {
  7590. mainTypeSpecified: mainTypeSpecified,
  7591. queryOptionMap: queryOptionMap,
  7592. others: others
  7593. };
  7594. }
  7595. var SINGLE_REFERRING = {
  7596. useDefault: true,
  7597. enableAll: false,
  7598. enableNone: false
  7599. };
  7600. var MULTIPLE_REFERRING = {
  7601. useDefault: false,
  7602. enableAll: true,
  7603. enableNone: true
  7604. };
  7605. function queryReferringComponents(ecModel, mainType, userOption, opt) {
  7606. opt = opt || SINGLE_REFERRING;
  7607. var indexOption = userOption.index;
  7608. var idOption = userOption.id;
  7609. var nameOption = userOption.name;
  7610. var result = {
  7611. models: null,
  7612. specified: indexOption != null || idOption != null || nameOption != null
  7613. };
  7614. if (!result.specified) {
  7615. // Use the first as default if `useDefault`.
  7616. var firstCmpt = void 0;
  7617. result.models = opt.useDefault && (firstCmpt = ecModel.getComponent(mainType)) ? [firstCmpt] : [];
  7618. return result;
  7619. }
  7620. if (indexOption === 'none' || indexOption === false) {
  7621. assert(opt.enableNone, '`"none"` or `false` is not a valid value on index option.');
  7622. result.models = [];
  7623. return result;
  7624. } // `queryComponents` will return all components if
  7625. // both all of index/id/name are null/undefined.
  7626. if (indexOption === 'all') {
  7627. assert(opt.enableAll, '`"all"` is not a valid value on index option.');
  7628. indexOption = idOption = nameOption = null;
  7629. }
  7630. result.models = ecModel.queryComponents({
  7631. mainType: mainType,
  7632. index: indexOption,
  7633. id: idOption,
  7634. name: nameOption
  7635. });
  7636. return result;
  7637. }
  7638. function setAttribute(dom, key, value) {
  7639. dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
  7640. }
  7641. function getAttribute(dom, key) {
  7642. return dom.getAttribute ? dom.getAttribute(key) : dom[key];
  7643. }
  7644. function getTooltipRenderMode(renderModeOption) {
  7645. if (renderModeOption === 'auto') {
  7646. // Using html when `document` exists, use richText otherwise
  7647. return env.domSupported ? 'html' : 'richText';
  7648. } else {
  7649. return renderModeOption || 'html';
  7650. }
  7651. }
  7652. /**
  7653. * Interpolate raw values of a series with percent
  7654. *
  7655. * @param data data
  7656. * @param labelModel label model of the text element
  7657. * @param sourceValue start value. May be null/undefined when init.
  7658. * @param targetValue end value
  7659. * @param percent 0~1 percentage; 0 uses start value while 1 uses end value
  7660. * @return interpolated values
  7661. * If `sourceValue` and `targetValue` are `number`, return `number`.
  7662. * If `sourceValue` and `targetValue` are `string`, return `string`.
  7663. * If `sourceValue` and `targetValue` are `(string | number)[]`, return `(string | number)[]`.
  7664. * Other cases do not supported.
  7665. */
  7666. function interpolateRawValues(data, precision, sourceValue, targetValue, percent) {
  7667. var isAutoPrecision = precision == null || precision === 'auto';
  7668. if (targetValue == null) {
  7669. return targetValue;
  7670. }
  7671. if (typeof targetValue === 'number') {
  7672. var value = interpolateNumber(sourceValue || 0, targetValue, percent);
  7673. return round(value, isAutoPrecision ? Math.max(getPrecision(sourceValue || 0), getPrecision(targetValue)) : precision);
  7674. } else if (typeof targetValue === 'string') {
  7675. return percent < 1 ? sourceValue : targetValue;
  7676. } else {
  7677. var interpolated = [];
  7678. var leftArr = sourceValue;
  7679. var rightArr = targetValue;
  7680. var length_1 = Math.max(leftArr ? leftArr.length : 0, rightArr.length);
  7681. for (var i = 0; i < length_1; ++i) {
  7682. var info = data.getDimensionInfo(i); // Don't interpolate ordinal dims
  7683. if (info && info.type === 'ordinal') {
  7684. // In init, there is no `sourceValue`, but should better not to get undefined result.
  7685. interpolated[i] = (percent < 1 && leftArr ? leftArr : rightArr)[i];
  7686. } else {
  7687. var leftVal = leftArr && leftArr[i] ? leftArr[i] : 0;
  7688. var rightVal = rightArr[i];
  7689. var value = interpolateNumber(leftVal, rightVal, percent);
  7690. interpolated[i] = round(value, isAutoPrecision ? Math.max(getPrecision(leftVal), getPrecision(rightVal)) : precision);
  7691. }
  7692. }
  7693. return interpolated;
  7694. }
  7695. }
  7696. var TYPE_DELIMITER = '.';
  7697. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  7698. var IS_EXTENDED_CLASS = '___EC__EXTENDED_CLASS___';
  7699. /**
  7700. * Notice, parseClassType('') should returns {main: '', sub: ''}
  7701. * @public
  7702. */
  7703. function parseClassType(componentType) {
  7704. var ret = {
  7705. main: '',
  7706. sub: ''
  7707. };
  7708. if (componentType) {
  7709. var typeArr = componentType.split(TYPE_DELIMITER);
  7710. ret.main = typeArr[0] || '';
  7711. ret.sub = typeArr[1] || '';
  7712. }
  7713. return ret;
  7714. }
  7715. /**
  7716. * @public
  7717. */
  7718. function checkClassType(componentType) {
  7719. assert(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  7720. }
  7721. function isExtendedClass(clz) {
  7722. return !!(clz && clz[IS_EXTENDED_CLASS]);
  7723. }
  7724. /**
  7725. * Implements `ExtendableConstructor` for `rootClz`.
  7726. *
  7727. * @usage
  7728. * ```ts
  7729. * class Xxx {}
  7730. * type XxxConstructor = typeof Xxx & ExtendableConstructor
  7731. * enableClassExtend(Xxx as XxxConstructor);
  7732. * ```
  7733. */
  7734. function enableClassExtend(rootClz, mandatoryMethods) {
  7735. rootClz.$constructor = rootClz; // FIXME: not necessary?
  7736. rootClz.extend = function (proto) {
  7737. if ("development" !== 'production') {
  7738. each(mandatoryMethods, function (method) {
  7739. if (!proto[method]) {
  7740. console.warn('Method `' + method + '` should be implemented' + (proto.type ? ' in ' + proto.type : '') + '.');
  7741. }
  7742. });
  7743. }
  7744. var superClass = this; // For backward compat, we both support ts class inheritance and this
  7745. // "extend" approach.
  7746. // The constructor should keep the same behavior as ts class inheritance:
  7747. // If this constructor/$constructor is not declared, auto invoke the super
  7748. // constructor.
  7749. // If this constructor/$constructor is declared, it is responsible for
  7750. // calling the super constructor.
  7751. function ExtendedClass() {
  7752. var args = [];
  7753. for (var _i = 0; _i < arguments.length; _i++) {
  7754. args[_i] = arguments[_i];
  7755. }
  7756. if (!proto.$constructor) {
  7757. if (!isESClass(superClass)) {
  7758. // Will throw error if superClass is an es6 native class.
  7759. superClass.apply(this, arguments);
  7760. } else {
  7761. var ins = createObject( // @ts-ignore
  7762. ExtendedClass.prototype, new (superClass.bind.apply(superClass, __spreadArray([void 0], args)))());
  7763. return ins;
  7764. }
  7765. } else {
  7766. proto.$constructor.apply(this, arguments);
  7767. }
  7768. }
  7769. ExtendedClass[IS_EXTENDED_CLASS] = true;
  7770. extend(ExtendedClass.prototype, proto);
  7771. ExtendedClass.extend = this.extend;
  7772. ExtendedClass.superCall = superCall;
  7773. ExtendedClass.superApply = superApply;
  7774. inherits(ExtendedClass, this);
  7775. ExtendedClass.superClass = superClass;
  7776. return ExtendedClass;
  7777. };
  7778. }
  7779. function isESClass(fn) {
  7780. return typeof fn === 'function' && /^class\s/.test(Function.prototype.toString.call(fn));
  7781. }
  7782. /**
  7783. * A work around to both support ts extend and this extend mechanism.
  7784. * on sub-class.
  7785. * @usage
  7786. * ```ts
  7787. * class Component { ... }
  7788. * classUtil.enableClassExtend(Component);
  7789. * classUtil.enableClassManagement(Component, {registerWhenExtend: true});
  7790. *
  7791. * class Series extends Component { ... }
  7792. * // Without calling `markExtend`, `registerWhenExtend` will not work.
  7793. * Component.markExtend(Series);
  7794. * ```
  7795. */
  7796. function mountExtend(SubClz, SupperClz) {
  7797. SubClz.extend = SupperClz.extend;
  7798. } // A random offset.
  7799. var classBase = Math.round(Math.random() * 10);
  7800. /**
  7801. * Implements `CheckableConstructor` for `target`.
  7802. * Can not use instanceof, consider different scope by
  7803. * cross domain or es module import in ec extensions.
  7804. * Mount a method "isInstance()" to Clz.
  7805. *
  7806. * @usage
  7807. * ```ts
  7808. * class Xxx {}
  7809. * type XxxConstructor = typeof Xxx & CheckableConstructor;
  7810. * enableClassCheck(Xxx as XxxConstructor)
  7811. * ```
  7812. */
  7813. function enableClassCheck(target) {
  7814. var classAttr = ['__\0is_clz', classBase++].join('_');
  7815. target.prototype[classAttr] = true;
  7816. if ("development" !== 'production') {
  7817. assert(!target.isInstance, 'The method "is" can not be defined.');
  7818. }
  7819. target.isInstance = function (obj) {
  7820. return !!(obj && obj[classAttr]);
  7821. };
  7822. } // superCall should have class info, which can not be fetch from 'this'.
  7823. // Consider this case:
  7824. // class A has method f,
  7825. // class B inherits class A, overrides method f, f call superApply('f'),
  7826. // class C inherits class B, do not overrides method f,
  7827. // then when method of class C is called, dead loop occured.
  7828. function superCall(context, methodName) {
  7829. var args = [];
  7830. for (var _i = 2; _i < arguments.length; _i++) {
  7831. args[_i - 2] = arguments[_i];
  7832. }
  7833. return this.superClass.prototype[methodName].apply(context, args);
  7834. }
  7835. function superApply(context, methodName, args) {
  7836. return this.superClass.prototype[methodName].apply(context, args);
  7837. }
  7838. /**
  7839. * Implements `ClassManager` for `target`
  7840. *
  7841. * @usage
  7842. * ```ts
  7843. * class Xxx {}
  7844. * type XxxConstructor = typeof Xxx & ClassManager
  7845. * enableClassManagement(Xxx as XxxConstructor);
  7846. * ```
  7847. */
  7848. function enableClassManagement(target) {
  7849. /**
  7850. * Component model classes
  7851. * key: componentType,
  7852. * value:
  7853. * componentClass, when componentType is 'xxx'
  7854. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  7855. */
  7856. var storage = {};
  7857. target.registerClass = function (clz) {
  7858. // `type` should not be a "instance memeber".
  7859. // If using TS class, should better declared as `static type = 'series.pie'`.
  7860. // otherwise users have to mount `type` on prototype manually.
  7861. // For backward compat and enable instance visit type via `this.type`,
  7862. // we stil support fetch `type` from prototype.
  7863. var componentFullType = clz.type || clz.prototype.type;
  7864. if (componentFullType) {
  7865. checkClassType(componentFullType); // If only static type declared, we assign it to prototype mandatorily.
  7866. clz.prototype.type = componentFullType;
  7867. var componentTypeInfo = parseClassType(componentFullType);
  7868. if (!componentTypeInfo.sub) {
  7869. if ("development" !== 'production') {
  7870. if (storage[componentTypeInfo.main]) {
  7871. console.warn(componentTypeInfo.main + ' exists.');
  7872. }
  7873. }
  7874. storage[componentTypeInfo.main] = clz;
  7875. } else if (componentTypeInfo.sub !== IS_CONTAINER) {
  7876. var container = makeContainer(componentTypeInfo);
  7877. container[componentTypeInfo.sub] = clz;
  7878. }
  7879. }
  7880. return clz;
  7881. };
  7882. target.getClass = function (mainType, subType, throwWhenNotFound) {
  7883. var clz = storage[mainType];
  7884. if (clz && clz[IS_CONTAINER]) {
  7885. clz = subType ? clz[subType] : null;
  7886. }
  7887. if (throwWhenNotFound && !clz) {
  7888. throw new Error(!subType ? mainType + '.' + 'type should be specified.' : 'Component ' + mainType + '.' + (subType || '') + ' is used but not imported.');
  7889. }
  7890. return clz;
  7891. };
  7892. target.getClassesByMainType = function (componentType) {
  7893. var componentTypeInfo = parseClassType(componentType);
  7894. var result = [];
  7895. var obj = storage[componentTypeInfo.main];
  7896. if (obj && obj[IS_CONTAINER]) {
  7897. each(obj, function (o, type) {
  7898. type !== IS_CONTAINER && result.push(o);
  7899. });
  7900. } else {
  7901. result.push(obj);
  7902. }
  7903. return result;
  7904. };
  7905. target.hasClass = function (componentType) {
  7906. // Just consider componentType.main.
  7907. var componentTypeInfo = parseClassType(componentType);
  7908. return !!storage[componentTypeInfo.main];
  7909. };
  7910. /**
  7911. * @return Like ['aa', 'bb'], but can not be ['aa.xx']
  7912. */
  7913. target.getAllClassMainTypes = function () {
  7914. var types = [];
  7915. each(storage, function (obj, type) {
  7916. types.push(type);
  7917. });
  7918. return types;
  7919. };
  7920. /**
  7921. * If a main type is container and has sub types
  7922. */
  7923. target.hasSubTypes = function (componentType) {
  7924. var componentTypeInfo = parseClassType(componentType);
  7925. var obj = storage[componentTypeInfo.main];
  7926. return obj && obj[IS_CONTAINER];
  7927. };
  7928. function makeContainer(componentTypeInfo) {
  7929. var container = storage[componentTypeInfo.main];
  7930. if (!container || !container[IS_CONTAINER]) {
  7931. container = storage[componentTypeInfo.main] = {};
  7932. container[IS_CONTAINER] = true;
  7933. }
  7934. return container;
  7935. }
  7936. } // /**
  7937. // * @param {string|Array.<string>} properties
  7938. // */
  7939. // export function setReadOnly(obj, properties) {
  7940. // FIXME It seems broken in IE8 simulation of IE11
  7941. // if (!zrUtil.isArray(properties)) {
  7942. // properties = properties != null ? [properties] : [];
  7943. // }
  7944. // zrUtil.each(properties, function (prop) {
  7945. // let value = obj[prop];
  7946. // Object.defineProperty
  7947. // && Object.defineProperty(obj, prop, {
  7948. // value: value, writable: false
  7949. // });
  7950. // zrUtil.isArray(obj[prop])
  7951. // && Object.freeze
  7952. // && Object.freeze(obj[prop]);
  7953. // });
  7954. // }
  7955. function makeStyleMapper(properties, ignoreParent) {
  7956. // Normalize
  7957. for (var i = 0; i < properties.length; i++) {
  7958. if (!properties[i][1]) {
  7959. properties[i][1] = properties[i][0];
  7960. }
  7961. }
  7962. ignoreParent = ignoreParent || false;
  7963. return function (model, excludes, includes) {
  7964. var style = {};
  7965. for (var i = 0; i < properties.length; i++) {
  7966. var propName = properties[i][1];
  7967. if (excludes && indexOf(excludes, propName) >= 0 || includes && indexOf(includes, propName) < 0) {
  7968. continue;
  7969. }
  7970. var val = model.getShallow(propName, ignoreParent);
  7971. if (val != null) {
  7972. style[properties[i][0]] = val;
  7973. }
  7974. } // TODO Text or image?
  7975. return style;
  7976. };
  7977. }
  7978. var AREA_STYLE_KEY_MAP = [['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor'] // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  7979. // So do not transfer decal directly.
  7980. ];
  7981. var getAreaStyle = makeStyleMapper(AREA_STYLE_KEY_MAP);
  7982. var AreaStyleMixin =
  7983. /** @class */
  7984. function () {
  7985. function AreaStyleMixin() {}
  7986. AreaStyleMixin.prototype.getAreaStyle = function (excludes, includes) {
  7987. return getAreaStyle(this, excludes, includes);
  7988. };
  7989. return AreaStyleMixin;
  7990. }();
  7991. var globalImageCache = new LRU(50);
  7992. function findExistImage(newImageOrSrc) {
  7993. if (typeof newImageOrSrc === 'string') {
  7994. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  7995. return cachedImgObj && cachedImgObj.image;
  7996. }
  7997. else {
  7998. return newImageOrSrc;
  7999. }
  8000. }
  8001. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  8002. if (!newImageOrSrc) {
  8003. return image;
  8004. }
  8005. else if (typeof newImageOrSrc === 'string') {
  8006. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  8007. return image;
  8008. }
  8009. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  8010. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  8011. if (cachedImgObj) {
  8012. image = cachedImgObj.image;
  8013. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  8014. }
  8015. else {
  8016. image = new Image();
  8017. image.onload = image.onerror = imageOnLoad;
  8018. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  8019. image: image,
  8020. pending: [pendingWrap]
  8021. });
  8022. image.src = image.__zrImageSrc = newImageOrSrc;
  8023. }
  8024. return image;
  8025. }
  8026. else {
  8027. return newImageOrSrc;
  8028. }
  8029. }
  8030. function imageOnLoad() {
  8031. var cachedImgObj = this.__cachedImgObj;
  8032. this.onload = this.onerror = this.__cachedImgObj = null;
  8033. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  8034. var pendingWrap = cachedImgObj.pending[i];
  8035. var cb = pendingWrap.cb;
  8036. cb && cb(this, pendingWrap.cbPayload);
  8037. pendingWrap.hostEl.dirty();
  8038. }
  8039. cachedImgObj.pending.length = 0;
  8040. }
  8041. function isImageReady(image) {
  8042. return image && image.width && image.height;
  8043. }
  8044. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  8045. function truncateText(text, containerWidth, font, ellipsis, options) {
  8046. if (!containerWidth) {
  8047. return '';
  8048. }
  8049. var textLines = (text + '').split('\n');
  8050. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  8051. for (var i = 0, len = textLines.length; i < len; i++) {
  8052. textLines[i] = truncateSingleLine(textLines[i], options);
  8053. }
  8054. return textLines.join('\n');
  8055. }
  8056. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  8057. options = options || {};
  8058. var preparedOpts = extend({}, options);
  8059. preparedOpts.font = font;
  8060. ellipsis = retrieve2(ellipsis, '...');
  8061. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  8062. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  8063. preparedOpts.cnCharWidth = getWidth('国', font);
  8064. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  8065. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  8066. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  8067. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  8068. contentWidth -= ascCharWidth;
  8069. }
  8070. var ellipsisWidth = getWidth(ellipsis, font);
  8071. if (ellipsisWidth > contentWidth) {
  8072. ellipsis = '';
  8073. ellipsisWidth = 0;
  8074. }
  8075. contentWidth = containerWidth - ellipsisWidth;
  8076. preparedOpts.ellipsis = ellipsis;
  8077. preparedOpts.ellipsisWidth = ellipsisWidth;
  8078. preparedOpts.contentWidth = contentWidth;
  8079. preparedOpts.containerWidth = containerWidth;
  8080. return preparedOpts;
  8081. }
  8082. function truncateSingleLine(textLine, options) {
  8083. var containerWidth = options.containerWidth;
  8084. var font = options.font;
  8085. var contentWidth = options.contentWidth;
  8086. if (!containerWidth) {
  8087. return '';
  8088. }
  8089. var lineWidth = getWidth(textLine, font);
  8090. if (lineWidth <= containerWidth) {
  8091. return textLine;
  8092. }
  8093. for (var j = 0;; j++) {
  8094. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  8095. textLine += options.ellipsis;
  8096. break;
  8097. }
  8098. var subLength = j === 0
  8099. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  8100. : lineWidth > 0
  8101. ? Math.floor(textLine.length * contentWidth / lineWidth)
  8102. : 0;
  8103. textLine = textLine.substr(0, subLength);
  8104. lineWidth = getWidth(textLine, font);
  8105. }
  8106. if (textLine === '') {
  8107. textLine = options.placeholder;
  8108. }
  8109. return textLine;
  8110. }
  8111. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  8112. var width = 0;
  8113. var i = 0;
  8114. for (var len = text.length; i < len && width < contentWidth; i++) {
  8115. var charCode = text.charCodeAt(i);
  8116. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  8117. }
  8118. return i;
  8119. }
  8120. function parsePlainText(text, style) {
  8121. text != null && (text += '');
  8122. var overflow = style.overflow;
  8123. var padding = style.padding;
  8124. var font = style.font;
  8125. var truncate = overflow === 'truncate';
  8126. var calculatedLineHeight = getLineHeight(font);
  8127. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  8128. var truncateLineOverflow = style.lineOverflow === 'truncate';
  8129. var width = style.width;
  8130. var lines;
  8131. if (width != null && overflow === 'break' || overflow === 'breakAll') {
  8132. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  8133. }
  8134. else {
  8135. lines = text ? text.split('\n') : [];
  8136. }
  8137. var contentHeight = lines.length * lineHeight;
  8138. var height = retrieve2(style.height, contentHeight);
  8139. if (contentHeight > height && truncateLineOverflow) {
  8140. var lineCount = Math.floor(height / lineHeight);
  8141. lines = lines.slice(0, lineCount);
  8142. }
  8143. var outerHeight = height;
  8144. var outerWidth = width;
  8145. if (padding) {
  8146. outerHeight += padding[0] + padding[2];
  8147. if (outerWidth != null) {
  8148. outerWidth += padding[1] + padding[3];
  8149. }
  8150. }
  8151. if (text && truncate && outerWidth != null) {
  8152. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  8153. minChar: style.truncateMinChar,
  8154. placeholder: style.placeholder
  8155. });
  8156. for (var i = 0; i < lines.length; i++) {
  8157. lines[i] = truncateSingleLine(lines[i], options);
  8158. }
  8159. }
  8160. if (width == null) {
  8161. var maxWidth = 0;
  8162. for (var i = 0; i < lines.length; i++) {
  8163. maxWidth = Math.max(getWidth(lines[i], font), maxWidth);
  8164. }
  8165. width = maxWidth;
  8166. }
  8167. return {
  8168. lines: lines,
  8169. height: height,
  8170. outerHeight: outerHeight,
  8171. lineHeight: lineHeight,
  8172. calculatedLineHeight: calculatedLineHeight,
  8173. contentHeight: contentHeight,
  8174. width: width
  8175. };
  8176. }
  8177. var RichTextToken = (function () {
  8178. function RichTextToken() {
  8179. }
  8180. return RichTextToken;
  8181. }());
  8182. var RichTextLine = (function () {
  8183. function RichTextLine(tokens) {
  8184. this.tokens = [];
  8185. if (tokens) {
  8186. this.tokens = tokens;
  8187. }
  8188. }
  8189. return RichTextLine;
  8190. }());
  8191. var RichTextContentBlock = (function () {
  8192. function RichTextContentBlock() {
  8193. this.width = 0;
  8194. this.height = 0;
  8195. this.contentWidth = 0;
  8196. this.contentHeight = 0;
  8197. this.outerWidth = 0;
  8198. this.outerHeight = 0;
  8199. this.lines = [];
  8200. }
  8201. return RichTextContentBlock;
  8202. }());
  8203. function parseRichText(text, style) {
  8204. var contentBlock = new RichTextContentBlock();
  8205. text != null && (text += '');
  8206. if (!text) {
  8207. return contentBlock;
  8208. }
  8209. var topWidth = style.width;
  8210. var topHeight = style.height;
  8211. var overflow = style.overflow;
  8212. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  8213. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  8214. : null;
  8215. var lastIndex = STYLE_REG.lastIndex = 0;
  8216. var result;
  8217. while ((result = STYLE_REG.exec(text)) != null) {
  8218. var matchedIndex = result.index;
  8219. if (matchedIndex > lastIndex) {
  8220. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  8221. }
  8222. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  8223. lastIndex = STYLE_REG.lastIndex;
  8224. }
  8225. if (lastIndex < text.length) {
  8226. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  8227. }
  8228. var pendingList = [];
  8229. var calculatedHeight = 0;
  8230. var calculatedWidth = 0;
  8231. var stlPadding = style.padding;
  8232. var truncate = overflow === 'truncate';
  8233. var truncateLine = style.lineOverflow === 'truncate';
  8234. function finishLine(line, lineWidth, lineHeight) {
  8235. line.width = lineWidth;
  8236. line.lineHeight = lineHeight;
  8237. calculatedHeight += lineHeight;
  8238. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  8239. }
  8240. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  8241. var line = contentBlock.lines[i];
  8242. var lineHeight = 0;
  8243. var lineWidth = 0;
  8244. for (var j = 0; j < line.tokens.length; j++) {
  8245. var token = line.tokens[j];
  8246. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  8247. var textPadding = token.textPadding = tokenStyle.padding;
  8248. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  8249. var font = token.font = tokenStyle.font || style.font;
  8250. token.contentHeight = getLineHeight(font);
  8251. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  8252. token.innerHeight = tokenHeight;
  8253. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  8254. token.height = tokenHeight;
  8255. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  8256. token.align = tokenStyle && tokenStyle.align || style.align;
  8257. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  8258. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  8259. if (j > 0) {
  8260. line.tokens = line.tokens.slice(0, j);
  8261. finishLine(line, lineWidth, lineHeight);
  8262. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  8263. }
  8264. else {
  8265. contentBlock.lines = contentBlock.lines.slice(0, i);
  8266. }
  8267. break outer;
  8268. }
  8269. var styleTokenWidth = tokenStyle.width;
  8270. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  8271. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  8272. token.percentWidth = styleTokenWidth;
  8273. pendingList.push(token);
  8274. token.contentWidth = getWidth(token.text, font);
  8275. }
  8276. else {
  8277. if (tokenWidthNotSpecified) {
  8278. var textBackgroundColor = tokenStyle.backgroundColor;
  8279. var bgImg = textBackgroundColor && textBackgroundColor.image;
  8280. if (bgImg) {
  8281. bgImg = findExistImage(bgImg);
  8282. if (isImageReady(bgImg)) {
  8283. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  8284. }
  8285. }
  8286. }
  8287. var remainTruncWidth = truncate && topWidth != null
  8288. ? topWidth - lineWidth : null;
  8289. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  8290. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  8291. token.text = '';
  8292. token.width = token.contentWidth = 0;
  8293. }
  8294. else {
  8295. token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  8296. token.width = token.contentWidth = getWidth(token.text, font);
  8297. }
  8298. }
  8299. else {
  8300. token.contentWidth = getWidth(token.text, font);
  8301. }
  8302. }
  8303. token.width += paddingH;
  8304. lineWidth += token.width;
  8305. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  8306. }
  8307. finishLine(line, lineWidth, lineHeight);
  8308. }
  8309. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  8310. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  8311. contentBlock.contentHeight = calculatedHeight;
  8312. contentBlock.contentWidth = calculatedWidth;
  8313. if (stlPadding) {
  8314. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  8315. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  8316. }
  8317. for (var i = 0; i < pendingList.length; i++) {
  8318. var token = pendingList[i];
  8319. var percentWidth = token.percentWidth;
  8320. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  8321. }
  8322. return contentBlock;
  8323. }
  8324. function pushTokens(block, str, style, wrapInfo, styleName) {
  8325. var isEmptyStr = str === '';
  8326. var tokenStyle = styleName && style.rich[styleName] || {};
  8327. var lines = block.lines;
  8328. var font = tokenStyle.font || style.font;
  8329. var newLine = false;
  8330. var strLines;
  8331. var linesWidths;
  8332. if (wrapInfo) {
  8333. var tokenPadding = tokenStyle.padding;
  8334. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  8335. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  8336. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  8337. if (lines.length > 0) {
  8338. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  8339. strLines = str.split('\n');
  8340. newLine = true;
  8341. }
  8342. }
  8343. wrapInfo.accumWidth = outerWidth_1;
  8344. }
  8345. else {
  8346. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  8347. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  8348. linesWidths = res.linesWidths;
  8349. strLines = res.lines;
  8350. }
  8351. }
  8352. else {
  8353. strLines = str.split('\n');
  8354. }
  8355. for (var i = 0; i < strLines.length; i++) {
  8356. var text = strLines[i];
  8357. var token = new RichTextToken();
  8358. token.styleName = styleName;
  8359. token.text = text;
  8360. token.isLineHolder = !text && !isEmptyStr;
  8361. if (typeof tokenStyle.width === 'number') {
  8362. token.width = tokenStyle.width;
  8363. }
  8364. else {
  8365. token.width = linesWidths
  8366. ? linesWidths[i]
  8367. : getWidth(text, font);
  8368. }
  8369. if (!i && !newLine) {
  8370. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  8371. var tokensLen = tokens.length;
  8372. (tokensLen === 1 && tokens[0].isLineHolder)
  8373. ? (tokens[0] = token)
  8374. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  8375. }
  8376. else {
  8377. lines.push(new RichTextLine([token]));
  8378. }
  8379. }
  8380. }
  8381. function isLatin(ch) {
  8382. var code = ch.charCodeAt(0);
  8383. return code >= 0x21 && code <= 0xFF;
  8384. }
  8385. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  8386. obj[ch] = true;
  8387. return obj;
  8388. }, {});
  8389. function isWordBreakChar(ch) {
  8390. if (isLatin(ch)) {
  8391. if (breakCharMap[ch]) {
  8392. return true;
  8393. }
  8394. return false;
  8395. }
  8396. return true;
  8397. }
  8398. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  8399. var lines = [];
  8400. var linesWidths = [];
  8401. var line = '';
  8402. var currentWord = '';
  8403. var currentWordWidth = 0;
  8404. var accumWidth = 0;
  8405. for (var i = 0; i < text.length; i++) {
  8406. var ch = text.charAt(i);
  8407. if (ch === '\n') {
  8408. if (currentWord) {
  8409. line += currentWord;
  8410. accumWidth += currentWordWidth;
  8411. }
  8412. lines.push(line);
  8413. linesWidths.push(accumWidth);
  8414. line = '';
  8415. currentWord = '';
  8416. currentWordWidth = 0;
  8417. accumWidth = 0;
  8418. continue;
  8419. }
  8420. var chWidth = getWidth(ch, font);
  8421. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  8422. if (!lines.length
  8423. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  8424. : accumWidth + chWidth > lineWidth) {
  8425. if (!accumWidth) {
  8426. if (inWord) {
  8427. lines.push(currentWord);
  8428. linesWidths.push(currentWordWidth);
  8429. currentWord = ch;
  8430. currentWordWidth = chWidth;
  8431. }
  8432. else {
  8433. lines.push(ch);
  8434. linesWidths.push(chWidth);
  8435. }
  8436. }
  8437. else if (line || currentWord) {
  8438. if (inWord) {
  8439. if (!line) {
  8440. line = currentWord;
  8441. currentWord = '';
  8442. currentWordWidth = 0;
  8443. accumWidth = currentWordWidth;
  8444. }
  8445. lines.push(line);
  8446. linesWidths.push(accumWidth - currentWordWidth);
  8447. currentWord += ch;
  8448. currentWordWidth += chWidth;
  8449. line = '';
  8450. accumWidth = currentWordWidth;
  8451. }
  8452. else {
  8453. if (currentWord) {
  8454. line += currentWord;
  8455. accumWidth += currentWordWidth;
  8456. currentWord = '';
  8457. currentWordWidth = 0;
  8458. }
  8459. lines.push(line);
  8460. linesWidths.push(accumWidth);
  8461. line = ch;
  8462. accumWidth = chWidth;
  8463. }
  8464. }
  8465. continue;
  8466. }
  8467. accumWidth += chWidth;
  8468. if (inWord) {
  8469. currentWord += ch;
  8470. currentWordWidth += chWidth;
  8471. }
  8472. else {
  8473. if (currentWord) {
  8474. line += currentWord;
  8475. currentWord = '';
  8476. currentWordWidth = 0;
  8477. }
  8478. line += ch;
  8479. }
  8480. }
  8481. if (!lines.length && !line) {
  8482. line = text;
  8483. currentWord = '';
  8484. currentWordWidth = 0;
  8485. }
  8486. if (currentWord) {
  8487. line += currentWord;
  8488. }
  8489. if (line) {
  8490. lines.push(line);
  8491. linesWidths.push(accumWidth);
  8492. }
  8493. if (lines.length === 1) {
  8494. accumWidth += lastAccumWidth;
  8495. }
  8496. return {
  8497. accumWidth: accumWidth,
  8498. lines: lines,
  8499. linesWidths: linesWidths
  8500. };
  8501. }
  8502. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  8503. var DEFAULT_COMMON_STYLE = {
  8504. shadowBlur: 0,
  8505. shadowOffsetX: 0,
  8506. shadowOffsetY: 0,
  8507. shadowColor: '#000',
  8508. opacity: 1,
  8509. blend: 'source-over'
  8510. };
  8511. var DEFAULT_COMMON_ANIMATION_PROPS = {
  8512. style: {
  8513. shadowBlur: true,
  8514. shadowOffsetX: true,
  8515. shadowOffsetY: true,
  8516. shadowColor: true,
  8517. opacity: true
  8518. }
  8519. };
  8520. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  8521. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  8522. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  8523. var Displayable = (function (_super) {
  8524. __extends(Displayable, _super);
  8525. function Displayable(props) {
  8526. return _super.call(this, props) || this;
  8527. }
  8528. Displayable.prototype._init = function (props) {
  8529. var keysArr = keys(props);
  8530. for (var i = 0; i < keysArr.length; i++) {
  8531. var key = keysArr[i];
  8532. if (key === 'style') {
  8533. this.useStyle(props[key]);
  8534. }
  8535. else {
  8536. _super.prototype.attrKV.call(this, key, props[key]);
  8537. }
  8538. }
  8539. if (!this.style) {
  8540. this.useStyle({});
  8541. }
  8542. };
  8543. Displayable.prototype.beforeBrush = function () { };
  8544. Displayable.prototype.afterBrush = function () { };
  8545. Displayable.prototype.innerBeforeBrush = function () { };
  8546. Displayable.prototype.innerAfterBrush = function () { };
  8547. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  8548. var m = this.transform;
  8549. if (this.ignore
  8550. || this.invisible
  8551. || this.style.opacity === 0
  8552. || (this.culling
  8553. && isDisplayableCulled(this, viewWidth, viewHeight))
  8554. || (m && !m[0] && !m[3])) {
  8555. return false;
  8556. }
  8557. if (considerClipPath && this.__clipPaths) {
  8558. for (var i = 0; i < this.__clipPaths.length; ++i) {
  8559. if (this.__clipPaths[i].isZeroArea()) {
  8560. return false;
  8561. }
  8562. }
  8563. }
  8564. if (considerAncestors && this.parent) {
  8565. var parent_1 = this.parent;
  8566. while (parent_1) {
  8567. if (parent_1.ignore) {
  8568. return false;
  8569. }
  8570. parent_1 = parent_1.parent;
  8571. }
  8572. }
  8573. return true;
  8574. };
  8575. Displayable.prototype.contain = function (x, y) {
  8576. return this.rectContain(x, y);
  8577. };
  8578. Displayable.prototype.traverse = function (cb, context) {
  8579. cb.call(context, this);
  8580. };
  8581. Displayable.prototype.rectContain = function (x, y) {
  8582. var coord = this.transformCoordToLocal(x, y);
  8583. var rect = this.getBoundingRect();
  8584. return rect.contain(coord[0], coord[1]);
  8585. };
  8586. Displayable.prototype.getPaintRect = function () {
  8587. var rect = this._paintRect;
  8588. if (!this._paintRect || this.__dirty) {
  8589. var transform = this.transform;
  8590. var elRect = this.getBoundingRect();
  8591. var style = this.style;
  8592. var shadowSize = style.shadowBlur || 0;
  8593. var shadowOffsetX = style.shadowOffsetX || 0;
  8594. var shadowOffsetY = style.shadowOffsetY || 0;
  8595. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  8596. if (transform) {
  8597. BoundingRect.applyTransform(rect, elRect, transform);
  8598. }
  8599. else {
  8600. rect.copy(elRect);
  8601. }
  8602. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  8603. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  8604. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  8605. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  8606. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  8607. }
  8608. var tolerance = this.dirtyRectTolerance;
  8609. if (!rect.isZero()) {
  8610. rect.x = Math.floor(rect.x - tolerance);
  8611. rect.y = Math.floor(rect.y - tolerance);
  8612. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  8613. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  8614. }
  8615. }
  8616. return rect;
  8617. };
  8618. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  8619. if (paintRect) {
  8620. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  8621. this._prevPaintRect.copy(paintRect);
  8622. }
  8623. else {
  8624. this._prevPaintRect = null;
  8625. }
  8626. };
  8627. Displayable.prototype.getPrevPaintRect = function () {
  8628. return this._prevPaintRect;
  8629. };
  8630. Displayable.prototype.animateStyle = function (loop) {
  8631. return this.animate('style', loop);
  8632. };
  8633. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  8634. if (targetKey === 'style') {
  8635. this.dirtyStyle();
  8636. }
  8637. else {
  8638. this.markRedraw();
  8639. }
  8640. };
  8641. Displayable.prototype.attrKV = function (key, value) {
  8642. if (key !== 'style') {
  8643. _super.prototype.attrKV.call(this, key, value);
  8644. }
  8645. else {
  8646. if (!this.style) {
  8647. this.useStyle(value);
  8648. }
  8649. else {
  8650. this.setStyle(value);
  8651. }
  8652. }
  8653. };
  8654. Displayable.prototype.setStyle = function (keyOrObj, value) {
  8655. if (typeof keyOrObj === 'string') {
  8656. this.style[keyOrObj] = value;
  8657. }
  8658. else {
  8659. extend(this.style, keyOrObj);
  8660. }
  8661. this.dirtyStyle();
  8662. return this;
  8663. };
  8664. Displayable.prototype.dirtyStyle = function (notRedraw) {
  8665. if (!notRedraw) {
  8666. this.markRedraw();
  8667. }
  8668. this.__dirty |= STYLE_CHANGED_BIT;
  8669. if (this._rect) {
  8670. this._rect = null;
  8671. }
  8672. };
  8673. Displayable.prototype.dirty = function () {
  8674. this.dirtyStyle();
  8675. };
  8676. Displayable.prototype.styleChanged = function () {
  8677. return !!(this.__dirty & STYLE_CHANGED_BIT);
  8678. };
  8679. Displayable.prototype.styleUpdated = function () {
  8680. this.__dirty &= ~STYLE_CHANGED_BIT;
  8681. };
  8682. Displayable.prototype.createStyle = function (obj) {
  8683. return createObject(DEFAULT_COMMON_STYLE, obj);
  8684. };
  8685. Displayable.prototype.useStyle = function (obj) {
  8686. if (!obj[STYLE_MAGIC_KEY]) {
  8687. obj = this.createStyle(obj);
  8688. }
  8689. if (this.__inHover) {
  8690. this.__hoverStyle = obj;
  8691. }
  8692. else {
  8693. this.style = obj;
  8694. }
  8695. this.dirtyStyle();
  8696. };
  8697. Displayable.prototype.isStyleObject = function (obj) {
  8698. return obj[STYLE_MAGIC_KEY];
  8699. };
  8700. Displayable.prototype._innerSaveToNormal = function (toState) {
  8701. _super.prototype._innerSaveToNormal.call(this, toState);
  8702. var normalState = this._normalState;
  8703. if (toState.style && !normalState.style) {
  8704. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  8705. }
  8706. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  8707. };
  8708. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  8709. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  8710. var needsRestoreToNormal = !(state && keepCurrentStates);
  8711. var targetStyle;
  8712. if (state && state.style) {
  8713. if (transition) {
  8714. if (keepCurrentStates) {
  8715. targetStyle = state.style;
  8716. }
  8717. else {
  8718. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  8719. this._mergeStyle(targetStyle, state.style);
  8720. }
  8721. }
  8722. else {
  8723. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  8724. this._mergeStyle(targetStyle, state.style);
  8725. }
  8726. }
  8727. else if (needsRestoreToNormal) {
  8728. targetStyle = normalState.style;
  8729. }
  8730. if (targetStyle) {
  8731. if (transition) {
  8732. var sourceStyle = this.style;
  8733. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  8734. if (needsRestoreToNormal) {
  8735. var changedKeys = keys(sourceStyle);
  8736. for (var i = 0; i < changedKeys.length; i++) {
  8737. var key = changedKeys[i];
  8738. if (key in targetStyle) {
  8739. targetStyle[key] = targetStyle[key];
  8740. this.style[key] = sourceStyle[key];
  8741. }
  8742. }
  8743. }
  8744. var targetKeys = keys(targetStyle);
  8745. for (var i = 0; i < targetKeys.length; i++) {
  8746. var key = targetKeys[i];
  8747. this.style[key] = this.style[key];
  8748. }
  8749. this._transitionState(stateName, {
  8750. style: targetStyle
  8751. }, animationCfg, this.getAnimationStyleProps());
  8752. }
  8753. else {
  8754. this.useStyle(targetStyle);
  8755. }
  8756. }
  8757. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  8758. for (var i = 0; i < statesKeys.length; i++) {
  8759. var key = statesKeys[i];
  8760. if (state && state[key] != null) {
  8761. this[key] = state[key];
  8762. }
  8763. else if (needsRestoreToNormal) {
  8764. if (normalState[key] != null) {
  8765. this[key] = normalState[key];
  8766. }
  8767. }
  8768. }
  8769. };
  8770. Displayable.prototype._mergeStates = function (states) {
  8771. var mergedState = _super.prototype._mergeStates.call(this, states);
  8772. var mergedStyle;
  8773. for (var i = 0; i < states.length; i++) {
  8774. var state = states[i];
  8775. if (state.style) {
  8776. mergedStyle = mergedStyle || {};
  8777. this._mergeStyle(mergedStyle, state.style);
  8778. }
  8779. }
  8780. if (mergedStyle) {
  8781. mergedState.style = mergedStyle;
  8782. }
  8783. return mergedState;
  8784. };
  8785. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  8786. extend(targetStyle, sourceStyle);
  8787. return targetStyle;
  8788. };
  8789. Displayable.prototype.getAnimationStyleProps = function () {
  8790. return DEFAULT_COMMON_ANIMATION_PROPS;
  8791. };
  8792. Displayable.initDefaultProps = (function () {
  8793. var dispProto = Displayable.prototype;
  8794. dispProto.type = 'displayable';
  8795. dispProto.invisible = false;
  8796. dispProto.z = 0;
  8797. dispProto.z2 = 0;
  8798. dispProto.zlevel = 0;
  8799. dispProto.culling = false;
  8800. dispProto.cursor = 'pointer';
  8801. dispProto.rectHover = false;
  8802. dispProto.incremental = false;
  8803. dispProto._rect = null;
  8804. dispProto.dirtyRectTolerance = 0;
  8805. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  8806. })();
  8807. return Displayable;
  8808. }(Element));
  8809. var tmpRect = new BoundingRect(0, 0, 0, 0);
  8810. var viewRect = new BoundingRect(0, 0, 0, 0);
  8811. function isDisplayableCulled(el, width, height) {
  8812. tmpRect.copy(el.getBoundingRect());
  8813. if (el.transform) {
  8814. tmpRect.applyTransform(el.transform);
  8815. }
  8816. viewRect.width = width;
  8817. viewRect.height = height;
  8818. return !tmpRect.intersect(viewRect);
  8819. }
  8820. var mathPow = Math.pow;
  8821. var mathSqrt = Math.sqrt;
  8822. var EPSILON$1 = 1e-8;
  8823. var EPSILON_NUMERIC = 1e-4;
  8824. var THREE_SQRT = mathSqrt(3);
  8825. var ONE_THIRD = 1 / 3;
  8826. var _v0 = create();
  8827. var _v1 = create();
  8828. var _v2 = create();
  8829. function isAroundZero(val) {
  8830. return val > -EPSILON$1 && val < EPSILON$1;
  8831. }
  8832. function isNotAroundZero$1(val) {
  8833. return val > EPSILON$1 || val < -EPSILON$1;
  8834. }
  8835. function cubicAt(p0, p1, p2, p3, t) {
  8836. var onet = 1 - t;
  8837. return onet * onet * (onet * p0 + 3 * t * p1)
  8838. + t * t * (t * p3 + 3 * onet * p2);
  8839. }
  8840. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  8841. var onet = 1 - t;
  8842. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  8843. + (p3 - p2) * t * t);
  8844. }
  8845. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  8846. var a = p3 + 3 * (p1 - p2) - p0;
  8847. var b = 3 * (p2 - p1 * 2 + p0);
  8848. var c = 3 * (p1 - p0);
  8849. var d = p0 - val;
  8850. var A = b * b - 3 * a * c;
  8851. var B = b * c - 9 * a * d;
  8852. var C = c * c - 3 * b * d;
  8853. var n = 0;
  8854. if (isAroundZero(A) && isAroundZero(B)) {
  8855. if (isAroundZero(b)) {
  8856. roots[0] = 0;
  8857. }
  8858. else {
  8859. var t1 = -c / b;
  8860. if (t1 >= 0 && t1 <= 1) {
  8861. roots[n++] = t1;
  8862. }
  8863. }
  8864. }
  8865. else {
  8866. var disc = B * B - 4 * A * C;
  8867. if (isAroundZero(disc)) {
  8868. var K = B / A;
  8869. var t1 = -b / a + K;
  8870. var t2 = -K / 2;
  8871. if (t1 >= 0 && t1 <= 1) {
  8872. roots[n++] = t1;
  8873. }
  8874. if (t2 >= 0 && t2 <= 1) {
  8875. roots[n++] = t2;
  8876. }
  8877. }
  8878. else if (disc > 0) {
  8879. var discSqrt = mathSqrt(disc);
  8880. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  8881. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  8882. if (Y1 < 0) {
  8883. Y1 = -mathPow(-Y1, ONE_THIRD);
  8884. }
  8885. else {
  8886. Y1 = mathPow(Y1, ONE_THIRD);
  8887. }
  8888. if (Y2 < 0) {
  8889. Y2 = -mathPow(-Y2, ONE_THIRD);
  8890. }
  8891. else {
  8892. Y2 = mathPow(Y2, ONE_THIRD);
  8893. }
  8894. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  8895. if (t1 >= 0 && t1 <= 1) {
  8896. roots[n++] = t1;
  8897. }
  8898. }
  8899. else {
  8900. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  8901. var theta = Math.acos(T) / 3;
  8902. var ASqrt = mathSqrt(A);
  8903. var tmp = Math.cos(theta);
  8904. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  8905. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  8906. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  8907. if (t1 >= 0 && t1 <= 1) {
  8908. roots[n++] = t1;
  8909. }
  8910. if (t2 >= 0 && t2 <= 1) {
  8911. roots[n++] = t2;
  8912. }
  8913. if (t3 >= 0 && t3 <= 1) {
  8914. roots[n++] = t3;
  8915. }
  8916. }
  8917. }
  8918. return n;
  8919. }
  8920. function cubicExtrema(p0, p1, p2, p3, extrema) {
  8921. var b = 6 * p2 - 12 * p1 + 6 * p0;
  8922. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  8923. var c = 3 * p1 - 3 * p0;
  8924. var n = 0;
  8925. if (isAroundZero(a)) {
  8926. if (isNotAroundZero$1(b)) {
  8927. var t1 = -c / b;
  8928. if (t1 >= 0 && t1 <= 1) {
  8929. extrema[n++] = t1;
  8930. }
  8931. }
  8932. }
  8933. else {
  8934. var disc = b * b - 4 * a * c;
  8935. if (isAroundZero(disc)) {
  8936. extrema[0] = -b / (2 * a);
  8937. }
  8938. else if (disc > 0) {
  8939. var discSqrt = mathSqrt(disc);
  8940. var t1 = (-b + discSqrt) / (2 * a);
  8941. var t2 = (-b - discSqrt) / (2 * a);
  8942. if (t1 >= 0 && t1 <= 1) {
  8943. extrema[n++] = t1;
  8944. }
  8945. if (t2 >= 0 && t2 <= 1) {
  8946. extrema[n++] = t2;
  8947. }
  8948. }
  8949. }
  8950. return n;
  8951. }
  8952. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  8953. var p01 = (p1 - p0) * t + p0;
  8954. var p12 = (p2 - p1) * t + p1;
  8955. var p23 = (p3 - p2) * t + p2;
  8956. var p012 = (p12 - p01) * t + p01;
  8957. var p123 = (p23 - p12) * t + p12;
  8958. var p0123 = (p123 - p012) * t + p012;
  8959. out[0] = p0;
  8960. out[1] = p01;
  8961. out[2] = p012;
  8962. out[3] = p0123;
  8963. out[4] = p0123;
  8964. out[5] = p123;
  8965. out[6] = p23;
  8966. out[7] = p3;
  8967. }
  8968. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  8969. var t;
  8970. var interval = 0.005;
  8971. var d = Infinity;
  8972. var prev;
  8973. var next;
  8974. var d1;
  8975. var d2;
  8976. _v0[0] = x;
  8977. _v0[1] = y;
  8978. for (var _t = 0; _t < 1; _t += 0.05) {
  8979. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  8980. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  8981. d1 = distSquare(_v0, _v1);
  8982. if (d1 < d) {
  8983. t = _t;
  8984. d = d1;
  8985. }
  8986. }
  8987. d = Infinity;
  8988. for (var i = 0; i < 32; i++) {
  8989. if (interval < EPSILON_NUMERIC) {
  8990. break;
  8991. }
  8992. prev = t - interval;
  8993. next = t + interval;
  8994. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  8995. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  8996. d1 = distSquare(_v1, _v0);
  8997. if (prev >= 0 && d1 < d) {
  8998. t = prev;
  8999. d = d1;
  9000. }
  9001. else {
  9002. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  9003. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  9004. d2 = distSquare(_v2, _v0);
  9005. if (next <= 1 && d2 < d) {
  9006. t = next;
  9007. d = d2;
  9008. }
  9009. else {
  9010. interval *= 0.5;
  9011. }
  9012. }
  9013. }
  9014. if (out) {
  9015. out[0] = cubicAt(x0, x1, x2, x3, t);
  9016. out[1] = cubicAt(y0, y1, y2, y3, t);
  9017. }
  9018. return mathSqrt(d);
  9019. }
  9020. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  9021. var px = x0;
  9022. var py = y0;
  9023. var d = 0;
  9024. var step = 1 / iteration;
  9025. for (var i = 1; i <= iteration; i++) {
  9026. var t = i * step;
  9027. var x = cubicAt(x0, x1, x2, x3, t);
  9028. var y = cubicAt(y0, y1, y2, y3, t);
  9029. var dx = x - px;
  9030. var dy = y - py;
  9031. d += Math.sqrt(dx * dx + dy * dy);
  9032. px = x;
  9033. py = y;
  9034. }
  9035. return d;
  9036. }
  9037. function quadraticAt(p0, p1, p2, t) {
  9038. var onet = 1 - t;
  9039. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  9040. }
  9041. function quadraticDerivativeAt(p0, p1, p2, t) {
  9042. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  9043. }
  9044. function quadraticRootAt(p0, p1, p2, val, roots) {
  9045. var a = p0 - 2 * p1 + p2;
  9046. var b = 2 * (p1 - p0);
  9047. var c = p0 - val;
  9048. var n = 0;
  9049. if (isAroundZero(a)) {
  9050. if (isNotAroundZero$1(b)) {
  9051. var t1 = -c / b;
  9052. if (t1 >= 0 && t1 <= 1) {
  9053. roots[n++] = t1;
  9054. }
  9055. }
  9056. }
  9057. else {
  9058. var disc = b * b - 4 * a * c;
  9059. if (isAroundZero(disc)) {
  9060. var t1 = -b / (2 * a);
  9061. if (t1 >= 0 && t1 <= 1) {
  9062. roots[n++] = t1;
  9063. }
  9064. }
  9065. else if (disc > 0) {
  9066. var discSqrt = mathSqrt(disc);
  9067. var t1 = (-b + discSqrt) / (2 * a);
  9068. var t2 = (-b - discSqrt) / (2 * a);
  9069. if (t1 >= 0 && t1 <= 1) {
  9070. roots[n++] = t1;
  9071. }
  9072. if (t2 >= 0 && t2 <= 1) {
  9073. roots[n++] = t2;
  9074. }
  9075. }
  9076. }
  9077. return n;
  9078. }
  9079. function quadraticExtremum(p0, p1, p2) {
  9080. var divider = p0 + p2 - 2 * p1;
  9081. if (divider === 0) {
  9082. return 0.5;
  9083. }
  9084. else {
  9085. return (p0 - p1) / divider;
  9086. }
  9087. }
  9088. function quadraticSubdivide(p0, p1, p2, t, out) {
  9089. var p01 = (p1 - p0) * t + p0;
  9090. var p12 = (p2 - p1) * t + p1;
  9091. var p012 = (p12 - p01) * t + p01;
  9092. out[0] = p0;
  9093. out[1] = p01;
  9094. out[2] = p012;
  9095. out[3] = p012;
  9096. out[4] = p12;
  9097. out[5] = p2;
  9098. }
  9099. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  9100. var t;
  9101. var interval = 0.005;
  9102. var d = Infinity;
  9103. _v0[0] = x;
  9104. _v0[1] = y;
  9105. for (var _t = 0; _t < 1; _t += 0.05) {
  9106. _v1[0] = quadraticAt(x0, x1, x2, _t);
  9107. _v1[1] = quadraticAt(y0, y1, y2, _t);
  9108. var d1 = distSquare(_v0, _v1);
  9109. if (d1 < d) {
  9110. t = _t;
  9111. d = d1;
  9112. }
  9113. }
  9114. d = Infinity;
  9115. for (var i = 0; i < 32; i++) {
  9116. if (interval < EPSILON_NUMERIC) {
  9117. break;
  9118. }
  9119. var prev = t - interval;
  9120. var next = t + interval;
  9121. _v1[0] = quadraticAt(x0, x1, x2, prev);
  9122. _v1[1] = quadraticAt(y0, y1, y2, prev);
  9123. var d1 = distSquare(_v1, _v0);
  9124. if (prev >= 0 && d1 < d) {
  9125. t = prev;
  9126. d = d1;
  9127. }
  9128. else {
  9129. _v2[0] = quadraticAt(x0, x1, x2, next);
  9130. _v2[1] = quadraticAt(y0, y1, y2, next);
  9131. var d2 = distSquare(_v2, _v0);
  9132. if (next <= 1 && d2 < d) {
  9133. t = next;
  9134. d = d2;
  9135. }
  9136. else {
  9137. interval *= 0.5;
  9138. }
  9139. }
  9140. }
  9141. if (out) {
  9142. out[0] = quadraticAt(x0, x1, x2, t);
  9143. out[1] = quadraticAt(y0, y1, y2, t);
  9144. }
  9145. return mathSqrt(d);
  9146. }
  9147. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  9148. var px = x0;
  9149. var py = y0;
  9150. var d = 0;
  9151. var step = 1 / iteration;
  9152. for (var i = 1; i <= iteration; i++) {
  9153. var t = i * step;
  9154. var x = quadraticAt(x0, x1, x2, t);
  9155. var y = quadraticAt(y0, y1, y2, t);
  9156. var dx = x - px;
  9157. var dy = y - py;
  9158. d += Math.sqrt(dx * dx + dy * dy);
  9159. px = x;
  9160. py = y;
  9161. }
  9162. return d;
  9163. }
  9164. var mathMin$1 = Math.min;
  9165. var mathMax$1 = Math.max;
  9166. var mathSin = Math.sin;
  9167. var mathCos = Math.cos;
  9168. var PI2 = Math.PI * 2;
  9169. var start = create();
  9170. var end = create();
  9171. var extremity = create();
  9172. function fromPoints(points, min, max) {
  9173. if (points.length === 0) {
  9174. return;
  9175. }
  9176. var p = points[0];
  9177. var left = p[0];
  9178. var right = p[0];
  9179. var top = p[1];
  9180. var bottom = p[1];
  9181. for (var i = 1; i < points.length; i++) {
  9182. p = points[i];
  9183. left = mathMin$1(left, p[0]);
  9184. right = mathMax$1(right, p[0]);
  9185. top = mathMin$1(top, p[1]);
  9186. bottom = mathMax$1(bottom, p[1]);
  9187. }
  9188. min[0] = left;
  9189. min[1] = top;
  9190. max[0] = right;
  9191. max[1] = bottom;
  9192. }
  9193. function fromLine(x0, y0, x1, y1, min, max) {
  9194. min[0] = mathMin$1(x0, x1);
  9195. min[1] = mathMin$1(y0, y1);
  9196. max[0] = mathMax$1(x0, x1);
  9197. max[1] = mathMax$1(y0, y1);
  9198. }
  9199. var xDim = [];
  9200. var yDim = [];
  9201. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  9202. var cubicExtrema$1 = cubicExtrema;
  9203. var cubicAt$1 = cubicAt;
  9204. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  9205. min[0] = Infinity;
  9206. min[1] = Infinity;
  9207. max[0] = -Infinity;
  9208. max[1] = -Infinity;
  9209. for (var i = 0; i < n; i++) {
  9210. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  9211. min[0] = mathMin$1(x, min[0]);
  9212. max[0] = mathMax$1(x, max[0]);
  9213. }
  9214. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  9215. for (var i = 0; i < n; i++) {
  9216. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  9217. min[1] = mathMin$1(y, min[1]);
  9218. max[1] = mathMax$1(y, max[1]);
  9219. }
  9220. min[0] = mathMin$1(x0, min[0]);
  9221. max[0] = mathMax$1(x0, max[0]);
  9222. min[0] = mathMin$1(x3, min[0]);
  9223. max[0] = mathMax$1(x3, max[0]);
  9224. min[1] = mathMin$1(y0, min[1]);
  9225. max[1] = mathMax$1(y0, max[1]);
  9226. min[1] = mathMin$1(y3, min[1]);
  9227. max[1] = mathMax$1(y3, max[1]);
  9228. }
  9229. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  9230. var quadraticExtremum$1 = quadraticExtremum;
  9231. var quadraticAt$1 = quadraticAt;
  9232. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  9233. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  9234. var x = quadraticAt$1(x0, x1, x2, tx);
  9235. var y = quadraticAt$1(y0, y1, y2, ty);
  9236. min[0] = mathMin$1(x0, x2, x);
  9237. min[1] = mathMin$1(y0, y2, y);
  9238. max[0] = mathMax$1(x0, x2, x);
  9239. max[1] = mathMax$1(y0, y2, y);
  9240. }
  9241. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  9242. var vec2Min = min;
  9243. var vec2Max = max;
  9244. var diff = Math.abs(startAngle - endAngle);
  9245. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  9246. min$1[0] = x - rx;
  9247. min$1[1] = y - ry;
  9248. max$1[0] = x + rx;
  9249. max$1[1] = y + ry;
  9250. return;
  9251. }
  9252. start[0] = mathCos(startAngle) * rx + x;
  9253. start[1] = mathSin(startAngle) * ry + y;
  9254. end[0] = mathCos(endAngle) * rx + x;
  9255. end[1] = mathSin(endAngle) * ry + y;
  9256. vec2Min(min$1, start, end);
  9257. vec2Max(max$1, start, end);
  9258. startAngle = startAngle % (PI2);
  9259. if (startAngle < 0) {
  9260. startAngle = startAngle + PI2;
  9261. }
  9262. endAngle = endAngle % (PI2);
  9263. if (endAngle < 0) {
  9264. endAngle = endAngle + PI2;
  9265. }
  9266. if (startAngle > endAngle && !anticlockwise) {
  9267. endAngle += PI2;
  9268. }
  9269. else if (startAngle < endAngle && anticlockwise) {
  9270. startAngle += PI2;
  9271. }
  9272. if (anticlockwise) {
  9273. var tmp = endAngle;
  9274. endAngle = startAngle;
  9275. startAngle = tmp;
  9276. }
  9277. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  9278. if (angle > startAngle) {
  9279. extremity[0] = mathCos(angle) * rx + x;
  9280. extremity[1] = mathSin(angle) * ry + y;
  9281. vec2Min(min$1, extremity, min$1);
  9282. vec2Max(max$1, extremity, max$1);
  9283. }
  9284. }
  9285. }
  9286. var CMD = {
  9287. M: 1,
  9288. L: 2,
  9289. C: 3,
  9290. Q: 4,
  9291. A: 5,
  9292. Z: 6,
  9293. R: 7
  9294. };
  9295. var tmpOutX = [];
  9296. var tmpOutY = [];
  9297. var min$1 = [];
  9298. var max$1 = [];
  9299. var min2 = [];
  9300. var max2 = [];
  9301. var mathMin$2 = Math.min;
  9302. var mathMax$2 = Math.max;
  9303. var mathCos$1 = Math.cos;
  9304. var mathSin$1 = Math.sin;
  9305. var mathSqrt$1 = Math.sqrt;
  9306. var mathAbs = Math.abs;
  9307. var PI = Math.PI;
  9308. var PI2$1 = PI * 2;
  9309. var hasTypedArray = typeof Float32Array !== 'undefined';
  9310. var tmpAngles = [];
  9311. function modPI2(radian) {
  9312. var n = Math.round(radian / PI * 1e8) / 1e8;
  9313. return (n % 2) * PI;
  9314. }
  9315. function normalizeArcAngles(angles, anticlockwise) {
  9316. var newStartAngle = modPI2(angles[0]);
  9317. if (newStartAngle < 0) {
  9318. newStartAngle += PI2$1;
  9319. }
  9320. var delta = newStartAngle - angles[0];
  9321. var newEndAngle = angles[1];
  9322. newEndAngle += delta;
  9323. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  9324. newEndAngle = newStartAngle + PI2$1;
  9325. }
  9326. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  9327. newEndAngle = newStartAngle - PI2$1;
  9328. }
  9329. else if (!anticlockwise && newStartAngle > newEndAngle) {
  9330. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  9331. }
  9332. else if (anticlockwise && newStartAngle < newEndAngle) {
  9333. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  9334. }
  9335. angles[0] = newStartAngle;
  9336. angles[1] = newEndAngle;
  9337. }
  9338. var PathProxy = (function () {
  9339. function PathProxy(notSaveData) {
  9340. this.dpr = 1;
  9341. this._xi = 0;
  9342. this._yi = 0;
  9343. this._x0 = 0;
  9344. this._y0 = 0;
  9345. this._len = 0;
  9346. if (notSaveData) {
  9347. this._saveData = false;
  9348. }
  9349. if (this._saveData) {
  9350. this.data = [];
  9351. }
  9352. }
  9353. PathProxy.prototype.increaseVersion = function () {
  9354. this._version++;
  9355. };
  9356. PathProxy.prototype.getVersion = function () {
  9357. return this._version;
  9358. };
  9359. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  9360. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  9361. if (segmentIgnoreThreshold > 0) {
  9362. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  9363. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  9364. }
  9365. };
  9366. PathProxy.prototype.setDPR = function (dpr) {
  9367. this.dpr = dpr;
  9368. };
  9369. PathProxy.prototype.setContext = function (ctx) {
  9370. this._ctx = ctx;
  9371. };
  9372. PathProxy.prototype.getContext = function () {
  9373. return this._ctx;
  9374. };
  9375. PathProxy.prototype.beginPath = function () {
  9376. this._ctx && this._ctx.beginPath();
  9377. this.reset();
  9378. return this;
  9379. };
  9380. PathProxy.prototype.reset = function () {
  9381. if (this._saveData) {
  9382. this._len = 0;
  9383. }
  9384. if (this._lineDash) {
  9385. this._lineDash = null;
  9386. this._dashOffset = 0;
  9387. }
  9388. if (this._pathSegLen) {
  9389. this._pathSegLen = null;
  9390. this._pathLen = 0;
  9391. }
  9392. this._version++;
  9393. };
  9394. PathProxy.prototype.moveTo = function (x, y) {
  9395. this._drawPendingPt();
  9396. this.addData(CMD.M, x, y);
  9397. this._ctx && this._ctx.moveTo(x, y);
  9398. this._x0 = x;
  9399. this._y0 = y;
  9400. this._xi = x;
  9401. this._yi = y;
  9402. return this;
  9403. };
  9404. PathProxy.prototype.lineTo = function (x, y) {
  9405. var dx = mathAbs(x - this._xi);
  9406. var dy = mathAbs(y - this._yi);
  9407. var exceedUnit = dx > this._ux || dy > this._uy;
  9408. this.addData(CMD.L, x, y);
  9409. if (this._ctx && exceedUnit) {
  9410. this._needsDash ? this._dashedLineTo(x, y)
  9411. : this._ctx.lineTo(x, y);
  9412. }
  9413. if (exceedUnit) {
  9414. this._xi = x;
  9415. this._yi = y;
  9416. this._pendingPtDist = 0;
  9417. }
  9418. else {
  9419. var d2 = dx * dx + dy * dy;
  9420. if (d2 > this._pendingPtDist) {
  9421. this._pendingPtX = x;
  9422. this._pendingPtY = y;
  9423. this._pendingPtDist = d2;
  9424. }
  9425. }
  9426. return this;
  9427. };
  9428. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  9429. this._drawPendingPt();
  9430. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  9431. if (this._ctx) {
  9432. this._needsDash ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  9433. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  9434. }
  9435. this._xi = x3;
  9436. this._yi = y3;
  9437. return this;
  9438. };
  9439. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  9440. this._drawPendingPt();
  9441. this.addData(CMD.Q, x1, y1, x2, y2);
  9442. if (this._ctx) {
  9443. this._needsDash ? this._dashedQuadraticTo(x1, y1, x2, y2)
  9444. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  9445. }
  9446. this._xi = x2;
  9447. this._yi = y2;
  9448. return this;
  9449. };
  9450. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  9451. this._drawPendingPt();
  9452. tmpAngles[0] = startAngle;
  9453. tmpAngles[1] = endAngle;
  9454. normalizeArcAngles(tmpAngles, anticlockwise);
  9455. startAngle = tmpAngles[0];
  9456. endAngle = tmpAngles[1];
  9457. var delta = endAngle - startAngle;
  9458. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  9459. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  9460. this._xi = mathCos$1(endAngle) * r + cx;
  9461. this._yi = mathSin$1(endAngle) * r + cy;
  9462. return this;
  9463. };
  9464. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  9465. this._drawPendingPt();
  9466. if (this._ctx) {
  9467. this._ctx.arcTo(x1, y1, x2, y2, radius);
  9468. }
  9469. return this;
  9470. };
  9471. PathProxy.prototype.rect = function (x, y, w, h) {
  9472. this._drawPendingPt();
  9473. this._ctx && this._ctx.rect(x, y, w, h);
  9474. this.addData(CMD.R, x, y, w, h);
  9475. return this;
  9476. };
  9477. PathProxy.prototype.closePath = function () {
  9478. this._drawPendingPt();
  9479. this.addData(CMD.Z);
  9480. var ctx = this._ctx;
  9481. var x0 = this._x0;
  9482. var y0 = this._y0;
  9483. if (ctx) {
  9484. this._needsDash && this._dashedLineTo(x0, y0);
  9485. ctx.closePath();
  9486. }
  9487. this._xi = x0;
  9488. this._yi = y0;
  9489. return this;
  9490. };
  9491. PathProxy.prototype.fill = function (ctx) {
  9492. ctx && ctx.fill();
  9493. this.toStatic();
  9494. };
  9495. PathProxy.prototype.stroke = function (ctx) {
  9496. ctx && ctx.stroke();
  9497. this.toStatic();
  9498. };
  9499. PathProxy.prototype.setLineDash = function (lineDash) {
  9500. if (lineDash instanceof Array) {
  9501. this._lineDash = lineDash;
  9502. this._dashIdx = 0;
  9503. var lineDashSum = 0;
  9504. for (var i = 0; i < lineDash.length; i++) {
  9505. lineDashSum += lineDash[i];
  9506. }
  9507. this._dashSum = lineDashSum;
  9508. this._needsDash = true;
  9509. }
  9510. else {
  9511. this._lineDash = null;
  9512. this._needsDash = false;
  9513. }
  9514. return this;
  9515. };
  9516. PathProxy.prototype.setLineDashOffset = function (offset) {
  9517. this._dashOffset = offset;
  9518. return this;
  9519. };
  9520. PathProxy.prototype.len = function () {
  9521. return this._len;
  9522. };
  9523. PathProxy.prototype.setData = function (data) {
  9524. var len = data.length;
  9525. if (!(this.data && this.data.length === len) && hasTypedArray) {
  9526. this.data = new Float32Array(len);
  9527. }
  9528. for (var i = 0; i < len; i++) {
  9529. this.data[i] = data[i];
  9530. }
  9531. this._len = len;
  9532. };
  9533. PathProxy.prototype.appendPath = function (path) {
  9534. if (!(path instanceof Array)) {
  9535. path = [path];
  9536. }
  9537. var len = path.length;
  9538. var appendSize = 0;
  9539. var offset = this._len;
  9540. for (var i = 0; i < len; i++) {
  9541. appendSize += path[i].len();
  9542. }
  9543. if (hasTypedArray && (this.data instanceof Float32Array)) {
  9544. this.data = new Float32Array(offset + appendSize);
  9545. }
  9546. for (var i = 0; i < len; i++) {
  9547. var appendPathData = path[i].data;
  9548. for (var k = 0; k < appendPathData.length; k++) {
  9549. this.data[offset++] = appendPathData[k];
  9550. }
  9551. }
  9552. this._len = offset;
  9553. };
  9554. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  9555. if (!this._saveData) {
  9556. return;
  9557. }
  9558. var data = this.data;
  9559. if (this._len + arguments.length > data.length) {
  9560. this._expandData();
  9561. data = this.data;
  9562. }
  9563. for (var i = 0; i < arguments.length; i++) {
  9564. data[this._len++] = arguments[i];
  9565. }
  9566. };
  9567. PathProxy.prototype._drawPendingPt = function () {
  9568. if (this._pendingPtDist > 0) {
  9569. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  9570. this._pendingPtDist = 0;
  9571. }
  9572. };
  9573. PathProxy.prototype._expandData = function () {
  9574. if (!(this.data instanceof Array)) {
  9575. var newData = [];
  9576. for (var i = 0; i < this._len; i++) {
  9577. newData[i] = this.data[i];
  9578. }
  9579. this.data = newData;
  9580. }
  9581. };
  9582. PathProxy.prototype._dashedLineTo = function (x1, y1) {
  9583. var dashSum = this._dashSum;
  9584. var lineDash = this._lineDash;
  9585. var ctx = this._ctx;
  9586. var offset = this._dashOffset;
  9587. var x0 = this._xi;
  9588. var y0 = this._yi;
  9589. var dx = x1 - x0;
  9590. var dy = y1 - y0;
  9591. var dist = mathSqrt$1(dx * dx + dy * dy);
  9592. var x = x0;
  9593. var y = y0;
  9594. var nDash = lineDash.length;
  9595. var dash;
  9596. var idx;
  9597. dx /= dist;
  9598. dy /= dist;
  9599. if (offset < 0) {
  9600. offset = dashSum + offset;
  9601. }
  9602. offset %= dashSum;
  9603. x -= offset * dx;
  9604. y -= offset * dy;
  9605. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  9606. || (dx === 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  9607. idx = this._dashIdx;
  9608. dash = lineDash[idx];
  9609. x += dx * dash;
  9610. y += dy * dash;
  9611. this._dashIdx = (idx + 1) % nDash;
  9612. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  9613. continue;
  9614. }
  9615. ctx[idx % 2 ? 'moveTo' : 'lineTo'](dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1), dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1));
  9616. }
  9617. dx = x - x1;
  9618. dy = y - y1;
  9619. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  9620. };
  9621. PathProxy.prototype._dashedBezierTo = function (x1, y1, x2, y2, x3, y3) {
  9622. var ctx = this._ctx;
  9623. var dashSum = this._dashSum;
  9624. var offset = this._dashOffset;
  9625. var lineDash = this._lineDash;
  9626. var x0 = this._xi;
  9627. var y0 = this._yi;
  9628. var bezierLen = 0;
  9629. var idx = this._dashIdx;
  9630. var nDash = lineDash.length;
  9631. var t;
  9632. var dx;
  9633. var dy;
  9634. var x;
  9635. var y;
  9636. var tmpLen = 0;
  9637. if (offset < 0) {
  9638. offset = dashSum + offset;
  9639. }
  9640. offset %= dashSum;
  9641. for (t = 0; t < 1; t += 0.1) {
  9642. dx = cubicAt(x0, x1, x2, x3, t + 0.1)
  9643. - cubicAt(x0, x1, x2, x3, t);
  9644. dy = cubicAt(y0, y1, y2, y3, t + 0.1)
  9645. - cubicAt(y0, y1, y2, y3, t);
  9646. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  9647. }
  9648. for (; idx < nDash; idx++) {
  9649. tmpLen += lineDash[idx];
  9650. if (tmpLen > offset) {
  9651. break;
  9652. }
  9653. }
  9654. t = (tmpLen - offset) / bezierLen;
  9655. while (t <= 1) {
  9656. x = cubicAt(x0, x1, x2, x3, t);
  9657. y = cubicAt(y0, y1, y2, y3, t);
  9658. idx % 2 ? ctx.moveTo(x, y)
  9659. : ctx.lineTo(x, y);
  9660. t += lineDash[idx] / bezierLen;
  9661. idx = (idx + 1) % nDash;
  9662. }
  9663. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  9664. dx = x3 - x;
  9665. dy = y3 - y;
  9666. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  9667. };
  9668. PathProxy.prototype._dashedQuadraticTo = function (x1, y1, x2, y2) {
  9669. var x3 = x2;
  9670. var y3 = y2;
  9671. x2 = (x2 + 2 * x1) / 3;
  9672. y2 = (y2 + 2 * y1) / 3;
  9673. x1 = (this._xi + 2 * x1) / 3;
  9674. y1 = (this._yi + 2 * y1) / 3;
  9675. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  9676. };
  9677. PathProxy.prototype.toStatic = function () {
  9678. if (!this._saveData) {
  9679. return;
  9680. }
  9681. this._drawPendingPt();
  9682. var data = this.data;
  9683. if (data instanceof Array) {
  9684. data.length = this._len;
  9685. if (hasTypedArray && this._len > 11) {
  9686. this.data = new Float32Array(data);
  9687. }
  9688. }
  9689. };
  9690. PathProxy.prototype.getBoundingRect = function () {
  9691. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  9692. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  9693. var data = this.data;
  9694. var xi = 0;
  9695. var yi = 0;
  9696. var x0 = 0;
  9697. var y0 = 0;
  9698. var i;
  9699. for (i = 0; i < this._len;) {
  9700. var cmd = data[i++];
  9701. var isFirst = i === 1;
  9702. if (isFirst) {
  9703. xi = data[i];
  9704. yi = data[i + 1];
  9705. x0 = xi;
  9706. y0 = yi;
  9707. }
  9708. switch (cmd) {
  9709. case CMD.M:
  9710. xi = x0 = data[i++];
  9711. yi = y0 = data[i++];
  9712. min2[0] = x0;
  9713. min2[1] = y0;
  9714. max2[0] = x0;
  9715. max2[1] = y0;
  9716. break;
  9717. case CMD.L:
  9718. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  9719. xi = data[i++];
  9720. yi = data[i++];
  9721. break;
  9722. case CMD.C:
  9723. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  9724. xi = data[i++];
  9725. yi = data[i++];
  9726. break;
  9727. case CMD.Q:
  9728. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  9729. xi = data[i++];
  9730. yi = data[i++];
  9731. break;
  9732. case CMD.A:
  9733. var cx = data[i++];
  9734. var cy = data[i++];
  9735. var rx = data[i++];
  9736. var ry = data[i++];
  9737. var startAngle = data[i++];
  9738. var endAngle = data[i++] + startAngle;
  9739. i += 1;
  9740. var anticlockwise = !data[i++];
  9741. if (isFirst) {
  9742. x0 = mathCos$1(startAngle) * rx + cx;
  9743. y0 = mathSin$1(startAngle) * ry + cy;
  9744. }
  9745. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  9746. xi = mathCos$1(endAngle) * rx + cx;
  9747. yi = mathSin$1(endAngle) * ry + cy;
  9748. break;
  9749. case CMD.R:
  9750. x0 = xi = data[i++];
  9751. y0 = yi = data[i++];
  9752. var width = data[i++];
  9753. var height = data[i++];
  9754. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  9755. break;
  9756. case CMD.Z:
  9757. xi = x0;
  9758. yi = y0;
  9759. break;
  9760. }
  9761. min(min$1, min$1, min2);
  9762. max(max$1, max$1, max2);
  9763. }
  9764. if (i === 0) {
  9765. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  9766. }
  9767. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  9768. };
  9769. PathProxy.prototype._calculateLength = function () {
  9770. var data = this.data;
  9771. var len = this._len;
  9772. var ux = this._ux;
  9773. var uy = this._uy;
  9774. var xi = 0;
  9775. var yi = 0;
  9776. var x0 = 0;
  9777. var y0 = 0;
  9778. if (!this._pathSegLen) {
  9779. this._pathSegLen = [];
  9780. }
  9781. var pathSegLen = this._pathSegLen;
  9782. var pathTotalLen = 0;
  9783. var segCount = 0;
  9784. for (var i = 0; i < len;) {
  9785. var cmd = data[i++];
  9786. var isFirst = i === 1;
  9787. if (isFirst) {
  9788. xi = data[i];
  9789. yi = data[i + 1];
  9790. x0 = xi;
  9791. y0 = yi;
  9792. }
  9793. var l = -1;
  9794. switch (cmd) {
  9795. case CMD.M:
  9796. xi = x0 = data[i++];
  9797. yi = y0 = data[i++];
  9798. break;
  9799. case CMD.L: {
  9800. var x2 = data[i++];
  9801. var y2 = data[i++];
  9802. var dx = x2 - xi;
  9803. var dy = y2 - yi;
  9804. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  9805. l = Math.sqrt(dx * dx + dy * dy);
  9806. xi = x2;
  9807. yi = y2;
  9808. }
  9809. break;
  9810. }
  9811. case CMD.C: {
  9812. var x1 = data[i++];
  9813. var y1 = data[i++];
  9814. var x2 = data[i++];
  9815. var y2 = data[i++];
  9816. var x3 = data[i++];
  9817. var y3 = data[i++];
  9818. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  9819. xi = x3;
  9820. yi = y3;
  9821. break;
  9822. }
  9823. case CMD.Q: {
  9824. var x1 = data[i++];
  9825. var y1 = data[i++];
  9826. var x2 = data[i++];
  9827. var y2 = data[i++];
  9828. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  9829. xi = x2;
  9830. yi = y2;
  9831. break;
  9832. }
  9833. case CMD.A:
  9834. var cx = data[i++];
  9835. var cy = data[i++];
  9836. var rx = data[i++];
  9837. var ry = data[i++];
  9838. var startAngle = data[i++];
  9839. var delta = data[i++];
  9840. var endAngle = delta + startAngle;
  9841. i += 1;
  9842. var anticlockwise = !data[i++];
  9843. if (isFirst) {
  9844. x0 = mathCos$1(startAngle) * rx + cx;
  9845. y0 = mathSin$1(startAngle) * ry + cy;
  9846. }
  9847. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  9848. xi = mathCos$1(endAngle) * rx + cx;
  9849. yi = mathSin$1(endAngle) * ry + cy;
  9850. break;
  9851. case CMD.R: {
  9852. x0 = xi = data[i++];
  9853. y0 = yi = data[i++];
  9854. var width = data[i++];
  9855. var height = data[i++];
  9856. l = width * 2 + height * 2;
  9857. break;
  9858. }
  9859. case CMD.Z: {
  9860. var dx = x0 - xi;
  9861. var dy = y0 - yi;
  9862. l = Math.sqrt(dx * dx + dy * dy);
  9863. xi = x0;
  9864. yi = y0;
  9865. break;
  9866. }
  9867. }
  9868. if (l >= 0) {
  9869. pathSegLen[segCount++] = l;
  9870. pathTotalLen += l;
  9871. }
  9872. }
  9873. this._pathLen = pathTotalLen;
  9874. return pathTotalLen;
  9875. };
  9876. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  9877. var d = this.data;
  9878. var ux = this._ux;
  9879. var uy = this._uy;
  9880. var len = this._len;
  9881. var x0;
  9882. var y0;
  9883. var xi;
  9884. var yi;
  9885. var x;
  9886. var y;
  9887. var drawPart = percent < 1;
  9888. var pathSegLen;
  9889. var pathTotalLen;
  9890. var accumLength = 0;
  9891. var segCount = 0;
  9892. var displayedLength;
  9893. var pendingPtDist = 0;
  9894. var pendingPtX;
  9895. var pendingPtY;
  9896. if (drawPart) {
  9897. if (!this._pathSegLen) {
  9898. this._calculateLength();
  9899. }
  9900. pathSegLen = this._pathSegLen;
  9901. pathTotalLen = this._pathLen;
  9902. displayedLength = percent * pathTotalLen;
  9903. if (!displayedLength) {
  9904. return;
  9905. }
  9906. }
  9907. lo: for (var i = 0; i < len;) {
  9908. var cmd = d[i++];
  9909. var isFirst = i === 1;
  9910. if (isFirst) {
  9911. xi = d[i];
  9912. yi = d[i + 1];
  9913. x0 = xi;
  9914. y0 = yi;
  9915. }
  9916. if (cmd !== CMD.L && pendingPtDist > 0) {
  9917. ctx.lineTo(pendingPtX, pendingPtY);
  9918. pendingPtDist = 0;
  9919. }
  9920. switch (cmd) {
  9921. case CMD.M:
  9922. x0 = xi = d[i++];
  9923. y0 = yi = d[i++];
  9924. ctx.moveTo(xi, yi);
  9925. break;
  9926. case CMD.L: {
  9927. x = d[i++];
  9928. y = d[i++];
  9929. var dx = mathAbs(x - xi);
  9930. var dy = mathAbs(y - yi);
  9931. if (dx > ux || dy > uy) {
  9932. if (drawPart) {
  9933. var l = pathSegLen[segCount++];
  9934. if (accumLength + l > displayedLength) {
  9935. var t = (displayedLength - accumLength) / l;
  9936. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  9937. break lo;
  9938. }
  9939. accumLength += l;
  9940. }
  9941. ctx.lineTo(x, y);
  9942. xi = x;
  9943. yi = y;
  9944. pendingPtDist = 0;
  9945. }
  9946. else {
  9947. var d2 = dx * dx + dy * dy;
  9948. if (d2 > pendingPtDist) {
  9949. pendingPtX = x;
  9950. pendingPtY = y;
  9951. pendingPtDist = d2;
  9952. }
  9953. }
  9954. break;
  9955. }
  9956. case CMD.C: {
  9957. var x1 = d[i++];
  9958. var y1 = d[i++];
  9959. var x2 = d[i++];
  9960. var y2 = d[i++];
  9961. var x3 = d[i++];
  9962. var y3 = d[i++];
  9963. if (drawPart) {
  9964. var l = pathSegLen[segCount++];
  9965. if (accumLength + l > displayedLength) {
  9966. var t = (displayedLength - accumLength) / l;
  9967. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  9968. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  9969. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  9970. break lo;
  9971. }
  9972. accumLength += l;
  9973. }
  9974. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  9975. xi = x3;
  9976. yi = y3;
  9977. break;
  9978. }
  9979. case CMD.Q: {
  9980. var x1 = d[i++];
  9981. var y1 = d[i++];
  9982. var x2 = d[i++];
  9983. var y2 = d[i++];
  9984. if (drawPart) {
  9985. var l = pathSegLen[segCount++];
  9986. if (accumLength + l > displayedLength) {
  9987. var t = (displayedLength - accumLength) / l;
  9988. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  9989. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  9990. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  9991. break lo;
  9992. }
  9993. accumLength += l;
  9994. }
  9995. ctx.quadraticCurveTo(x1, y1, x2, y2);
  9996. xi = x2;
  9997. yi = y2;
  9998. break;
  9999. }
  10000. case CMD.A:
  10001. var cx = d[i++];
  10002. var cy = d[i++];
  10003. var rx = d[i++];
  10004. var ry = d[i++];
  10005. var startAngle = d[i++];
  10006. var delta = d[i++];
  10007. var psi = d[i++];
  10008. var anticlockwise = !d[i++];
  10009. var r = (rx > ry) ? rx : ry;
  10010. var isEllipse = mathAbs(rx - ry) > 1e-3;
  10011. var endAngle = startAngle + delta;
  10012. var breakBuild = false;
  10013. if (drawPart) {
  10014. var l = pathSegLen[segCount++];
  10015. if (accumLength + l > displayedLength) {
  10016. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  10017. breakBuild = true;
  10018. }
  10019. accumLength += l;
  10020. }
  10021. if (isEllipse && ctx.ellipse) {
  10022. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  10023. }
  10024. else {
  10025. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10026. }
  10027. if (breakBuild) {
  10028. break lo;
  10029. }
  10030. if (isFirst) {
  10031. x0 = mathCos$1(startAngle) * rx + cx;
  10032. y0 = mathSin$1(startAngle) * ry + cy;
  10033. }
  10034. xi = mathCos$1(endAngle) * rx + cx;
  10035. yi = mathSin$1(endAngle) * ry + cy;
  10036. break;
  10037. case CMD.R:
  10038. x0 = xi = d[i];
  10039. y0 = yi = d[i + 1];
  10040. x = d[i++];
  10041. y = d[i++];
  10042. var width = d[i++];
  10043. var height = d[i++];
  10044. if (drawPart) {
  10045. var l = pathSegLen[segCount++];
  10046. if (accumLength + l > displayedLength) {
  10047. var d_1 = displayedLength - accumLength;
  10048. ctx.moveTo(x, y);
  10049. ctx.lineTo(x + mathMin$2(d_1, width), y);
  10050. d_1 -= width;
  10051. if (d_1 > 0) {
  10052. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  10053. }
  10054. d_1 -= height;
  10055. if (d_1 > 0) {
  10056. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  10057. }
  10058. d_1 -= width;
  10059. if (d_1 > 0) {
  10060. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  10061. }
  10062. break lo;
  10063. }
  10064. accumLength += l;
  10065. }
  10066. ctx.rect(x, y, width, height);
  10067. break;
  10068. case CMD.Z:
  10069. if (drawPart) {
  10070. var l = pathSegLen[segCount++];
  10071. if (accumLength + l > displayedLength) {
  10072. var t = (displayedLength - accumLength) / l;
  10073. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  10074. break lo;
  10075. }
  10076. accumLength += l;
  10077. }
  10078. ctx.closePath();
  10079. xi = x0;
  10080. yi = y0;
  10081. }
  10082. }
  10083. };
  10084. PathProxy.prototype.clone = function () {
  10085. var newProxy = new PathProxy();
  10086. var data = this.data;
  10087. newProxy.data = data.slice ? data.slice()
  10088. : Array.prototype.slice.call(data);
  10089. newProxy._len = this._len;
  10090. return newProxy;
  10091. };
  10092. PathProxy.CMD = CMD;
  10093. PathProxy.initDefaultProps = (function () {
  10094. var proto = PathProxy.prototype;
  10095. proto._saveData = true;
  10096. proto._needsDash = false;
  10097. proto._dashOffset = 0;
  10098. proto._dashIdx = 0;
  10099. proto._dashSum = 0;
  10100. proto._ux = 0;
  10101. proto._uy = 0;
  10102. proto._pendingPtDist = 0;
  10103. proto._version = 0;
  10104. })();
  10105. return PathProxy;
  10106. }());
  10107. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  10108. if (lineWidth === 0) {
  10109. return false;
  10110. }
  10111. var _l = lineWidth;
  10112. var _a = 0;
  10113. var _b = x0;
  10114. if ((y > y0 + _l && y > y1 + _l)
  10115. || (y < y0 - _l && y < y1 - _l)
  10116. || (x > x0 + _l && x > x1 + _l)
  10117. || (x < x0 - _l && x < x1 - _l)) {
  10118. return false;
  10119. }
  10120. if (x0 !== x1) {
  10121. _a = (y0 - y1) / (x0 - x1);
  10122. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  10123. }
  10124. else {
  10125. return Math.abs(x - x0) <= _l / 2;
  10126. }
  10127. var tmp = _a * x - y + _b;
  10128. var _s = tmp * tmp / (_a * _a + 1);
  10129. return _s <= _l / 2 * _l / 2;
  10130. }
  10131. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  10132. if (lineWidth === 0) {
  10133. return false;
  10134. }
  10135. var _l = lineWidth;
  10136. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  10137. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  10138. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  10139. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  10140. return false;
  10141. }
  10142. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  10143. return d <= _l / 2;
  10144. }
  10145. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  10146. if (lineWidth === 0) {
  10147. return false;
  10148. }
  10149. var _l = lineWidth;
  10150. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  10151. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  10152. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  10153. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  10154. return false;
  10155. }
  10156. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  10157. return d <= _l / 2;
  10158. }
  10159. var PI2$2 = Math.PI * 2;
  10160. function normalizeRadian(angle) {
  10161. angle %= PI2$2;
  10162. if (angle < 0) {
  10163. angle += PI2$2;
  10164. }
  10165. return angle;
  10166. }
  10167. var PI2$3 = Math.PI * 2;
  10168. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  10169. if (lineWidth === 0) {
  10170. return false;
  10171. }
  10172. var _l = lineWidth;
  10173. x -= cx;
  10174. y -= cy;
  10175. var d = Math.sqrt(x * x + y * y);
  10176. if ((d - _l > r) || (d + _l < r)) {
  10177. return false;
  10178. }
  10179. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  10180. return true;
  10181. }
  10182. if (anticlockwise) {
  10183. var tmp = startAngle;
  10184. startAngle = normalizeRadian(endAngle);
  10185. endAngle = normalizeRadian(tmp);
  10186. }
  10187. else {
  10188. startAngle = normalizeRadian(startAngle);
  10189. endAngle = normalizeRadian(endAngle);
  10190. }
  10191. if (startAngle > endAngle) {
  10192. endAngle += PI2$3;
  10193. }
  10194. var angle = Math.atan2(y, x);
  10195. if (angle < 0) {
  10196. angle += PI2$3;
  10197. }
  10198. return (angle >= startAngle && angle <= endAngle)
  10199. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  10200. }
  10201. function windingLine(x0, y0, x1, y1, x, y) {
  10202. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  10203. return 0;
  10204. }
  10205. if (y1 === y0) {
  10206. return 0;
  10207. }
  10208. var t = (y - y0) / (y1 - y0);
  10209. var dir = y1 < y0 ? 1 : -1;
  10210. if (t === 1 || t === 0) {
  10211. dir = y1 < y0 ? 0.5 : -0.5;
  10212. }
  10213. var x_ = t * (x1 - x0) + x0;
  10214. return x_ === x ? Infinity : x_ > x ? dir : 0;
  10215. }
  10216. var CMD$1 = PathProxy.CMD;
  10217. var PI2$4 = Math.PI * 2;
  10218. var EPSILON$2 = 1e-4;
  10219. function isAroundEqual(a, b) {
  10220. return Math.abs(a - b) < EPSILON$2;
  10221. }
  10222. var roots = [-1, -1, -1];
  10223. var extrema = [-1, -1];
  10224. function swapExtrema() {
  10225. var tmp = extrema[0];
  10226. extrema[0] = extrema[1];
  10227. extrema[1] = tmp;
  10228. }
  10229. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  10230. if ((y > y0 && y > y1 && y > y2 && y > y3)
  10231. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  10232. return 0;
  10233. }
  10234. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  10235. if (nRoots === 0) {
  10236. return 0;
  10237. }
  10238. else {
  10239. var w = 0;
  10240. var nExtrema = -1;
  10241. var y0_ = void 0;
  10242. var y1_ = void 0;
  10243. for (var i = 0; i < nRoots; i++) {
  10244. var t = roots[i];
  10245. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  10246. var x_ = cubicAt(x0, x1, x2, x3, t);
  10247. if (x_ < x) {
  10248. continue;
  10249. }
  10250. if (nExtrema < 0) {
  10251. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  10252. if (extrema[1] < extrema[0] && nExtrema > 1) {
  10253. swapExtrema();
  10254. }
  10255. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  10256. if (nExtrema > 1) {
  10257. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  10258. }
  10259. }
  10260. if (nExtrema === 2) {
  10261. if (t < extrema[0]) {
  10262. w += y0_ < y0 ? unit : -unit;
  10263. }
  10264. else if (t < extrema[1]) {
  10265. w += y1_ < y0_ ? unit : -unit;
  10266. }
  10267. else {
  10268. w += y3 < y1_ ? unit : -unit;
  10269. }
  10270. }
  10271. else {
  10272. if (t < extrema[0]) {
  10273. w += y0_ < y0 ? unit : -unit;
  10274. }
  10275. else {
  10276. w += y3 < y0_ ? unit : -unit;
  10277. }
  10278. }
  10279. }
  10280. return w;
  10281. }
  10282. }
  10283. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  10284. if ((y > y0 && y > y1 && y > y2)
  10285. || (y < y0 && y < y1 && y < y2)) {
  10286. return 0;
  10287. }
  10288. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  10289. if (nRoots === 0) {
  10290. return 0;
  10291. }
  10292. else {
  10293. var t = quadraticExtremum(y0, y1, y2);
  10294. if (t >= 0 && t <= 1) {
  10295. var w = 0;
  10296. var y_ = quadraticAt(y0, y1, y2, t);
  10297. for (var i = 0; i < nRoots; i++) {
  10298. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  10299. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  10300. if (x_ < x) {
  10301. continue;
  10302. }
  10303. if (roots[i] < t) {
  10304. w += y_ < y0 ? unit : -unit;
  10305. }
  10306. else {
  10307. w += y2 < y_ ? unit : -unit;
  10308. }
  10309. }
  10310. return w;
  10311. }
  10312. else {
  10313. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  10314. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  10315. if (x_ < x) {
  10316. return 0;
  10317. }
  10318. return y2 < y0 ? unit : -unit;
  10319. }
  10320. }
  10321. }
  10322. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  10323. y -= cy;
  10324. if (y > r || y < -r) {
  10325. return 0;
  10326. }
  10327. var tmp = Math.sqrt(r * r - y * y);
  10328. roots[0] = -tmp;
  10329. roots[1] = tmp;
  10330. var dTheta = Math.abs(startAngle - endAngle);
  10331. if (dTheta < 1e-4) {
  10332. return 0;
  10333. }
  10334. if (dTheta >= PI2$4 - 1e-4) {
  10335. startAngle = 0;
  10336. endAngle = PI2$4;
  10337. var dir = anticlockwise ? 1 : -1;
  10338. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  10339. return dir;
  10340. }
  10341. else {
  10342. return 0;
  10343. }
  10344. }
  10345. if (startAngle > endAngle) {
  10346. var tmp_1 = startAngle;
  10347. startAngle = endAngle;
  10348. endAngle = tmp_1;
  10349. }
  10350. if (startAngle < 0) {
  10351. startAngle += PI2$4;
  10352. endAngle += PI2$4;
  10353. }
  10354. var w = 0;
  10355. for (var i = 0; i < 2; i++) {
  10356. var x_ = roots[i];
  10357. if (x_ + cx > x) {
  10358. var angle = Math.atan2(y, x_);
  10359. var dir = anticlockwise ? 1 : -1;
  10360. if (angle < 0) {
  10361. angle = PI2$4 + angle;
  10362. }
  10363. if ((angle >= startAngle && angle <= endAngle)
  10364. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  10365. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  10366. dir = -dir;
  10367. }
  10368. w += dir;
  10369. }
  10370. }
  10371. }
  10372. return w;
  10373. }
  10374. function containPath(path, lineWidth, isStroke, x, y) {
  10375. var data = path.data;
  10376. var len = path.len();
  10377. var w = 0;
  10378. var xi = 0;
  10379. var yi = 0;
  10380. var x0 = 0;
  10381. var y0 = 0;
  10382. var x1;
  10383. var y1;
  10384. for (var i = 0; i < len;) {
  10385. var cmd = data[i++];
  10386. var isFirst = i === 1;
  10387. if (cmd === CMD$1.M && i > 1) {
  10388. if (!isStroke) {
  10389. w += windingLine(xi, yi, x0, y0, x, y);
  10390. }
  10391. }
  10392. if (isFirst) {
  10393. xi = data[i];
  10394. yi = data[i + 1];
  10395. x0 = xi;
  10396. y0 = yi;
  10397. }
  10398. switch (cmd) {
  10399. case CMD$1.M:
  10400. x0 = data[i++];
  10401. y0 = data[i++];
  10402. xi = x0;
  10403. yi = y0;
  10404. break;
  10405. case CMD$1.L:
  10406. if (isStroke) {
  10407. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  10408. return true;
  10409. }
  10410. }
  10411. else {
  10412. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  10413. }
  10414. xi = data[i++];
  10415. yi = data[i++];
  10416. break;
  10417. case CMD$1.C:
  10418. if (isStroke) {
  10419. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  10420. return true;
  10421. }
  10422. }
  10423. else {
  10424. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  10425. }
  10426. xi = data[i++];
  10427. yi = data[i++];
  10428. break;
  10429. case CMD$1.Q:
  10430. if (isStroke) {
  10431. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  10432. return true;
  10433. }
  10434. }
  10435. else {
  10436. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  10437. }
  10438. xi = data[i++];
  10439. yi = data[i++];
  10440. break;
  10441. case CMD$1.A:
  10442. var cx = data[i++];
  10443. var cy = data[i++];
  10444. var rx = data[i++];
  10445. var ry = data[i++];
  10446. var theta = data[i++];
  10447. var dTheta = data[i++];
  10448. i += 1;
  10449. var anticlockwise = !!(1 - data[i++]);
  10450. x1 = Math.cos(theta) * rx + cx;
  10451. y1 = Math.sin(theta) * ry + cy;
  10452. if (!isFirst) {
  10453. w += windingLine(xi, yi, x1, y1, x, y);
  10454. }
  10455. else {
  10456. x0 = x1;
  10457. y0 = y1;
  10458. }
  10459. var _x = (x - cx) * ry / rx + cx;
  10460. if (isStroke) {
  10461. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  10462. return true;
  10463. }
  10464. }
  10465. else {
  10466. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  10467. }
  10468. xi = Math.cos(theta + dTheta) * rx + cx;
  10469. yi = Math.sin(theta + dTheta) * ry + cy;
  10470. break;
  10471. case CMD$1.R:
  10472. x0 = xi = data[i++];
  10473. y0 = yi = data[i++];
  10474. var width = data[i++];
  10475. var height = data[i++];
  10476. x1 = x0 + width;
  10477. y1 = y0 + height;
  10478. if (isStroke) {
  10479. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  10480. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  10481. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  10482. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  10483. return true;
  10484. }
  10485. }
  10486. else {
  10487. w += windingLine(x1, y0, x1, y1, x, y);
  10488. w += windingLine(x0, y1, x0, y0, x, y);
  10489. }
  10490. break;
  10491. case CMD$1.Z:
  10492. if (isStroke) {
  10493. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  10494. return true;
  10495. }
  10496. }
  10497. else {
  10498. w += windingLine(xi, yi, x0, y0, x, y);
  10499. }
  10500. xi = x0;
  10501. yi = y0;
  10502. break;
  10503. }
  10504. }
  10505. if (!isStroke && !isAroundEqual(yi, y0)) {
  10506. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  10507. }
  10508. return w !== 0;
  10509. }
  10510. function contain(pathProxy, x, y) {
  10511. return containPath(pathProxy, 0, false, x, y);
  10512. }
  10513. function containStroke$4(pathProxy, lineWidth, x, y) {
  10514. return containPath(pathProxy, lineWidth, true, x, y);
  10515. }
  10516. var DEFAULT_PATH_STYLE = defaults({
  10517. fill: '#000',
  10518. stroke: null,
  10519. strokePercent: 1,
  10520. fillOpacity: 1,
  10521. strokeOpacity: 1,
  10522. lineDashOffset: 0,
  10523. lineWidth: 1,
  10524. lineCap: 'butt',
  10525. miterLimit: 10,
  10526. strokeNoScale: false,
  10527. strokeFirst: false
  10528. }, DEFAULT_COMMON_STYLE);
  10529. var DEFAULT_PATH_ANIMATION_PROPS = {
  10530. style: defaults({
  10531. fill: true,
  10532. stroke: true,
  10533. strokePercent: true,
  10534. fillOpacity: true,
  10535. strokeOpacity: true,
  10536. lineDashOffset: true,
  10537. lineWidth: true,
  10538. miterLimit: true
  10539. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  10540. };
  10541. var pathCopyParams = [
  10542. 'x', 'y', 'rotation', 'scaleX', 'scaleY', 'originX', 'originY', 'invisible',
  10543. 'culling', 'z', 'z2', 'zlevel', 'parent'
  10544. ];
  10545. var Path = (function (_super) {
  10546. __extends(Path, _super);
  10547. function Path(opts) {
  10548. return _super.call(this, opts) || this;
  10549. }
  10550. Path.prototype.update = function () {
  10551. var _this = this;
  10552. _super.prototype.update.call(this);
  10553. var style = this.style;
  10554. if (style.decal) {
  10555. var decalEl = this._decalEl = this._decalEl || new Path();
  10556. if (decalEl.buildPath === Path.prototype.buildPath) {
  10557. decalEl.buildPath = function (ctx) {
  10558. _this.buildPath(ctx, _this.shape);
  10559. };
  10560. }
  10561. decalEl.silent = true;
  10562. var decalElStyle = decalEl.style;
  10563. for (var key in style) {
  10564. if (decalElStyle[key] !== style[key]) {
  10565. decalElStyle[key] = style[key];
  10566. }
  10567. }
  10568. decalElStyle.fill = style.fill ? style.decal : null;
  10569. decalElStyle.decal = null;
  10570. decalElStyle.shadowColor = null;
  10571. style.strokeFirst && (decalElStyle.stroke = null);
  10572. for (var i = 0; i < pathCopyParams.length; ++i) {
  10573. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  10574. }
  10575. decalEl.__dirty |= REDRAW_BIT;
  10576. }
  10577. else if (this._decalEl) {
  10578. this._decalEl = null;
  10579. }
  10580. };
  10581. Path.prototype.getDecalElement = function () {
  10582. return this._decalEl;
  10583. };
  10584. Path.prototype._init = function (props) {
  10585. var keysArr = keys(props);
  10586. this.shape = this.getDefaultShape();
  10587. var defaultStyle = this.getDefaultStyle();
  10588. if (defaultStyle) {
  10589. this.useStyle(defaultStyle);
  10590. }
  10591. for (var i = 0; i < keysArr.length; i++) {
  10592. var key = keysArr[i];
  10593. var value = props[key];
  10594. if (key === 'style') {
  10595. if (!this.style) {
  10596. this.useStyle(value);
  10597. }
  10598. else {
  10599. extend(this.style, value);
  10600. }
  10601. }
  10602. else if (key === 'shape') {
  10603. extend(this.shape, value);
  10604. }
  10605. else {
  10606. _super.prototype.attrKV.call(this, key, value);
  10607. }
  10608. }
  10609. if (!this.style) {
  10610. this.useStyle({});
  10611. }
  10612. };
  10613. Path.prototype.getDefaultStyle = function () {
  10614. return null;
  10615. };
  10616. Path.prototype.getDefaultShape = function () {
  10617. return {};
  10618. };
  10619. Path.prototype.canBeInsideText = function () {
  10620. return this.hasFill();
  10621. };
  10622. Path.prototype.getInsideTextFill = function () {
  10623. var pathFill = this.style.fill;
  10624. if (pathFill !== 'none') {
  10625. if (isString(pathFill)) {
  10626. var fillLum = lum(pathFill, 0);
  10627. if (fillLum > 0.5) {
  10628. return DARK_LABEL_COLOR;
  10629. }
  10630. else if (fillLum > 0.2) {
  10631. return LIGHTER_LABEL_COLOR;
  10632. }
  10633. return LIGHT_LABEL_COLOR;
  10634. }
  10635. else if (pathFill) {
  10636. return LIGHT_LABEL_COLOR;
  10637. }
  10638. }
  10639. return DARK_LABEL_COLOR;
  10640. };
  10641. Path.prototype.getInsideTextStroke = function (textFill) {
  10642. var pathFill = this.style.fill;
  10643. if (isString(pathFill)) {
  10644. var zr = this.__zr;
  10645. var isDarkMode = !!(zr && zr.isDarkMode());
  10646. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  10647. if (isDarkMode === isDarkLabel) {
  10648. return pathFill;
  10649. }
  10650. }
  10651. };
  10652. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  10653. Path.prototype.pathUpdated = function () {
  10654. this.__dirty &= ~SHAPE_CHANGED_BIT;
  10655. };
  10656. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  10657. !this.path && this.createPathProxy();
  10658. this.path.beginPath();
  10659. this.buildPath(this.path, this.shape, inBatch);
  10660. return this.path;
  10661. };
  10662. Path.prototype.createPathProxy = function () {
  10663. this.path = new PathProxy(false);
  10664. };
  10665. Path.prototype.hasStroke = function () {
  10666. var style = this.style;
  10667. var stroke = style.stroke;
  10668. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  10669. };
  10670. Path.prototype.hasFill = function () {
  10671. var style = this.style;
  10672. var fill = style.fill;
  10673. return fill != null && fill !== 'none';
  10674. };
  10675. Path.prototype.getBoundingRect = function () {
  10676. var rect = this._rect;
  10677. var style = this.style;
  10678. var needsUpdateRect = !rect;
  10679. if (needsUpdateRect) {
  10680. var firstInvoke = false;
  10681. if (!this.path) {
  10682. firstInvoke = true;
  10683. this.createPathProxy();
  10684. }
  10685. var path = this.path;
  10686. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  10687. path.beginPath();
  10688. this.buildPath(path, this.shape, false);
  10689. this.pathUpdated();
  10690. }
  10691. rect = path.getBoundingRect();
  10692. }
  10693. this._rect = rect;
  10694. if (this.hasStroke() && this.path && this.path.len() > 0) {
  10695. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  10696. if (this.__dirty || needsUpdateRect) {
  10697. rectWithStroke.copy(rect);
  10698. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10699. var w = style.lineWidth;
  10700. if (!this.hasFill()) {
  10701. var strokeContainThreshold = this.strokeContainThreshold;
  10702. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  10703. }
  10704. if (lineScale > 1e-10) {
  10705. rectWithStroke.width += w / lineScale;
  10706. rectWithStroke.height += w / lineScale;
  10707. rectWithStroke.x -= w / lineScale / 2;
  10708. rectWithStroke.y -= w / lineScale / 2;
  10709. }
  10710. }
  10711. return rectWithStroke;
  10712. }
  10713. return rect;
  10714. };
  10715. Path.prototype.contain = function (x, y) {
  10716. var localPos = this.transformCoordToLocal(x, y);
  10717. var rect = this.getBoundingRect();
  10718. var style = this.style;
  10719. x = localPos[0];
  10720. y = localPos[1];
  10721. if (rect.contain(x, y)) {
  10722. var pathProxy = this.path;
  10723. if (this.hasStroke()) {
  10724. var lineWidth = style.lineWidth;
  10725. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10726. if (lineScale > 1e-10) {
  10727. if (!this.hasFill()) {
  10728. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  10729. }
  10730. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  10731. return true;
  10732. }
  10733. }
  10734. }
  10735. if (this.hasFill()) {
  10736. return contain(pathProxy, x, y);
  10737. }
  10738. }
  10739. return false;
  10740. };
  10741. Path.prototype.dirtyShape = function () {
  10742. this.__dirty |= SHAPE_CHANGED_BIT;
  10743. if (this._rect) {
  10744. this._rect = null;
  10745. }
  10746. if (this._decalEl) {
  10747. this._decalEl.dirtyShape();
  10748. }
  10749. this.markRedraw();
  10750. };
  10751. Path.prototype.dirty = function () {
  10752. this.dirtyStyle();
  10753. this.dirtyShape();
  10754. };
  10755. Path.prototype.animateShape = function (loop) {
  10756. return this.animate('shape', loop);
  10757. };
  10758. Path.prototype.updateDuringAnimation = function (targetKey) {
  10759. if (targetKey === 'style') {
  10760. this.dirtyStyle();
  10761. }
  10762. else if (targetKey === 'shape') {
  10763. this.dirtyShape();
  10764. }
  10765. else {
  10766. this.markRedraw();
  10767. }
  10768. };
  10769. Path.prototype.attrKV = function (key, value) {
  10770. if (key === 'shape') {
  10771. this.setShape(value);
  10772. }
  10773. else {
  10774. _super.prototype.attrKV.call(this, key, value);
  10775. }
  10776. };
  10777. Path.prototype.setShape = function (keyOrObj, value) {
  10778. var shape = this.shape;
  10779. if (!shape) {
  10780. shape = this.shape = {};
  10781. }
  10782. if (typeof keyOrObj === 'string') {
  10783. shape[keyOrObj] = value;
  10784. }
  10785. else {
  10786. extend(shape, keyOrObj);
  10787. }
  10788. this.dirtyShape();
  10789. return this;
  10790. };
  10791. Path.prototype.shapeChanged = function () {
  10792. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  10793. };
  10794. Path.prototype.createStyle = function (obj) {
  10795. return createObject(DEFAULT_PATH_STYLE, obj);
  10796. };
  10797. Path.prototype._innerSaveToNormal = function (toState) {
  10798. _super.prototype._innerSaveToNormal.call(this, toState);
  10799. var normalState = this._normalState;
  10800. if (toState.shape && !normalState.shape) {
  10801. normalState.shape = extend({}, this.shape);
  10802. }
  10803. };
  10804. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  10805. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  10806. var needsRestoreToNormal = !(state && keepCurrentStates);
  10807. var targetShape;
  10808. if (state && state.shape) {
  10809. if (transition) {
  10810. if (keepCurrentStates) {
  10811. targetShape = state.shape;
  10812. }
  10813. else {
  10814. targetShape = extend({}, normalState.shape);
  10815. extend(targetShape, state.shape);
  10816. }
  10817. }
  10818. else {
  10819. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  10820. extend(targetShape, state.shape);
  10821. }
  10822. }
  10823. else if (needsRestoreToNormal) {
  10824. targetShape = normalState.shape;
  10825. }
  10826. if (targetShape) {
  10827. if (transition) {
  10828. this.shape = extend({}, this.shape);
  10829. var targetShapePrimaryProps = {};
  10830. var shapeKeys = keys(targetShape);
  10831. for (var i = 0; i < shapeKeys.length; i++) {
  10832. var key = shapeKeys[i];
  10833. if (typeof targetShape[key] === 'object') {
  10834. this.shape[key] = targetShape[key];
  10835. }
  10836. else {
  10837. targetShapePrimaryProps[key] = targetShape[key];
  10838. }
  10839. }
  10840. this._transitionState(stateName, {
  10841. shape: targetShapePrimaryProps
  10842. }, animationCfg);
  10843. }
  10844. else {
  10845. this.shape = targetShape;
  10846. this.dirtyShape();
  10847. }
  10848. }
  10849. };
  10850. Path.prototype._mergeStates = function (states) {
  10851. var mergedState = _super.prototype._mergeStates.call(this, states);
  10852. var mergedShape;
  10853. for (var i = 0; i < states.length; i++) {
  10854. var state = states[i];
  10855. if (state.shape) {
  10856. mergedShape = mergedShape || {};
  10857. this._mergeStyle(mergedShape, state.shape);
  10858. }
  10859. }
  10860. if (mergedShape) {
  10861. mergedState.shape = mergedShape;
  10862. }
  10863. return mergedState;
  10864. };
  10865. Path.prototype.getAnimationStyleProps = function () {
  10866. return DEFAULT_PATH_ANIMATION_PROPS;
  10867. };
  10868. Path.prototype.isZeroArea = function () {
  10869. return false;
  10870. };
  10871. Path.extend = function (defaultProps) {
  10872. var Sub = (function (_super) {
  10873. __extends(Sub, _super);
  10874. function Sub(opts) {
  10875. var _this = _super.call(this, opts) || this;
  10876. defaultProps.init && defaultProps.init.call(_this, opts);
  10877. return _this;
  10878. }
  10879. Sub.prototype.getDefaultStyle = function () {
  10880. return clone(defaultProps.style);
  10881. };
  10882. Sub.prototype.getDefaultShape = function () {
  10883. return clone(defaultProps.shape);
  10884. };
  10885. return Sub;
  10886. }(Path));
  10887. for (var key in defaultProps) {
  10888. if (typeof defaultProps[key] === 'function') {
  10889. Sub.prototype[key] = defaultProps[key];
  10890. }
  10891. }
  10892. return Sub;
  10893. };
  10894. Path.initDefaultProps = (function () {
  10895. var pathProto = Path.prototype;
  10896. pathProto.type = 'path';
  10897. pathProto.strokeContainThreshold = 5;
  10898. pathProto.segmentIgnoreThreshold = 0;
  10899. pathProto.subPixelOptimize = false;
  10900. pathProto.autoBatch = false;
  10901. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  10902. })();
  10903. return Path;
  10904. }(Displayable));
  10905. var DEFAULT_TSPAN_STYLE = defaults({
  10906. strokeFirst: true,
  10907. font: DEFAULT_FONT,
  10908. x: 0,
  10909. y: 0,
  10910. textAlign: 'left',
  10911. textBaseline: 'top',
  10912. miterLimit: 2
  10913. }, DEFAULT_PATH_STYLE);
  10914. var TSpan = (function (_super) {
  10915. __extends(TSpan, _super);
  10916. function TSpan() {
  10917. return _super !== null && _super.apply(this, arguments) || this;
  10918. }
  10919. TSpan.prototype.hasStroke = function () {
  10920. var style = this.style;
  10921. var stroke = style.stroke;
  10922. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10923. };
  10924. TSpan.prototype.hasFill = function () {
  10925. var style = this.style;
  10926. var fill = style.fill;
  10927. return fill != null && fill !== 'none';
  10928. };
  10929. TSpan.prototype.createStyle = function (obj) {
  10930. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10931. };
  10932. TSpan.prototype.setBoundingRect = function (rect) {
  10933. this._rect = rect;
  10934. };
  10935. TSpan.prototype.getBoundingRect = function () {
  10936. var style = this.style;
  10937. if (!this._rect) {
  10938. var text = style.text;
  10939. text != null ? (text += '') : (text = '');
  10940. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10941. rect.x += style.x || 0;
  10942. rect.y += style.y || 0;
  10943. if (this.hasStroke()) {
  10944. var w = style.lineWidth;
  10945. rect.x -= w / 2;
  10946. rect.y -= w / 2;
  10947. rect.width += w;
  10948. rect.height += w;
  10949. }
  10950. this._rect = rect;
  10951. }
  10952. return this._rect;
  10953. };
  10954. TSpan.initDefaultProps = (function () {
  10955. var tspanProto = TSpan.prototype;
  10956. tspanProto.dirtyRectTolerance = 10;
  10957. })();
  10958. return TSpan;
  10959. }(Displayable));
  10960. TSpan.prototype.type = 'tspan';
  10961. var DEFAULT_IMAGE_STYLE = defaults({
  10962. x: 0,
  10963. y: 0
  10964. }, DEFAULT_COMMON_STYLE);
  10965. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  10966. style: defaults({
  10967. x: true,
  10968. y: true,
  10969. width: true,
  10970. height: true,
  10971. sx: true,
  10972. sy: true,
  10973. sWidth: true,
  10974. sHeight: true
  10975. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  10976. };
  10977. function isImageLike(source) {
  10978. return !!(source
  10979. && typeof source !== 'string'
  10980. && source.width && source.height);
  10981. }
  10982. var ZRImage = (function (_super) {
  10983. __extends(ZRImage, _super);
  10984. function ZRImage() {
  10985. return _super !== null && _super.apply(this, arguments) || this;
  10986. }
  10987. ZRImage.prototype.createStyle = function (obj) {
  10988. return createObject(DEFAULT_IMAGE_STYLE, obj);
  10989. };
  10990. ZRImage.prototype._getSize = function (dim) {
  10991. var style = this.style;
  10992. var size = style[dim];
  10993. if (size != null) {
  10994. return size;
  10995. }
  10996. var imageSource = isImageLike(style.image)
  10997. ? style.image : this.__image;
  10998. if (!imageSource) {
  10999. return 0;
  11000. }
  11001. var otherDim = dim === 'width' ? 'height' : 'width';
  11002. var otherDimSize = style[otherDim];
  11003. if (otherDimSize == null) {
  11004. return imageSource[dim];
  11005. }
  11006. else {
  11007. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  11008. }
  11009. };
  11010. ZRImage.prototype.getWidth = function () {
  11011. return this._getSize('width');
  11012. };
  11013. ZRImage.prototype.getHeight = function () {
  11014. return this._getSize('height');
  11015. };
  11016. ZRImage.prototype.getAnimationStyleProps = function () {
  11017. return DEFAULT_IMAGE_ANIMATION_PROPS;
  11018. };
  11019. ZRImage.prototype.getBoundingRect = function () {
  11020. var style = this.style;
  11021. if (!this._rect) {
  11022. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  11023. }
  11024. return this._rect;
  11025. };
  11026. return ZRImage;
  11027. }(Displayable));
  11028. ZRImage.prototype.type = 'image';
  11029. function buildPath(ctx, shape) {
  11030. var x = shape.x;
  11031. var y = shape.y;
  11032. var width = shape.width;
  11033. var height = shape.height;
  11034. var r = shape.r;
  11035. var r1;
  11036. var r2;
  11037. var r3;
  11038. var r4;
  11039. if (width < 0) {
  11040. x = x + width;
  11041. width = -width;
  11042. }
  11043. if (height < 0) {
  11044. y = y + height;
  11045. height = -height;
  11046. }
  11047. if (typeof r === 'number') {
  11048. r1 = r2 = r3 = r4 = r;
  11049. }
  11050. else if (r instanceof Array) {
  11051. if (r.length === 1) {
  11052. r1 = r2 = r3 = r4 = r[0];
  11053. }
  11054. else if (r.length === 2) {
  11055. r1 = r3 = r[0];
  11056. r2 = r4 = r[1];
  11057. }
  11058. else if (r.length === 3) {
  11059. r1 = r[0];
  11060. r2 = r4 = r[1];
  11061. r3 = r[2];
  11062. }
  11063. else {
  11064. r1 = r[0];
  11065. r2 = r[1];
  11066. r3 = r[2];
  11067. r4 = r[3];
  11068. }
  11069. }
  11070. else {
  11071. r1 = r2 = r3 = r4 = 0;
  11072. }
  11073. var total;
  11074. if (r1 + r2 > width) {
  11075. total = r1 + r2;
  11076. r1 *= width / total;
  11077. r2 *= width / total;
  11078. }
  11079. if (r3 + r4 > width) {
  11080. total = r3 + r4;
  11081. r3 *= width / total;
  11082. r4 *= width / total;
  11083. }
  11084. if (r2 + r3 > height) {
  11085. total = r2 + r3;
  11086. r2 *= height / total;
  11087. r3 *= height / total;
  11088. }
  11089. if (r1 + r4 > height) {
  11090. total = r1 + r4;
  11091. r1 *= height / total;
  11092. r4 *= height / total;
  11093. }
  11094. ctx.moveTo(x + r1, y);
  11095. ctx.lineTo(x + width - r2, y);
  11096. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  11097. ctx.lineTo(x + width, y + height - r3);
  11098. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  11099. ctx.lineTo(x + r4, y + height);
  11100. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  11101. ctx.lineTo(x, y + r1);
  11102. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  11103. }
  11104. var round$1 = Math.round;
  11105. function subPixelOptimizeLine(outputShape, inputShape, style) {
  11106. if (!inputShape) {
  11107. return;
  11108. }
  11109. var x1 = inputShape.x1;
  11110. var x2 = inputShape.x2;
  11111. var y1 = inputShape.y1;
  11112. var y2 = inputShape.y2;
  11113. outputShape.x1 = x1;
  11114. outputShape.x2 = x2;
  11115. outputShape.y1 = y1;
  11116. outputShape.y2 = y2;
  11117. var lineWidth = style && style.lineWidth;
  11118. if (!lineWidth) {
  11119. return outputShape;
  11120. }
  11121. if (round$1(x1 * 2) === round$1(x2 * 2)) {
  11122. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  11123. }
  11124. if (round$1(y1 * 2) === round$1(y2 * 2)) {
  11125. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  11126. }
  11127. return outputShape;
  11128. }
  11129. function subPixelOptimizeRect(outputShape, inputShape, style) {
  11130. if (!inputShape) {
  11131. return;
  11132. }
  11133. var originX = inputShape.x;
  11134. var originY = inputShape.y;
  11135. var originWidth = inputShape.width;
  11136. var originHeight = inputShape.height;
  11137. outputShape.x = originX;
  11138. outputShape.y = originY;
  11139. outputShape.width = originWidth;
  11140. outputShape.height = originHeight;
  11141. var lineWidth = style && style.lineWidth;
  11142. if (!lineWidth) {
  11143. return outputShape;
  11144. }
  11145. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  11146. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  11147. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  11148. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  11149. return outputShape;
  11150. }
  11151. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  11152. if (!lineWidth) {
  11153. return position;
  11154. }
  11155. var doubledPosition = round$1(position * 2);
  11156. return (doubledPosition + round$1(lineWidth)) % 2 === 0
  11157. ? doubledPosition / 2
  11158. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  11159. }
  11160. var RectShape = (function () {
  11161. function RectShape() {
  11162. this.x = 0;
  11163. this.y = 0;
  11164. this.width = 0;
  11165. this.height = 0;
  11166. }
  11167. return RectShape;
  11168. }());
  11169. var subPixelOptimizeOutputShape = {};
  11170. var Rect = (function (_super) {
  11171. __extends(Rect, _super);
  11172. function Rect(opts) {
  11173. return _super.call(this, opts) || this;
  11174. }
  11175. Rect.prototype.getDefaultShape = function () {
  11176. return new RectShape();
  11177. };
  11178. Rect.prototype.buildPath = function (ctx, shape) {
  11179. var x;
  11180. var y;
  11181. var width;
  11182. var height;
  11183. if (this.subPixelOptimize) {
  11184. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  11185. x = optimizedShape.x;
  11186. y = optimizedShape.y;
  11187. width = optimizedShape.width;
  11188. height = optimizedShape.height;
  11189. optimizedShape.r = shape.r;
  11190. shape = optimizedShape;
  11191. }
  11192. else {
  11193. x = shape.x;
  11194. y = shape.y;
  11195. width = shape.width;
  11196. height = shape.height;
  11197. }
  11198. if (!shape.r) {
  11199. ctx.rect(x, y, width, height);
  11200. }
  11201. else {
  11202. buildPath(ctx, shape);
  11203. }
  11204. };
  11205. Rect.prototype.isZeroArea = function () {
  11206. return !this.shape.width || !this.shape.height;
  11207. };
  11208. return Rect;
  11209. }(Path));
  11210. Rect.prototype.type = 'rect';
  11211. var DEFAULT_RICH_TEXT_COLOR = {
  11212. fill: '#000'
  11213. };
  11214. var DEFAULT_STROKE_LINE_WIDTH = 2;
  11215. var DEFAULT_TEXT_ANIMATION_PROPS = {
  11216. style: defaults({
  11217. fill: true,
  11218. stroke: true,
  11219. fillOpacity: true,
  11220. strokeOpacity: true,
  11221. lineWidth: true,
  11222. fontSize: true,
  11223. lineHeight: true,
  11224. width: true,
  11225. height: true,
  11226. textShadowColor: true,
  11227. textShadowBlur: true,
  11228. textShadowOffsetX: true,
  11229. textShadowOffsetY: true,
  11230. backgroundColor: true,
  11231. padding: true,
  11232. borderColor: true,
  11233. borderWidth: true,
  11234. borderRadius: true
  11235. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11236. };
  11237. var ZRText = (function (_super) {
  11238. __extends(ZRText, _super);
  11239. function ZRText(opts) {
  11240. var _this = _super.call(this) || this;
  11241. _this.type = 'text';
  11242. _this._children = [];
  11243. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  11244. _this.attr(opts);
  11245. return _this;
  11246. }
  11247. ZRText.prototype.childrenRef = function () {
  11248. return this._children;
  11249. };
  11250. ZRText.prototype.update = function () {
  11251. _super.prototype.update.call(this);
  11252. if (this.styleChanged()) {
  11253. this._updateSubTexts();
  11254. }
  11255. for (var i = 0; i < this._children.length; i++) {
  11256. var child = this._children[i];
  11257. child.zlevel = this.zlevel;
  11258. child.z = this.z;
  11259. child.z2 = this.z2;
  11260. child.culling = this.culling;
  11261. child.cursor = this.cursor;
  11262. child.invisible = this.invisible;
  11263. }
  11264. };
  11265. ZRText.prototype.updateTransform = function () {
  11266. var innerTransformable = this.innerTransformable;
  11267. if (innerTransformable) {
  11268. innerTransformable.updateTransform();
  11269. if (innerTransformable.transform) {
  11270. this.transform = innerTransformable.transform;
  11271. }
  11272. }
  11273. else {
  11274. _super.prototype.updateTransform.call(this);
  11275. }
  11276. };
  11277. ZRText.prototype.getLocalTransform = function (m) {
  11278. var innerTransformable = this.innerTransformable;
  11279. return innerTransformable
  11280. ? innerTransformable.getLocalTransform(m)
  11281. : _super.prototype.getLocalTransform.call(this, m);
  11282. };
  11283. ZRText.prototype.getComputedTransform = function () {
  11284. if (this.__hostTarget) {
  11285. this.__hostTarget.getComputedTransform();
  11286. this.__hostTarget.updateInnerText(true);
  11287. }
  11288. return _super.prototype.getComputedTransform.call(this);
  11289. };
  11290. ZRText.prototype._updateSubTexts = function () {
  11291. this._childCursor = 0;
  11292. normalizeTextStyle(this.style);
  11293. this.style.rich
  11294. ? this._updateRichTexts()
  11295. : this._updatePlainTexts();
  11296. this._children.length = this._childCursor;
  11297. this.styleUpdated();
  11298. };
  11299. ZRText.prototype.addSelfToZr = function (zr) {
  11300. _super.prototype.addSelfToZr.call(this, zr);
  11301. for (var i = 0; i < this._children.length; i++) {
  11302. this._children[i].__zr = zr;
  11303. }
  11304. };
  11305. ZRText.prototype.removeSelfFromZr = function (zr) {
  11306. _super.prototype.removeSelfFromZr.call(this, zr);
  11307. for (var i = 0; i < this._children.length; i++) {
  11308. this._children[i].__zr = null;
  11309. }
  11310. };
  11311. ZRText.prototype.getBoundingRect = function () {
  11312. if (this.styleChanged()) {
  11313. this._updateSubTexts();
  11314. }
  11315. if (!this._rect) {
  11316. var tmpRect = new BoundingRect(0, 0, 0, 0);
  11317. var children = this._children;
  11318. var tmpMat = [];
  11319. var rect = null;
  11320. for (var i = 0; i < children.length; i++) {
  11321. var child = children[i];
  11322. var childRect = child.getBoundingRect();
  11323. var transform = child.getLocalTransform(tmpMat);
  11324. if (transform) {
  11325. tmpRect.copy(childRect);
  11326. tmpRect.applyTransform(transform);
  11327. rect = rect || tmpRect.clone();
  11328. rect.union(tmpRect);
  11329. }
  11330. else {
  11331. rect = rect || childRect.clone();
  11332. rect.union(childRect);
  11333. }
  11334. }
  11335. this._rect = rect || tmpRect;
  11336. }
  11337. return this._rect;
  11338. };
  11339. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  11340. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  11341. };
  11342. ZRText.prototype.setTextContent = function (textContent) {
  11343. throw new Error('Can\'t attach text on another text');
  11344. };
  11345. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  11346. if (!sourceStyle) {
  11347. return targetStyle;
  11348. }
  11349. var sourceRich = sourceStyle.rich;
  11350. var targetRich = targetStyle.rich || (sourceRich && {});
  11351. extend(targetStyle, sourceStyle);
  11352. if (sourceRich && targetRich) {
  11353. this._mergeRich(targetRich, sourceRich);
  11354. targetStyle.rich = targetRich;
  11355. }
  11356. else if (targetRich) {
  11357. targetStyle.rich = targetRich;
  11358. }
  11359. return targetStyle;
  11360. };
  11361. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  11362. var richNames = keys(sourceRich);
  11363. for (var i = 0; i < richNames.length; i++) {
  11364. var richName = richNames[i];
  11365. targetRich[richName] = targetRich[richName] || {};
  11366. extend(targetRich[richName], sourceRich[richName]);
  11367. }
  11368. };
  11369. ZRText.prototype.getAnimationStyleProps = function () {
  11370. return DEFAULT_TEXT_ANIMATION_PROPS;
  11371. };
  11372. ZRText.prototype._getOrCreateChild = function (Ctor) {
  11373. var child = this._children[this._childCursor];
  11374. if (!child || !(child instanceof Ctor)) {
  11375. child = new Ctor();
  11376. }
  11377. this._children[this._childCursor++] = child;
  11378. child.__zr = this.__zr;
  11379. child.parent = this;
  11380. return child;
  11381. };
  11382. ZRText.prototype._updatePlainTexts = function () {
  11383. var style = this.style;
  11384. var textFont = style.font || DEFAULT_FONT;
  11385. var textPadding = style.padding;
  11386. var text = getStyleText(style);
  11387. var contentBlock = parsePlainText(text, style);
  11388. var needDrawBg = needDrawBackground(style);
  11389. var bgColorDrawn = !!(style.backgroundColor);
  11390. var outerHeight = contentBlock.outerHeight;
  11391. var textLines = contentBlock.lines;
  11392. var lineHeight = contentBlock.lineHeight;
  11393. var defaultStyle = this._defaultStyle;
  11394. var baseX = style.x || 0;
  11395. var baseY = style.y || 0;
  11396. var textAlign = style.align || defaultStyle.align || 'left';
  11397. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  11398. var textX = baseX;
  11399. var textY = adjustTextY(baseY, contentBlock.contentHeight, verticalAlign);
  11400. if (needDrawBg || textPadding) {
  11401. var outerWidth_1 = contentBlock.width;
  11402. textPadding && (outerWidth_1 += textPadding[1] + textPadding[3]);
  11403. var boxX = adjustTextX(baseX, outerWidth_1, textAlign);
  11404. var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
  11405. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth_1, outerHeight);
  11406. }
  11407. textY += lineHeight / 2;
  11408. if (textPadding) {
  11409. textX = getTextXForPadding(baseX, textAlign, textPadding);
  11410. if (verticalAlign === 'top') {
  11411. textY += textPadding[0];
  11412. }
  11413. else if (verticalAlign === 'bottom') {
  11414. textY -= textPadding[2];
  11415. }
  11416. }
  11417. var defaultLineWidth = 0;
  11418. var useDefaultFill = false;
  11419. var textFill = getFill('fill' in style
  11420. ? style.fill
  11421. : (useDefaultFill = true, defaultStyle.fill));
  11422. var textStroke = getStroke('stroke' in style
  11423. ? style.stroke
  11424. : (!bgColorDrawn
  11425. && (!defaultStyle.autoStroke || useDefaultFill))
  11426. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  11427. : null);
  11428. var hasShadow = style.textShadowBlur > 0;
  11429. var fixedBoundingRect = style.width != null
  11430. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  11431. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  11432. for (var i = 0; i < textLines.length; i++) {
  11433. var el = this._getOrCreateChild(TSpan);
  11434. var subElStyle = el.createStyle();
  11435. el.useStyle(subElStyle);
  11436. subElStyle.text = textLines[i];
  11437. subElStyle.x = textX;
  11438. subElStyle.y = textY;
  11439. if (textAlign) {
  11440. subElStyle.textAlign = textAlign;
  11441. }
  11442. subElStyle.textBaseline = 'middle';
  11443. subElStyle.opacity = style.opacity;
  11444. subElStyle.strokeFirst = true;
  11445. if (hasShadow) {
  11446. subElStyle.shadowBlur = style.textShadowBlur || 0;
  11447. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  11448. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  11449. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  11450. }
  11451. if (textStroke) {
  11452. subElStyle.stroke = textStroke;
  11453. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  11454. subElStyle.lineDash = style.lineDash;
  11455. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  11456. }
  11457. if (textFill) {
  11458. subElStyle.fill = textFill;
  11459. }
  11460. subElStyle.font = textFont;
  11461. textY += lineHeight;
  11462. if (fixedBoundingRect) {
  11463. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), style.width, calculatedLineHeight));
  11464. }
  11465. }
  11466. };
  11467. ZRText.prototype._updateRichTexts = function () {
  11468. var style = this.style;
  11469. var text = getStyleText(style);
  11470. var contentBlock = parseRichText(text, style);
  11471. var contentWidth = contentBlock.width;
  11472. var outerWidth = contentBlock.outerWidth;
  11473. var outerHeight = contentBlock.outerHeight;
  11474. var textPadding = style.padding;
  11475. var baseX = style.x || 0;
  11476. var baseY = style.y || 0;
  11477. var defaultStyle = this._defaultStyle;
  11478. var textAlign = style.align || defaultStyle.align;
  11479. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  11480. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  11481. var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
  11482. var xLeft = boxX;
  11483. var lineTop = boxY;
  11484. if (textPadding) {
  11485. xLeft += textPadding[3];
  11486. lineTop += textPadding[0];
  11487. }
  11488. var xRight = xLeft + contentWidth;
  11489. if (needDrawBackground(style)) {
  11490. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  11491. }
  11492. var bgColorDrawn = !!(style.backgroundColor);
  11493. for (var i = 0; i < contentBlock.lines.length; i++) {
  11494. var line = contentBlock.lines[i];
  11495. var tokens = line.tokens;
  11496. var tokenCount = tokens.length;
  11497. var lineHeight = line.lineHeight;
  11498. var remainedWidth = line.width;
  11499. var leftIndex = 0;
  11500. var lineXLeft = xLeft;
  11501. var lineXRight = xRight;
  11502. var rightIndex = tokenCount - 1;
  11503. var token = void 0;
  11504. while (leftIndex < tokenCount
  11505. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  11506. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  11507. remainedWidth -= token.width;
  11508. lineXLeft += token.width;
  11509. leftIndex++;
  11510. }
  11511. while (rightIndex >= 0
  11512. && (token = tokens[rightIndex], token.align === 'right')) {
  11513. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  11514. remainedWidth -= token.width;
  11515. lineXRight -= token.width;
  11516. rightIndex--;
  11517. }
  11518. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  11519. while (leftIndex <= rightIndex) {
  11520. token = tokens[leftIndex];
  11521. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  11522. lineXLeft += token.width;
  11523. leftIndex++;
  11524. }
  11525. lineTop += lineHeight;
  11526. }
  11527. };
  11528. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  11529. var tokenStyle = style.rich[token.styleName] || {};
  11530. tokenStyle.text = token.text;
  11531. var verticalAlign = token.verticalAlign;
  11532. var y = lineTop + lineHeight / 2;
  11533. if (verticalAlign === 'top') {
  11534. y = lineTop + token.height / 2;
  11535. }
  11536. else if (verticalAlign === 'bottom') {
  11537. y = lineTop + lineHeight - token.height / 2;
  11538. }
  11539. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  11540. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  11541. ? x - token.width
  11542. : textAlign === 'center'
  11543. ? x - token.width / 2
  11544. : x, y - token.height / 2, token.width, token.height);
  11545. var bgColorDrawn = !!tokenStyle.backgroundColor;
  11546. var textPadding = token.textPadding;
  11547. if (textPadding) {
  11548. x = getTextXForPadding(x, textAlign, textPadding);
  11549. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  11550. }
  11551. var el = this._getOrCreateChild(TSpan);
  11552. var subElStyle = el.createStyle();
  11553. el.useStyle(subElStyle);
  11554. var defaultStyle = this._defaultStyle;
  11555. var useDefaultFill = false;
  11556. var defaultLineWidth = 0;
  11557. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  11558. : 'fill' in style ? style.fill
  11559. : (useDefaultFill = true, defaultStyle.fill));
  11560. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  11561. : 'stroke' in style ? style.stroke
  11562. : (!bgColorDrawn
  11563. && !parentBgColorDrawn
  11564. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  11565. : null);
  11566. var hasShadow = tokenStyle.textShadowBlur > 0
  11567. || style.textShadowBlur > 0;
  11568. subElStyle.text = token.text;
  11569. subElStyle.x = x;
  11570. subElStyle.y = y;
  11571. if (hasShadow) {
  11572. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  11573. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  11574. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  11575. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  11576. }
  11577. subElStyle.textAlign = textAlign;
  11578. subElStyle.textBaseline = 'middle';
  11579. subElStyle.font = token.font || DEFAULT_FONT;
  11580. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  11581. if (textStroke) {
  11582. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  11583. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  11584. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  11585. subElStyle.stroke = textStroke;
  11586. }
  11587. if (textFill) {
  11588. subElStyle.fill = textFill;
  11589. }
  11590. var textWidth = token.contentWidth;
  11591. var textHeight = token.contentHeight;
  11592. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  11593. };
  11594. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  11595. var textBackgroundColor = style.backgroundColor;
  11596. var textBorderWidth = style.borderWidth;
  11597. var textBorderColor = style.borderColor;
  11598. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  11599. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  11600. var textBorderRadius = style.borderRadius;
  11601. var self = this;
  11602. var rectEl;
  11603. var imgEl;
  11604. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  11605. rectEl = this._getOrCreateChild(Rect);
  11606. rectEl.useStyle(rectEl.createStyle());
  11607. rectEl.style.fill = null;
  11608. var rectShape = rectEl.shape;
  11609. rectShape.x = x;
  11610. rectShape.y = y;
  11611. rectShape.width = width;
  11612. rectShape.height = height;
  11613. rectShape.r = textBorderRadius;
  11614. rectEl.dirtyShape();
  11615. }
  11616. if (isPlainOrGradientBg) {
  11617. var rectStyle = rectEl.style;
  11618. rectStyle.fill = textBackgroundColor || null;
  11619. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  11620. }
  11621. else if (isImageBg) {
  11622. imgEl = this._getOrCreateChild(ZRImage);
  11623. imgEl.onload = function () {
  11624. self.dirtyStyle();
  11625. };
  11626. var imgStyle = imgEl.style;
  11627. imgStyle.image = textBackgroundColor.image;
  11628. imgStyle.x = x;
  11629. imgStyle.y = y;
  11630. imgStyle.width = width;
  11631. imgStyle.height = height;
  11632. }
  11633. if (textBorderWidth && textBorderColor) {
  11634. var rectStyle = rectEl.style;
  11635. rectStyle.lineWidth = textBorderWidth;
  11636. rectStyle.stroke = textBorderColor;
  11637. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  11638. rectStyle.lineDash = style.borderDash;
  11639. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  11640. rectEl.strokeContainThreshold = 0;
  11641. if (rectEl.hasFill() && rectEl.hasStroke()) {
  11642. rectStyle.strokeFirst = true;
  11643. rectStyle.lineWidth *= 2;
  11644. }
  11645. }
  11646. var commonStyle = (rectEl || imgEl).style;
  11647. commonStyle.shadowBlur = style.shadowBlur || 0;
  11648. commonStyle.shadowColor = style.shadowColor || 'transparent';
  11649. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  11650. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  11651. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  11652. };
  11653. ZRText.makeFont = function (style) {
  11654. var font = '';
  11655. if (style.fontSize || style.fontFamily || style.fontWeight) {
  11656. var fontSize = '';
  11657. if (typeof style.fontSize === 'string'
  11658. && (style.fontSize.indexOf('px') !== -1
  11659. || style.fontSize.indexOf('rem') !== -1
  11660. || style.fontSize.indexOf('em') !== -1)) {
  11661. fontSize = style.fontSize;
  11662. }
  11663. else if (!isNaN(+style.fontSize)) {
  11664. fontSize = style.fontSize + 'px';
  11665. }
  11666. else {
  11667. fontSize = '12px';
  11668. }
  11669. font = [
  11670. style.fontStyle,
  11671. style.fontWeight,
  11672. fontSize,
  11673. style.fontFamily || 'sans-serif'
  11674. ].join(' ');
  11675. }
  11676. return font && trim(font) || style.textFont || style.font;
  11677. };
  11678. return ZRText;
  11679. }(Displayable));
  11680. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  11681. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  11682. function normalizeTextStyle(style) {
  11683. normalizeStyle(style);
  11684. each(style.rich, normalizeStyle);
  11685. return style;
  11686. }
  11687. function normalizeStyle(style) {
  11688. if (style) {
  11689. style.font = ZRText.makeFont(style);
  11690. var textAlign = style.align;
  11691. textAlign === 'middle' && (textAlign = 'center');
  11692. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  11693. var verticalAlign = style.verticalAlign;
  11694. verticalAlign === 'center' && (verticalAlign = 'middle');
  11695. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  11696. var textPadding = style.padding;
  11697. if (textPadding) {
  11698. style.padding = normalizeCssArray(style.padding);
  11699. }
  11700. }
  11701. }
  11702. function getStroke(stroke, lineWidth) {
  11703. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  11704. ? null
  11705. : (stroke.image || stroke.colorStops)
  11706. ? '#000'
  11707. : stroke;
  11708. }
  11709. function getFill(fill) {
  11710. return (fill == null || fill === 'none')
  11711. ? null
  11712. : (fill.image || fill.colorStops)
  11713. ? '#000'
  11714. : fill;
  11715. }
  11716. function getTextXForPadding(x, textAlign, textPadding) {
  11717. return textAlign === 'right'
  11718. ? (x - textPadding[1])
  11719. : textAlign === 'center'
  11720. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  11721. : (x + textPadding[3]);
  11722. }
  11723. function getStyleText(style) {
  11724. var text = style.text;
  11725. text != null && (text += '');
  11726. return text;
  11727. }
  11728. function needDrawBackground(style) {
  11729. return !!(style.backgroundColor
  11730. || style.lineHeight
  11731. || (style.borderWidth && style.borderColor));
  11732. }
  11733. var getECData = makeInner();
  11734. var setCommonECData = function (seriesIndex, dataType, dataIdx, el) {
  11735. if (el) {
  11736. var ecData = getECData(el); // Add data index and series index for indexing the data by element
  11737. // Useful in tooltip
  11738. ecData.dataIndex = dataIdx;
  11739. ecData.dataType = dataType;
  11740. ecData.seriesIndex = seriesIndex; // TODO: not store dataIndex on children.
  11741. if (el.type === 'group') {
  11742. el.traverse(function (child) {
  11743. var childECData = getECData(child);
  11744. childECData.seriesIndex = seriesIndex;
  11745. childECData.dataIndex = dataIdx;
  11746. childECData.dataType = dataType;
  11747. });
  11748. }
  11749. }
  11750. };
  11751. var _highlightNextDigit = 1;
  11752. var _highlightKeyMap = {};
  11753. var getSavedStates = makeInner();
  11754. var HOVER_STATE_NORMAL = 0;
  11755. var HOVER_STATE_BLUR = 1;
  11756. var HOVER_STATE_EMPHASIS = 2;
  11757. var SPECIAL_STATES = ['emphasis', 'blur', 'select'];
  11758. var DISPLAY_STATES = ['normal', 'emphasis', 'blur', 'select'];
  11759. var Z2_EMPHASIS_LIFT = 10;
  11760. var Z2_SELECT_LIFT = 9;
  11761. var HIGHLIGHT_ACTION_TYPE = 'highlight';
  11762. var DOWNPLAY_ACTION_TYPE = 'downplay';
  11763. var SELECT_ACTION_TYPE = 'select';
  11764. var UNSELECT_ACTION_TYPE = 'unselect';
  11765. var TOGGLE_SELECT_ACTION_TYPE = 'toggleSelect';
  11766. function hasFillOrStroke(fillOrStroke) {
  11767. return fillOrStroke != null && fillOrStroke !== 'none';
  11768. } // Most lifted color are duplicated.
  11769. var liftedColorCache = new LRU(100);
  11770. function liftColor(color$1) {
  11771. if (typeof color$1 !== 'string') {
  11772. return color$1;
  11773. }
  11774. var liftedColor = liftedColorCache.get(color$1);
  11775. if (!liftedColor) {
  11776. liftedColor = lift(color$1, -0.1);
  11777. liftedColorCache.put(color$1, liftedColor);
  11778. }
  11779. return liftedColor;
  11780. }
  11781. function doChangeHoverState(el, stateName, hoverStateEnum) {
  11782. if (el.onHoverStateChange && (el.hoverState || 0) !== hoverStateEnum) {
  11783. el.onHoverStateChange(stateName);
  11784. }
  11785. el.hoverState = hoverStateEnum;
  11786. }
  11787. function singleEnterEmphasis(el) {
  11788. // Only mark the flag.
  11789. // States will be applied in the echarts.ts in next frame.
  11790. doChangeHoverState(el, 'emphasis', HOVER_STATE_EMPHASIS);
  11791. }
  11792. function singleLeaveEmphasis(el) {
  11793. // Only mark the flag.
  11794. // States will be applied in the echarts.ts in next frame.
  11795. if (el.hoverState === HOVER_STATE_EMPHASIS) {
  11796. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  11797. }
  11798. }
  11799. function singleEnterBlur(el) {
  11800. doChangeHoverState(el, 'blur', HOVER_STATE_BLUR);
  11801. }
  11802. function singleLeaveBlur(el) {
  11803. if (el.hoverState === HOVER_STATE_BLUR) {
  11804. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  11805. }
  11806. }
  11807. function singleEnterSelect(el) {
  11808. el.selected = true;
  11809. }
  11810. function singleLeaveSelect(el) {
  11811. el.selected = false;
  11812. }
  11813. function updateElementState(el, updater, commonParam) {
  11814. updater(el, commonParam);
  11815. }
  11816. function traverseUpdateState(el, updater, commonParam) {
  11817. updateElementState(el, updater, commonParam);
  11818. el.isGroup && el.traverse(function (child) {
  11819. updateElementState(child, updater, commonParam);
  11820. });
  11821. }
  11822. function setStatesFlag(el, stateName) {
  11823. switch (stateName) {
  11824. case 'emphasis':
  11825. el.hoverState = HOVER_STATE_EMPHASIS;
  11826. break;
  11827. case 'normal':
  11828. el.hoverState = HOVER_STATE_NORMAL;
  11829. break;
  11830. case 'blur':
  11831. el.hoverState = HOVER_STATE_BLUR;
  11832. break;
  11833. case 'select':
  11834. el.selected = true;
  11835. }
  11836. }
  11837. function getFromStateStyle(el, props, toStateName, defaultValue) {
  11838. var style = el.style;
  11839. var fromState = {};
  11840. for (var i = 0; i < props.length; i++) {
  11841. var propName = props[i];
  11842. var val = style[propName];
  11843. fromState[propName] = val == null ? defaultValue && defaultValue[propName] : val;
  11844. }
  11845. for (var i = 0; i < el.animators.length; i++) {
  11846. var animator = el.animators[i];
  11847. if (animator.__fromStateTransition // Dont consider the animation to emphasis state.
  11848. && animator.__fromStateTransition.indexOf(toStateName) < 0 && animator.targetName === 'style') {
  11849. animator.saveFinalToTarget(fromState, props);
  11850. }
  11851. }
  11852. return fromState;
  11853. }
  11854. function createEmphasisDefaultState(el, stateName, targetStates, state) {
  11855. var hasSelect = targetStates && indexOf(targetStates, 'select') >= 0;
  11856. var cloned = false;
  11857. if (el instanceof Path) {
  11858. var store = getSavedStates(el);
  11859. var fromFill = hasSelect ? store.selectFill || store.normalFill : store.normalFill;
  11860. var fromStroke = hasSelect ? store.selectStroke || store.normalStroke : store.normalStroke;
  11861. if (hasFillOrStroke(fromFill) || hasFillOrStroke(fromStroke)) {
  11862. state = state || {};
  11863. var emphasisStyle = state.style || {}; // inherit case
  11864. if (emphasisStyle.fill === 'inherit') {
  11865. cloned = true;
  11866. state = extend({}, state);
  11867. emphasisStyle = extend({}, emphasisStyle);
  11868. emphasisStyle.fill = fromFill;
  11869. } // Apply default color lift
  11870. else if (!hasFillOrStroke(emphasisStyle.fill) && hasFillOrStroke(fromFill)) {
  11871. cloned = true; // Not modify the original value.
  11872. state = extend({}, state);
  11873. emphasisStyle = extend({}, emphasisStyle); // Already being applied 'emphasis'. DON'T lift color multiple times.
  11874. emphasisStyle.fill = liftColor(fromFill);
  11875. } // Not highlight stroke if fill has been highlighted.
  11876. else if (!hasFillOrStroke(emphasisStyle.stroke) && hasFillOrStroke(fromStroke)) {
  11877. if (!cloned) {
  11878. state = extend({}, state);
  11879. emphasisStyle = extend({}, emphasisStyle);
  11880. }
  11881. emphasisStyle.stroke = liftColor(fromStroke);
  11882. }
  11883. state.style = emphasisStyle;
  11884. }
  11885. }
  11886. if (state) {
  11887. // TODO Share with textContent?
  11888. if (state.z2 == null) {
  11889. if (!cloned) {
  11890. state = extend({}, state);
  11891. }
  11892. var z2EmphasisLift = el.z2EmphasisLift;
  11893. state.z2 = el.z2 + (z2EmphasisLift != null ? z2EmphasisLift : Z2_EMPHASIS_LIFT);
  11894. }
  11895. }
  11896. return state;
  11897. }
  11898. function createSelectDefaultState(el, stateName, state) {
  11899. // const hasSelect = indexOf(el.currentStates, stateName) >= 0;
  11900. if (state) {
  11901. // TODO Share with textContent?
  11902. if (state.z2 == null) {
  11903. state = extend({}, state);
  11904. var z2SelectLift = el.z2SelectLift;
  11905. state.z2 = el.z2 + (z2SelectLift != null ? z2SelectLift : Z2_SELECT_LIFT);
  11906. }
  11907. }
  11908. return state;
  11909. }
  11910. function createBlurDefaultState(el, stateName, state) {
  11911. var hasBlur = indexOf(el.currentStates, stateName) >= 0;
  11912. var currentOpacity = el.style.opacity;
  11913. var fromState = !hasBlur ? getFromStateStyle(el, ['opacity'], stateName, {
  11914. opacity: 1
  11915. }) : null;
  11916. state = state || {};
  11917. var blurStyle = state.style || {};
  11918. if (blurStyle.opacity == null) {
  11919. // clone state
  11920. state = extend({}, state);
  11921. blurStyle = extend({
  11922. // Already being applied 'emphasis'. DON'T mul opacity multiple times.
  11923. opacity: hasBlur ? currentOpacity : fromState.opacity * 0.1
  11924. }, blurStyle);
  11925. state.style = blurStyle;
  11926. }
  11927. return state;
  11928. }
  11929. function elementStateProxy(stateName, targetStates) {
  11930. var state = this.states[stateName];
  11931. if (this.style) {
  11932. if (stateName === 'emphasis') {
  11933. return createEmphasisDefaultState(this, stateName, targetStates, state);
  11934. } else if (stateName === 'blur') {
  11935. return createBlurDefaultState(this, stateName, state);
  11936. } else if (stateName === 'select') {
  11937. return createSelectDefaultState(this, stateName, state);
  11938. }
  11939. }
  11940. return state;
  11941. }
  11942. /**FI
  11943. * Set hover style (namely "emphasis style") of element.
  11944. * @param el Should not be `zrender/graphic/Group`.
  11945. * @param focus 'self' | 'selfInSeries' | 'series'
  11946. */
  11947. function setDefaultStateProxy(el) {
  11948. el.stateProxy = elementStateProxy;
  11949. var textContent = el.getTextContent();
  11950. var textGuide = el.getTextGuideLine();
  11951. if (textContent) {
  11952. textContent.stateProxy = elementStateProxy;
  11953. }
  11954. if (textGuide) {
  11955. textGuide.stateProxy = elementStateProxy;
  11956. }
  11957. }
  11958. function enterEmphasisWhenMouseOver(el, e) {
  11959. !shouldSilent(el, e) // "emphasis" event highlight has higher priority than mouse highlight.
  11960. && !el.__highByOuter && traverseUpdateState(el, singleEnterEmphasis);
  11961. }
  11962. function leaveEmphasisWhenMouseOut(el, e) {
  11963. !shouldSilent(el, e) // "emphasis" event highlight has higher priority than mouse highlight.
  11964. && !el.__highByOuter && traverseUpdateState(el, singleLeaveEmphasis);
  11965. }
  11966. function enterEmphasis(el, highlightDigit) {
  11967. el.__highByOuter |= 1 << (highlightDigit || 0);
  11968. traverseUpdateState(el, singleEnterEmphasis);
  11969. }
  11970. function leaveEmphasis(el, highlightDigit) {
  11971. !(el.__highByOuter &= ~(1 << (highlightDigit || 0))) && traverseUpdateState(el, singleLeaveEmphasis);
  11972. }
  11973. function enterBlur(el) {
  11974. traverseUpdateState(el, singleEnterBlur);
  11975. }
  11976. function leaveBlur(el) {
  11977. traverseUpdateState(el, singleLeaveBlur);
  11978. }
  11979. function enterSelect(el) {
  11980. traverseUpdateState(el, singleEnterSelect);
  11981. }
  11982. function leaveSelect(el) {
  11983. traverseUpdateState(el, singleLeaveSelect);
  11984. }
  11985. function shouldSilent(el, e) {
  11986. return el.__highDownSilentOnTouch && e.zrByTouch;
  11987. }
  11988. function allLeaveBlur(api) {
  11989. var model = api.getModel();
  11990. model.eachComponent(function (componentType, componentModel) {
  11991. var view = componentType === 'series' ? api.getViewOfSeriesModel(componentModel) : api.getViewOfComponentModel(componentModel); // Leave blur anyway
  11992. view.group.traverse(function (child) {
  11993. singleLeaveBlur(child);
  11994. });
  11995. });
  11996. }
  11997. function blurSeries(targetSeriesIndex, focus, blurScope, api) {
  11998. var ecModel = api.getModel();
  11999. blurScope = blurScope || 'coordinateSystem';
  12000. function leaveBlurOfIndices(data, dataIndices) {
  12001. for (var i = 0; i < dataIndices.length; i++) {
  12002. var itemEl = data.getItemGraphicEl(dataIndices[i]);
  12003. itemEl && leaveBlur(itemEl);
  12004. }
  12005. }
  12006. if (targetSeriesIndex == null) {
  12007. return;
  12008. }
  12009. if (!focus || focus === 'none') {
  12010. return;
  12011. }
  12012. var targetSeriesModel = ecModel.getSeriesByIndex(targetSeriesIndex);
  12013. var targetCoordSys = targetSeriesModel.coordinateSystem;
  12014. if (targetCoordSys && targetCoordSys.master) {
  12015. targetCoordSys = targetCoordSys.master;
  12016. }
  12017. var blurredSeries = [];
  12018. ecModel.eachSeries(function (seriesModel) {
  12019. var sameSeries = targetSeriesModel === seriesModel;
  12020. var coordSys = seriesModel.coordinateSystem;
  12021. if (coordSys && coordSys.master) {
  12022. coordSys = coordSys.master;
  12023. }
  12024. var sameCoordSys = coordSys && targetCoordSys ? coordSys === targetCoordSys : sameSeries; // If there is no coordinate system. use sameSeries instead.
  12025. if (!( // Not blur other series if blurScope series
  12026. blurScope === 'series' && !sameSeries // Not blur other coordinate system if blurScope is coordinateSystem
  12027. || blurScope === 'coordinateSystem' && !sameCoordSys // Not blur self series if focus is series.
  12028. || focus === 'series' && sameSeries // TODO blurScope: coordinate system
  12029. )) {
  12030. var view = api.getViewOfSeriesModel(seriesModel);
  12031. view.group.traverse(function (child) {
  12032. singleEnterBlur(child);
  12033. });
  12034. if (isArrayLike(focus)) {
  12035. leaveBlurOfIndices(seriesModel.getData(), focus);
  12036. } else if (isObject(focus)) {
  12037. var dataTypes = keys(focus);
  12038. for (var d = 0; d < dataTypes.length; d++) {
  12039. leaveBlurOfIndices(seriesModel.getData(dataTypes[d]), focus[dataTypes[d]]);
  12040. }
  12041. }
  12042. blurredSeries.push(seriesModel);
  12043. }
  12044. });
  12045. ecModel.eachComponent(function (componentType, componentModel) {
  12046. if (componentType === 'series') {
  12047. return;
  12048. }
  12049. var view = api.getViewOfComponentModel(componentModel);
  12050. if (view && view.blurSeries) {
  12051. view.blurSeries(blurredSeries, ecModel);
  12052. }
  12053. });
  12054. }
  12055. function blurComponent(componentMainType, componentIndex, api) {
  12056. if (componentMainType == null || componentIndex == null) {
  12057. return;
  12058. }
  12059. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12060. if (!componentModel) {
  12061. return;
  12062. }
  12063. var view = api.getViewOfComponentModel(componentModel);
  12064. if (!view || !view.focusBlurEnabled) {
  12065. return;
  12066. }
  12067. view.group.traverse(function (child) {
  12068. singleEnterBlur(child);
  12069. });
  12070. }
  12071. function blurSeriesFromHighlightPayload(seriesModel, payload, api) {
  12072. var seriesIndex = seriesModel.seriesIndex;
  12073. var data = seriesModel.getData(payload.dataType);
  12074. var dataIndex = queryDataIndex(data, payload); // Pick the first one if there is multiple/none exists.
  12075. dataIndex = (isArray(dataIndex) ? dataIndex[0] : dataIndex) || 0;
  12076. var el = data.getItemGraphicEl(dataIndex);
  12077. if (!el) {
  12078. var count = data.count();
  12079. var current = 0; // If data on dataIndex is NaN.
  12080. while (!el && current < count) {
  12081. el = data.getItemGraphicEl(current++);
  12082. }
  12083. }
  12084. if (el) {
  12085. var ecData = getECData(el);
  12086. blurSeries(seriesIndex, ecData.focus, ecData.blurScope, api);
  12087. } else {
  12088. // If there is no element put on the data. Try getting it from raw option
  12089. // TODO Should put it on seriesModel?
  12090. var focus_1 = seriesModel.get(['emphasis', 'focus']);
  12091. var blurScope = seriesModel.get(['emphasis', 'blurScope']);
  12092. if (focus_1 != null) {
  12093. blurSeries(seriesIndex, focus_1, blurScope, api);
  12094. }
  12095. }
  12096. }
  12097. function findComponentHighDownDispatchers(componentMainType, componentIndex, name, api) {
  12098. var ret = {
  12099. focusSelf: false,
  12100. dispatchers: null
  12101. };
  12102. if (componentMainType == null || componentMainType === 'series' || componentIndex == null || name == null) {
  12103. return ret;
  12104. }
  12105. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12106. if (!componentModel) {
  12107. return ret;
  12108. }
  12109. var view = api.getViewOfComponentModel(componentModel);
  12110. if (!view || !view.findHighDownDispatchers) {
  12111. return ret;
  12112. }
  12113. var dispatchers = view.findHighDownDispatchers(name); // At presnet, the component (like Geo) only blur inside itself.
  12114. // So we do not use `blurScope` in component.
  12115. var focusSelf;
  12116. for (var i = 0; i < dispatchers.length; i++) {
  12117. if ("development" !== 'production' && !isHighDownDispatcher(dispatchers[i])) {
  12118. error('param should be highDownDispatcher');
  12119. }
  12120. if (getECData(dispatchers[i]).focus === 'self') {
  12121. focusSelf = true;
  12122. break;
  12123. }
  12124. }
  12125. return {
  12126. focusSelf: focusSelf,
  12127. dispatchers: dispatchers
  12128. };
  12129. }
  12130. function handleGlobalMouseOverForHighDown(dispatcher, e, api) {
  12131. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12132. error('param should be highDownDispatcher');
  12133. }
  12134. var ecData = getECData(dispatcher);
  12135. var _a = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api),
  12136. dispatchers = _a.dispatchers,
  12137. focusSelf = _a.focusSelf; // If `findHighDownDispatchers` is supported on the component,
  12138. // highlight/downplay elements with the same name.
  12139. if (dispatchers) {
  12140. if (focusSelf) {
  12141. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12142. }
  12143. each(dispatchers, function (dispatcher) {
  12144. return enterEmphasisWhenMouseOver(dispatcher, e);
  12145. });
  12146. } else {
  12147. // Try blur all in the related series. Then emphasis the hoverred.
  12148. // TODO. progressive mode.
  12149. blurSeries(ecData.seriesIndex, ecData.focus, ecData.blurScope, api);
  12150. if (ecData.focus === 'self') {
  12151. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12152. } // Other than series, component that not support `findHighDownDispatcher` will
  12153. // also use it. But in this case, highlight/downplay are only supported in
  12154. // mouse hover but not in dispatchAction.
  12155. enterEmphasisWhenMouseOver(dispatcher, e);
  12156. }
  12157. }
  12158. function handleGlboalMouseOutForHighDown(dispatcher, e, api) {
  12159. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12160. error('param should be highDownDispatcher');
  12161. }
  12162. allLeaveBlur(api);
  12163. var ecData = getECData(dispatcher);
  12164. var dispatchers = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api).dispatchers;
  12165. if (dispatchers) {
  12166. each(dispatchers, function (dispatcher) {
  12167. return leaveEmphasisWhenMouseOut(dispatcher, e);
  12168. });
  12169. } else {
  12170. leaveEmphasisWhenMouseOut(dispatcher, e);
  12171. }
  12172. }
  12173. function toggleSelectionFromPayload(seriesModel, payload, api) {
  12174. if (!isSelectChangePayload(payload)) {
  12175. return;
  12176. }
  12177. var dataType = payload.dataType;
  12178. var data = seriesModel.getData(dataType);
  12179. var dataIndex = queryDataIndex(data, payload);
  12180. if (!isArray(dataIndex)) {
  12181. dataIndex = [dataIndex];
  12182. }
  12183. seriesModel[payload.type === TOGGLE_SELECT_ACTION_TYPE ? 'toggleSelect' : payload.type === SELECT_ACTION_TYPE ? 'select' : 'unselect'](dataIndex, dataType);
  12184. }
  12185. function updateSeriesElementSelection(seriesModel) {
  12186. var allData = seriesModel.getAllData();
  12187. each(allData, function (_a) {
  12188. var data = _a.data,
  12189. type = _a.type;
  12190. data.eachItemGraphicEl(function (el, idx) {
  12191. seriesModel.isSelected(idx, type) ? enterSelect(el) : leaveSelect(el);
  12192. });
  12193. });
  12194. }
  12195. function getAllSelectedIndices(ecModel) {
  12196. var ret = [];
  12197. ecModel.eachSeries(function (seriesModel) {
  12198. var allData = seriesModel.getAllData();
  12199. each(allData, function (_a) {
  12200. var data = _a.data,
  12201. type = _a.type;
  12202. var dataIndices = seriesModel.getSelectedDataIndices();
  12203. if (dataIndices.length > 0) {
  12204. var item = {
  12205. dataIndex: dataIndices,
  12206. seriesIndex: seriesModel.seriesIndex
  12207. };
  12208. if (type != null) {
  12209. item.dataType = type;
  12210. }
  12211. ret.push(item);
  12212. }
  12213. });
  12214. });
  12215. return ret;
  12216. }
  12217. /**
  12218. * Enable the function that mouseover will trigger the emphasis state.
  12219. *
  12220. * NOTE:
  12221. * This function should be used on the element with dataIndex, seriesIndex.
  12222. *
  12223. */
  12224. function enableHoverEmphasis(el, focus, blurScope) {
  12225. setAsHighDownDispatcher(el, true);
  12226. traverseUpdateState(el, setDefaultStateProxy);
  12227. enableHoverFocus(el, focus, blurScope);
  12228. }
  12229. function enableHoverFocus(el, focus, blurScope) {
  12230. var ecData = getECData(el);
  12231. if (focus != null) {
  12232. // TODO dataIndex may be set after this function. This check is not useful.
  12233. // if (ecData.dataIndex == null) {
  12234. // if (__DEV__) {
  12235. // console.warn('focus can only been set on element with dataIndex');
  12236. // }
  12237. // }
  12238. // else {
  12239. ecData.focus = focus;
  12240. ecData.blurScope = blurScope; // }
  12241. } else if (ecData.focus) {
  12242. ecData.focus = null;
  12243. }
  12244. }
  12245. var OTHER_STATES = ['emphasis', 'blur', 'select'];
  12246. var defaultStyleGetterMap = {
  12247. itemStyle: 'getItemStyle',
  12248. lineStyle: 'getLineStyle',
  12249. areaStyle: 'getAreaStyle'
  12250. };
  12251. /**
  12252. * Set emphasis/blur/selected states of element.
  12253. */
  12254. function setStatesStylesFromModel(el, itemModel, styleType, // default itemStyle
  12255. getter) {
  12256. styleType = styleType || 'itemStyle';
  12257. for (var i = 0; i < OTHER_STATES.length; i++) {
  12258. var stateName = OTHER_STATES[i];
  12259. var model = itemModel.getModel([stateName, styleType]);
  12260. var state = el.ensureState(stateName); // Let it throw error if getterType is not found.
  12261. state.style = getter ? getter(model) : model[defaultStyleGetterMap[styleType]]();
  12262. }
  12263. }
  12264. /**
  12265. * @parame el
  12266. * @param el.highDownSilentOnTouch
  12267. * In touch device, mouseover event will be trigger on touchstart event
  12268. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  12269. * conveniently use hoverStyle when tap on touch screen without additional
  12270. * code for compatibility.
  12271. * But if the chart/component has select feature, which usually also use
  12272. * hoverStyle, there might be conflict between 'select-highlight' and
  12273. * 'hover-highlight' especially when roam is enabled (see geo for example).
  12274. * In this case, `highDownSilentOnTouch` should be used to disable
  12275. * hover-highlight on touch device.
  12276. * @param asDispatcher If `false`, do not set as "highDownDispatcher".
  12277. */
  12278. function setAsHighDownDispatcher(el, asDispatcher) {
  12279. var disable = asDispatcher === false;
  12280. var extendedEl = el; // Make `highDownSilentOnTouch` and `onStateChange` only work after
  12281. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  12282. if (el.highDownSilentOnTouch) {
  12283. extendedEl.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  12284. } // Simple optimize, since this method might be
  12285. // called for each elements of a group in some cases.
  12286. if (!disable || extendedEl.__highDownDispatcher) {
  12287. // Emphasis, normal can be triggered manually by API or other components like hover link.
  12288. // el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);
  12289. // Also keep previous record.
  12290. extendedEl.__highByOuter = extendedEl.__highByOuter || 0;
  12291. extendedEl.__highDownDispatcher = !disable;
  12292. }
  12293. }
  12294. function isHighDownDispatcher(el) {
  12295. return !!(el && el.__highDownDispatcher);
  12296. }
  12297. /**
  12298. * Support hightlight/downplay record on each elements.
  12299. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  12300. * user triggerred hightlight/downplay should not conflict.
  12301. * Only all of the highlightDigit cleared, return to normal.
  12302. * @param {string} highlightKey
  12303. * @return {number} highlightDigit
  12304. */
  12305. function getHighlightDigit(highlightKey) {
  12306. var highlightDigit = _highlightKeyMap[highlightKey];
  12307. if (highlightDigit == null && _highlightNextDigit <= 32) {
  12308. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  12309. }
  12310. return highlightDigit;
  12311. }
  12312. function isSelectChangePayload(payload) {
  12313. var payloadType = payload.type;
  12314. return payloadType === SELECT_ACTION_TYPE || payloadType === UNSELECT_ACTION_TYPE || payloadType === TOGGLE_SELECT_ACTION_TYPE;
  12315. }
  12316. function isHighDownPayload(payload) {
  12317. var payloadType = payload.type;
  12318. return payloadType === HIGHLIGHT_ACTION_TYPE || payloadType === DOWNPLAY_ACTION_TYPE;
  12319. }
  12320. function savePathStates(el) {
  12321. var store = getSavedStates(el);
  12322. store.normalFill = el.style.fill;
  12323. store.normalStroke = el.style.stroke;
  12324. var selectState = el.states.select || {};
  12325. store.selectFill = selectState.style && selectState.style.fill || null;
  12326. store.selectStroke = selectState.style && selectState.style.stroke || null;
  12327. }
  12328. var CMD$2 = PathProxy.CMD;
  12329. var points = [[], [], []];
  12330. var mathSqrt$2 = Math.sqrt;
  12331. var mathAtan2 = Math.atan2;
  12332. function transformPath(path, m) {
  12333. if (!m) {
  12334. return;
  12335. }
  12336. var data = path.data;
  12337. var len = path.len();
  12338. var cmd;
  12339. var nPoint;
  12340. var i;
  12341. var j;
  12342. var k;
  12343. var p;
  12344. var M = CMD$2.M;
  12345. var C = CMD$2.C;
  12346. var L = CMD$2.L;
  12347. var R = CMD$2.R;
  12348. var A = CMD$2.A;
  12349. var Q = CMD$2.Q;
  12350. for (i = 0, j = 0; i < len;) {
  12351. cmd = data[i++];
  12352. j = i;
  12353. nPoint = 0;
  12354. switch (cmd) {
  12355. case M:
  12356. nPoint = 1;
  12357. break;
  12358. case L:
  12359. nPoint = 1;
  12360. break;
  12361. case C:
  12362. nPoint = 3;
  12363. break;
  12364. case Q:
  12365. nPoint = 2;
  12366. break;
  12367. case A:
  12368. var x = m[4];
  12369. var y = m[5];
  12370. var sx = mathSqrt$2(m[0] * m[0] + m[1] * m[1]);
  12371. var sy = mathSqrt$2(m[2] * m[2] + m[3] * m[3]);
  12372. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  12373. data[i] *= sx;
  12374. data[i++] += x;
  12375. data[i] *= sy;
  12376. data[i++] += y;
  12377. data[i++] *= sx;
  12378. data[i++] *= sy;
  12379. data[i++] += angle;
  12380. data[i++] += angle;
  12381. i += 2;
  12382. j = i;
  12383. break;
  12384. case R:
  12385. p[0] = data[i++];
  12386. p[1] = data[i++];
  12387. applyTransform(p, p, m);
  12388. data[j++] = p[0];
  12389. data[j++] = p[1];
  12390. p[0] += data[i++];
  12391. p[1] += data[i++];
  12392. applyTransform(p, p, m);
  12393. data[j++] = p[0];
  12394. data[j++] = p[1];
  12395. }
  12396. for (k = 0; k < nPoint; k++) {
  12397. var p_1 = points[k];
  12398. p_1[0] = data[i++];
  12399. p_1[1] = data[i++];
  12400. applyTransform(p_1, p_1, m);
  12401. data[j++] = p_1[0];
  12402. data[j++] = p_1[1];
  12403. }
  12404. }
  12405. path.increaseVersion();
  12406. }
  12407. var mathSqrt$3 = Math.sqrt;
  12408. var mathSin$2 = Math.sin;
  12409. var mathCos$2 = Math.cos;
  12410. var PI$1 = Math.PI;
  12411. function vMag(v) {
  12412. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12413. }
  12414. function vRatio(u, v) {
  12415. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12416. }
  12417. function vAngle(u, v) {
  12418. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  12419. * Math.acos(vRatio(u, v));
  12420. }
  12421. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12422. var psi = psiDeg * (PI$1 / 180.0);
  12423. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  12424. + mathSin$2(psi) * (y1 - y2) / 2.0;
  12425. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  12426. + mathCos$2(psi) * (y1 - y2) / 2.0;
  12427. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  12428. if (lambda > 1) {
  12429. rx *= mathSqrt$3(lambda);
  12430. ry *= mathSqrt$3(lambda);
  12431. }
  12432. var f = (fa === fs ? -1 : 1)
  12433. * mathSqrt$3((((rx * rx) * (ry * ry))
  12434. - ((rx * rx) * (yp * yp))
  12435. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  12436. + (ry * ry) * (xp * xp))) || 0;
  12437. var cxp = f * rx * yp / ry;
  12438. var cyp = f * -ry * xp / rx;
  12439. var cx = (x1 + x2) / 2.0
  12440. + mathCos$2(psi) * cxp
  12441. - mathSin$2(psi) * cyp;
  12442. var cy = (y1 + y2) / 2.0
  12443. + mathSin$2(psi) * cxp
  12444. + mathCos$2(psi) * cyp;
  12445. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  12446. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  12447. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  12448. var dTheta = vAngle(u, v);
  12449. if (vRatio(u, v) <= -1) {
  12450. dTheta = PI$1;
  12451. }
  12452. if (vRatio(u, v) >= 1) {
  12453. dTheta = 0;
  12454. }
  12455. if (dTheta < 0) {
  12456. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  12457. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  12458. }
  12459. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  12460. }
  12461. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  12462. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  12463. function createPathProxyFromString(data) {
  12464. var path = new PathProxy();
  12465. if (!data) {
  12466. return path;
  12467. }
  12468. var cpx = 0;
  12469. var cpy = 0;
  12470. var subpathX = cpx;
  12471. var subpathY = cpy;
  12472. var prevCmd;
  12473. var CMD = PathProxy.CMD;
  12474. var cmdList = data.match(commandReg);
  12475. if (!cmdList) {
  12476. return path;
  12477. }
  12478. for (var l = 0; l < cmdList.length; l++) {
  12479. var cmdText = cmdList[l];
  12480. var cmdStr = cmdText.charAt(0);
  12481. var cmd = void 0;
  12482. var p = cmdText.match(numberReg) || [];
  12483. var pLen = p.length;
  12484. for (var i = 0; i < pLen; i++) {
  12485. p[i] = parseFloat(p[i]);
  12486. }
  12487. var off = 0;
  12488. while (off < pLen) {
  12489. var ctlPtx = void 0;
  12490. var ctlPty = void 0;
  12491. var rx = void 0;
  12492. var ry = void 0;
  12493. var psi = void 0;
  12494. var fa = void 0;
  12495. var fs = void 0;
  12496. var x1 = cpx;
  12497. var y1 = cpy;
  12498. var len = void 0;
  12499. var pathData = void 0;
  12500. switch (cmdStr) {
  12501. case 'l':
  12502. cpx += p[off++];
  12503. cpy += p[off++];
  12504. cmd = CMD.L;
  12505. path.addData(cmd, cpx, cpy);
  12506. break;
  12507. case 'L':
  12508. cpx = p[off++];
  12509. cpy = p[off++];
  12510. cmd = CMD.L;
  12511. path.addData(cmd, cpx, cpy);
  12512. break;
  12513. case 'm':
  12514. cpx += p[off++];
  12515. cpy += p[off++];
  12516. cmd = CMD.M;
  12517. path.addData(cmd, cpx, cpy);
  12518. subpathX = cpx;
  12519. subpathY = cpy;
  12520. cmdStr = 'l';
  12521. break;
  12522. case 'M':
  12523. cpx = p[off++];
  12524. cpy = p[off++];
  12525. cmd = CMD.M;
  12526. path.addData(cmd, cpx, cpy);
  12527. subpathX = cpx;
  12528. subpathY = cpy;
  12529. cmdStr = 'L';
  12530. break;
  12531. case 'h':
  12532. cpx += p[off++];
  12533. cmd = CMD.L;
  12534. path.addData(cmd, cpx, cpy);
  12535. break;
  12536. case 'H':
  12537. cpx = p[off++];
  12538. cmd = CMD.L;
  12539. path.addData(cmd, cpx, cpy);
  12540. break;
  12541. case 'v':
  12542. cpy += p[off++];
  12543. cmd = CMD.L;
  12544. path.addData(cmd, cpx, cpy);
  12545. break;
  12546. case 'V':
  12547. cpy = p[off++];
  12548. cmd = CMD.L;
  12549. path.addData(cmd, cpx, cpy);
  12550. break;
  12551. case 'C':
  12552. cmd = CMD.C;
  12553. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  12554. cpx = p[off - 2];
  12555. cpy = p[off - 1];
  12556. break;
  12557. case 'c':
  12558. cmd = CMD.C;
  12559. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  12560. cpx += p[off - 2];
  12561. cpy += p[off - 1];
  12562. break;
  12563. case 'S':
  12564. ctlPtx = cpx;
  12565. ctlPty = cpy;
  12566. len = path.len();
  12567. pathData = path.data;
  12568. if (prevCmd === CMD.C) {
  12569. ctlPtx += cpx - pathData[len - 4];
  12570. ctlPty += cpy - pathData[len - 3];
  12571. }
  12572. cmd = CMD.C;
  12573. x1 = p[off++];
  12574. y1 = p[off++];
  12575. cpx = p[off++];
  12576. cpy = p[off++];
  12577. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12578. break;
  12579. case 's':
  12580. ctlPtx = cpx;
  12581. ctlPty = cpy;
  12582. len = path.len();
  12583. pathData = path.data;
  12584. if (prevCmd === CMD.C) {
  12585. ctlPtx += cpx - pathData[len - 4];
  12586. ctlPty += cpy - pathData[len - 3];
  12587. }
  12588. cmd = CMD.C;
  12589. x1 = cpx + p[off++];
  12590. y1 = cpy + p[off++];
  12591. cpx += p[off++];
  12592. cpy += p[off++];
  12593. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12594. break;
  12595. case 'Q':
  12596. x1 = p[off++];
  12597. y1 = p[off++];
  12598. cpx = p[off++];
  12599. cpy = p[off++];
  12600. cmd = CMD.Q;
  12601. path.addData(cmd, x1, y1, cpx, cpy);
  12602. break;
  12603. case 'q':
  12604. x1 = p[off++] + cpx;
  12605. y1 = p[off++] + cpy;
  12606. cpx += p[off++];
  12607. cpy += p[off++];
  12608. cmd = CMD.Q;
  12609. path.addData(cmd, x1, y1, cpx, cpy);
  12610. break;
  12611. case 'T':
  12612. ctlPtx = cpx;
  12613. ctlPty = cpy;
  12614. len = path.len();
  12615. pathData = path.data;
  12616. if (prevCmd === CMD.Q) {
  12617. ctlPtx += cpx - pathData[len - 4];
  12618. ctlPty += cpy - pathData[len - 3];
  12619. }
  12620. cpx = p[off++];
  12621. cpy = p[off++];
  12622. cmd = CMD.Q;
  12623. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12624. break;
  12625. case 't':
  12626. ctlPtx = cpx;
  12627. ctlPty = cpy;
  12628. len = path.len();
  12629. pathData = path.data;
  12630. if (prevCmd === CMD.Q) {
  12631. ctlPtx += cpx - pathData[len - 4];
  12632. ctlPty += cpy - pathData[len - 3];
  12633. }
  12634. cpx += p[off++];
  12635. cpy += p[off++];
  12636. cmd = CMD.Q;
  12637. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12638. break;
  12639. case 'A':
  12640. rx = p[off++];
  12641. ry = p[off++];
  12642. psi = p[off++];
  12643. fa = p[off++];
  12644. fs = p[off++];
  12645. x1 = cpx, y1 = cpy;
  12646. cpx = p[off++];
  12647. cpy = p[off++];
  12648. cmd = CMD.A;
  12649. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12650. break;
  12651. case 'a':
  12652. rx = p[off++];
  12653. ry = p[off++];
  12654. psi = p[off++];
  12655. fa = p[off++];
  12656. fs = p[off++];
  12657. x1 = cpx, y1 = cpy;
  12658. cpx += p[off++];
  12659. cpy += p[off++];
  12660. cmd = CMD.A;
  12661. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12662. break;
  12663. }
  12664. }
  12665. if (cmdStr === 'z' || cmdStr === 'Z') {
  12666. cmd = CMD.Z;
  12667. path.addData(cmd);
  12668. cpx = subpathX;
  12669. cpy = subpathY;
  12670. }
  12671. prevCmd = cmd;
  12672. }
  12673. path.toStatic();
  12674. return path;
  12675. }
  12676. var SVGPath = (function (_super) {
  12677. __extends(SVGPath, _super);
  12678. function SVGPath() {
  12679. return _super !== null && _super.apply(this, arguments) || this;
  12680. }
  12681. SVGPath.prototype.applyTransform = function (m) { };
  12682. return SVGPath;
  12683. }(Path));
  12684. function isPathProxy(path) {
  12685. return path.setData != null;
  12686. }
  12687. function createPathOptions(str, opts) {
  12688. var pathProxy = createPathProxyFromString(str);
  12689. var innerOpts = extend({}, opts);
  12690. innerOpts.buildPath = function (path) {
  12691. if (isPathProxy(path)) {
  12692. path.setData(pathProxy.data);
  12693. var ctx = path.getContext();
  12694. if (ctx) {
  12695. path.rebuildPath(ctx, 1);
  12696. }
  12697. }
  12698. else {
  12699. var ctx = path;
  12700. pathProxy.rebuildPath(ctx, 1);
  12701. }
  12702. };
  12703. innerOpts.applyTransform = function (m) {
  12704. transformPath(pathProxy, m);
  12705. this.dirtyShape();
  12706. };
  12707. return innerOpts;
  12708. }
  12709. function createFromString(str, opts) {
  12710. return new SVGPath(createPathOptions(str, opts));
  12711. }
  12712. function extendFromString(str, defaultOpts) {
  12713. var innerOpts = createPathOptions(str, defaultOpts);
  12714. var Sub = (function (_super) {
  12715. __extends(Sub, _super);
  12716. function Sub(opts) {
  12717. var _this = _super.call(this, opts) || this;
  12718. _this.applyTransform = innerOpts.applyTransform;
  12719. _this.buildPath = innerOpts.buildPath;
  12720. return _this;
  12721. }
  12722. return Sub;
  12723. }(SVGPath));
  12724. return Sub;
  12725. }
  12726. function mergePath(pathEls, opts) {
  12727. var pathList = [];
  12728. var len = pathEls.length;
  12729. for (var i = 0; i < len; i++) {
  12730. var pathEl = pathEls[i];
  12731. pathList.push(pathEl.getUpdatedPathProxy(true));
  12732. }
  12733. var pathBundle = new Path(opts);
  12734. pathBundle.createPathProxy();
  12735. pathBundle.buildPath = function (path) {
  12736. if (isPathProxy(path)) {
  12737. path.appendPath(pathList);
  12738. var ctx = path.getContext();
  12739. if (ctx) {
  12740. path.rebuildPath(ctx, 1);
  12741. }
  12742. }
  12743. };
  12744. return pathBundle;
  12745. }
  12746. var CircleShape = (function () {
  12747. function CircleShape() {
  12748. this.cx = 0;
  12749. this.cy = 0;
  12750. this.r = 0;
  12751. }
  12752. return CircleShape;
  12753. }());
  12754. var Circle = (function (_super) {
  12755. __extends(Circle, _super);
  12756. function Circle(opts) {
  12757. return _super.call(this, opts) || this;
  12758. }
  12759. Circle.prototype.getDefaultShape = function () {
  12760. return new CircleShape();
  12761. };
  12762. Circle.prototype.buildPath = function (ctx, shape, inBundle) {
  12763. if (inBundle) {
  12764. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12765. }
  12766. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  12767. };
  12768. return Circle;
  12769. }(Path));
  12770. Circle.prototype.type = 'circle';
  12771. var EllipseShape = (function () {
  12772. function EllipseShape() {
  12773. this.cx = 0;
  12774. this.cy = 0;
  12775. this.rx = 0;
  12776. this.ry = 0;
  12777. }
  12778. return EllipseShape;
  12779. }());
  12780. var Ellipse = (function (_super) {
  12781. __extends(Ellipse, _super);
  12782. function Ellipse(opts) {
  12783. return _super.call(this, opts) || this;
  12784. }
  12785. Ellipse.prototype.getDefaultShape = function () {
  12786. return new EllipseShape();
  12787. };
  12788. Ellipse.prototype.buildPath = function (ctx, shape) {
  12789. var k = 0.5522848;
  12790. var x = shape.cx;
  12791. var y = shape.cy;
  12792. var a = shape.rx;
  12793. var b = shape.ry;
  12794. var ox = a * k;
  12795. var oy = b * k;
  12796. ctx.moveTo(x - a, y);
  12797. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  12798. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  12799. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  12800. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  12801. ctx.closePath();
  12802. };
  12803. return Ellipse;
  12804. }(Path));
  12805. Ellipse.prototype.type = 'ellipse';
  12806. var PI$2 = Math.PI;
  12807. var PI2$5 = PI$2 * 2;
  12808. var mathSin$3 = Math.sin;
  12809. var mathCos$3 = Math.cos;
  12810. var mathACos = Math.acos;
  12811. var mathATan2 = Math.atan2;
  12812. var mathAbs$1 = Math.abs;
  12813. var mathSqrt$4 = Math.sqrt;
  12814. var mathMax$3 = Math.max;
  12815. var mathMin$3 = Math.min;
  12816. var e = 1e-4;
  12817. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  12818. var x10 = x1 - x0;
  12819. var y10 = y1 - y0;
  12820. var x32 = x3 - x2;
  12821. var y32 = y3 - y2;
  12822. var t = y32 * x10 - x32 * y10;
  12823. if (t * t < e) {
  12824. return;
  12825. }
  12826. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  12827. return [x0 + t * x10, y0 + t * y10];
  12828. }
  12829. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  12830. var x01 = x0 - x1;
  12831. var y01 = y0 - y1;
  12832. var lo = (clockwise ? cr : -cr) / mathSqrt$4(x01 * x01 + y01 * y01);
  12833. var ox = lo * y01;
  12834. var oy = -lo * x01;
  12835. var x11 = x0 + ox;
  12836. var y11 = y0 + oy;
  12837. var x10 = x1 + ox;
  12838. var y10 = y1 + oy;
  12839. var x00 = (x11 + x10) / 2;
  12840. var y00 = (y11 + y10) / 2;
  12841. var dx = x10 - x11;
  12842. var dy = y10 - y11;
  12843. var d2 = dx * dx + dy * dy;
  12844. var r = radius - cr;
  12845. var s = x11 * y10 - x10 * y11;
  12846. var d = (dy < 0 ? -1 : 1) * mathSqrt$4(mathMax$3(0, r * r * d2 - s * s));
  12847. var cx0 = (s * dy - dx * d) / d2;
  12848. var cy0 = (-s * dx - dy * d) / d2;
  12849. var cx1 = (s * dy + dx * d) / d2;
  12850. var cy1 = (-s * dx + dy * d) / d2;
  12851. var dx0 = cx0 - x00;
  12852. var dy0 = cy0 - y00;
  12853. var dx1 = cx1 - x00;
  12854. var dy1 = cy1 - y00;
  12855. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  12856. cx0 = cx1;
  12857. cy0 = cy1;
  12858. }
  12859. return {
  12860. cx: cx0,
  12861. cy: cy0,
  12862. x01: -ox,
  12863. y01: -oy,
  12864. x11: cx0 * (radius / r - 1),
  12865. y11: cy0 * (radius / r - 1)
  12866. };
  12867. }
  12868. function buildPath$1(ctx, shape) {
  12869. var radius = mathMax$3(shape.r, 0);
  12870. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  12871. var hasRadius = radius > 0;
  12872. var hasInnerRadius = innerRadius > 0;
  12873. if (!hasRadius && !hasInnerRadius) {
  12874. return;
  12875. }
  12876. if (!hasRadius) {
  12877. radius = innerRadius;
  12878. innerRadius = 0;
  12879. }
  12880. if (innerRadius > radius) {
  12881. var tmp = radius;
  12882. radius = innerRadius;
  12883. innerRadius = tmp;
  12884. }
  12885. var clockwise = !!shape.clockwise;
  12886. var startAngle = shape.startAngle;
  12887. var endAngle = shape.endAngle;
  12888. var arc;
  12889. if (startAngle === endAngle) {
  12890. arc = 0;
  12891. }
  12892. else {
  12893. var tmpAngles = [startAngle, endAngle];
  12894. normalizeArcAngles(tmpAngles, !clockwise);
  12895. arc = mathAbs$1(tmpAngles[0] - tmpAngles[1]);
  12896. }
  12897. var x = shape.cx;
  12898. var y = shape.cy;
  12899. var cornerRadius = shape.cornerRadius || 0;
  12900. var innerCornerRadius = shape.innerCornerRadius || 0;
  12901. if (!(radius > e)) {
  12902. ctx.moveTo(x, y);
  12903. }
  12904. else if (arc > PI2$5 - e) {
  12905. ctx.moveTo(x + radius * mathCos$3(startAngle), y + radius * mathSin$3(startAngle));
  12906. ctx.arc(x, y, radius, startAngle, endAngle, !clockwise);
  12907. if (innerRadius > e) {
  12908. ctx.moveTo(x + innerRadius * mathCos$3(endAngle), y + innerRadius * mathSin$3(endAngle));
  12909. ctx.arc(x, y, innerRadius, endAngle, startAngle, clockwise);
  12910. }
  12911. }
  12912. else {
  12913. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  12914. var cr = mathMin$3(halfRd, cornerRadius);
  12915. var icr = mathMin$3(halfRd, innerCornerRadius);
  12916. var cr0 = icr;
  12917. var cr1 = cr;
  12918. var xrs = radius * mathCos$3(startAngle);
  12919. var yrs = radius * mathSin$3(startAngle);
  12920. var xire = innerRadius * mathCos$3(endAngle);
  12921. var yire = innerRadius * mathSin$3(endAngle);
  12922. var xre = void 0;
  12923. var yre = void 0;
  12924. var xirs = void 0;
  12925. var yirs = void 0;
  12926. if (cr > e || icr > e) {
  12927. xre = radius * mathCos$3(endAngle);
  12928. yre = radius * mathSin$3(endAngle);
  12929. xirs = innerRadius * mathCos$3(startAngle);
  12930. yirs = innerRadius * mathSin$3(startAngle);
  12931. if (arc < PI$2) {
  12932. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  12933. if (it_1) {
  12934. var x0 = xrs - it_1[0];
  12935. var y0 = yrs - it_1[1];
  12936. var x1 = xre - it_1[0];
  12937. var y1 = yre - it_1[1];
  12938. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$4(x0 * x0 + y0 * y0) * mathSqrt$4(x1 * x1 + y1 * y1))) / 2);
  12939. var b = mathSqrt$4(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  12940. cr0 = mathMin$3(icr, (innerRadius - b) / (a - 1));
  12941. cr1 = mathMin$3(cr, (radius - b) / (a + 1));
  12942. }
  12943. }
  12944. }
  12945. if (!(arc > e)) {
  12946. ctx.moveTo(x + xrs, y + yrs);
  12947. }
  12948. else if (cr1 > e) {
  12949. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, cr1, clockwise);
  12950. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, cr1, clockwise);
  12951. ctx.moveTo(x + ct0.cx + ct0.x01, y + ct0.cy + ct0.y01);
  12952. if (cr1 < cr) {
  12953. ctx.arc(x + ct0.cx, y + ct0.cy, cr1, mathATan2(ct0.y01, ct0.x01), mathATan2(ct1.y01, ct1.x01), !clockwise);
  12954. }
  12955. else {
  12956. ctx.arc(x + ct0.cx, y + ct0.cy, cr1, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);
  12957. ctx.arc(x, y, radius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), !clockwise);
  12958. ctx.arc(x + ct1.cx, y + ct1.cy, cr1, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
  12959. }
  12960. }
  12961. else {
  12962. ctx.moveTo(x + xrs, y + yrs);
  12963. ctx.arc(x, y, radius, startAngle, endAngle, !clockwise);
  12964. }
  12965. if (!(innerRadius > e) || !(arc > e)) {
  12966. ctx.lineTo(x + xire, y + yire);
  12967. }
  12968. else if (cr0 > e) {
  12969. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -cr0, clockwise);
  12970. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -cr0, clockwise);
  12971. ctx.lineTo(x + ct0.cx + ct0.x01, y + ct0.cy + ct0.y01);
  12972. if (cr0 < icr) {
  12973. ctx.arc(x + ct0.cx, y + ct0.cy, cr0, mathATan2(ct0.y01, ct0.x01), mathATan2(ct1.y01, ct1.x01), !clockwise);
  12974. }
  12975. else {
  12976. ctx.arc(x + ct0.cx, y + ct0.cy, cr0, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);
  12977. ctx.arc(x, y, innerRadius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), clockwise);
  12978. ctx.arc(x + ct1.cx, y + ct1.cy, cr0, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
  12979. }
  12980. }
  12981. else {
  12982. ctx.lineTo(x + xire, y + yire);
  12983. ctx.arc(x, y, innerRadius, endAngle, startAngle, clockwise);
  12984. }
  12985. }
  12986. ctx.closePath();
  12987. }
  12988. var SectorShape = (function () {
  12989. function SectorShape() {
  12990. this.cx = 0;
  12991. this.cy = 0;
  12992. this.r0 = 0;
  12993. this.r = 0;
  12994. this.startAngle = 0;
  12995. this.endAngle = Math.PI * 2;
  12996. this.clockwise = true;
  12997. this.cornerRadius = 0;
  12998. this.innerCornerRadius = 0;
  12999. }
  13000. return SectorShape;
  13001. }());
  13002. var Sector = (function (_super) {
  13003. __extends(Sector, _super);
  13004. function Sector(opts) {
  13005. return _super.call(this, opts) || this;
  13006. }
  13007. Sector.prototype.getDefaultShape = function () {
  13008. return new SectorShape();
  13009. };
  13010. Sector.prototype.buildPath = function (ctx, shape) {
  13011. buildPath$1(ctx, shape);
  13012. };
  13013. Sector.prototype.isZeroArea = function () {
  13014. return this.shape.startAngle === this.shape.endAngle
  13015. || this.shape.r === this.shape.r0;
  13016. };
  13017. return Sector;
  13018. }(Path));
  13019. Sector.prototype.type = 'sector';
  13020. var RingShape = (function () {
  13021. function RingShape() {
  13022. this.cx = 0;
  13023. this.cy = 0;
  13024. this.r = 0;
  13025. this.r0 = 0;
  13026. }
  13027. return RingShape;
  13028. }());
  13029. var Ring = (function (_super) {
  13030. __extends(Ring, _super);
  13031. function Ring(opts) {
  13032. return _super.call(this, opts) || this;
  13033. }
  13034. Ring.prototype.getDefaultShape = function () {
  13035. return new RingShape();
  13036. };
  13037. Ring.prototype.buildPath = function (ctx, shape) {
  13038. var x = shape.cx;
  13039. var y = shape.cy;
  13040. var PI2 = Math.PI * 2;
  13041. ctx.moveTo(x + shape.r, y);
  13042. ctx.arc(x, y, shape.r, 0, PI2, false);
  13043. ctx.moveTo(x + shape.r0, y);
  13044. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13045. };
  13046. return Ring;
  13047. }(Path));
  13048. Ring.prototype.type = 'ring';
  13049. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13050. var v0 = (p2 - p0) * 0.5;
  13051. var v1 = (p3 - p1) * 0.5;
  13052. return (2 * (p1 - p2) + v0 + v1) * t3
  13053. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  13054. + v0 * t + p1;
  13055. }
  13056. function smoothSpline(points, isLoop) {
  13057. var len = points.length;
  13058. var ret = [];
  13059. var distance$1 = 0;
  13060. for (var i = 1; i < len; i++) {
  13061. distance$1 += distance(points[i - 1], points[i]);
  13062. }
  13063. var segs = distance$1 / 2;
  13064. segs = segs < len ? len : segs;
  13065. for (var i = 0; i < segs; i++) {
  13066. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  13067. var idx = Math.floor(pos);
  13068. var w = pos - idx;
  13069. var p0 = void 0;
  13070. var p1 = points[idx % len];
  13071. var p2 = void 0;
  13072. var p3 = void 0;
  13073. if (!isLoop) {
  13074. p0 = points[idx === 0 ? idx : idx - 1];
  13075. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  13076. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  13077. }
  13078. else {
  13079. p0 = points[(idx - 1 + len) % len];
  13080. p2 = points[(idx + 1) % len];
  13081. p3 = points[(idx + 2) % len];
  13082. }
  13083. var w2 = w * w;
  13084. var w3 = w * w2;
  13085. ret.push([
  13086. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13087. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13088. ]);
  13089. }
  13090. return ret;
  13091. }
  13092. function smoothBezier(points, smooth, isLoop, constraint) {
  13093. var cps = [];
  13094. var v = [];
  13095. var v1 = [];
  13096. var v2 = [];
  13097. var prevPoint;
  13098. var nextPoint;
  13099. var min$1;
  13100. var max$1;
  13101. if (constraint) {
  13102. min$1 = [Infinity, Infinity];
  13103. max$1 = [-Infinity, -Infinity];
  13104. for (var i = 0, len = points.length; i < len; i++) {
  13105. min(min$1, min$1, points[i]);
  13106. max(max$1, max$1, points[i]);
  13107. }
  13108. min(min$1, min$1, constraint[0]);
  13109. max(max$1, max$1, constraint[1]);
  13110. }
  13111. for (var i = 0, len = points.length; i < len; i++) {
  13112. var point = points[i];
  13113. if (isLoop) {
  13114. prevPoint = points[i ? i - 1 : len - 1];
  13115. nextPoint = points[(i + 1) % len];
  13116. }
  13117. else {
  13118. if (i === 0 || i === len - 1) {
  13119. cps.push(clone$1(points[i]));
  13120. continue;
  13121. }
  13122. else {
  13123. prevPoint = points[i - 1];
  13124. nextPoint = points[i + 1];
  13125. }
  13126. }
  13127. sub(v, nextPoint, prevPoint);
  13128. scale(v, v, smooth);
  13129. var d0 = distance(point, prevPoint);
  13130. var d1 = distance(point, nextPoint);
  13131. var sum = d0 + d1;
  13132. if (sum !== 0) {
  13133. d0 /= sum;
  13134. d1 /= sum;
  13135. }
  13136. scale(v1, v, -d0);
  13137. scale(v2, v, d1);
  13138. var cp0 = add([], point, v1);
  13139. var cp1 = add([], point, v2);
  13140. if (constraint) {
  13141. max(cp0, cp0, min$1);
  13142. min(cp0, cp0, max$1);
  13143. max(cp1, cp1, min$1);
  13144. min(cp1, cp1, max$1);
  13145. }
  13146. cps.push(cp0);
  13147. cps.push(cp1);
  13148. }
  13149. if (isLoop) {
  13150. cps.push(cps.shift());
  13151. }
  13152. return cps;
  13153. }
  13154. function buildPath$2(ctx, shape, closePath) {
  13155. var smooth = shape.smooth;
  13156. var points = shape.points;
  13157. if (points && points.length >= 2) {
  13158. if (smooth && smooth !== 'spline') {
  13159. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  13160. ctx.moveTo(points[0][0], points[0][1]);
  13161. var len = points.length;
  13162. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13163. var cp1 = controlPoints[i * 2];
  13164. var cp2 = controlPoints[i * 2 + 1];
  13165. var p = points[(i + 1) % len];
  13166. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  13167. }
  13168. }
  13169. else {
  13170. if (smooth === 'spline') {
  13171. points = smoothSpline(points, closePath);
  13172. }
  13173. ctx.moveTo(points[0][0], points[0][1]);
  13174. for (var i = 1, l = points.length; i < l; i++) {
  13175. ctx.lineTo(points[i][0], points[i][1]);
  13176. }
  13177. }
  13178. closePath && ctx.closePath();
  13179. }
  13180. }
  13181. var PolygonShape = (function () {
  13182. function PolygonShape() {
  13183. this.points = null;
  13184. this.smooth = 0;
  13185. this.smoothConstraint = null;
  13186. }
  13187. return PolygonShape;
  13188. }());
  13189. var Polygon = (function (_super) {
  13190. __extends(Polygon, _super);
  13191. function Polygon(opts) {
  13192. return _super.call(this, opts) || this;
  13193. }
  13194. Polygon.prototype.getDefaultShape = function () {
  13195. return new PolygonShape();
  13196. };
  13197. Polygon.prototype.buildPath = function (ctx, shape) {
  13198. buildPath$2(ctx, shape, true);
  13199. };
  13200. return Polygon;
  13201. }(Path));
  13202. Polygon.prototype.type = 'polygon';
  13203. var PolylineShape = (function () {
  13204. function PolylineShape() {
  13205. this.points = null;
  13206. this.percent = 1;
  13207. this.smooth = 0;
  13208. this.smoothConstraint = null;
  13209. }
  13210. return PolylineShape;
  13211. }());
  13212. var Polyline = (function (_super) {
  13213. __extends(Polyline, _super);
  13214. function Polyline(opts) {
  13215. return _super.call(this, opts) || this;
  13216. }
  13217. Polyline.prototype.getDefaultStyle = function () {
  13218. return {
  13219. stroke: '#000',
  13220. fill: null
  13221. };
  13222. };
  13223. Polyline.prototype.getDefaultShape = function () {
  13224. return new PolylineShape();
  13225. };
  13226. Polyline.prototype.buildPath = function (ctx, shape) {
  13227. buildPath$2(ctx, shape, false);
  13228. };
  13229. return Polyline;
  13230. }(Path));
  13231. Polyline.prototype.type = 'polyline';
  13232. var subPixelOptimizeOutputShape$1 = {};
  13233. var LineShape = (function () {
  13234. function LineShape() {
  13235. this.x1 = 0;
  13236. this.y1 = 0;
  13237. this.x2 = 0;
  13238. this.y2 = 0;
  13239. this.percent = 1;
  13240. }
  13241. return LineShape;
  13242. }());
  13243. var Line = (function (_super) {
  13244. __extends(Line, _super);
  13245. function Line(opts) {
  13246. return _super.call(this, opts) || this;
  13247. }
  13248. Line.prototype.getDefaultStyle = function () {
  13249. return {
  13250. stroke: '#000',
  13251. fill: null
  13252. };
  13253. };
  13254. Line.prototype.getDefaultShape = function () {
  13255. return new LineShape();
  13256. };
  13257. Line.prototype.buildPath = function (ctx, shape) {
  13258. var x1;
  13259. var y1;
  13260. var x2;
  13261. var y2;
  13262. if (this.subPixelOptimize) {
  13263. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  13264. x1 = optimizedShape.x1;
  13265. y1 = optimizedShape.y1;
  13266. x2 = optimizedShape.x2;
  13267. y2 = optimizedShape.y2;
  13268. }
  13269. else {
  13270. x1 = shape.x1;
  13271. y1 = shape.y1;
  13272. x2 = shape.x2;
  13273. y2 = shape.y2;
  13274. }
  13275. var percent = shape.percent;
  13276. if (percent === 0) {
  13277. return;
  13278. }
  13279. ctx.moveTo(x1, y1);
  13280. if (percent < 1) {
  13281. x2 = x1 * (1 - percent) + x2 * percent;
  13282. y2 = y1 * (1 - percent) + y2 * percent;
  13283. }
  13284. ctx.lineTo(x2, y2);
  13285. };
  13286. Line.prototype.pointAt = function (p) {
  13287. var shape = this.shape;
  13288. return [
  13289. shape.x1 * (1 - p) + shape.x2 * p,
  13290. shape.y1 * (1 - p) + shape.y2 * p
  13291. ];
  13292. };
  13293. return Line;
  13294. }(Path));
  13295. Line.prototype.type = 'line';
  13296. var out = [];
  13297. var BezierCurveShape = (function () {
  13298. function BezierCurveShape() {
  13299. this.x1 = 0;
  13300. this.y1 = 0;
  13301. this.x2 = 0;
  13302. this.y2 = 0;
  13303. this.cpx1 = 0;
  13304. this.cpy1 = 0;
  13305. this.percent = 1;
  13306. }
  13307. return BezierCurveShape;
  13308. }());
  13309. function someVectorAt(shape, t, isTangent) {
  13310. var cpx2 = shape.cpx2;
  13311. var cpy2 = shape.cpy2;
  13312. if (cpx2 === null || cpy2 === null) {
  13313. return [
  13314. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13315. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13316. ];
  13317. }
  13318. else {
  13319. return [
  13320. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13321. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13322. ];
  13323. }
  13324. }
  13325. var BezierCurve = (function (_super) {
  13326. __extends(BezierCurve, _super);
  13327. function BezierCurve(opts) {
  13328. return _super.call(this, opts) || this;
  13329. }
  13330. BezierCurve.prototype.getDefaultStyle = function () {
  13331. return {
  13332. stroke: '#000',
  13333. fill: null
  13334. };
  13335. };
  13336. BezierCurve.prototype.getDefaultShape = function () {
  13337. return new BezierCurveShape();
  13338. };
  13339. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13340. var x1 = shape.x1;
  13341. var y1 = shape.y1;
  13342. var x2 = shape.x2;
  13343. var y2 = shape.y2;
  13344. var cpx1 = shape.cpx1;
  13345. var cpy1 = shape.cpy1;
  13346. var cpx2 = shape.cpx2;
  13347. var cpy2 = shape.cpy2;
  13348. var percent = shape.percent;
  13349. if (percent === 0) {
  13350. return;
  13351. }
  13352. ctx.moveTo(x1, y1);
  13353. if (cpx2 == null || cpy2 == null) {
  13354. if (percent < 1) {
  13355. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13356. cpx1 = out[1];
  13357. x2 = out[2];
  13358. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13359. cpy1 = out[1];
  13360. y2 = out[2];
  13361. }
  13362. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13363. }
  13364. else {
  13365. if (percent < 1) {
  13366. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13367. cpx1 = out[1];
  13368. cpx2 = out[2];
  13369. x2 = out[3];
  13370. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13371. cpy1 = out[1];
  13372. cpy2 = out[2];
  13373. y2 = out[3];
  13374. }
  13375. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13376. }
  13377. };
  13378. BezierCurve.prototype.pointAt = function (t) {
  13379. return someVectorAt(this.shape, t, false);
  13380. };
  13381. BezierCurve.prototype.tangentAt = function (t) {
  13382. var p = someVectorAt(this.shape, t, true);
  13383. return normalize(p, p);
  13384. };
  13385. return BezierCurve;
  13386. }(Path));
  13387. BezierCurve.prototype.type = 'bezier-curve';
  13388. var ArcShape = (function () {
  13389. function ArcShape() {
  13390. this.cx = 0;
  13391. this.cy = 0;
  13392. this.r = 0;
  13393. this.startAngle = 0;
  13394. this.endAngle = Math.PI * 2;
  13395. this.clockwise = true;
  13396. }
  13397. return ArcShape;
  13398. }());
  13399. var Arc = (function (_super) {
  13400. __extends(Arc, _super);
  13401. function Arc(opts) {
  13402. return _super.call(this, opts) || this;
  13403. }
  13404. Arc.prototype.getDefaultStyle = function () {
  13405. return {
  13406. stroke: '#000',
  13407. fill: null
  13408. };
  13409. };
  13410. Arc.prototype.getDefaultShape = function () {
  13411. return new ArcShape();
  13412. };
  13413. Arc.prototype.buildPath = function (ctx, shape) {
  13414. var x = shape.cx;
  13415. var y = shape.cy;
  13416. var r = Math.max(shape.r, 0);
  13417. var startAngle = shape.startAngle;
  13418. var endAngle = shape.endAngle;
  13419. var clockwise = shape.clockwise;
  13420. var unitX = Math.cos(startAngle);
  13421. var unitY = Math.sin(startAngle);
  13422. ctx.moveTo(unitX * r + x, unitY * r + y);
  13423. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13424. };
  13425. return Arc;
  13426. }(Path));
  13427. Arc.prototype.type = 'arc';
  13428. var CompoundPath = (function (_super) {
  13429. __extends(CompoundPath, _super);
  13430. function CompoundPath() {
  13431. var _this = _super !== null && _super.apply(this, arguments) || this;
  13432. _this.type = 'compound';
  13433. return _this;
  13434. }
  13435. CompoundPath.prototype._updatePathDirty = function () {
  13436. var paths = this.shape.paths;
  13437. var dirtyPath = this.shapeChanged();
  13438. for (var i = 0; i < paths.length; i++) {
  13439. dirtyPath = dirtyPath || paths[i].shapeChanged();
  13440. }
  13441. if (dirtyPath) {
  13442. this.dirtyShape();
  13443. }
  13444. };
  13445. CompoundPath.prototype.beforeBrush = function () {
  13446. this._updatePathDirty();
  13447. var paths = this.shape.paths || [];
  13448. var scale = this.getGlobalScale();
  13449. for (var i = 0; i < paths.length; i++) {
  13450. if (!paths[i].path) {
  13451. paths[i].createPathProxy();
  13452. }
  13453. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  13454. }
  13455. };
  13456. CompoundPath.prototype.buildPath = function (ctx, shape) {
  13457. var paths = shape.paths || [];
  13458. for (var i = 0; i < paths.length; i++) {
  13459. paths[i].buildPath(ctx, paths[i].shape, true);
  13460. }
  13461. };
  13462. CompoundPath.prototype.afterBrush = function () {
  13463. var paths = this.shape.paths || [];
  13464. for (var i = 0; i < paths.length; i++) {
  13465. paths[i].pathUpdated();
  13466. }
  13467. };
  13468. CompoundPath.prototype.getBoundingRect = function () {
  13469. this._updatePathDirty.call(this);
  13470. return Path.prototype.getBoundingRect.call(this);
  13471. };
  13472. return CompoundPath;
  13473. }(Path));
  13474. var Gradient = (function () {
  13475. function Gradient(colorStops) {
  13476. this.colorStops = colorStops || [];
  13477. }
  13478. Gradient.prototype.addColorStop = function (offset, color) {
  13479. this.colorStops.push({
  13480. offset: offset,
  13481. color: color
  13482. });
  13483. };
  13484. return Gradient;
  13485. }());
  13486. var LinearGradient = (function (_super) {
  13487. __extends(LinearGradient, _super);
  13488. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  13489. var _this = _super.call(this, colorStops) || this;
  13490. _this.x = x == null ? 0 : x;
  13491. _this.y = y == null ? 0 : y;
  13492. _this.x2 = x2 == null ? 1 : x2;
  13493. _this.y2 = y2 == null ? 0 : y2;
  13494. _this.type = 'linear';
  13495. _this.global = globalCoord || false;
  13496. return _this;
  13497. }
  13498. return LinearGradient;
  13499. }(Gradient));
  13500. var RadialGradient = (function (_super) {
  13501. __extends(RadialGradient, _super);
  13502. function RadialGradient(x, y, r, colorStops, globalCoord) {
  13503. var _this = _super.call(this, colorStops) || this;
  13504. _this.x = x == null ? 0.5 : x;
  13505. _this.y = y == null ? 0.5 : y;
  13506. _this.r = r == null ? 0.5 : r;
  13507. _this.type = 'radial';
  13508. _this.global = globalCoord || false;
  13509. return _this;
  13510. }
  13511. return RadialGradient;
  13512. }(Gradient));
  13513. var extent = [0, 0];
  13514. var extent2 = [0, 0];
  13515. var minTv$1 = new Point();
  13516. var maxTv$1 = new Point();
  13517. var OrientedBoundingRect = (function () {
  13518. function OrientedBoundingRect(rect, transform) {
  13519. this._corners = [];
  13520. this._axes = [];
  13521. this._origin = [0, 0];
  13522. for (var i = 0; i < 4; i++) {
  13523. this._corners[i] = new Point();
  13524. }
  13525. for (var i = 0; i < 2; i++) {
  13526. this._axes[i] = new Point();
  13527. }
  13528. if (rect) {
  13529. this.fromBoundingRect(rect, transform);
  13530. }
  13531. }
  13532. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13533. var corners = this._corners;
  13534. var axes = this._axes;
  13535. var x = rect.x;
  13536. var y = rect.y;
  13537. var x2 = x + rect.width;
  13538. var y2 = y + rect.height;
  13539. corners[0].set(x, y);
  13540. corners[1].set(x2, y);
  13541. corners[2].set(x2, y2);
  13542. corners[3].set(x, y2);
  13543. if (transform) {
  13544. for (var i = 0; i < 4; i++) {
  13545. corners[i].transform(transform);
  13546. }
  13547. }
  13548. Point.sub(axes[0], corners[1], corners[0]);
  13549. Point.sub(axes[1], corners[3], corners[0]);
  13550. axes[0].normalize();
  13551. axes[1].normalize();
  13552. for (var i = 0; i < 2; i++) {
  13553. this._origin[i] = axes[i].dot(corners[0]);
  13554. }
  13555. };
  13556. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13557. var overlapped = true;
  13558. var noMtv = !mtv;
  13559. minTv$1.set(Infinity, Infinity);
  13560. maxTv$1.set(0, 0);
  13561. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13562. overlapped = false;
  13563. if (noMtv) {
  13564. return overlapped;
  13565. }
  13566. }
  13567. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13568. overlapped = false;
  13569. if (noMtv) {
  13570. return overlapped;
  13571. }
  13572. }
  13573. if (!noMtv) {
  13574. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  13575. }
  13576. return overlapped;
  13577. };
  13578. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  13579. var overlapped = true;
  13580. for (var i = 0; i < 2; i++) {
  13581. var axis = this._axes[i];
  13582. this._getProjMinMaxOnAxis(i, self._corners, extent);
  13583. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  13584. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  13585. overlapped = false;
  13586. if (noMtv) {
  13587. return overlapped;
  13588. }
  13589. var dist0 = Math.abs(extent2[0] - extent[1]);
  13590. var dist1 = Math.abs(extent[0] - extent2[1]);
  13591. if (Math.min(dist0, dist1) > maxTv.len()) {
  13592. if (dist0 < dist1) {
  13593. Point.scale(maxTv, axis, -dist0 * inverse);
  13594. }
  13595. else {
  13596. Point.scale(maxTv, axis, dist1 * inverse);
  13597. }
  13598. }
  13599. }
  13600. else if (minTv) {
  13601. var dist0 = Math.abs(extent2[0] - extent[1]);
  13602. var dist1 = Math.abs(extent[0] - extent2[1]);
  13603. if (Math.min(dist0, dist1) < minTv.len()) {
  13604. if (dist0 < dist1) {
  13605. Point.scale(minTv, axis, dist0 * inverse);
  13606. }
  13607. else {
  13608. Point.scale(minTv, axis, -dist1 * inverse);
  13609. }
  13610. }
  13611. }
  13612. }
  13613. return overlapped;
  13614. };
  13615. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  13616. var axis = this._axes[dim];
  13617. var origin = this._origin;
  13618. var proj = corners[0].dot(axis) + origin[dim];
  13619. var min = proj;
  13620. var max = proj;
  13621. for (var i = 1; i < corners.length; i++) {
  13622. var proj_1 = corners[i].dot(axis) + origin[dim];
  13623. min = Math.min(proj_1, min);
  13624. max = Math.max(proj_1, max);
  13625. }
  13626. out[0] = min;
  13627. out[1] = max;
  13628. };
  13629. return OrientedBoundingRect;
  13630. }());
  13631. var m = [];
  13632. var IncrementalDisplayable = (function (_super) {
  13633. __extends(IncrementalDisplayable, _super);
  13634. function IncrementalDisplayable() {
  13635. var _this = _super !== null && _super.apply(this, arguments) || this;
  13636. _this.notClear = true;
  13637. _this.incremental = true;
  13638. _this._displayables = [];
  13639. _this._temporaryDisplayables = [];
  13640. _this._cursor = 0;
  13641. return _this;
  13642. }
  13643. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  13644. cb.call(context, this);
  13645. };
  13646. IncrementalDisplayable.prototype.useStyle = function () {
  13647. this.style = {};
  13648. };
  13649. IncrementalDisplayable.prototype.getCursor = function () {
  13650. return this._cursor;
  13651. };
  13652. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  13653. this._cursor = this._displayables.length;
  13654. };
  13655. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  13656. this._displayables = [];
  13657. this._temporaryDisplayables = [];
  13658. this._cursor = 0;
  13659. this.markRedraw();
  13660. this.notClear = false;
  13661. };
  13662. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  13663. this._temporaryDisplayables = [];
  13664. };
  13665. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  13666. if (notPersistent) {
  13667. this._temporaryDisplayables.push(displayable);
  13668. }
  13669. else {
  13670. this._displayables.push(displayable);
  13671. }
  13672. this.markRedraw();
  13673. };
  13674. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  13675. notPersistent = notPersistent || false;
  13676. for (var i = 0; i < displayables.length; i++) {
  13677. this.addDisplayable(displayables[i], notPersistent);
  13678. }
  13679. };
  13680. IncrementalDisplayable.prototype.getDisplayables = function () {
  13681. return this._displayables;
  13682. };
  13683. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  13684. return this._temporaryDisplayables;
  13685. };
  13686. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  13687. for (var i = this._cursor; i < this._displayables.length; i++) {
  13688. cb && cb(this._displayables[i]);
  13689. }
  13690. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13691. cb && cb(this._temporaryDisplayables[i]);
  13692. }
  13693. };
  13694. IncrementalDisplayable.prototype.update = function () {
  13695. this.updateTransform();
  13696. for (var i = this._cursor; i < this._displayables.length; i++) {
  13697. var displayable = this._displayables[i];
  13698. displayable.parent = this;
  13699. displayable.update();
  13700. displayable.parent = null;
  13701. }
  13702. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13703. var displayable = this._temporaryDisplayables[i];
  13704. displayable.parent = this;
  13705. displayable.update();
  13706. displayable.parent = null;
  13707. }
  13708. };
  13709. IncrementalDisplayable.prototype.getBoundingRect = function () {
  13710. if (!this._rect) {
  13711. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  13712. for (var i = 0; i < this._displayables.length; i++) {
  13713. var displayable = this._displayables[i];
  13714. var childRect = displayable.getBoundingRect().clone();
  13715. if (displayable.needLocalTransform()) {
  13716. childRect.applyTransform(displayable.getLocalTransform(m));
  13717. }
  13718. rect.union(childRect);
  13719. }
  13720. this._rect = rect;
  13721. }
  13722. return this._rect;
  13723. };
  13724. IncrementalDisplayable.prototype.contain = function (x, y) {
  13725. var localPos = this.transformCoordToLocal(x, y);
  13726. var rect = this.getBoundingRect();
  13727. if (rect.contain(localPos[0], localPos[1])) {
  13728. for (var i = 0; i < this._displayables.length; i++) {
  13729. var displayable = this._displayables[i];
  13730. if (displayable.contain(x, y)) {
  13731. return true;
  13732. }
  13733. }
  13734. }
  13735. return false;
  13736. };
  13737. return IncrementalDisplayable;
  13738. }(Displayable));
  13739. var transitionStore = makeInner();
  13740. /**
  13741. * Return null if animation is disabled.
  13742. */
  13743. function getAnimationConfig(animationType, animatableModel, dataIndex, // Extra opts can override the option in animatable model.
  13744. extraOpts, // TODO It's only for pictorial bar now.
  13745. extraDelayParams) {
  13746. var animationPayload; // Check if there is global animation configuration from dataZoom/resize can override the config in option.
  13747. // If animation is enabled. Will use this animation config in payload.
  13748. // If animation is disabled. Just ignore it.
  13749. if (animatableModel && animatableModel.ecModel) {
  13750. var updatePayload = animatableModel.ecModel.getUpdatePayload();
  13751. animationPayload = updatePayload && updatePayload.animation;
  13752. }
  13753. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  13754. var isUpdate = animationType === 'update';
  13755. if (animationEnabled) {
  13756. var duration = void 0;
  13757. var easing = void 0;
  13758. var delay = void 0;
  13759. if (extraOpts) {
  13760. duration = retrieve2(extraOpts.duration, 200);
  13761. easing = retrieve2(extraOpts.easing, 'cubicOut');
  13762. delay = 0;
  13763. } else {
  13764. duration = animatableModel.getShallow(isUpdate ? 'animationDurationUpdate' : 'animationDuration');
  13765. easing = animatableModel.getShallow(isUpdate ? 'animationEasingUpdate' : 'animationEasing');
  13766. delay = animatableModel.getShallow(isUpdate ? 'animationDelayUpdate' : 'animationDelay');
  13767. } // animation from payload has highest priority.
  13768. if (animationPayload) {
  13769. animationPayload.duration != null && (duration = animationPayload.duration);
  13770. animationPayload.easing != null && (easing = animationPayload.easing);
  13771. animationPayload.delay != null && (delay = animationPayload.delay);
  13772. }
  13773. if (typeof delay === 'function') {
  13774. delay = delay(dataIndex, extraDelayParams);
  13775. }
  13776. if (typeof duration === 'function') {
  13777. duration = duration(dataIndex);
  13778. }
  13779. var config = {
  13780. duration: duration || 0,
  13781. delay: delay,
  13782. easing: easing
  13783. };
  13784. return config;
  13785. } else {
  13786. return null;
  13787. }
  13788. }
  13789. function animateOrSetProps(animationType, el, props, animatableModel, dataIndex, cb, during) {
  13790. var isFrom = false;
  13791. var removeOpt;
  13792. if (typeof dataIndex === 'function') {
  13793. during = cb;
  13794. cb = dataIndex;
  13795. dataIndex = null;
  13796. } else if (isObject(dataIndex)) {
  13797. cb = dataIndex.cb;
  13798. during = dataIndex.during;
  13799. isFrom = dataIndex.isFrom;
  13800. removeOpt = dataIndex.removeOpt;
  13801. dataIndex = dataIndex.dataIndex;
  13802. }
  13803. var isRemove = animationType === 'remove';
  13804. if (!isRemove) {
  13805. // Must stop the remove animation.
  13806. el.stopAnimation('remove');
  13807. }
  13808. var animationConfig = getAnimationConfig(animationType, animatableModel, dataIndex, isRemove ? removeOpt || {} : null, animatableModel && animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  13809. if (animationConfig && animationConfig.duration > 0) {
  13810. var duration = animationConfig.duration;
  13811. var animationDelay = animationConfig.delay;
  13812. var animationEasing = animationConfig.easing;
  13813. var animateConfig = {
  13814. duration: duration,
  13815. delay: animationDelay || 0,
  13816. easing: animationEasing,
  13817. done: cb,
  13818. force: !!cb || !!during,
  13819. // Set to final state in update/init animation.
  13820. // So the post processing based on the path shape can be done correctly.
  13821. setToFinal: !isRemove,
  13822. scope: animationType,
  13823. during: during
  13824. };
  13825. isFrom ? el.animateFrom(props, animateConfig) : el.animateTo(props, animateConfig);
  13826. } else {
  13827. el.stopAnimation(); // If `isFrom`, the props is the "from" props.
  13828. !isFrom && el.attr(props); // Call during at least once.
  13829. during && during(1);
  13830. cb && cb();
  13831. }
  13832. }
  13833. /**
  13834. * Update graphic element properties with or without animation according to the
  13835. * configuration in series.
  13836. *
  13837. * Caution: this method will stop previous animation.
  13838. * So do not use this method to one element twice before
  13839. * animation starts, unless you know what you are doing.
  13840. * @example
  13841. * graphic.updateProps(el, {
  13842. * position: [100, 100]
  13843. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  13844. * // Or
  13845. * graphic.updateProps(el, {
  13846. * position: [100, 100]
  13847. * }, seriesModel, function () { console.log('Animation done!'); });
  13848. */
  13849. function updateProps(el, props, // TODO: TYPE AnimatableModel
  13850. animatableModel, dataIndex, cb, during) {
  13851. animateOrSetProps('update', el, props, animatableModel, dataIndex, cb, during);
  13852. }
  13853. /**
  13854. * Init graphic element properties with or without animation according to the
  13855. * configuration in series.
  13856. *
  13857. * Caution: this method will stop previous animation.
  13858. * So do not use this method to one element twice before
  13859. * animation starts, unless you know what you are doing.
  13860. */
  13861. function initProps(el, props, animatableModel, dataIndex, cb, during) {
  13862. animateOrSetProps('init', el, props, animatableModel, dataIndex, cb, during);
  13863. }
  13864. /**
  13865. * If element is removed.
  13866. * It can determine if element is having remove animation.
  13867. */
  13868. function isElementRemoved(el) {
  13869. if (!el.__zr) {
  13870. return true;
  13871. }
  13872. for (var i = 0; i < el.animators.length; i++) {
  13873. var animator = el.animators[i];
  13874. if (animator.scope === 'remove') {
  13875. return true;
  13876. }
  13877. }
  13878. return false;
  13879. }
  13880. /**
  13881. * Remove graphic element
  13882. */
  13883. function removeElement(el, props, animatableModel, dataIndex, cb, during) {
  13884. // Don't do remove animation twice.
  13885. if (isElementRemoved(el)) {
  13886. return;
  13887. }
  13888. animateOrSetProps('remove', el, props, animatableModel, dataIndex, cb, during);
  13889. }
  13890. function fadeOutDisplayable(el, animatableModel, dataIndex, done) {
  13891. el.removeTextContent();
  13892. el.removeTextGuideLine();
  13893. removeElement(el, {
  13894. style: {
  13895. opacity: 0
  13896. }
  13897. }, animatableModel, dataIndex, done);
  13898. }
  13899. function removeElementWithFadeOut(el, animatableModel, dataIndex) {
  13900. function doRemove() {
  13901. el.parent && el.parent.remove(el);
  13902. } // Hide label and labelLine first
  13903. // TODO Also use fade out animation?
  13904. if (!el.isGroup) {
  13905. fadeOutDisplayable(el, animatableModel, dataIndex, doRemove);
  13906. } else {
  13907. el.traverse(function (disp) {
  13908. if (!disp.isGroup) {
  13909. // Can invoke doRemove multiple times.
  13910. fadeOutDisplayable(disp, animatableModel, dataIndex, doRemove);
  13911. }
  13912. });
  13913. }
  13914. }
  13915. /**
  13916. * Save old style for style transition in universalTransition module.
  13917. * It's used when element will be reused in each render.
  13918. * For chart like map, heatmap, which will always create new element.
  13919. * We don't need to save this because universalTransition can get old style from the old element
  13920. */
  13921. function saveOldStyle(el) {
  13922. transitionStore(el).oldStyle = el.style;
  13923. }
  13924. var mathMax$4 = Math.max;
  13925. var mathMin$4 = Math.min;
  13926. var _customShapeMap = {};
  13927. /**
  13928. * Extend shape with parameters
  13929. */
  13930. function extendShape(opts) {
  13931. return Path.extend(opts);
  13932. }
  13933. var extendPathFromString = extendFromString;
  13934. /**
  13935. * Extend path
  13936. */
  13937. function extendPath(pathData, opts) {
  13938. return extendPathFromString(pathData, opts);
  13939. }
  13940. /**
  13941. * Register a user defined shape.
  13942. * The shape class can be fetched by `getShapeClass`
  13943. * This method will overwrite the registered shapes, including
  13944. * the registered built-in shapes, if using the same `name`.
  13945. * The shape can be used in `custom series` and
  13946. * `graphic component` by declaring `{type: name}`.
  13947. *
  13948. * @param name
  13949. * @param ShapeClass Can be generated by `extendShape`.
  13950. */
  13951. function registerShape(name, ShapeClass) {
  13952. _customShapeMap[name] = ShapeClass;
  13953. }
  13954. /**
  13955. * Find shape class registered by `registerShape`. Usually used in
  13956. * fetching user defined shape.
  13957. *
  13958. * [Caution]:
  13959. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  13960. * to use user registered shapes.
  13961. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  13962. * `registerShape` by default. That enables users to get both built-in
  13963. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  13964. * the built-in shapes by using names like 'circle', 'rect' via calling
  13965. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  13966. * in case that it is overwritten by users, except that some features, like
  13967. * `custom series`, `graphic component`, do it deliberately.
  13968. *
  13969. * (2) In the features like `custom series`, `graphic component`, the user input
  13970. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  13971. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  13972. * are reserved names, that is, if some user register a shape named `'image'`,
  13973. * the shape will not be used. If we intending to add some more reserved names
  13974. * in feature, that might bring break changes (disable some existing user shape
  13975. * names). But that case probably rearly happen. So we dont make more mechanism
  13976. * to resolve this issue here.
  13977. *
  13978. * @param name
  13979. * @return The shape class. If not found, return nothing.
  13980. */
  13981. function getShapeClass(name) {
  13982. if (_customShapeMap.hasOwnProperty(name)) {
  13983. return _customShapeMap[name];
  13984. }
  13985. }
  13986. /**
  13987. * Create a path element from path data string
  13988. * @param pathData
  13989. * @param opts
  13990. * @param rect
  13991. * @param layout 'center' or 'cover' default to be cover
  13992. */
  13993. function makePath(pathData, opts, rect, layout) {
  13994. var path = createFromString(pathData, opts);
  13995. if (rect) {
  13996. if (layout === 'center') {
  13997. rect = centerGraphic(rect, path.getBoundingRect());
  13998. }
  13999. resizePath(path, rect);
  14000. }
  14001. return path;
  14002. }
  14003. /**
  14004. * Create a image element from image url
  14005. * @param imageUrl image url
  14006. * @param opts options
  14007. * @param rect constrain rect
  14008. * @param layout 'center' or 'cover'. Default to be 'cover'
  14009. */
  14010. function makeImage(imageUrl, rect, layout) {
  14011. var zrImg = new ZRImage({
  14012. style: {
  14013. image: imageUrl,
  14014. x: rect.x,
  14015. y: rect.y,
  14016. width: rect.width,
  14017. height: rect.height
  14018. },
  14019. onload: function (img) {
  14020. if (layout === 'center') {
  14021. var boundingRect = {
  14022. width: img.width,
  14023. height: img.height
  14024. };
  14025. zrImg.setStyle(centerGraphic(rect, boundingRect));
  14026. }
  14027. }
  14028. });
  14029. return zrImg;
  14030. }
  14031. /**
  14032. * Get position of centered element in bounding box.
  14033. *
  14034. * @param rect element local bounding box
  14035. * @param boundingRect constraint bounding box
  14036. * @return element position containing x, y, width, and height
  14037. */
  14038. function centerGraphic(rect, boundingRect) {
  14039. // Set rect to center, keep width / height ratio.
  14040. var aspect = boundingRect.width / boundingRect.height;
  14041. var width = rect.height * aspect;
  14042. var height;
  14043. if (width <= rect.width) {
  14044. height = rect.height;
  14045. } else {
  14046. width = rect.width;
  14047. height = width / aspect;
  14048. }
  14049. var cx = rect.x + rect.width / 2;
  14050. var cy = rect.y + rect.height / 2;
  14051. return {
  14052. x: cx - width / 2,
  14053. y: cy - height / 2,
  14054. width: width,
  14055. height: height
  14056. };
  14057. }
  14058. var mergePath$1 = mergePath;
  14059. /**
  14060. * Resize a path to fit the rect
  14061. * @param path
  14062. * @param rect
  14063. */
  14064. function resizePath(path, rect) {
  14065. if (!path.applyTransform) {
  14066. return;
  14067. }
  14068. var pathRect = path.getBoundingRect();
  14069. var m = pathRect.calculateTransform(rect);
  14070. path.applyTransform(m);
  14071. }
  14072. /**
  14073. * Sub pixel optimize line for canvas
  14074. */
  14075. function subPixelOptimizeLine$1(param) {
  14076. subPixelOptimizeLine(param.shape, param.shape, param.style);
  14077. return param;
  14078. }
  14079. /**
  14080. * Sub pixel optimize rect for canvas
  14081. */
  14082. function subPixelOptimizeRect$1(param) {
  14083. subPixelOptimizeRect(param.shape, param.shape, param.style);
  14084. return param;
  14085. }
  14086. /**
  14087. * Sub pixel optimize for canvas
  14088. *
  14089. * @param position Coordinate, such as x, y
  14090. * @param lineWidth Should be nonnegative integer.
  14091. * @param positiveOrNegative Default false (negative).
  14092. * @return Optimized position.
  14093. */
  14094. var subPixelOptimize$1 = subPixelOptimize;
  14095. /**
  14096. * Get transform matrix of target (param target),
  14097. * in coordinate of its ancestor (param ancestor)
  14098. *
  14099. * @param target
  14100. * @param [ancestor]
  14101. */
  14102. function getTransform(target, ancestor) {
  14103. var mat = identity([]);
  14104. while (target && target !== ancestor) {
  14105. mul$1(mat, target.getLocalTransform(), mat);
  14106. target = target.parent;
  14107. }
  14108. return mat;
  14109. }
  14110. /**
  14111. * Apply transform to an vertex.
  14112. * @param target [x, y]
  14113. * @param transform Can be:
  14114. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  14115. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  14116. * @param invert Whether use invert matrix.
  14117. * @return [x, y]
  14118. */
  14119. function applyTransform$1(target, transform, invert$1) {
  14120. if (transform && !isArrayLike(transform)) {
  14121. transform = Transformable.getLocalTransform(transform);
  14122. }
  14123. if (invert$1) {
  14124. transform = invert([], transform);
  14125. }
  14126. return applyTransform([], target, transform);
  14127. }
  14128. /**
  14129. * @param direction 'left' 'right' 'top' 'bottom'
  14130. * @param transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  14131. * @param invert Whether use invert matrix.
  14132. * @return Transformed direction. 'left' 'right' 'top' 'bottom'
  14133. */
  14134. function transformDirection(direction, transform, invert) {
  14135. // Pick a base, ensure that transform result will not be (0, 0).
  14136. var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : Math.abs(2 * transform[4] / transform[0]);
  14137. var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : Math.abs(2 * transform[4] / transform[2]);
  14138. var vertex = [direction === 'left' ? -hBase : direction === 'right' ? hBase : 0, direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0];
  14139. vertex = applyTransform$1(vertex, transform, invert);
  14140. return Math.abs(vertex[0]) > Math.abs(vertex[1]) ? vertex[0] > 0 ? 'right' : 'left' : vertex[1] > 0 ? 'bottom' : 'top';
  14141. }
  14142. function isNotGroup(el) {
  14143. return !el.isGroup;
  14144. }
  14145. function isPath(el) {
  14146. return el.shape != null;
  14147. }
  14148. /**
  14149. * Apply group transition animation from g1 to g2.
  14150. * If no animatableModel, no animation.
  14151. */
  14152. function groupTransition(g1, g2, animatableModel) {
  14153. if (!g1 || !g2) {
  14154. return;
  14155. }
  14156. function getElMap(g) {
  14157. var elMap = {};
  14158. g.traverse(function (el) {
  14159. if (isNotGroup(el) && el.anid) {
  14160. elMap[el.anid] = el;
  14161. }
  14162. });
  14163. return elMap;
  14164. }
  14165. function getAnimatableProps(el) {
  14166. var obj = {
  14167. x: el.x,
  14168. y: el.y,
  14169. rotation: el.rotation
  14170. };
  14171. if (isPath(el)) {
  14172. obj.shape = extend({}, el.shape);
  14173. }
  14174. return obj;
  14175. }
  14176. var elMap1 = getElMap(g1);
  14177. g2.traverse(function (el) {
  14178. if (isNotGroup(el) && el.anid) {
  14179. var oldEl = elMap1[el.anid];
  14180. if (oldEl) {
  14181. var newProp = getAnimatableProps(el);
  14182. el.attr(getAnimatableProps(oldEl));
  14183. updateProps(el, newProp, animatableModel, getECData(el).dataIndex);
  14184. }
  14185. }
  14186. });
  14187. }
  14188. function clipPointsByRect(points, rect) {
  14189. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  14190. // and when element have border.
  14191. return map(points, function (point) {
  14192. var x = point[0];
  14193. x = mathMax$4(x, rect.x);
  14194. x = mathMin$4(x, rect.x + rect.width);
  14195. var y = point[1];
  14196. y = mathMax$4(y, rect.y);
  14197. y = mathMin$4(y, rect.y + rect.height);
  14198. return [x, y];
  14199. });
  14200. }
  14201. /**
  14202. * Return a new clipped rect. If rect size are negative, return undefined.
  14203. */
  14204. function clipRectByRect(targetRect, rect) {
  14205. var x = mathMax$4(targetRect.x, rect.x);
  14206. var x2 = mathMin$4(targetRect.x + targetRect.width, rect.x + rect.width);
  14207. var y = mathMax$4(targetRect.y, rect.y);
  14208. var y2 = mathMin$4(targetRect.y + targetRect.height, rect.y + rect.height); // If the total rect is cliped, nothing, including the border,
  14209. // should be painted. So return undefined.
  14210. if (x2 >= x && y2 >= y) {
  14211. return {
  14212. x: x,
  14213. y: y,
  14214. width: x2 - x,
  14215. height: y2 - y
  14216. };
  14217. }
  14218. }
  14219. function createIcon(iconStr, // Support 'image://' or 'path://' or direct svg path.
  14220. opt, rect) {
  14221. var innerOpts = extend({
  14222. rectHover: true
  14223. }, opt);
  14224. var style = innerOpts.style = {
  14225. strokeNoScale: true
  14226. };
  14227. rect = rect || {
  14228. x: -1,
  14229. y: -1,
  14230. width: 2,
  14231. height: 2
  14232. };
  14233. if (iconStr) {
  14234. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), defaults(style, rect), new ZRImage(innerOpts)) : makePath(iconStr.replace('path://', ''), innerOpts, rect, 'center');
  14235. }
  14236. }
  14237. /**
  14238. * Return `true` if the given line (line `a`) and the given polygon
  14239. * are intersect.
  14240. * Note that we do not count colinear as intersect here because no
  14241. * requirement for that. We could do that if required in future.
  14242. */
  14243. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  14244. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  14245. var p = points[i];
  14246. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  14247. return true;
  14248. }
  14249. p2 = p;
  14250. }
  14251. }
  14252. /**
  14253. * Return `true` if the given two lines (line `a` and line `b`)
  14254. * are intersect.
  14255. * Note that we do not count colinear as intersect here because no
  14256. * requirement for that. We could do that if required in future.
  14257. */
  14258. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  14259. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  14260. var mx = a2x - a1x;
  14261. var my = a2y - a1y;
  14262. var nx = b2x - b1x;
  14263. var ny = b2y - b1y; // `vec_m` and `vec_n` are parallel iff
  14264. // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  14265. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  14266. if (nearZero(nmCrossProduct)) {
  14267. return false;
  14268. } // `vec_m` and `vec_n` are intersect iff
  14269. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  14270. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  14271. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  14272. var b1a1x = a1x - b1x;
  14273. var b1a1y = a1y - b1y;
  14274. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  14275. if (q < 0 || q > 1) {
  14276. return false;
  14277. }
  14278. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  14279. if (p < 0 || p > 1) {
  14280. return false;
  14281. }
  14282. return true;
  14283. }
  14284. /**
  14285. * Cross product of 2-dimension vector.
  14286. */
  14287. function crossProduct2d(x1, y1, x2, y2) {
  14288. return x1 * y2 - x2 * y1;
  14289. }
  14290. function nearZero(val) {
  14291. return val <= 1e-6 && val >= -1e-6;
  14292. }
  14293. function setTooltipConfig(opt) {
  14294. var itemTooltipOption = opt.itemTooltipOption;
  14295. var componentModel = opt.componentModel;
  14296. var itemName = opt.itemName;
  14297. var itemTooltipOptionObj = isString(itemTooltipOption) ? {
  14298. formatter: itemTooltipOption
  14299. } : itemTooltipOption;
  14300. var mainType = componentModel.mainType;
  14301. var componentIndex = componentModel.componentIndex;
  14302. var formatterParams = {
  14303. componentType: mainType,
  14304. name: itemName,
  14305. $vars: ['name']
  14306. };
  14307. formatterParams[mainType + 'Index'] = componentIndex;
  14308. var formatterParamsExtra = opt.formatterParamsExtra;
  14309. if (formatterParamsExtra) {
  14310. each(keys(formatterParamsExtra), function (key) {
  14311. if (!hasOwn(formatterParams, key)) {
  14312. formatterParams[key] = formatterParamsExtra[key];
  14313. formatterParams.$vars.push(key);
  14314. }
  14315. });
  14316. }
  14317. var ecData = getECData(opt.el);
  14318. ecData.componentMainType = mainType;
  14319. ecData.componentIndex = componentIndex;
  14320. ecData.tooltipConfig = {
  14321. name: itemName,
  14322. option: defaults({
  14323. content: itemName,
  14324. formatterParams: formatterParams
  14325. }, itemTooltipOptionObj)
  14326. };
  14327. } // Register built-in shapes. These shapes might be overwirtten
  14328. // by users, although we do not recommend that.
  14329. registerShape('circle', Circle);
  14330. registerShape('ellipse', Ellipse);
  14331. registerShape('sector', Sector);
  14332. registerShape('ring', Ring);
  14333. registerShape('polygon', Polygon);
  14334. registerShape('polyline', Polyline);
  14335. registerShape('rect', Rect);
  14336. registerShape('line', Line);
  14337. registerShape('bezierCurve', BezierCurve);
  14338. registerShape('arc', Arc);
  14339. var graphic = /*#__PURE__*/Object.freeze({
  14340. __proto__: null,
  14341. updateProps: updateProps,
  14342. initProps: initProps,
  14343. removeElement: removeElement,
  14344. removeElementWithFadeOut: removeElementWithFadeOut,
  14345. isElementRemoved: isElementRemoved,
  14346. extendShape: extendShape,
  14347. extendPath: extendPath,
  14348. registerShape: registerShape,
  14349. getShapeClass: getShapeClass,
  14350. makePath: makePath,
  14351. makeImage: makeImage,
  14352. mergePath: mergePath$1,
  14353. resizePath: resizePath,
  14354. subPixelOptimizeLine: subPixelOptimizeLine$1,
  14355. subPixelOptimizeRect: subPixelOptimizeRect$1,
  14356. subPixelOptimize: subPixelOptimize$1,
  14357. getTransform: getTransform,
  14358. applyTransform: applyTransform$1,
  14359. transformDirection: transformDirection,
  14360. groupTransition: groupTransition,
  14361. clipPointsByRect: clipPointsByRect,
  14362. clipRectByRect: clipRectByRect,
  14363. createIcon: createIcon,
  14364. linePolygonIntersect: linePolygonIntersect,
  14365. lineLineIntersect: lineLineIntersect,
  14366. setTooltipConfig: setTooltipConfig,
  14367. Group: Group,
  14368. Image: ZRImage,
  14369. Text: ZRText,
  14370. Circle: Circle,
  14371. Ellipse: Ellipse,
  14372. Sector: Sector,
  14373. Ring: Ring,
  14374. Polygon: Polygon,
  14375. Polyline: Polyline,
  14376. Rect: Rect,
  14377. Line: Line,
  14378. BezierCurve: BezierCurve,
  14379. Arc: Arc,
  14380. IncrementalDisplayable: IncrementalDisplayable,
  14381. CompoundPath: CompoundPath,
  14382. LinearGradient: LinearGradient,
  14383. RadialGradient: RadialGradient,
  14384. BoundingRect: BoundingRect,
  14385. OrientedBoundingRect: OrientedBoundingRect,
  14386. Point: Point,
  14387. Path: Path
  14388. });
  14389. var EMPTY_OBJ = {};
  14390. function setLabelText(label, labelTexts) {
  14391. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  14392. var stateName = SPECIAL_STATES[i];
  14393. var text = labelTexts[stateName];
  14394. var state = label.ensureState(stateName);
  14395. state.style = state.style || {};
  14396. state.style.text = text;
  14397. }
  14398. var oldStates = label.currentStates.slice();
  14399. label.clearStates(true);
  14400. label.setStyle({
  14401. text: labelTexts.normal
  14402. });
  14403. label.useStates(oldStates, true);
  14404. }
  14405. function getLabelText(opt, stateModels, interpolatedValue) {
  14406. var labelFetcher = opt.labelFetcher;
  14407. var labelDataIndex = opt.labelDataIndex;
  14408. var labelDimIndex = opt.labelDimIndex;
  14409. var normalModel = stateModels.normal;
  14410. var baseText;
  14411. if (labelFetcher) {
  14412. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, normalModel && normalModel.get('formatter'), interpolatedValue != null ? {
  14413. interpolatedValue: interpolatedValue
  14414. } : null);
  14415. }
  14416. if (baseText == null) {
  14417. baseText = isFunction(opt.defaultText) ? opt.defaultText(labelDataIndex, opt, interpolatedValue) : opt.defaultText;
  14418. }
  14419. var statesText = {
  14420. normal: baseText
  14421. };
  14422. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  14423. var stateName = SPECIAL_STATES[i];
  14424. var stateModel = stateModels[stateName];
  14425. statesText[stateName] = retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, stateName, null, labelDimIndex, stateModel && stateModel.get('formatter')) : null, baseText);
  14426. }
  14427. return statesText;
  14428. }
  14429. function setLabelStyle(targetEl, labelStatesModels, opt, stateSpecified // TODO specified position?
  14430. ) {
  14431. opt = opt || EMPTY_OBJ;
  14432. var isSetOnText = targetEl instanceof ZRText;
  14433. var needsCreateText = false;
  14434. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  14435. var stateModel = labelStatesModels[DISPLAY_STATES[i]];
  14436. if (stateModel && stateModel.getShallow('show')) {
  14437. needsCreateText = true;
  14438. break;
  14439. }
  14440. }
  14441. var textContent = isSetOnText ? targetEl : targetEl.getTextContent();
  14442. if (needsCreateText) {
  14443. if (!isSetOnText) {
  14444. // Reuse the previous
  14445. if (!textContent) {
  14446. textContent = new ZRText();
  14447. targetEl.setTextContent(textContent);
  14448. } // Use same state proxy
  14449. if (targetEl.stateProxy) {
  14450. textContent.stateProxy = targetEl.stateProxy;
  14451. }
  14452. }
  14453. var labelStatesTexts = getLabelText(opt, labelStatesModels);
  14454. var normalModel = labelStatesModels.normal;
  14455. var showNormal = !!normalModel.getShallow('show');
  14456. var normalStyle = createTextStyle(normalModel, stateSpecified && stateSpecified.normal, opt, false, !isSetOnText);
  14457. normalStyle.text = labelStatesTexts.normal;
  14458. if (!isSetOnText) {
  14459. // Always create new
  14460. targetEl.setTextConfig(createTextConfig(normalModel, opt, false));
  14461. }
  14462. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  14463. var stateName = SPECIAL_STATES[i];
  14464. var stateModel = labelStatesModels[stateName];
  14465. if (stateModel) {
  14466. var stateObj = textContent.ensureState(stateName);
  14467. var stateShow = !!retrieve2(stateModel.getShallow('show'), showNormal);
  14468. if (stateShow !== showNormal) {
  14469. stateObj.ignore = !stateShow;
  14470. }
  14471. stateObj.style = createTextStyle(stateModel, stateSpecified && stateSpecified[stateName], opt, true, !isSetOnText);
  14472. stateObj.style.text = labelStatesTexts[stateName];
  14473. if (!isSetOnText) {
  14474. var targetElEmphasisState = targetEl.ensureState(stateName);
  14475. targetElEmphasisState.textConfig = createTextConfig(stateModel, opt, true);
  14476. }
  14477. }
  14478. } // PENDING: if there is many requirements that emphasis position
  14479. // need to be different from normal position, we might consider
  14480. // auto slient is those cases.
  14481. textContent.silent = !!normalModel.getShallow('silent'); // Keep x and y
  14482. if (textContent.style.x != null) {
  14483. normalStyle.x = textContent.style.x;
  14484. }
  14485. if (textContent.style.y != null) {
  14486. normalStyle.y = textContent.style.y;
  14487. }
  14488. textContent.ignore = !showNormal; // Always create new style.
  14489. textContent.useStyle(normalStyle);
  14490. textContent.dirty();
  14491. if (opt.enableTextSetter) {
  14492. labelInner(textContent).setLabelText = function (interpolatedValue) {
  14493. var labelStatesTexts = getLabelText(opt, labelStatesModels, interpolatedValue);
  14494. setLabelText(textContent, labelStatesTexts);
  14495. };
  14496. }
  14497. } else if (textContent) {
  14498. // Not display rich text.
  14499. textContent.ignore = true;
  14500. }
  14501. targetEl.dirty();
  14502. }
  14503. function getLabelStatesModels(itemModel, labelName) {
  14504. labelName = labelName || 'label';
  14505. var statesModels = {
  14506. normal: itemModel.getModel(labelName)
  14507. };
  14508. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  14509. var stateName = SPECIAL_STATES[i];
  14510. statesModels[stateName] = itemModel.getModel([stateName, labelName]);
  14511. }
  14512. return statesModels;
  14513. }
  14514. /**
  14515. * Set basic textStyle properties.
  14516. */
  14517. function createTextStyle(textStyleModel, specifiedTextStyle, // Fixed style in the code. Can't be set by model.
  14518. opt, isNotNormal, isAttached // If text is attached on an element. If so, auto color will handling in zrender.
  14519. ) {
  14520. var textStyle = {};
  14521. setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached);
  14522. specifiedTextStyle && extend(textStyle, specifiedTextStyle); // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14523. return textStyle;
  14524. }
  14525. function createTextConfig(textStyleModel, opt, isNotNormal) {
  14526. opt = opt || {};
  14527. var textConfig = {};
  14528. var labelPosition;
  14529. var labelRotate = textStyleModel.getShallow('rotate');
  14530. var labelDistance = retrieve2(textStyleModel.getShallow('distance'), isNotNormal ? null : 5);
  14531. var labelOffset = textStyleModel.getShallow('offset');
  14532. labelPosition = textStyleModel.getShallow('position') || (isNotNormal ? null : 'inside'); // 'outside' is not a valid zr textPostion value, but used
  14533. // in bar series, and magric type should be considered.
  14534. labelPosition === 'outside' && (labelPosition = opt.defaultOutsidePosition || 'top');
  14535. if (labelPosition != null) {
  14536. textConfig.position = labelPosition;
  14537. }
  14538. if (labelOffset != null) {
  14539. textConfig.offset = labelOffset;
  14540. }
  14541. if (labelRotate != null) {
  14542. labelRotate *= Math.PI / 180;
  14543. textConfig.rotation = labelRotate;
  14544. }
  14545. if (labelDistance != null) {
  14546. textConfig.distance = labelDistance;
  14547. } // fill and auto is determined by the color of path fill if it's not specified by developers.
  14548. textConfig.outsideFill = textStyleModel.get('color') === 'inherit' ? opt.inheritColor || null : 'auto';
  14549. return textConfig;
  14550. }
  14551. /**
  14552. * The uniform entry of set text style, that is, retrieve style definitions
  14553. * from `model` and set to `textStyle` object.
  14554. *
  14555. * Never in merge mode, but in overwrite mode, that is, all of the text style
  14556. * properties will be set. (Consider the states of normal and emphasis and
  14557. * default value can be adopted, merge would make the logic too complicated
  14558. * to manage.)
  14559. */
  14560. function setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached) {
  14561. // Consider there will be abnormal when merge hover style to normal style if given default value.
  14562. opt = opt || EMPTY_OBJ;
  14563. var ecModel = textStyleModel.ecModel;
  14564. var globalTextStyle = ecModel && ecModel.option.textStyle; // Consider case:
  14565. // {
  14566. // data: [{
  14567. // value: 12,
  14568. // label: {
  14569. // rich: {
  14570. // // no 'a' here but using parent 'a'.
  14571. // }
  14572. // }
  14573. // }],
  14574. // rich: {
  14575. // a: { ... }
  14576. // }
  14577. // }
  14578. var richItemNames = getRichItemNames(textStyleModel);
  14579. var richResult;
  14580. if (richItemNames) {
  14581. richResult = {};
  14582. for (var name_1 in richItemNames) {
  14583. if (richItemNames.hasOwnProperty(name_1)) {
  14584. // Cascade is supported in rich.
  14585. var richTextStyle = textStyleModel.getModel(['rich', name_1]); // In rich, never `disableBox`.
  14586. // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  14587. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  14588. // That might confuses users. So probably we should put `textStyleModel` as the
  14589. // root ancestor of the `richTextStyle`. But that would be a break change.
  14590. setTokenTextStyle(richResult[name_1] = {}, richTextStyle, globalTextStyle, opt, isNotNormal, isAttached, false, true);
  14591. }
  14592. }
  14593. }
  14594. if (richResult) {
  14595. textStyle.rich = richResult;
  14596. }
  14597. var overflow = textStyleModel.get('overflow');
  14598. if (overflow) {
  14599. textStyle.overflow = overflow;
  14600. }
  14601. var margin = textStyleModel.get('minMargin');
  14602. if (margin != null) {
  14603. textStyle.margin = margin;
  14604. }
  14605. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isNotNormal, isAttached, true, false);
  14606. } // Consider case:
  14607. // {
  14608. // data: [{
  14609. // value: 12,
  14610. // label: {
  14611. // rich: {
  14612. // // no 'a' here but using parent 'a'.
  14613. // }
  14614. // }
  14615. // }],
  14616. // rich: {
  14617. // a: { ... }
  14618. // }
  14619. // }
  14620. // TODO TextStyleModel
  14621. function getRichItemNames(textStyleModel) {
  14622. // Use object to remove duplicated names.
  14623. var richItemNameMap;
  14624. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  14625. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  14626. if (rich) {
  14627. richItemNameMap = richItemNameMap || {};
  14628. var richKeys = keys(rich);
  14629. for (var i = 0; i < richKeys.length; i++) {
  14630. var richKey = richKeys[i];
  14631. richItemNameMap[richKey] = 1;
  14632. }
  14633. }
  14634. textStyleModel = textStyleModel.parentModel;
  14635. }
  14636. return richItemNameMap;
  14637. }
  14638. var TEXT_PROPS_WITH_GLOBAL = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'];
  14639. var TEXT_PROPS_SELF = ['align', 'lineHeight', 'width', 'height', 'tag', 'verticalAlign'];
  14640. var TEXT_PROPS_BOX = ['padding', 'borderWidth', 'borderRadius', 'borderDashOffset', 'backgroundColor', 'borderColor', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14641. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isNotNormal, isAttached, isBlock, inRich) {
  14642. // In merge mode, default value should not be given.
  14643. globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
  14644. var inheritColor = opt && opt.inheritColor;
  14645. var fillColor = textStyleModel.getShallow('color');
  14646. var strokeColor = textStyleModel.getShallow('textBorderColor');
  14647. var opacity = retrieve2(textStyleModel.getShallow('opacity'), globalTextStyle.opacity);
  14648. if (fillColor === 'inherit' || fillColor === 'auto') {
  14649. if ("development" !== 'production') {
  14650. if (fillColor === 'auto') {
  14651. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  14652. }
  14653. }
  14654. if (inheritColor) {
  14655. fillColor = inheritColor;
  14656. } else {
  14657. fillColor = null;
  14658. }
  14659. }
  14660. if (strokeColor === 'inherit' || strokeColor === 'auto') {
  14661. if ("development" !== 'production') {
  14662. if (strokeColor === 'auto') {
  14663. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  14664. }
  14665. }
  14666. if (inheritColor) {
  14667. strokeColor = inheritColor;
  14668. } else {
  14669. strokeColor = null;
  14670. }
  14671. }
  14672. if (!isAttached) {
  14673. // Only use default global textStyle.color if text is individual.
  14674. // Otherwise it will use the strategy of attached text color because text may be on a path.
  14675. fillColor = fillColor || globalTextStyle.color;
  14676. strokeColor = strokeColor || globalTextStyle.textBorderColor;
  14677. }
  14678. if (fillColor != null) {
  14679. textStyle.fill = fillColor;
  14680. }
  14681. if (strokeColor != null) {
  14682. textStyle.stroke = strokeColor;
  14683. }
  14684. var textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  14685. if (textBorderWidth != null) {
  14686. textStyle.lineWidth = textBorderWidth;
  14687. }
  14688. var textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
  14689. if (textBorderType != null) {
  14690. textStyle.lineDash = textBorderType;
  14691. }
  14692. var textBorderDashOffset = retrieve2(textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset);
  14693. if (textBorderDashOffset != null) {
  14694. textStyle.lineDashOffset = textBorderDashOffset;
  14695. }
  14696. if (!isNotNormal && opacity == null && !inRich) {
  14697. opacity = opt && opt.defaultOpacity;
  14698. }
  14699. if (opacity != null) {
  14700. textStyle.opacity = opacity;
  14701. } // TODO
  14702. if (!isNotNormal && !isAttached) {
  14703. // Set default finally.
  14704. if (textStyle.fill == null && opt.inheritColor) {
  14705. textStyle.fill = opt.inheritColor;
  14706. }
  14707. } // Do not use `getFont` here, because merge should be supported, where
  14708. // part of these properties may be changed in emphasis style, and the
  14709. // others should remain their original value got from normal style.
  14710. for (var i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
  14711. var key = TEXT_PROPS_WITH_GLOBAL[i];
  14712. var val = retrieve2(textStyleModel.getShallow(key), globalTextStyle[key]);
  14713. if (val != null) {
  14714. textStyle[key] = val;
  14715. }
  14716. }
  14717. for (var i = 0; i < TEXT_PROPS_SELF.length; i++) {
  14718. var key = TEXT_PROPS_SELF[i];
  14719. var val = textStyleModel.getShallow(key);
  14720. if (val != null) {
  14721. textStyle[key] = val;
  14722. }
  14723. }
  14724. if (textStyle.verticalAlign == null) {
  14725. var baseline = textStyleModel.getShallow('baseline');
  14726. if (baseline != null) {
  14727. textStyle.verticalAlign = baseline;
  14728. }
  14729. }
  14730. if (!isBlock || !opt.disableBox) {
  14731. for (var i = 0; i < TEXT_PROPS_BOX.length; i++) {
  14732. var key = TEXT_PROPS_BOX[i];
  14733. var val = textStyleModel.getShallow(key);
  14734. if (val != null) {
  14735. textStyle[key] = val;
  14736. }
  14737. }
  14738. var borderType = textStyleModel.getShallow('borderType');
  14739. if (borderType != null) {
  14740. textStyle.borderDash = borderType;
  14741. }
  14742. if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
  14743. if ("development" !== 'production') {
  14744. if (textStyle.backgroundColor === 'auto') {
  14745. deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\'');
  14746. }
  14747. }
  14748. textStyle.backgroundColor = inheritColor;
  14749. }
  14750. if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) {
  14751. if ("development" !== 'production') {
  14752. if (textStyle.borderColor === 'auto') {
  14753. deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\'');
  14754. }
  14755. }
  14756. textStyle.borderColor = inheritColor;
  14757. }
  14758. }
  14759. }
  14760. function getFont(opt, ecModel) {
  14761. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  14762. return trim([// FIXME in node-canvas fontWeight is before fontStyle
  14763. 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(' '));
  14764. }
  14765. var labelInner = makeInner();
  14766. function setLabelValueAnimation(label, labelStatesModels, value, getDefaultText) {
  14767. if (!label) {
  14768. return;
  14769. }
  14770. var obj = labelInner(label);
  14771. obj.prevValue = obj.value;
  14772. obj.value = value;
  14773. var normalLabelModel = labelStatesModels.normal;
  14774. obj.valueAnimation = normalLabelModel.get('valueAnimation');
  14775. if (obj.valueAnimation) {
  14776. obj.precision = normalLabelModel.get('precision');
  14777. obj.defaultInterpolatedText = getDefaultText;
  14778. obj.statesModels = labelStatesModels;
  14779. }
  14780. }
  14781. var PATH_COLOR = ['textStyle', 'color']; // TODO Performance improvement?
  14782. var tmpRichText = new ZRText();
  14783. var TextStyleMixin =
  14784. /** @class */
  14785. function () {
  14786. function TextStyleMixin() {}
  14787. /**
  14788. * Get color property or get color from option.textStyle.color
  14789. */
  14790. // TODO Callback
  14791. TextStyleMixin.prototype.getTextColor = function (isEmphasis) {
  14792. var ecModel = this.ecModel;
  14793. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  14794. };
  14795. /**
  14796. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  14797. * @return {string}
  14798. */
  14799. TextStyleMixin.prototype.getFont = function () {
  14800. return getFont({
  14801. fontStyle: this.getShallow('fontStyle'),
  14802. fontWeight: this.getShallow('fontWeight'),
  14803. fontSize: this.getShallow('fontSize'),
  14804. fontFamily: this.getShallow('fontFamily')
  14805. }, this.ecModel);
  14806. };
  14807. TextStyleMixin.prototype.getTextRect = function (text) {
  14808. tmpRichText.useStyle({
  14809. text: text,
  14810. fontStyle: this.getShallow('fontStyle'),
  14811. fontWeight: this.getShallow('fontWeight'),
  14812. fontSize: this.getShallow('fontSize'),
  14813. fontFamily: this.getShallow('fontFamily'),
  14814. verticalAlign: this.getShallow('verticalAlign') || this.getShallow('baseline'),
  14815. padding: this.getShallow('padding'),
  14816. lineHeight: this.getShallow('lineHeight'),
  14817. rich: this.getShallow('rich')
  14818. });
  14819. tmpRichText.update();
  14820. return tmpRichText.getBoundingRect();
  14821. };
  14822. return TextStyleMixin;
  14823. }();
  14824. var LINE_STYLE_KEY_MAP = [['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['lineDash', 'type'], ['lineDashOffset', 'dashOffset'], ['lineCap', 'cap'], ['lineJoin', 'join'], ['miterLimit'] // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  14825. // So do not transfer decal directly.
  14826. ];
  14827. var getLineStyle = makeStyleMapper(LINE_STYLE_KEY_MAP);
  14828. var LineStyleMixin =
  14829. /** @class */
  14830. function () {
  14831. function LineStyleMixin() {}
  14832. LineStyleMixin.prototype.getLineStyle = function (excludes) {
  14833. return getLineStyle(this, excludes);
  14834. };
  14835. return LineStyleMixin;
  14836. }();
  14837. 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'] // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  14838. // So do not transfer decal directly.
  14839. ];
  14840. var getItemStyle = makeStyleMapper(ITEM_STYLE_KEY_MAP);
  14841. var ItemStyleMixin =
  14842. /** @class */
  14843. function () {
  14844. function ItemStyleMixin() {}
  14845. ItemStyleMixin.prototype.getItemStyle = function (excludes, includes) {
  14846. return getItemStyle(this, excludes, includes);
  14847. };
  14848. return ItemStyleMixin;
  14849. }();
  14850. var Model =
  14851. /** @class */
  14852. function () {
  14853. function Model(option, parentModel, ecModel) {
  14854. this.parentModel = parentModel;
  14855. this.ecModel = ecModel;
  14856. this.option = option; // Simple optimization
  14857. // if (this.init) {
  14858. // if (arguments.length <= 4) {
  14859. // this.init(option, parentModel, ecModel, extraOpt);
  14860. // }
  14861. // else {
  14862. // this.init.apply(this, arguments);
  14863. // }
  14864. // }
  14865. }
  14866. Model.prototype.init = function (option, parentModel, ecModel) {
  14867. var rest = [];
  14868. for (var _i = 3; _i < arguments.length; _i++) {
  14869. rest[_i - 3] = arguments[_i];
  14870. }
  14871. };
  14872. /**
  14873. * Merge the input option to me.
  14874. */
  14875. Model.prototype.mergeOption = function (option, ecModel) {
  14876. merge(this.option, option, true);
  14877. }; // `path` can be 'xxx.yyy.zzz', so the return value type have to be `ModelOption`
  14878. // TODO: TYPE strict key check?
  14879. // get(path: string | string[], ignoreParent?: boolean): ModelOption;
  14880. Model.prototype.get = function (path, ignoreParent) {
  14881. if (path == null) {
  14882. return this.option;
  14883. }
  14884. return this._doGet(this.parsePath(path), !ignoreParent && this.parentModel);
  14885. };
  14886. Model.prototype.getShallow = function (key, ignoreParent) {
  14887. var option = this.option;
  14888. var val = option == null ? option : option[key];
  14889. if (val == null && !ignoreParent) {
  14890. var parentModel = this.parentModel;
  14891. if (parentModel) {
  14892. // FIXME:TS do not know how to make it works
  14893. val = parentModel.getShallow(key);
  14894. }
  14895. }
  14896. return val;
  14897. }; // `path` can be 'xxx.yyy.zzz', so the return value type have to be `Model<ModelOption>`
  14898. // getModel(path: string | string[], parentModel?: Model): Model;
  14899. // TODO 'xxx.yyy.zzz' is deprecated
  14900. Model.prototype.getModel = function (path, parentModel) {
  14901. var hasPath = path != null;
  14902. var pathFinal = hasPath ? this.parsePath(path) : null;
  14903. var obj = hasPath ? this._doGet(pathFinal) : this.option;
  14904. parentModel = parentModel || this.parentModel && this.parentModel.getModel(this.resolveParentPath(pathFinal));
  14905. return new Model(obj, parentModel, this.ecModel);
  14906. };
  14907. /**
  14908. * Squash option stack into one.
  14909. * parentModel will be removed after squashed.
  14910. *
  14911. * NOTE: resolveParentPath will not be applied here for simplicity. DON'T use this function
  14912. * if resolveParentPath is modified.
  14913. *
  14914. * @param deepMerge If do deep merge. Default to be false.
  14915. */
  14916. // squash(
  14917. // deepMerge?: boolean,
  14918. // handleCallback?: (func: () => object) => object
  14919. // ) {
  14920. // const optionStack = [];
  14921. // let model: Model = this;
  14922. // while (model) {
  14923. // if (model.option) {
  14924. // optionStack.push(model.option);
  14925. // }
  14926. // model = model.parentModel;
  14927. // }
  14928. // const newOption = {} as Opt;
  14929. // let option;
  14930. // while (option = optionStack.pop()) { // Top down merge
  14931. // if (isFunction(option) && handleCallback) {
  14932. // option = handleCallback(option);
  14933. // }
  14934. // if (deepMerge) {
  14935. // merge(newOption, option);
  14936. // }
  14937. // else {
  14938. // extend(newOption, option);
  14939. // }
  14940. // }
  14941. // // Remove parentModel
  14942. // this.option = newOption;
  14943. // this.parentModel = null;
  14944. // }
  14945. /**
  14946. * If model has option
  14947. */
  14948. Model.prototype.isEmpty = function () {
  14949. return this.option == null;
  14950. };
  14951. Model.prototype.restoreData = function () {}; // Pending
  14952. Model.prototype.clone = function () {
  14953. var Ctor = this.constructor;
  14954. return new Ctor(clone(this.option));
  14955. }; // setReadOnly(properties): void {
  14956. // clazzUtil.setReadOnly(this, properties);
  14957. // }
  14958. // If path is null/undefined, return null/undefined.
  14959. Model.prototype.parsePath = function (path) {
  14960. if (typeof path === 'string') {
  14961. return path.split('.');
  14962. }
  14963. return path;
  14964. }; // Resolve path for parent. Perhaps useful when parent use a different property.
  14965. // Default to be a identity resolver.
  14966. // Can be modified to a different resolver.
  14967. Model.prototype.resolveParentPath = function (path) {
  14968. return path;
  14969. }; // FIXME:TS check whether put this method here
  14970. Model.prototype.isAnimationEnabled = function () {
  14971. if (!env.node && this.option) {
  14972. if (this.option.animation != null) {
  14973. return !!this.option.animation;
  14974. } else if (this.parentModel) {
  14975. return this.parentModel.isAnimationEnabled();
  14976. }
  14977. }
  14978. };
  14979. Model.prototype._doGet = function (pathArr, parentModel) {
  14980. var obj = this.option;
  14981. if (!pathArr) {
  14982. return obj;
  14983. }
  14984. for (var i = 0; i < pathArr.length; i++) {
  14985. // Ignore empty
  14986. if (!pathArr[i]) {
  14987. continue;
  14988. } // obj could be number/string/... (like 0)
  14989. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  14990. if (obj == null) {
  14991. break;
  14992. }
  14993. }
  14994. if (obj == null && parentModel) {
  14995. obj = parentModel._doGet(this.resolveParentPath(pathArr), parentModel.parentModel);
  14996. }
  14997. return obj;
  14998. };
  14999. return Model;
  15000. }();
  15001. enableClassExtend(Model);
  15002. enableClassCheck(Model);
  15003. mixin(Model, LineStyleMixin);
  15004. mixin(Model, ItemStyleMixin);
  15005. mixin(Model, AreaStyleMixin);
  15006. mixin(Model, TextStyleMixin);
  15007. var base = Math.round(Math.random() * 10);
  15008. /**
  15009. * @public
  15010. * @param {string} type
  15011. * @return {string}
  15012. */
  15013. function getUID(type) {
  15014. // Considering the case of crossing js context,
  15015. // use Math.random to make id as unique as possible.
  15016. return [type || '', base++].join('_');
  15017. }
  15018. /**
  15019. * Implements `SubTypeDefaulterManager` for `target`.
  15020. */
  15021. function enableSubTypeDefaulter(target) {
  15022. var subTypeDefaulters = {};
  15023. target.registerSubTypeDefaulter = function (componentType, defaulter) {
  15024. var componentTypeInfo = parseClassType(componentType);
  15025. subTypeDefaulters[componentTypeInfo.main] = defaulter;
  15026. };
  15027. target.determineSubType = function (componentType, option) {
  15028. var type = option.type;
  15029. if (!type) {
  15030. var componentTypeMain = parseClassType(componentType).main;
  15031. if (target.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15032. type = subTypeDefaulters[componentTypeMain](option);
  15033. }
  15034. }
  15035. return type;
  15036. };
  15037. }
  15038. /**
  15039. * Implements `TopologicalTravelable<any>` for `entity`.
  15040. *
  15041. * Topological travel on Activity Network (Activity On Vertices).
  15042. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15043. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15044. * If there is circular dependencey, Error will be thrown.
  15045. */
  15046. function enableTopologicalTravel(entity, dependencyGetter) {
  15047. /**
  15048. * @param targetNameList Target Component type list.
  15049. * Can be ['aa', 'bb', 'aa.xx']
  15050. * @param fullNameList By which we can build dependency graph.
  15051. * @param callback Params: componentType, dependencies.
  15052. * @param context Scope of callback.
  15053. */
  15054. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15055. if (!targetNameList.length) {
  15056. return;
  15057. }
  15058. var result = makeDepndencyGraph(fullNameList);
  15059. var graph = result.graph;
  15060. var noEntryList = result.noEntryList;
  15061. var targetNameSet = {};
  15062. each(targetNameList, function (name) {
  15063. targetNameSet[name] = true;
  15064. });
  15065. while (noEntryList.length) {
  15066. var currComponentType = noEntryList.pop();
  15067. var currVertex = graph[currComponentType];
  15068. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15069. if (isInTargetNameSet) {
  15070. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15071. delete targetNameSet[currComponentType];
  15072. }
  15073. each(currVertex.successor, isInTargetNameSet ? removeEdgeAndAdd : removeEdge);
  15074. }
  15075. each(targetNameSet, function () {
  15076. var errMsg = '';
  15077. if ("development" !== 'production') {
  15078. errMsg = makePrintable('Circular dependency may exists: ', targetNameSet, targetNameList, fullNameList);
  15079. }
  15080. throw new Error(errMsg);
  15081. });
  15082. function removeEdge(succComponentType) {
  15083. graph[succComponentType].entryCount--;
  15084. if (graph[succComponentType].entryCount === 0) {
  15085. noEntryList.push(succComponentType);
  15086. }
  15087. } // Consider this case: legend depends on series, and we call
  15088. // chart.setOption({series: [...]}), where only series is in option.
  15089. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15090. // not be called, but only sereis.mergeOption is called. Thus legend
  15091. // have no chance to update its local record about series (like which
  15092. // name of series is available in legend).
  15093. function removeEdgeAndAdd(succComponentType) {
  15094. targetNameSet[succComponentType] = true;
  15095. removeEdge(succComponentType);
  15096. }
  15097. };
  15098. function makeDepndencyGraph(fullNameList) {
  15099. var graph = {};
  15100. var noEntryList = [];
  15101. each(fullNameList, function (name) {
  15102. var thisItem = createDependencyGraphItem(graph, name);
  15103. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15104. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15105. thisItem.entryCount = availableDeps.length;
  15106. if (thisItem.entryCount === 0) {
  15107. noEntryList.push(name);
  15108. }
  15109. each(availableDeps, function (dependentName) {
  15110. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15111. thisItem.predecessor.push(dependentName);
  15112. }
  15113. var thatItem = createDependencyGraphItem(graph, dependentName);
  15114. if (indexOf(thatItem.successor, dependentName) < 0) {
  15115. thatItem.successor.push(name);
  15116. }
  15117. });
  15118. });
  15119. return {
  15120. graph: graph,
  15121. noEntryList: noEntryList
  15122. };
  15123. }
  15124. function createDependencyGraphItem(graph, name) {
  15125. if (!graph[name]) {
  15126. graph[name] = {
  15127. predecessor: [],
  15128. successor: []
  15129. };
  15130. }
  15131. return graph[name];
  15132. }
  15133. function getAvailableDependencies(originalDeps, fullNameList) {
  15134. var availableDeps = [];
  15135. each(originalDeps, function (dep) {
  15136. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15137. });
  15138. return availableDeps;
  15139. }
  15140. }
  15141. function inheritDefaultOption(superOption, subOption) {
  15142. // See also `model/Component.ts#getDefaultOption`
  15143. return merge(merge({}, superOption, true), subOption, true);
  15144. }
  15145. /*
  15146. * Licensed to the Apache Software Foundation (ASF) under one
  15147. * or more contributor license agreements. See the NOTICE file
  15148. * distributed with this work for additional information
  15149. * regarding copyright ownership. The ASF licenses this file
  15150. * to you under the Apache License, Version 2.0 (the
  15151. * "License"); you may not use this file except in compliance
  15152. * with the License. You may obtain a copy of the License at
  15153. *
  15154. * http://www.apache.org/licenses/LICENSE-2.0
  15155. *
  15156. * Unless required by applicable law or agreed to in writing,
  15157. * software distributed under the License is distributed on an
  15158. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15159. * KIND, either express or implied. See the License for the
  15160. * specific language governing permissions and limitations
  15161. * under the License.
  15162. */
  15163. /**
  15164. * AUTO-GENERATED FILE. DO NOT MODIFY.
  15165. */
  15166. /*
  15167. * Licensed to the Apache Software Foundation (ASF) under one
  15168. * or more contributor license agreements. See the NOTICE file
  15169. * distributed with this work for additional information
  15170. * regarding copyright ownership. The ASF licenses this file
  15171. * to you under the Apache License, Version 2.0 (the
  15172. * "License"); you may not use this file except in compliance
  15173. * with the License. You may obtain a copy of the License at
  15174. *
  15175. * http://www.apache.org/licenses/LICENSE-2.0
  15176. *
  15177. * Unless required by applicable law or agreed to in writing,
  15178. * software distributed under the License is distributed on an
  15179. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15180. * KIND, either express or implied. See the License for the
  15181. * specific language governing permissions and limitations
  15182. * under the License.
  15183. */
  15184. /**
  15185. * Language: English.
  15186. */
  15187. var langEN = {
  15188. time: {
  15189. month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  15190. monthAbbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  15191. dayOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  15192. dayOfWeekAbbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  15193. },
  15194. legend: {
  15195. selector: {
  15196. all: 'All',
  15197. inverse: 'Inv'
  15198. }
  15199. },
  15200. toolbox: {
  15201. brush: {
  15202. title: {
  15203. rect: 'Box Select',
  15204. polygon: 'Lasso Select',
  15205. lineX: 'Horizontally Select',
  15206. lineY: 'Vertically Select',
  15207. keep: 'Keep Selections',
  15208. clear: 'Clear Selections'
  15209. }
  15210. },
  15211. dataView: {
  15212. title: 'Data View',
  15213. lang: ['Data View', 'Close', 'Refresh']
  15214. },
  15215. dataZoom: {
  15216. title: {
  15217. zoom: 'Zoom',
  15218. back: 'Zoom Reset'
  15219. }
  15220. },
  15221. magicType: {
  15222. title: {
  15223. line: 'Switch to Line Chart',
  15224. bar: 'Switch to Bar Chart',
  15225. stack: 'Stack',
  15226. tiled: 'Tile'
  15227. }
  15228. },
  15229. restore: {
  15230. title: 'Restore'
  15231. },
  15232. saveAsImage: {
  15233. title: 'Save as Image',
  15234. lang: ['Right Click to Save Image']
  15235. }
  15236. },
  15237. series: {
  15238. typeNames: {
  15239. pie: 'Pie chart',
  15240. bar: 'Bar chart',
  15241. line: 'Line chart',
  15242. scatter: 'Scatter plot',
  15243. effectScatter: 'Ripple scatter plot',
  15244. radar: 'Radar chart',
  15245. tree: 'Tree',
  15246. treemap: 'Treemap',
  15247. boxplot: 'Boxplot',
  15248. candlestick: 'Candlestick',
  15249. k: 'K line chart',
  15250. heatmap: 'Heat map',
  15251. map: 'Map',
  15252. parallel: 'Parallel coordinate map',
  15253. lines: 'Line graph',
  15254. graph: 'Relationship graph',
  15255. sankey: 'Sankey diagram',
  15256. funnel: 'Funnel chart',
  15257. gauge: 'Gauge',
  15258. pictorialBar: 'Pictorial bar',
  15259. themeRiver: 'Theme River Map',
  15260. sunburst: 'Sunburst'
  15261. }
  15262. },
  15263. aria: {
  15264. general: {
  15265. withTitle: 'This is a chart about "{title}"',
  15266. withoutTitle: 'This is a chart'
  15267. },
  15268. series: {
  15269. single: {
  15270. prefix: '',
  15271. withName: ' with type {seriesType} named {seriesName}.',
  15272. withoutName: ' with type {seriesType}.'
  15273. },
  15274. multiple: {
  15275. prefix: '. It consists of {seriesCount} series count.',
  15276. withName: ' The {seriesId} series is a {seriesType} representing {seriesName}.',
  15277. withoutName: ' The {seriesId} series is a {seriesType}.',
  15278. separator: {
  15279. middle: '',
  15280. end: ''
  15281. }
  15282. }
  15283. },
  15284. data: {
  15285. allData: 'The data is as follows: ',
  15286. partialData: 'The first {displayCnt} items are: ',
  15287. withName: 'the data for {name} is {value}',
  15288. withoutName: '{value}',
  15289. separator: {
  15290. middle: ', ',
  15291. end: '. '
  15292. }
  15293. }
  15294. }
  15295. };
  15296. /*
  15297. * Licensed to the Apache Software Foundation (ASF) under one
  15298. * or more contributor license agreements. See the NOTICE file
  15299. * distributed with this work for additional information
  15300. * regarding copyright ownership. The ASF licenses this file
  15301. * to you under the Apache License, Version 2.0 (the
  15302. * "License"); you may not use this file except in compliance
  15303. * with the License. You may obtain a copy of the License at
  15304. *
  15305. * http://www.apache.org/licenses/LICENSE-2.0
  15306. *
  15307. * Unless required by applicable law or agreed to in writing,
  15308. * software distributed under the License is distributed on an
  15309. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15310. * KIND, either express or implied. See the License for the
  15311. * specific language governing permissions and limitations
  15312. * under the License.
  15313. */
  15314. /**
  15315. * AUTO-GENERATED FILE. DO NOT MODIFY.
  15316. */
  15317. /*
  15318. * Licensed to the Apache Software Foundation (ASF) under one
  15319. * or more contributor license agreements. See the NOTICE file
  15320. * distributed with this work for additional information
  15321. * regarding copyright ownership. The ASF licenses this file
  15322. * to you under the Apache License, Version 2.0 (the
  15323. * "License"); you may not use this file except in compliance
  15324. * with the License. You may obtain a copy of the License at
  15325. *
  15326. * http://www.apache.org/licenses/LICENSE-2.0
  15327. *
  15328. * Unless required by applicable law or agreed to in writing,
  15329. * software distributed under the License is distributed on an
  15330. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15331. * KIND, either express or implied. See the License for the
  15332. * specific language governing permissions and limitations
  15333. * under the License.
  15334. */
  15335. var langZH = {
  15336. time: {
  15337. month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  15338. monthAbbr: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  15339. dayOfWeek: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  15340. dayOfWeekAbbr: ['日', '一', '二', '三', '四', '五', '六']
  15341. },
  15342. legend: {
  15343. selector: {
  15344. all: '全选',
  15345. inverse: '反选'
  15346. }
  15347. },
  15348. toolbox: {
  15349. brush: {
  15350. title: {
  15351. rect: '矩形选择',
  15352. polygon: '圈选',
  15353. lineX: '横向选择',
  15354. lineY: '纵向选择',
  15355. keep: '保持选择',
  15356. clear: '清除选择'
  15357. }
  15358. },
  15359. dataView: {
  15360. title: '数据视图',
  15361. lang: ['数据视图', '关闭', '刷新']
  15362. },
  15363. dataZoom: {
  15364. title: {
  15365. zoom: '区域缩放',
  15366. back: '区域缩放还原'
  15367. }
  15368. },
  15369. magicType: {
  15370. title: {
  15371. line: '切换为折线图',
  15372. bar: '切换为柱状图',
  15373. stack: '切换为堆叠',
  15374. tiled: '切换为平铺'
  15375. }
  15376. },
  15377. restore: {
  15378. title: '还原'
  15379. },
  15380. saveAsImage: {
  15381. title: '保存为图片',
  15382. lang: ['右键另存为图片']
  15383. }
  15384. },
  15385. series: {
  15386. typeNames: {
  15387. pie: '饼图',
  15388. bar: '柱状图',
  15389. line: '折线图',
  15390. scatter: '散点图',
  15391. effectScatter: '涟漪散点图',
  15392. radar: '雷达图',
  15393. tree: '树图',
  15394. treemap: '矩形树图',
  15395. boxplot: '箱型图',
  15396. candlestick: 'K线图',
  15397. k: 'K线图',
  15398. heatmap: '热力图',
  15399. map: '地图',
  15400. parallel: '平行坐标图',
  15401. lines: '线图',
  15402. graph: '关系图',
  15403. sankey: '桑基图',
  15404. funnel: '漏斗图',
  15405. gauge: '仪表盘图',
  15406. pictorialBar: '象形柱图',
  15407. themeRiver: '主题河流图',
  15408. sunburst: '旭日图'
  15409. }
  15410. },
  15411. aria: {
  15412. general: {
  15413. withTitle: '这是一个关于“{title}”的图表。',
  15414. withoutTitle: '这是一个图表,'
  15415. },
  15416. series: {
  15417. single: {
  15418. prefix: '',
  15419. withName: '图表类型是{seriesType},表示{seriesName}。',
  15420. withoutName: '图表类型是{seriesType}。'
  15421. },
  15422. multiple: {
  15423. prefix: '它由{seriesCount}个图表系列组成。',
  15424. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  15425. withoutName: '第{seriesId}个系列是一个{seriesType},',
  15426. separator: {
  15427. middle: ';',
  15428. end: '。'
  15429. }
  15430. }
  15431. },
  15432. data: {
  15433. allData: '其数据是——',
  15434. partialData: '其中,前{displayCnt}项是——',
  15435. withName: '{name}的数据是{value}',
  15436. withoutName: '{value}',
  15437. separator: {
  15438. middle: ',',
  15439. end: ''
  15440. }
  15441. }
  15442. }
  15443. };
  15444. var LOCALE_ZH = 'ZH';
  15445. var LOCALE_EN = 'EN';
  15446. var DEFAULT_LOCALE = LOCALE_EN;
  15447. var localeStorage = {};
  15448. var localeModels = {};
  15449. var SYSTEM_LANG = !env.domSupported ? DEFAULT_LOCALE : function () {
  15450. var langStr = (
  15451. /* eslint-disable-next-line */
  15452. document.documentElement.lang || navigator.language || navigator.browserLanguage).toUpperCase();
  15453. return langStr.indexOf(LOCALE_ZH) > -1 ? LOCALE_ZH : DEFAULT_LOCALE;
  15454. }();
  15455. function registerLocale(locale, localeObj) {
  15456. locale = locale.toUpperCase();
  15457. localeModels[locale] = new Model(localeObj);
  15458. localeStorage[locale] = localeObj;
  15459. } // export function getLocale(locale: string) {
  15460. // return localeStorage[locale];
  15461. // }
  15462. function createLocaleObject(locale) {
  15463. if (isString(locale)) {
  15464. var localeObj = localeStorage[locale.toUpperCase()] || {};
  15465. if (locale === LOCALE_ZH || locale === LOCALE_EN) {
  15466. return clone(localeObj);
  15467. } else {
  15468. return merge(clone(localeObj), clone(localeStorage[DEFAULT_LOCALE]), false);
  15469. }
  15470. } else {
  15471. return merge(clone(locale), clone(localeStorage[DEFAULT_LOCALE]), false);
  15472. }
  15473. }
  15474. function getLocaleModel(lang) {
  15475. return localeModels[lang];
  15476. }
  15477. function getDefaultLocaleModel() {
  15478. return localeModels[DEFAULT_LOCALE];
  15479. } // Default locale
  15480. registerLocale(LOCALE_EN, langEN);
  15481. registerLocale(LOCALE_ZH, langZH);
  15482. var ONE_SECOND = 1000;
  15483. var ONE_MINUTE = ONE_SECOND * 60;
  15484. var ONE_HOUR = ONE_MINUTE * 60;
  15485. var ONE_DAY = ONE_HOUR * 24;
  15486. var ONE_YEAR = ONE_DAY * 365;
  15487. var defaultLeveledFormatter = {
  15488. year: '{yyyy}',
  15489. month: '{MMM}',
  15490. day: '{d}',
  15491. hour: '{HH}:{mm}',
  15492. minute: '{HH}:{mm}',
  15493. second: '{HH}:{mm}:{ss}',
  15494. millisecond: '{HH}:{mm}:{ss} {SSS}',
  15495. none: '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss} {SSS}'
  15496. };
  15497. var fullDayFormatter = '{yyyy}-{MM}-{dd}';
  15498. var fullLeveledFormatter = {
  15499. year: '{yyyy}',
  15500. month: '{yyyy}-{MM}',
  15501. day: fullDayFormatter,
  15502. hour: fullDayFormatter + ' ' + defaultLeveledFormatter.hour,
  15503. minute: fullDayFormatter + ' ' + defaultLeveledFormatter.minute,
  15504. second: fullDayFormatter + ' ' + defaultLeveledFormatter.second,
  15505. millisecond: defaultLeveledFormatter.none
  15506. };
  15507. var primaryTimeUnits = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
  15508. var timeUnits = ['year', 'half-year', 'quarter', 'month', 'week', 'half-week', 'day', 'half-day', 'quarter-day', 'hour', 'minute', 'second', 'millisecond'];
  15509. function pad(str, len) {
  15510. str += '';
  15511. return '0000'.substr(0, len - str.length) + str;
  15512. }
  15513. function getPrimaryTimeUnit(timeUnit) {
  15514. switch (timeUnit) {
  15515. case 'half-year':
  15516. case 'quarter':
  15517. return 'month';
  15518. case 'week':
  15519. case 'half-week':
  15520. return 'day';
  15521. case 'half-day':
  15522. case 'quarter-day':
  15523. return 'hour';
  15524. default:
  15525. // year, minutes, second, milliseconds
  15526. return timeUnit;
  15527. }
  15528. }
  15529. function isPrimaryTimeUnit(timeUnit) {
  15530. return timeUnit === getPrimaryTimeUnit(timeUnit);
  15531. }
  15532. function getDefaultFormatPrecisionOfInterval(timeUnit) {
  15533. switch (timeUnit) {
  15534. case 'year':
  15535. case 'month':
  15536. return 'day';
  15537. case 'millisecond':
  15538. return 'millisecond';
  15539. default:
  15540. // Also for day, hour, minute, second
  15541. return 'second';
  15542. }
  15543. }
  15544. function format( // Note: The result based on `isUTC` are totally different, which can not be just simply
  15545. // substituted by the result without `isUTC`. So we make the param `isUTC` mandatory.
  15546. time, template, isUTC, lang) {
  15547. var date = parseDate(time);
  15548. var y = date[fullYearGetterName(isUTC)]();
  15549. var M = date[monthGetterName(isUTC)]() + 1;
  15550. var q = Math.floor((M - 1) / 4) + 1;
  15551. var d = date[dateGetterName(isUTC)]();
  15552. var e = date['get' + (isUTC ? 'UTC' : '') + 'Day']();
  15553. var H = date[hoursGetterName(isUTC)]();
  15554. var h = (H - 1) % 12 + 1;
  15555. var m = date[minutesGetterName(isUTC)]();
  15556. var s = date[secondsGetterName(isUTC)]();
  15557. var S = date[millisecondsGetterName(isUTC)]();
  15558. var localeModel = lang instanceof Model ? lang : getLocaleModel(lang || SYSTEM_LANG) || getDefaultLocaleModel();
  15559. var timeModel = localeModel.getModel('time');
  15560. var month = timeModel.get('month');
  15561. var monthAbbr = timeModel.get('monthAbbr');
  15562. var dayOfWeek = timeModel.get('dayOfWeek');
  15563. var dayOfWeekAbbr = timeModel.get('dayOfWeekAbbr');
  15564. return (template || '').replace(/{yyyy}/g, y + '').replace(/{yy}/g, y % 100 + '').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 + '');
  15565. }
  15566. function leveledFormat(tick, idx, formatter, lang, isUTC) {
  15567. var template = null;
  15568. if (typeof formatter === 'string') {
  15569. // Single formatter for all units at all levels
  15570. template = formatter;
  15571. } else if (typeof formatter === 'function') {
  15572. // Callback formatter
  15573. template = formatter(tick.value, idx, {
  15574. level: tick.level
  15575. });
  15576. } else {
  15577. var defaults$1 = extend({}, defaultLeveledFormatter);
  15578. if (tick.level > 0) {
  15579. for (var i = 0; i < primaryTimeUnits.length; ++i) {
  15580. defaults$1[primaryTimeUnits[i]] = "{primary|" + defaults$1[primaryTimeUnits[i]] + "}";
  15581. }
  15582. }
  15583. var mergedFormatter = formatter ? formatter.inherit === false ? formatter // Use formatter with bigger units
  15584. : defaults(formatter, defaults$1) : defaults$1;
  15585. var unit = getUnitFromValue(tick.value, isUTC);
  15586. if (mergedFormatter[unit]) {
  15587. template = mergedFormatter[unit];
  15588. } else if (mergedFormatter.inherit) {
  15589. // Unit formatter is not defined and should inherit from bigger units
  15590. var targetId = timeUnits.indexOf(unit);
  15591. for (var i = targetId - 1; i >= 0; --i) {
  15592. if (mergedFormatter[unit]) {
  15593. template = mergedFormatter[unit];
  15594. break;
  15595. }
  15596. }
  15597. template = template || defaults$1.none;
  15598. }
  15599. if (isArray(template)) {
  15600. var levelId = tick.level == null ? 0 : tick.level >= 0 ? tick.level : template.length + tick.level;
  15601. levelId = Math.min(levelId, template.length - 1);
  15602. template = template[levelId];
  15603. }
  15604. }
  15605. return format(new Date(tick.value), template, isUTC, lang);
  15606. }
  15607. function getUnitFromValue(value, isUTC) {
  15608. var date = parseDate(value);
  15609. var M = date[monthGetterName(isUTC)]() + 1;
  15610. var d = date[dateGetterName(isUTC)]();
  15611. var h = date[hoursGetterName(isUTC)]();
  15612. var m = date[minutesGetterName(isUTC)]();
  15613. var s = date[secondsGetterName(isUTC)]();
  15614. var S = date[millisecondsGetterName(isUTC)]();
  15615. var isSecond = S === 0;
  15616. var isMinute = isSecond && s === 0;
  15617. var isHour = isMinute && m === 0;
  15618. var isDay = isHour && h === 0;
  15619. var isMonth = isDay && d === 1;
  15620. var isYear = isMonth && M === 1;
  15621. if (isYear) {
  15622. return 'year';
  15623. } else if (isMonth) {
  15624. return 'month';
  15625. } else if (isDay) {
  15626. return 'day';
  15627. } else if (isHour) {
  15628. return 'hour';
  15629. } else if (isMinute) {
  15630. return 'minute';
  15631. } else if (isSecond) {
  15632. return 'second';
  15633. } else {
  15634. return 'millisecond';
  15635. }
  15636. }
  15637. function getUnitValue(value, unit, isUTC) {
  15638. var date = typeof value === 'number' ? parseDate(value) : value;
  15639. unit = unit || getUnitFromValue(value, isUTC);
  15640. switch (unit) {
  15641. case 'year':
  15642. return date[fullYearGetterName(isUTC)]();
  15643. case 'half-year':
  15644. return date[monthGetterName(isUTC)]() >= 6 ? 1 : 0;
  15645. case 'quarter':
  15646. return Math.floor((date[monthGetterName(isUTC)]() + 1) / 4);
  15647. case 'month':
  15648. return date[monthGetterName(isUTC)]();
  15649. case 'day':
  15650. return date[dateGetterName(isUTC)]();
  15651. case 'half-day':
  15652. return date[hoursGetterName(isUTC)]() / 24;
  15653. case 'hour':
  15654. return date[hoursGetterName(isUTC)]();
  15655. case 'minute':
  15656. return date[minutesGetterName(isUTC)]();
  15657. case 'second':
  15658. return date[secondsGetterName(isUTC)]();
  15659. case 'millisecond':
  15660. return date[millisecondsGetterName(isUTC)]();
  15661. }
  15662. }
  15663. function fullYearGetterName(isUTC) {
  15664. return isUTC ? 'getUTCFullYear' : 'getFullYear';
  15665. }
  15666. function monthGetterName(isUTC) {
  15667. return isUTC ? 'getUTCMonth' : 'getMonth';
  15668. }
  15669. function dateGetterName(isUTC) {
  15670. return isUTC ? 'getUTCDate' : 'getDate';
  15671. }
  15672. function hoursGetterName(isUTC) {
  15673. return isUTC ? 'getUTCHours' : 'getHours';
  15674. }
  15675. function minutesGetterName(isUTC) {
  15676. return isUTC ? 'getUTCMinutes' : 'getMinutes';
  15677. }
  15678. function secondsGetterName(isUTC) {
  15679. return isUTC ? 'getUTCSeconds' : 'getSeconds';
  15680. }
  15681. function millisecondsGetterName(isUTC) {
  15682. return isUTC ? 'getUTCMilliseconds' : 'getMilliseconds';
  15683. }
  15684. function fullYearSetterName(isUTC) {
  15685. return isUTC ? 'setUTCFullYear' : 'setFullYear';
  15686. }
  15687. function monthSetterName(isUTC) {
  15688. return isUTC ? 'setUTCMonth' : 'setMonth';
  15689. }
  15690. function dateSetterName(isUTC) {
  15691. return isUTC ? 'setUTCDate' : 'setDate';
  15692. }
  15693. function hoursSetterName(isUTC) {
  15694. return isUTC ? 'setUTCHours' : 'setHours';
  15695. }
  15696. function minutesSetterName(isUTC) {
  15697. return isUTC ? 'setUTCMinutes' : 'setMinutes';
  15698. }
  15699. function secondsSetterName(isUTC) {
  15700. return isUTC ? 'setUTCSeconds' : 'setSeconds';
  15701. }
  15702. function millisecondsSetterName(isUTC) {
  15703. return isUTC ? 'setUTCMilliseconds' : 'setMilliseconds';
  15704. }
  15705. function getTextRect(text, font, align, verticalAlign, padding, rich, truncate, lineHeight) {
  15706. var textEl = new ZRText({
  15707. style: {
  15708. text: text,
  15709. font: font,
  15710. align: align,
  15711. verticalAlign: verticalAlign,
  15712. padding: padding,
  15713. rich: rich,
  15714. overflow: truncate ? 'truncate' : null,
  15715. lineHeight: lineHeight
  15716. }
  15717. });
  15718. return textEl.getBoundingRect();
  15719. }
  15720. /**
  15721. * Add a comma each three digit.
  15722. */
  15723. function addCommas(x) {
  15724. if (!isNumeric(x)) {
  15725. return isString(x) ? x : '-';
  15726. }
  15727. var parts = (x + '').split('.');
  15728. return parts[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (parts.length > 1 ? '.' + parts[1] : '');
  15729. }
  15730. function toCamelCase(str, upperCaseFirst) {
  15731. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  15732. return group1.toUpperCase();
  15733. });
  15734. if (upperCaseFirst && str) {
  15735. str = str.charAt(0).toUpperCase() + str.slice(1);
  15736. }
  15737. return str;
  15738. }
  15739. var normalizeCssArray$1 = normalizeCssArray;
  15740. var replaceReg = /([&<>"'])/g;
  15741. var replaceMap = {
  15742. '&': '&amp;',
  15743. '<': '&lt;',
  15744. '>': '&gt;',
  15745. '"': '&quot;',
  15746. '\'': '&#39;'
  15747. };
  15748. function encodeHTML(source) {
  15749. return source == null ? '' : (source + '').replace(replaceReg, function (str, c) {
  15750. return replaceMap[c];
  15751. });
  15752. }
  15753. /**
  15754. * Make value user readable for tooltip and label.
  15755. * "User readable":
  15756. * Try to not print programmer-specific text like NaN, Infinity, null, undefined.
  15757. * Avoid to display an empty string, which users can not recognize there is
  15758. * a value and it might look like a bug.
  15759. */
  15760. function makeValueReadable(value, valueType, useUTC) {
  15761. var USER_READABLE_DEFUALT_TIME_PATTERN = '{yyyy}-{MM}-{dd} {hh}:{mm}:{ss}';
  15762. function stringToUserReadable(str) {
  15763. return str && trim(str) ? str : '-';
  15764. }
  15765. function isNumberUserReadable(num) {
  15766. return !!(num != null && !isNaN(num) && isFinite(num));
  15767. }
  15768. var isTypeTime = valueType === 'time';
  15769. var isValueDate = value instanceof Date;
  15770. if (isTypeTime || isValueDate) {
  15771. var date = isTypeTime ? parseDate(value) : value;
  15772. if (!isNaN(+date)) {
  15773. return format(date, USER_READABLE_DEFUALT_TIME_PATTERN, useUTC);
  15774. } else if (isValueDate) {
  15775. return '-';
  15776. } // In other cases, continue to try to display the value in the following code.
  15777. }
  15778. if (valueType === 'ordinal') {
  15779. return isStringSafe(value) ? stringToUserReadable(value) : isNumber(value) ? isNumberUserReadable(value) ? value + '' : '-' : '-';
  15780. } // By default.
  15781. var numericResult = numericToNumber(value);
  15782. return isNumberUserReadable(numericResult) ? addCommas(numericResult) : isStringSafe(value) ? stringToUserReadable(value) : typeof value === 'boolean' ? value + '' : '-';
  15783. }
  15784. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  15785. var wrapVar = function (varName, seriesIdx) {
  15786. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  15787. };
  15788. /**
  15789. * Template formatter
  15790. * @param {Array.<Object>|Object} paramsList
  15791. */
  15792. function formatTpl(tpl, paramsList, encode) {
  15793. if (!isArray(paramsList)) {
  15794. paramsList = [paramsList];
  15795. }
  15796. var seriesLen = paramsList.length;
  15797. if (!seriesLen) {
  15798. return '';
  15799. }
  15800. var $vars = paramsList[0].$vars || [];
  15801. for (var i = 0; i < $vars.length; i++) {
  15802. var alias = TPL_VAR_ALIAS[i];
  15803. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  15804. }
  15805. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  15806. for (var k = 0; k < $vars.length; k++) {
  15807. var val = paramsList[seriesIdx][$vars[k]];
  15808. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  15809. }
  15810. }
  15811. return tpl;
  15812. }
  15813. function getTooltipMarker(inOpt, extraCssText) {
  15814. var opt = isString(inOpt) ? {
  15815. color: inOpt,
  15816. extraCssText: extraCssText
  15817. } : inOpt || {};
  15818. var color = opt.color;
  15819. var type = opt.type;
  15820. extraCssText = opt.extraCssText;
  15821. var renderMode = opt.renderMode || 'html';
  15822. if (!color) {
  15823. return '';
  15824. }
  15825. if (renderMode === 'html') {
  15826. 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:' // Only support string
  15827. + 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>';
  15828. } else {
  15829. // Should better not to auto generate style name by auto-increment number here.
  15830. // Because this util is usually called in tooltip formatter, which is probably
  15831. // called repeatly when mouse move and the auto-increment number increases fast.
  15832. // Users can make their own style name by theirselves, make it unique and readable.
  15833. var markerId = opt.markerId || 'markerX';
  15834. return {
  15835. renderMode: renderMode,
  15836. content: '{' + markerId + '|} ',
  15837. style: type === 'subItem' ? {
  15838. width: 4,
  15839. height: 4,
  15840. borderRadius: 2,
  15841. backgroundColor: color
  15842. } : {
  15843. width: 10,
  15844. height: 10,
  15845. borderRadius: 5,
  15846. backgroundColor: color
  15847. }
  15848. };
  15849. }
  15850. }
  15851. /**
  15852. * @deprecated Use `time/format` instead.
  15853. * ISO Date format
  15854. * @param {string} tpl
  15855. * @param {number} value
  15856. * @param {boolean} [isUTC=false] Default in local time.
  15857. * see `module:echarts/scale/Time`
  15858. * and `module:echarts/util/number#parseDate`.
  15859. * @inner
  15860. */
  15861. function formatTime(tpl, value, isUTC) {
  15862. if ("development" !== 'production') {
  15863. deprecateReplaceLog('echarts.format.formatTime', 'echarts.time.format');
  15864. }
  15865. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  15866. tpl = 'MM-dd\nyyyy';
  15867. }
  15868. var date = parseDate(value);
  15869. var utc = isUTC ? 'UTC' : '';
  15870. var y = date['get' + utc + 'FullYear']();
  15871. var M = date['get' + utc + 'Month']() + 1;
  15872. var d = date['get' + utc + 'Date']();
  15873. var h = date['get' + utc + 'Hours']();
  15874. var m = date['get' + utc + 'Minutes']();
  15875. var s = date['get' + utc + 'Seconds']();
  15876. var S = date['get' + utc + 'Milliseconds']();
  15877. tpl = tpl.replace('MM', pad(M, 2)).replace('M', M).replace('yyyy', y).replace('yy', y % 100 + '').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));
  15878. return tpl;
  15879. }
  15880. /**
  15881. * Capital first
  15882. * @param {string} str
  15883. * @return {string}
  15884. */
  15885. function capitalFirst(str) {
  15886. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  15887. }
  15888. /**
  15889. * @return Never be null/undefined.
  15890. */
  15891. function convertToColorString(color, defaultColor) {
  15892. defaultColor = defaultColor || 'transparent';
  15893. return isString(color) ? color : isObject(color) ? color.colorStops && (color.colorStops[0] || {}).color || defaultColor : defaultColor;
  15894. }
  15895. /**
  15896. * open new tab
  15897. * @param link url
  15898. * @param target blank or self
  15899. */
  15900. function windowOpen(link, target) {
  15901. /* global window */
  15902. if (target === '_blank' || target === 'blank') {
  15903. var blank = window.open();
  15904. blank.opener = null;
  15905. blank.location.href = link;
  15906. } else {
  15907. window.open(link, target);
  15908. }
  15909. }
  15910. var each$1 = each;
  15911. /**
  15912. * @public
  15913. */
  15914. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  15915. /**
  15916. * @public
  15917. */
  15918. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  15919. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  15920. var x = 0;
  15921. var y = 0;
  15922. if (maxWidth == null) {
  15923. maxWidth = Infinity;
  15924. }
  15925. if (maxHeight == null) {
  15926. maxHeight = Infinity;
  15927. }
  15928. var currentLineMaxSize = 0;
  15929. group.eachChild(function (child, idx) {
  15930. var rect = child.getBoundingRect();
  15931. var nextChild = group.childAt(idx + 1);
  15932. var nextChildRect = nextChild && nextChild.getBoundingRect();
  15933. var nextX;
  15934. var nextY;
  15935. if (orient === 'horizontal') {
  15936. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  15937. nextX = x + moveX; // Wrap when width exceeds maxWidth or meet a `newline` group
  15938. // FIXME compare before adding gap?
  15939. if (nextX > maxWidth || child.newline) {
  15940. x = 0;
  15941. nextX = moveX;
  15942. y += currentLineMaxSize + gap;
  15943. currentLineMaxSize = rect.height;
  15944. } else {
  15945. // FIXME: consider rect.y is not `0`?
  15946. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  15947. }
  15948. } else {
  15949. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  15950. nextY = y + moveY; // Wrap when width exceeds maxHeight or meet a `newline` group
  15951. if (nextY > maxHeight || child.newline) {
  15952. x += currentLineMaxSize + gap;
  15953. y = 0;
  15954. nextY = moveY;
  15955. currentLineMaxSize = rect.width;
  15956. } else {
  15957. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  15958. }
  15959. }
  15960. if (child.newline) {
  15961. return;
  15962. }
  15963. child.x = x;
  15964. child.y = y;
  15965. child.markRedraw();
  15966. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  15967. });
  15968. }
  15969. /**
  15970. * VBox or HBox layouting
  15971. * @param {string} orient
  15972. * @param {module:zrender/graphic/Group} group
  15973. * @param {number} gap
  15974. * @param {number} [width=Infinity]
  15975. * @param {number} [height=Infinity]
  15976. */
  15977. var box = boxLayout;
  15978. /**
  15979. * VBox layouting
  15980. * @param {module:zrender/graphic/Group} group
  15981. * @param {number} gap
  15982. * @param {number} [width=Infinity]
  15983. * @param {number} [height=Infinity]
  15984. */
  15985. var vbox = curry(boxLayout, 'vertical');
  15986. /**
  15987. * HBox layouting
  15988. * @param {module:zrender/graphic/Group} group
  15989. * @param {number} gap
  15990. * @param {number} [width=Infinity]
  15991. * @param {number} [height=Infinity]
  15992. */
  15993. var hbox = curry(boxLayout, 'horizontal');
  15994. /**
  15995. * Parse position info.
  15996. */
  15997. function getLayoutRect(positionInfo, containerRect, margin) {
  15998. margin = normalizeCssArray$1(margin || 0);
  15999. var containerWidth = containerRect.width;
  16000. var containerHeight = containerRect.height;
  16001. var left = parsePercent$1(positionInfo.left, containerWidth);
  16002. var top = parsePercent$1(positionInfo.top, containerHeight);
  16003. var right = parsePercent$1(positionInfo.right, containerWidth);
  16004. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  16005. var width = parsePercent$1(positionInfo.width, containerWidth);
  16006. var height = parsePercent$1(positionInfo.height, containerHeight);
  16007. var verticalMargin = margin[2] + margin[0];
  16008. var horizontalMargin = margin[1] + margin[3];
  16009. var aspect = positionInfo.aspect; // If width is not specified, calculate width from left and right
  16010. if (isNaN(width)) {
  16011. width = containerWidth - right - horizontalMargin - left;
  16012. }
  16013. if (isNaN(height)) {
  16014. height = containerHeight - bottom - verticalMargin - top;
  16015. }
  16016. if (aspect != null) {
  16017. // If width and height are not given
  16018. // 1. Graph should not exceeds the container
  16019. // 2. Aspect must be keeped
  16020. // 3. Graph should take the space as more as possible
  16021. // FIXME
  16022. // Margin is not considered, because there is no case that both
  16023. // using margin and aspect so far.
  16024. if (isNaN(width) && isNaN(height)) {
  16025. if (aspect > containerWidth / containerHeight) {
  16026. width = containerWidth * 0.8;
  16027. } else {
  16028. height = containerHeight * 0.8;
  16029. }
  16030. } // Calculate width or height with given aspect
  16031. if (isNaN(width)) {
  16032. width = aspect * height;
  16033. }
  16034. if (isNaN(height)) {
  16035. height = width / aspect;
  16036. }
  16037. } // If left is not specified, calculate left from right and width
  16038. if (isNaN(left)) {
  16039. left = containerWidth - right - width - horizontalMargin;
  16040. }
  16041. if (isNaN(top)) {
  16042. top = containerHeight - bottom - height - verticalMargin;
  16043. } // Align left and top
  16044. switch (positionInfo.left || positionInfo.right) {
  16045. case 'center':
  16046. left = containerWidth / 2 - width / 2 - margin[3];
  16047. break;
  16048. case 'right':
  16049. left = containerWidth - width - horizontalMargin;
  16050. break;
  16051. }
  16052. switch (positionInfo.top || positionInfo.bottom) {
  16053. case 'middle':
  16054. case 'center':
  16055. top = containerHeight / 2 - height / 2 - margin[0];
  16056. break;
  16057. case 'bottom':
  16058. top = containerHeight - height - verticalMargin;
  16059. break;
  16060. } // If something is wrong and left, top, width, height are calculated as NaN
  16061. left = left || 0;
  16062. top = top || 0;
  16063. if (isNaN(width)) {
  16064. // Width may be NaN if only one value is given except width
  16065. width = containerWidth - horizontalMargin - left - (right || 0);
  16066. }
  16067. if (isNaN(height)) {
  16068. // Height may be NaN if only one value is given except height
  16069. height = containerHeight - verticalMargin - top - (bottom || 0);
  16070. }
  16071. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  16072. rect.margin = margin;
  16073. return rect;
  16074. }
  16075. /**
  16076. * Position a zr element in viewport
  16077. * Group position is specified by either
  16078. * {left, top}, {right, bottom}
  16079. * If all properties exists, right and bottom will be igonred.
  16080. *
  16081. * Logic:
  16082. * 1. Scale (against origin point in parent coord)
  16083. * 2. Rotate (against origin point in parent coord)
  16084. * 3. Traslate (with el.position by this method)
  16085. * So this method only fixes the last step 'Traslate', which does not affect
  16086. * scaling and rotating.
  16087. *
  16088. * If be called repeatly with the same input el, the same result will be gotten.
  16089. *
  16090. * @param el Should have `getBoundingRect` method.
  16091. * @param positionInfo
  16092. * @param positionInfo.left
  16093. * @param positionInfo.top
  16094. * @param positionInfo.right
  16095. * @param positionInfo.bottom
  16096. * @param positionInfo.width Only for opt.boundingModel: 'raw'
  16097. * @param positionInfo.height Only for opt.boundingModel: 'raw'
  16098. * @param containerRect
  16099. * @param margin
  16100. * @param opt
  16101. * @param opt.hv Only horizontal or only vertical. Default to be [1, 1]
  16102. * @param opt.boundingMode
  16103. * Specify how to calculate boundingRect when locating.
  16104. * 'all': Position the boundingRect that is transformed and uioned
  16105. * both itself and its descendants.
  16106. * This mode simplies confine the elements in the bounding
  16107. * of their container (e.g., using 'right: 0').
  16108. * 'raw': Position the boundingRect that is not transformed and only itself.
  16109. * This mode is useful when you want a element can overflow its
  16110. * container. (Consider a rotated circle needs to be located in a corner.)
  16111. * In this mode positionInfo.width/height can only be number.
  16112. */
  16113. function positionElement(el, positionInfo, containerRect, margin, opt) {
  16114. var h = !opt || !opt.hv || opt.hv[0];
  16115. var v = !opt || !opt.hv || opt.hv[1];
  16116. var boundingMode = opt && opt.boundingMode || 'all';
  16117. if (!h && !v) {
  16118. return;
  16119. }
  16120. var rect;
  16121. if (boundingMode === 'raw') {
  16122. rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect();
  16123. } else {
  16124. rect = el.getBoundingRect();
  16125. if (el.needLocalTransform()) {
  16126. var transform = el.getLocalTransform(); // Notice: raw rect may be inner object of el,
  16127. // which should not be modified.
  16128. rect = rect.clone();
  16129. rect.applyTransform(transform);
  16130. }
  16131. } // The real width and height can not be specified but calculated by the given el.
  16132. var layoutRect = getLayoutRect(defaults({
  16133. width: rect.width,
  16134. height: rect.height
  16135. }, positionInfo), containerRect, margin); // Because 'tranlate' is the last step in transform
  16136. // (see zrender/core/Transformable#getLocalTransform),
  16137. // we can just only modify el.position to get final result.
  16138. var dx = h ? layoutRect.x - rect.x : 0;
  16139. var dy = v ? layoutRect.y - rect.y : 0;
  16140. if (boundingMode === 'raw') {
  16141. el.x = dx;
  16142. el.y = dy;
  16143. } else {
  16144. el.x += dx;
  16145. el.y += dy;
  16146. }
  16147. el.markRedraw();
  16148. }
  16149. function fetchLayoutMode(ins) {
  16150. var layoutMode = ins.layoutMode || ins.constructor.layoutMode;
  16151. return isObject(layoutMode) ? layoutMode : layoutMode ? {
  16152. type: layoutMode
  16153. } : null;
  16154. }
  16155. /**
  16156. * Consider Case:
  16157. * When default option has {left: 0, width: 100}, and we set {right: 0}
  16158. * through setOption or media query, using normal zrUtil.merge will cause
  16159. * {right: 0} does not take effect.
  16160. *
  16161. * @example
  16162. * ComponentModel.extend({
  16163. * init: function () {
  16164. * ...
  16165. * let inputPositionParams = layout.getLayoutParams(option);
  16166. * this.mergeOption(inputPositionParams);
  16167. * },
  16168. * mergeOption: function (newOption) {
  16169. * newOption && zrUtil.merge(thisOption, newOption, true);
  16170. * layout.mergeLayoutParam(thisOption, newOption);
  16171. * }
  16172. * });
  16173. *
  16174. * @param targetOption
  16175. * @param newOption
  16176. * @param opt
  16177. */
  16178. function mergeLayoutParam(targetOption, newOption, opt) {
  16179. var ignoreSize = opt && opt.ignoreSize;
  16180. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  16181. var hResult = merge(HV_NAMES[0], 0);
  16182. var vResult = merge(HV_NAMES[1], 1);
  16183. copy(HV_NAMES[0], targetOption, hResult);
  16184. copy(HV_NAMES[1], targetOption, vResult);
  16185. function merge(names, hvIdx) {
  16186. var newParams = {};
  16187. var newValueCount = 0;
  16188. var merged = {};
  16189. var mergedValueCount = 0;
  16190. var enoughParamNumber = 2;
  16191. each$1(names, function (name) {
  16192. merged[name] = targetOption[name];
  16193. });
  16194. each$1(names, function (name) {
  16195. // Consider case: newOption.width is null, which is
  16196. // set by user for removing width setting.
  16197. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  16198. hasValue(newParams, name) && newValueCount++;
  16199. hasValue(merged, name) && mergedValueCount++;
  16200. });
  16201. if (ignoreSize[hvIdx]) {
  16202. // Only one of left/right is premitted to exist.
  16203. if (hasValue(newOption, names[1])) {
  16204. merged[names[2]] = null;
  16205. } else if (hasValue(newOption, names[2])) {
  16206. merged[names[1]] = null;
  16207. }
  16208. return merged;
  16209. } // Case: newOption: {width: ..., right: ...},
  16210. // or targetOption: {right: ...} and newOption: {width: ...},
  16211. // There is no conflict when merged only has params count
  16212. // little than enoughParamNumber.
  16213. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  16214. return merged;
  16215. } // Case: newOption: {width: ..., right: ...},
  16216. // Than we can make sure user only want those two, and ignore
  16217. // all origin params in targetOption.
  16218. else if (newValueCount >= enoughParamNumber) {
  16219. return newParams;
  16220. } else {
  16221. // Chose another param from targetOption by priority.
  16222. for (var i = 0; i < names.length; i++) {
  16223. var name_1 = names[i];
  16224. if (!hasProp(newParams, name_1) && hasProp(targetOption, name_1)) {
  16225. newParams[name_1] = targetOption[name_1];
  16226. break;
  16227. }
  16228. }
  16229. return newParams;
  16230. }
  16231. }
  16232. function hasProp(obj, name) {
  16233. return obj.hasOwnProperty(name);
  16234. }
  16235. function hasValue(obj, name) {
  16236. return obj[name] != null && obj[name] !== 'auto';
  16237. }
  16238. function copy(names, target, source) {
  16239. each$1(names, function (name) {
  16240. target[name] = source[name];
  16241. });
  16242. }
  16243. }
  16244. /**
  16245. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16246. */
  16247. function getLayoutParams(source) {
  16248. return copyLayoutParams({}, source);
  16249. }
  16250. /**
  16251. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16252. * @param {Object} source
  16253. * @return {Object} Result contains those props.
  16254. */
  16255. function copyLayoutParams(target, source) {
  16256. source && target && each$1(LOCATION_PARAMS, function (name) {
  16257. source.hasOwnProperty(name) && (target[name] = source[name]);
  16258. });
  16259. return target;
  16260. }
  16261. var inner = makeInner();
  16262. var ComponentModel =
  16263. /** @class */
  16264. function (_super) {
  16265. __extends(ComponentModel, _super);
  16266. function ComponentModel(option, parentModel, ecModel) {
  16267. var _this = _super.call(this, option, parentModel, ecModel) || this;
  16268. _this.uid = getUID('ec_cpt_model');
  16269. return _this;
  16270. }
  16271. ComponentModel.prototype.init = function (option, parentModel, ecModel) {
  16272. this.mergeDefaultAndTheme(option, ecModel);
  16273. };
  16274. ComponentModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  16275. var layoutMode = fetchLayoutMode(this);
  16276. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  16277. var themeModel = ecModel.getTheme();
  16278. merge(option, themeModel.get(this.mainType));
  16279. merge(option, this.getDefaultOption());
  16280. if (layoutMode) {
  16281. mergeLayoutParam(option, inputPositionParams, layoutMode);
  16282. }
  16283. };
  16284. ComponentModel.prototype.mergeOption = function (option, ecModel) {
  16285. merge(this.option, option, true);
  16286. var layoutMode = fetchLayoutMode(this);
  16287. if (layoutMode) {
  16288. mergeLayoutParam(this.option, option, layoutMode);
  16289. }
  16290. };
  16291. /**
  16292. * Called immediately after `init` or `mergeOption` of this instance called.
  16293. */
  16294. ComponentModel.prototype.optionUpdated = function (newCptOption, isInit) {};
  16295. /**
  16296. * [How to declare defaultOption]:
  16297. *
  16298. * (A) If using class declaration in typescript (since echarts 5):
  16299. * ```ts
  16300. * import {ComponentOption} from '../model/option';
  16301. * export interface XxxOption extends ComponentOption {
  16302. * aaa: number
  16303. * }
  16304. * export class XxxModel extends Component {
  16305. * static type = 'xxx';
  16306. * static defaultOption: XxxOption = {
  16307. * aaa: 123
  16308. * }
  16309. * }
  16310. * Component.registerClass(XxxModel);
  16311. * ```
  16312. * ```ts
  16313. * import {inheritDefaultOption} from '../util/component';
  16314. * import {XxxModel, XxxOption} from './XxxModel';
  16315. * export interface XxxSubOption extends XxxOption {
  16316. * bbb: number
  16317. * }
  16318. * class XxxSubModel extends XxxModel {
  16319. * static defaultOption: XxxSubOption = inheritDefaultOption(XxxModel.defaultOption, {
  16320. * bbb: 456
  16321. * })
  16322. * fn() {
  16323. * let opt = this.getDefaultOption();
  16324. * // opt is {aaa: 123, bbb: 456}
  16325. * }
  16326. * }
  16327. * ```
  16328. *
  16329. * (B) If using class extend (previous approach in echarts 3 & 4):
  16330. * ```js
  16331. * let XxxComponent = Component.extend({
  16332. * defaultOption: {
  16333. * xx: 123
  16334. * }
  16335. * })
  16336. * ```
  16337. * ```js
  16338. * let XxxSubComponent = XxxComponent.extend({
  16339. * defaultOption: {
  16340. * yy: 456
  16341. * },
  16342. * fn: function () {
  16343. * let opt = this.getDefaultOption();
  16344. * // opt is {xx: 123, yy: 456}
  16345. * }
  16346. * })
  16347. * ```
  16348. */
  16349. ComponentModel.prototype.getDefaultOption = function () {
  16350. var ctor = this.constructor; // If using class declaration, it is different to travel super class
  16351. // in legacy env and auto merge defaultOption. So if using class
  16352. // declaration, defaultOption should be merged manually.
  16353. if (!isExtendedClass(ctor)) {
  16354. // When using ts class, defaultOption must be declared as static.
  16355. return ctor.defaultOption;
  16356. } // FIXME: remove this approach?
  16357. var fields = inner(this);
  16358. if (!fields.defaultOption) {
  16359. var optList = [];
  16360. var clz = ctor;
  16361. while (clz) {
  16362. var opt = clz.prototype.defaultOption;
  16363. opt && optList.push(opt);
  16364. clz = clz.superClass;
  16365. }
  16366. var defaultOption = {};
  16367. for (var i = optList.length - 1; i >= 0; i--) {
  16368. defaultOption = merge(defaultOption, optList[i], true);
  16369. }
  16370. fields.defaultOption = defaultOption;
  16371. }
  16372. return fields.defaultOption;
  16373. };
  16374. /**
  16375. * Notice: always force to input param `useDefault` in case that forget to consider it.
  16376. * The same behavior as `modelUtil.parseFinder`.
  16377. *
  16378. * @param useDefault In many cases like series refer axis and axis refer grid,
  16379. * If axis index / axis id not specified, use the first target as default.
  16380. * In other cases like dataZoom refer axis, if not specified, measn no refer.
  16381. */
  16382. ComponentModel.prototype.getReferringComponents = function (mainType, opt) {
  16383. var indexKey = mainType + 'Index';
  16384. var idKey = mainType + 'Id';
  16385. return queryReferringComponents(this.ecModel, mainType, {
  16386. index: this.get(indexKey, true),
  16387. id: this.get(idKey, true)
  16388. }, opt);
  16389. };
  16390. ComponentModel.prototype.getBoxLayoutParams = function () {
  16391. // Consider itself having box layout configs.
  16392. var boxLayoutModel = this;
  16393. return {
  16394. left: boxLayoutModel.get('left'),
  16395. top: boxLayoutModel.get('top'),
  16396. right: boxLayoutModel.get('right'),
  16397. bottom: boxLayoutModel.get('bottom'),
  16398. width: boxLayoutModel.get('width'),
  16399. height: boxLayoutModel.get('height')
  16400. };
  16401. };
  16402. ComponentModel.protoInitialize = function () {
  16403. var proto = ComponentModel.prototype;
  16404. proto.type = 'component';
  16405. proto.id = '';
  16406. proto.name = '';
  16407. proto.mainType = '';
  16408. proto.subType = '';
  16409. proto.componentIndex = 0;
  16410. }();
  16411. return ComponentModel;
  16412. }(Model);
  16413. mountExtend(ComponentModel, Model);
  16414. enableClassManagement(ComponentModel);
  16415. enableSubTypeDefaulter(ComponentModel);
  16416. enableTopologicalTravel(ComponentModel, getDependencies);
  16417. function getDependencies(componentType) {
  16418. var deps = [];
  16419. each(ComponentModel.getClassesByMainType(componentType), function (clz) {
  16420. deps = deps.concat(clz.dependencies || clz.prototype.dependencies || []);
  16421. }); // Ensure main type.
  16422. deps = map(deps, function (type) {
  16423. return parseClassType(type).main;
  16424. }); // Hack dataset for convenience.
  16425. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  16426. deps.unshift('dataset');
  16427. }
  16428. return deps;
  16429. }
  16430. /*
  16431. * Licensed to the Apache Software Foundation (ASF) under one
  16432. * or more contributor license agreements. See the NOTICE file
  16433. * distributed with this work for additional information
  16434. * regarding copyright ownership. The ASF licenses this file
  16435. * to you under the Apache License, Version 2.0 (the
  16436. * "License"); you may not use this file except in compliance
  16437. * with the License. You may obtain a copy of the License at
  16438. *
  16439. * http://www.apache.org/licenses/LICENSE-2.0
  16440. *
  16441. * Unless required by applicable law or agreed to in writing,
  16442. * software distributed under the License is distributed on an
  16443. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16444. * KIND, either express or implied. See the License for the
  16445. * specific language governing permissions and limitations
  16446. * under the License.
  16447. */
  16448. /**
  16449. * AUTO-GENERATED FILE. DO NOT MODIFY.
  16450. */
  16451. /*
  16452. * Licensed to the Apache Software Foundation (ASF) under one
  16453. * or more contributor license agreements. See the NOTICE file
  16454. * distributed with this work for additional information
  16455. * regarding copyright ownership. The ASF licenses this file
  16456. * to you under the Apache License, Version 2.0 (the
  16457. * "License"); you may not use this file except in compliance
  16458. * with the License. You may obtain a copy of the License at
  16459. *
  16460. * http://www.apache.org/licenses/LICENSE-2.0
  16461. *
  16462. * Unless required by applicable law or agreed to in writing,
  16463. * software distributed under the License is distributed on an
  16464. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16465. * KIND, either express or implied. See the License for the
  16466. * specific language governing permissions and limitations
  16467. * under the License.
  16468. */
  16469. var platform = ''; // Navigator not exists in node
  16470. if (typeof navigator !== 'undefined') {
  16471. /* global navigator */
  16472. platform = navigator.platform || '';
  16473. }
  16474. var decalColor = 'rgba(0, 0, 0, 0.2)';
  16475. var globalDefault = {
  16476. darkMode: 'auto',
  16477. // backgroundColor: 'rgba(0,0,0,0)',
  16478. colorBy: 'series',
  16479. color: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'],
  16480. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  16481. aria: {
  16482. decal: {
  16483. decals: [{
  16484. color: decalColor,
  16485. dashArrayX: [1, 0],
  16486. dashArrayY: [2, 5],
  16487. symbolSize: 1,
  16488. rotation: Math.PI / 6
  16489. }, {
  16490. color: decalColor,
  16491. symbol: 'circle',
  16492. dashArrayX: [[8, 8], [0, 8, 8, 0]],
  16493. dashArrayY: [6, 0],
  16494. symbolSize: 0.8
  16495. }, {
  16496. color: decalColor,
  16497. dashArrayX: [1, 0],
  16498. dashArrayY: [4, 3],
  16499. rotation: -Math.PI / 4
  16500. }, {
  16501. color: decalColor,
  16502. dashArrayX: [[6, 6], [0, 6, 6, 0]],
  16503. dashArrayY: [6, 0]
  16504. }, {
  16505. color: decalColor,
  16506. dashArrayX: [[1, 0], [1, 6]],
  16507. dashArrayY: [1, 0, 6, 0],
  16508. rotation: Math.PI / 4
  16509. }, {
  16510. color: decalColor,
  16511. symbol: 'triangle',
  16512. dashArrayX: [[9, 9], [0, 9, 9, 0]],
  16513. dashArrayY: [7, 2],
  16514. symbolSize: 0.75
  16515. }]
  16516. }
  16517. },
  16518. // If xAxis and yAxis declared, grid is created by default.
  16519. // grid: {},
  16520. textStyle: {
  16521. // color: '#000',
  16522. // decoration: 'none',
  16523. // PENDING
  16524. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  16525. // fontFamily: 'Arial, Verdana, sans-serif',
  16526. fontSize: 12,
  16527. fontStyle: 'normal',
  16528. fontWeight: 'normal'
  16529. },
  16530. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  16531. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  16532. // Default is source-over
  16533. blendMode: null,
  16534. stateAnimation: {
  16535. duration: 300,
  16536. easing: 'cubicOut'
  16537. },
  16538. animation: 'auto',
  16539. animationDuration: 1000,
  16540. animationDurationUpdate: 500,
  16541. animationEasing: 'cubicInOut',
  16542. animationEasingUpdate: 'cubicInOut',
  16543. animationThreshold: 2000,
  16544. // Configuration for progressive/incremental rendering
  16545. progressiveThreshold: 3000,
  16546. progressive: 400,
  16547. // Threshold of if use single hover layer to optimize.
  16548. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  16549. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  16550. // which is unexpected.
  16551. // see example <echarts/test/heatmap-large.html>.
  16552. hoverLayerThreshold: 3000,
  16553. // See: module:echarts/scale/Time
  16554. useUTC: false
  16555. };
  16556. var VISUAL_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'itemGroupId', 'seriesName']);
  16557. var SOURCE_FORMAT_ORIGINAL = 'original';
  16558. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  16559. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  16560. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  16561. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  16562. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  16563. var SERIES_LAYOUT_BY_COLUMN = 'column';
  16564. var SERIES_LAYOUT_BY_ROW = 'row';
  16565. var BE_ORDINAL = {
  16566. Must: 1,
  16567. Might: 2,
  16568. Not: 3 // Other cases
  16569. };
  16570. var innerGlobalModel = makeInner();
  16571. /**
  16572. * MUST be called before mergeOption of all series.
  16573. */
  16574. function resetSourceDefaulter(ecModel) {
  16575. // `datasetMap` is used to make default encode.
  16576. innerGlobalModel(ecModel).datasetMap = createHashMap();
  16577. }
  16578. /**
  16579. * [The strategy of the arrengment of data dimensions for dataset]:
  16580. * "value way": all axes are non-category axes. So series one by one take
  16581. * several (the number is coordSysDims.length) dimensions from dataset.
  16582. * The result of data arrengment of data dimensions like:
  16583. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  16584. * "category way": at least one axis is category axis. So the the first data
  16585. * dimension is always mapped to the first category axis and shared by
  16586. * all of the series. The other data dimensions are taken by series like
  16587. * "value way" does.
  16588. * The result of data arrengment of data dimensions like:
  16589. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  16590. *
  16591. * @return encode Never be `null/undefined`.
  16592. */
  16593. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  16594. var encode = {};
  16595. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
  16596. if (!datasetModel || !coordDimensions) {
  16597. return encode;
  16598. }
  16599. var encodeItemName = [];
  16600. var encodeSeriesName = [];
  16601. var ecModel = seriesModel.ecModel;
  16602. var datasetMap = innerGlobalModel(ecModel).datasetMap;
  16603. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  16604. var baseCategoryDimIndex;
  16605. var categoryWayValueDimStart;
  16606. coordDimensions = coordDimensions.slice();
  16607. each(coordDimensions, function (coordDimInfoLoose, coordDimIdx) {
  16608. var coordDimInfo = isObject(coordDimInfoLoose) ? coordDimInfoLoose : coordDimensions[coordDimIdx] = {
  16609. name: coordDimInfoLoose
  16610. };
  16611. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  16612. baseCategoryDimIndex = coordDimIdx;
  16613. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimInfo);
  16614. }
  16615. encode[coordDimInfo.name] = [];
  16616. });
  16617. var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
  16618. categoryWayDim: categoryWayValueDimStart,
  16619. valueWayDim: 0
  16620. }); // TODO
  16621. // Auto detect first time axis and do arrangement.
  16622. each(coordDimensions, function (coordDimInfo, coordDimIdx) {
  16623. var coordDimName = coordDimInfo.name;
  16624. var count = getDataDimCountOnCoordDim(coordDimInfo); // In value way.
  16625. if (baseCategoryDimIndex == null) {
  16626. var start = datasetRecord.valueWayDim;
  16627. pushDim(encode[coordDimName], start, count);
  16628. pushDim(encodeSeriesName, start, count);
  16629. datasetRecord.valueWayDim += count; // ??? TODO give a better default series name rule?
  16630. // especially when encode x y specified.
  16631. // consider: when mutiple series share one dimension
  16632. // category axis, series name should better use
  16633. // the other dimsion name. On the other hand, use
  16634. // both dimensions name.
  16635. } // In category way, the first category axis.
  16636. else if (baseCategoryDimIndex === coordDimIdx) {
  16637. pushDim(encode[coordDimName], 0, count);
  16638. pushDim(encodeItemName, 0, count);
  16639. } // In category way, the other axis.
  16640. else {
  16641. var start = datasetRecord.categoryWayDim;
  16642. pushDim(encode[coordDimName], start, count);
  16643. pushDim(encodeSeriesName, start, count);
  16644. datasetRecord.categoryWayDim += count;
  16645. }
  16646. });
  16647. function pushDim(dimIdxArr, idxFrom, idxCount) {
  16648. for (var i = 0; i < idxCount; i++) {
  16649. dimIdxArr.push(idxFrom + i);
  16650. }
  16651. }
  16652. function getDataDimCountOnCoordDim(coordDimInfo) {
  16653. var dimsDef = coordDimInfo.dimsDef;
  16654. return dimsDef ? dimsDef.length : 1;
  16655. }
  16656. encodeItemName.length && (encode.itemName = encodeItemName);
  16657. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  16658. return encode;
  16659. }
  16660. /**
  16661. * Work for data like [{name: ..., value: ...}, ...].
  16662. *
  16663. * @return encode Never be `null/undefined`.
  16664. */
  16665. function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
  16666. var encode = {};
  16667. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
  16668. if (!datasetModel) {
  16669. return encode;
  16670. }
  16671. var sourceFormat = source.sourceFormat;
  16672. var dimensionsDefine = source.dimensionsDefine;
  16673. var potentialNameDimIndex;
  16674. if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  16675. each(dimensionsDefine, function (dim, idx) {
  16676. if ((isObject(dim) ? dim.name : dim) === 'name') {
  16677. potentialNameDimIndex = idx;
  16678. }
  16679. });
  16680. }
  16681. var idxResult = function () {
  16682. var idxRes0 = {};
  16683. var idxRes1 = {};
  16684. var guessRecords = []; // 5 is an experience value.
  16685. for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
  16686. var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i);
  16687. guessRecords.push(guessResult);
  16688. var isPureNumber = guessResult === BE_ORDINAL.Not; // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
  16689. // and then find a name dim with the priority:
  16690. // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
  16691. if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
  16692. idxRes0.v = i;
  16693. }
  16694. if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) {
  16695. idxRes0.n = i;
  16696. }
  16697. if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
  16698. return idxRes0;
  16699. } // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
  16700. // find the first BE_ORDINAL.Might as the value dim,
  16701. // and then find a name dim with the priority:
  16702. // "other dim" > "the value dim itself".
  16703. // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
  16704. // treated as number.
  16705. if (!isPureNumber) {
  16706. if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
  16707. idxRes1.v = i;
  16708. }
  16709. if (idxRes1.n == null || idxRes1.n === idxRes1.v) {
  16710. idxRes1.n = i;
  16711. }
  16712. }
  16713. }
  16714. function fulfilled(idxResult) {
  16715. return idxResult.v != null && idxResult.n != null;
  16716. }
  16717. return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
  16718. }();
  16719. if (idxResult) {
  16720. encode.value = [idxResult.v]; // `potentialNameDimIndex` has highest priority.
  16721. var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n; // By default, label use itemName in charts.
  16722. // So we dont set encodeLabel here.
  16723. encode.itemName = [nameDimIndex];
  16724. encode.seriesName = [nameDimIndex];
  16725. }
  16726. return encode;
  16727. }
  16728. /**
  16729. * @return If return null/undefined, indicate that should not use datasetModel.
  16730. */
  16731. function querySeriesUpstreamDatasetModel(seriesModel) {
  16732. // Caution: consider the scenario:
  16733. // A dataset is declared and a series is not expected to use the dataset,
  16734. // and at the beginning `setOption({series: { noData })` (just prepare other
  16735. // option but no data), then `setOption({series: {data: [...]}); In this case,
  16736. // the user should set an empty array to avoid that dataset is used by default.
  16737. var thisData = seriesModel.get('data', true);
  16738. if (!thisData) {
  16739. return queryReferringComponents(seriesModel.ecModel, 'dataset', {
  16740. index: seriesModel.get('datasetIndex', true),
  16741. id: seriesModel.get('datasetId', true)
  16742. }, SINGLE_REFERRING).models[0];
  16743. }
  16744. }
  16745. /**
  16746. * @return Always return an array event empty.
  16747. */
  16748. function queryDatasetUpstreamDatasetModels(datasetModel) {
  16749. // Only these attributes declared, we by defualt reference to `datasetIndex: 0`.
  16750. // Otherwise, no reference.
  16751. if (!datasetModel.get('transform', true) && !datasetModel.get('fromTransformResult', true)) {
  16752. return [];
  16753. }
  16754. return queryReferringComponents(datasetModel.ecModel, 'dataset', {
  16755. index: datasetModel.get('fromDatasetIndex', true),
  16756. id: datasetModel.get('fromDatasetId', true)
  16757. }, SINGLE_REFERRING).models;
  16758. }
  16759. /**
  16760. * The rule should not be complex, otherwise user might not
  16761. * be able to known where the data is wrong.
  16762. * The code is ugly, but how to make it neat?
  16763. */
  16764. function guessOrdinal(source, dimIndex) {
  16765. return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
  16766. } // dimIndex may be overflow source data.
  16767. // return {BE_ORDINAL}
  16768. function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
  16769. var result; // Experience value.
  16770. var maxLoop = 5;
  16771. if (isTypedArray(data)) {
  16772. return BE_ORDINAL.Not;
  16773. } // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  16774. // always exists in source.
  16775. var dimName;
  16776. var dimType;
  16777. if (dimensionsDefine) {
  16778. var dimDefItem = dimensionsDefine[dimIndex];
  16779. if (isObject(dimDefItem)) {
  16780. dimName = dimDefItem.name;
  16781. dimType = dimDefItem.type;
  16782. } else if (isString(dimDefItem)) {
  16783. dimName = dimDefItem;
  16784. }
  16785. }
  16786. if (dimType != null) {
  16787. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  16788. }
  16789. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  16790. var dataArrayRows = data;
  16791. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  16792. var sample = dataArrayRows[dimIndex];
  16793. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  16794. if ((result = detectValue(sample[startIndex + i])) != null) {
  16795. return result;
  16796. }
  16797. }
  16798. } else {
  16799. for (var i = 0; i < dataArrayRows.length && i < maxLoop; i++) {
  16800. var row = dataArrayRows[startIndex + i];
  16801. if (row && (result = detectValue(row[dimIndex])) != null) {
  16802. return result;
  16803. }
  16804. }
  16805. }
  16806. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  16807. var dataObjectRows = data;
  16808. if (!dimName) {
  16809. return BE_ORDINAL.Not;
  16810. }
  16811. for (var i = 0; i < dataObjectRows.length && i < maxLoop; i++) {
  16812. var item = dataObjectRows[i];
  16813. if (item && (result = detectValue(item[dimName])) != null) {
  16814. return result;
  16815. }
  16816. }
  16817. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  16818. var dataKeyedColumns = data;
  16819. if (!dimName) {
  16820. return BE_ORDINAL.Not;
  16821. }
  16822. var sample = dataKeyedColumns[dimName];
  16823. if (!sample || isTypedArray(sample)) {
  16824. return BE_ORDINAL.Not;
  16825. }
  16826. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  16827. if ((result = detectValue(sample[i])) != null) {
  16828. return result;
  16829. }
  16830. }
  16831. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  16832. var dataOriginal = data;
  16833. for (var i = 0; i < dataOriginal.length && i < maxLoop; i++) {
  16834. var item = dataOriginal[i];
  16835. var val = getDataItemValue(item);
  16836. if (!isArray(val)) {
  16837. return BE_ORDINAL.Not;
  16838. }
  16839. if ((result = detectValue(val[dimIndex])) != null) {
  16840. return result;
  16841. }
  16842. }
  16843. }
  16844. function detectValue(val) {
  16845. var beStr = isString(val); // Consider usage convenience, '1', '2' will be treated as "number".
  16846. // `isFinit('')` get `true`.
  16847. if (val != null && isFinite(val) && val !== '') {
  16848. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  16849. } else if (beStr && val !== '-') {
  16850. return BE_ORDINAL.Must;
  16851. }
  16852. }
  16853. return BE_ORDINAL.Not;
  16854. }
  16855. var internalOptionCreatorMap = createHashMap();
  16856. function registerInternalOptionCreator(mainType, creator) {
  16857. assert(internalOptionCreatorMap.get(mainType) == null && creator);
  16858. internalOptionCreatorMap.set(mainType, creator);
  16859. }
  16860. function concatInternalOptions(ecModel, mainType, newCmptOptionList) {
  16861. var internalOptionCreator = internalOptionCreatorMap.get(mainType);
  16862. if (!internalOptionCreator) {
  16863. return newCmptOptionList;
  16864. }
  16865. var internalOptions = internalOptionCreator(ecModel);
  16866. if (!internalOptions) {
  16867. return newCmptOptionList;
  16868. }
  16869. if ("development" !== 'production') {
  16870. for (var i = 0; i < internalOptions.length; i++) {
  16871. assert(isComponentIdInternal(internalOptions[i]));
  16872. }
  16873. }
  16874. return newCmptOptionList.concat(internalOptions);
  16875. }
  16876. var innerColor = makeInner();
  16877. var innerDecal = makeInner();
  16878. var PaletteMixin =
  16879. /** @class */
  16880. function () {
  16881. function PaletteMixin() {}
  16882. PaletteMixin.prototype.getColorFromPalette = function (name, scope, requestNum) {
  16883. var defaultPalette = normalizeToArray(this.get('color', true));
  16884. var layeredPalette = this.get('colorLayer', true);
  16885. return getFromPalette(this, innerColor, defaultPalette, layeredPalette, name, scope, requestNum);
  16886. };
  16887. PaletteMixin.prototype.clearColorPalette = function () {
  16888. clearPalette(this, innerColor);
  16889. };
  16890. return PaletteMixin;
  16891. }();
  16892. function getDecalFromPalette(ecModel, name, scope, requestNum) {
  16893. var defaultDecals = normalizeToArray(ecModel.get(['aria', 'decal', 'decals']));
  16894. return getFromPalette(ecModel, innerDecal, defaultDecals, null, name, scope, requestNum);
  16895. }
  16896. function getNearestPalette(palettes, requestColorNum) {
  16897. var paletteNum = palettes.length; // TODO palettes must be in order
  16898. for (var i = 0; i < paletteNum; i++) {
  16899. if (palettes[i].length > requestColorNum) {
  16900. return palettes[i];
  16901. }
  16902. }
  16903. return palettes[paletteNum - 1];
  16904. }
  16905. /**
  16906. * @param name MUST NOT be null/undefined. Otherwise call this function
  16907. * twise with the same parameters will get different result.
  16908. * @param scope default this.
  16909. * @return Can be null/undefined
  16910. */
  16911. function getFromPalette(that, inner, defaultPalette, layeredPalette, name, scope, requestNum) {
  16912. scope = scope || that;
  16913. var scopeFields = inner(scope);
  16914. var paletteIdx = scopeFields.paletteIdx || 0;
  16915. var paletteNameMap = scopeFields.paletteNameMap = scopeFields.paletteNameMap || {}; // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  16916. if (paletteNameMap.hasOwnProperty(name)) {
  16917. return paletteNameMap[name];
  16918. }
  16919. var palette = requestNum == null || !layeredPalette ? defaultPalette : getNearestPalette(layeredPalette, requestNum); // In case can't find in layered color palette.
  16920. palette = palette || defaultPalette;
  16921. if (!palette || !palette.length) {
  16922. return;
  16923. }
  16924. var pickedPaletteItem = palette[paletteIdx];
  16925. if (name) {
  16926. paletteNameMap[name] = pickedPaletteItem;
  16927. }
  16928. scopeFields.paletteIdx = (paletteIdx + 1) % palette.length;
  16929. return pickedPaletteItem;
  16930. }
  16931. function clearPalette(that, inner) {
  16932. inner(that).paletteIdx = 0;
  16933. inner(that).paletteNameMap = {};
  16934. }
  16935. // Internal method names:
  16936. // -----------------------
  16937. var reCreateSeriesIndices;
  16938. var assertSeriesInitialized;
  16939. var initBase;
  16940. var OPTION_INNER_KEY = '\0_ec_inner';
  16941. var OPTION_INNER_VALUE = 1;
  16942. var BUITIN_COMPONENTS_MAP = {
  16943. grid: 'GridComponent',
  16944. polar: 'PolarComponent',
  16945. geo: 'GeoComponent',
  16946. singleAxis: 'SingleAxisComponent',
  16947. parallel: 'ParallelComponent',
  16948. calendar: 'CalendarComponent',
  16949. graphic: 'GraphicComponent',
  16950. toolbox: 'ToolboxComponent',
  16951. tooltip: 'TooltipComponent',
  16952. axisPointer: 'AxisPointerComponent',
  16953. brush: 'BrushComponent',
  16954. title: 'TitleComponent',
  16955. timeline: 'TimelineComponent',
  16956. markPoint: 'MarkPointComponent',
  16957. markLine: 'MarkLineComponent',
  16958. markArea: 'MarkAreaComponent',
  16959. legend: 'LegendComponent',
  16960. dataZoom: 'DataZoomComponent',
  16961. visualMap: 'VisualMapComponent',
  16962. // aria: 'AriaComponent',
  16963. // dataset: 'DatasetComponent',
  16964. // Dependencies
  16965. xAxis: 'GridComponent',
  16966. yAxis: 'GridComponent',
  16967. angleAxis: 'PolarComponent',
  16968. radiusAxis: 'PolarComponent'
  16969. };
  16970. var BUILTIN_CHARTS_MAP = {
  16971. line: 'LineChart',
  16972. bar: 'BarChart',
  16973. pie: 'PieChart',
  16974. scatter: 'ScatterChart',
  16975. radar: 'RadarChart',
  16976. map: 'MapChart',
  16977. tree: 'TreeChart',
  16978. treemap: 'TreemapChart',
  16979. graph: 'GraphChart',
  16980. gauge: 'GaugeChart',
  16981. funnel: 'FunnelChart',
  16982. parallel: 'ParallelChart',
  16983. sankey: 'SankeyChart',
  16984. boxplot: 'BoxplotChart',
  16985. candlestick: 'CandlestickChart',
  16986. effectScatter: 'EffectScatterChart',
  16987. lines: 'LinesChart',
  16988. heatmap: 'HeatmapChart',
  16989. pictorialBar: 'PictorialBarChart',
  16990. themeRiver: 'ThemeRiverChart',
  16991. sunburst: 'SunburstChart',
  16992. custom: 'CustomChart'
  16993. };
  16994. var componetsMissingLogPrinted = {};
  16995. function checkMissingComponents(option) {
  16996. each(option, function (componentOption, mainType) {
  16997. if (!ComponentModel.hasClass(mainType)) {
  16998. var componentImportName = BUITIN_COMPONENTS_MAP[mainType];
  16999. if (componentImportName && !componetsMissingLogPrinted[componentImportName]) {
  17000. error("Component " + mainType + " is used but not imported.\nimport { " + componentImportName + " } from 'echarts/components';\necharts.use([" + componentImportName + "]);");
  17001. componetsMissingLogPrinted[componentImportName] = true;
  17002. }
  17003. }
  17004. });
  17005. }
  17006. var GlobalModel =
  17007. /** @class */
  17008. function (_super) {
  17009. __extends(GlobalModel, _super);
  17010. function GlobalModel() {
  17011. return _super !== null && _super.apply(this, arguments) || this;
  17012. }
  17013. GlobalModel.prototype.init = function (option, parentModel, ecModel, theme, locale, optionManager) {
  17014. theme = theme || {};
  17015. this.option = null; // Mark as not initialized.
  17016. this._theme = new Model(theme);
  17017. this._locale = new Model(locale);
  17018. this._optionManager = optionManager;
  17019. };
  17020. GlobalModel.prototype.setOption = function (option, opts, optionPreprocessorFuncs) {
  17021. if ("development" !== 'production') {
  17022. assert(option != null, 'option is null/undefined');
  17023. assert(option[OPTION_INNER_KEY] !== OPTION_INNER_VALUE, 'please use chart.getOption()');
  17024. }
  17025. var innerOpt = normalizeSetOptionInput(opts);
  17026. this._optionManager.setOption(option, optionPreprocessorFuncs, innerOpt);
  17027. this._resetOption(null, innerOpt);
  17028. };
  17029. /**
  17030. * @param type null/undefined: reset all.
  17031. * 'recreate': force recreate all.
  17032. * 'timeline': only reset timeline option
  17033. * 'media': only reset media query option
  17034. * @return Whether option changed.
  17035. */
  17036. GlobalModel.prototype.resetOption = function (type, opt) {
  17037. return this._resetOption(type, normalizeSetOptionInput(opt));
  17038. };
  17039. GlobalModel.prototype._resetOption = function (type, opt) {
  17040. var optionChanged = false;
  17041. var optionManager = this._optionManager;
  17042. if (!type || type === 'recreate') {
  17043. var baseOption = optionManager.mountOption(type === 'recreate');
  17044. if ("development" !== 'production') {
  17045. checkMissingComponents(baseOption);
  17046. }
  17047. if (!this.option || type === 'recreate') {
  17048. initBase(this, baseOption);
  17049. } else {
  17050. this.restoreData();
  17051. this._mergeOption(baseOption, opt);
  17052. }
  17053. optionChanged = true;
  17054. }
  17055. if (type === 'timeline' || type === 'media') {
  17056. this.restoreData();
  17057. } // By design, if `setOption(option2)` at the second time, and `option2` is a `ECUnitOption`,
  17058. // it should better not have the same props with `MediaUnit['option']`.
  17059. // Becuase either `option2` or `MediaUnit['option']` will be always merged to "current option"
  17060. // rather than original "baseOption". If they both override a prop, the result might be
  17061. // unexpected when media state changed after `setOption` called.
  17062. // If we really need to modify a props in each `MediaUnit['option']`, use the full version
  17063. // (`{baseOption, media}`) in `setOption`.
  17064. // For `timeline`, the case is the same.
  17065. if (!type || type === 'recreate' || type === 'timeline') {
  17066. var timelineOption = optionManager.getTimelineOption(this);
  17067. if (timelineOption) {
  17068. optionChanged = true;
  17069. this._mergeOption(timelineOption, opt);
  17070. }
  17071. }
  17072. if (!type || type === 'recreate' || type === 'media') {
  17073. var mediaOptions = optionManager.getMediaOption(this);
  17074. if (mediaOptions.length) {
  17075. each(mediaOptions, function (mediaOption) {
  17076. optionChanged = true;
  17077. this._mergeOption(mediaOption, opt);
  17078. }, this);
  17079. }
  17080. }
  17081. return optionChanged;
  17082. };
  17083. GlobalModel.prototype.mergeOption = function (option) {
  17084. this._mergeOption(option, null);
  17085. };
  17086. GlobalModel.prototype._mergeOption = function (newOption, opt) {
  17087. var option = this.option;
  17088. var componentsMap = this._componentsMap;
  17089. var componentsCount = this._componentsCount;
  17090. var newCmptTypes = [];
  17091. var newCmptTypeMap = createHashMap();
  17092. var replaceMergeMainTypeMap = opt && opt.replaceMergeMainTypeMap;
  17093. resetSourceDefaulter(this); // If no component class, merge directly.
  17094. // For example: color, animaiton options, etc.
  17095. each(newOption, function (componentOption, mainType) {
  17096. if (componentOption == null) {
  17097. return;
  17098. }
  17099. if (!ComponentModel.hasClass(mainType)) {
  17100. // globalSettingTask.dirty();
  17101. option[mainType] = option[mainType] == null ? clone(componentOption) : merge(option[mainType], componentOption, true);
  17102. } else if (mainType) {
  17103. newCmptTypes.push(mainType);
  17104. newCmptTypeMap.set(mainType, true);
  17105. }
  17106. });
  17107. if (replaceMergeMainTypeMap) {
  17108. // If there is a mainType `xxx` in `replaceMerge` but not declared in option,
  17109. // we trade it as it is declared in option as `{xxx: []}`. Because:
  17110. // (1) for normal merge, `{xxx: null/undefined}` are the same meaning as `{xxx: []}`.
  17111. // (2) some preprocessor may convert some of `{xxx: null/undefined}` to `{xxx: []}`.
  17112. replaceMergeMainTypeMap.each(function (val, mainTypeInReplaceMerge) {
  17113. if (ComponentModel.hasClass(mainTypeInReplaceMerge) && !newCmptTypeMap.get(mainTypeInReplaceMerge)) {
  17114. newCmptTypes.push(mainTypeInReplaceMerge);
  17115. newCmptTypeMap.set(mainTypeInReplaceMerge, true);
  17116. }
  17117. });
  17118. }
  17119. ComponentModel.topologicalTravel(newCmptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this);
  17120. function visitComponent(mainType) {
  17121. var newCmptOptionList = concatInternalOptions(this, mainType, normalizeToArray(newOption[mainType]));
  17122. var oldCmptList = componentsMap.get(mainType);
  17123. var mergeMode = // `!oldCmptList` means init. See the comment in `mappingToExists`
  17124. !oldCmptList ? 'replaceAll' : replaceMergeMainTypeMap && replaceMergeMainTypeMap.get(mainType) ? 'replaceMerge' : 'normalMerge';
  17125. var mappingResult = mappingToExists(oldCmptList, newCmptOptionList, mergeMode); // Set mainType and complete subType.
  17126. setComponentTypeToKeyInfo(mappingResult, mainType, ComponentModel); // Empty it before the travel, in order to prevent `this._componentsMap`
  17127. // from being used in the `init`/`mergeOption`/`optionUpdated` of some
  17128. // components, which is probably incorrect logic.
  17129. option[mainType] = null;
  17130. componentsMap.set(mainType, null);
  17131. componentsCount.set(mainType, 0);
  17132. var optionsByMainType = [];
  17133. var cmptsByMainType = [];
  17134. var cmptsCountByMainType = 0;
  17135. each(mappingResult, function (resultItem, index) {
  17136. var componentModel = resultItem.existing;
  17137. var newCmptOption = resultItem.newOption;
  17138. if (!newCmptOption) {
  17139. if (componentModel) {
  17140. // Consider where is no new option and should be merged using {},
  17141. // see removeEdgeAndAdd in topologicalTravel and
  17142. // ComponentModel.getAllClassMainTypes.
  17143. componentModel.mergeOption({}, this);
  17144. componentModel.optionUpdated({}, false);
  17145. } // If no both `resultItem.exist` and `resultItem.option`,
  17146. // either it is in `replaceMerge` and not matched by any id,
  17147. // or it has been removed in previous `replaceMerge` and left a "hole" in this component index.
  17148. } else {
  17149. var isSeriesType = mainType === 'series';
  17150. var ComponentModelClass = ComponentModel.getClass(mainType, resultItem.keyInfo.subType, !isSeriesType // Give a more detailed warn later if series don't exists
  17151. );
  17152. if (!ComponentModelClass) {
  17153. if ("development" !== 'production') {
  17154. var subType = resultItem.keyInfo.subType;
  17155. var seriesImportName = BUILTIN_CHARTS_MAP[subType];
  17156. if (!componetsMissingLogPrinted[subType]) {
  17157. componetsMissingLogPrinted[subType] = true;
  17158. if (seriesImportName) {
  17159. error("Series " + subType + " is used but not imported.\nimport { " + seriesImportName + " } from 'echarts/charts';\necharts.use([" + seriesImportName + "]);");
  17160. } else {
  17161. error("Unkown series " + subType);
  17162. }
  17163. }
  17164. }
  17165. return;
  17166. }
  17167. if (componentModel && componentModel.constructor === ComponentModelClass) {
  17168. componentModel.name = resultItem.keyInfo.name; // componentModel.settingTask && componentModel.settingTask.dirty();
  17169. componentModel.mergeOption(newCmptOption, this);
  17170. componentModel.optionUpdated(newCmptOption, false);
  17171. } else {
  17172. // PENDING Global as parent ?
  17173. var extraOpt = extend({
  17174. componentIndex: index
  17175. }, resultItem.keyInfo);
  17176. componentModel = new ComponentModelClass(newCmptOption, this, this, extraOpt); // Assign `keyInfo`
  17177. extend(componentModel, extraOpt);
  17178. if (resultItem.brandNew) {
  17179. componentModel.__requireNewView = true;
  17180. }
  17181. componentModel.init(newCmptOption, this, this); // Call optionUpdated after init.
  17182. // newCmptOption has been used as componentModel.option
  17183. // and may be merged with theme and default, so pass null
  17184. // to avoid confusion.
  17185. componentModel.optionUpdated(null, true);
  17186. }
  17187. }
  17188. if (componentModel) {
  17189. optionsByMainType.push(componentModel.option);
  17190. cmptsByMainType.push(componentModel);
  17191. cmptsCountByMainType++;
  17192. } else {
  17193. // Always do assign to avoid elided item in array.
  17194. optionsByMainType.push(void 0);
  17195. cmptsByMainType.push(void 0);
  17196. }
  17197. }, this);
  17198. option[mainType] = optionsByMainType;
  17199. componentsMap.set(mainType, cmptsByMainType);
  17200. componentsCount.set(mainType, cmptsCountByMainType); // Backup series for filtering.
  17201. if (mainType === 'series') {
  17202. reCreateSeriesIndices(this);
  17203. }
  17204. } // If no series declared, ensure `_seriesIndices` initialized.
  17205. if (!this._seriesIndices) {
  17206. reCreateSeriesIndices(this);
  17207. }
  17208. };
  17209. /**
  17210. * Get option for output (cloned option and inner info removed)
  17211. */
  17212. GlobalModel.prototype.getOption = function () {
  17213. var option = clone(this.option);
  17214. each(option, function (optInMainType, mainType) {
  17215. if (ComponentModel.hasClass(mainType)) {
  17216. var opts = normalizeToArray(optInMainType); // Inner cmpts need to be removed.
  17217. // Inner cmpts might not be at last since ec5.0, but still
  17218. // compatible for users: if inner cmpt at last, splice the returned array.
  17219. var realLen = opts.length;
  17220. var metNonInner = false;
  17221. for (var i = realLen - 1; i >= 0; i--) {
  17222. // Remove options with inner id.
  17223. if (opts[i] && !isComponentIdInternal(opts[i])) {
  17224. metNonInner = true;
  17225. } else {
  17226. opts[i] = null;
  17227. !metNonInner && realLen--;
  17228. }
  17229. }
  17230. opts.length = realLen;
  17231. option[mainType] = opts;
  17232. }
  17233. });
  17234. delete option[OPTION_INNER_KEY];
  17235. return option;
  17236. };
  17237. GlobalModel.prototype.getTheme = function () {
  17238. return this._theme;
  17239. };
  17240. GlobalModel.prototype.getLocaleModel = function () {
  17241. return this._locale;
  17242. };
  17243. GlobalModel.prototype.setUpdatePayload = function (payload) {
  17244. this._payload = payload;
  17245. };
  17246. GlobalModel.prototype.getUpdatePayload = function () {
  17247. return this._payload;
  17248. };
  17249. /**
  17250. * @param idx If not specified, return the first one.
  17251. */
  17252. GlobalModel.prototype.getComponent = function (mainType, idx) {
  17253. var list = this._componentsMap.get(mainType);
  17254. if (list) {
  17255. var cmpt = list[idx || 0];
  17256. if (cmpt) {
  17257. return cmpt;
  17258. } else if (idx == null) {
  17259. for (var i = 0; i < list.length; i++) {
  17260. if (list[i]) {
  17261. return list[i];
  17262. }
  17263. }
  17264. }
  17265. }
  17266. };
  17267. /**
  17268. * @return Never be null/undefined.
  17269. */
  17270. GlobalModel.prototype.queryComponents = function (condition) {
  17271. var mainType = condition.mainType;
  17272. if (!mainType) {
  17273. return [];
  17274. }
  17275. var index = condition.index;
  17276. var id = condition.id;
  17277. var name = condition.name;
  17278. var cmpts = this._componentsMap.get(mainType);
  17279. if (!cmpts || !cmpts.length) {
  17280. return [];
  17281. }
  17282. var result;
  17283. if (index != null) {
  17284. result = [];
  17285. each(normalizeToArray(index), function (idx) {
  17286. cmpts[idx] && result.push(cmpts[idx]);
  17287. });
  17288. } else if (id != null) {
  17289. result = queryByIdOrName('id', id, cmpts);
  17290. } else if (name != null) {
  17291. result = queryByIdOrName('name', name, cmpts);
  17292. } else {
  17293. // Return all non-empty components in that mainType
  17294. result = filter(cmpts, function (cmpt) {
  17295. return !!cmpt;
  17296. });
  17297. }
  17298. return filterBySubType(result, condition);
  17299. };
  17300. /**
  17301. * The interface is different from queryComponents,
  17302. * which is convenient for inner usage.
  17303. *
  17304. * @usage
  17305. * let result = findComponents(
  17306. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  17307. * );
  17308. * let result = findComponents(
  17309. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  17310. * );
  17311. * let result = findComponents(
  17312. * {mainType: 'series',
  17313. * filter: function (model, index) {...}}
  17314. * );
  17315. * // result like [component0, componnet1, ...]
  17316. */
  17317. GlobalModel.prototype.findComponents = function (condition) {
  17318. var query = condition.query;
  17319. var mainType = condition.mainType;
  17320. var queryCond = getQueryCond(query);
  17321. var result = queryCond ? this.queryComponents(queryCond) // Retrieve all non-empty components.
  17322. : filter(this._componentsMap.get(mainType), function (cmpt) {
  17323. return !!cmpt;
  17324. });
  17325. return doFilter(filterBySubType(result, condition));
  17326. function getQueryCond(q) {
  17327. var indexAttr = mainType + 'Index';
  17328. var idAttr = mainType + 'Id';
  17329. var nameAttr = mainType + 'Name';
  17330. return q && (q[indexAttr] != null || q[idAttr] != null || q[nameAttr] != null) ? {
  17331. mainType: mainType,
  17332. // subType will be filtered finally.
  17333. index: q[indexAttr],
  17334. id: q[idAttr],
  17335. name: q[nameAttr]
  17336. } : null;
  17337. }
  17338. function doFilter(res) {
  17339. return condition.filter ? filter(res, condition.filter) : res;
  17340. }
  17341. };
  17342. GlobalModel.prototype.eachComponent = function (mainType, cb, context) {
  17343. var componentsMap = this._componentsMap;
  17344. if (isFunction(mainType)) {
  17345. var ctxForAll_1 = cb;
  17346. var cbForAll_1 = mainType;
  17347. componentsMap.each(function (cmpts, componentType) {
  17348. for (var i = 0; cmpts && i < cmpts.length; i++) {
  17349. var cmpt = cmpts[i];
  17350. cmpt && cbForAll_1.call(ctxForAll_1, componentType, cmpt, cmpt.componentIndex);
  17351. }
  17352. });
  17353. } else {
  17354. var cmpts = isString(mainType) ? componentsMap.get(mainType) : isObject(mainType) ? this.findComponents(mainType) : null;
  17355. for (var i = 0; cmpts && i < cmpts.length; i++) {
  17356. var cmpt = cmpts[i];
  17357. cmpt && cb.call(context, cmpt, cmpt.componentIndex);
  17358. }
  17359. }
  17360. };
  17361. /**
  17362. * Get series list before filtered by name.
  17363. */
  17364. GlobalModel.prototype.getSeriesByName = function (name) {
  17365. var nameStr = convertOptionIdName(name, null);
  17366. return filter(this._componentsMap.get('series'), function (oneSeries) {
  17367. return !!oneSeries && nameStr != null && oneSeries.name === nameStr;
  17368. });
  17369. };
  17370. /**
  17371. * Get series list before filtered by index.
  17372. */
  17373. GlobalModel.prototype.getSeriesByIndex = function (seriesIndex) {
  17374. return this._componentsMap.get('series')[seriesIndex];
  17375. };
  17376. /**
  17377. * Get series list before filtered by type.
  17378. * FIXME: rename to getRawSeriesByType?
  17379. */
  17380. GlobalModel.prototype.getSeriesByType = function (subType) {
  17381. return filter(this._componentsMap.get('series'), function (oneSeries) {
  17382. return !!oneSeries && oneSeries.subType === subType;
  17383. });
  17384. };
  17385. /**
  17386. * Get all series before filtered.
  17387. */
  17388. GlobalModel.prototype.getSeries = function () {
  17389. return filter(this._componentsMap.get('series'), function (oneSeries) {
  17390. return !!oneSeries;
  17391. });
  17392. };
  17393. /**
  17394. * Count series before filtered.
  17395. */
  17396. GlobalModel.prototype.getSeriesCount = function () {
  17397. return this._componentsCount.get('series');
  17398. };
  17399. /**
  17400. * After filtering, series may be different
  17401. * frome raw series.
  17402. */
  17403. GlobalModel.prototype.eachSeries = function (cb, context) {
  17404. assertSeriesInitialized(this);
  17405. each(this._seriesIndices, function (rawSeriesIndex) {
  17406. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17407. cb.call(context, series, rawSeriesIndex);
  17408. }, this);
  17409. };
  17410. /**
  17411. * Iterate raw series before filtered.
  17412. *
  17413. * @param {Function} cb
  17414. * @param {*} context
  17415. */
  17416. GlobalModel.prototype.eachRawSeries = function (cb, context) {
  17417. each(this._componentsMap.get('series'), function (series) {
  17418. series && cb.call(context, series, series.componentIndex);
  17419. });
  17420. };
  17421. /**
  17422. * After filtering, series may be different.
  17423. * frome raw series.
  17424. */
  17425. GlobalModel.prototype.eachSeriesByType = function (subType, cb, context) {
  17426. assertSeriesInitialized(this);
  17427. each(this._seriesIndices, function (rawSeriesIndex) {
  17428. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17429. if (series.subType === subType) {
  17430. cb.call(context, series, rawSeriesIndex);
  17431. }
  17432. }, this);
  17433. };
  17434. /**
  17435. * Iterate raw series before filtered of given type.
  17436. */
  17437. GlobalModel.prototype.eachRawSeriesByType = function (subType, cb, context) {
  17438. return each(this.getSeriesByType(subType), cb, context);
  17439. };
  17440. GlobalModel.prototype.isSeriesFiltered = function (seriesModel) {
  17441. assertSeriesInitialized(this);
  17442. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  17443. };
  17444. GlobalModel.prototype.getCurrentSeriesIndices = function () {
  17445. return (this._seriesIndices || []).slice();
  17446. };
  17447. GlobalModel.prototype.filterSeries = function (cb, context) {
  17448. assertSeriesInitialized(this);
  17449. var newSeriesIndices = [];
  17450. each(this._seriesIndices, function (seriesRawIdx) {
  17451. var series = this._componentsMap.get('series')[seriesRawIdx];
  17452. cb.call(context, series, seriesRawIdx) && newSeriesIndices.push(seriesRawIdx);
  17453. }, this);
  17454. this._seriesIndices = newSeriesIndices;
  17455. this._seriesIndicesMap = createHashMap(newSeriesIndices);
  17456. };
  17457. GlobalModel.prototype.restoreData = function (payload) {
  17458. reCreateSeriesIndices(this);
  17459. var componentsMap = this._componentsMap;
  17460. var componentTypes = [];
  17461. componentsMap.each(function (components, componentType) {
  17462. if (ComponentModel.hasClass(componentType)) {
  17463. componentTypes.push(componentType);
  17464. }
  17465. });
  17466. ComponentModel.topologicalTravel(componentTypes, ComponentModel.getAllClassMainTypes(), function (componentType) {
  17467. each(componentsMap.get(componentType), function (component) {
  17468. if (component && (componentType !== 'series' || !isNotTargetSeries(component, payload))) {
  17469. component.restoreData();
  17470. }
  17471. });
  17472. });
  17473. };
  17474. GlobalModel.internalField = function () {
  17475. reCreateSeriesIndices = function (ecModel) {
  17476. var seriesIndices = ecModel._seriesIndices = [];
  17477. each(ecModel._componentsMap.get('series'), function (series) {
  17478. // series may have been removed by `replaceMerge`.
  17479. series && seriesIndices.push(series.componentIndex);
  17480. });
  17481. ecModel._seriesIndicesMap = createHashMap(seriesIndices);
  17482. };
  17483. assertSeriesInitialized = function (ecModel) {
  17484. // Components that use _seriesIndices should depends on series component,
  17485. // which make sure that their initialization is after series.
  17486. if ("development" !== 'production') {
  17487. if (!ecModel._seriesIndices) {
  17488. throw new Error('Option should contains series.');
  17489. }
  17490. }
  17491. };
  17492. initBase = function (ecModel, baseOption) {
  17493. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  17494. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  17495. ecModel.option = {};
  17496. ecModel.option[OPTION_INNER_KEY] = OPTION_INNER_VALUE; // Init with series: [], in case of calling findSeries method
  17497. // before series initialized.
  17498. ecModel._componentsMap = createHashMap({
  17499. series: []
  17500. });
  17501. ecModel._componentsCount = createHashMap(); // If user spefied `option.aria`, aria will be enable. This detection should be
  17502. // performed before theme and globalDefault merge.
  17503. var airaOption = baseOption.aria;
  17504. if (isObject(airaOption) && airaOption.enabled == null) {
  17505. airaOption.enabled = true;
  17506. }
  17507. mergeTheme(baseOption, ecModel._theme.option); // TODO Needs clone when merging to the unexisted property
  17508. merge(baseOption, globalDefault, false);
  17509. ecModel._mergeOption(baseOption, null);
  17510. };
  17511. }();
  17512. return GlobalModel;
  17513. }(Model);
  17514. function isNotTargetSeries(seriesModel, payload) {
  17515. if (payload) {
  17516. var index = payload.seriesIndex;
  17517. var id = payload.seriesId;
  17518. var name_1 = payload.seriesName;
  17519. return index != null && seriesModel.componentIndex !== index || id != null && seriesModel.id !== id || name_1 != null && seriesModel.name !== name_1;
  17520. }
  17521. }
  17522. function mergeTheme(option, theme) {
  17523. // PENDING
  17524. // NOT use `colorLayer` in theme if option has `color`
  17525. var notMergeColorLayer = option.color && !option.colorLayer;
  17526. each(theme, function (themeItem, name) {
  17527. if (name === 'colorLayer' && notMergeColorLayer) {
  17528. return;
  17529. } // If it is component model mainType, the model handles that merge later.
  17530. // otherwise, merge them here.
  17531. if (!ComponentModel.hasClass(name)) {
  17532. if (typeof themeItem === 'object') {
  17533. option[name] = !option[name] ? clone(themeItem) : merge(option[name], themeItem, false);
  17534. } else {
  17535. if (option[name] == null) {
  17536. option[name] = themeItem;
  17537. }
  17538. }
  17539. }
  17540. });
  17541. }
  17542. function queryByIdOrName(attr, idOrName, cmpts) {
  17543. // Here is a break from echarts4: string and number are
  17544. // treated as equal.
  17545. if (isArray(idOrName)) {
  17546. var keyMap_1 = createHashMap();
  17547. each(idOrName, function (idOrNameItem) {
  17548. if (idOrNameItem != null) {
  17549. var idName = convertOptionIdName(idOrNameItem, null);
  17550. idName != null && keyMap_1.set(idOrNameItem, true);
  17551. }
  17552. });
  17553. return filter(cmpts, function (cmpt) {
  17554. return cmpt && keyMap_1.get(cmpt[attr]);
  17555. });
  17556. } else {
  17557. var idName_1 = convertOptionIdName(idOrName, null);
  17558. return filter(cmpts, function (cmpt) {
  17559. return cmpt && idName_1 != null && cmpt[attr] === idName_1;
  17560. });
  17561. }
  17562. }
  17563. function filterBySubType(components, condition) {
  17564. // Using hasOwnProperty for restrict. Consider
  17565. // subType is undefined in user payload.
  17566. return condition.hasOwnProperty('subType') ? filter(components, function (cmpt) {
  17567. return cmpt && cmpt.subType === condition.subType;
  17568. }) : components;
  17569. }
  17570. function normalizeSetOptionInput(opts) {
  17571. var replaceMergeMainTypeMap = createHashMap();
  17572. opts && each(normalizeToArray(opts.replaceMerge), function (mainType) {
  17573. if ("development" !== 'production') {
  17574. assert(ComponentModel.hasClass(mainType), '"' + mainType + '" is not valid component main type in "replaceMerge"');
  17575. }
  17576. replaceMergeMainTypeMap.set(mainType, true);
  17577. });
  17578. return {
  17579. replaceMergeMainTypeMap: replaceMergeMainTypeMap
  17580. };
  17581. }
  17582. mixin(GlobalModel, PaletteMixin);
  17583. var availableMethods = ['getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed', 'on', 'off', 'getDataURL', 'getConnectedDataURL', // 'getModel',
  17584. 'getOption', // 'getViewOfComponentModel',
  17585. // 'getViewOfSeriesModel',
  17586. 'getId', 'updateLabelLayout'];
  17587. var ExtensionAPI =
  17588. /** @class */
  17589. function () {
  17590. function ExtensionAPI(ecInstance) {
  17591. each(availableMethods, function (methodName) {
  17592. this[methodName] = bind(ecInstance[methodName], ecInstance);
  17593. }, this);
  17594. }
  17595. return ExtensionAPI;
  17596. }();
  17597. var coordinateSystemCreators = {};
  17598. var CoordinateSystemManager =
  17599. /** @class */
  17600. function () {
  17601. function CoordinateSystemManager() {
  17602. this._coordinateSystems = [];
  17603. }
  17604. CoordinateSystemManager.prototype.create = function (ecModel, api) {
  17605. var coordinateSystems = [];
  17606. each(coordinateSystemCreators, function (creater, type) {
  17607. var list = creater.create(ecModel, api);
  17608. coordinateSystems = coordinateSystems.concat(list || []);
  17609. });
  17610. this._coordinateSystems = coordinateSystems;
  17611. };
  17612. CoordinateSystemManager.prototype.update = function (ecModel, api) {
  17613. each(this._coordinateSystems, function (coordSys) {
  17614. coordSys.update && coordSys.update(ecModel, api);
  17615. });
  17616. };
  17617. CoordinateSystemManager.prototype.getCoordinateSystems = function () {
  17618. return this._coordinateSystems.slice();
  17619. };
  17620. CoordinateSystemManager.register = function (type, creator) {
  17621. coordinateSystemCreators[type] = creator;
  17622. };
  17623. CoordinateSystemManager.get = function (type) {
  17624. return coordinateSystemCreators[type];
  17625. };
  17626. return CoordinateSystemManager;
  17627. }();
  17628. var QUERY_REG = /^(min|max)?(.+)$/; // Key: mainType
  17629. // type FakeComponentsMap = HashMap<(MappingExistingItem & { subType: string })[]>;
  17630. /**
  17631. * TERM EXPLANATIONS:
  17632. * See `ECOption` and `ECUnitOption` in `src/util/types.ts`.
  17633. */
  17634. var OptionManager =
  17635. /** @class */
  17636. function () {
  17637. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  17638. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  17639. // rawOption cloned and backuped when timeline changed, which does no
  17640. // good to performance. What's more, that both timeline and setOption
  17641. // method supply 'notMerge' brings complex and some problems.
  17642. // Consider this case:
  17643. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  17644. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  17645. function OptionManager(api) {
  17646. this._timelineOptions = [];
  17647. this._mediaList = [];
  17648. /**
  17649. * -1, means default.
  17650. * empty means no media.
  17651. */
  17652. this._currentMediaIndices = [];
  17653. this._api = api;
  17654. }
  17655. OptionManager.prototype.setOption = function (rawOption, optionPreprocessorFuncs, opt) {
  17656. if (rawOption) {
  17657. // That set dat primitive is dangerous if user reuse the data when setOption again.
  17658. each(normalizeToArray(rawOption.series), function (series) {
  17659. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  17660. });
  17661. each(normalizeToArray(rawOption.dataset), function (dataset) {
  17662. dataset && dataset.source && isTypedArray(dataset.source) && setAsPrimitive(dataset.source);
  17663. });
  17664. } // Caution: some series modify option data, if do not clone,
  17665. // it should ensure that the repeat modify correctly
  17666. // (create a new object when modify itself).
  17667. rawOption = clone(rawOption); // FIXME
  17668. // If some property is set in timeline options or media option but
  17669. // not set in baseOption, a warning should be given.
  17670. var optionBackup = this._optionBackup;
  17671. var newParsedOption = parseRawOption(rawOption, optionPreprocessorFuncs, !optionBackup);
  17672. this._newBaseOption = newParsedOption.baseOption; // For setOption at second time (using merge mode);
  17673. if (optionBackup) {
  17674. // FIXME
  17675. // the restore merge solution is essentially incorrect.
  17676. // the mapping can not be 100% consistent with ecModel, which probably brings
  17677. // potential bug!
  17678. // The first merge is delayed, becuase in most cases, users do not call `setOption` twice.
  17679. // let fakeCmptsMap = this._fakeCmptsMap;
  17680. // if (!fakeCmptsMap) {
  17681. // fakeCmptsMap = this._fakeCmptsMap = createHashMap();
  17682. // mergeToBackupOption(fakeCmptsMap, null, optionBackup.baseOption, null);
  17683. // }
  17684. // mergeToBackupOption(
  17685. // fakeCmptsMap, optionBackup.baseOption, newParsedOption.baseOption, opt
  17686. // );
  17687. // For simplicity, timeline options and media options do not support merge,
  17688. // that is, if you `setOption` twice and both has timeline options, the latter
  17689. // timeline opitons will not be merged to the formers, but just substitude them.
  17690. if (newParsedOption.timelineOptions.length) {
  17691. optionBackup.timelineOptions = newParsedOption.timelineOptions;
  17692. }
  17693. if (newParsedOption.mediaList.length) {
  17694. optionBackup.mediaList = newParsedOption.mediaList;
  17695. }
  17696. if (newParsedOption.mediaDefault) {
  17697. optionBackup.mediaDefault = newParsedOption.mediaDefault;
  17698. }
  17699. } else {
  17700. this._optionBackup = newParsedOption;
  17701. }
  17702. };
  17703. OptionManager.prototype.mountOption = function (isRecreate) {
  17704. var optionBackup = this._optionBackup;
  17705. this._timelineOptions = optionBackup.timelineOptions;
  17706. this._mediaList = optionBackup.mediaList;
  17707. this._mediaDefault = optionBackup.mediaDefault;
  17708. this._currentMediaIndices = [];
  17709. return clone(isRecreate // this._optionBackup.baseOption, which is created at the first `setOption`
  17710. // called, and is merged into every new option by inner method `mergeToBackupOption`
  17711. // each time `setOption` called, can be only used in `isRecreate`, because
  17712. // its reliability is under suspicion. In other cases option merge is
  17713. // performed by `model.mergeOption`.
  17714. ? optionBackup.baseOption : this._newBaseOption);
  17715. };
  17716. OptionManager.prototype.getTimelineOption = function (ecModel) {
  17717. var option;
  17718. var timelineOptions = this._timelineOptions;
  17719. if (timelineOptions.length) {
  17720. // getTimelineOption can only be called after ecModel inited,
  17721. // so we can get currentIndex from timelineModel.
  17722. var timelineModel = ecModel.getComponent('timeline');
  17723. if (timelineModel) {
  17724. option = clone( // FIXME:TS as TimelineModel or quivlant interface
  17725. timelineOptions[timelineModel.getCurrentIndex()]);
  17726. }
  17727. }
  17728. return option;
  17729. };
  17730. OptionManager.prototype.getMediaOption = function (ecModel) {
  17731. var ecWidth = this._api.getWidth();
  17732. var ecHeight = this._api.getHeight();
  17733. var mediaList = this._mediaList;
  17734. var mediaDefault = this._mediaDefault;
  17735. var indices = [];
  17736. var result = []; // No media defined.
  17737. if (!mediaList.length && !mediaDefault) {
  17738. return result;
  17739. } // Multi media may be applied, the latter defined media has higher priority.
  17740. for (var i = 0, len = mediaList.length; i < len; i++) {
  17741. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  17742. indices.push(i);
  17743. }
  17744. } // FIXME
  17745. // Whether mediaDefault should force users to provide? Otherwise
  17746. // the change by media query can not be recorvered.
  17747. if (!indices.length && mediaDefault) {
  17748. indices = [-1];
  17749. }
  17750. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  17751. result = map(indices, function (index) {
  17752. return clone(index === -1 ? mediaDefault.option : mediaList[index].option);
  17753. });
  17754. } // Otherwise return nothing.
  17755. this._currentMediaIndices = indices;
  17756. return result;
  17757. };
  17758. return OptionManager;
  17759. }();
  17760. /**
  17761. * [RAW_OPTION_PATTERNS]
  17762. * (Note: "series: []" represents all other props in `ECUnitOption`)
  17763. *
  17764. * (1) No prop "baseOption" declared:
  17765. * Root option is used as "baseOption" (except prop "options" and "media").
  17766. * ```js
  17767. * option = {
  17768. * series: [],
  17769. * timeline: {},
  17770. * options: [],
  17771. * };
  17772. * option = {
  17773. * series: [],
  17774. * media: {},
  17775. * };
  17776. * option = {
  17777. * series: [],
  17778. * timeline: {},
  17779. * options: [],
  17780. * media: {},
  17781. * }
  17782. * ```
  17783. *
  17784. * (2) Prop "baseOption" declared:
  17785. * If "baseOption" declared, `ECUnitOption` props can only be declared
  17786. * inside "baseOption" except prop "timeline" (compat ec2).
  17787. * ```js
  17788. * option = {
  17789. * baseOption: {
  17790. * timeline: {},
  17791. * series: [],
  17792. * },
  17793. * options: []
  17794. * };
  17795. * option = {
  17796. * baseOption: {
  17797. * series: [],
  17798. * },
  17799. * media: []
  17800. * };
  17801. * option = {
  17802. * baseOption: {
  17803. * timeline: {},
  17804. * series: [],
  17805. * },
  17806. * options: []
  17807. * media: []
  17808. * };
  17809. * option = {
  17810. * // ec3 compat ec2: allow (only) `timeline` declared
  17811. * // outside baseOption. Keep this setting for compat.
  17812. * timeline: {},
  17813. * baseOption: {
  17814. * series: [],
  17815. * },
  17816. * options: [],
  17817. * media: []
  17818. * };
  17819. * ```
  17820. */
  17821. function parseRawOption( // `rawOption` May be modified
  17822. rawOption, optionPreprocessorFuncs, isNew) {
  17823. var mediaList = [];
  17824. var mediaDefault;
  17825. var baseOption;
  17826. var declaredBaseOption = rawOption.baseOption; // Compatible with ec2, [RAW_OPTION_PATTERNS] above.
  17827. var timelineOnRoot = rawOption.timeline;
  17828. var timelineOptionsOnRoot = rawOption.options;
  17829. var mediaOnRoot = rawOption.media;
  17830. var hasMedia = !!rawOption.media;
  17831. var hasTimeline = !!(timelineOptionsOnRoot || timelineOnRoot || declaredBaseOption && declaredBaseOption.timeline);
  17832. if (declaredBaseOption) {
  17833. baseOption = declaredBaseOption; // For merge option.
  17834. if (!baseOption.timeline) {
  17835. baseOption.timeline = timelineOnRoot;
  17836. }
  17837. } // For convenience, enable to use the root option as the `baseOption`:
  17838. // `{ ...normalOptionProps, media: [{ ... }, { ... }] }`
  17839. else {
  17840. if (hasTimeline || hasMedia) {
  17841. rawOption.options = rawOption.media = null;
  17842. }
  17843. baseOption = rawOption;
  17844. }
  17845. if (hasMedia) {
  17846. if (isArray(mediaOnRoot)) {
  17847. each(mediaOnRoot, function (singleMedia) {
  17848. if ("development" !== 'production') {
  17849. // Real case of wrong config.
  17850. if (singleMedia && !singleMedia.option && isObject(singleMedia.query) && isObject(singleMedia.query.option)) {
  17851. error('Illegal media option. Must be like { media: [ { query: {}, option: {} } ] }');
  17852. }
  17853. }
  17854. if (singleMedia && singleMedia.option) {
  17855. if (singleMedia.query) {
  17856. mediaList.push(singleMedia);
  17857. } else if (!mediaDefault) {
  17858. // Use the first media default.
  17859. mediaDefault = singleMedia;
  17860. }
  17861. }
  17862. });
  17863. } else {
  17864. if ("development" !== 'production') {
  17865. // Real case of wrong config.
  17866. error('Illegal media option. Must be an array. Like { media: [ {...}, {...} ] }');
  17867. }
  17868. }
  17869. }
  17870. doPreprocess(baseOption);
  17871. each(timelineOptionsOnRoot, function (option) {
  17872. return doPreprocess(option);
  17873. });
  17874. each(mediaList, function (media) {
  17875. return doPreprocess(media.option);
  17876. });
  17877. function doPreprocess(option) {
  17878. each(optionPreprocessorFuncs, function (preProcess) {
  17879. preProcess(option, isNew);
  17880. });
  17881. }
  17882. return {
  17883. baseOption: baseOption,
  17884. timelineOptions: timelineOptionsOnRoot || [],
  17885. mediaDefault: mediaDefault,
  17886. mediaList: mediaList
  17887. };
  17888. }
  17889. /**
  17890. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  17891. * Support: width, height, aspectRatio
  17892. * Can use max or min as prefix.
  17893. */
  17894. function applyMediaQuery(query, ecWidth, ecHeight) {
  17895. var realMap = {
  17896. width: ecWidth,
  17897. height: ecHeight,
  17898. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  17899. };
  17900. var applicatable = true;
  17901. each(query, function (value, attr) {
  17902. var matched = attr.match(QUERY_REG);
  17903. if (!matched || !matched[1] || !matched[2]) {
  17904. return;
  17905. }
  17906. var operator = matched[1];
  17907. var realAttr = matched[2].toLowerCase();
  17908. if (!compare(realMap[realAttr], value, operator)) {
  17909. applicatable = false;
  17910. }
  17911. });
  17912. return applicatable;
  17913. }
  17914. function compare(real, expect, operator) {
  17915. if (operator === 'min') {
  17916. return real >= expect;
  17917. } else if (operator === 'max') {
  17918. return real <= expect;
  17919. } else {
  17920. // Equals
  17921. return real === expect;
  17922. }
  17923. }
  17924. function indicesEquals(indices1, indices2) {
  17925. // indices is always order by asc and has only finite number.
  17926. return indices1.join(',') === indices2.join(',');
  17927. }
  17928. var each$2 = each;
  17929. var isObject$1 = isObject;
  17930. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  17931. function compatEC2ItemStyle(opt) {
  17932. var itemStyleOpt = opt && opt.itemStyle;
  17933. if (!itemStyleOpt) {
  17934. return;
  17935. }
  17936. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  17937. var styleName = POSSIBLE_STYLES[i];
  17938. var normalItemStyleOpt = itemStyleOpt.normal;
  17939. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  17940. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  17941. if ("development" !== 'production') {
  17942. deprecateReplaceLog("itemStyle.normal." + styleName, styleName);
  17943. }
  17944. opt[styleName] = opt[styleName] || {};
  17945. if (!opt[styleName].normal) {
  17946. opt[styleName].normal = normalItemStyleOpt[styleName];
  17947. } else {
  17948. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  17949. }
  17950. normalItemStyleOpt[styleName] = null;
  17951. }
  17952. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  17953. if ("development" !== 'production') {
  17954. deprecateReplaceLog("itemStyle.emphasis." + styleName, "emphasis." + styleName);
  17955. }
  17956. opt[styleName] = opt[styleName] || {};
  17957. if (!opt[styleName].emphasis) {
  17958. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  17959. } else {
  17960. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  17961. }
  17962. emphasisItemStyleOpt[styleName] = null;
  17963. }
  17964. }
  17965. }
  17966. function convertNormalEmphasis(opt, optType, useExtend) {
  17967. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  17968. var normalOpt = opt[optType].normal;
  17969. var emphasisOpt = opt[optType].emphasis;
  17970. if (normalOpt) {
  17971. if ("development" !== 'production') {
  17972. // eslint-disable-next-line max-len
  17973. deprecateLog("'normal' hierarchy in " + optType + " has been removed since 4.0. All style properties are configured in " + optType + " directly now.");
  17974. } // Timeline controlStyle has other properties besides normal and emphasis
  17975. if (useExtend) {
  17976. opt[optType].normal = opt[optType].emphasis = null;
  17977. defaults(opt[optType], normalOpt);
  17978. } else {
  17979. opt[optType] = normalOpt;
  17980. }
  17981. }
  17982. if (emphasisOpt) {
  17983. if ("development" !== 'production') {
  17984. deprecateLog(optType + ".emphasis has been changed to emphasis." + optType + " since 4.0");
  17985. }
  17986. opt.emphasis = opt.emphasis || {};
  17987. opt.emphasis[optType] = emphasisOpt; // Also compat the case user mix the style and focus together in ec3 style
  17988. // for example: { itemStyle: { normal: {}, emphasis: {focus, shadowBlur} } }
  17989. if (emphasisOpt.focus) {
  17990. opt.emphasis.focus = emphasisOpt.focus;
  17991. }
  17992. if (emphasisOpt.blurScope) {
  17993. opt.emphasis.blurScope = emphasisOpt.blurScope;
  17994. }
  17995. }
  17996. }
  17997. }
  17998. function removeEC3NormalStatus(opt) {
  17999. convertNormalEmphasis(opt, 'itemStyle');
  18000. convertNormalEmphasis(opt, 'lineStyle');
  18001. convertNormalEmphasis(opt, 'areaStyle');
  18002. convertNormalEmphasis(opt, 'label');
  18003. convertNormalEmphasis(opt, 'labelLine'); // treemap
  18004. convertNormalEmphasis(opt, 'upperLabel'); // graph
  18005. convertNormalEmphasis(opt, 'edgeLabel');
  18006. }
  18007. function compatTextStyle(opt, propName) {
  18008. // Check whether is not object (string\null\undefined ...)
  18009. var labelOptSingle = isObject$1(opt) && opt[propName];
  18010. var textStyle = isObject$1(labelOptSingle) && labelOptSingle.textStyle;
  18011. if (textStyle) {
  18012. if ("development" !== 'production') {
  18013. // eslint-disable-next-line max-len
  18014. deprecateLog("textStyle hierarchy in " + propName + " has been removed since 4.0. All textStyle properties are configured in " + propName + " directly now.");
  18015. }
  18016. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  18017. var textPropName = TEXT_STYLE_OPTIONS[i];
  18018. if (textStyle.hasOwnProperty(textPropName)) {
  18019. labelOptSingle[textPropName] = textStyle[textPropName];
  18020. }
  18021. }
  18022. }
  18023. }
  18024. function compatEC3CommonStyles(opt) {
  18025. if (opt) {
  18026. removeEC3NormalStatus(opt);
  18027. compatTextStyle(opt, 'label');
  18028. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  18029. }
  18030. }
  18031. function processSeries(seriesOpt) {
  18032. if (!isObject$1(seriesOpt)) {
  18033. return;
  18034. }
  18035. compatEC2ItemStyle(seriesOpt);
  18036. removeEC3NormalStatus(seriesOpt);
  18037. compatTextStyle(seriesOpt, 'label'); // treemap
  18038. compatTextStyle(seriesOpt, 'upperLabel'); // graph
  18039. compatTextStyle(seriesOpt, 'edgeLabel');
  18040. if (seriesOpt.emphasis) {
  18041. compatTextStyle(seriesOpt.emphasis, 'label'); // treemap
  18042. compatTextStyle(seriesOpt.emphasis, 'upperLabel'); // graph
  18043. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  18044. }
  18045. var markPoint = seriesOpt.markPoint;
  18046. if (markPoint) {
  18047. compatEC2ItemStyle(markPoint);
  18048. compatEC3CommonStyles(markPoint);
  18049. }
  18050. var markLine = seriesOpt.markLine;
  18051. if (markLine) {
  18052. compatEC2ItemStyle(markLine);
  18053. compatEC3CommonStyles(markLine);
  18054. }
  18055. var markArea = seriesOpt.markArea;
  18056. if (markArea) {
  18057. compatEC3CommonStyles(markArea);
  18058. }
  18059. var data = seriesOpt.data; // Break with ec3: if `setOption` again, there may be no `type` in option,
  18060. // then the backward compat based on option type will not be performed.
  18061. if (seriesOpt.type === 'graph') {
  18062. data = data || seriesOpt.nodes;
  18063. var edgeData = seriesOpt.links || seriesOpt.edges;
  18064. if (edgeData && !isTypedArray(edgeData)) {
  18065. for (var i = 0; i < edgeData.length; i++) {
  18066. compatEC3CommonStyles(edgeData[i]);
  18067. }
  18068. }
  18069. each(seriesOpt.categories, function (opt) {
  18070. removeEC3NormalStatus(opt);
  18071. });
  18072. }
  18073. if (data && !isTypedArray(data)) {
  18074. for (var i = 0; i < data.length; i++) {
  18075. compatEC3CommonStyles(data[i]);
  18076. }
  18077. } // mark point data
  18078. markPoint = seriesOpt.markPoint;
  18079. if (markPoint && markPoint.data) {
  18080. var mpData = markPoint.data;
  18081. for (var i = 0; i < mpData.length; i++) {
  18082. compatEC3CommonStyles(mpData[i]);
  18083. }
  18084. } // mark line data
  18085. markLine = seriesOpt.markLine;
  18086. if (markLine && markLine.data) {
  18087. var mlData = markLine.data;
  18088. for (var i = 0; i < mlData.length; i++) {
  18089. if (isArray(mlData[i])) {
  18090. compatEC3CommonStyles(mlData[i][0]);
  18091. compatEC3CommonStyles(mlData[i][1]);
  18092. } else {
  18093. compatEC3CommonStyles(mlData[i]);
  18094. }
  18095. }
  18096. } // Series
  18097. if (seriesOpt.type === 'gauge') {
  18098. compatTextStyle(seriesOpt, 'axisLabel');
  18099. compatTextStyle(seriesOpt, 'title');
  18100. compatTextStyle(seriesOpt, 'detail');
  18101. } else if (seriesOpt.type === 'treemap') {
  18102. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  18103. each(seriesOpt.levels, function (opt) {
  18104. removeEC3NormalStatus(opt);
  18105. });
  18106. } else if (seriesOpt.type === 'tree') {
  18107. removeEC3NormalStatus(seriesOpt.leaves);
  18108. } // sunburst starts from ec4, so it does not need to compat levels.
  18109. }
  18110. function toArr(o) {
  18111. return isArray(o) ? o : o ? [o] : [];
  18112. }
  18113. function toObj(o) {
  18114. return (isArray(o) ? o[0] : o) || {};
  18115. }
  18116. function globalCompatStyle(option, isTheme) {
  18117. each$2(toArr(option.series), function (seriesOpt) {
  18118. isObject$1(seriesOpt) && processSeries(seriesOpt);
  18119. });
  18120. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  18121. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  18122. each$2(axes, function (axisName) {
  18123. each$2(toArr(option[axisName]), function (axisOpt) {
  18124. if (axisOpt) {
  18125. compatTextStyle(axisOpt, 'axisLabel');
  18126. compatTextStyle(axisOpt.axisPointer, 'label');
  18127. }
  18128. });
  18129. });
  18130. each$2(toArr(option.parallel), function (parallelOpt) {
  18131. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  18132. compatTextStyle(parallelAxisDefault, 'axisLabel');
  18133. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  18134. });
  18135. each$2(toArr(option.calendar), function (calendarOpt) {
  18136. convertNormalEmphasis(calendarOpt, 'itemStyle');
  18137. compatTextStyle(calendarOpt, 'dayLabel');
  18138. compatTextStyle(calendarOpt, 'monthLabel');
  18139. compatTextStyle(calendarOpt, 'yearLabel');
  18140. }); // radar.name.textStyle
  18141. each$2(toArr(option.radar), function (radarOpt) {
  18142. compatTextStyle(radarOpt, 'name'); // Use axisName instead of name because component has name property
  18143. if (radarOpt.name && radarOpt.axisName == null) {
  18144. radarOpt.axisName = radarOpt.name;
  18145. delete radarOpt.name;
  18146. if ("development" !== 'production') {
  18147. deprecateLog('name property in radar component has been changed to axisName');
  18148. }
  18149. }
  18150. if (radarOpt.nameGap != null && radarOpt.axisNameGap == null) {
  18151. radarOpt.axisNameGap = radarOpt.nameGap;
  18152. delete radarOpt.nameGap;
  18153. if ("development" !== 'production') {
  18154. deprecateLog('nameGap property in radar component has been changed to axisNameGap');
  18155. }
  18156. }
  18157. });
  18158. each$2(toArr(option.geo), function (geoOpt) {
  18159. if (isObject$1(geoOpt)) {
  18160. compatEC3CommonStyles(geoOpt);
  18161. each$2(toArr(geoOpt.regions), function (regionObj) {
  18162. compatEC3CommonStyles(regionObj);
  18163. });
  18164. }
  18165. });
  18166. each$2(toArr(option.timeline), function (timelineOpt) {
  18167. compatEC3CommonStyles(timelineOpt);
  18168. convertNormalEmphasis(timelineOpt, 'label');
  18169. convertNormalEmphasis(timelineOpt, 'itemStyle');
  18170. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  18171. var data = timelineOpt.data;
  18172. isArray(data) && each(data, function (item) {
  18173. if (isObject(item)) {
  18174. convertNormalEmphasis(item, 'label');
  18175. convertNormalEmphasis(item, 'itemStyle');
  18176. }
  18177. });
  18178. });
  18179. each$2(toArr(option.toolbox), function (toolboxOpt) {
  18180. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  18181. each$2(toolboxOpt.feature, function (featureOpt) {
  18182. convertNormalEmphasis(featureOpt, 'iconStyle');
  18183. });
  18184. });
  18185. compatTextStyle(toObj(option.axisPointer), 'label');
  18186. compatTextStyle(toObj(option.tooltip).axisPointer, 'label'); // Clean logs
  18187. // storedLogs = {};
  18188. }
  18189. function get(opt, path) {
  18190. var pathArr = path.split(',');
  18191. var obj = opt;
  18192. for (var i = 0; i < pathArr.length; i++) {
  18193. obj = obj && obj[pathArr[i]];
  18194. if (obj == null) {
  18195. break;
  18196. }
  18197. }
  18198. return obj;
  18199. }
  18200. function set$1(opt, path, val, overwrite) {
  18201. var pathArr = path.split(',');
  18202. var obj = opt;
  18203. var key;
  18204. var i = 0;
  18205. for (; i < pathArr.length - 1; i++) {
  18206. key = pathArr[i];
  18207. if (obj[key] == null) {
  18208. obj[key] = {};
  18209. }
  18210. obj = obj[key];
  18211. }
  18212. if (overwrite || obj[pathArr[i]] == null) {
  18213. obj[pathArr[i]] = val;
  18214. }
  18215. }
  18216. function compatLayoutProperties(option) {
  18217. option && each(LAYOUT_PROPERTIES, function (prop) {
  18218. if (prop[0] in option && !(prop[1] in option)) {
  18219. option[prop[1]] = option[prop[0]];
  18220. }
  18221. });
  18222. }
  18223. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  18224. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  18225. var BAR_ITEM_STYLE_MAP = [['borderRadius', 'barBorderRadius'], ['borderColor', 'barBorderColor'], ['borderWidth', 'barBorderWidth']];
  18226. function compatBarItemStyle(option) {
  18227. var itemStyle = option && option.itemStyle;
  18228. if (itemStyle) {
  18229. for (var i = 0; i < BAR_ITEM_STYLE_MAP.length; i++) {
  18230. var oldName = BAR_ITEM_STYLE_MAP[i][1];
  18231. var newName = BAR_ITEM_STYLE_MAP[i][0];
  18232. if (itemStyle[oldName] != null) {
  18233. itemStyle[newName] = itemStyle[oldName];
  18234. if ("development" !== 'production') {
  18235. deprecateReplaceLog(oldName, newName);
  18236. }
  18237. }
  18238. }
  18239. }
  18240. }
  18241. function compatPieLabel(option) {
  18242. if (!option) {
  18243. return;
  18244. }
  18245. if (option.alignTo === 'edge' && option.margin != null && option.edgeDistance == null) {
  18246. if ("development" !== 'production') {
  18247. deprecateReplaceLog('label.margin', 'label.edgeDistance', 'pie');
  18248. }
  18249. option.edgeDistance = option.margin;
  18250. }
  18251. }
  18252. function compatSunburstState(option) {
  18253. if (!option) {
  18254. return;
  18255. }
  18256. if (option.downplay && !option.blur) {
  18257. option.blur = option.downplay;
  18258. if ("development" !== 'production') {
  18259. deprecateReplaceLog('downplay', 'blur', 'sunburst');
  18260. }
  18261. }
  18262. }
  18263. function compatGraphFocus(option) {
  18264. if (!option) {
  18265. return;
  18266. }
  18267. if (option.focusNodeAdjacency != null) {
  18268. option.emphasis = option.emphasis || {};
  18269. if (option.emphasis.focus == null) {
  18270. if ("development" !== 'production') {
  18271. deprecateReplaceLog('focusNodeAdjacency', 'emphasis: { focus: \'adjacency\'}', 'graph/sankey');
  18272. }
  18273. option.emphasis.focus = 'adjacency';
  18274. }
  18275. }
  18276. }
  18277. function traverseTree(data, cb) {
  18278. if (data) {
  18279. for (var i = 0; i < data.length; i++) {
  18280. cb(data[i]);
  18281. data[i] && traverseTree(data[i].children, cb);
  18282. }
  18283. }
  18284. }
  18285. function globalBackwardCompat(option, isTheme) {
  18286. globalCompatStyle(option, isTheme); // Make sure series array for model initialization.
  18287. option.series = normalizeToArray(option.series);
  18288. each(option.series, function (seriesOpt) {
  18289. if (!isObject(seriesOpt)) {
  18290. return;
  18291. }
  18292. var seriesType = seriesOpt.type;
  18293. if (seriesType === 'line') {
  18294. if (seriesOpt.clipOverflow != null) {
  18295. seriesOpt.clip = seriesOpt.clipOverflow;
  18296. if ("development" !== 'production') {
  18297. deprecateReplaceLog('clipOverflow', 'clip', 'line');
  18298. }
  18299. }
  18300. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  18301. if (seriesOpt.clockWise != null) {
  18302. seriesOpt.clockwise = seriesOpt.clockWise;
  18303. if ("development" !== 'production') {
  18304. deprecateReplaceLog('clockWise', 'clockwise');
  18305. }
  18306. }
  18307. compatPieLabel(seriesOpt.label);
  18308. var data = seriesOpt.data;
  18309. if (data && !isTypedArray(data)) {
  18310. for (var i = 0; i < data.length; i++) {
  18311. compatPieLabel(data[i]);
  18312. }
  18313. }
  18314. if (seriesOpt.hoverOffset != null) {
  18315. seriesOpt.emphasis = seriesOpt.emphasis || {};
  18316. if (seriesOpt.emphasis.scaleSize = null) {
  18317. if ("development" !== 'production') {
  18318. deprecateReplaceLog('hoverOffset', 'emphasis.scaleSize');
  18319. }
  18320. seriesOpt.emphasis.scaleSize = seriesOpt.hoverOffset;
  18321. }
  18322. }
  18323. } else if (seriesType === 'gauge') {
  18324. var pointerColor = get(seriesOpt, 'pointer.color');
  18325. pointerColor != null && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  18326. } else if (seriesType === 'bar') {
  18327. compatBarItemStyle(seriesOpt);
  18328. compatBarItemStyle(seriesOpt.backgroundStyle);
  18329. compatBarItemStyle(seriesOpt.emphasis);
  18330. var data = seriesOpt.data;
  18331. if (data && !isTypedArray(data)) {
  18332. for (var i = 0; i < data.length; i++) {
  18333. if (typeof data[i] === 'object') {
  18334. compatBarItemStyle(data[i]);
  18335. compatBarItemStyle(data[i] && data[i].emphasis);
  18336. }
  18337. }
  18338. }
  18339. } else if (seriesType === 'sunburst') {
  18340. var highlightPolicy = seriesOpt.highlightPolicy;
  18341. if (highlightPolicy) {
  18342. seriesOpt.emphasis = seriesOpt.emphasis || {};
  18343. if (!seriesOpt.emphasis.focus) {
  18344. seriesOpt.emphasis.focus = highlightPolicy;
  18345. if ("development" !== 'production') {
  18346. deprecateReplaceLog('highlightPolicy', 'emphasis.focus', 'sunburst');
  18347. }
  18348. }
  18349. }
  18350. compatSunburstState(seriesOpt);
  18351. traverseTree(seriesOpt.data, compatSunburstState);
  18352. } else if (seriesType === 'graph' || seriesType === 'sankey') {
  18353. compatGraphFocus(seriesOpt); // TODO nodes, edges?
  18354. } else if (seriesType === 'map') {
  18355. if (seriesOpt.mapType && !seriesOpt.map) {
  18356. if ("development" !== 'production') {
  18357. deprecateReplaceLog('mapType', 'map', 'map');
  18358. }
  18359. seriesOpt.map = seriesOpt.mapType;
  18360. }
  18361. if (seriesOpt.mapLocation) {
  18362. if ("development" !== 'production') {
  18363. deprecateLog('`mapLocation` is not used anymore.');
  18364. }
  18365. defaults(seriesOpt, seriesOpt.mapLocation);
  18366. }
  18367. }
  18368. if (seriesOpt.hoverAnimation != null) {
  18369. seriesOpt.emphasis = seriesOpt.emphasis || {};
  18370. if (seriesOpt.emphasis && seriesOpt.emphasis.scale == null) {
  18371. if ("development" !== 'production') {
  18372. deprecateReplaceLog('hoverAnimation', 'emphasis.scale');
  18373. }
  18374. seriesOpt.emphasis.scale = seriesOpt.hoverAnimation;
  18375. }
  18376. }
  18377. compatLayoutProperties(seriesOpt);
  18378. }); // dataRange has changed to visualMap
  18379. if (option.dataRange) {
  18380. option.visualMap = option.dataRange;
  18381. }
  18382. each(COMPATITABLE_COMPONENTS, function (componentName) {
  18383. var options = option[componentName];
  18384. if (options) {
  18385. if (!isArray(options)) {
  18386. options = [options];
  18387. }
  18388. each(options, function (option) {
  18389. compatLayoutProperties(option);
  18390. });
  18391. }
  18392. });
  18393. }
  18394. // data processing stage is blocked in stream.
  18395. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  18396. // (2) Only register once when import repeatly.
  18397. // Should be executed after series filtered and before stack calculation.
  18398. function dataStack(ecModel) {
  18399. var stackInfoMap = createHashMap();
  18400. ecModel.eachSeries(function (seriesModel) {
  18401. var stack = seriesModel.get('stack'); // Compatibal: when `stack` is set as '', do not stack.
  18402. if (stack) {
  18403. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  18404. var data = seriesModel.getData();
  18405. var stackInfo = {
  18406. // Used for calculate axis extent automatically.
  18407. // TODO: Type getCalculationInfo return more specific type?
  18408. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  18409. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  18410. stackedDimension: data.getCalculationInfo('stackedDimension'),
  18411. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  18412. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  18413. data: data,
  18414. seriesModel: seriesModel
  18415. }; // If stacked on axis that do not support data stack.
  18416. if (!stackInfo.stackedDimension || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)) {
  18417. return;
  18418. }
  18419. stackInfoList.length && data.setCalculationInfo('stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel);
  18420. stackInfoList.push(stackInfo);
  18421. }
  18422. });
  18423. stackInfoMap.each(calculateStack);
  18424. }
  18425. function calculateStack(stackInfoList) {
  18426. each(stackInfoList, function (targetStackInfo, idxInStack) {
  18427. var resultVal = [];
  18428. var resultNaN = [NaN, NaN];
  18429. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  18430. var targetData = targetStackInfo.data;
  18431. var isStackedByIndex = targetStackInfo.isStackedByIndex; // Should not write on raw data, because stack series model list changes
  18432. // depending on legend selection.
  18433. targetData.modify(dims, function (v0, v1, dataIndex) {
  18434. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex); // Consider `connectNulls` of line area, if value is NaN, stackedOver
  18435. // should also be NaN, to draw a appropriate belt area.
  18436. if (isNaN(sum)) {
  18437. return resultNaN;
  18438. }
  18439. var byValue;
  18440. var stackedDataRawIndex;
  18441. if (isStackedByIndex) {
  18442. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  18443. } else {
  18444. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  18445. } // If stackOver is NaN, chart view will render point on value start.
  18446. var stackedOver = NaN;
  18447. for (var j = idxInStack - 1; j >= 0; j--) {
  18448. var stackInfo = stackInfoList[j]; // Has been optimized by inverted indices on `stackedByDimension`.
  18449. if (!isStackedByIndex) {
  18450. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  18451. }
  18452. if (stackedDataRawIndex >= 0) {
  18453. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex); // Considering positive stack, negative stack and empty data
  18454. if (sum >= 0 && val > 0 || // Positive stack
  18455. sum <= 0 && val < 0 // Negative stack
  18456. ) {
  18457. // The sum should be as less as possible to be effected
  18458. // by floating arithmetic problem. A wrong result probably
  18459. // filtered incorrectly by axis min/max.
  18460. sum = addSafe(sum, val);
  18461. stackedOver = val;
  18462. break;
  18463. }
  18464. }
  18465. }
  18466. resultVal[0] = sum;
  18467. resultVal[1] = stackedOver;
  18468. return resultVal;
  18469. });
  18470. });
  18471. }
  18472. var SourceImpl =
  18473. /** @class */
  18474. function () {
  18475. function SourceImpl(fields) {
  18476. this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
  18477. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN; // Visit config
  18478. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  18479. this.startIndex = fields.startIndex || 0;
  18480. this.dimensionsDetectedCount = fields.dimensionsDetectedCount;
  18481. this.metaRawOption = fields.metaRawOption;
  18482. var dimensionsDefine = this.dimensionsDefine = fields.dimensionsDefine;
  18483. if (dimensionsDefine) {
  18484. for (var i = 0; i < dimensionsDefine.length; i++) {
  18485. var dim = dimensionsDefine[i];
  18486. if (dim.type == null) {
  18487. if (guessOrdinal(this, i) === BE_ORDINAL.Must) {
  18488. dim.type = 'ordinal';
  18489. }
  18490. }
  18491. }
  18492. }
  18493. }
  18494. return SourceImpl;
  18495. }();
  18496. function isSourceInstance(val) {
  18497. return val instanceof SourceImpl;
  18498. }
  18499. /**
  18500. * Create a source from option.
  18501. * NOTE: Created source is immutable. Don't change any properties in it.
  18502. */
  18503. function createSource(sourceData, thisMetaRawOption, // can be null. If not provided, auto detect it from `sourceData`.
  18504. sourceFormat) {
  18505. sourceFormat = sourceFormat || detectSourceFormat(sourceData);
  18506. var seriesLayoutBy = thisMetaRawOption.seriesLayoutBy;
  18507. var determined = determineSourceDimensions(sourceData, sourceFormat, seriesLayoutBy, thisMetaRawOption.sourceHeader, thisMetaRawOption.dimensions);
  18508. var source = new SourceImpl({
  18509. data: sourceData,
  18510. sourceFormat: sourceFormat,
  18511. seriesLayoutBy: seriesLayoutBy,
  18512. dimensionsDefine: determined.dimensionsDefine,
  18513. startIndex: determined.startIndex,
  18514. dimensionsDetectedCount: determined.dimensionsDetectedCount,
  18515. metaRawOption: clone(thisMetaRawOption)
  18516. });
  18517. return source;
  18518. }
  18519. /**
  18520. * Wrap original series data for some compatibility cases.
  18521. */
  18522. function createSourceFromSeriesDataOption(data) {
  18523. return new SourceImpl({
  18524. data: data,
  18525. sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL
  18526. });
  18527. }
  18528. /**
  18529. * Clone source but excludes source data.
  18530. */
  18531. function cloneSourceShallow(source) {
  18532. return new SourceImpl({
  18533. data: source.data,
  18534. sourceFormat: source.sourceFormat,
  18535. seriesLayoutBy: source.seriesLayoutBy,
  18536. dimensionsDefine: clone(source.dimensionsDefine),
  18537. startIndex: source.startIndex,
  18538. dimensionsDetectedCount: source.dimensionsDetectedCount
  18539. });
  18540. }
  18541. /**
  18542. * Note: An empty array will be detected as `SOURCE_FORMAT_ARRAY_ROWS`.
  18543. */
  18544. function detectSourceFormat(data) {
  18545. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  18546. if (isTypedArray(data)) {
  18547. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  18548. } else if (isArray(data)) {
  18549. // FIXME Whether tolerate null in top level array?
  18550. if (data.length === 0) {
  18551. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  18552. }
  18553. for (var i = 0, len = data.length; i < len; i++) {
  18554. var item = data[i];
  18555. if (item == null) {
  18556. continue;
  18557. } else if (isArray(item)) {
  18558. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  18559. break;
  18560. } else if (isObject(item)) {
  18561. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  18562. break;
  18563. }
  18564. }
  18565. } else if (isObject(data)) {
  18566. for (var key in data) {
  18567. if (hasOwn(data, key) && isArrayLike(data[key])) {
  18568. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  18569. break;
  18570. }
  18571. }
  18572. }
  18573. return sourceFormat;
  18574. }
  18575. /**
  18576. * Determine the source definitions from data standalone dimensions definitions
  18577. * are not specified.
  18578. */
  18579. function determineSourceDimensions(data, sourceFormat, seriesLayoutBy, sourceHeader, // standalone raw dimensions definition, like:
  18580. // {
  18581. // dimensions: ['aa', 'bb', { name: 'cc', type: 'time' }]
  18582. // }
  18583. // in `dataset` or `series`
  18584. dimensionsDefine) {
  18585. var dimensionsDetectedCount;
  18586. var startIndex; // PEDING: could data be null/undefined here?
  18587. // currently, if `dataset.source` not specified, error thrown.
  18588. // if `series.data` not specified, nothing rendered without error thrown.
  18589. // Should test these cases.
  18590. if (!data) {
  18591. return {
  18592. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  18593. startIndex: startIndex,
  18594. dimensionsDetectedCount: dimensionsDetectedCount
  18595. };
  18596. }
  18597. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18598. var dataArrayRows = data; // Rule: Most of the first line are string: it is header.
  18599. // Caution: consider a line with 5 string and 1 number,
  18600. // it still can not be sure it is a head, because the
  18601. // 5 string may be 5 values of category columns.
  18602. if (sourceHeader === 'auto' || sourceHeader == null) {
  18603. arrayRowsTravelFirst(function (val) {
  18604. // '-' is regarded as null/undefined.
  18605. if (val != null && val !== '-') {
  18606. if (isString(val)) {
  18607. startIndex == null && (startIndex = 1);
  18608. } else {
  18609. startIndex = 0;
  18610. }
  18611. } // 10 is an experience number, avoid long loop.
  18612. }, seriesLayoutBy, dataArrayRows, 10);
  18613. } else {
  18614. startIndex = isNumber(sourceHeader) ? sourceHeader : sourceHeader ? 1 : 0;
  18615. }
  18616. if (!dimensionsDefine && startIndex === 1) {
  18617. dimensionsDefine = [];
  18618. arrayRowsTravelFirst(function (val, index) {
  18619. dimensionsDefine[index] = val != null ? val + '' : '';
  18620. }, seriesLayoutBy, dataArrayRows, Infinity);
  18621. }
  18622. dimensionsDetectedCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? dataArrayRows.length : dataArrayRows[0] ? dataArrayRows[0].length : null;
  18623. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18624. if (!dimensionsDefine) {
  18625. dimensionsDefine = objectRowsCollectDimensions(data);
  18626. }
  18627. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18628. if (!dimensionsDefine) {
  18629. dimensionsDefine = [];
  18630. each(data, function (colArr, key) {
  18631. dimensionsDefine.push(key);
  18632. });
  18633. }
  18634. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18635. var value0 = getDataItemValue(data[0]);
  18636. dimensionsDetectedCount = isArray(value0) && value0.length || 1;
  18637. } else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18638. if ("development" !== 'production') {
  18639. assert(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  18640. }
  18641. }
  18642. return {
  18643. startIndex: startIndex,
  18644. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  18645. dimensionsDetectedCount: dimensionsDetectedCount
  18646. };
  18647. }
  18648. function objectRowsCollectDimensions(data) {
  18649. var firstIndex = 0;
  18650. var obj;
  18651. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  18652. if (obj) {
  18653. var dimensions_1 = [];
  18654. each(obj, function (value, key) {
  18655. dimensions_1.push(key);
  18656. });
  18657. return dimensions_1;
  18658. }
  18659. } // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  18660. // which is reasonable. But dimension name is duplicated.
  18661. // Returns undefined or an array contains only object without null/undefiend or string.
  18662. function normalizeDimensionsOption(dimensionsDefine) {
  18663. if (!dimensionsDefine) {
  18664. // The meaning of null/undefined is different from empty array.
  18665. return;
  18666. }
  18667. var nameMap = createHashMap();
  18668. return map(dimensionsDefine, function (rawItem, index) {
  18669. rawItem = isObject(rawItem) ? rawItem : {
  18670. name: rawItem
  18671. }; // Other fields will be discarded.
  18672. var item = {
  18673. name: rawItem.name,
  18674. displayName: rawItem.displayName,
  18675. type: rawItem.type
  18676. }; // User can set null in dimensions.
  18677. // We dont auto specify name, othewise a given name may
  18678. // cause it be refered unexpectedly.
  18679. if (item.name == null) {
  18680. return item;
  18681. } // Also consider number form like 2012.
  18682. item.name += ''; // User may also specify displayName.
  18683. // displayName will always exists except user not
  18684. // specified or dim name is not specified or detected.
  18685. // (A auto generated dim name will not be used as
  18686. // displayName).
  18687. if (item.displayName == null) {
  18688. item.displayName = item.name;
  18689. }
  18690. var exist = nameMap.get(item.name);
  18691. if (!exist) {
  18692. nameMap.set(item.name, {
  18693. count: 1
  18694. });
  18695. } else {
  18696. item.name += '-' + exist.count++;
  18697. }
  18698. return item;
  18699. });
  18700. }
  18701. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  18702. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18703. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18704. cb(data[i] ? data[i][0] : null, i);
  18705. }
  18706. } else {
  18707. var value0 = data[0] || [];
  18708. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  18709. cb(value0[i], i);
  18710. }
  18711. }
  18712. }
  18713. function shouldRetrieveDataByName(source) {
  18714. var sourceFormat = source.sourceFormat;
  18715. return sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS;
  18716. }
  18717. /*
  18718. * Licensed to the Apache Software Foundation (ASF) under one
  18719. * or more contributor license agreements. See the NOTICE file
  18720. * distributed with this work for additional information
  18721. * regarding copyright ownership. The ASF licenses this file
  18722. * to you under the Apache License, Version 2.0 (the
  18723. * "License"); you may not use this file except in compliance
  18724. * with the License. You may obtain a copy of the License at
  18725. *
  18726. * http://www.apache.org/licenses/LICENSE-2.0
  18727. *
  18728. * Unless required by applicable law or agreed to in writing,
  18729. * software distributed under the License is distributed on an
  18730. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18731. * KIND, either express or implied. See the License for the
  18732. * specific language governing permissions and limitations
  18733. * under the License.
  18734. */
  18735. /**
  18736. * AUTO-GENERATED FILE. DO NOT MODIFY.
  18737. */
  18738. /*
  18739. * Licensed to the Apache Software Foundation (ASF) under one
  18740. * or more contributor license agreements. See the NOTICE file
  18741. * distributed with this work for additional information
  18742. * regarding copyright ownership. The ASF licenses this file
  18743. * to you under the Apache License, Version 2.0 (the
  18744. * "License"); you may not use this file except in compliance
  18745. * with the License. You may obtain a copy of the License at
  18746. *
  18747. * http://www.apache.org/licenses/LICENSE-2.0
  18748. *
  18749. * Unless required by applicable law or agreed to in writing,
  18750. * software distributed under the License is distributed on an
  18751. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18752. * KIND, either express or implied. See the License for the
  18753. * specific language governing permissions and limitations
  18754. * under the License.
  18755. */
  18756. var _a, _b, _c; // TODO
  18757. var providerMethods;
  18758. var mountMethods;
  18759. /**
  18760. * If normal array used, mutable chunk size is supported.
  18761. * If typed array used, chunk size must be fixed.
  18762. */
  18763. var DefaultDataProvider =
  18764. /** @class */
  18765. function () {
  18766. function DefaultDataProvider(sourceParam, dimSize) {
  18767. // let source: Source;
  18768. var source = !isSourceInstance(sourceParam) ? createSourceFromSeriesDataOption(sourceParam) : sourceParam; // declare source is Source;
  18769. this._source = source;
  18770. var data = this._data = source.data; // Typed array. TODO IE10+?
  18771. if (source.sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18772. if ("development" !== 'production') {
  18773. if (dimSize == null) {
  18774. throw new Error('Typed array data must specify dimension size');
  18775. }
  18776. }
  18777. this._offset = 0;
  18778. this._dimSize = dimSize;
  18779. this._data = data;
  18780. }
  18781. mountMethods(this, data, source);
  18782. }
  18783. DefaultDataProvider.prototype.getSource = function () {
  18784. return this._source;
  18785. };
  18786. DefaultDataProvider.prototype.count = function () {
  18787. return 0;
  18788. };
  18789. DefaultDataProvider.prototype.getItem = function (idx, out) {
  18790. return;
  18791. };
  18792. DefaultDataProvider.prototype.appendData = function (newData) {};
  18793. DefaultDataProvider.prototype.clean = function () {};
  18794. DefaultDataProvider.protoInitialize = function () {
  18795. // PENDING: To avoid potential incompat (e.g., prototype
  18796. // is visited somewhere), still init them on prototype.
  18797. var proto = DefaultDataProvider.prototype;
  18798. proto.pure = false;
  18799. proto.persistent = true;
  18800. }();
  18801. DefaultDataProvider.internalField = function () {
  18802. var _a;
  18803. mountMethods = function (provider, data, source) {
  18804. var sourceFormat = source.sourceFormat;
  18805. var seriesLayoutBy = source.seriesLayoutBy;
  18806. var startIndex = source.startIndex;
  18807. var dimsDef = source.dimensionsDefine;
  18808. var methods = providerMethods[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  18809. if ("development" !== 'production') {
  18810. assert(methods, 'Invalide sourceFormat: ' + sourceFormat);
  18811. }
  18812. extend(provider, methods);
  18813. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18814. provider.getItem = getItemForTypedArray;
  18815. provider.count = countForTypedArray;
  18816. provider.fillStorage = fillStorageForTypedArray;
  18817. } else {
  18818. var rawItemGetter = getRawSourceItemGetter(sourceFormat, seriesLayoutBy);
  18819. provider.getItem = bind(rawItemGetter, null, data, startIndex, dimsDef);
  18820. var rawCounter = getRawSourceDataCounter(sourceFormat, seriesLayoutBy);
  18821. provider.count = bind(rawCounter, null, data, startIndex, dimsDef);
  18822. }
  18823. };
  18824. var getItemForTypedArray = function (idx, out) {
  18825. idx = idx - this._offset;
  18826. out = out || [];
  18827. var data = this._data;
  18828. var dimSize = this._dimSize;
  18829. var offset = dimSize * idx;
  18830. for (var i = 0; i < dimSize; i++) {
  18831. out[i] = data[offset + i];
  18832. }
  18833. return out;
  18834. };
  18835. var fillStorageForTypedArray = function (start, end, storage, extent) {
  18836. var data = this._data;
  18837. var dimSize = this._dimSize;
  18838. for (var dim = 0; dim < dimSize; dim++) {
  18839. var dimExtent = extent[dim];
  18840. var min = dimExtent[0] == null ? Infinity : dimExtent[0];
  18841. var max = dimExtent[1] == null ? -Infinity : dimExtent[1];
  18842. var count = end - start;
  18843. var arr = storage[dim];
  18844. for (var i = 0; i < count; i++) {
  18845. // appendData with TypedArray will always do replace in provider.
  18846. var val = data[i * dimSize + dim];
  18847. arr[start + i] = val;
  18848. val < min && (min = val);
  18849. val > max && (max = val);
  18850. }
  18851. dimExtent[0] = min;
  18852. dimExtent[1] = max;
  18853. }
  18854. };
  18855. var countForTypedArray = function () {
  18856. return this._data ? this._data.length / this._dimSize : 0;
  18857. };
  18858. providerMethods = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = {
  18859. pure: true,
  18860. appendData: appendDataSimply
  18861. }, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = {
  18862. pure: true,
  18863. appendData: function () {
  18864. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  18865. }
  18866. }, _a[SOURCE_FORMAT_OBJECT_ROWS] = {
  18867. pure: true,
  18868. appendData: appendDataSimply
  18869. }, _a[SOURCE_FORMAT_KEYED_COLUMNS] = {
  18870. pure: true,
  18871. appendData: function (newData) {
  18872. var data = this._data;
  18873. each(newData, function (newCol, key) {
  18874. var oldCol = data[key] || (data[key] = []);
  18875. for (var i = 0; i < (newCol || []).length; i++) {
  18876. oldCol.push(newCol[i]);
  18877. }
  18878. });
  18879. }
  18880. }, _a[SOURCE_FORMAT_ORIGINAL] = {
  18881. appendData: appendDataSimply
  18882. }, _a[SOURCE_FORMAT_TYPED_ARRAY] = {
  18883. persistent: false,
  18884. pure: true,
  18885. appendData: function (newData) {
  18886. if ("development" !== 'production') {
  18887. assert(isTypedArray(newData), 'Added data must be TypedArray if data in initialization is TypedArray');
  18888. }
  18889. this._data = newData;
  18890. },
  18891. // Clean self if data is already used.
  18892. clean: function () {
  18893. // PENDING
  18894. this._offset += this.count();
  18895. this._data = null;
  18896. }
  18897. }, _a);
  18898. function appendDataSimply(newData) {
  18899. for (var i = 0; i < newData.length; i++) {
  18900. this._data.push(newData[i]);
  18901. }
  18902. }
  18903. }();
  18904. return DefaultDataProvider;
  18905. }();
  18906. var getItemSimply = function (rawData, startIndex, dimsDef, idx) {
  18907. return rawData[idx];
  18908. };
  18909. var rawSourceItemGetterMap = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef, idx) {
  18910. return rawData[idx + startIndex];
  18911. }, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef, idx, out) {
  18912. idx += startIndex;
  18913. var item = out || [];
  18914. var data = rawData;
  18915. for (var i = 0; i < data.length; i++) {
  18916. var row = data[i];
  18917. item[i] = row ? row[idx] : null;
  18918. }
  18919. return item;
  18920. }, _a[SOURCE_FORMAT_OBJECT_ROWS] = getItemSimply, _a[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef, idx, out) {
  18921. var item = out || [];
  18922. for (var i = 0; i < dimsDef.length; i++) {
  18923. var dimName = dimsDef[i].name;
  18924. if ("development" !== 'production') {
  18925. if (dimName == null) {
  18926. throw new Error();
  18927. }
  18928. }
  18929. var col = rawData[dimName];
  18930. item[i] = col ? col[idx] : null;
  18931. }
  18932. return item;
  18933. }, _a[SOURCE_FORMAT_ORIGINAL] = getItemSimply, _a);
  18934. function getRawSourceItemGetter(sourceFormat, seriesLayoutBy) {
  18935. var method = rawSourceItemGetterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  18936. if ("development" !== 'production') {
  18937. assert(method, 'Do not support get item on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  18938. }
  18939. return method;
  18940. }
  18941. var countSimply = function (rawData, startIndex, dimsDef) {
  18942. return rawData.length;
  18943. };
  18944. var rawSourceDataCounterMap = (_b = {}, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef) {
  18945. return Math.max(0, rawData.length - startIndex);
  18946. }, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef) {
  18947. var row = rawData[0];
  18948. return row ? Math.max(0, row.length - startIndex) : 0;
  18949. }, _b[SOURCE_FORMAT_OBJECT_ROWS] = countSimply, _b[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef) {
  18950. var dimName = dimsDef[0].name;
  18951. if ("development" !== 'production') {
  18952. if (dimName == null) {
  18953. throw new Error();
  18954. }
  18955. }
  18956. var col = rawData[dimName];
  18957. return col ? col.length : 0;
  18958. }, _b[SOURCE_FORMAT_ORIGINAL] = countSimply, _b);
  18959. function getRawSourceDataCounter(sourceFormat, seriesLayoutBy) {
  18960. var method = rawSourceDataCounterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  18961. if ("development" !== 'production') {
  18962. assert(method, 'Do not suppport count on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  18963. }
  18964. return method;
  18965. }
  18966. var getRawValueSimply = function (dataItem, dimIndex, property) {
  18967. return dataItem[dimIndex];
  18968. };
  18969. var rawSourceValueGetterMap = (_c = {}, _c[SOURCE_FORMAT_ARRAY_ROWS] = getRawValueSimply, _c[SOURCE_FORMAT_OBJECT_ROWS] = function (dataItem, dimIndex, property) {
  18970. return dataItem[property];
  18971. }, _c[SOURCE_FORMAT_KEYED_COLUMNS] = getRawValueSimply, _c[SOURCE_FORMAT_ORIGINAL] = function (dataItem, dimIndex, property) {
  18972. // FIXME: In some case (markpoint in geo (geo-map.html)),
  18973. // dataItem is {coord: [...]}
  18974. var value = getDataItemValue(dataItem);
  18975. return !(value instanceof Array) ? value : value[dimIndex];
  18976. }, _c[SOURCE_FORMAT_TYPED_ARRAY] = getRawValueSimply, _c);
  18977. function getRawSourceValueGetter(sourceFormat) {
  18978. var method = rawSourceValueGetterMap[sourceFormat];
  18979. if ("development" !== 'production') {
  18980. assert(method, 'Do not suppport get value on "' + sourceFormat + '".');
  18981. }
  18982. return method;
  18983. }
  18984. function getMethodMapKey(sourceFormat, seriesLayoutBy) {
  18985. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + seriesLayoutBy : sourceFormat;
  18986. } // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  18987. // Consider persistent.
  18988. // Caution: why use raw value to display on label or tooltip?
  18989. // A reason is to avoid format. For example time value we do not know
  18990. // how to format is expected. More over, if stack is used, calculated
  18991. // value may be 0.91000000001, which have brings trouble to display.
  18992. // TODO: consider how to treat null/undefined/NaN when display?
  18993. function retrieveRawValue(data, dataIndex, // If dimIndex is null/undefined, return OptionDataItem.
  18994. // Otherwise, return OptionDataValue.
  18995. dim) {
  18996. if (!data) {
  18997. return;
  18998. } // Consider data may be not persistent.
  18999. var dataItem = data.getRawDataItem(dataIndex);
  19000. if (dataItem == null) {
  19001. return;
  19002. }
  19003. var store = data.getStore();
  19004. var sourceFormat = store.getSource().sourceFormat;
  19005. if (dim != null) {
  19006. var dimIndex = data.getDimensionIndex(dim);
  19007. var property = store.getDimensionProperty(dimIndex);
  19008. return getRawSourceValueGetter(sourceFormat)(dataItem, dimIndex, property);
  19009. } else {
  19010. var result = dataItem;
  19011. if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  19012. result = getDataItemValue(dataItem);
  19013. }
  19014. return result;
  19015. }
  19016. }
  19017. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  19018. var DataFormatMixin =
  19019. /** @class */
  19020. function () {
  19021. function DataFormatMixin() {}
  19022. /**
  19023. * Get params for formatter
  19024. */
  19025. DataFormatMixin.prototype.getDataParams = function (dataIndex, dataType) {
  19026. var data = this.getData(dataType);
  19027. var rawValue = this.getRawValue(dataIndex, dataType);
  19028. var rawDataIndex = data.getRawIndex(dataIndex);
  19029. var name = data.getName(dataIndex);
  19030. var itemOpt = data.getRawDataItem(dataIndex);
  19031. var style = data.getItemVisual(dataIndex, 'style');
  19032. var color = style && style[data.getItemVisual(dataIndex, 'drawType') || 'fill'];
  19033. var borderColor = style && style.stroke;
  19034. var mainType = this.mainType;
  19035. var isSeries = mainType === 'series';
  19036. var userOutput = data.userOutput && data.userOutput.get();
  19037. return {
  19038. componentType: mainType,
  19039. componentSubType: this.subType,
  19040. componentIndex: this.componentIndex,
  19041. seriesType: isSeries ? this.subType : null,
  19042. seriesIndex: this.seriesIndex,
  19043. seriesId: isSeries ? this.id : null,
  19044. seriesName: isSeries ? this.name : null,
  19045. name: name,
  19046. dataIndex: rawDataIndex,
  19047. data: itemOpt,
  19048. dataType: dataType,
  19049. value: rawValue,
  19050. color: color,
  19051. borderColor: borderColor,
  19052. dimensionNames: userOutput ? userOutput.fullDimensions : null,
  19053. encode: userOutput ? userOutput.encode : null,
  19054. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  19055. $vars: ['seriesName', 'name', 'value']
  19056. };
  19057. };
  19058. /**
  19059. * Format label
  19060. * @param dataIndex
  19061. * @param status 'normal' by default
  19062. * @param dataType
  19063. * @param labelDimIndex Only used in some chart that
  19064. * use formatter in different dimensions, like radar.
  19065. * @param formatter Formatter given outside.
  19066. * @return return null/undefined if no formatter
  19067. */
  19068. DataFormatMixin.prototype.getFormattedLabel = function (dataIndex, status, dataType, labelDimIndex, formatter, extendParams) {
  19069. status = status || 'normal';
  19070. var data = this.getData(dataType);
  19071. var params = this.getDataParams(dataIndex, dataType);
  19072. if (extendParams) {
  19073. params.value = extendParams.interpolatedValue;
  19074. }
  19075. if (labelDimIndex != null && isArray(params.value)) {
  19076. params.value = params.value[labelDimIndex];
  19077. }
  19078. if (!formatter) {
  19079. var itemModel = data.getItemModel(dataIndex); // @ts-ignore
  19080. formatter = itemModel.get(status === 'normal' ? ['label', 'formatter'] : [status, 'label', 'formatter']);
  19081. }
  19082. if (typeof formatter === 'function') {
  19083. params.status = status;
  19084. params.dimensionIndex = labelDimIndex;
  19085. return formatter(params);
  19086. } else if (typeof formatter === 'string') {
  19087. var str = formatTpl(formatter, params); // Support 'aaa{@[3]}bbb{@product}ccc'.
  19088. // Do not support '}' in dim name util have to.
  19089. return str.replace(DIMENSION_LABEL_REG, function (origin, dimStr) {
  19090. var len = dimStr.length;
  19091. var dimLoose = dimStr;
  19092. if (dimLoose.charAt(0) === '[' && dimLoose.charAt(len - 1) === ']') {
  19093. dimLoose = +dimLoose.slice(1, len - 1); // Also support: '[]' => 0
  19094. if ("development" !== 'production') {
  19095. if (isNaN(dimLoose)) {
  19096. error("Invalide label formatter: @" + dimStr + ", only support @[0], @[1], @[2], ...");
  19097. }
  19098. }
  19099. }
  19100. var val = retrieveRawValue(data, dataIndex, dimLoose);
  19101. if (extendParams && isArray(extendParams.interpolatedValue)) {
  19102. var dimIndex = data.getDimensionIndex(dimLoose);
  19103. if (dimIndex >= 0) {
  19104. val = extendParams.interpolatedValue[dimIndex];
  19105. }
  19106. }
  19107. return val != null ? val + '' : '';
  19108. });
  19109. }
  19110. };
  19111. /**
  19112. * Get raw value in option
  19113. */
  19114. DataFormatMixin.prototype.getRawValue = function (idx, dataType) {
  19115. return retrieveRawValue(this.getData(dataType), idx);
  19116. };
  19117. /**
  19118. * Should be implemented.
  19119. * @param {number} dataIndex
  19120. * @param {boolean} [multipleSeries=false]
  19121. * @param {string} [dataType]
  19122. */
  19123. DataFormatMixin.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  19124. // Empty function
  19125. return;
  19126. };
  19127. return DataFormatMixin;
  19128. }();
  19129. // but guess little chance has been used outside. Do we need to backward
  19130. // compat it?
  19131. // type TooltipFormatResultLegacyObject = {
  19132. // // `html` means the markup language text, either in 'html' or 'richText'.
  19133. // // The name `html` is not appropriate becuase in 'richText' it is not a HTML
  19134. // // string. But still support it for backward compat.
  19135. // html: string;
  19136. // markers: Dictionary<ColorString>;
  19137. // };
  19138. /**
  19139. * For backward compat, normalize the return from `formatTooltip`.
  19140. */
  19141. function normalizeTooltipFormatResult(result // markersExisting: Dictionary<ColorString>
  19142. ) {
  19143. var markupText; // let markers: Dictionary<ColorString>;
  19144. var markupFragment;
  19145. if (isObject(result)) {
  19146. if (result.type) {
  19147. markupFragment = result;
  19148. } else {
  19149. if ("development" !== 'production') {
  19150. console.warn('The return type of `formatTooltip` is not supported: ' + makePrintable(result));
  19151. }
  19152. } // else {
  19153. // markupText = (result as TooltipFormatResultLegacyObject).html;
  19154. // markers = (result as TooltipFormatResultLegacyObject).markers;
  19155. // if (markersExisting) {
  19156. // markers = zrUtil.merge(markersExisting, markers);
  19157. // }
  19158. // }
  19159. } else {
  19160. markupText = result;
  19161. }
  19162. return {
  19163. markupText: markupText,
  19164. // markers: markers || markersExisting,
  19165. markupFragment: markupFragment
  19166. };
  19167. }
  19168. /**
  19169. * @param {Object} define
  19170. * @return See the return of `createTask`.
  19171. */
  19172. function createTask(define) {
  19173. return new Task(define);
  19174. }
  19175. var Task =
  19176. /** @class */
  19177. function () {
  19178. function Task(define) {
  19179. define = define || {};
  19180. this._reset = define.reset;
  19181. this._plan = define.plan;
  19182. this._count = define.count;
  19183. this._onDirty = define.onDirty;
  19184. this._dirty = true;
  19185. }
  19186. /**
  19187. * @param step Specified step.
  19188. * @param skip Skip customer perform call.
  19189. * @param modBy Sampling window size.
  19190. * @param modDataCount Sampling count.
  19191. * @return whether unfinished.
  19192. */
  19193. Task.prototype.perform = function (performArgs) {
  19194. var upTask = this._upstream;
  19195. var skip = performArgs && performArgs.skip; // TODO some refactor.
  19196. // Pull data. Must pull data each time, because context.data
  19197. // may be updated by Series.setData.
  19198. if (this._dirty && upTask) {
  19199. var context = this.context;
  19200. context.data = context.outputData = upTask.context.outputData;
  19201. }
  19202. if (this.__pipeline) {
  19203. this.__pipeline.currentTask = this;
  19204. }
  19205. var planResult;
  19206. if (this._plan && !skip) {
  19207. planResult = this._plan(this.context);
  19208. } // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  19209. // elements uniformed distributed when progress, especially when moving or zooming.
  19210. var lastModBy = normalizeModBy(this._modBy);
  19211. var lastModDataCount = this._modDataCount || 0;
  19212. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  19213. var modDataCount = performArgs && performArgs.modDataCount || 0;
  19214. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  19215. planResult = 'reset';
  19216. }
  19217. function normalizeModBy(val) {
  19218. !(val >= 1) && (val = 1); // jshint ignore:line
  19219. return val;
  19220. }
  19221. var forceFirstProgress;
  19222. if (this._dirty || planResult === 'reset') {
  19223. this._dirty = false;
  19224. forceFirstProgress = this._doReset(skip);
  19225. }
  19226. this._modBy = modBy;
  19227. this._modDataCount = modDataCount;
  19228. var step = performArgs && performArgs.step;
  19229. if (upTask) {
  19230. if ("development" !== 'production') {
  19231. assert(upTask._outputDueEnd != null);
  19232. }
  19233. this._dueEnd = upTask._outputDueEnd;
  19234. } // DataTask or overallTask
  19235. else {
  19236. if ("development" !== 'production') {
  19237. assert(!this._progress || this._count);
  19238. }
  19239. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  19240. } // Note: Stubs, that its host overall task let it has progress, has progress.
  19241. // If no progress, pass index from upstream to downstream each time plan called.
  19242. if (this._progress) {
  19243. var start = this._dueIndex;
  19244. var end = Math.min(step != null ? this._dueIndex + step : Infinity, this._dueEnd);
  19245. if (!skip && (forceFirstProgress || start < end)) {
  19246. var progress = this._progress;
  19247. if (isArray(progress)) {
  19248. for (var i = 0; i < progress.length; i++) {
  19249. this._doProgress(progress[i], start, end, modBy, modDataCount);
  19250. }
  19251. } else {
  19252. this._doProgress(progress, start, end, modBy, modDataCount);
  19253. }
  19254. }
  19255. this._dueIndex = end; // If no `outputDueEnd`, assume that output data and
  19256. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  19257. var outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : end;
  19258. if ("development" !== 'production') {
  19259. // ??? Can not rollback.
  19260. assert(outputDueEnd >= this._outputDueEnd);
  19261. }
  19262. this._outputDueEnd = outputDueEnd;
  19263. } else {
  19264. // (1) Some overall task has no progress.
  19265. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  19266. // This should always be performed so it can be passed to downstream.
  19267. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : this._dueEnd;
  19268. }
  19269. return this.unfinished();
  19270. };
  19271. Task.prototype.dirty = function () {
  19272. this._dirty = true;
  19273. this._onDirty && this._onDirty(this.context);
  19274. };
  19275. Task.prototype._doProgress = function (progress, start, end, modBy, modDataCount) {
  19276. iterator.reset(start, end, modBy, modDataCount);
  19277. this._callingProgress = progress;
  19278. this._callingProgress({
  19279. start: start,
  19280. end: end,
  19281. count: end - start,
  19282. next: iterator.next
  19283. }, this.context);
  19284. };
  19285. Task.prototype._doReset = function (skip) {
  19286. this._dueIndex = this._outputDueEnd = this._dueEnd = 0;
  19287. this._settedOutputEnd = null;
  19288. var progress;
  19289. var forceFirstProgress;
  19290. if (!skip && this._reset) {
  19291. progress = this._reset(this.context);
  19292. if (progress && progress.progress) {
  19293. forceFirstProgress = progress.forceFirstProgress;
  19294. progress = progress.progress;
  19295. } // To simplify no progress checking, array must has item.
  19296. if (isArray(progress) && !progress.length) {
  19297. progress = null;
  19298. }
  19299. }
  19300. this._progress = progress;
  19301. this._modBy = this._modDataCount = null;
  19302. var downstream = this._downstream;
  19303. downstream && downstream.dirty();
  19304. return forceFirstProgress;
  19305. };
  19306. Task.prototype.unfinished = function () {
  19307. return this._progress && this._dueIndex < this._dueEnd;
  19308. };
  19309. /**
  19310. * @param downTask The downstream task.
  19311. * @return The downstream task.
  19312. */
  19313. Task.prototype.pipe = function (downTask) {
  19314. if ("development" !== 'production') {
  19315. assert(downTask && !downTask._disposed && downTask !== this);
  19316. } // If already downstream, do not dirty downTask.
  19317. if (this._downstream !== downTask || this._dirty) {
  19318. this._downstream = downTask;
  19319. downTask._upstream = this;
  19320. downTask.dirty();
  19321. }
  19322. };
  19323. Task.prototype.dispose = function () {
  19324. if (this._disposed) {
  19325. return;
  19326. }
  19327. this._upstream && (this._upstream._downstream = null);
  19328. this._downstream && (this._downstream._upstream = null);
  19329. this._dirty = false;
  19330. this._disposed = true;
  19331. };
  19332. Task.prototype.getUpstream = function () {
  19333. return this._upstream;
  19334. };
  19335. Task.prototype.getDownstream = function () {
  19336. return this._downstream;
  19337. };
  19338. Task.prototype.setOutputEnd = function (end) {
  19339. // This only happend in dataTask, dataZoom, map, currently.
  19340. // where dataZoom do not set end each time, but only set
  19341. // when reset. So we should record the setted end, in case
  19342. // that the stub of dataZoom perform again and earse the
  19343. // setted end by upstream.
  19344. this._outputDueEnd = this._settedOutputEnd = end;
  19345. };
  19346. return Task;
  19347. }();
  19348. var iterator = function () {
  19349. var end;
  19350. var current;
  19351. var modBy;
  19352. var modDataCount;
  19353. var winCount;
  19354. var it = {
  19355. reset: function (s, e, sStep, sCount) {
  19356. current = s;
  19357. end = e;
  19358. modBy = sStep;
  19359. modDataCount = sCount;
  19360. winCount = Math.ceil(modDataCount / modBy);
  19361. it.next = modBy > 1 && modDataCount > 0 ? modNext : sequentialNext;
  19362. }
  19363. };
  19364. return it;
  19365. function sequentialNext() {
  19366. return current < end ? current++ : null;
  19367. }
  19368. function modNext() {
  19369. var dataIndex = current % winCount * modBy + Math.ceil(current / winCount);
  19370. var result = current >= end ? null : dataIndex < modDataCount ? dataIndex // If modDataCount is smaller than data.count() (consider `appendData` case),
  19371. // Use normal linear rendering mode.
  19372. : current;
  19373. current++;
  19374. return result;
  19375. }
  19376. }(); ///////////////////////////////////////////////////////////
  19377. // For stream debug (Should be commented out after used!)
  19378. // @usage: printTask(this, 'begin');
  19379. // @usage: printTask(this, null, {someExtraProp});
  19380. // @usage: Use `__idxInPipeline` as conditional breakpiont.
  19381. //
  19382. // window.printTask = function (task: any, prefix: string, extra: { [key: string]: unknown }): void {
  19383. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  19384. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  19385. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  19386. // let props = [];
  19387. // if (task.__pipeline) {
  19388. // let val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  19389. // props.push({text: '__idxInPipeline/total', value: val});
  19390. // } else {
  19391. // let stubCount = 0;
  19392. // task.agentStubMap.each(() => stubCount++);
  19393. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  19394. // }
  19395. // props.push({text: 'uid', value: task.uidDebug});
  19396. // if (task.__pipeline) {
  19397. // props.push({text: 'pipelineId', value: task.__pipeline.id});
  19398. // task.agent && props.push(
  19399. // {text: 'stubFor', value: task.agent.uidDebug}
  19400. // );
  19401. // }
  19402. // props.push(
  19403. // {text: 'dirty', value: task._dirty},
  19404. // {text: 'dueIndex', value: task._dueIndex},
  19405. // {text: 'dueEnd', value: task._dueEnd},
  19406. // {text: 'outputDueEnd', value: task._outputDueEnd}
  19407. // );
  19408. // if (extra) {
  19409. // Object.keys(extra).forEach(key => {
  19410. // props.push({text: key, value: extra[key]});
  19411. // });
  19412. // }
  19413. // let args = ['color: blue'];
  19414. // let msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  19415. // args.push('color: green', 'color: red'),
  19416. // `${item.text}: %c${item.value}`
  19417. // )).join('%c, ');
  19418. // console.log.apply(console, [msg].concat(args));
  19419. // // console.log(this);
  19420. // };
  19421. // window.printPipeline = function (task: any, prefix: string) {
  19422. // const pipeline = task.__pipeline;
  19423. // let currTask = pipeline.head;
  19424. // while (currTask) {
  19425. // window.printTask(currTask, prefix);
  19426. // currTask = currTask._downstream;
  19427. // }
  19428. // };
  19429. // window.showChain = function (chainHeadTask) {
  19430. // var chain = [];
  19431. // var task = chainHeadTask;
  19432. // while (task) {
  19433. // chain.push({
  19434. // task: task,
  19435. // up: task._upstream,
  19436. // down: task._downstream,
  19437. // idxInPipeline: task.__idxInPipeline
  19438. // });
  19439. // task = task._downstream;
  19440. // }
  19441. // return chain;
  19442. // };
  19443. // window.findTaskInChain = function (task, chainHeadTask) {
  19444. // let chain = window.showChain(chainHeadTask);
  19445. // let result = [];
  19446. // for (let i = 0; i < chain.length; i++) {
  19447. // let chainItem = chain[i];
  19448. // if (chainItem.task === task) {
  19449. // result.push(i);
  19450. // }
  19451. // }
  19452. // return result;
  19453. // };
  19454. // window.printChainAEachInChainB = function (chainHeadTaskA, chainHeadTaskB) {
  19455. // let chainA = window.showChain(chainHeadTaskA);
  19456. // for (let i = 0; i < chainA.length; i++) {
  19457. // console.log('chainAIdx:', i, 'inChainB:', window.findTaskInChain(chainA[i].task, chainHeadTaskB));
  19458. // }
  19459. // };
  19460. /**
  19461. * Convert raw the value in to inner value in List.
  19462. *
  19463. * [Performance sensitive]
  19464. *
  19465. * [Caution]: this is the key logic of user value parser.
  19466. * For backward compatibiliy, do not modify it until have to!
  19467. */
  19468. function parseDataValue(value, // For high performance, do not omit the second param.
  19469. opt) {
  19470. // Performance sensitive.
  19471. var dimType = opt && opt.type;
  19472. if (dimType === 'ordinal') {
  19473. // If given value is a category string
  19474. return value;
  19475. }
  19476. if (dimType === 'time' // spead up when using timestamp
  19477. && typeof value !== 'number' && value != null && value !== '-') {
  19478. value = +parseDate(value);
  19479. } // dimType defaults 'number'.
  19480. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  19481. // parse to NaN.
  19482. // number-like string (like ' 123 ') can be converted to a number.
  19483. // where null/undefined or other string will be converted to NaN.
  19484. return value == null || value === '' ? NaN // If string (like '-'), using '+' parse to NaN
  19485. // If object, also parse to NaN
  19486. : +value;
  19487. }
  19488. var valueParserMap = createHashMap({
  19489. 'number': function (val) {
  19490. // Do not use `numericToNumber` here. We have by defualt `numericToNumber`.
  19491. // Here the number parser can have loose rule:
  19492. // enable to cut suffix: "120px" => 120, "14%" => 14.
  19493. return parseFloat(val);
  19494. },
  19495. 'time': function (val) {
  19496. // return timestamp.
  19497. return +parseDate(val);
  19498. },
  19499. 'trim': function (val) {
  19500. return typeof val === 'string' ? trim(val) : val;
  19501. }
  19502. });
  19503. var SortOrderComparator =
  19504. /** @class */
  19505. function () {
  19506. /**
  19507. * @param order by defualt: 'asc'
  19508. * @param incomparable by defualt: Always on the tail.
  19509. * That is, if 'asc' => 'max', if 'desc' => 'min'
  19510. * See the definition of "incomparable" in [SORT_COMPARISON_RULE]
  19511. */
  19512. function SortOrderComparator(order, incomparable) {
  19513. var isDesc = order === 'desc';
  19514. this._resultLT = isDesc ? 1 : -1;
  19515. if (incomparable == null) {
  19516. incomparable = isDesc ? 'min' : 'max';
  19517. }
  19518. this._incomparable = incomparable === 'min' ? -Infinity : Infinity;
  19519. } // See [SORT_COMPARISON_RULE].
  19520. // Performance sensitive.
  19521. SortOrderComparator.prototype.evaluate = function (lval, rval) {
  19522. // Most cases is 'number', and typeof maybe 10 times faseter than parseFloat.
  19523. var lvalTypeof = typeof lval;
  19524. var rvalTypeof = typeof rval;
  19525. var lvalFloat = lvalTypeof === 'number' ? lval : numericToNumber(lval);
  19526. var rvalFloat = rvalTypeof === 'number' ? rval : numericToNumber(rval);
  19527. var lvalNotNumeric = isNaN(lvalFloat);
  19528. var rvalNotNumeric = isNaN(rvalFloat);
  19529. if (lvalNotNumeric) {
  19530. lvalFloat = this._incomparable;
  19531. }
  19532. if (rvalNotNumeric) {
  19533. rvalFloat = this._incomparable;
  19534. }
  19535. if (lvalNotNumeric && rvalNotNumeric) {
  19536. var lvalIsStr = lvalTypeof === 'string';
  19537. var rvalIsStr = rvalTypeof === 'string';
  19538. if (lvalIsStr) {
  19539. lvalFloat = rvalIsStr ? lval : 0;
  19540. }
  19541. if (rvalIsStr) {
  19542. rvalFloat = lvalIsStr ? rval : 0;
  19543. }
  19544. }
  19545. return lvalFloat < rvalFloat ? this._resultLT : lvalFloat > rvalFloat ? -this._resultLT : 0;
  19546. };
  19547. return SortOrderComparator;
  19548. }();
  19549. /**
  19550. * TODO: disable writable.
  19551. * This structure will be exposed to users.
  19552. */
  19553. var ExternalSource =
  19554. /** @class */
  19555. function () {
  19556. function ExternalSource() {}
  19557. ExternalSource.prototype.getRawData = function () {
  19558. // Only built-in transform available.
  19559. throw new Error('not supported');
  19560. };
  19561. ExternalSource.prototype.getRawDataItem = function (dataIndex) {
  19562. // Only built-in transform available.
  19563. throw new Error('not supported');
  19564. };
  19565. ExternalSource.prototype.cloneRawData = function () {
  19566. return;
  19567. };
  19568. /**
  19569. * @return If dimension not found, return null/undefined.
  19570. */
  19571. ExternalSource.prototype.getDimensionInfo = function (dim) {
  19572. return;
  19573. };
  19574. /**
  19575. * dimensions defined if and only if either:
  19576. * (a) dataset.dimensions are declared.
  19577. * (b) dataset data include dimensions definitions in data (detected or via specified `sourceHeader`).
  19578. * If dimensions are defined, `dimensionInfoAll` is corresponding to
  19579. * the defined dimensions.
  19580. * Otherwise, `dimensionInfoAll` is determined by data columns.
  19581. * @return Always return an array (even empty array).
  19582. */
  19583. ExternalSource.prototype.cloneAllDimensionInfo = function () {
  19584. return;
  19585. };
  19586. ExternalSource.prototype.count = function () {
  19587. return;
  19588. };
  19589. /**
  19590. * Only support by dimension index.
  19591. * No need to support by dimension name in transform function,
  19592. * becuase transform function is not case-specific, no need to use name literally.
  19593. */
  19594. ExternalSource.prototype.retrieveValue = function (dataIndex, dimIndex) {
  19595. return;
  19596. };
  19597. ExternalSource.prototype.retrieveValueFromItem = function (dataItem, dimIndex) {
  19598. return;
  19599. };
  19600. ExternalSource.prototype.convertValue = function (rawVal, dimInfo) {
  19601. return parseDataValue(rawVal, dimInfo);
  19602. };
  19603. return ExternalSource;
  19604. }();
  19605. function createExternalSource(internalSource, externalTransform) {
  19606. var extSource = new ExternalSource();
  19607. var data = internalSource.data;
  19608. var sourceFormat = extSource.sourceFormat = internalSource.sourceFormat;
  19609. var sourceHeaderCount = internalSource.startIndex;
  19610. var errMsg = '';
  19611. if (internalSource.seriesLayoutBy !== SERIES_LAYOUT_BY_COLUMN) {
  19612. // For the logic simplicity in transformer, only 'culumn' is
  19613. // supported in data transform. Otherwise, the `dimensionsDefine`
  19614. // might be detected by 'row', which probably confuses users.
  19615. if ("development" !== 'production') {
  19616. errMsg = '`seriesLayoutBy` of upstream dataset can only be "column" in data transform.';
  19617. }
  19618. throwError(errMsg);
  19619. } // [MEMO]
  19620. // Create a new dimensions structure for exposing.
  19621. // Do not expose all dimension info to users directly.
  19622. // Becuase the dimension is probably auto detected from data and not might reliable.
  19623. // Should not lead the transformers to think that is relialbe and return it.
  19624. // See [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  19625. var dimensions = [];
  19626. var dimsByName = {};
  19627. var dimsDef = internalSource.dimensionsDefine;
  19628. if (dimsDef) {
  19629. each(dimsDef, function (dimDef, idx) {
  19630. var name = dimDef.name;
  19631. var dimDefExt = {
  19632. index: idx,
  19633. name: name,
  19634. displayName: dimDef.displayName
  19635. };
  19636. dimensions.push(dimDefExt); // Users probably not sepcify dimension name. For simplicity, data transform
  19637. // do not generate dimension name.
  19638. if (name != null) {
  19639. // Dimension name should not be duplicated.
  19640. // For simplicity, data transform forbid name duplication, do not generate
  19641. // new name like module `completeDimensions.ts` did, but just tell users.
  19642. var errMsg_1 = '';
  19643. if (hasOwn(dimsByName, name)) {
  19644. if ("development" !== 'production') {
  19645. errMsg_1 = 'dimension name "' + name + '" duplicated.';
  19646. }
  19647. throwError(errMsg_1);
  19648. }
  19649. dimsByName[name] = dimDefExt;
  19650. }
  19651. });
  19652. } // If dimension definitions are not defined and can not be detected.
  19653. // e.g., pure data `[[11, 22], ...]`.
  19654. else {
  19655. for (var i = 0; i < internalSource.dimensionsDetectedCount || 0; i++) {
  19656. // Do not generete name or anything others. The consequence process in
  19657. // `transform` or `series` probably have there own name generation strategry.
  19658. dimensions.push({
  19659. index: i
  19660. });
  19661. }
  19662. } // Implement public methods:
  19663. var rawItemGetter = getRawSourceItemGetter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  19664. if (externalTransform.__isBuiltIn) {
  19665. extSource.getRawDataItem = function (dataIndex) {
  19666. return rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  19667. };
  19668. extSource.getRawData = bind(getRawData, null, internalSource);
  19669. }
  19670. extSource.cloneRawData = bind(cloneRawData, null, internalSource);
  19671. var rawCounter = getRawSourceDataCounter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  19672. extSource.count = bind(rawCounter, null, data, sourceHeaderCount, dimensions);
  19673. var rawValueGetter = getRawSourceValueGetter(sourceFormat);
  19674. extSource.retrieveValue = function (dataIndex, dimIndex) {
  19675. var rawItem = rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  19676. return retrieveValueFromItem(rawItem, dimIndex);
  19677. };
  19678. var retrieveValueFromItem = extSource.retrieveValueFromItem = function (dataItem, dimIndex) {
  19679. if (dataItem == null) {
  19680. return;
  19681. }
  19682. var dimDef = dimensions[dimIndex]; // When `dimIndex` is `null`, `rawValueGetter` return the whole item.
  19683. if (dimDef) {
  19684. return rawValueGetter(dataItem, dimIndex, dimDef.name);
  19685. }
  19686. };
  19687. extSource.getDimensionInfo = bind(getDimensionInfo, null, dimensions, dimsByName);
  19688. extSource.cloneAllDimensionInfo = bind(cloneAllDimensionInfo, null, dimensions);
  19689. return extSource;
  19690. }
  19691. function getRawData(upstream) {
  19692. var sourceFormat = upstream.sourceFormat;
  19693. if (!isSupportedSourceFormat(sourceFormat)) {
  19694. var errMsg = '';
  19695. if ("development" !== 'production') {
  19696. errMsg = '`getRawData` is not supported in source format ' + sourceFormat;
  19697. }
  19698. throwError(errMsg);
  19699. }
  19700. return upstream.data;
  19701. }
  19702. function cloneRawData(upstream) {
  19703. var sourceFormat = upstream.sourceFormat;
  19704. var data = upstream.data;
  19705. if (!isSupportedSourceFormat(sourceFormat)) {
  19706. var errMsg = '';
  19707. if ("development" !== 'production') {
  19708. errMsg = '`cloneRawData` is not supported in source format ' + sourceFormat;
  19709. }
  19710. throwError(errMsg);
  19711. }
  19712. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  19713. var result = [];
  19714. for (var i = 0, len = data.length; i < len; i++) {
  19715. // Not strictly clone for performance
  19716. result.push(data[i].slice());
  19717. }
  19718. return result;
  19719. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  19720. var result = [];
  19721. for (var i = 0, len = data.length; i < len; i++) {
  19722. // Not strictly clone for performance
  19723. result.push(extend({}, data[i]));
  19724. }
  19725. return result;
  19726. }
  19727. }
  19728. function getDimensionInfo(dimensions, dimsByName, dim) {
  19729. if (dim == null) {
  19730. return;
  19731. } // Keep the same logic as `List::getDimension` did.
  19732. if (typeof dim === 'number' // If being a number-like string but not being defined a dimension name.
  19733. || !isNaN(dim) && !hasOwn(dimsByName, dim)) {
  19734. return dimensions[dim];
  19735. } else if (hasOwn(dimsByName, dim)) {
  19736. return dimsByName[dim];
  19737. }
  19738. }
  19739. function cloneAllDimensionInfo(dimensions) {
  19740. return clone(dimensions);
  19741. }
  19742. var externalTransformMap = createHashMap();
  19743. function registerExternalTransform(externalTransform) {
  19744. externalTransform = clone(externalTransform);
  19745. var type = externalTransform.type;
  19746. var errMsg = '';
  19747. if (!type) {
  19748. if ("development" !== 'production') {
  19749. errMsg = 'Must have a `type` when `registerTransform`.';
  19750. }
  19751. throwError(errMsg);
  19752. }
  19753. var typeParsed = type.split(':');
  19754. if (typeParsed.length !== 2) {
  19755. if ("development" !== 'production') {
  19756. errMsg = 'Name must include namespace like "ns:regression".';
  19757. }
  19758. throwError(errMsg);
  19759. } // Namespace 'echarts:xxx' is official namespace, where the transforms should
  19760. // be called directly via 'xxx' rather than 'echarts:xxx'.
  19761. var isBuiltIn = false;
  19762. if (typeParsed[0] === 'echarts') {
  19763. type = typeParsed[1];
  19764. isBuiltIn = true;
  19765. }
  19766. externalTransform.__isBuiltIn = isBuiltIn;
  19767. externalTransformMap.set(type, externalTransform);
  19768. }
  19769. function applyDataTransform(rawTransOption, sourceList, infoForPrint) {
  19770. var pipedTransOption = normalizeToArray(rawTransOption);
  19771. var pipeLen = pipedTransOption.length;
  19772. var errMsg = '';
  19773. if (!pipeLen) {
  19774. if ("development" !== 'production') {
  19775. errMsg = 'If `transform` declared, it should at least contain one transform.';
  19776. }
  19777. throwError(errMsg);
  19778. }
  19779. for (var i = 0, len = pipeLen; i < len; i++) {
  19780. var transOption = pipedTransOption[i];
  19781. sourceList = applySingleDataTransform(transOption, sourceList, infoForPrint, pipeLen === 1 ? null : i); // piped transform only support single input, except the fist one.
  19782. // piped transform only support single output, except the last one.
  19783. if (i !== len - 1) {
  19784. sourceList.length = Math.max(sourceList.length, 1);
  19785. }
  19786. }
  19787. return sourceList;
  19788. }
  19789. function applySingleDataTransform(transOption, upSourceList, infoForPrint, // If `pipeIndex` is null/undefined, no piped transform.
  19790. pipeIndex) {
  19791. var errMsg = '';
  19792. if (!upSourceList.length) {
  19793. if ("development" !== 'production') {
  19794. errMsg = 'Must have at least one upstream dataset.';
  19795. }
  19796. throwError(errMsg);
  19797. }
  19798. if (!isObject(transOption)) {
  19799. if ("development" !== 'production') {
  19800. errMsg = 'transform declaration must be an object rather than ' + typeof transOption + '.';
  19801. }
  19802. throwError(errMsg);
  19803. }
  19804. var transType = transOption.type;
  19805. var externalTransform = externalTransformMap.get(transType);
  19806. if (!externalTransform) {
  19807. if ("development" !== 'production') {
  19808. errMsg = 'Can not find transform on type "' + transType + '".';
  19809. }
  19810. throwError(errMsg);
  19811. } // Prepare source
  19812. var extUpSourceList = map(upSourceList, function (upSource) {
  19813. return createExternalSource(upSource, externalTransform);
  19814. });
  19815. var resultList = normalizeToArray(externalTransform.transform({
  19816. upstream: extUpSourceList[0],
  19817. upstreamList: extUpSourceList,
  19818. config: clone(transOption.config)
  19819. }));
  19820. if ("development" !== 'production') {
  19821. if (transOption.print) {
  19822. var printStrArr = map(resultList, function (extSource) {
  19823. var pipeIndexStr = pipeIndex != null ? ' === pipe index: ' + pipeIndex : '';
  19824. return ['=== dataset index: ' + infoForPrint.datasetIndex + pipeIndexStr + ' ===', '- transform result data:', makePrintable(extSource.data), '- transform result dimensions:', makePrintable(extSource.dimensions)].join('\n');
  19825. }).join('\n');
  19826. consoleLog(printStrArr);
  19827. }
  19828. }
  19829. return map(resultList, function (result, resultIndex) {
  19830. var errMsg = '';
  19831. if (!isObject(result)) {
  19832. if ("development" !== 'production') {
  19833. errMsg = 'A transform should not return some empty results.';
  19834. }
  19835. throwError(errMsg);
  19836. }
  19837. if (!result.data) {
  19838. if ("development" !== 'production') {
  19839. errMsg = 'Transform result data should be not be null or undefined';
  19840. }
  19841. throwError(errMsg);
  19842. }
  19843. var sourceFormat = detectSourceFormat(result.data);
  19844. if (!isSupportedSourceFormat(sourceFormat)) {
  19845. if ("development" !== 'production') {
  19846. errMsg = 'Transform result data should be array rows or object rows.';
  19847. }
  19848. throwError(errMsg);
  19849. }
  19850. var resultMetaRawOption;
  19851. var firstUpSource = upSourceList[0];
  19852. /**
  19853. * Intuitively, the end users known the content of the original `dataset.source`,
  19854. * calucating the transform result in mind.
  19855. * Suppose the original `dataset.source` is:
  19856. * ```js
  19857. * [
  19858. * ['product', '2012', '2013', '2014', '2015'],
  19859. * ['AAA', 41.1, 30.4, 65.1, 53.3],
  19860. * ['BBB', 86.5, 92.1, 85.7, 83.1],
  19861. * ['CCC', 24.1, 67.2, 79.5, 86.4]
  19862. * ]
  19863. * ```
  19864. * The dimension info have to be detected from the source data.
  19865. * Some of the transformers (like filter, sort) will follow the dimension info
  19866. * of upstream, while others use new dimensions (like aggregate).
  19867. * Transformer can output a field `dimensions` to define the its own output dimensions.
  19868. * We also allow transformers to ignore the output `dimensions` field, and
  19869. * inherit the upstream dimensions definition. It can reduce the burden of handling
  19870. * dimensions in transformers.
  19871. *
  19872. * See also [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  19873. */
  19874. if (firstUpSource && resultIndex === 0 // If transformer returns `dimensions`, it means that the transformer has different
  19875. // dimensions definitions. We do not inherit anything from upstream.
  19876. && !result.dimensions) {
  19877. var startIndex = firstUpSource.startIndex; // We copy the header of upstream to the result becuase:
  19878. // (1) The returned data always does not contain header line and can not be used
  19879. // as dimension-detection. In this case we can not use "detected dimensions" of
  19880. // upstream directly, because it might be detected based on different `seriesLayoutBy`.
  19881. // (2) We should support that the series read the upstream source in `seriesLayoutBy: 'row'`.
  19882. // So the original detected header should be add to the result, otherwise they can not be read.
  19883. if (startIndex) {
  19884. result.data = firstUpSource.data.slice(0, startIndex).concat(result.data);
  19885. }
  19886. resultMetaRawOption = {
  19887. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  19888. sourceHeader: startIndex,
  19889. dimensions: firstUpSource.metaRawOption.dimensions
  19890. };
  19891. } else {
  19892. resultMetaRawOption = {
  19893. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  19894. sourceHeader: 0,
  19895. dimensions: result.dimensions
  19896. };
  19897. }
  19898. return createSource(result.data, resultMetaRawOption, null);
  19899. });
  19900. }
  19901. function isSupportedSourceFormat(sourceFormat) {
  19902. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS || sourceFormat === SOURCE_FORMAT_OBJECT_ROWS;
  19903. }
  19904. var UNDEFINED = 'undefined';
  19905. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  19906. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  19907. // different from the Ctor of typed array.
  19908. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  19909. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  19910. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  19911. var CtorFloat64Array = typeof Float64Array === UNDEFINED ? Array : Float64Array;
  19912. /**
  19913. * Multi dimensional data store
  19914. */
  19915. var dataCtors = {
  19916. 'float': CtorFloat64Array,
  19917. 'int': CtorInt32Array,
  19918. // Ordinal data type can be string or int
  19919. 'ordinal': Array,
  19920. 'number': Array,
  19921. 'time': CtorFloat64Array
  19922. };
  19923. var defaultDimValueGetters;
  19924. function getIndicesCtor(rawCount) {
  19925. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  19926. return rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  19927. }
  19928. function getInitialExtent() {
  19929. return [Infinity, -Infinity];
  19930. }
  19931. function cloneChunk(originalChunk) {
  19932. var Ctor = originalChunk.constructor; // Only shallow clone is enough when Array.
  19933. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  19934. }
  19935. function prepareStore(store, dimIdx, dimType, end, append) {
  19936. var DataCtor = dataCtors[dimType || 'float'];
  19937. if (append) {
  19938. var oldStore = store[dimIdx];
  19939. var oldLen = oldStore && oldStore.length;
  19940. if (!(oldLen === end)) {
  19941. var newStore = new DataCtor(end); // The cost of the copy is probably inconsiderable
  19942. // within the initial chunkSize.
  19943. for (var j = 0; j < oldLen; j++) {
  19944. newStore[j] = oldStore[j];
  19945. }
  19946. store[dimIdx] = newStore;
  19947. }
  19948. } else {
  19949. store[dimIdx] = new DataCtor(end);
  19950. }
  19951. }
  19952. /**
  19953. * Basically, DataStore API keep immutable.
  19954. */
  19955. var DataStore =
  19956. /** @class */
  19957. function () {
  19958. function DataStore() {
  19959. this._chunks = []; // It will not be calculated util needed.
  19960. this._rawExtent = [];
  19961. this._extent = [];
  19962. this._count = 0;
  19963. this._rawCount = 0;
  19964. this._calcDimNameToIdx = createHashMap();
  19965. }
  19966. /**
  19967. * Initialize from data
  19968. */
  19969. DataStore.prototype.initData = function (provider, inputDimensions, dimValueGetter) {
  19970. if ("development" !== 'production') {
  19971. assert(isFunction(provider.getItem) && isFunction(provider.count), 'Inavlid data provider.');
  19972. }
  19973. this._provider = provider; // Clear
  19974. this._chunks = [];
  19975. this._indices = null;
  19976. this.getRawIndex = this._getRawIdxIdentity;
  19977. var source = provider.getSource();
  19978. var defaultGetter = this.defaultDimValueGetter = defaultDimValueGetters[source.sourceFormat]; // Default dim value getter
  19979. this._dimValueGetter = dimValueGetter || defaultGetter; // Reset raw extent.
  19980. this._rawExtent = [];
  19981. var willRetrieveDataByName = shouldRetrieveDataByName(source);
  19982. this._dimensions = map(inputDimensions, function (dim) {
  19983. if ("development" !== 'production') {
  19984. if (willRetrieveDataByName) {
  19985. assert(dim.property != null);
  19986. }
  19987. }
  19988. return {
  19989. // Only pick these two props. Not leak other properties like orderMeta.
  19990. type: dim.type,
  19991. property: dim.property
  19992. };
  19993. });
  19994. this._initDataFromProvider(0, provider.count());
  19995. };
  19996. DataStore.prototype.getProvider = function () {
  19997. return this._provider;
  19998. };
  19999. /**
  20000. * Caution: even when a `source` instance owned by a series, the created data store
  20001. * may still be shared by different sereis (the source hash does not use all `source`
  20002. * props, see `sourceManager`). In this case, the `source` props that are not used in
  20003. * hash (like `source.dimensionDefine`) probably only belongs to a certain series and
  20004. * thus should not be fetch here.
  20005. */
  20006. DataStore.prototype.getSource = function () {
  20007. return this._provider.getSource();
  20008. };
  20009. /**
  20010. * @caution Only used in dataStack.
  20011. */
  20012. DataStore.prototype.ensureCalculationDimension = function (dimName, type) {
  20013. var calcDimNameToIdx = this._calcDimNameToIdx;
  20014. var dimensions = this._dimensions;
  20015. var calcDimIdx = calcDimNameToIdx.get(dimName);
  20016. if (calcDimIdx != null) {
  20017. if (dimensions[calcDimIdx].type === type) {
  20018. return calcDimIdx;
  20019. }
  20020. } else {
  20021. calcDimIdx = dimensions.length;
  20022. }
  20023. dimensions[calcDimIdx] = {
  20024. type: type
  20025. };
  20026. calcDimNameToIdx.set(dimName, calcDimIdx);
  20027. this._chunks[calcDimIdx] = new dataCtors[type || 'float'](this._rawCount);
  20028. this._rawExtent[calcDimIdx] = getInitialExtent();
  20029. return calcDimIdx;
  20030. };
  20031. DataStore.prototype.collectOrdinalMeta = function (dimIdx, ordinalMeta) {
  20032. var chunk = this._chunks[dimIdx];
  20033. var dim = this._dimensions[dimIdx];
  20034. var rawExtents = this._rawExtent;
  20035. var offset = dim.ordinalOffset || 0;
  20036. var len = chunk.length;
  20037. if (offset === 0) {
  20038. // We need to reset the rawExtent if collect is from start.
  20039. // Because this dimension may be guessed as number and calcuating a wrong extent.
  20040. rawExtents[dimIdx] = getInitialExtent();
  20041. }
  20042. var dimRawExtent = rawExtents[dimIdx]; // Parse from previous data offset. len may be changed after appendData
  20043. for (var i = offset; i < len; i++) {
  20044. var val = chunk[i] = ordinalMeta.parseAndCollect(chunk[i]);
  20045. dimRawExtent[0] = Math.min(val, dimRawExtent[0]);
  20046. dimRawExtent[1] = Math.max(val, dimRawExtent[1]);
  20047. }
  20048. dim.ordinalMeta = ordinalMeta;
  20049. dim.ordinalOffset = len;
  20050. dim.type = 'ordinal'; // Force to be ordinal
  20051. };
  20052. DataStore.prototype.getOrdinalMeta = function (dimIdx) {
  20053. var dimInfo = this._dimensions[dimIdx];
  20054. var ordinalMeta = dimInfo.ordinalMeta;
  20055. return ordinalMeta;
  20056. };
  20057. DataStore.prototype.getDimensionProperty = function (dimIndex) {
  20058. var item = this._dimensions[dimIndex];
  20059. return item && item.property;
  20060. };
  20061. /**
  20062. * Caution: Can be only called on raw data (before `this._indices` created).
  20063. */
  20064. DataStore.prototype.appendData = function (data) {
  20065. if ("development" !== 'production') {
  20066. assert(!this._indices, 'appendData can only be called on raw data.');
  20067. }
  20068. var provider = this._provider;
  20069. var start = this.count();
  20070. provider.appendData(data);
  20071. var end = provider.count();
  20072. if (!provider.persistent) {
  20073. end += start;
  20074. }
  20075. if (start < end) {
  20076. this._initDataFromProvider(start, end, true);
  20077. }
  20078. return [start, end];
  20079. };
  20080. DataStore.prototype.appendValues = function (values, minFillLen) {
  20081. var chunks = this._chunks;
  20082. var dimensions = this._dimensions;
  20083. var dimLen = dimensions.length;
  20084. var rawExtent = this._rawExtent;
  20085. var start = this.count();
  20086. var end = start + Math.max(values.length, minFillLen || 0);
  20087. for (var i = 0; i < dimLen; i++) {
  20088. var dim = dimensions[i];
  20089. prepareStore(chunks, i, dim.type, end, true);
  20090. }
  20091. var emptyDataItem = [];
  20092. for (var idx = start; idx < end; idx++) {
  20093. var sourceIdx = idx - start; // Store the data by dimensions
  20094. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  20095. var dim = dimensions[dimIdx];
  20096. var val = defaultDimValueGetters.arrayRows.call(this, values[sourceIdx] || emptyDataItem, dim.property, sourceIdx, dimIdx);
  20097. chunks[dimIdx][idx] = val;
  20098. var dimRawExtent = rawExtent[dimIdx];
  20099. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  20100. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  20101. }
  20102. }
  20103. this._rawCount = this._count = end;
  20104. return {
  20105. start: start,
  20106. end: end
  20107. };
  20108. };
  20109. DataStore.prototype._initDataFromProvider = function (start, end, append) {
  20110. var provider = this._provider;
  20111. var chunks = this._chunks;
  20112. var dimensions = this._dimensions;
  20113. var dimLen = dimensions.length;
  20114. var rawExtent = this._rawExtent;
  20115. var dimNames = map(dimensions, function (dim) {
  20116. return dim.property;
  20117. });
  20118. for (var i = 0; i < dimLen; i++) {
  20119. var dim = dimensions[i];
  20120. if (!rawExtent[i]) {
  20121. rawExtent[i] = getInitialExtent();
  20122. }
  20123. prepareStore(chunks, i, dim.type, end, append);
  20124. }
  20125. if (provider.fillStorage) {
  20126. provider.fillStorage(start, end, chunks, rawExtent);
  20127. } else {
  20128. var dataItem = [];
  20129. for (var idx = start; idx < end; idx++) {
  20130. // NOTICE: Try not to write things into dataItem
  20131. dataItem = provider.getItem(idx, dataItem); // Each data item is value
  20132. // [1, 2]
  20133. // 2
  20134. // Bar chart, line chart which uses category axis
  20135. // only gives the 'y' value. 'x' value is the indices of category
  20136. // Use a tempValue to normalize the value to be a (x, y) value
  20137. // Store the data by dimensions
  20138. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  20139. var dimStorage = chunks[dimIdx]; // PENDING NULL is empty or zero
  20140. var val = this._dimValueGetter(dataItem, dimNames[dimIdx], idx, dimIdx);
  20141. dimStorage[idx] = val;
  20142. var dimRawExtent = rawExtent[dimIdx];
  20143. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  20144. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  20145. }
  20146. }
  20147. }
  20148. if (!provider.persistent && provider.clean) {
  20149. // Clean unused data if data source is typed array.
  20150. provider.clean();
  20151. }
  20152. this._rawCount = this._count = end; // Reset data extent
  20153. this._extent = [];
  20154. };
  20155. DataStore.prototype.count = function () {
  20156. return this._count;
  20157. };
  20158. /**
  20159. * Get value. Return NaN if idx is out of range.
  20160. */
  20161. DataStore.prototype.get = function (dim, idx) {
  20162. if (!(idx >= 0 && idx < this._count)) {
  20163. return NaN;
  20164. }
  20165. var dimStore = this._chunks[dim];
  20166. return dimStore ? dimStore[this.getRawIndex(idx)] : NaN;
  20167. };
  20168. DataStore.prototype.getValues = function (dimensions, idx) {
  20169. var values = [];
  20170. var dimArr = [];
  20171. if (idx == null) {
  20172. idx = dimensions; // TODO get all from store?
  20173. dimensions = []; // All dimensions
  20174. for (var i = 0; i < this._dimensions.length; i++) {
  20175. dimArr.push(i);
  20176. }
  20177. } else {
  20178. dimArr = dimensions;
  20179. }
  20180. for (var i = 0, len = dimArr.length; i < len; i++) {
  20181. values.push(this.get(dimArr[i], idx));
  20182. }
  20183. return values;
  20184. };
  20185. /**
  20186. * @param dim concrete dim
  20187. */
  20188. DataStore.prototype.getByRawIndex = function (dim, rawIdx) {
  20189. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  20190. return NaN;
  20191. }
  20192. var dimStore = this._chunks[dim];
  20193. return dimStore ? dimStore[rawIdx] : NaN;
  20194. };
  20195. /**
  20196. * Get sum of data in one dimension
  20197. */
  20198. DataStore.prototype.getSum = function (dim) {
  20199. var dimData = this._chunks[dim];
  20200. var sum = 0;
  20201. if (dimData) {
  20202. for (var i = 0, len = this.count(); i < len; i++) {
  20203. var value = this.get(dim, i);
  20204. if (!isNaN(value)) {
  20205. sum += value;
  20206. }
  20207. }
  20208. }
  20209. return sum;
  20210. };
  20211. /**
  20212. * Get median of data in one dimension
  20213. */
  20214. DataStore.prototype.getMedian = function (dim) {
  20215. var dimDataArray = []; // map all data of one dimension
  20216. this.each([dim], function (val) {
  20217. if (!isNaN(val)) {
  20218. dimDataArray.push(val);
  20219. }
  20220. }); // TODO
  20221. // Use quick select?
  20222. var sortedDimDataArray = dimDataArray.sort(function (a, b) {
  20223. return a - b;
  20224. });
  20225. var len = this.count(); // calculate median
  20226. return len === 0 ? 0 : len % 2 === 1 ? sortedDimDataArray[(len - 1) / 2] : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  20227. };
  20228. /**
  20229. * Retreive the index with given raw data index
  20230. */
  20231. DataStore.prototype.indexOfRawIndex = function (rawIndex) {
  20232. if (rawIndex >= this._rawCount || rawIndex < 0) {
  20233. return -1;
  20234. }
  20235. if (!this._indices) {
  20236. return rawIndex;
  20237. } // Indices are ascending
  20238. var indices = this._indices; // If rawIndex === dataIndex
  20239. var rawDataIndex = indices[rawIndex];
  20240. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  20241. return rawIndex;
  20242. }
  20243. var left = 0;
  20244. var right = this._count - 1;
  20245. while (left <= right) {
  20246. var mid = (left + right) / 2 | 0;
  20247. if (indices[mid] < rawIndex) {
  20248. left = mid + 1;
  20249. } else if (indices[mid] > rawIndex) {
  20250. right = mid - 1;
  20251. } else {
  20252. return mid;
  20253. }
  20254. }
  20255. return -1;
  20256. };
  20257. /**
  20258. * Retreive the index of nearest value
  20259. * @param dim
  20260. * @param value
  20261. * @param [maxDistance=Infinity]
  20262. * @return If and only if multiple indices has
  20263. * the same value, they are put to the result.
  20264. */
  20265. DataStore.prototype.indicesOfNearest = function (dim, value, maxDistance) {
  20266. var chunks = this._chunks;
  20267. var dimData = chunks[dim];
  20268. var nearestIndices = [];
  20269. if (!dimData) {
  20270. return nearestIndices;
  20271. }
  20272. if (maxDistance == null) {
  20273. maxDistance = Infinity;
  20274. }
  20275. var minDist = Infinity;
  20276. var minDiff = -1;
  20277. var nearestIndicesLen = 0; // Check the test case of `test/ut/spec/data/SeriesData.js`.
  20278. for (var i = 0, len = this.count(); i < len; i++) {
  20279. var dataIndex = this.getRawIndex(i);
  20280. var diff = value - dimData[dataIndex];
  20281. var dist = Math.abs(diff);
  20282. if (dist <= maxDistance) {
  20283. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  20284. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  20285. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  20286. // So we chose the one that `diff >= 0` in this csae.
  20287. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  20288. // should be push to `nearestIndices`.
  20289. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  20290. minDist = dist;
  20291. minDiff = diff;
  20292. nearestIndicesLen = 0;
  20293. }
  20294. if (diff === minDiff) {
  20295. nearestIndices[nearestIndicesLen++] = i;
  20296. }
  20297. }
  20298. }
  20299. nearestIndices.length = nearestIndicesLen;
  20300. return nearestIndices;
  20301. };
  20302. DataStore.prototype.getIndices = function () {
  20303. var newIndices;
  20304. var indices = this._indices;
  20305. if (indices) {
  20306. var Ctor = indices.constructor;
  20307. var thisCount = this._count; // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  20308. if (Ctor === Array) {
  20309. newIndices = new Ctor(thisCount);
  20310. for (var i = 0; i < thisCount; i++) {
  20311. newIndices[i] = indices[i];
  20312. }
  20313. } else {
  20314. newIndices = new Ctor(indices.buffer, 0, thisCount);
  20315. }
  20316. } else {
  20317. var Ctor = getIndicesCtor(this._rawCount);
  20318. newIndices = new Ctor(this.count());
  20319. for (var i = 0; i < newIndices.length; i++) {
  20320. newIndices[i] = i;
  20321. }
  20322. }
  20323. return newIndices;
  20324. };
  20325. /**
  20326. * Data filter.
  20327. */
  20328. DataStore.prototype.filter = function (dims, cb) {
  20329. if (!this._count) {
  20330. return this;
  20331. }
  20332. var newStore = this.clone();
  20333. var count = newStore.count();
  20334. var Ctor = getIndicesCtor(newStore._rawCount);
  20335. var newIndices = new Ctor(count);
  20336. var value = [];
  20337. var dimSize = dims.length;
  20338. var offset = 0;
  20339. var dim0 = dims[0];
  20340. var chunks = newStore._chunks;
  20341. for (var i = 0; i < count; i++) {
  20342. var keep = void 0;
  20343. var rawIdx = newStore.getRawIndex(i); // Simple optimization
  20344. if (dimSize === 0) {
  20345. keep = cb(i);
  20346. } else if (dimSize === 1) {
  20347. var val = chunks[dim0][rawIdx];
  20348. keep = cb(val, i);
  20349. } else {
  20350. var k = 0;
  20351. for (; k < dimSize; k++) {
  20352. value[k] = chunks[dims[k]][rawIdx];
  20353. }
  20354. value[k] = i;
  20355. keep = cb.apply(null, value);
  20356. }
  20357. if (keep) {
  20358. newIndices[offset++] = rawIdx;
  20359. }
  20360. } // Set indices after filtered.
  20361. if (offset < count) {
  20362. newStore._indices = newIndices;
  20363. }
  20364. newStore._count = offset; // Reset data extent
  20365. newStore._extent = [];
  20366. newStore._updateGetRawIdx();
  20367. return newStore;
  20368. };
  20369. /**
  20370. * Select data in range. (For optimization of filter)
  20371. * (Manually inline code, support 5 million data filtering in data zoom.)
  20372. */
  20373. DataStore.prototype.selectRange = function (range) {
  20374. var newStore = this.clone();
  20375. var len = newStore._count;
  20376. if (!len) {
  20377. return this;
  20378. }
  20379. var dims = keys(range);
  20380. var dimSize = dims.length;
  20381. if (!dimSize) {
  20382. return this;
  20383. }
  20384. var originalCount = newStore.count();
  20385. var Ctor = getIndicesCtor(newStore._rawCount);
  20386. var newIndices = new Ctor(originalCount);
  20387. var offset = 0;
  20388. var dim0 = dims[0];
  20389. var min = range[dim0][0];
  20390. var max = range[dim0][1];
  20391. var storeArr = newStore._chunks;
  20392. var quickFinished = false;
  20393. if (!newStore._indices) {
  20394. // Extreme optimization for common case. About 2x faster in chrome.
  20395. var idx = 0;
  20396. if (dimSize === 1) {
  20397. var dimStorage = storeArr[dims[0]];
  20398. for (var i = 0; i < len; i++) {
  20399. var val = dimStorage[i]; // NaN will not be filtered. Consider the case, in line chart, empty
  20400. // value indicates the line should be broken. But for the case like
  20401. // scatter plot, a data item with empty value will not be rendered,
  20402. // but the axis extent may be effected if some other dim of the data
  20403. // item has value. Fortunately it is not a significant negative effect.
  20404. if (val >= min && val <= max || isNaN(val)) {
  20405. newIndices[offset++] = idx;
  20406. }
  20407. idx++;
  20408. }
  20409. quickFinished = true;
  20410. } else if (dimSize === 2) {
  20411. var dimStorage = storeArr[dims[0]];
  20412. var dimStorage2 = storeArr[dims[1]];
  20413. var min2 = range[dims[1]][0];
  20414. var max2 = range[dims[1]][1];
  20415. for (var i = 0; i < len; i++) {
  20416. var val = dimStorage[i];
  20417. var val2 = dimStorage2[i]; // Do not filter NaN, see comment above.
  20418. if ((val >= min && val <= max || isNaN(val)) && (val2 >= min2 && val2 <= max2 || isNaN(val2))) {
  20419. newIndices[offset++] = idx;
  20420. }
  20421. idx++;
  20422. }
  20423. quickFinished = true;
  20424. }
  20425. }
  20426. if (!quickFinished) {
  20427. if (dimSize === 1) {
  20428. for (var i = 0; i < originalCount; i++) {
  20429. var rawIndex = newStore.getRawIndex(i);
  20430. var val = storeArr[dims[0]][rawIndex]; // Do not filter NaN, see comment above.
  20431. if (val >= min && val <= max || isNaN(val)) {
  20432. newIndices[offset++] = rawIndex;
  20433. }
  20434. }
  20435. } else {
  20436. for (var i = 0; i < originalCount; i++) {
  20437. var keep = true;
  20438. var rawIndex = newStore.getRawIndex(i);
  20439. for (var k = 0; k < dimSize; k++) {
  20440. var dimk = dims[k];
  20441. var val = storeArr[dimk][rawIndex]; // Do not filter NaN, see comment above.
  20442. if (val < range[dimk][0] || val > range[dimk][1]) {
  20443. keep = false;
  20444. }
  20445. }
  20446. if (keep) {
  20447. newIndices[offset++] = newStore.getRawIndex(i);
  20448. }
  20449. }
  20450. }
  20451. } // Set indices after filtered.
  20452. if (offset < originalCount) {
  20453. newStore._indices = newIndices;
  20454. }
  20455. newStore._count = offset; // Reset data extent
  20456. newStore._extent = [];
  20457. newStore._updateGetRawIdx();
  20458. return newStore;
  20459. }; // /**
  20460. // * Data mapping to a plain array
  20461. // */
  20462. // mapArray(dims: DimensionIndex[], cb: MapArrayCb): any[] {
  20463. // const result: any[] = [];
  20464. // this.each(dims, function () {
  20465. // result.push(cb && (cb as MapArrayCb).apply(null, arguments));
  20466. // });
  20467. // return result;
  20468. // }
  20469. /**
  20470. * Data mapping to a new List with given dimensions
  20471. */
  20472. DataStore.prototype.map = function (dims, cb) {
  20473. // TODO only clone picked chunks.
  20474. var target = this.clone(dims);
  20475. this._updateDims(target, dims, cb);
  20476. return target;
  20477. };
  20478. /**
  20479. * @caution Danger!! Only used in dataStack.
  20480. */
  20481. DataStore.prototype.modify = function (dims, cb) {
  20482. this._updateDims(this, dims, cb);
  20483. };
  20484. DataStore.prototype._updateDims = function (target, dims, cb) {
  20485. var targetChunks = target._chunks;
  20486. var tmpRetValue = [];
  20487. var dimSize = dims.length;
  20488. var dataCount = target.count();
  20489. var values = [];
  20490. var rawExtent = target._rawExtent;
  20491. for (var i = 0; i < dims.length; i++) {
  20492. rawExtent[dims[i]] = getInitialExtent();
  20493. }
  20494. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  20495. var rawIndex = target.getRawIndex(dataIndex);
  20496. for (var k = 0; k < dimSize; k++) {
  20497. values[k] = targetChunks[dims[k]][rawIndex];
  20498. }
  20499. values[dimSize] = dataIndex;
  20500. var retValue = cb && cb.apply(null, values);
  20501. if (retValue != null) {
  20502. // a number or string (in oridinal dimension)?
  20503. if (typeof retValue !== 'object') {
  20504. tmpRetValue[0] = retValue;
  20505. retValue = tmpRetValue;
  20506. }
  20507. for (var i = 0; i < retValue.length; i++) {
  20508. var dim = dims[i];
  20509. var val = retValue[i];
  20510. var rawExtentOnDim = rawExtent[dim];
  20511. var dimStore = targetChunks[dim];
  20512. if (dimStore) {
  20513. dimStore[rawIndex] = val;
  20514. }
  20515. if (val < rawExtentOnDim[0]) {
  20516. rawExtentOnDim[0] = val;
  20517. }
  20518. if (val > rawExtentOnDim[1]) {
  20519. rawExtentOnDim[1] = val;
  20520. }
  20521. }
  20522. }
  20523. }
  20524. };
  20525. /**
  20526. * Large data down sampling using largest-triangle-three-buckets
  20527. * @param {string} valueDimension
  20528. * @param {number} targetCount
  20529. */
  20530. DataStore.prototype.lttbDownSample = function (valueDimension, rate) {
  20531. var target = this.clone([valueDimension], true);
  20532. var targetStorage = target._chunks;
  20533. var dimStore = targetStorage[valueDimension];
  20534. var len = this.count();
  20535. var sampledIndex = 0;
  20536. var frameSize = Math.floor(1 / rate);
  20537. var currentRawIndex = this.getRawIndex(0);
  20538. var maxArea;
  20539. var area;
  20540. var nextRawIndex;
  20541. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize) + 2); // First frame use the first data.
  20542. newIndices[sampledIndex++] = currentRawIndex;
  20543. for (var i = 1; i < len - 1; i += frameSize) {
  20544. var nextFrameStart = Math.min(i + frameSize, len - 1);
  20545. var nextFrameEnd = Math.min(i + frameSize * 2, len);
  20546. var avgX = (nextFrameEnd + nextFrameStart) / 2;
  20547. var avgY = 0;
  20548. for (var idx = nextFrameStart; idx < nextFrameEnd; idx++) {
  20549. var rawIndex = this.getRawIndex(idx);
  20550. var y = dimStore[rawIndex];
  20551. if (isNaN(y)) {
  20552. continue;
  20553. }
  20554. avgY += y;
  20555. }
  20556. avgY /= nextFrameEnd - nextFrameStart;
  20557. var frameStart = i;
  20558. var frameEnd = Math.min(i + frameSize, len);
  20559. var pointAX = i - 1;
  20560. var pointAY = dimStore[currentRawIndex];
  20561. maxArea = -1;
  20562. nextRawIndex = frameStart; // Find a point from current frame that construct a triangel with largest area with previous selected point
  20563. // And the average of next frame.
  20564. for (var idx = frameStart; idx < frameEnd; idx++) {
  20565. var rawIndex = this.getRawIndex(idx);
  20566. var y = dimStore[rawIndex];
  20567. if (isNaN(y)) {
  20568. continue;
  20569. } // Calculate triangle area over three buckets
  20570. area = Math.abs((pointAX - avgX) * (y - pointAY) - (pointAX - idx) * (avgY - pointAY));
  20571. if (area > maxArea) {
  20572. maxArea = area;
  20573. nextRawIndex = rawIndex; // Next a is this b
  20574. }
  20575. }
  20576. newIndices[sampledIndex++] = nextRawIndex;
  20577. currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
  20578. } // First frame use the last data.
  20579. newIndices[sampledIndex++] = this.getRawIndex(len - 1);
  20580. target._count = sampledIndex;
  20581. target._indices = newIndices;
  20582. target.getRawIndex = this._getRawIdx;
  20583. return target;
  20584. };
  20585. /**
  20586. * Large data down sampling on given dimension
  20587. * @param sampleIndex Sample index for name and id
  20588. */
  20589. DataStore.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  20590. var target = this.clone([dimension], true);
  20591. var targetStorage = target._chunks;
  20592. var frameValues = [];
  20593. var frameSize = Math.floor(1 / rate);
  20594. var dimStore = targetStorage[dimension];
  20595. var len = this.count();
  20596. var rawExtentOnDim = target._rawExtent[dimension] = getInitialExtent();
  20597. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize));
  20598. var offset = 0;
  20599. for (var i = 0; i < len; i += frameSize) {
  20600. // Last frame
  20601. if (frameSize > len - i) {
  20602. frameSize = len - i;
  20603. frameValues.length = frameSize;
  20604. }
  20605. for (var k = 0; k < frameSize; k++) {
  20606. var dataIdx = this.getRawIndex(i + k);
  20607. frameValues[k] = dimStore[dataIdx];
  20608. }
  20609. var value = sampleValue(frameValues);
  20610. var sampleFrameIdx = this.getRawIndex(Math.min(i + sampleIndex(frameValues, value) || 0, len - 1)); // Only write value on the filtered data
  20611. dimStore[sampleFrameIdx] = value;
  20612. if (value < rawExtentOnDim[0]) {
  20613. rawExtentOnDim[0] = value;
  20614. }
  20615. if (value > rawExtentOnDim[1]) {
  20616. rawExtentOnDim[1] = value;
  20617. }
  20618. newIndices[offset++] = sampleFrameIdx;
  20619. }
  20620. target._count = offset;
  20621. target._indices = newIndices;
  20622. target._updateGetRawIdx();
  20623. return target;
  20624. };
  20625. /**
  20626. * Data iteration
  20627. * @param ctx default this
  20628. * @example
  20629. * list.each('x', function (x, idx) {});
  20630. * list.each(['x', 'y'], function (x, y, idx) {});
  20631. * list.each(function (idx) {})
  20632. */
  20633. DataStore.prototype.each = function (dims, cb) {
  20634. if (!this._count) {
  20635. return;
  20636. }
  20637. var dimSize = dims.length;
  20638. var chunks = this._chunks;
  20639. for (var i = 0, len = this.count(); i < len; i++) {
  20640. var rawIdx = this.getRawIndex(i); // Simple optimization
  20641. switch (dimSize) {
  20642. case 0:
  20643. cb(i);
  20644. break;
  20645. case 1:
  20646. cb(chunks[dims[0]][rawIdx], i);
  20647. break;
  20648. case 2:
  20649. cb(chunks[dims[0]][rawIdx], chunks[dims[1]][rawIdx], i);
  20650. break;
  20651. default:
  20652. var k = 0;
  20653. var value = [];
  20654. for (; k < dimSize; k++) {
  20655. value[k] = chunks[dims[k]][rawIdx];
  20656. } // Index
  20657. value[k] = i;
  20658. cb.apply(null, value);
  20659. }
  20660. }
  20661. };
  20662. /**
  20663. * Get extent of data in one dimension
  20664. */
  20665. DataStore.prototype.getDataExtent = function (dim) {
  20666. // Make sure use concrete dim as cache name.
  20667. var dimData = this._chunks[dim];
  20668. var initialExtent = getInitialExtent();
  20669. if (!dimData) {
  20670. return initialExtent;
  20671. } // Make more strict checkings to ensure hitting cache.
  20672. var currEnd = this.count(); // Consider the most cases when using data zoom, `getDataExtent`
  20673. // happened before filtering. We cache raw extent, which is not
  20674. // necessary to be cleared and recalculated when restore data.
  20675. var useRaw = !this._indices;
  20676. var dimExtent;
  20677. if (useRaw) {
  20678. return this._rawExtent[dim].slice();
  20679. }
  20680. dimExtent = this._extent[dim];
  20681. if (dimExtent) {
  20682. return dimExtent.slice();
  20683. }
  20684. dimExtent = initialExtent;
  20685. var min = dimExtent[0];
  20686. var max = dimExtent[1];
  20687. for (var i = 0; i < currEnd; i++) {
  20688. var rawIdx = this.getRawIndex(i);
  20689. var value = dimData[rawIdx];
  20690. value < min && (min = value);
  20691. value > max && (max = value);
  20692. }
  20693. dimExtent = [min, max];
  20694. this._extent[dim] = dimExtent;
  20695. return dimExtent;
  20696. };
  20697. /**
  20698. * Get raw data item
  20699. */
  20700. DataStore.prototype.getRawDataItem = function (idx) {
  20701. var rawIdx = this.getRawIndex(idx);
  20702. if (!this._provider.persistent) {
  20703. var val = [];
  20704. var chunks = this._chunks;
  20705. for (var i = 0; i < chunks.length; i++) {
  20706. val.push(chunks[i][rawIdx]);
  20707. }
  20708. return val;
  20709. } else {
  20710. return this._provider.getItem(rawIdx);
  20711. }
  20712. };
  20713. /**
  20714. * Clone shallow.
  20715. *
  20716. * @param clonedDims Determine which dims to clone. Will share the data if not specified.
  20717. */
  20718. DataStore.prototype.clone = function (clonedDims, ignoreIndices) {
  20719. var target = new DataStore();
  20720. var chunks = this._chunks;
  20721. var clonedDimsMap = clonedDims && reduce(clonedDims, function (obj, dimIdx) {
  20722. obj[dimIdx] = true;
  20723. return obj;
  20724. }, {});
  20725. if (clonedDimsMap) {
  20726. for (var i = 0; i < chunks.length; i++) {
  20727. // Not clone if dim is not picked.
  20728. target._chunks[i] = !clonedDimsMap[i] ? chunks[i] : cloneChunk(chunks[i]);
  20729. }
  20730. } else {
  20731. target._chunks = chunks;
  20732. }
  20733. this._copyCommonProps(target);
  20734. if (!ignoreIndices) {
  20735. target._indices = this._cloneIndices();
  20736. }
  20737. target._updateGetRawIdx();
  20738. return target;
  20739. };
  20740. DataStore.prototype._copyCommonProps = function (target) {
  20741. target._count = this._count;
  20742. target._rawCount = this._rawCount;
  20743. target._provider = this._provider;
  20744. target._dimensions = this._dimensions;
  20745. target._extent = clone(this._extent);
  20746. target._rawExtent = clone(this._rawExtent);
  20747. };
  20748. DataStore.prototype._cloneIndices = function () {
  20749. if (this._indices) {
  20750. var Ctor = this._indices.constructor;
  20751. var indices = void 0;
  20752. if (Ctor === Array) {
  20753. var thisCount = this._indices.length;
  20754. indices = new Ctor(thisCount);
  20755. for (var i = 0; i < thisCount; i++) {
  20756. indices[i] = this._indices[i];
  20757. }
  20758. } else {
  20759. indices = new Ctor(this._indices);
  20760. }
  20761. return indices;
  20762. }
  20763. return null;
  20764. };
  20765. DataStore.prototype._getRawIdxIdentity = function (idx) {
  20766. return idx;
  20767. };
  20768. DataStore.prototype._getRawIdx = function (idx) {
  20769. if (idx < this._count && idx >= 0) {
  20770. return this._indices[idx];
  20771. }
  20772. return -1;
  20773. };
  20774. DataStore.prototype._updateGetRawIdx = function () {
  20775. this.getRawIndex = this._indices ? this._getRawIdx : this._getRawIdxIdentity;
  20776. };
  20777. DataStore.internalField = function () {
  20778. function getDimValueSimply(dataItem, property, dataIndex, dimIndex) {
  20779. return parseDataValue(dataItem[dimIndex], this._dimensions[dimIndex]);
  20780. }
  20781. defaultDimValueGetters = {
  20782. arrayRows: getDimValueSimply,
  20783. objectRows: function (dataItem, property, dataIndex, dimIndex) {
  20784. return parseDataValue(dataItem[property], this._dimensions[dimIndex]);
  20785. },
  20786. keyedColumns: getDimValueSimply,
  20787. original: function (dataItem, property, dataIndex, dimIndex) {
  20788. // Performance sensitive, do not use modelUtil.getDataItemValue.
  20789. // If dataItem is an plain object with no value field, the let `value`
  20790. // will be assigned with the object, but it will be tread correctly
  20791. // in the `convertValue`.
  20792. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  20793. return parseDataValue(value instanceof Array ? value[dimIndex] // If value is a single number or something else not array.
  20794. : value, this._dimensions[dimIndex]);
  20795. },
  20796. typedArray: function (dataItem, property, dataIndex, dimIndex) {
  20797. return dataItem[dimIndex];
  20798. }
  20799. };
  20800. }();
  20801. return DataStore;
  20802. }();
  20803. /**
  20804. * [REQUIREMENT_MEMO]:
  20805. * (0) `metaRawOption` means `dimensions`/`sourceHeader`/`seriesLayoutBy` in raw option.
  20806. * (1) Keep support the feature: `metaRawOption` can be specified both on `series` and
  20807. * `root-dataset`. Them on `series` has higher priority.
  20808. * (2) Do not support to set `metaRawOption` on a `non-root-dataset`, because it might
  20809. * confuse users: whether those props indicate how to visit the upstream source or visit
  20810. * the transform result source, and some transforms has nothing to do with these props,
  20811. * and some transforms might have multiple upstream.
  20812. * (3) Transforms should specify `metaRawOption` in each output, just like they can be
  20813. * declared in `root-dataset`.
  20814. * (4) At present only support visit source in `SERIES_LAYOUT_BY_COLUMN` in transforms.
  20815. * That is for reducing complexity in transfroms.
  20816. * PENDING: Whether to provide transposition transform?
  20817. *
  20818. * [IMPLEMENTAION_MEMO]:
  20819. * "sourceVisitConfig" are calculated from `metaRawOption` and `data`.
  20820. * They will not be calculated until `source` is about to be visited (to prevent from
  20821. * duplicate calcuation). `source` is visited only in series and input to transforms.
  20822. *
  20823. * [DIMENSION_INHERIT_RULE]:
  20824. * By default the dimensions are inherited from ancestors, unless a transform return
  20825. * a new dimensions definition.
  20826. * Consider the case:
  20827. * ```js
  20828. * dataset: [{
  20829. * source: [ ['Product', 'Sales', 'Prise'], ['Cookies', 321, 44.21], ...]
  20830. * }, {
  20831. * transform: { type: 'filter', ... }
  20832. * }]
  20833. * dataset: [{
  20834. * dimension: ['Product', 'Sales', 'Prise'],
  20835. * source: [ ['Cookies', 321, 44.21], ...]
  20836. * }, {
  20837. * transform: { type: 'filter', ... }
  20838. * }]
  20839. * ```
  20840. * The two types of option should have the same behavior after transform.
  20841. *
  20842. *
  20843. * [SCENARIO]:
  20844. * (1) Provide source data directly:
  20845. * ```js
  20846. * series: {
  20847. * encode: {...},
  20848. * dimensions: [...]
  20849. * seriesLayoutBy: 'row',
  20850. * data: [[...]]
  20851. * }
  20852. * ```
  20853. * (2) Series refer to dataset.
  20854. * ```js
  20855. * series: [{
  20856. * encode: {...}
  20857. * // Ignore datasetIndex means `datasetIndex: 0`
  20858. * // and the dimensions defination in dataset is used
  20859. * }, {
  20860. * encode: {...},
  20861. * seriesLayoutBy: 'column',
  20862. * datasetIndex: 1
  20863. * }]
  20864. * ```
  20865. * (3) dataset transform
  20866. * ```js
  20867. * dataset: [{
  20868. * source: [...]
  20869. * }, {
  20870. * source: [...]
  20871. * }, {
  20872. * // By default from 0.
  20873. * transform: { type: 'filter', config: {...} }
  20874. * }, {
  20875. * // Piped.
  20876. * transform: [
  20877. * { type: 'filter', config: {...} },
  20878. * { type: 'sort', config: {...} }
  20879. * ]
  20880. * }, {
  20881. * id: 'regressionData',
  20882. * fromDatasetIndex: 1,
  20883. * // Third-party transform
  20884. * transform: { type: 'ecStat:regression', config: {...} }
  20885. * }, {
  20886. * // retrieve the extra result.
  20887. * id: 'regressionFormula',
  20888. * fromDatasetId: 'regressionData',
  20889. * fromTransformResult: 1
  20890. * }]
  20891. * ```
  20892. */
  20893. var SourceManager =
  20894. /** @class */
  20895. function () {
  20896. function SourceManager(sourceHost) {
  20897. // Cached source. Do not repeat calculating if not dirty.
  20898. this._sourceList = [];
  20899. this._storeList = []; // version sign of each upstream source manager.
  20900. this._upstreamSignList = [];
  20901. this._versionSignBase = 0;
  20902. this._dirty = true;
  20903. this._sourceHost = sourceHost;
  20904. }
  20905. /**
  20906. * Mark dirty.
  20907. */
  20908. SourceManager.prototype.dirty = function () {
  20909. this._setLocalSource([], []);
  20910. this._storeList = [];
  20911. this._dirty = true;
  20912. };
  20913. SourceManager.prototype._setLocalSource = function (sourceList, upstreamSignList) {
  20914. this._sourceList = sourceList;
  20915. this._upstreamSignList = upstreamSignList;
  20916. this._versionSignBase++;
  20917. if (this._versionSignBase > 9e10) {
  20918. this._versionSignBase = 0;
  20919. }
  20920. };
  20921. /**
  20922. * For detecting whether the upstream source is dirty, so that
  20923. * the local cached source (in `_sourceList`) should be discarded.
  20924. */
  20925. SourceManager.prototype._getVersionSign = function () {
  20926. return this._sourceHost.uid + '_' + this._versionSignBase;
  20927. };
  20928. /**
  20929. * Always return a source instance. Otherwise throw error.
  20930. */
  20931. SourceManager.prototype.prepareSource = function () {
  20932. // For the case that call `setOption` multiple time but no data changed,
  20933. // cache the result source to prevent from repeating transform.
  20934. if (this._isDirty()) {
  20935. this._createSource();
  20936. this._dirty = false;
  20937. }
  20938. };
  20939. SourceManager.prototype._createSource = function () {
  20940. this._setLocalSource([], []);
  20941. var sourceHost = this._sourceHost;
  20942. var upSourceMgrList = this._getUpstreamSourceManagers();
  20943. var hasUpstream = !!upSourceMgrList.length;
  20944. var resultSourceList;
  20945. var upstreamSignList;
  20946. if (isSeries(sourceHost)) {
  20947. var seriesModel = sourceHost;
  20948. var data = void 0;
  20949. var sourceFormat = void 0;
  20950. var upSource = void 0; // Has upstream dataset
  20951. if (hasUpstream) {
  20952. var upSourceMgr = upSourceMgrList[0];
  20953. upSourceMgr.prepareSource();
  20954. upSource = upSourceMgr.getSource();
  20955. data = upSource.data;
  20956. sourceFormat = upSource.sourceFormat;
  20957. upstreamSignList = [upSourceMgr._getVersionSign()];
  20958. } // Series data is from own.
  20959. else {
  20960. data = seriesModel.get('data', true);
  20961. sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  20962. upstreamSignList = [];
  20963. } // See [REQUIREMENT_MEMO], merge settings on series and parent dataset if it is root.
  20964. var newMetaRawOption = this._getSourceMetaRawOption() || {};
  20965. var upMetaRawOption = upSource && upSource.metaRawOption || {};
  20966. var seriesLayoutBy = retrieve2(newMetaRawOption.seriesLayoutBy, upMetaRawOption.seriesLayoutBy) || null;
  20967. var sourceHeader = retrieve2(newMetaRawOption.sourceHeader, upMetaRawOption.sourceHeader) || null; // Note here we should not use `upSource.dimensionsDefine`. Consider the case:
  20968. // `upSource.dimensionsDefine` is detected by `seriesLayoutBy: 'column'`,
  20969. // but series need `seriesLayoutBy: 'row'`.
  20970. var dimensions = retrieve2(newMetaRawOption.dimensions, upMetaRawOption.dimensions); // We share source with dataset as much as possible
  20971. // to avoid extra memroy cost of high dimensional data.
  20972. var needsCreateSource = seriesLayoutBy !== upMetaRawOption.seriesLayoutBy || !!sourceHeader !== !!upMetaRawOption.sourceHeader || dimensions;
  20973. resultSourceList = needsCreateSource ? [createSource(data, {
  20974. seriesLayoutBy: seriesLayoutBy,
  20975. sourceHeader: sourceHeader,
  20976. dimensions: dimensions
  20977. }, sourceFormat)] : [];
  20978. } else {
  20979. var datasetModel = sourceHost; // Has upstream dataset.
  20980. if (hasUpstream) {
  20981. var result = this._applyTransform(upSourceMgrList);
  20982. resultSourceList = result.sourceList;
  20983. upstreamSignList = result.upstreamSignList;
  20984. } // Is root dataset.
  20985. else {
  20986. var sourceData = datasetModel.get('source', true);
  20987. resultSourceList = [createSource(sourceData, this._getSourceMetaRawOption(), null)];
  20988. upstreamSignList = [];
  20989. }
  20990. }
  20991. if ("development" !== 'production') {
  20992. assert(resultSourceList && upstreamSignList);
  20993. }
  20994. this._setLocalSource(resultSourceList, upstreamSignList);
  20995. };
  20996. SourceManager.prototype._applyTransform = function (upMgrList) {
  20997. var datasetModel = this._sourceHost;
  20998. var transformOption = datasetModel.get('transform', true);
  20999. var fromTransformResult = datasetModel.get('fromTransformResult', true);
  21000. if ("development" !== 'production') {
  21001. assert(fromTransformResult != null || transformOption != null);
  21002. }
  21003. if (fromTransformResult != null) {
  21004. var errMsg = '';
  21005. if (upMgrList.length !== 1) {
  21006. if ("development" !== 'production') {
  21007. errMsg = 'When using `fromTransformResult`, there should be only one upstream dataset';
  21008. }
  21009. doThrow(errMsg);
  21010. }
  21011. }
  21012. var sourceList;
  21013. var upSourceList = [];
  21014. var upstreamSignList = [];
  21015. each(upMgrList, function (upMgr) {
  21016. upMgr.prepareSource();
  21017. var upSource = upMgr.getSource(fromTransformResult || 0);
  21018. var errMsg = '';
  21019. if (fromTransformResult != null && !upSource) {
  21020. if ("development" !== 'production') {
  21021. errMsg = 'Can not retrieve result by `fromTransformResult`: ' + fromTransformResult;
  21022. }
  21023. doThrow(errMsg);
  21024. }
  21025. upSourceList.push(upSource);
  21026. upstreamSignList.push(upMgr._getVersionSign());
  21027. });
  21028. if (transformOption) {
  21029. sourceList = applyDataTransform(transformOption, upSourceList, {
  21030. datasetIndex: datasetModel.componentIndex
  21031. });
  21032. } else if (fromTransformResult != null) {
  21033. sourceList = [cloneSourceShallow(upSourceList[0])];
  21034. }
  21035. return {
  21036. sourceList: sourceList,
  21037. upstreamSignList: upstreamSignList
  21038. };
  21039. };
  21040. SourceManager.prototype._isDirty = function () {
  21041. if (this._dirty) {
  21042. return true;
  21043. } // All sourceList is from the some upsteam.
  21044. var upSourceMgrList = this._getUpstreamSourceManagers();
  21045. for (var i = 0; i < upSourceMgrList.length; i++) {
  21046. var upSrcMgr = upSourceMgrList[i];
  21047. if ( // Consider the case that there is ancestor diry, call it recursively.
  21048. // The performance is probably not an issue because usually the chain is not long.
  21049. upSrcMgr._isDirty() || this._upstreamSignList[i] !== upSrcMgr._getVersionSign()) {
  21050. return true;
  21051. }
  21052. }
  21053. };
  21054. /**
  21055. * @param sourceIndex By defualt 0, means "main source".
  21056. * Most cases there is only one source.
  21057. */
  21058. SourceManager.prototype.getSource = function (sourceIndex) {
  21059. sourceIndex = sourceIndex || 0;
  21060. var source = this._sourceList[sourceIndex];
  21061. if (!source) {
  21062. // Series may share source instance with dataset.
  21063. var upSourceMgrList = this._getUpstreamSourceManagers();
  21064. return upSourceMgrList[0] && upSourceMgrList[0].getSource(sourceIndex);
  21065. }
  21066. return source;
  21067. };
  21068. /**
  21069. *
  21070. * Get a data store which can be shared across series.
  21071. * Only available for series.
  21072. *
  21073. * @param seriesDimRequest Dimensions that are generated in series.
  21074. * Should have been sorted by `storeDimIndex` asc.
  21075. */
  21076. SourceManager.prototype.getSharedDataStore = function (seriesDimRequest) {
  21077. if ("development" !== 'production') {
  21078. assert(isSeries(this._sourceHost), 'Can only call getDataStore on series source manager.');
  21079. }
  21080. var schema = seriesDimRequest.makeStoreSchema();
  21081. return this._innerGetDataStore(schema.dimensions, seriesDimRequest.source, schema.hash);
  21082. };
  21083. SourceManager.prototype._innerGetDataStore = function (storeDims, seriesSource, sourceReadKey) {
  21084. // TODO Can use other sourceIndex?
  21085. var sourceIndex = 0;
  21086. var storeList = this._storeList;
  21087. var cachedStoreMap = storeList[sourceIndex];
  21088. if (!cachedStoreMap) {
  21089. cachedStoreMap = storeList[sourceIndex] = {};
  21090. }
  21091. var cachedStore = cachedStoreMap[sourceReadKey];
  21092. if (!cachedStore) {
  21093. var upSourceMgr = this._getUpstreamSourceManagers()[0];
  21094. if (isSeries(this._sourceHost) && upSourceMgr) {
  21095. cachedStore = upSourceMgr._innerGetDataStore(storeDims, seriesSource, sourceReadKey);
  21096. } else {
  21097. cachedStore = new DataStore(); // Always create store from source of series.
  21098. cachedStore.initData(new DefaultDataProvider(seriesSource, storeDims.length), storeDims);
  21099. }
  21100. cachedStoreMap[sourceReadKey] = cachedStore;
  21101. }
  21102. return cachedStore;
  21103. };
  21104. /**
  21105. * PEDING: Is it fast enough?
  21106. * If no upstream, return empty array.
  21107. */
  21108. SourceManager.prototype._getUpstreamSourceManagers = function () {
  21109. // Always get the relationship from the raw option.
  21110. // Do not cache the link of the dependency graph, so that
  21111. // no need to update them when change happen.
  21112. var sourceHost = this._sourceHost;
  21113. if (isSeries(sourceHost)) {
  21114. var datasetModel = querySeriesUpstreamDatasetModel(sourceHost);
  21115. return !datasetModel ? [] : [datasetModel.getSourceManager()];
  21116. } else {
  21117. return map(queryDatasetUpstreamDatasetModels(sourceHost), function (datasetModel) {
  21118. return datasetModel.getSourceManager();
  21119. });
  21120. }
  21121. };
  21122. SourceManager.prototype._getSourceMetaRawOption = function () {
  21123. var sourceHost = this._sourceHost;
  21124. var seriesLayoutBy;
  21125. var sourceHeader;
  21126. var dimensions;
  21127. if (isSeries(sourceHost)) {
  21128. seriesLayoutBy = sourceHost.get('seriesLayoutBy', true);
  21129. sourceHeader = sourceHost.get('sourceHeader', true);
  21130. dimensions = sourceHost.get('dimensions', true);
  21131. } // See [REQUIREMENT_MEMO], `non-root-dataset` do not support them.
  21132. else if (!this._getUpstreamSourceManagers().length) {
  21133. var model = sourceHost;
  21134. seriesLayoutBy = model.get('seriesLayoutBy', true);
  21135. sourceHeader = model.get('sourceHeader', true);
  21136. dimensions = model.get('dimensions', true);
  21137. }
  21138. return {
  21139. seriesLayoutBy: seriesLayoutBy,
  21140. sourceHeader: sourceHeader,
  21141. dimensions: dimensions
  21142. };
  21143. };
  21144. return SourceManager;
  21145. }();
  21146. // disable the transform merge, but do not disable transfrom clone from rawOption.
  21147. function disableTransformOptionMerge(datasetModel) {
  21148. var transformOption = datasetModel.option.transform;
  21149. transformOption && setAsPrimitive(datasetModel.option.transform);
  21150. }
  21151. function isSeries(sourceHost) {
  21152. // Avoid circular dependency with Series.ts
  21153. return sourceHost.mainType === 'series';
  21154. }
  21155. function doThrow(errMsg) {
  21156. throw new Error(errMsg);
  21157. }
  21158. var TOOLTIP_LINE_HEIGHT_CSS = 'line-height:1'; // TODO: more textStyle option
  21159. function getTooltipTextStyle(textStyle, renderMode) {
  21160. var nameFontColor = textStyle.color || '#6e7079';
  21161. var nameFontSize = textStyle.fontSize || 12;
  21162. var nameFontWeight = textStyle.fontWeight || '400';
  21163. var valueFontColor = textStyle.color || '#464646';
  21164. var valueFontSize = textStyle.fontSize || 14;
  21165. var valueFontWeight = textStyle.fontWeight || '900';
  21166. if (renderMode === 'html') {
  21167. // `textStyle` is probably from user input, should be encoded to reduce security risk.
  21168. return {
  21169. // eslint-disable-next-line max-len
  21170. nameStyle: "font-size:" + encodeHTML(nameFontSize + '') + "px;color:" + encodeHTML(nameFontColor) + ";font-weight:" + encodeHTML(nameFontWeight + ''),
  21171. // eslint-disable-next-line max-len
  21172. valueStyle: "font-size:" + encodeHTML(valueFontSize + '') + "px;color:" + encodeHTML(valueFontColor) + ";font-weight:" + encodeHTML(valueFontWeight + '')
  21173. };
  21174. } else {
  21175. return {
  21176. nameStyle: {
  21177. fontSize: nameFontSize,
  21178. fill: nameFontColor,
  21179. fontWeight: nameFontWeight
  21180. },
  21181. valueStyle: {
  21182. fontSize: valueFontSize,
  21183. fill: valueFontColor,
  21184. fontWeight: valueFontWeight
  21185. }
  21186. };
  21187. }
  21188. } // See `TooltipMarkupLayoutIntent['innerGapLevel']`.
  21189. // (value from UI design)
  21190. var HTML_GAPS = [0, 10, 20, 30];
  21191. var RICH_TEXT_GAPS = ['', '\n', '\n\n', '\n\n\n']; // eslint-disable-next-line max-len
  21192. function createTooltipMarkup(type, option) {
  21193. option.type = type;
  21194. return option;
  21195. }
  21196. function getBuilder(fragment) {
  21197. return hasOwn(builderMap, fragment.type) && builderMap[fragment.type];
  21198. }
  21199. var builderMap = {
  21200. /**
  21201. * A `section` block is like:
  21202. * ```
  21203. * header
  21204. * subBlock
  21205. * subBlock
  21206. * ...
  21207. * ```
  21208. */
  21209. section: {
  21210. planLayout: function (fragment) {
  21211. var subBlockLen = fragment.blocks.length;
  21212. var thisBlockHasInnerGap = subBlockLen > 1 || subBlockLen > 0 && !fragment.noHeader;
  21213. var thisGapLevelBetweenSubBlocks = 0;
  21214. each(fragment.blocks, function (subBlock) {
  21215. getBuilder(subBlock).planLayout(subBlock);
  21216. var subGapLevel = subBlock.__gapLevelBetweenSubBlocks; // If the some of the sub-blocks have some gaps (like 10px) inside, this block
  21217. // should use a larger gap (like 20px) to distinguish those sub-blocks.
  21218. if (subGapLevel >= thisGapLevelBetweenSubBlocks) {
  21219. thisGapLevelBetweenSubBlocks = subGapLevel + (thisBlockHasInnerGap && ( // 0 always can not be readable gap level.
  21220. !subGapLevel // If no header, always keep the sub gap level. Otherwise
  21221. // look weird in case `multipleSeries`.
  21222. || subBlock.type === 'section' && !subBlock.noHeader) ? 1 : 0);
  21223. }
  21224. });
  21225. fragment.__gapLevelBetweenSubBlocks = thisGapLevelBetweenSubBlocks;
  21226. },
  21227. build: function (ctx, fragment, topMarginForOuterGap, toolTipTextStyle) {
  21228. var noHeader = fragment.noHeader;
  21229. var gaps = getGap(fragment);
  21230. var subMarkupText = buildSubBlocks(ctx, fragment, noHeader ? topMarginForOuterGap : gaps.html, toolTipTextStyle);
  21231. if (noHeader) {
  21232. return subMarkupText;
  21233. }
  21234. var displayableHeader = makeValueReadable(fragment.header, 'ordinal', ctx.useUTC);
  21235. var nameStyle = getTooltipTextStyle(toolTipTextStyle, ctx.renderMode).nameStyle;
  21236. if (ctx.renderMode === 'richText') {
  21237. return wrapInlineNameRichText(ctx, displayableHeader, nameStyle) + gaps.richText + subMarkupText;
  21238. } else {
  21239. return wrapBlockHTML("<div style=\"" + nameStyle + ";" + TOOLTIP_LINE_HEIGHT_CSS + ";\">" + encodeHTML(displayableHeader) + '</div>' + subMarkupText, topMarginForOuterGap);
  21240. }
  21241. }
  21242. },
  21243. /**
  21244. * A `nameValue` block is like:
  21245. * ```
  21246. * marker name value
  21247. * ```
  21248. */
  21249. nameValue: {
  21250. planLayout: function (fragment) {
  21251. fragment.__gapLevelBetweenSubBlocks = 0;
  21252. },
  21253. build: function (ctx, fragment, topMarginForOuterGap, toolTipTextStyle) {
  21254. var renderMode = ctx.renderMode;
  21255. var noName = fragment.noName;
  21256. var noValue = fragment.noValue;
  21257. var noMarker = !fragment.markerType;
  21258. var name = fragment.name;
  21259. var value = fragment.value;
  21260. var useUTC = ctx.useUTC;
  21261. if (noName && noValue) {
  21262. return;
  21263. }
  21264. var markerStr = noMarker ? '' : ctx.markupStyleCreator.makeTooltipMarker(fragment.markerType, fragment.markerColor || '#333', renderMode);
  21265. var readableName = noName ? '' : makeValueReadable(name, 'ordinal', useUTC);
  21266. var valueTypeOption = fragment.valueType;
  21267. var readableValueList = noValue ? [] : isArray(value) ? map(value, function (val, idx) {
  21268. return makeValueReadable(val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption, useUTC);
  21269. }) : [makeValueReadable(value, isArray(valueTypeOption) ? valueTypeOption[0] : valueTypeOption, useUTC)];
  21270. var valueAlignRight = !noMarker || !noName; // It little weird if only value next to marker but far from marker.
  21271. var valueCloseToMarker = !noMarker && noName;
  21272. var _a = getTooltipTextStyle(toolTipTextStyle, renderMode),
  21273. nameStyle = _a.nameStyle,
  21274. valueStyle = _a.valueStyle;
  21275. return renderMode === 'richText' ? (noMarker ? '' : markerStr) + (noName ? '' : wrapInlineNameRichText(ctx, readableName, nameStyle)) // Value has commas inside, so use ' ' as delimiter for multiple values.
  21276. + (noValue ? '' : wrapInlineValueRichText(ctx, readableValueList, valueAlignRight, valueCloseToMarker, valueStyle)) : wrapBlockHTML((noMarker ? '' : markerStr) + (noName ? '' : wrapInlineNameHTML(readableName, !noMarker, nameStyle)) + (noValue ? '' : wrapInlineValueHTML(readableValueList, valueAlignRight, valueCloseToMarker, valueStyle)), topMarginForOuterGap);
  21277. }
  21278. }
  21279. };
  21280. function buildSubBlocks(ctx, fragment, topMarginForOuterGap, tooltipTextStyle) {
  21281. var subMarkupTextList = [];
  21282. var subBlocks = fragment.blocks || [];
  21283. assert(!subBlocks || isArray(subBlocks));
  21284. subBlocks = subBlocks || [];
  21285. var orderMode = ctx.orderMode;
  21286. if (fragment.sortBlocks && orderMode) {
  21287. subBlocks = subBlocks.slice();
  21288. var orderMap = {
  21289. valueAsc: 'asc',
  21290. valueDesc: 'desc'
  21291. };
  21292. if (hasOwn(orderMap, orderMode)) {
  21293. var comparator_1 = new SortOrderComparator(orderMap[orderMode], null);
  21294. subBlocks.sort(function (a, b) {
  21295. return comparator_1.evaluate(a.sortParam, b.sortParam);
  21296. });
  21297. } // FIXME 'seriesDesc' necessary?
  21298. else if (orderMode === 'seriesDesc') {
  21299. subBlocks.reverse();
  21300. }
  21301. }
  21302. var gaps = getGap(fragment);
  21303. each(subBlocks, function (subBlock, idx) {
  21304. var subMarkupText = getBuilder(subBlock).build(ctx, subBlock, idx > 0 ? gaps.html : 0, tooltipTextStyle);
  21305. subMarkupText != null && subMarkupTextList.push(subMarkupText);
  21306. });
  21307. if (!subMarkupTextList.length) {
  21308. return;
  21309. }
  21310. return ctx.renderMode === 'richText' ? subMarkupTextList.join(gaps.richText) : wrapBlockHTML(subMarkupTextList.join(''), topMarginForOuterGap);
  21311. }
  21312. /**
  21313. * @return markupText. null/undefined means no content.
  21314. */
  21315. function buildTooltipMarkup(fragment, markupStyleCreator, renderMode, orderMode, useUTC, toolTipTextStyle) {
  21316. if (!fragment) {
  21317. return;
  21318. }
  21319. var builder = getBuilder(fragment);
  21320. builder.planLayout(fragment);
  21321. var ctx = {
  21322. useUTC: useUTC,
  21323. renderMode: renderMode,
  21324. orderMode: orderMode,
  21325. markupStyleCreator: markupStyleCreator
  21326. };
  21327. return builder.build(ctx, fragment, 0, toolTipTextStyle);
  21328. }
  21329. function getGap(fragment) {
  21330. var gapLevelBetweenSubBlocks = fragment.__gapLevelBetweenSubBlocks;
  21331. return {
  21332. html: HTML_GAPS[gapLevelBetweenSubBlocks],
  21333. richText: RICH_TEXT_GAPS[gapLevelBetweenSubBlocks]
  21334. };
  21335. }
  21336. function wrapBlockHTML(encodedContent, topGap) {
  21337. var clearfix = '<div style="clear:both"></div>';
  21338. var marginCSS = "margin: " + topGap + "px 0 0";
  21339. return "<div style=\"" + marginCSS + ";" + TOOLTIP_LINE_HEIGHT_CSS + ";\">" + encodedContent + clearfix + '</div>';
  21340. }
  21341. function wrapInlineNameHTML(name, leftHasMarker, style) {
  21342. var marginCss = leftHasMarker ? 'margin-left:2px' : '';
  21343. return "<span style=\"" + style + ";" + marginCss + "\">" + encodeHTML(name) + '</span>';
  21344. }
  21345. function wrapInlineValueHTML(valueList, alignRight, valueCloseToMarker, style) {
  21346. // Do not too close to marker, considering there are multiple values separated by spaces.
  21347. var paddingStr = valueCloseToMarker ? '10px' : '20px';
  21348. var alignCSS = alignRight ? "float:right;margin-left:" + paddingStr : '';
  21349. return "<span style=\"" + alignCSS + ";" + style + "\">" // Value has commas inside, so use ' ' as delimiter for multiple values.
  21350. + map(valueList, function (value) {
  21351. return encodeHTML(value);
  21352. }).join('&nbsp;&nbsp;') + '</span>';
  21353. }
  21354. function wrapInlineNameRichText(ctx, name, style) {
  21355. return ctx.markupStyleCreator.wrapRichTextStyle(name, style);
  21356. }
  21357. function wrapInlineValueRichText(ctx, valueList, alignRight, valueCloseToMarker, style) {
  21358. var styles = [style];
  21359. var paddingLeft = valueCloseToMarker ? 10 : 20;
  21360. alignRight && styles.push({
  21361. padding: [0, 0, 0, paddingLeft],
  21362. align: 'right'
  21363. }); // Value has commas inside, so use ' ' as delimiter for multiple values.
  21364. return ctx.markupStyleCreator.wrapRichTextStyle(valueList.join(' '), styles);
  21365. }
  21366. function retrieveVisualColorForTooltipMarker(series, dataIndex) {
  21367. var style = series.getData().getItemVisual(dataIndex, 'style');
  21368. var color = style[series.visualDrawType];
  21369. return convertToColorString(color);
  21370. }
  21371. function getPaddingFromTooltipModel(model, renderMode) {
  21372. var padding = model.get('padding');
  21373. return padding != null ? padding // We give slightly different to look pretty.
  21374. : renderMode === 'richText' ? [8, 10] : 10;
  21375. }
  21376. /**
  21377. * The major feature is generate styles for `renderMode: 'richText'`.
  21378. * But it also serves `renderMode: 'html'` to provide
  21379. * "renderMode-independent" API.
  21380. */
  21381. var TooltipMarkupStyleCreator =
  21382. /** @class */
  21383. function () {
  21384. function TooltipMarkupStyleCreator() {
  21385. this.richTextStyles = {}; // Notice that "generate a style name" usuall happens repeatly when mouse moving and
  21386. // displaying a tooltip. So we put the `_nextStyleNameId` as a member of each creator
  21387. // rather than static shared by all creators (which will cause it increase to fast).
  21388. this._nextStyleNameId = getRandomIdBase();
  21389. }
  21390. TooltipMarkupStyleCreator.prototype._generateStyleName = function () {
  21391. return '__EC_aUTo_' + this._nextStyleNameId++;
  21392. };
  21393. TooltipMarkupStyleCreator.prototype.makeTooltipMarker = function (markerType, colorStr, renderMode) {
  21394. var markerId = renderMode === 'richText' ? this._generateStyleName() : null;
  21395. var marker = getTooltipMarker({
  21396. color: colorStr,
  21397. type: markerType,
  21398. renderMode: renderMode,
  21399. markerId: markerId
  21400. });
  21401. if (isString(marker)) {
  21402. return marker;
  21403. } else {
  21404. if ("development" !== 'production') {
  21405. assert(markerId);
  21406. }
  21407. this.richTextStyles[markerId] = marker.style;
  21408. return marker.content;
  21409. }
  21410. };
  21411. /**
  21412. * @usage
  21413. * ```ts
  21414. * const styledText = markupStyleCreator.wrapRichTextStyle([
  21415. * // The styles will be auto merged.
  21416. * {
  21417. * fontSize: 12,
  21418. * color: 'blue'
  21419. * },
  21420. * {
  21421. * padding: 20
  21422. * }
  21423. * ]);
  21424. * ```
  21425. */
  21426. TooltipMarkupStyleCreator.prototype.wrapRichTextStyle = function (text, styles) {
  21427. var finalStl = {};
  21428. if (isArray(styles)) {
  21429. each(styles, function (stl) {
  21430. return extend(finalStl, stl);
  21431. });
  21432. } else {
  21433. extend(finalStl, styles);
  21434. }
  21435. var styleName = this._generateStyleName();
  21436. this.richTextStyles[styleName] = finalStl;
  21437. return "{" + styleName + "|" + text + "}";
  21438. };
  21439. return TooltipMarkupStyleCreator;
  21440. }();
  21441. function defaultSeriesFormatTooltip(opt) {
  21442. var series = opt.series;
  21443. var dataIndex = opt.dataIndex;
  21444. var multipleSeries = opt.multipleSeries;
  21445. var data = series.getData();
  21446. var tooltipDims = data.mapDimensionsAll('defaultedTooltip');
  21447. var tooltipDimLen = tooltipDims.length;
  21448. var value = series.getRawValue(dataIndex);
  21449. var isValueArr = isArray(value);
  21450. var markerColor = retrieveVisualColorForTooltipMarker(series, dataIndex); // Complicated rule for pretty tooltip.
  21451. var inlineValue;
  21452. var inlineValueType;
  21453. var subBlocks;
  21454. var sortParam;
  21455. if (tooltipDimLen > 1 || isValueArr && !tooltipDimLen) {
  21456. var formatArrResult = formatTooltipArrayValue(value, series, dataIndex, tooltipDims, markerColor);
  21457. inlineValue = formatArrResult.inlineValues;
  21458. inlineValueType = formatArrResult.inlineValueTypes;
  21459. subBlocks = formatArrResult.blocks; // Only support tooltip sort by the first inline value. It's enough in most cases.
  21460. sortParam = formatArrResult.inlineValues[0];
  21461. } else if (tooltipDimLen) {
  21462. var dimInfo = data.getDimensionInfo(tooltipDims[0]);
  21463. sortParam = inlineValue = retrieveRawValue(data, dataIndex, tooltipDims[0]);
  21464. inlineValueType = dimInfo.type;
  21465. } else {
  21466. sortParam = inlineValue = isValueArr ? value[0] : value;
  21467. } // Do not show generated series name. It might not be readable.
  21468. var seriesNameSpecified = isNameSpecified(series);
  21469. var seriesName = seriesNameSpecified && series.name || '';
  21470. var itemName = data.getName(dataIndex);
  21471. var inlineName = multipleSeries ? seriesName : itemName;
  21472. return createTooltipMarkup('section', {
  21473. header: seriesName,
  21474. // When series name not specified, do not show a header line with only '-'.
  21475. // This case alway happen in tooltip.trigger: 'item'.
  21476. noHeader: multipleSeries || !seriesNameSpecified,
  21477. sortParam: sortParam,
  21478. blocks: [createTooltipMarkup('nameValue', {
  21479. markerType: 'item',
  21480. markerColor: markerColor,
  21481. // Do not mix display seriesName and itemName in one tooltip,
  21482. // which might confuses users.
  21483. name: inlineName,
  21484. // name dimension might be auto assigned, where the name might
  21485. // be not readable. So we check trim here.
  21486. noName: !trim(inlineName),
  21487. value: inlineValue,
  21488. valueType: inlineValueType
  21489. })].concat(subBlocks || [])
  21490. });
  21491. }
  21492. function formatTooltipArrayValue(value, series, dataIndex, tooltipDims, colorStr) {
  21493. // check: category-no-encode-has-axis-data in dataset.html
  21494. var data = series.getData();
  21495. var isValueMultipleLine = reduce(value, function (isValueMultipleLine, val, idx) {
  21496. var dimItem = data.getDimensionInfo(idx);
  21497. return isValueMultipleLine = isValueMultipleLine || dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  21498. }, false);
  21499. var inlineValues = [];
  21500. var inlineValueTypes = [];
  21501. var blocks = [];
  21502. tooltipDims.length ? each(tooltipDims, function (dim) {
  21503. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  21504. }) // By default, all dims is used on tooltip.
  21505. : each(value, setEachItem);
  21506. function setEachItem(val, dim) {
  21507. var dimInfo = data.getDimensionInfo(dim); // If `dimInfo.tooltip` is not set, show tooltip.
  21508. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  21509. return;
  21510. }
  21511. if (isValueMultipleLine) {
  21512. blocks.push(createTooltipMarkup('nameValue', {
  21513. markerType: 'subItem',
  21514. markerColor: colorStr,
  21515. name: dimInfo.displayName,
  21516. value: val,
  21517. valueType: dimInfo.type
  21518. }));
  21519. } else {
  21520. inlineValues.push(val);
  21521. inlineValueTypes.push(dimInfo.type);
  21522. }
  21523. }
  21524. return {
  21525. inlineValues: inlineValues,
  21526. inlineValueTypes: inlineValueTypes,
  21527. blocks: blocks
  21528. };
  21529. }
  21530. var inner$1 = makeInner();
  21531. function getSelectionKey(data, dataIndex) {
  21532. return data.getName(dataIndex) || data.getId(dataIndex);
  21533. }
  21534. var SERIES_UNIVERSAL_TRANSITION_PROP = '__universalTransitionEnabled';
  21535. var SeriesModel =
  21536. /** @class */
  21537. function (_super) {
  21538. __extends(SeriesModel, _super);
  21539. function SeriesModel() {
  21540. // [Caution]: Becuase this class or desecendants can be used as `XXX.extend(subProto)`,
  21541. // the class members must not be initialized in constructor or declaration place.
  21542. // Otherwise there is bad case:
  21543. // class A {xxx = 1;}
  21544. // enableClassExtend(A);
  21545. // class B extends A {}
  21546. // var C = B.extend({xxx: 5});
  21547. // var c = new C();
  21548. // console.log(c.xxx); // expect 5 but always 1.
  21549. var _this = _super !== null && _super.apply(this, arguments) || this; // ---------------------------------------
  21550. // Props about data selection
  21551. // ---------------------------------------
  21552. _this._selectedDataIndicesMap = {};
  21553. return _this;
  21554. }
  21555. SeriesModel.prototype.init = function (option, parentModel, ecModel) {
  21556. this.seriesIndex = this.componentIndex;
  21557. this.dataTask = createTask({
  21558. count: dataTaskCount,
  21559. reset: dataTaskReset
  21560. });
  21561. this.dataTask.context = {
  21562. model: this
  21563. };
  21564. this.mergeDefaultAndTheme(option, ecModel);
  21565. var sourceManager = inner$1(this).sourceManager = new SourceManager(this);
  21566. sourceManager.prepareSource();
  21567. var data = this.getInitialData(option, ecModel);
  21568. wrapData(data, this);
  21569. this.dataTask.context.data = data;
  21570. if ("development" !== 'production') {
  21571. assert(data, 'getInitialData returned invalid data.');
  21572. }
  21573. inner$1(this).dataBeforeProcessed = data; // If we reverse the order (make data firstly, and then make
  21574. // dataBeforeProcessed by cloneShallow), cloneShallow will
  21575. // cause data.graph.data !== data when using
  21576. // module:echarts/data/Graph or module:echarts/data/Tree.
  21577. // See module:echarts/data/helper/linkSeriesData
  21578. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  21579. // init or merge stage, because the data can be restored. So we do not `restoreData`
  21580. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  21581. // Call `seriesModel.getRawData()` instead.
  21582. // this.restoreData();
  21583. autoSeriesName(this);
  21584. this._initSelectedMapFromData(data);
  21585. };
  21586. /**
  21587. * Util for merge default and theme to option
  21588. */
  21589. SeriesModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  21590. var layoutMode = fetchLayoutMode(this);
  21591. var inputPositionParams = layoutMode ? getLayoutParams(option) : {}; // Backward compat: using subType on theme.
  21592. // But if name duplicate between series subType
  21593. // (for example: parallel) add component mainType,
  21594. // add suffix 'Series'.
  21595. var themeSubType = this.subType;
  21596. if (ComponentModel.hasClass(themeSubType)) {
  21597. themeSubType += 'Series';
  21598. }
  21599. merge(option, ecModel.getTheme().get(this.subType));
  21600. merge(option, this.getDefaultOption()); // Default label emphasis `show`
  21601. defaultEmphasis(option, 'label', ['show']);
  21602. this.fillDataTextStyle(option.data);
  21603. if (layoutMode) {
  21604. mergeLayoutParam(option, inputPositionParams, layoutMode);
  21605. }
  21606. };
  21607. SeriesModel.prototype.mergeOption = function (newSeriesOption, ecModel) {
  21608. // this.settingTask.dirty();
  21609. newSeriesOption = merge(this.option, newSeriesOption, true);
  21610. this.fillDataTextStyle(newSeriesOption.data);
  21611. var layoutMode = fetchLayoutMode(this);
  21612. if (layoutMode) {
  21613. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  21614. }
  21615. var sourceManager = inner$1(this).sourceManager;
  21616. sourceManager.dirty();
  21617. sourceManager.prepareSource();
  21618. var data = this.getInitialData(newSeriesOption, ecModel);
  21619. wrapData(data, this);
  21620. this.dataTask.dirty();
  21621. this.dataTask.context.data = data;
  21622. inner$1(this).dataBeforeProcessed = data;
  21623. autoSeriesName(this);
  21624. this._initSelectedMapFromData(data);
  21625. };
  21626. SeriesModel.prototype.fillDataTextStyle = function (data) {
  21627. // Default data label emphasis `show`
  21628. // FIXME Tree structure data ?
  21629. // FIXME Performance ?
  21630. if (data && !isTypedArray(data)) {
  21631. var props = ['show'];
  21632. for (var i = 0; i < data.length; i++) {
  21633. if (data[i] && data[i].label) {
  21634. defaultEmphasis(data[i], 'label', props);
  21635. }
  21636. }
  21637. }
  21638. };
  21639. /**
  21640. * Init a data structure from data related option in series
  21641. * Must be overriden.
  21642. */
  21643. SeriesModel.prototype.getInitialData = function (option, ecModel) {
  21644. return;
  21645. };
  21646. /**
  21647. * Append data to list
  21648. */
  21649. SeriesModel.prototype.appendData = function (params) {
  21650. // FIXME ???
  21651. // (1) If data from dataset, forbidden append.
  21652. // (2) support append data of dataset.
  21653. var data = this.getRawData();
  21654. data.appendData(params.data);
  21655. };
  21656. /**
  21657. * Consider some method like `filter`, `map` need make new data,
  21658. * We should make sure that `seriesModel.getData()` get correct
  21659. * data in the stream procedure. So we fetch data from upstream
  21660. * each time `task.perform` called.
  21661. */
  21662. SeriesModel.prototype.getData = function (dataType) {
  21663. var task = getCurrentTask(this);
  21664. if (task) {
  21665. var data = task.context.data;
  21666. return dataType == null ? data : data.getLinkedData(dataType);
  21667. } else {
  21668. // When series is not alive (that may happen when click toolbox
  21669. // restore or setOption with not merge mode), series data may
  21670. // be still need to judge animation or something when graphic
  21671. // elements want to know whether fade out.
  21672. return inner$1(this).data;
  21673. }
  21674. };
  21675. SeriesModel.prototype.getAllData = function () {
  21676. var mainData = this.getData();
  21677. return mainData && mainData.getLinkedDataAll ? mainData.getLinkedDataAll() : [{
  21678. data: mainData
  21679. }];
  21680. };
  21681. SeriesModel.prototype.setData = function (data) {
  21682. var task = getCurrentTask(this);
  21683. if (task) {
  21684. var context = task.context; // Consider case: filter, data sample.
  21685. // FIXME:TS never used, so comment it
  21686. // if (context.data !== data && task.modifyOutputEnd) {
  21687. // task.setOutputEnd(data.count());
  21688. // }
  21689. context.outputData = data; // Caution: setData should update context.data,
  21690. // Because getData may be called multiply in a
  21691. // single stage and expect to get the data just
  21692. // set. (For example, AxisProxy, x y both call
  21693. // getData and setDate sequentially).
  21694. // So the context.data should be fetched from
  21695. // upstream each time when a stage starts to be
  21696. // performed.
  21697. if (task !== this.dataTask) {
  21698. context.data = data;
  21699. }
  21700. }
  21701. inner$1(this).data = data;
  21702. };
  21703. SeriesModel.prototype.getEncode = function () {
  21704. var encode = this.get('encode', true);
  21705. if (encode) {
  21706. return createHashMap(encode);
  21707. }
  21708. };
  21709. SeriesModel.prototype.getSourceManager = function () {
  21710. return inner$1(this).sourceManager;
  21711. };
  21712. SeriesModel.prototype.getSource = function () {
  21713. return this.getSourceManager().getSource();
  21714. };
  21715. /**
  21716. * Get data before processed
  21717. */
  21718. SeriesModel.prototype.getRawData = function () {
  21719. return inner$1(this).dataBeforeProcessed;
  21720. };
  21721. SeriesModel.prototype.getColorBy = function () {
  21722. var colorBy = this.get('colorBy');
  21723. return colorBy || 'series';
  21724. };
  21725. SeriesModel.prototype.isColorBySeries = function () {
  21726. return this.getColorBy() === 'series';
  21727. };
  21728. /**
  21729. * Get base axis if has coordinate system and has axis.
  21730. * By default use coordSys.getBaseAxis();
  21731. * Can be overrided for some chart.
  21732. * @return {type} description
  21733. */
  21734. SeriesModel.prototype.getBaseAxis = function () {
  21735. var coordSys = this.coordinateSystem; // @ts-ignore
  21736. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  21737. };
  21738. /**
  21739. * Default tooltip formatter
  21740. *
  21741. * @param dataIndex
  21742. * @param multipleSeries
  21743. * @param dataType
  21744. * @param renderMode valid values: 'html'(by default) and 'richText'.
  21745. * 'html' is used for rendering tooltip in extra DOM form, and the result
  21746. * string is used as DOM HTML content.
  21747. * 'richText' is used for rendering tooltip in rich text form, for those where
  21748. * DOM operation is not supported.
  21749. * @return formatted tooltip with `html` and `markers`
  21750. * Notice: The override method can also return string
  21751. */
  21752. SeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  21753. return defaultSeriesFormatTooltip({
  21754. series: this,
  21755. dataIndex: dataIndex,
  21756. multipleSeries: multipleSeries
  21757. });
  21758. };
  21759. SeriesModel.prototype.isAnimationEnabled = function () {
  21760. if (env.node) {
  21761. return false;
  21762. }
  21763. var animationEnabled = this.getShallow('animation');
  21764. if (animationEnabled) {
  21765. if (this.getData().count() > this.getShallow('animationThreshold')) {
  21766. animationEnabled = false;
  21767. }
  21768. }
  21769. return !!animationEnabled;
  21770. };
  21771. SeriesModel.prototype.restoreData = function () {
  21772. this.dataTask.dirty();
  21773. };
  21774. SeriesModel.prototype.getColorFromPalette = function (name, scope, requestColorNum) {
  21775. var ecModel = this.ecModel; // PENDING
  21776. var color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
  21777. if (!color) {
  21778. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  21779. }
  21780. return color;
  21781. };
  21782. /**
  21783. * Use `data.mapDimensionsAll(coordDim)` instead.
  21784. * @deprecated
  21785. */
  21786. SeriesModel.prototype.coordDimToDataDim = function (coordDim) {
  21787. return this.getRawData().mapDimensionsAll(coordDim);
  21788. };
  21789. /**
  21790. * Get progressive rendering count each step
  21791. */
  21792. SeriesModel.prototype.getProgressive = function () {
  21793. return this.get('progressive');
  21794. };
  21795. /**
  21796. * Get progressive rendering count each step
  21797. */
  21798. SeriesModel.prototype.getProgressiveThreshold = function () {
  21799. return this.get('progressiveThreshold');
  21800. }; // PENGING If selectedMode is null ?
  21801. SeriesModel.prototype.select = function (innerDataIndices, dataType) {
  21802. this._innerSelect(this.getData(dataType), innerDataIndices);
  21803. };
  21804. SeriesModel.prototype.unselect = function (innerDataIndices, dataType) {
  21805. var selectedMap = this.option.selectedMap;
  21806. if (!selectedMap) {
  21807. return;
  21808. }
  21809. var data = this.getData(dataType);
  21810. for (var i = 0; i < innerDataIndices.length; i++) {
  21811. var dataIndex = innerDataIndices[i];
  21812. var nameOrId = getSelectionKey(data, dataIndex);
  21813. selectedMap[nameOrId] = false;
  21814. this._selectedDataIndicesMap[nameOrId] = -1;
  21815. }
  21816. };
  21817. SeriesModel.prototype.toggleSelect = function (innerDataIndices, dataType) {
  21818. var tmpArr = [];
  21819. for (var i = 0; i < innerDataIndices.length; i++) {
  21820. tmpArr[0] = innerDataIndices[i];
  21821. this.isSelected(innerDataIndices[i], dataType) ? this.unselect(tmpArr, dataType) : this.select(tmpArr, dataType);
  21822. }
  21823. };
  21824. SeriesModel.prototype.getSelectedDataIndices = function () {
  21825. var selectedDataIndicesMap = this._selectedDataIndicesMap;
  21826. var nameOrIds = keys(selectedDataIndicesMap);
  21827. var dataIndices = [];
  21828. for (var i = 0; i < nameOrIds.length; i++) {
  21829. var dataIndex = selectedDataIndicesMap[nameOrIds[i]];
  21830. if (dataIndex >= 0) {
  21831. dataIndices.push(dataIndex);
  21832. }
  21833. }
  21834. return dataIndices;
  21835. };
  21836. SeriesModel.prototype.isSelected = function (dataIndex, dataType) {
  21837. var selectedMap = this.option.selectedMap;
  21838. if (!selectedMap) {
  21839. return false;
  21840. }
  21841. var data = this.getData(dataType);
  21842. var nameOrId = getSelectionKey(data, dataIndex);
  21843. return selectedMap[nameOrId] || false;
  21844. };
  21845. SeriesModel.prototype.isUniversalTransitionEnabled = function () {
  21846. if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  21847. return true;
  21848. }
  21849. var universalTransitionOpt = this.option.universalTransition; // Quick reject
  21850. if (!universalTransitionOpt) {
  21851. return false;
  21852. }
  21853. if (universalTransitionOpt === true) {
  21854. return true;
  21855. } // Can be simply 'universalTransition: true'
  21856. return universalTransitionOpt && universalTransitionOpt.enabled;
  21857. };
  21858. SeriesModel.prototype._innerSelect = function (data, innerDataIndices) {
  21859. var _a, _b;
  21860. var selectedMode = this.option.selectedMode;
  21861. var len = innerDataIndices.length;
  21862. if (!selectedMode || !len) {
  21863. return;
  21864. }
  21865. if (selectedMode === 'multiple') {
  21866. var selectedMap = this.option.selectedMap || (this.option.selectedMap = {});
  21867. for (var i = 0; i < len; i++) {
  21868. var dataIndex = innerDataIndices[i]; // TODO diffrent types of data share same object.
  21869. var nameOrId = getSelectionKey(data, dataIndex);
  21870. selectedMap[nameOrId] = true;
  21871. this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
  21872. }
  21873. } else if (selectedMode === 'single' || selectedMode === true) {
  21874. var lastDataIndex = innerDataIndices[len - 1];
  21875. var nameOrId = getSelectionKey(data, lastDataIndex);
  21876. this.option.selectedMap = (_a = {}, _a[nameOrId] = true, _a);
  21877. this._selectedDataIndicesMap = (_b = {}, _b[nameOrId] = data.getRawIndex(lastDataIndex), _b);
  21878. }
  21879. };
  21880. SeriesModel.prototype._initSelectedMapFromData = function (data) {
  21881. // Ignore select info in data if selectedMap exists.
  21882. // NOTE It's only for legacy usage. edge data is not supported.
  21883. if (this.option.selectedMap) {
  21884. return;
  21885. }
  21886. var dataIndices = [];
  21887. if (data.hasItemOption) {
  21888. data.each(function (idx) {
  21889. var rawItem = data.getRawDataItem(idx);
  21890. if (rawItem && rawItem.selected) {
  21891. dataIndices.push(idx);
  21892. }
  21893. });
  21894. }
  21895. if (dataIndices.length > 0) {
  21896. this._innerSelect(data, dataIndices);
  21897. }
  21898. }; // /**
  21899. // * @see {module:echarts/stream/Scheduler}
  21900. // */
  21901. // abstract pipeTask: null
  21902. SeriesModel.registerClass = function (clz) {
  21903. return ComponentModel.registerClass(clz);
  21904. };
  21905. SeriesModel.protoInitialize = function () {
  21906. var proto = SeriesModel.prototype;
  21907. proto.type = 'series.__base__';
  21908. proto.seriesIndex = 0;
  21909. proto.ignoreStyleOnData = false;
  21910. proto.hasSymbolVisual = false;
  21911. proto.defaultSymbol = 'circle'; // Make sure the values can be accessed!
  21912. proto.visualStyleAccessPath = 'itemStyle';
  21913. proto.visualDrawType = 'fill';
  21914. }();
  21915. return SeriesModel;
  21916. }(ComponentModel);
  21917. mixin(SeriesModel, DataFormatMixin);
  21918. mixin(SeriesModel, PaletteMixin);
  21919. mountExtend(SeriesModel, ComponentModel);
  21920. /**
  21921. * MUST be called after `prepareSource` called
  21922. * Here we need to make auto series, especially for auto legend. But we
  21923. * do not modify series.name in option to avoid side effects.
  21924. */
  21925. function autoSeriesName(seriesModel) {
  21926. // User specified name has higher priority, otherwise it may cause
  21927. // series can not be queried unexpectedly.
  21928. var name = seriesModel.name;
  21929. if (!isNameSpecified(seriesModel)) {
  21930. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  21931. }
  21932. }
  21933. function getSeriesAutoName(seriesModel) {
  21934. var data = seriesModel.getRawData();
  21935. var dataDims = data.mapDimensionsAll('seriesName');
  21936. var nameArr = [];
  21937. each(dataDims, function (dataDim) {
  21938. var dimInfo = data.getDimensionInfo(dataDim);
  21939. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  21940. });
  21941. return nameArr.join(' ');
  21942. }
  21943. function dataTaskCount(context) {
  21944. return context.model.getRawData().count();
  21945. }
  21946. function dataTaskReset(context) {
  21947. var seriesModel = context.model;
  21948. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  21949. return dataTaskProgress;
  21950. }
  21951. function dataTaskProgress(param, context) {
  21952. // Avoid repead cloneShallow when data just created in reset.
  21953. if (context.outputData && param.end > context.outputData.count()) {
  21954. context.model.getRawData().cloneShallow(context.outputData);
  21955. }
  21956. } // TODO refactor
  21957. function wrapData(data, seriesModel) {
  21958. each(concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
  21959. data.wrapMethod(methodName, curry(onDataChange, seriesModel));
  21960. });
  21961. }
  21962. function onDataChange(seriesModel, newList) {
  21963. var task = getCurrentTask(seriesModel);
  21964. if (task) {
  21965. // Consider case: filter, selectRange
  21966. task.setOutputEnd((newList || this).count());
  21967. }
  21968. return newList;
  21969. }
  21970. function getCurrentTask(seriesModel) {
  21971. var scheduler = (seriesModel.ecModel || {}).scheduler;
  21972. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  21973. if (pipeline) {
  21974. // When pipline finished, the currrentTask keep the last
  21975. // task (renderTask).
  21976. var task = pipeline.currentTask;
  21977. if (task) {
  21978. var agentStubMap = task.agentStubMap;
  21979. if (agentStubMap) {
  21980. task = agentStubMap.get(seriesModel.uid);
  21981. }
  21982. }
  21983. return task;
  21984. }
  21985. }
  21986. var ComponentView =
  21987. /** @class */
  21988. function () {
  21989. function ComponentView() {
  21990. this.group = new Group();
  21991. this.uid = getUID('viewComponent');
  21992. }
  21993. ComponentView.prototype.init = function (ecModel, api) {};
  21994. ComponentView.prototype.render = function (model, ecModel, api, payload) {};
  21995. ComponentView.prototype.dispose = function (ecModel, api) {};
  21996. ComponentView.prototype.updateView = function (model, ecModel, api, payload) {// Do nothing;
  21997. };
  21998. ComponentView.prototype.updateLayout = function (model, ecModel, api, payload) {// Do nothing;
  21999. };
  22000. ComponentView.prototype.updateVisual = function (model, ecModel, api, payload) {// Do nothing;
  22001. };
  22002. /**
  22003. * Hook for blur target series.
  22004. * Can be used in marker for blur the markers
  22005. */
  22006. ComponentView.prototype.blurSeries = function (seriesModels, ecModel) {// Do nothing;
  22007. };
  22008. return ComponentView;
  22009. }();
  22010. enableClassExtend(ComponentView);
  22011. enableClassManagement(ComponentView);
  22012. /**
  22013. * @return {string} If large mode changed, return string 'reset';
  22014. */
  22015. function createRenderPlanner() {
  22016. var inner = makeInner();
  22017. return function (seriesModel) {
  22018. var fields = inner(seriesModel);
  22019. var pipelineContext = seriesModel.pipelineContext;
  22020. var originalLarge = !!fields.large;
  22021. var originalProgressive = !!fields.progressiveRender; // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  22022. // exists. See #11611 . Probably we need to modify this structure, see the comment
  22023. // on `performRawSeries` in `Schedular.js`.
  22024. var large = fields.large = !!(pipelineContext && pipelineContext.large);
  22025. var progressive = fields.progressiveRender = !!(pipelineContext && pipelineContext.progressiveRender);
  22026. return !!(originalLarge !== large || originalProgressive !== progressive) && 'reset';
  22027. };
  22028. }
  22029. var inner$2 = makeInner();
  22030. var renderPlanner = createRenderPlanner();
  22031. var ChartView =
  22032. /** @class */
  22033. function () {
  22034. function ChartView() {
  22035. this.group = new Group();
  22036. this.uid = getUID('viewChart');
  22037. this.renderTask = createTask({
  22038. plan: renderTaskPlan,
  22039. reset: renderTaskReset
  22040. });
  22041. this.renderTask.context = {
  22042. view: this
  22043. };
  22044. }
  22045. ChartView.prototype.init = function (ecModel, api) {};
  22046. ChartView.prototype.render = function (seriesModel, ecModel, api, payload) {};
  22047. /**
  22048. * Highlight series or specified data item.
  22049. */
  22050. ChartView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  22051. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  22052. };
  22053. /**
  22054. * Downplay series or specified data item.
  22055. */
  22056. ChartView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  22057. toggleHighlight(seriesModel.getData(), payload, 'normal');
  22058. };
  22059. /**
  22060. * Remove self.
  22061. */
  22062. ChartView.prototype.remove = function (ecModel, api) {
  22063. this.group.removeAll();
  22064. };
  22065. /**
  22066. * Dispose self.
  22067. */
  22068. ChartView.prototype.dispose = function (ecModel, api) {};
  22069. ChartView.prototype.updateView = function (seriesModel, ecModel, api, payload) {
  22070. this.render(seriesModel, ecModel, api, payload);
  22071. }; // FIXME never used?
  22072. ChartView.prototype.updateLayout = function (seriesModel, ecModel, api, payload) {
  22073. this.render(seriesModel, ecModel, api, payload);
  22074. }; // FIXME never used?
  22075. ChartView.prototype.updateVisual = function (seriesModel, ecModel, api, payload) {
  22076. this.render(seriesModel, ecModel, api, payload);
  22077. };
  22078. ChartView.markUpdateMethod = function (payload, methodName) {
  22079. inner$2(payload).updateMethod = methodName;
  22080. };
  22081. ChartView.protoInitialize = function () {
  22082. var proto = ChartView.prototype;
  22083. proto.type = 'chart';
  22084. }();
  22085. return ChartView;
  22086. }();
  22087. /**
  22088. * Set state of single element
  22089. */
  22090. function elSetState(el, state, highlightDigit) {
  22091. if (el) {
  22092. (state === 'emphasis' ? enterEmphasis : leaveEmphasis)(el, highlightDigit);
  22093. }
  22094. }
  22095. function toggleHighlight(data, payload, state) {
  22096. var dataIndex = queryDataIndex(data, payload);
  22097. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  22098. if (dataIndex != null) {
  22099. each(normalizeToArray(dataIndex), function (dataIdx) {
  22100. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  22101. });
  22102. } else {
  22103. data.eachItemGraphicEl(function (el) {
  22104. elSetState(el, state, highlightDigit);
  22105. });
  22106. }
  22107. }
  22108. enableClassExtend(ChartView, ['dispose']);
  22109. enableClassManagement(ChartView);
  22110. function renderTaskPlan(context) {
  22111. return renderPlanner(context.model);
  22112. }
  22113. function renderTaskReset(context) {
  22114. var seriesModel = context.model;
  22115. var ecModel = context.ecModel;
  22116. var api = context.api;
  22117. var payload = context.payload; // FIXME: remove updateView updateVisual
  22118. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  22119. var view = context.view;
  22120. var updateMethod = payload && inner$2(payload).updateMethod;
  22121. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod // `appendData` is also supported when data amount
  22122. // is less than progressive threshold.
  22123. : 'render';
  22124. if (methodName !== 'render') {
  22125. view[methodName](seriesModel, ecModel, api, payload);
  22126. }
  22127. return progressMethodMap[methodName];
  22128. }
  22129. var progressMethodMap = {
  22130. incrementalPrepareRender: {
  22131. progress: function (params, context) {
  22132. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  22133. }
  22134. },
  22135. render: {
  22136. // Put view.render in `progress` to support appendData. But in this case
  22137. // view.render should not be called in reset, otherwise it will be called
  22138. // twise. Use `forceFirstProgress` to make sure that view.render is called
  22139. // in any cases.
  22140. forceFirstProgress: true,
  22141. progress: function (params, context) {
  22142. context.view.render(context.model, context.ecModel, context.api, context.payload);
  22143. }
  22144. }
  22145. };
  22146. /*
  22147. * Licensed to the Apache Software Foundation (ASF) under one
  22148. * or more contributor license agreements. See the NOTICE file
  22149. * distributed with this work for additional information
  22150. * regarding copyright ownership. The ASF licenses this file
  22151. * to you under the Apache License, Version 2.0 (the
  22152. * "License"); you may not use this file except in compliance
  22153. * with the License. You may obtain a copy of the License at
  22154. *
  22155. * http://www.apache.org/licenses/LICENSE-2.0
  22156. *
  22157. * Unless required by applicable law or agreed to in writing,
  22158. * software distributed under the License is distributed on an
  22159. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22160. * KIND, either express or implied. See the License for the
  22161. * specific language governing permissions and limitations
  22162. * under the License.
  22163. */
  22164. /**
  22165. * AUTO-GENERATED FILE. DO NOT MODIFY.
  22166. */
  22167. /*
  22168. * Licensed to the Apache Software Foundation (ASF) under one
  22169. * or more contributor license agreements. See the NOTICE file
  22170. * distributed with this work for additional information
  22171. * regarding copyright ownership. The ASF licenses this file
  22172. * to you under the Apache License, Version 2.0 (the
  22173. * "License"); you may not use this file except in compliance
  22174. * with the License. You may obtain a copy of the License at
  22175. *
  22176. * http://www.apache.org/licenses/LICENSE-2.0
  22177. *
  22178. * Unless required by applicable law or agreed to in writing,
  22179. * software distributed under the License is distributed on an
  22180. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22181. * KIND, either express or implied. See the License for the
  22182. * specific language governing permissions and limitations
  22183. * under the License.
  22184. */
  22185. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  22186. var RATE = '\0__throttleRate';
  22187. var THROTTLE_TYPE = '\0__throttleType';
  22188. /**
  22189. * @public
  22190. * @param {(Function)} fn
  22191. * @param {number} [delay=0] Unit: ms.
  22192. * @param {boolean} [debounce=false]
  22193. * true: If call interval less than `delay`, only the last call works.
  22194. * false: If call interval less than `delay, call works on fixed rate.
  22195. * @return {(Function)} throttled fn.
  22196. */
  22197. function throttle(fn, delay, debounce) {
  22198. var currCall;
  22199. var lastCall = 0;
  22200. var lastExec = 0;
  22201. var timer = null;
  22202. var diff;
  22203. var scope;
  22204. var args;
  22205. var debounceNextCall;
  22206. delay = delay || 0;
  22207. function exec() {
  22208. lastExec = new Date().getTime();
  22209. timer = null;
  22210. fn.apply(scope, args || []);
  22211. }
  22212. var cb = function () {
  22213. var cbArgs = [];
  22214. for (var _i = 0; _i < arguments.length; _i++) {
  22215. cbArgs[_i] = arguments[_i];
  22216. }
  22217. currCall = new Date().getTime();
  22218. scope = this;
  22219. args = cbArgs;
  22220. var thisDelay = debounceNextCall || delay;
  22221. var thisDebounce = debounceNextCall || debounce;
  22222. debounceNextCall = null;
  22223. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  22224. clearTimeout(timer); // Here we should make sure that: the `exec` SHOULD NOT be called later
  22225. // than a new call of `cb`, that is, preserving the command order. Consider
  22226. // calculating "scale rate" when roaming as an example. When a call of `cb`
  22227. // happens, either the `exec` is called dierectly, or the call is delayed.
  22228. // But the delayed call should never be later than next call of `cb`. Under
  22229. // this assurance, we can simply update view state each time `dispatchAction`
  22230. // triggered by user roaming, but not need to add extra code to avoid the
  22231. // state being "rolled-back".
  22232. if (thisDebounce) {
  22233. timer = setTimeout(exec, thisDelay);
  22234. } else {
  22235. if (diff >= 0) {
  22236. exec();
  22237. } else {
  22238. timer = setTimeout(exec, -diff);
  22239. }
  22240. }
  22241. lastCall = currCall;
  22242. };
  22243. /**
  22244. * Clear throttle.
  22245. * @public
  22246. */
  22247. cb.clear = function () {
  22248. if (timer) {
  22249. clearTimeout(timer);
  22250. timer = null;
  22251. }
  22252. };
  22253. /**
  22254. * Enable debounce once.
  22255. */
  22256. cb.debounceNextCall = function (debounceDelay) {
  22257. debounceNextCall = debounceDelay;
  22258. };
  22259. return cb;
  22260. }
  22261. /**
  22262. * Create throttle method or update throttle rate.
  22263. *
  22264. * @example
  22265. * ComponentView.prototype.render = function () {
  22266. * ...
  22267. * throttle.createOrUpdate(
  22268. * this,
  22269. * '_dispatchAction',
  22270. * this.model.get('throttle'),
  22271. * 'fixRate'
  22272. * );
  22273. * };
  22274. * ComponentView.prototype.remove = function () {
  22275. * throttle.clear(this, '_dispatchAction');
  22276. * };
  22277. * ComponentView.prototype.dispose = function () {
  22278. * throttle.clear(this, '_dispatchAction');
  22279. * };
  22280. *
  22281. */
  22282. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  22283. var fn = obj[fnAttr];
  22284. if (!fn) {
  22285. return;
  22286. }
  22287. var originFn = fn[ORIGIN_METHOD] || fn;
  22288. var lastThrottleType = fn[THROTTLE_TYPE];
  22289. var lastRate = fn[RATE];
  22290. if (lastRate !== rate || lastThrottleType !== throttleType) {
  22291. if (rate == null || !throttleType) {
  22292. return obj[fnAttr] = originFn;
  22293. }
  22294. fn = obj[fnAttr] = throttle(originFn, rate, throttleType === 'debounce');
  22295. fn[ORIGIN_METHOD] = originFn;
  22296. fn[THROTTLE_TYPE] = throttleType;
  22297. fn[RATE] = rate;
  22298. }
  22299. return fn;
  22300. }
  22301. /**
  22302. * Clear throttle. Example see throttle.createOrUpdate.
  22303. */
  22304. function clear(obj, fnAttr) {
  22305. var fn = obj[fnAttr];
  22306. if (fn && fn[ORIGIN_METHOD]) {
  22307. obj[fnAttr] = fn[ORIGIN_METHOD];
  22308. }
  22309. }
  22310. var inner$3 = makeInner();
  22311. var defaultStyleMappers = {
  22312. itemStyle: makeStyleMapper(ITEM_STYLE_KEY_MAP, true),
  22313. lineStyle: makeStyleMapper(LINE_STYLE_KEY_MAP, true)
  22314. };
  22315. var defaultColorKey = {
  22316. lineStyle: 'stroke',
  22317. itemStyle: 'fill'
  22318. };
  22319. function getStyleMapper(seriesModel, stylePath) {
  22320. var styleMapper = seriesModel.visualStyleMapper || defaultStyleMappers[stylePath];
  22321. if (!styleMapper) {
  22322. console.warn("Unkown style type '" + stylePath + "'.");
  22323. return defaultStyleMappers.itemStyle;
  22324. }
  22325. return styleMapper;
  22326. }
  22327. function getDefaultColorKey(seriesModel, stylePath) {
  22328. // return defaultColorKey[stylePath] ||
  22329. var colorKey = seriesModel.visualDrawType || defaultColorKey[stylePath];
  22330. if (!colorKey) {
  22331. console.warn("Unkown style type '" + stylePath + "'.");
  22332. return 'fill';
  22333. }
  22334. return colorKey;
  22335. }
  22336. var seriesStyleTask = {
  22337. createOnAllSeries: true,
  22338. performRawSeries: true,
  22339. reset: function (seriesModel, ecModel) {
  22340. var data = seriesModel.getData();
  22341. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle'; // Set in itemStyle
  22342. var styleModel = seriesModel.getModel(stylePath);
  22343. var getStyle = getStyleMapper(seriesModel, stylePath);
  22344. var globalStyle = getStyle(styleModel);
  22345. var decalOption = styleModel.getShallow('decal');
  22346. if (decalOption) {
  22347. data.setVisual('decal', decalOption);
  22348. decalOption.dirty = true;
  22349. } // TODO
  22350. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  22351. var color = globalStyle[colorKey]; // TODO style callback
  22352. var colorCallback = isFunction(color) ? color : null;
  22353. var hasAutoColor = globalStyle.fill === 'auto' || globalStyle.stroke === 'auto'; // Get from color palette by default.
  22354. if (!globalStyle[colorKey] || colorCallback || hasAutoColor) {
  22355. // Note: if some series has color specified (e.g., by itemStyle.color), we DO NOT
  22356. // make it effect palette. Bacause some scenarios users need to make some series
  22357. // transparent or as background, which should better not effect the palette.
  22358. var colorPalette = seriesModel.getColorFromPalette( // TODO series count changed.
  22359. seriesModel.name, null, ecModel.getSeriesCount());
  22360. if (!globalStyle[colorKey]) {
  22361. globalStyle[colorKey] = colorPalette;
  22362. data.setVisual('colorFromPalette', true);
  22363. }
  22364. globalStyle.fill = globalStyle.fill === 'auto' || typeof globalStyle.fill === 'function' ? colorPalette : globalStyle.fill;
  22365. globalStyle.stroke = globalStyle.stroke === 'auto' || typeof globalStyle.stroke === 'function' ? colorPalette : globalStyle.stroke;
  22366. }
  22367. data.setVisual('style', globalStyle);
  22368. data.setVisual('drawType', colorKey); // Only visible series has each data be visual encoded
  22369. if (!ecModel.isSeriesFiltered(seriesModel) && colorCallback) {
  22370. data.setVisual('colorFromPalette', false);
  22371. return {
  22372. dataEach: function (data, idx) {
  22373. var dataParams = seriesModel.getDataParams(idx);
  22374. var itemStyle = extend({}, globalStyle);
  22375. itemStyle[colorKey] = colorCallback(dataParams);
  22376. data.setItemVisual(idx, 'style', itemStyle);
  22377. }
  22378. };
  22379. }
  22380. }
  22381. };
  22382. var sharedModel = new Model();
  22383. var dataStyleTask = {
  22384. createOnAllSeries: true,
  22385. performRawSeries: true,
  22386. reset: function (seriesModel, ecModel) {
  22387. if (seriesModel.ignoreStyleOnData || ecModel.isSeriesFiltered(seriesModel)) {
  22388. return;
  22389. }
  22390. var data = seriesModel.getData();
  22391. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle'; // Set in itemStyle
  22392. var getStyle = getStyleMapper(seriesModel, stylePath);
  22393. var colorKey = data.getVisual('drawType');
  22394. return {
  22395. dataEach: data.hasItemOption ? function (data, idx) {
  22396. // Not use getItemModel for performance considuration
  22397. var rawItem = data.getRawDataItem(idx);
  22398. if (rawItem && rawItem[stylePath]) {
  22399. sharedModel.option = rawItem[stylePath];
  22400. var style = getStyle(sharedModel);
  22401. var existsStyle = data.ensureUniqueItemVisual(idx, 'style');
  22402. extend(existsStyle, style);
  22403. if (sharedModel.option.decal) {
  22404. data.setItemVisual(idx, 'decal', sharedModel.option.decal);
  22405. sharedModel.option.decal.dirty = true;
  22406. }
  22407. if (colorKey in style) {
  22408. data.setItemVisual(idx, 'colorFromPalette', false);
  22409. }
  22410. }
  22411. } : null
  22412. };
  22413. }
  22414. }; // Pick color from palette for the data which has not been set with color yet.
  22415. // Note: do not support stream rendering. No such cases yet.
  22416. var dataColorPaletteTask = {
  22417. performRawSeries: true,
  22418. overallReset: function (ecModel) {
  22419. // Each type of series use one scope.
  22420. // Pie and funnel are using diferrent scopes
  22421. var paletteScopeGroupByType = createHashMap();
  22422. ecModel.eachSeries(function (seriesModel) {
  22423. var colorBy = seriesModel.getColorBy();
  22424. if (seriesModel.isColorBySeries()) {
  22425. return;
  22426. }
  22427. var key = seriesModel.type + '-' + colorBy;
  22428. var colorScope = paletteScopeGroupByType.get(key);
  22429. if (!colorScope) {
  22430. colorScope = {};
  22431. paletteScopeGroupByType.set(key, colorScope);
  22432. }
  22433. inner$3(seriesModel).scope = colorScope;
  22434. });
  22435. ecModel.eachSeries(function (seriesModel) {
  22436. if (seriesModel.isColorBySeries() || ecModel.isSeriesFiltered(seriesModel)) {
  22437. return;
  22438. }
  22439. var dataAll = seriesModel.getRawData();
  22440. var idxMap = {};
  22441. var data = seriesModel.getData();
  22442. var colorScope = inner$3(seriesModel).scope;
  22443. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  22444. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  22445. data.each(function (idx) {
  22446. var rawIdx = data.getRawIndex(idx);
  22447. idxMap[rawIdx] = idx;
  22448. }); // Iterate on data before filtered. To make sure color from palette can be
  22449. // Consistent when toggling legend.
  22450. dataAll.each(function (rawIdx) {
  22451. var idx = idxMap[rawIdx];
  22452. var fromPalette = data.getItemVisual(idx, 'colorFromPalette'); // Get color from palette for each data only when the color is inherited from series color, which is
  22453. // also picked from color palette. So following situation is not in the case:
  22454. // 1. series.itemStyle.color is set
  22455. // 2. color is encoded by visualMap
  22456. if (fromPalette) {
  22457. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  22458. var name_1 = dataAll.getName(rawIdx) || rawIdx + '';
  22459. var dataCount = dataAll.count();
  22460. itemStyle[colorKey] = seriesModel.getColorFromPalette(name_1, colorScope, dataCount);
  22461. }
  22462. });
  22463. });
  22464. }
  22465. };
  22466. var PI$3 = Math.PI;
  22467. /**
  22468. * @param {module:echarts/ExtensionAPI} api
  22469. * @param {Object} [opts]
  22470. * @param {string} [opts.text]
  22471. * @param {string} [opts.color]
  22472. * @param {string} [opts.textColor]
  22473. * @return {module:zrender/Element}
  22474. */
  22475. function defaultLoading(api, opts) {
  22476. opts = opts || {};
  22477. defaults(opts, {
  22478. text: 'loading',
  22479. textColor: '#000',
  22480. fontSize: 12,
  22481. fontWeight: 'normal',
  22482. fontStyle: 'normal',
  22483. fontFamily: 'sans-serif',
  22484. maskColor: 'rgba(255, 255, 255, 0.8)',
  22485. showSpinner: true,
  22486. color: '#5470c6',
  22487. spinnerRadius: 10,
  22488. lineWidth: 5,
  22489. zlevel: 0
  22490. });
  22491. var group = new Group();
  22492. var mask = new Rect({
  22493. style: {
  22494. fill: opts.maskColor
  22495. },
  22496. zlevel: opts.zlevel,
  22497. z: 10000
  22498. });
  22499. group.add(mask);
  22500. var textContent = new ZRText({
  22501. style: {
  22502. text: opts.text,
  22503. fill: opts.textColor,
  22504. fontSize: opts.fontSize,
  22505. fontWeight: opts.fontWeight,
  22506. fontStyle: opts.fontStyle,
  22507. fontFamily: opts.fontFamily
  22508. },
  22509. zlevel: opts.zlevel,
  22510. z: 10001
  22511. });
  22512. var labelRect = new Rect({
  22513. style: {
  22514. fill: 'none'
  22515. },
  22516. textContent: textContent,
  22517. textConfig: {
  22518. position: 'right',
  22519. distance: 10
  22520. },
  22521. zlevel: opts.zlevel,
  22522. z: 10001
  22523. });
  22524. group.add(labelRect);
  22525. var arc;
  22526. if (opts.showSpinner) {
  22527. arc = new Arc({
  22528. shape: {
  22529. startAngle: -PI$3 / 2,
  22530. endAngle: -PI$3 / 2 + 0.1,
  22531. r: opts.spinnerRadius
  22532. },
  22533. style: {
  22534. stroke: opts.color,
  22535. lineCap: 'round',
  22536. lineWidth: opts.lineWidth
  22537. },
  22538. zlevel: opts.zlevel,
  22539. z: 10001
  22540. });
  22541. arc.animateShape(true).when(1000, {
  22542. endAngle: PI$3 * 3 / 2
  22543. }).start('circularInOut');
  22544. arc.animateShape(true).when(1000, {
  22545. startAngle: PI$3 * 3 / 2
  22546. }).delay(300).start('circularInOut');
  22547. group.add(arc);
  22548. } // Inject resize
  22549. group.resize = function () {
  22550. var textWidth = textContent.getBoundingRect().width;
  22551. var r = opts.showSpinner ? opts.spinnerRadius : 0; // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  22552. // textDistance needs to be calculated when both animation and text exist
  22553. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 - (opts.showSpinner && textWidth ? 0 : 5 + textWidth / 2) // only show the text
  22554. + (opts.showSpinner ? 0 : textWidth / 2) // only show the spinner
  22555. + (textWidth ? 0 : r);
  22556. var cy = api.getHeight() / 2;
  22557. opts.showSpinner && arc.setShape({
  22558. cx: cx,
  22559. cy: cy
  22560. });
  22561. labelRect.setShape({
  22562. x: cx - r,
  22563. y: cy - r,
  22564. width: r * 2,
  22565. height: r * 2
  22566. });
  22567. mask.setShape({
  22568. x: 0,
  22569. y: 0,
  22570. width: api.getWidth(),
  22571. height: api.getHeight()
  22572. });
  22573. };
  22574. group.resize();
  22575. return group;
  22576. }
  22577. var Scheduler =
  22578. /** @class */
  22579. function () {
  22580. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  22581. // key: handlerUID
  22582. this._stageTaskMap = createHashMap();
  22583. this.ecInstance = ecInstance;
  22584. this.api = api; // Fix current processors in case that in some rear cases that
  22585. // processors might be registered after echarts instance created.
  22586. // Register processors incrementally for a echarts instance is
  22587. // not supported by this stream architecture.
  22588. dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  22589. visualHandlers = this._visualHandlers = visualHandlers.slice();
  22590. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  22591. }
  22592. Scheduler.prototype.restoreData = function (ecModel, payload) {
  22593. // TODO: Only restore needed series and components, but not all components.
  22594. // Currently `restoreData` of all of the series and component will be called.
  22595. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  22596. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  22597. // and some components like coordinate system, axes, dataZoom, visualMap only
  22598. // need their target series refresh.
  22599. // (1) If we are implementing this feature some day, we should consider these cases:
  22600. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  22601. // on the settings of `dataZoom`), it should be re-performed if the component
  22602. // is modified by `setOption`.
  22603. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  22604. // it should be re-performed when the result array of `getTargetSeries` changed.
  22605. // We use `dependencies` to cover these issues.
  22606. // (3) How to update target series when coordinate system related components modified.
  22607. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  22608. // and this case all of the tasks will be set as dirty.
  22609. ecModel.restoreData(payload); // Theoretically an overall task not only depends on each of its target series, but also
  22610. // depends on all of the series.
  22611. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  22612. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  22613. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  22614. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  22615. // probably cause state chaos (consider `dataZoomProcessor`).
  22616. this._stageTaskMap.each(function (taskRecord) {
  22617. var overallTask = taskRecord.overallTask;
  22618. overallTask && overallTask.dirty();
  22619. });
  22620. }; // If seriesModel provided, incremental threshold is check by series data.
  22621. Scheduler.prototype.getPerformArgs = function (task, isBlock) {
  22622. // For overall task
  22623. if (!task.__pipeline) {
  22624. return;
  22625. }
  22626. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  22627. var pCtx = pipeline.context;
  22628. var incremental = !isBlock && pipeline.progressiveEnabled && (!pCtx || pCtx.progressiveRender) && task.__idxInPipeline > pipeline.blockIndex;
  22629. var step = incremental ? pipeline.step : null;
  22630. var modDataCount = pCtx && pCtx.modDataCount;
  22631. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  22632. return {
  22633. step: step,
  22634. modBy: modBy,
  22635. modDataCount: modDataCount
  22636. };
  22637. };
  22638. Scheduler.prototype.getPipeline = function (pipelineId) {
  22639. return this._pipelineMap.get(pipelineId);
  22640. };
  22641. /**
  22642. * Current, progressive rendering starts from visual and layout.
  22643. * Always detect render mode in the same stage, avoiding that incorrect
  22644. * detection caused by data filtering.
  22645. * Caution:
  22646. * `updateStreamModes` use `seriesModel.getData()`.
  22647. */
  22648. Scheduler.prototype.updateStreamModes = function (seriesModel, view) {
  22649. var pipeline = this._pipelineMap.get(seriesModel.uid);
  22650. var data = seriesModel.getData();
  22651. var dataLen = data.count(); // `progressiveRender` means that can render progressively in each
  22652. // animation frame. Note that some types of series do not provide
  22653. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  22654. // use the term `incremental` but not `progressive` to describe the
  22655. // case that `chart.appendData`.
  22656. var progressiveRender = pipeline.progressiveEnabled && view.incrementalPrepareRender && dataLen >= pipeline.threshold;
  22657. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold'); // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  22658. // see `test/candlestick-large3.html`
  22659. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  22660. seriesModel.pipelineContext = pipeline.context = {
  22661. progressiveRender: progressiveRender,
  22662. modDataCount: modDataCount,
  22663. large: large
  22664. };
  22665. };
  22666. Scheduler.prototype.restorePipelines = function (ecModel) {
  22667. var scheduler = this;
  22668. var pipelineMap = scheduler._pipelineMap = createHashMap();
  22669. ecModel.eachSeries(function (seriesModel) {
  22670. var progressive = seriesModel.getProgressive();
  22671. var pipelineId = seriesModel.uid;
  22672. pipelineMap.set(pipelineId, {
  22673. id: pipelineId,
  22674. head: null,
  22675. tail: null,
  22676. threshold: seriesModel.getProgressiveThreshold(),
  22677. progressiveEnabled: progressive && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  22678. blockIndex: -1,
  22679. step: Math.round(progressive || 700),
  22680. count: 0
  22681. });
  22682. scheduler._pipe(seriesModel, seriesModel.dataTask);
  22683. });
  22684. };
  22685. Scheduler.prototype.prepareStageTasks = function () {
  22686. var stageTaskMap = this._stageTaskMap;
  22687. var ecModel = this.api.getModel();
  22688. var api = this.api;
  22689. each(this._allHandlers, function (handler) {
  22690. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, {});
  22691. var errMsg = '';
  22692. if ("development" !== 'production') {
  22693. // Currently do not need to support to sepecify them both.
  22694. errMsg = '"reset" and "overallReset" must not be both specified.';
  22695. }
  22696. assert(!(handler.reset && handler.overallReset), errMsg);
  22697. handler.reset && this._createSeriesStageTask(handler, record, ecModel, api);
  22698. handler.overallReset && this._createOverallStageTask(handler, record, ecModel, api);
  22699. }, this);
  22700. };
  22701. Scheduler.prototype.prepareView = function (view, model, ecModel, api) {
  22702. var renderTask = view.renderTask;
  22703. var context = renderTask.context;
  22704. context.model = model;
  22705. context.ecModel = ecModel;
  22706. context.api = api;
  22707. renderTask.__block = !view.incrementalPrepareRender;
  22708. this._pipe(model, renderTask);
  22709. };
  22710. Scheduler.prototype.performDataProcessorTasks = function (ecModel, payload) {
  22711. // If we do not use `block` here, it should be considered when to update modes.
  22712. this._performStageTasks(this._dataProcessorHandlers, ecModel, payload, {
  22713. block: true
  22714. });
  22715. };
  22716. Scheduler.prototype.performVisualTasks = function (ecModel, payload, opt) {
  22717. this._performStageTasks(this._visualHandlers, ecModel, payload, opt);
  22718. };
  22719. Scheduler.prototype._performStageTasks = function (stageHandlers, ecModel, payload, opt) {
  22720. opt = opt || {};
  22721. var unfinished = false;
  22722. var scheduler = this;
  22723. each(stageHandlers, function (stageHandler, idx) {
  22724. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  22725. return;
  22726. }
  22727. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  22728. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  22729. var overallTask = stageHandlerRecord.overallTask;
  22730. if (overallTask) {
  22731. var overallNeedDirty_1;
  22732. var agentStubMap = overallTask.agentStubMap;
  22733. agentStubMap.each(function (stub) {
  22734. if (needSetDirty(opt, stub)) {
  22735. stub.dirty();
  22736. overallNeedDirty_1 = true;
  22737. }
  22738. });
  22739. overallNeedDirty_1 && overallTask.dirty();
  22740. scheduler.updatePayload(overallTask, payload);
  22741. var performArgs_1 = scheduler.getPerformArgs(overallTask, opt.block); // Execute stubs firstly, which may set the overall task dirty,
  22742. // then execute the overall task. And stub will call seriesModel.setData,
  22743. // which ensures that in the overallTask seriesModel.getData() will not
  22744. // return incorrect data.
  22745. agentStubMap.each(function (stub) {
  22746. stub.perform(performArgs_1);
  22747. });
  22748. if (overallTask.perform(performArgs_1)) {
  22749. unfinished = true;
  22750. }
  22751. } else if (seriesTaskMap) {
  22752. seriesTaskMap.each(function (task, pipelineId) {
  22753. if (needSetDirty(opt, task)) {
  22754. task.dirty();
  22755. }
  22756. var performArgs = scheduler.getPerformArgs(task, opt.block); // FIXME
  22757. // if intending to decalare `performRawSeries` in handlers, only
  22758. // stream-independent (specifically, data item independent) operations can be
  22759. // performed. Because is a series is filtered, most of the tasks will not
  22760. // be performed. A stream-dependent operation probably cause wrong biz logic.
  22761. // Perhaps we should not provide a separate callback for this case instead
  22762. // of providing the config `performRawSeries`. The stream-dependent operaions
  22763. // and stream-independent operations should better not be mixed.
  22764. performArgs.skip = !stageHandler.performRawSeries && ecModel.isSeriesFiltered(task.context.model);
  22765. scheduler.updatePayload(task, payload);
  22766. if (task.perform(performArgs)) {
  22767. unfinished = true;
  22768. }
  22769. });
  22770. }
  22771. });
  22772. function needSetDirty(opt, task) {
  22773. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  22774. }
  22775. this.unfinished = unfinished || this.unfinished;
  22776. };
  22777. Scheduler.prototype.performSeriesTasks = function (ecModel) {
  22778. var unfinished;
  22779. ecModel.eachSeries(function (seriesModel) {
  22780. // Progress to the end for dataInit and dataRestore.
  22781. unfinished = seriesModel.dataTask.perform() || unfinished;
  22782. });
  22783. this.unfinished = unfinished || this.unfinished;
  22784. };
  22785. Scheduler.prototype.plan = function () {
  22786. // Travel pipelines, check block.
  22787. this._pipelineMap.each(function (pipeline) {
  22788. var task = pipeline.tail;
  22789. do {
  22790. if (task.__block) {
  22791. pipeline.blockIndex = task.__idxInPipeline;
  22792. break;
  22793. }
  22794. task = task.getUpstream();
  22795. } while (task);
  22796. });
  22797. };
  22798. Scheduler.prototype.updatePayload = function (task, payload) {
  22799. payload !== 'remain' && (task.context.payload = payload);
  22800. };
  22801. Scheduler.prototype._createSeriesStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  22802. var scheduler = this;
  22803. var oldSeriesTaskMap = stageHandlerRecord.seriesTaskMap; // The count of stages are totally about only several dozen, so
  22804. // do not need to reuse the map.
  22805. var newSeriesTaskMap = stageHandlerRecord.seriesTaskMap = createHashMap();
  22806. var seriesType = stageHandler.seriesType;
  22807. var getTargetSeries = stageHandler.getTargetSeries; // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  22808. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  22809. // it works but it may cause other irrelevant charts blocked.
  22810. if (stageHandler.createOnAllSeries) {
  22811. ecModel.eachRawSeries(create);
  22812. } else if (seriesType) {
  22813. ecModel.eachRawSeriesByType(seriesType, create);
  22814. } else if (getTargetSeries) {
  22815. getTargetSeries(ecModel, api).each(create);
  22816. }
  22817. function create(seriesModel) {
  22818. var pipelineId = seriesModel.uid; // Init tasks for each seriesModel only once.
  22819. // Reuse original task instance.
  22820. var task = newSeriesTaskMap.set(pipelineId, oldSeriesTaskMap && oldSeriesTaskMap.get(pipelineId) || createTask({
  22821. plan: seriesTaskPlan,
  22822. reset: seriesTaskReset,
  22823. count: seriesTaskCount
  22824. }));
  22825. task.context = {
  22826. model: seriesModel,
  22827. ecModel: ecModel,
  22828. api: api,
  22829. // PENDING: `useClearVisual` not used?
  22830. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  22831. plan: stageHandler.plan,
  22832. reset: stageHandler.reset,
  22833. scheduler: scheduler
  22834. };
  22835. scheduler._pipe(seriesModel, task);
  22836. }
  22837. };
  22838. Scheduler.prototype._createOverallStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  22839. var scheduler = this;
  22840. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask // For overall task, the function only be called on reset stage.
  22841. || createTask({
  22842. reset: overallTaskReset
  22843. });
  22844. overallTask.context = {
  22845. ecModel: ecModel,
  22846. api: api,
  22847. overallReset: stageHandler.overallReset,
  22848. scheduler: scheduler
  22849. };
  22850. var oldAgentStubMap = overallTask.agentStubMap; // The count of stages are totally about only several dozen, so
  22851. // do not need to reuse the map.
  22852. var newAgentStubMap = overallTask.agentStubMap = createHashMap();
  22853. var seriesType = stageHandler.seriesType;
  22854. var getTargetSeries = stageHandler.getTargetSeries;
  22855. var overallProgress = true;
  22856. var shouldOverallTaskDirty = false; // FIXME:TS never used, so comment it
  22857. // let modifyOutputEnd = stageHandler.modifyOutputEnd;
  22858. // An overall task with seriesType detected or has `getTargetSeries`, we add
  22859. // stub in each pipelines, it will set the overall task dirty when the pipeline
  22860. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  22861. // we set the pipeline block.
  22862. var errMsg = '';
  22863. if ("development" !== 'production') {
  22864. errMsg = '"createOnAllSeries" do not supported for "overallReset", ' + 'becuase it will block all streams.';
  22865. }
  22866. assert(!stageHandler.createOnAllSeries, errMsg);
  22867. if (seriesType) {
  22868. ecModel.eachRawSeriesByType(seriesType, createStub);
  22869. } else if (getTargetSeries) {
  22870. getTargetSeries(ecModel, api).each(createStub);
  22871. } // Otherwise, (usually it is legancy case), the overall task will only be
  22872. // executed when upstream dirty. Otherwise the progressive rendering of all
  22873. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  22874. // dirty info from upsteam.
  22875. else {
  22876. overallProgress = false;
  22877. each(ecModel.getSeries(), createStub);
  22878. }
  22879. function createStub(seriesModel) {
  22880. var pipelineId = seriesModel.uid;
  22881. var stub = newAgentStubMap.set(pipelineId, oldAgentStubMap && oldAgentStubMap.get(pipelineId) || ( // When the result of `getTargetSeries` changed, the overallTask
  22882. // should be set as dirty and re-performed.
  22883. shouldOverallTaskDirty = true, createTask({
  22884. reset: stubReset,
  22885. onDirty: stubOnDirty
  22886. })));
  22887. stub.context = {
  22888. model: seriesModel,
  22889. overallProgress: overallProgress // FIXME:TS never used, so comment it
  22890. // modifyOutputEnd: modifyOutputEnd
  22891. };
  22892. stub.agent = overallTask;
  22893. stub.__block = overallProgress;
  22894. scheduler._pipe(seriesModel, stub);
  22895. }
  22896. if (shouldOverallTaskDirty) {
  22897. overallTask.dirty();
  22898. }
  22899. };
  22900. Scheduler.prototype._pipe = function (seriesModel, task) {
  22901. var pipelineId = seriesModel.uid;
  22902. var pipeline = this._pipelineMap.get(pipelineId);
  22903. !pipeline.head && (pipeline.head = task);
  22904. pipeline.tail && pipeline.tail.pipe(task);
  22905. pipeline.tail = task;
  22906. task.__idxInPipeline = pipeline.count++;
  22907. task.__pipeline = pipeline;
  22908. };
  22909. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  22910. if (isFunction(stageHandler)) {
  22911. stageHandler = {
  22912. overallReset: stageHandler,
  22913. seriesType: detectSeriseType(stageHandler)
  22914. };
  22915. }
  22916. stageHandler.uid = getUID('stageHandler');
  22917. visualType && (stageHandler.visualType = visualType);
  22918. return stageHandler;
  22919. };
  22920. return Scheduler;
  22921. }();
  22922. function overallTaskReset(context) {
  22923. context.overallReset(context.ecModel, context.api, context.payload);
  22924. }
  22925. function stubReset(context) {
  22926. return context.overallProgress && stubProgress;
  22927. }
  22928. function stubProgress() {
  22929. this.agent.dirty();
  22930. this.getDownstream().dirty();
  22931. }
  22932. function stubOnDirty() {
  22933. this.agent && this.agent.dirty();
  22934. }
  22935. function seriesTaskPlan(context) {
  22936. return context.plan ? context.plan(context.model, context.ecModel, context.api, context.payload) : null;
  22937. }
  22938. function seriesTaskReset(context) {
  22939. if (context.useClearVisual) {
  22940. context.data.clearAllVisual();
  22941. }
  22942. var resetDefines = context.resetDefines = normalizeToArray(context.reset(context.model, context.ecModel, context.api, context.payload));
  22943. return resetDefines.length > 1 ? map(resetDefines, function (v, idx) {
  22944. return makeSeriesTaskProgress(idx);
  22945. }) : singleSeriesTaskProgress;
  22946. }
  22947. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  22948. function makeSeriesTaskProgress(resetDefineIdx) {
  22949. return function (params, context) {
  22950. var data = context.data;
  22951. var resetDefine = context.resetDefines[resetDefineIdx];
  22952. if (resetDefine && resetDefine.dataEach) {
  22953. for (var i = params.start; i < params.end; i++) {
  22954. resetDefine.dataEach(data, i);
  22955. }
  22956. } else if (resetDefine && resetDefine.progress) {
  22957. resetDefine.progress(params, data);
  22958. }
  22959. };
  22960. }
  22961. function seriesTaskCount(context) {
  22962. return context.data.count();
  22963. }
  22964. /**
  22965. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  22966. * To ensure that they can work normally, they should work in block mode, that is,
  22967. * they should not be started util the previous tasks finished. So they cause the
  22968. * progressive rendering disabled. We try to detect the series type, to narrow down
  22969. * the block range to only the series type they concern, but not all series.
  22970. */
  22971. function detectSeriseType(legacyFunc) {
  22972. seriesType = null;
  22973. try {
  22974. // Assume there is no async when calling `eachSeriesByType`.
  22975. legacyFunc(ecModelMock, apiMock);
  22976. } catch (e) {}
  22977. return seriesType;
  22978. }
  22979. var ecModelMock = {};
  22980. var apiMock = {};
  22981. var seriesType;
  22982. mockMethods(ecModelMock, GlobalModel);
  22983. mockMethods(apiMock, ExtensionAPI);
  22984. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  22985. seriesType = type;
  22986. };
  22987. ecModelMock.eachComponent = function (cond) {
  22988. if (cond.mainType === 'series' && cond.subType) {
  22989. seriesType = cond.subType;
  22990. }
  22991. };
  22992. function mockMethods(target, Clz) {
  22993. /* eslint-disable */
  22994. for (var name_1 in Clz.prototype) {
  22995. // Do not use hasOwnProperty
  22996. target[name_1] = noop;
  22997. }
  22998. /* eslint-enable */
  22999. }
  23000. /*
  23001. * Licensed to the Apache Software Foundation (ASF) under one
  23002. * or more contributor license agreements. See the NOTICE file
  23003. * distributed with this work for additional information
  23004. * regarding copyright ownership. The ASF licenses this file
  23005. * to you under the Apache License, Version 2.0 (the
  23006. * "License"); you may not use this file except in compliance
  23007. * with the License. You may obtain a copy of the License at
  23008. *
  23009. * http://www.apache.org/licenses/LICENSE-2.0
  23010. *
  23011. * Unless required by applicable law or agreed to in writing,
  23012. * software distributed under the License is distributed on an
  23013. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23014. * KIND, either express or implied. See the License for the
  23015. * specific language governing permissions and limitations
  23016. * under the License.
  23017. */
  23018. /**
  23019. * AUTO-GENERATED FILE. DO NOT MODIFY.
  23020. */
  23021. /*
  23022. * Licensed to the Apache Software Foundation (ASF) under one
  23023. * or more contributor license agreements. See the NOTICE file
  23024. * distributed with this work for additional information
  23025. * regarding copyright ownership. The ASF licenses this file
  23026. * to you under the Apache License, Version 2.0 (the
  23027. * "License"); you may not use this file except in compliance
  23028. * with the License. You may obtain a copy of the License at
  23029. *
  23030. * http://www.apache.org/licenses/LICENSE-2.0
  23031. *
  23032. * Unless required by applicable law or agreed to in writing,
  23033. * software distributed under the License is distributed on an
  23034. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23035. * KIND, either express or implied. See the License for the
  23036. * specific language governing permissions and limitations
  23037. * under the License.
  23038. */
  23039. var colorAll = ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'];
  23040. var lightTheme = {
  23041. color: colorAll,
  23042. colorLayer: [['#37A2DA', '#ffd85c', '#fd7b5f'], ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'], ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'], colorAll]
  23043. };
  23044. /*
  23045. * Licensed to the Apache Software Foundation (ASF) under one
  23046. * or more contributor license agreements. See the NOTICE file
  23047. * distributed with this work for additional information
  23048. * regarding copyright ownership. The ASF licenses this file
  23049. * to you under the Apache License, Version 2.0 (the
  23050. * "License"); you may not use this file except in compliance
  23051. * with the License. You may obtain a copy of the License at
  23052. *
  23053. * http://www.apache.org/licenses/LICENSE-2.0
  23054. *
  23055. * Unless required by applicable law or agreed to in writing,
  23056. * software distributed under the License is distributed on an
  23057. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23058. * KIND, either express or implied. See the License for the
  23059. * specific language governing permissions and limitations
  23060. * under the License.
  23061. */
  23062. /**
  23063. * AUTO-GENERATED FILE. DO NOT MODIFY.
  23064. */
  23065. /*
  23066. * Licensed to the Apache Software Foundation (ASF) under one
  23067. * or more contributor license agreements. See the NOTICE file
  23068. * distributed with this work for additional information
  23069. * regarding copyright ownership. The ASF licenses this file
  23070. * to you under the Apache License, Version 2.0 (the
  23071. * "License"); you may not use this file except in compliance
  23072. * with the License. You may obtain a copy of the License at
  23073. *
  23074. * http://www.apache.org/licenses/LICENSE-2.0
  23075. *
  23076. * Unless required by applicable law or agreed to in writing,
  23077. * software distributed under the License is distributed on an
  23078. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23079. * KIND, either express or implied. See the License for the
  23080. * specific language governing permissions and limitations
  23081. * under the License.
  23082. */
  23083. var contrastColor = '#B9B8CE';
  23084. var backgroundColor = '#100C2A';
  23085. var axisCommon = function () {
  23086. return {
  23087. axisLine: {
  23088. lineStyle: {
  23089. color: contrastColor
  23090. }
  23091. },
  23092. splitLine: {
  23093. lineStyle: {
  23094. color: '#484753'
  23095. }
  23096. },
  23097. splitArea: {
  23098. areaStyle: {
  23099. color: ['rgba(255,255,255,0.02)', 'rgba(255,255,255,0.05)']
  23100. }
  23101. },
  23102. minorSplitLine: {
  23103. lineStyle: {
  23104. color: '#20203B'
  23105. }
  23106. }
  23107. };
  23108. };
  23109. var colorPalette = ['#4992ff', '#7cffb2', '#fddd60', '#ff6e76', '#58d9f9', '#05c091', '#ff8a45', '#8d48e3', '#dd79ff'];
  23110. var theme = {
  23111. darkMode: true,
  23112. color: colorPalette,
  23113. backgroundColor: backgroundColor,
  23114. axisPointer: {
  23115. lineStyle: {
  23116. color: '#817f91'
  23117. },
  23118. crossStyle: {
  23119. color: '#817f91'
  23120. },
  23121. label: {
  23122. // TODO Contrast of label backgorundColor
  23123. color: '#fff'
  23124. }
  23125. },
  23126. legend: {
  23127. textStyle: {
  23128. color: contrastColor
  23129. }
  23130. },
  23131. textStyle: {
  23132. color: contrastColor
  23133. },
  23134. title: {
  23135. textStyle: {
  23136. color: '#EEF1FA'
  23137. },
  23138. subtextStyle: {
  23139. color: '#B9B8CE'
  23140. }
  23141. },
  23142. toolbox: {
  23143. iconStyle: {
  23144. borderColor: contrastColor
  23145. }
  23146. },
  23147. dataZoom: {
  23148. borderColor: '#71708A',
  23149. textStyle: {
  23150. color: contrastColor
  23151. },
  23152. brushStyle: {
  23153. color: 'rgba(135,163,206,0.3)'
  23154. },
  23155. handleStyle: {
  23156. color: '#353450',
  23157. borderColor: '#C5CBE3'
  23158. },
  23159. moveHandleStyle: {
  23160. color: '#B0B6C3',
  23161. opacity: 0.3
  23162. },
  23163. fillerColor: 'rgba(135,163,206,0.2)',
  23164. emphasis: {
  23165. handleStyle: {
  23166. borderColor: '#91B7F2',
  23167. color: '#4D587D'
  23168. },
  23169. moveHandleStyle: {
  23170. color: '#636D9A',
  23171. opacity: 0.7
  23172. }
  23173. },
  23174. dataBackground: {
  23175. lineStyle: {
  23176. color: '#71708A',
  23177. width: 1
  23178. },
  23179. areaStyle: {
  23180. color: '#71708A'
  23181. }
  23182. },
  23183. selectedDataBackground: {
  23184. lineStyle: {
  23185. color: '#87A3CE'
  23186. },
  23187. areaStyle: {
  23188. color: '#87A3CE'
  23189. }
  23190. }
  23191. },
  23192. visualMap: {
  23193. textStyle: {
  23194. color: contrastColor
  23195. }
  23196. },
  23197. timeline: {
  23198. lineStyle: {
  23199. color: contrastColor
  23200. },
  23201. label: {
  23202. color: contrastColor
  23203. },
  23204. controlStyle: {
  23205. color: contrastColor,
  23206. borderColor: contrastColor
  23207. }
  23208. },
  23209. calendar: {
  23210. itemStyle: {
  23211. color: backgroundColor
  23212. },
  23213. dayLabel: {
  23214. color: contrastColor
  23215. },
  23216. monthLabel: {
  23217. color: contrastColor
  23218. },
  23219. yearLabel: {
  23220. color: contrastColor
  23221. }
  23222. },
  23223. timeAxis: axisCommon(),
  23224. logAxis: axisCommon(),
  23225. valueAxis: axisCommon(),
  23226. categoryAxis: axisCommon(),
  23227. line: {
  23228. symbol: 'circle'
  23229. },
  23230. graph: {
  23231. color: colorPalette
  23232. },
  23233. gauge: {
  23234. title: {
  23235. color: contrastColor
  23236. },
  23237. axisLine: {
  23238. lineStyle: {
  23239. color: [[1, 'rgba(207,212,219,0.2)']]
  23240. }
  23241. },
  23242. axisLabel: {
  23243. color: contrastColor
  23244. },
  23245. detail: {
  23246. color: '#EEF1FA'
  23247. }
  23248. },
  23249. candlestick: {
  23250. itemStyle: {
  23251. color: '#f64e56',
  23252. color0: '#54ea92',
  23253. borderColor: '#f64e56',
  23254. borderColor0: '#54ea92' // borderColor: '#ca2824',
  23255. // borderColor0: '#09a443'
  23256. }
  23257. }
  23258. };
  23259. theme.categoryAxis.splitLine.show = false;
  23260. /**
  23261. * Usage of query:
  23262. * `chart.on('click', query, handler);`
  23263. * The `query` can be:
  23264. * + The component type query string, only `mainType` or `mainType.subType`,
  23265. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  23266. * + The component query object, like:
  23267. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  23268. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  23269. * + The data query object, like:
  23270. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  23271. * + The other query object (cmponent customized query), like:
  23272. * `{element: 'some'}` (only available in custom series).
  23273. *
  23274. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  23275. * same as there is no such prop in the `query` object.
  23276. */
  23277. var ECEventProcessor =
  23278. /** @class */
  23279. function () {
  23280. function ECEventProcessor() {}
  23281. ECEventProcessor.prototype.normalizeQuery = function (query) {
  23282. var cptQuery = {};
  23283. var dataQuery = {};
  23284. var otherQuery = {}; // `query` is `mainType` or `mainType.subType` of component.
  23285. if (isString(query)) {
  23286. var condCptType = parseClassType(query); // `.main` and `.sub` may be ''.
  23287. cptQuery.mainType = condCptType.main || null;
  23288. cptQuery.subType = condCptType.sub || null;
  23289. } // `query` is an object, convert to {mainType, index, name, id}.
  23290. else {
  23291. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  23292. // can not be used in `compomentModel.filterForExposedEvent`.
  23293. var suffixes_1 = ['Index', 'Name', 'Id'];
  23294. var dataKeys_1 = {
  23295. name: 1,
  23296. dataIndex: 1,
  23297. dataType: 1
  23298. };
  23299. each(query, function (val, key) {
  23300. var reserved = false;
  23301. for (var i = 0; i < suffixes_1.length; i++) {
  23302. var propSuffix = suffixes_1[i];
  23303. var suffixPos = key.lastIndexOf(propSuffix);
  23304. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  23305. var mainType = key.slice(0, suffixPos); // Consider `dataIndex`.
  23306. if (mainType !== 'data') {
  23307. cptQuery.mainType = mainType;
  23308. cptQuery[propSuffix.toLowerCase()] = val;
  23309. reserved = true;
  23310. }
  23311. }
  23312. }
  23313. if (dataKeys_1.hasOwnProperty(key)) {
  23314. dataQuery[key] = val;
  23315. reserved = true;
  23316. }
  23317. if (!reserved) {
  23318. otherQuery[key] = val;
  23319. }
  23320. });
  23321. }
  23322. return {
  23323. cptQuery: cptQuery,
  23324. dataQuery: dataQuery,
  23325. otherQuery: otherQuery
  23326. };
  23327. };
  23328. ECEventProcessor.prototype.filter = function (eventType, query) {
  23329. // They should be assigned before each trigger call.
  23330. var eventInfo = this.eventInfo;
  23331. if (!eventInfo) {
  23332. return true;
  23333. }
  23334. var targetEl = eventInfo.targetEl;
  23335. var packedEvent = eventInfo.packedEvent;
  23336. var model = eventInfo.model;
  23337. var view = eventInfo.view; // For event like 'globalout'.
  23338. if (!model || !view) {
  23339. return true;
  23340. }
  23341. var cptQuery = query.cptQuery;
  23342. var dataQuery = query.dataQuery;
  23343. 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));
  23344. function check(query, host, prop, propOnHost) {
  23345. return query[prop] == null || host[propOnHost || prop] === query[prop];
  23346. }
  23347. };
  23348. ECEventProcessor.prototype.afterTrigger = function () {
  23349. // Make sure the eventInfo wont be used in next trigger.
  23350. this.eventInfo = null;
  23351. };
  23352. return ECEventProcessor;
  23353. }();
  23354. var seriesSymbolTask = {
  23355. createOnAllSeries: true,
  23356. // For legend.
  23357. performRawSeries: true,
  23358. reset: function (seriesModel, ecModel) {
  23359. var data = seriesModel.getData();
  23360. if (seriesModel.legendIcon) {
  23361. data.setVisual('legendIcon', seriesModel.legendIcon);
  23362. }
  23363. if (!seriesModel.hasSymbolVisual) {
  23364. return;
  23365. }
  23366. var symbolType = seriesModel.get('symbol');
  23367. var symbolSize = seriesModel.get('symbolSize');
  23368. var keepAspect = seriesModel.get('symbolKeepAspect');
  23369. var symbolRotate = seriesModel.get('symbolRotate');
  23370. var symbolOffset = seriesModel.get('symbolOffset');
  23371. var hasSymbolTypeCallback = isFunction(symbolType);
  23372. var hasSymbolSizeCallback = isFunction(symbolSize);
  23373. var hasSymbolRotateCallback = isFunction(symbolRotate);
  23374. var hasSymbolOffsetCallback = isFunction(symbolOffset);
  23375. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback || hasSymbolOffsetCallback;
  23376. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : seriesModel.defaultSymbol;
  23377. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  23378. var seriesSymbolRotate = !hasSymbolRotateCallback ? symbolRotate : null;
  23379. var seriesSymbolOffset = !hasSymbolOffsetCallback ? symbolOffset : null;
  23380. data.setVisual({
  23381. legendIcon: seriesModel.legendIcon || seriesSymbol,
  23382. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  23383. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  23384. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  23385. // some cases but generally it is not recommanded.
  23386. symbol: seriesSymbol,
  23387. symbolSize: seriesSymbolSize,
  23388. symbolKeepAspect: keepAspect,
  23389. symbolRotate: seriesSymbolRotate,
  23390. symbolOffset: seriesSymbolOffset
  23391. }); // Only visible series has each data be visual encoded
  23392. if (ecModel.isSeriesFiltered(seriesModel)) {
  23393. return;
  23394. }
  23395. function dataEach(data, idx) {
  23396. var rawValue = seriesModel.getRawValue(idx);
  23397. var params = seriesModel.getDataParams(idx);
  23398. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  23399. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  23400. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  23401. hasSymbolOffsetCallback && data.setItemVisual(idx, 'symbolOffset', symbolOffset(rawValue, params));
  23402. }
  23403. return {
  23404. dataEach: hasCallback ? dataEach : null
  23405. };
  23406. }
  23407. };
  23408. var dataSymbolTask = {
  23409. createOnAllSeries: true,
  23410. // For legend.
  23411. performRawSeries: true,
  23412. reset: function (seriesModel, ecModel) {
  23413. if (!seriesModel.hasSymbolVisual) {
  23414. return;
  23415. } // Only visible series has each data be visual encoded
  23416. if (ecModel.isSeriesFiltered(seriesModel)) {
  23417. return;
  23418. }
  23419. var data = seriesModel.getData();
  23420. function dataEach(data, idx) {
  23421. var itemModel = data.getItemModel(idx);
  23422. var itemSymbolType = itemModel.getShallow('symbol', true);
  23423. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  23424. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  23425. var itemSymbolOffset = itemModel.getShallow('symbolOffset', true);
  23426. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  23427. if (itemSymbolType != null) {
  23428. data.setItemVisual(idx, 'symbol', itemSymbolType);
  23429. }
  23430. if (itemSymbolSize != null) {
  23431. // PENDING Transform symbolSize ?
  23432. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  23433. }
  23434. if (itemSymbolRotate != null) {
  23435. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  23436. }
  23437. if (itemSymbolOffset != null) {
  23438. data.setItemVisual(idx, 'symbolOffset', itemSymbolOffset);
  23439. }
  23440. if (itemSymbolKeepAspect != null) {
  23441. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  23442. }
  23443. }
  23444. return {
  23445. dataEach: data.hasItemOption ? dataEach : null
  23446. };
  23447. }
  23448. };
  23449. /*
  23450. * Licensed to the Apache Software Foundation (ASF) under one
  23451. * or more contributor license agreements. See the NOTICE file
  23452. * distributed with this work for additional information
  23453. * regarding copyright ownership. The ASF licenses this file
  23454. * to you under the Apache License, Version 2.0 (the
  23455. * "License"); you may not use this file except in compliance
  23456. * with the License. You may obtain a copy of the License at
  23457. *
  23458. * http://www.apache.org/licenses/LICENSE-2.0
  23459. *
  23460. * Unless required by applicable law or agreed to in writing,
  23461. * software distributed under the License is distributed on an
  23462. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23463. * KIND, either express or implied. See the License for the
  23464. * specific language governing permissions and limitations
  23465. * under the License.
  23466. */
  23467. /**
  23468. * AUTO-GENERATED FILE. DO NOT MODIFY.
  23469. */
  23470. /*
  23471. * Licensed to the Apache Software Foundation (ASF) under one
  23472. * or more contributor license agreements. See the NOTICE file
  23473. * distributed with this work for additional information
  23474. * regarding copyright ownership. The ASF licenses this file
  23475. * to you under the Apache License, Version 2.0 (the
  23476. * "License"); you may not use this file except in compliance
  23477. * with the License. You may obtain a copy of the License at
  23478. *
  23479. * http://www.apache.org/licenses/LICENSE-2.0
  23480. *
  23481. * Unless required by applicable law or agreed to in writing,
  23482. * software distributed under the License is distributed on an
  23483. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23484. * KIND, either express or implied. See the License for the
  23485. * specific language governing permissions and limitations
  23486. * under the License.
  23487. */
  23488. function getItemVisualFromData(data, dataIndex, key) {
  23489. switch (key) {
  23490. case 'color':
  23491. var style = data.getItemVisual(dataIndex, 'style');
  23492. return style[data.getVisual('drawType')];
  23493. case 'opacity':
  23494. return data.getItemVisual(dataIndex, 'style').opacity;
  23495. case 'symbol':
  23496. case 'symbolSize':
  23497. case 'liftZ':
  23498. return data.getItemVisual(dataIndex, key);
  23499. default:
  23500. if ("development" !== 'production') {
  23501. console.warn("Unknown visual type " + key);
  23502. }
  23503. }
  23504. }
  23505. function getVisualFromData(data, key) {
  23506. switch (key) {
  23507. case 'color':
  23508. var style = data.getVisual('style');
  23509. return style[data.getVisual('drawType')];
  23510. case 'opacity':
  23511. return data.getVisual('style').opacity;
  23512. case 'symbol':
  23513. case 'symbolSize':
  23514. case 'liftZ':
  23515. return data.getVisual(key);
  23516. default:
  23517. if ("development" !== 'production') {
  23518. console.warn("Unknown visual type " + key);
  23519. }
  23520. }
  23521. }
  23522. // Inlucdes: pieSelect, pieUnSelect, pieToggleSelect, mapSelect, mapUnSelect, mapToggleSelect
  23523. function createLegacyDataSelectAction(seriesType, ecRegisterAction) {
  23524. function getSeriesIndices(ecModel, payload) {
  23525. var seriesIndices = [];
  23526. ecModel.eachComponent({
  23527. mainType: 'series',
  23528. subType: seriesType,
  23529. query: payload
  23530. }, function (seriesModel) {
  23531. seriesIndices.push(seriesModel.seriesIndex);
  23532. });
  23533. return seriesIndices;
  23534. }
  23535. each([[seriesType + 'ToggleSelect', 'toggleSelect'], [seriesType + 'Select', 'select'], [seriesType + 'UnSelect', 'unselect']], function (eventsMap) {
  23536. ecRegisterAction(eventsMap[0], function (payload, ecModel, api) {
  23537. payload = extend({}, payload);
  23538. if ("development" !== 'production') {
  23539. deprecateReplaceLog(payload.type, eventsMap[1]);
  23540. }
  23541. api.dispatchAction(extend(payload, {
  23542. type: eventsMap[1],
  23543. seriesIndex: getSeriesIndices(ecModel, payload)
  23544. }));
  23545. });
  23546. });
  23547. }
  23548. function handleSeriesLegacySelectEvents(type, eventPostfix, ecIns, ecModel, payload) {
  23549. var legacyEventName = type + eventPostfix;
  23550. if (!ecIns.isSilent(legacyEventName)) {
  23551. if ("development" !== 'production') {
  23552. deprecateLog("event " + legacyEventName + " is deprecated.");
  23553. }
  23554. ecModel.eachComponent({
  23555. mainType: 'series',
  23556. subType: 'pie'
  23557. }, function (seriesModel) {
  23558. var seriesIndex = seriesModel.seriesIndex;
  23559. var selected = payload.selected;
  23560. for (var i = 0; i < selected.length; i++) {
  23561. if (selected[i].seriesIndex === seriesIndex) {
  23562. var data = seriesModel.getData();
  23563. var dataIndex = queryDataIndex(data, payload.fromActionPayload);
  23564. ecIns.trigger(legacyEventName, {
  23565. type: legacyEventName,
  23566. seriesId: seriesModel.id,
  23567. name: isArray(dataIndex) ? data.getName(dataIndex[0]) : data.getName(dataIndex),
  23568. selected: extend({}, seriesModel.option.selectedMap)
  23569. });
  23570. }
  23571. }
  23572. });
  23573. }
  23574. }
  23575. function handleLegacySelectEvents(messageCenter, ecIns, api) {
  23576. messageCenter.on('selectchanged', function (params) {
  23577. var ecModel = api.getModel();
  23578. if (params.isFromClick) {
  23579. handleSeriesLegacySelectEvents('map', 'selectchanged', ecIns, ecModel, params);
  23580. handleSeriesLegacySelectEvents('pie', 'selectchanged', ecIns, ecModel, params);
  23581. } else if (params.fromAction === 'select') {
  23582. handleSeriesLegacySelectEvents('map', 'selected', ecIns, ecModel, params);
  23583. handleSeriesLegacySelectEvents('pie', 'selected', ecIns, ecModel, params);
  23584. } else if (params.fromAction === 'unselect') {
  23585. handleSeriesLegacySelectEvents('map', 'unselected', ecIns, ecModel, params);
  23586. handleSeriesLegacySelectEvents('pie', 'unselected', ecIns, ecModel, params);
  23587. }
  23588. });
  23589. }
  23590. /*
  23591. * Licensed to the Apache Software Foundation (ASF) under one
  23592. * or more contributor license agreements. See the NOTICE file
  23593. * distributed with this work for additional information
  23594. * regarding copyright ownership. The ASF licenses this file
  23595. * to you under the Apache License, Version 2.0 (the
  23596. * "License"); you may not use this file except in compliance
  23597. * with the License. You may obtain a copy of the License at
  23598. *
  23599. * http://www.apache.org/licenses/LICENSE-2.0
  23600. *
  23601. * Unless required by applicable law or agreed to in writing,
  23602. * software distributed under the License is distributed on an
  23603. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23604. * KIND, either express or implied. See the License for the
  23605. * specific language governing permissions and limitations
  23606. * under the License.
  23607. */
  23608. /**
  23609. * AUTO-GENERATED FILE. DO NOT MODIFY.
  23610. */
  23611. /*
  23612. * Licensed to the Apache Software Foundation (ASF) under one
  23613. * or more contributor license agreements. See the NOTICE file
  23614. * distributed with this work for additional information
  23615. * regarding copyright ownership. The ASF licenses this file
  23616. * to you under the Apache License, Version 2.0 (the
  23617. * "License"); you may not use this file except in compliance
  23618. * with the License. You may obtain a copy of the License at
  23619. *
  23620. * http://www.apache.org/licenses/LICENSE-2.0
  23621. *
  23622. * Unless required by applicable law or agreed to in writing,
  23623. * software distributed under the License is distributed on an
  23624. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23625. * KIND, either express or implied. See the License for the
  23626. * specific language governing permissions and limitations
  23627. * under the License.
  23628. */
  23629. function findEventDispatcher(target, det, returnFirstMatch) {
  23630. var found;
  23631. while (target) {
  23632. if (det(target)) {
  23633. found = target;
  23634. if (returnFirstMatch) {
  23635. break;
  23636. }
  23637. }
  23638. target = target.__hostTarget || target.parent;
  23639. }
  23640. return found;
  23641. }
  23642. var wmUniqueIndex = Math.round(Math.random() * 9);
  23643. var supportDefineProperty = typeof Object.defineProperty === 'function';
  23644. var WeakMap = (function () {
  23645. function WeakMap() {
  23646. this._id = '__ec_inner_' + wmUniqueIndex++;
  23647. }
  23648. WeakMap.prototype.get = function (key) {
  23649. return this._guard(key)[this._id];
  23650. };
  23651. WeakMap.prototype.set = function (key, value) {
  23652. var target = this._guard(key);
  23653. if (supportDefineProperty) {
  23654. Object.defineProperty(target, this._id, {
  23655. value: value,
  23656. enumerable: false,
  23657. configurable: true
  23658. });
  23659. }
  23660. else {
  23661. target[this._id] = value;
  23662. }
  23663. return this;
  23664. };
  23665. WeakMap.prototype["delete"] = function (key) {
  23666. if (this.has(key)) {
  23667. delete this._guard(key)[this._id];
  23668. return true;
  23669. }
  23670. return false;
  23671. };
  23672. WeakMap.prototype.has = function (key) {
  23673. return !!this._guard(key)[this._id];
  23674. };
  23675. WeakMap.prototype._guard = function (key) {
  23676. if (key !== Object(key)) {
  23677. throw TypeError('Value of WeakMap is not a non-null object.');
  23678. }
  23679. return key;
  23680. };
  23681. return WeakMap;
  23682. }());
  23683. /**
  23684. * Triangle shape
  23685. * @inner
  23686. */
  23687. var Triangle = Path.extend({
  23688. type: 'triangle',
  23689. shape: {
  23690. cx: 0,
  23691. cy: 0,
  23692. width: 0,
  23693. height: 0
  23694. },
  23695. buildPath: function (path, shape) {
  23696. var cx = shape.cx;
  23697. var cy = shape.cy;
  23698. var width = shape.width / 2;
  23699. var height = shape.height / 2;
  23700. path.moveTo(cx, cy - height);
  23701. path.lineTo(cx + width, cy + height);
  23702. path.lineTo(cx - width, cy + height);
  23703. path.closePath();
  23704. }
  23705. });
  23706. /**
  23707. * Diamond shape
  23708. * @inner
  23709. */
  23710. var Diamond = Path.extend({
  23711. type: 'diamond',
  23712. shape: {
  23713. cx: 0,
  23714. cy: 0,
  23715. width: 0,
  23716. height: 0
  23717. },
  23718. buildPath: function (path, shape) {
  23719. var cx = shape.cx;
  23720. var cy = shape.cy;
  23721. var width = shape.width / 2;
  23722. var height = shape.height / 2;
  23723. path.moveTo(cx, cy - height);
  23724. path.lineTo(cx + width, cy);
  23725. path.lineTo(cx, cy + height);
  23726. path.lineTo(cx - width, cy);
  23727. path.closePath();
  23728. }
  23729. });
  23730. /**
  23731. * Pin shape
  23732. * @inner
  23733. */
  23734. var Pin = Path.extend({
  23735. type: 'pin',
  23736. shape: {
  23737. // x, y on the cusp
  23738. x: 0,
  23739. y: 0,
  23740. width: 0,
  23741. height: 0
  23742. },
  23743. buildPath: function (path, shape) {
  23744. var x = shape.x;
  23745. var y = shape.y;
  23746. var w = shape.width / 5 * 3; // Height must be larger than width
  23747. var h = Math.max(w, shape.height);
  23748. var r = w / 2; // Dist on y with tangent point and circle center
  23749. var dy = r * r / (h - r);
  23750. var cy = y - h + r + dy;
  23751. var angle = Math.asin(dy / r); // Dist on x with tangent point and circle center
  23752. var dx = Math.cos(angle) * r;
  23753. var tanX = Math.sin(angle);
  23754. var tanY = Math.cos(angle);
  23755. var cpLen = r * 0.6;
  23756. var cpLen2 = r * 0.7;
  23757. path.moveTo(x - dx, cy + dy);
  23758. path.arc(x, cy, r, Math.PI - angle, Math.PI * 2 + angle);
  23759. path.bezierCurveTo(x + dx - tanX * cpLen, cy + dy + tanY * cpLen, x, y - cpLen2, x, y);
  23760. path.bezierCurveTo(x, y - cpLen2, x - dx + tanX * cpLen, cy + dy + tanY * cpLen, x - dx, cy + dy);
  23761. path.closePath();
  23762. }
  23763. });
  23764. /**
  23765. * Arrow shape
  23766. * @inner
  23767. */
  23768. var Arrow = Path.extend({
  23769. type: 'arrow',
  23770. shape: {
  23771. x: 0,
  23772. y: 0,
  23773. width: 0,
  23774. height: 0
  23775. },
  23776. buildPath: function (ctx, shape) {
  23777. var height = shape.height;
  23778. var width = shape.width;
  23779. var x = shape.x;
  23780. var y = shape.y;
  23781. var dx = width / 3 * 2;
  23782. ctx.moveTo(x, y);
  23783. ctx.lineTo(x + dx, y + height);
  23784. ctx.lineTo(x, y + height / 4 * 3);
  23785. ctx.lineTo(x - dx, y + height);
  23786. ctx.lineTo(x, y);
  23787. ctx.closePath();
  23788. }
  23789. });
  23790. /**
  23791. * Map of path contructors
  23792. */
  23793. // TODO Use function to build symbol path.
  23794. var symbolCtors = {
  23795. line: Line,
  23796. rect: Rect,
  23797. roundRect: Rect,
  23798. square: Rect,
  23799. circle: Circle,
  23800. diamond: Diamond,
  23801. pin: Pin,
  23802. arrow: Arrow,
  23803. triangle: Triangle
  23804. };
  23805. var symbolShapeMakers = {
  23806. line: function (x, y, w, h, shape) {
  23807. shape.x1 = x;
  23808. shape.y1 = y + h / 2;
  23809. shape.x2 = x + w;
  23810. shape.y2 = y + h / 2;
  23811. },
  23812. rect: function (x, y, w, h, shape) {
  23813. shape.x = x;
  23814. shape.y = y;
  23815. shape.width = w;
  23816. shape.height = h;
  23817. },
  23818. roundRect: function (x, y, w, h, shape) {
  23819. shape.x = x;
  23820. shape.y = y;
  23821. shape.width = w;
  23822. shape.height = h;
  23823. shape.r = Math.min(w, h) / 4;
  23824. },
  23825. square: function (x, y, w, h, shape) {
  23826. var size = Math.min(w, h);
  23827. shape.x = x;
  23828. shape.y = y;
  23829. shape.width = size;
  23830. shape.height = size;
  23831. },
  23832. circle: function (x, y, w, h, shape) {
  23833. // Put circle in the center of square
  23834. shape.cx = x + w / 2;
  23835. shape.cy = y + h / 2;
  23836. shape.r = Math.min(w, h) / 2;
  23837. },
  23838. diamond: function (x, y, w, h, shape) {
  23839. shape.cx = x + w / 2;
  23840. shape.cy = y + h / 2;
  23841. shape.width = w;
  23842. shape.height = h;
  23843. },
  23844. pin: function (x, y, w, h, shape) {
  23845. shape.x = x + w / 2;
  23846. shape.y = y + h / 2;
  23847. shape.width = w;
  23848. shape.height = h;
  23849. },
  23850. arrow: function (x, y, w, h, shape) {
  23851. shape.x = x + w / 2;
  23852. shape.y = y + h / 2;
  23853. shape.width = w;
  23854. shape.height = h;
  23855. },
  23856. triangle: function (x, y, w, h, shape) {
  23857. shape.cx = x + w / 2;
  23858. shape.cy = y + h / 2;
  23859. shape.width = w;
  23860. shape.height = h;
  23861. }
  23862. };
  23863. var symbolBuildProxies = {};
  23864. each(symbolCtors, function (Ctor, name) {
  23865. symbolBuildProxies[name] = new Ctor();
  23866. });
  23867. var SymbolClz = Path.extend({
  23868. type: 'symbol',
  23869. shape: {
  23870. symbolType: '',
  23871. x: 0,
  23872. y: 0,
  23873. width: 0,
  23874. height: 0
  23875. },
  23876. calculateTextPosition: function (out, config, rect) {
  23877. var res = calculateTextPosition(out, config, rect);
  23878. var shape = this.shape;
  23879. if (shape && shape.symbolType === 'pin' && config.position === 'inside') {
  23880. res.y = rect.y + rect.height * 0.4;
  23881. }
  23882. return res;
  23883. },
  23884. buildPath: function (ctx, shape, inBundle) {
  23885. var symbolType = shape.symbolType;
  23886. if (symbolType !== 'none') {
  23887. var proxySymbol = symbolBuildProxies[symbolType];
  23888. if (!proxySymbol) {
  23889. // Default rect
  23890. symbolType = 'rect';
  23891. proxySymbol = symbolBuildProxies[symbolType];
  23892. }
  23893. symbolShapeMakers[symbolType](shape.x, shape.y, shape.width, shape.height, proxySymbol.shape);
  23894. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  23895. }
  23896. }
  23897. }); // Provide setColor helper method to avoid determine if set the fill or stroke outside
  23898. function symbolPathSetColor(color, innerColor) {
  23899. if (this.type !== 'image') {
  23900. var symbolStyle = this.style;
  23901. if (this.__isEmptyBrush) {
  23902. symbolStyle.stroke = color;
  23903. symbolStyle.fill = innerColor || '#fff'; // TODO Same width with lineStyle in LineView
  23904. symbolStyle.lineWidth = 2;
  23905. } else if (this.shape.symbolType === 'line') {
  23906. symbolStyle.stroke = color;
  23907. } else {
  23908. symbolStyle.fill = color;
  23909. }
  23910. this.markRedraw();
  23911. }
  23912. }
  23913. /**
  23914. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  23915. */
  23916. function createSymbol(symbolType, x, y, w, h, color, // whether to keep the ratio of w/h,
  23917. keepAspect) {
  23918. // TODO Support image object, DynamicImage.
  23919. var isEmpty = symbolType.indexOf('empty') === 0;
  23920. if (isEmpty) {
  23921. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  23922. }
  23923. var symbolPath;
  23924. if (symbolType.indexOf('image://') === 0) {
  23925. symbolPath = makeImage(symbolType.slice(8), new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  23926. } else if (symbolType.indexOf('path://') === 0) {
  23927. symbolPath = makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  23928. } else {
  23929. symbolPath = new SymbolClz({
  23930. shape: {
  23931. symbolType: symbolType,
  23932. x: x,
  23933. y: y,
  23934. width: w,
  23935. height: h
  23936. }
  23937. });
  23938. }
  23939. symbolPath.__isEmptyBrush = isEmpty; // TODO Should deprecate setColor
  23940. symbolPath.setColor = symbolPathSetColor;
  23941. if (color) {
  23942. symbolPath.setColor(color);
  23943. }
  23944. return symbolPath;
  23945. }
  23946. function normalizeSymbolSize(symbolSize) {
  23947. if (!isArray(symbolSize)) {
  23948. symbolSize = [+symbolSize, +symbolSize];
  23949. }
  23950. return [symbolSize[0] || 0, symbolSize[1] || 0];
  23951. }
  23952. function normalizeSymbolOffset(symbolOffset, symbolSize) {
  23953. if (symbolOffset == null) {
  23954. return;
  23955. }
  23956. if (!isArray(symbolOffset)) {
  23957. symbolOffset = [symbolOffset, symbolOffset];
  23958. }
  23959. return [parsePercent$1(symbolOffset[0], symbolSize[0]) || 0, parsePercent$1(retrieve2(symbolOffset[1], symbolOffset[0]), symbolSize[1]) || 0];
  23960. }
  23961. function createLinearGradient(ctx, obj, rect) {
  23962. var x = obj.x == null ? 0 : obj.x;
  23963. var x2 = obj.x2 == null ? 1 : obj.x2;
  23964. var y = obj.y == null ? 0 : obj.y;
  23965. var y2 = obj.y2 == null ? 0 : obj.y2;
  23966. if (!obj.global) {
  23967. x = x * rect.width + rect.x;
  23968. x2 = x2 * rect.width + rect.x;
  23969. y = y * rect.height + rect.y;
  23970. y2 = y2 * rect.height + rect.y;
  23971. }
  23972. x = isNaN(x) ? 0 : x;
  23973. x2 = isNaN(x2) ? 1 : x2;
  23974. y = isNaN(y) ? 0 : y;
  23975. y2 = isNaN(y2) ? 0 : y2;
  23976. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  23977. return canvasGradient;
  23978. }
  23979. function createRadialGradient(ctx, obj, rect) {
  23980. var width = rect.width;
  23981. var height = rect.height;
  23982. var min = Math.min(width, height);
  23983. var x = obj.x == null ? 0.5 : obj.x;
  23984. var y = obj.y == null ? 0.5 : obj.y;
  23985. var r = obj.r == null ? 0.5 : obj.r;
  23986. if (!obj.global) {
  23987. x = x * width + rect.x;
  23988. y = y * height + rect.y;
  23989. r = r * min;
  23990. }
  23991. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  23992. return canvasGradient;
  23993. }
  23994. function getCanvasGradient(ctx, obj, rect) {
  23995. var canvasGradient = obj.type === 'radial'
  23996. ? createRadialGradient(ctx, obj, rect)
  23997. : createLinearGradient(ctx, obj, rect);
  23998. var colorStops = obj.colorStops;
  23999. for (var i = 0; i < colorStops.length; i++) {
  24000. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  24001. }
  24002. return canvasGradient;
  24003. }
  24004. function isClipPathChanged(clipPaths, prevClipPaths) {
  24005. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  24006. return false;
  24007. }
  24008. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  24009. return true;
  24010. }
  24011. for (var i = 0; i < clipPaths.length; i++) {
  24012. if (clipPaths[i] !== prevClipPaths[i]) {
  24013. return true;
  24014. }
  24015. }
  24016. return false;
  24017. }
  24018. function normalizeLineDash(lineType, lineWidth) {
  24019. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  24020. return null;
  24021. }
  24022. lineWidth = lineWidth || 1;
  24023. return lineType === 'dashed'
  24024. ? [4 * lineWidth, 2 * lineWidth]
  24025. : lineType === 'dotted'
  24026. ? [lineWidth]
  24027. : isNumber(lineType)
  24028. ? [lineType] : isArray(lineType) ? lineType : null;
  24029. }
  24030. var pathProxyForDraw = new PathProxy(true);
  24031. function styleHasStroke(style) {
  24032. var stroke = style.stroke;
  24033. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  24034. }
  24035. function isValidStrokeFillStyle(strokeOrFill) {
  24036. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  24037. }
  24038. function styleHasFill(style) {
  24039. var fill = style.fill;
  24040. return fill != null && fill !== 'none';
  24041. }
  24042. function doFillPath(ctx, style) {
  24043. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  24044. var originalGlobalAlpha = ctx.globalAlpha;
  24045. ctx.globalAlpha = style.fillOpacity * style.opacity;
  24046. ctx.fill();
  24047. ctx.globalAlpha = originalGlobalAlpha;
  24048. }
  24049. else {
  24050. ctx.fill();
  24051. }
  24052. }
  24053. function doStrokePath(ctx, style) {
  24054. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  24055. var originalGlobalAlpha = ctx.globalAlpha;
  24056. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  24057. ctx.stroke();
  24058. ctx.globalAlpha = originalGlobalAlpha;
  24059. }
  24060. else {
  24061. ctx.stroke();
  24062. }
  24063. }
  24064. function createCanvasPattern(ctx, pattern, el) {
  24065. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  24066. if (isImageReady(image)) {
  24067. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  24068. if (typeof DOMMatrix === 'function'
  24069. && canvasPattern.setTransform) {
  24070. var matrix = new DOMMatrix();
  24071. matrix.rotateSelf(0, 0, (pattern.rotation || 0) / Math.PI * 180);
  24072. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  24073. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  24074. canvasPattern.setTransform(matrix);
  24075. }
  24076. return canvasPattern;
  24077. }
  24078. }
  24079. function brushPath(ctx, el, style, inBatch) {
  24080. var hasStroke = styleHasStroke(style);
  24081. var hasFill = styleHasFill(style);
  24082. var strokePercent = style.strokePercent;
  24083. var strokePart = strokePercent < 1;
  24084. var firstDraw = !el.path;
  24085. if ((!el.silent || strokePart) && firstDraw) {
  24086. el.createPathProxy();
  24087. }
  24088. var path = el.path || pathProxyForDraw;
  24089. if (!inBatch) {
  24090. var fill = style.fill;
  24091. var stroke = style.stroke;
  24092. var hasFillGradient = hasFill && !!fill.colorStops;
  24093. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  24094. var hasFillPattern = hasFill && !!fill.image;
  24095. var hasStrokePattern = hasStroke && !!stroke.image;
  24096. var fillGradient = void 0;
  24097. var strokeGradient = void 0;
  24098. var fillPattern = void 0;
  24099. var strokePattern = void 0;
  24100. var rect = void 0;
  24101. if (hasFillGradient || hasStrokeGradient) {
  24102. rect = el.getBoundingRect();
  24103. }
  24104. if (hasFillGradient) {
  24105. fillGradient = el.__dirty
  24106. ? getCanvasGradient(ctx, fill, rect)
  24107. : el.__canvasFillGradient;
  24108. el.__canvasFillGradient = fillGradient;
  24109. }
  24110. if (hasStrokeGradient) {
  24111. strokeGradient = el.__dirty
  24112. ? getCanvasGradient(ctx, stroke, rect)
  24113. : el.__canvasStrokeGradient;
  24114. el.__canvasStrokeGradient = strokeGradient;
  24115. }
  24116. if (hasFillPattern) {
  24117. fillPattern = (el.__dirty || !el.__canvasFillPattern)
  24118. ? createCanvasPattern(ctx, fill, el)
  24119. : el.__canvasFillPattern;
  24120. el.__canvasFillPattern = fillPattern;
  24121. }
  24122. if (hasStrokePattern) {
  24123. strokePattern = (el.__dirty || !el.__canvasStrokePattern)
  24124. ? createCanvasPattern(ctx, stroke, el)
  24125. : el.__canvasStrokePattern;
  24126. el.__canvasStrokePattern = fillPattern;
  24127. }
  24128. if (hasFillGradient) {
  24129. ctx.fillStyle = fillGradient;
  24130. }
  24131. else if (hasFillPattern) {
  24132. if (fillPattern) {
  24133. ctx.fillStyle = fillPattern;
  24134. }
  24135. else {
  24136. hasFill = false;
  24137. }
  24138. }
  24139. if (hasStrokeGradient) {
  24140. ctx.strokeStyle = strokeGradient;
  24141. }
  24142. else if (hasStrokePattern) {
  24143. if (strokePattern) {
  24144. ctx.strokeStyle = strokePattern;
  24145. }
  24146. else {
  24147. hasStroke = false;
  24148. }
  24149. }
  24150. }
  24151. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  24152. var lineDashOffset = style.lineDashOffset;
  24153. var ctxLineDash = !!ctx.setLineDash;
  24154. var scale = el.getGlobalScale();
  24155. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  24156. if (lineDash) {
  24157. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  24158. if (lineScale_1 && lineScale_1 !== 1) {
  24159. lineDash = map(lineDash, function (rawVal) {
  24160. return rawVal / lineScale_1;
  24161. });
  24162. lineDashOffset /= lineScale_1;
  24163. }
  24164. }
  24165. var needsRebuild = true;
  24166. if (firstDraw || (el.__dirty & SHAPE_CHANGED_BIT)
  24167. || (lineDash && !ctxLineDash && hasStroke)) {
  24168. path.setDPR(ctx.dpr);
  24169. if (strokePart) {
  24170. path.setContext(null);
  24171. }
  24172. else {
  24173. path.setContext(ctx);
  24174. needsRebuild = false;
  24175. }
  24176. path.reset();
  24177. if (lineDash && !ctxLineDash) {
  24178. path.setLineDash(lineDash);
  24179. path.setLineDashOffset(lineDashOffset);
  24180. }
  24181. el.buildPath(path, el.shape, inBatch);
  24182. path.toStatic();
  24183. el.pathUpdated();
  24184. }
  24185. if (needsRebuild) {
  24186. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  24187. }
  24188. if (lineDash && ctxLineDash) {
  24189. ctx.setLineDash(lineDash);
  24190. ctx.lineDashOffset = lineDashOffset;
  24191. }
  24192. if (!inBatch) {
  24193. if (style.strokeFirst) {
  24194. if (hasStroke) {
  24195. doStrokePath(ctx, style);
  24196. }
  24197. if (hasFill) {
  24198. doFillPath(ctx, style);
  24199. }
  24200. }
  24201. else {
  24202. if (hasFill) {
  24203. doFillPath(ctx, style);
  24204. }
  24205. if (hasStroke) {
  24206. doStrokePath(ctx, style);
  24207. }
  24208. }
  24209. }
  24210. if (lineDash && ctxLineDash) {
  24211. ctx.setLineDash([]);
  24212. }
  24213. }
  24214. function brushImage(ctx, el, style) {
  24215. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  24216. if (!image || !isImageReady(image)) {
  24217. return;
  24218. }
  24219. var x = style.x || 0;
  24220. var y = style.y || 0;
  24221. var width = el.getWidth();
  24222. var height = el.getHeight();
  24223. var aspect = image.width / image.height;
  24224. if (width == null && height != null) {
  24225. width = height * aspect;
  24226. }
  24227. else if (height == null && width != null) {
  24228. height = width / aspect;
  24229. }
  24230. else if (width == null && height == null) {
  24231. width = image.width;
  24232. height = image.height;
  24233. }
  24234. if (style.sWidth && style.sHeight) {
  24235. var sx = style.sx || 0;
  24236. var sy = style.sy || 0;
  24237. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  24238. }
  24239. else if (style.sx && style.sy) {
  24240. var sx = style.sx;
  24241. var sy = style.sy;
  24242. var sWidth = width - sx;
  24243. var sHeight = height - sy;
  24244. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  24245. }
  24246. else {
  24247. ctx.drawImage(image, x, y, width, height);
  24248. }
  24249. }
  24250. function brushText(ctx, el, style) {
  24251. var text = style.text;
  24252. text != null && (text += '');
  24253. if (text) {
  24254. ctx.font = style.font || DEFAULT_FONT;
  24255. ctx.textAlign = style.textAlign;
  24256. ctx.textBaseline = style.textBaseline;
  24257. var hasLineDash = void 0;
  24258. if (ctx.setLineDash) {
  24259. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  24260. var lineDashOffset = style.lineDashOffset;
  24261. if (lineDash) {
  24262. var lineScale_2 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  24263. if (lineScale_2 && lineScale_2 !== 1) {
  24264. lineDash = map(lineDash, function (rawVal) {
  24265. return rawVal / lineScale_2;
  24266. });
  24267. lineDashOffset /= lineScale_2;
  24268. }
  24269. ctx.setLineDash(lineDash);
  24270. ctx.lineDashOffset = lineDashOffset;
  24271. hasLineDash = true;
  24272. }
  24273. }
  24274. if (style.strokeFirst) {
  24275. if (styleHasStroke(style)) {
  24276. ctx.strokeText(text, style.x, style.y);
  24277. }
  24278. if (styleHasFill(style)) {
  24279. ctx.fillText(text, style.x, style.y);
  24280. }
  24281. }
  24282. else {
  24283. if (styleHasFill(style)) {
  24284. ctx.fillText(text, style.x, style.y);
  24285. }
  24286. if (styleHasStroke(style)) {
  24287. ctx.strokeText(text, style.x, style.y);
  24288. }
  24289. }
  24290. if (hasLineDash) {
  24291. ctx.setLineDash([]);
  24292. }
  24293. }
  24294. }
  24295. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  24296. var STROKE_PROPS = [
  24297. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  24298. ];
  24299. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  24300. var styleChanged = false;
  24301. if (!forceSetAll) {
  24302. prevStyle = prevStyle || {};
  24303. if (style === prevStyle) {
  24304. return false;
  24305. }
  24306. }
  24307. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  24308. if (!styleChanged) {
  24309. flushPathDrawn(ctx, scope);
  24310. styleChanged = true;
  24311. }
  24312. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  24313. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  24314. }
  24315. if (forceSetAll || style.blend !== prevStyle.blend) {
  24316. if (!styleChanged) {
  24317. flushPathDrawn(ctx, scope);
  24318. styleChanged = true;
  24319. }
  24320. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  24321. }
  24322. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  24323. var propName = SHADOW_NUMBER_PROPS[i];
  24324. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  24325. if (!styleChanged) {
  24326. flushPathDrawn(ctx, scope);
  24327. styleChanged = true;
  24328. }
  24329. ctx[propName] = ctx.dpr * (style[propName] || 0);
  24330. }
  24331. }
  24332. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  24333. if (!styleChanged) {
  24334. flushPathDrawn(ctx, scope);
  24335. styleChanged = true;
  24336. }
  24337. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  24338. }
  24339. return styleChanged;
  24340. }
  24341. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  24342. var style = getStyle(el, scope.inHover);
  24343. var prevStyle = forceSetAll
  24344. ? null
  24345. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  24346. if (style === prevStyle) {
  24347. return false;
  24348. }
  24349. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  24350. if (forceSetAll || style.fill !== prevStyle.fill) {
  24351. if (!styleChanged) {
  24352. flushPathDrawn(ctx, scope);
  24353. styleChanged = true;
  24354. }
  24355. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  24356. }
  24357. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  24358. if (!styleChanged) {
  24359. flushPathDrawn(ctx, scope);
  24360. styleChanged = true;
  24361. }
  24362. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  24363. }
  24364. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  24365. if (!styleChanged) {
  24366. flushPathDrawn(ctx, scope);
  24367. styleChanged = true;
  24368. }
  24369. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  24370. }
  24371. if (el.hasStroke()) {
  24372. var lineWidth = style.lineWidth;
  24373. var newLineWidth = lineWidth / ((style.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1);
  24374. if (ctx.lineWidth !== newLineWidth) {
  24375. if (!styleChanged) {
  24376. flushPathDrawn(ctx, scope);
  24377. styleChanged = true;
  24378. }
  24379. ctx.lineWidth = newLineWidth;
  24380. }
  24381. }
  24382. for (var i = 0; i < STROKE_PROPS.length; i++) {
  24383. var prop = STROKE_PROPS[i];
  24384. var propName = prop[0];
  24385. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  24386. if (!styleChanged) {
  24387. flushPathDrawn(ctx, scope);
  24388. styleChanged = true;
  24389. }
  24390. ctx[propName] = style[propName] || prop[1];
  24391. }
  24392. }
  24393. return styleChanged;
  24394. }
  24395. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  24396. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  24397. }
  24398. function setContextTransform(ctx, el) {
  24399. var m = el.transform;
  24400. var dpr = ctx.dpr || 1;
  24401. if (m) {
  24402. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  24403. }
  24404. else {
  24405. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  24406. }
  24407. }
  24408. function updateClipStatus(clipPaths, ctx, scope) {
  24409. var allClipped = false;
  24410. for (var i = 0; i < clipPaths.length; i++) {
  24411. var clipPath = clipPaths[i];
  24412. allClipped = allClipped || clipPath.isZeroArea();
  24413. setContextTransform(ctx, clipPath);
  24414. ctx.beginPath();
  24415. clipPath.buildPath(ctx, clipPath.shape);
  24416. ctx.clip();
  24417. }
  24418. scope.allClipped = allClipped;
  24419. }
  24420. function isTransformChanged(m0, m1) {
  24421. if (m0 && m1) {
  24422. return m0[0] !== m1[0]
  24423. || m0[1] !== m1[1]
  24424. || m0[2] !== m1[2]
  24425. || m0[3] !== m1[3]
  24426. || m0[4] !== m1[4]
  24427. || m0[5] !== m1[5];
  24428. }
  24429. else if (!m0 && !m1) {
  24430. return false;
  24431. }
  24432. return true;
  24433. }
  24434. var DRAW_TYPE_PATH = 1;
  24435. var DRAW_TYPE_IMAGE = 2;
  24436. var DRAW_TYPE_TEXT = 3;
  24437. var DRAW_TYPE_INCREMENTAL = 4;
  24438. function canPathBatch(style) {
  24439. var hasFill = styleHasFill(style);
  24440. var hasStroke = styleHasStroke(style);
  24441. return !(style.lineDash
  24442. || !(+hasFill ^ +hasStroke)
  24443. || (hasFill && typeof style.fill !== 'string')
  24444. || (hasStroke && typeof style.stroke !== 'string')
  24445. || style.strokePercent < 1
  24446. || style.strokeOpacity < 1
  24447. || style.fillOpacity < 1);
  24448. }
  24449. function flushPathDrawn(ctx, scope) {
  24450. scope.batchFill && ctx.fill();
  24451. scope.batchStroke && ctx.stroke();
  24452. scope.batchFill = '';
  24453. scope.batchStroke = '';
  24454. }
  24455. function getStyle(el, inHover) {
  24456. return inHover ? (el.__hoverStyle || el.style) : el.style;
  24457. }
  24458. function brushSingle(ctx, el) {
  24459. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  24460. }
  24461. function brush(ctx, el, scope, isLast) {
  24462. var m = el.transform;
  24463. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  24464. el.__dirty &= ~REDRAW_BIT;
  24465. el.__isRendered = false;
  24466. return;
  24467. }
  24468. var clipPaths = el.__clipPaths;
  24469. var prevElClipPaths = scope.prevElClipPaths;
  24470. var forceSetTransform = false;
  24471. var forceSetStyle = false;
  24472. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  24473. if (prevElClipPaths && prevElClipPaths.length) {
  24474. flushPathDrawn(ctx, scope);
  24475. ctx.restore();
  24476. forceSetStyle = forceSetTransform = true;
  24477. scope.prevElClipPaths = null;
  24478. scope.allClipped = false;
  24479. scope.prevEl = null;
  24480. }
  24481. if (clipPaths && clipPaths.length) {
  24482. flushPathDrawn(ctx, scope);
  24483. ctx.save();
  24484. updateClipStatus(clipPaths, ctx, scope);
  24485. forceSetTransform = true;
  24486. }
  24487. scope.prevElClipPaths = clipPaths;
  24488. }
  24489. if (scope.allClipped) {
  24490. el.__isRendered = false;
  24491. return;
  24492. }
  24493. el.beforeBrush && el.beforeBrush();
  24494. el.innerBeforeBrush();
  24495. var prevEl = scope.prevEl;
  24496. if (!prevEl) {
  24497. forceSetStyle = forceSetTransform = true;
  24498. }
  24499. var canBatchPath = el instanceof Path
  24500. && el.autoBatch
  24501. && canPathBatch(el.style);
  24502. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  24503. flushPathDrawn(ctx, scope);
  24504. setContextTransform(ctx, el);
  24505. }
  24506. else if (!canBatchPath) {
  24507. flushPathDrawn(ctx, scope);
  24508. }
  24509. var style = getStyle(el, scope.inHover);
  24510. if (el instanceof Path) {
  24511. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  24512. forceSetStyle = true;
  24513. scope.lastDrawType = DRAW_TYPE_PATH;
  24514. }
  24515. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  24516. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  24517. ctx.beginPath();
  24518. }
  24519. brushPath(ctx, el, style, canBatchPath);
  24520. if (canBatchPath) {
  24521. scope.batchFill = style.fill || '';
  24522. scope.batchStroke = style.stroke || '';
  24523. }
  24524. }
  24525. else {
  24526. if (el instanceof TSpan) {
  24527. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  24528. forceSetStyle = true;
  24529. scope.lastDrawType = DRAW_TYPE_TEXT;
  24530. }
  24531. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  24532. brushText(ctx, el, style);
  24533. }
  24534. else if (el instanceof ZRImage) {
  24535. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  24536. forceSetStyle = true;
  24537. scope.lastDrawType = DRAW_TYPE_IMAGE;
  24538. }
  24539. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  24540. brushImage(ctx, el, style);
  24541. }
  24542. else if (el instanceof IncrementalDisplayable) {
  24543. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  24544. forceSetStyle = true;
  24545. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  24546. }
  24547. brushIncremental(ctx, el, scope);
  24548. }
  24549. }
  24550. if (canBatchPath && isLast) {
  24551. flushPathDrawn(ctx, scope);
  24552. }
  24553. el.innerAfterBrush();
  24554. el.afterBrush && el.afterBrush();
  24555. scope.prevEl = el;
  24556. el.__dirty = 0;
  24557. el.__isRendered = true;
  24558. }
  24559. function brushIncremental(ctx, el, scope) {
  24560. var displayables = el.getDisplayables();
  24561. var temporalDisplayables = el.getTemporalDisplayables();
  24562. ctx.save();
  24563. var innerScope = {
  24564. prevElClipPaths: null,
  24565. prevEl: null,
  24566. allClipped: false,
  24567. viewWidth: scope.viewWidth,
  24568. viewHeight: scope.viewHeight,
  24569. inHover: scope.inHover
  24570. };
  24571. var i;
  24572. var len;
  24573. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  24574. var displayable = displayables[i];
  24575. displayable.beforeBrush && displayable.beforeBrush();
  24576. displayable.innerBeforeBrush();
  24577. brush(ctx, displayable, innerScope, i === len - 1);
  24578. displayable.innerAfterBrush();
  24579. displayable.afterBrush && displayable.afterBrush();
  24580. innerScope.prevEl = displayable;
  24581. }
  24582. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  24583. var displayable = temporalDisplayables[i_1];
  24584. displayable.beforeBrush && displayable.beforeBrush();
  24585. displayable.innerBeforeBrush();
  24586. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  24587. displayable.innerAfterBrush();
  24588. displayable.afterBrush && displayable.afterBrush();
  24589. innerScope.prevEl = displayable;
  24590. }
  24591. el.clearTemporalDisplayables();
  24592. el.notClear = true;
  24593. ctx.restore();
  24594. }
  24595. var decalMap = new WeakMap();
  24596. var decalCache = new LRU(100);
  24597. var decalKeys = ['symbol', 'symbolSize', 'symbolKeepAspect', 'color', 'backgroundColor', 'dashArrayX', 'dashArrayY', 'maxTileWidth', 'maxTileHeight'];
  24598. /**
  24599. * Create or update pattern image from decal options
  24600. *
  24601. * @param {InnerDecalObject | 'none'} decalObject decal options, 'none' if no decal
  24602. * @return {Pattern} pattern with generated image, null if no decal
  24603. */
  24604. function createOrUpdatePatternFromDecal(decalObject, api) {
  24605. if (decalObject === 'none') {
  24606. return null;
  24607. }
  24608. var dpr = api.getDevicePixelRatio();
  24609. var zr = api.getZr();
  24610. var isSVG = zr.painter.type === 'svg';
  24611. if (decalObject.dirty) {
  24612. decalMap["delete"](decalObject);
  24613. }
  24614. var oldPattern = decalMap.get(decalObject);
  24615. if (oldPattern) {
  24616. return oldPattern;
  24617. }
  24618. var decalOpt = defaults(decalObject, {
  24619. symbol: 'rect',
  24620. symbolSize: 1,
  24621. symbolKeepAspect: true,
  24622. color: 'rgba(0, 0, 0, 0.2)',
  24623. backgroundColor: null,
  24624. dashArrayX: 5,
  24625. dashArrayY: 5,
  24626. rotation: 0,
  24627. maxTileWidth: 512,
  24628. maxTileHeight: 512
  24629. });
  24630. if (decalOpt.backgroundColor === 'none') {
  24631. decalOpt.backgroundColor = null;
  24632. }
  24633. var pattern = {
  24634. repeat: 'repeat'
  24635. };
  24636. setPatternnSource(pattern);
  24637. pattern.rotation = decalOpt.rotation;
  24638. pattern.scaleX = pattern.scaleY = isSVG ? 1 : 1 / dpr;
  24639. decalMap.set(decalObject, pattern);
  24640. decalObject.dirty = false;
  24641. return pattern;
  24642. function setPatternnSource(pattern) {
  24643. var keys = [dpr];
  24644. var isValidKey = true;
  24645. for (var i = 0; i < decalKeys.length; ++i) {
  24646. var value = decalOpt[decalKeys[i]];
  24647. var valueType = typeof value;
  24648. if (value != null && !isArray(value) && valueType !== 'string' && valueType !== 'number' && valueType !== 'boolean') {
  24649. isValidKey = false;
  24650. break;
  24651. }
  24652. keys.push(value);
  24653. }
  24654. var cacheKey;
  24655. if (isValidKey) {
  24656. cacheKey = keys.join(',') + (isSVG ? '-svg' : '');
  24657. var cache = decalCache.get(cacheKey);
  24658. if (cache) {
  24659. isSVG ? pattern.svgElement = cache : pattern.image = cache;
  24660. }
  24661. }
  24662. var dashArrayX = normalizeDashArrayX(decalOpt.dashArrayX);
  24663. var dashArrayY = normalizeDashArrayY(decalOpt.dashArrayY);
  24664. var symbolArray = normalizeSymbolArray(decalOpt.symbol);
  24665. var lineBlockLengthsX = getLineBlockLengthX(dashArrayX);
  24666. var lineBlockLengthY = getLineBlockLengthY(dashArrayY);
  24667. var canvas = !isSVG && createCanvas();
  24668. var svgRoot = isSVG && zr.painter.createSVGElement('g');
  24669. var pSize = getPatternSize();
  24670. var ctx;
  24671. if (canvas) {
  24672. canvas.width = pSize.width * dpr;
  24673. canvas.height = pSize.height * dpr;
  24674. ctx = canvas.getContext('2d');
  24675. }
  24676. brushDecal();
  24677. if (isValidKey) {
  24678. decalCache.put(cacheKey, canvas || svgRoot);
  24679. }
  24680. pattern.image = canvas;
  24681. pattern.svgElement = svgRoot;
  24682. pattern.svgWidth = pSize.width;
  24683. pattern.svgHeight = pSize.height;
  24684. /**
  24685. * Get minumum length that can make a repeatable pattern.
  24686. *
  24687. * @return {Object} pattern width and height
  24688. */
  24689. function getPatternSize() {
  24690. /**
  24691. * For example, if dash is [[3, 2], [2, 1]] for X, it looks like
  24692. * |--- --- --- --- --- ...
  24693. * |-- -- -- -- -- -- -- -- ...
  24694. * |--- --- --- --- --- ...
  24695. * |-- -- -- -- -- -- -- -- ...
  24696. * So the minumum length of X is 15,
  24697. * which is the least common multiple of `3 + 2` and `2 + 1`
  24698. * |--- --- --- |--- --- ...
  24699. * |-- -- -- -- -- |-- -- -- ...
  24700. */
  24701. var width = 1;
  24702. for (var i = 0, xlen = lineBlockLengthsX.length; i < xlen; ++i) {
  24703. width = getLeastCommonMultiple(width, lineBlockLengthsX[i]);
  24704. }
  24705. var symbolRepeats = 1;
  24706. for (var i = 0, xlen = symbolArray.length; i < xlen; ++i) {
  24707. symbolRepeats = getLeastCommonMultiple(symbolRepeats, symbolArray[i].length);
  24708. }
  24709. width *= symbolRepeats;
  24710. var height = lineBlockLengthY * lineBlockLengthsX.length * symbolArray.length;
  24711. if ("development" !== 'production') {
  24712. var warn = function (attrName) {
  24713. /* eslint-disable-next-line */
  24714. 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.");
  24715. };
  24716. if (width > decalOpt.maxTileWidth) {
  24717. warn('maxTileWidth');
  24718. }
  24719. if (height > decalOpt.maxTileHeight) {
  24720. warn('maxTileHeight');
  24721. }
  24722. }
  24723. return {
  24724. width: Math.max(1, Math.min(width, decalOpt.maxTileWidth)),
  24725. height: Math.max(1, Math.min(height, decalOpt.maxTileHeight))
  24726. };
  24727. }
  24728. function brushDecal() {
  24729. if (ctx) {
  24730. ctx.clearRect(0, 0, canvas.width, canvas.height);
  24731. if (decalOpt.backgroundColor) {
  24732. ctx.fillStyle = decalOpt.backgroundColor;
  24733. ctx.fillRect(0, 0, canvas.width, canvas.height);
  24734. }
  24735. }
  24736. var ySum = 0;
  24737. for (var i = 0; i < dashArrayY.length; ++i) {
  24738. ySum += dashArrayY[i];
  24739. }
  24740. if (ySum <= 0) {
  24741. // dashArrayY is 0, draw nothing
  24742. return;
  24743. }
  24744. var y = -lineBlockLengthY;
  24745. var yId = 0;
  24746. var yIdTotal = 0;
  24747. var xId0 = 0;
  24748. while (y < pSize.height) {
  24749. if (yId % 2 === 0) {
  24750. var symbolYId = yIdTotal / 2 % symbolArray.length;
  24751. var x = 0;
  24752. var xId1 = 0;
  24753. var xId1Total = 0;
  24754. while (x < pSize.width * 2) {
  24755. var xSum = 0;
  24756. for (var i = 0; i < dashArrayX[xId0].length; ++i) {
  24757. xSum += dashArrayX[xId0][i];
  24758. }
  24759. if (xSum <= 0) {
  24760. // Skip empty line
  24761. break;
  24762. } // E.g., [15, 5, 20, 5] draws only for 15 and 20
  24763. if (xId1 % 2 === 0) {
  24764. var size = (1 - decalOpt.symbolSize) * 0.5;
  24765. var left = x + dashArrayX[xId0][xId1] * size;
  24766. var top_1 = y + dashArrayY[yId] * size;
  24767. var width = dashArrayX[xId0][xId1] * decalOpt.symbolSize;
  24768. var height = dashArrayY[yId] * decalOpt.symbolSize;
  24769. var symbolXId = xId1Total / 2 % symbolArray[symbolYId].length;
  24770. brushSymbol(left, top_1, width, height, symbolArray[symbolYId][symbolXId]);
  24771. }
  24772. x += dashArrayX[xId0][xId1];
  24773. ++xId1Total;
  24774. ++xId1;
  24775. if (xId1 === dashArrayX[xId0].length) {
  24776. xId1 = 0;
  24777. }
  24778. }
  24779. ++xId0;
  24780. if (xId0 === dashArrayX.length) {
  24781. xId0 = 0;
  24782. }
  24783. }
  24784. y += dashArrayY[yId];
  24785. ++yIdTotal;
  24786. ++yId;
  24787. if (yId === dashArrayY.length) {
  24788. yId = 0;
  24789. }
  24790. }
  24791. function brushSymbol(x, y, width, height, symbolType) {
  24792. var scale = isSVG ? 1 : dpr;
  24793. var symbol = createSymbol(symbolType, x * scale, y * scale, width * scale, height * scale, decalOpt.color, decalOpt.symbolKeepAspect);
  24794. if (isSVG) {
  24795. svgRoot.appendChild(zr.painter.paintOne(symbol));
  24796. } else {
  24797. // Paint to canvas for all other renderers.
  24798. brushSingle(ctx, symbol);
  24799. }
  24800. }
  24801. }
  24802. }
  24803. }
  24804. /**
  24805. * Convert symbol array into normalized array
  24806. *
  24807. * @param {string | (string | string[])[]} symbol symbol input
  24808. * @return {string[][]} normolized symbol array
  24809. */
  24810. function normalizeSymbolArray(symbol) {
  24811. if (!symbol || symbol.length === 0) {
  24812. return [['rect']];
  24813. }
  24814. if (typeof symbol === 'string') {
  24815. return [[symbol]];
  24816. }
  24817. var isAllString = true;
  24818. for (var i = 0; i < symbol.length; ++i) {
  24819. if (typeof symbol[i] !== 'string') {
  24820. isAllString = false;
  24821. break;
  24822. }
  24823. }
  24824. if (isAllString) {
  24825. return normalizeSymbolArray([symbol]);
  24826. }
  24827. var result = [];
  24828. for (var i = 0; i < symbol.length; ++i) {
  24829. if (typeof symbol[i] === 'string') {
  24830. result.push([symbol[i]]);
  24831. } else {
  24832. result.push(symbol[i]);
  24833. }
  24834. }
  24835. return result;
  24836. }
  24837. /**
  24838. * Convert dash input into dashArray
  24839. *
  24840. * @param {DecalDashArrayX} dash dash input
  24841. * @return {number[][]} normolized dash array
  24842. */
  24843. function normalizeDashArrayX(dash) {
  24844. if (!dash || dash.length === 0) {
  24845. return [[0, 0]];
  24846. }
  24847. if (typeof dash === 'number') {
  24848. var dashValue = Math.ceil(dash);
  24849. return [[dashValue, dashValue]];
  24850. }
  24851. /**
  24852. * [20, 5] should be normalized into [[20, 5]],
  24853. * while [20, [5, 10]] should be normalized into [[20, 20], [5, 10]]
  24854. */
  24855. var isAllNumber = true;
  24856. for (var i = 0; i < dash.length; ++i) {
  24857. if (typeof dash[i] !== 'number') {
  24858. isAllNumber = false;
  24859. break;
  24860. }
  24861. }
  24862. if (isAllNumber) {
  24863. return normalizeDashArrayX([dash]);
  24864. }
  24865. var result = [];
  24866. for (var i = 0; i < dash.length; ++i) {
  24867. if (typeof dash[i] === 'number') {
  24868. var dashValue = Math.ceil(dash[i]);
  24869. result.push([dashValue, dashValue]);
  24870. } else {
  24871. var dashValue = map(dash[i], function (n) {
  24872. return Math.ceil(n);
  24873. });
  24874. if (dashValue.length % 2 === 1) {
  24875. // [4, 2, 1] means |---- - -- |---- - -- |
  24876. // so normalize it to be [4, 2, 1, 4, 2, 1]
  24877. result.push(dashValue.concat(dashValue));
  24878. } else {
  24879. result.push(dashValue);
  24880. }
  24881. }
  24882. }
  24883. return result;
  24884. }
  24885. /**
  24886. * Convert dash input into dashArray
  24887. *
  24888. * @param {DecalDashArrayY} dash dash input
  24889. * @return {number[]} normolized dash array
  24890. */
  24891. function normalizeDashArrayY(dash) {
  24892. if (!dash || typeof dash === 'object' && dash.length === 0) {
  24893. return [0, 0];
  24894. }
  24895. if (typeof dash === 'number') {
  24896. var dashValue_1 = Math.ceil(dash);
  24897. return [dashValue_1, dashValue_1];
  24898. }
  24899. var dashValue = map(dash, function (n) {
  24900. return Math.ceil(n);
  24901. });
  24902. return dash.length % 2 ? dashValue.concat(dashValue) : dashValue;
  24903. }
  24904. /**
  24905. * Get block length of each line. A block is the length of dash line and space.
  24906. * For example, a line with [4, 1] has a dash line of 4 and a space of 1 after
  24907. * that, so the block length of this line is 5.
  24908. *
  24909. * @param {number[][]} dash dash arrary of X or Y
  24910. * @return {number[]} block length of each line
  24911. */
  24912. function getLineBlockLengthX(dash) {
  24913. return map(dash, function (line) {
  24914. return getLineBlockLengthY(line);
  24915. });
  24916. }
  24917. function getLineBlockLengthY(dash) {
  24918. var blockLength = 0;
  24919. for (var i = 0; i < dash.length; ++i) {
  24920. blockLength += dash[i];
  24921. }
  24922. if (dash.length % 2 === 1) {
  24923. // [4, 2, 1] means |---- - -- |---- - -- |
  24924. // So total length is (4 + 2 + 1) * 2
  24925. return blockLength * 2;
  24926. }
  24927. return blockLength;
  24928. }
  24929. function decalVisual(ecModel, api) {
  24930. ecModel.eachRawSeries(function (seriesModel) {
  24931. if (ecModel.isSeriesFiltered(seriesModel)) {
  24932. return;
  24933. }
  24934. var data = seriesModel.getData();
  24935. if (data.hasItemVisual()) {
  24936. data.each(function (idx) {
  24937. var decal = data.getItemVisual(idx, 'decal');
  24938. if (decal) {
  24939. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  24940. itemStyle.decal = createOrUpdatePatternFromDecal(decal, api);
  24941. }
  24942. });
  24943. }
  24944. var decal = data.getVisual('decal');
  24945. if (decal) {
  24946. var style = data.getVisual('style');
  24947. style.decal = createOrUpdatePatternFromDecal(decal, api);
  24948. }
  24949. });
  24950. }
  24951. function parseXML(svg) {
  24952. if (isString(svg)) {
  24953. var parser = new DOMParser();
  24954. svg = parser.parseFromString(svg, 'text/xml');
  24955. }
  24956. var svgNode = svg;
  24957. if (svgNode.nodeType === 9) {
  24958. svgNode = svgNode.firstChild;
  24959. }
  24960. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  24961. svgNode = svgNode.nextSibling;
  24962. }
  24963. return svgNode;
  24964. }
  24965. var nodeParsers;
  24966. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  24967. 'fill': 'fill',
  24968. 'stroke': 'stroke',
  24969. 'stroke-width': 'lineWidth',
  24970. 'opacity': 'opacity',
  24971. 'fill-opacity': 'fillOpacity',
  24972. 'stroke-opacity': 'strokeOpacity',
  24973. 'stroke-dasharray': 'lineDash',
  24974. 'stroke-dashoffset': 'lineDashOffset',
  24975. 'stroke-linecap': 'lineCap',
  24976. 'stroke-linejoin': 'lineJoin',
  24977. 'stroke-miterlimit': 'miterLimit',
  24978. 'font-family': 'fontFamily',
  24979. 'font-size': 'fontSize',
  24980. 'font-style': 'fontStyle',
  24981. 'font-weight': 'fontWeight',
  24982. 'text-anchor': 'textAlign',
  24983. 'visibility': 'visibility',
  24984. 'display': 'display'
  24985. };
  24986. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  24987. var SELF_STYLE_ATTRIBUTES_MAP = {
  24988. 'alignment-baseline': 'textBaseline',
  24989. 'stop-color': 'stopColor'
  24990. };
  24991. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  24992. var SVGParser = (function () {
  24993. function SVGParser() {
  24994. this._defs = {};
  24995. this._root = null;
  24996. }
  24997. SVGParser.prototype.parse = function (xml, opt) {
  24998. opt = opt || {};
  24999. var svg = parseXML(xml);
  25000. if (!svg) {
  25001. throw new Error('Illegal svg');
  25002. }
  25003. this._defsUsePending = [];
  25004. var root = new Group();
  25005. this._root = root;
  25006. var named = [];
  25007. var viewBox = svg.getAttribute('viewBox') || '';
  25008. var width = parseFloat((svg.getAttribute('width') || opt.width));
  25009. var height = parseFloat((svg.getAttribute('height') || opt.height));
  25010. isNaN(width) && (width = null);
  25011. isNaN(height) && (height = null);
  25012. parseAttributes(svg, root, null, true, false);
  25013. var child = svg.firstChild;
  25014. while (child) {
  25015. this._parseNode(child, root, named, null, false, false);
  25016. child = child.nextSibling;
  25017. }
  25018. applyDefs(this._defs, this._defsUsePending);
  25019. this._defsUsePending = [];
  25020. var viewBoxRect;
  25021. var viewBoxTransform;
  25022. if (viewBox) {
  25023. var viewBoxArr = splitNumberSequence(viewBox);
  25024. if (viewBoxArr.length >= 4) {
  25025. viewBoxRect = {
  25026. x: parseFloat((viewBoxArr[0] || 0)),
  25027. y: parseFloat((viewBoxArr[1] || 0)),
  25028. width: parseFloat(viewBoxArr[2]),
  25029. height: parseFloat(viewBoxArr[3])
  25030. };
  25031. }
  25032. }
  25033. if (viewBoxRect && width != null && height != null) {
  25034. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  25035. if (!opt.ignoreViewBox) {
  25036. var elRoot = root;
  25037. root = new Group();
  25038. root.add(elRoot);
  25039. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  25040. elRoot.x = viewBoxTransform.x;
  25041. elRoot.y = viewBoxTransform.y;
  25042. }
  25043. }
  25044. if (!opt.ignoreRootClip && width != null && height != null) {
  25045. root.setClipPath(new Rect({
  25046. shape: { x: 0, y: 0, width: width, height: height }
  25047. }));
  25048. }
  25049. return {
  25050. root: root,
  25051. width: width,
  25052. height: height,
  25053. viewBoxRect: viewBoxRect,
  25054. viewBoxTransform: viewBoxTransform,
  25055. named: named
  25056. };
  25057. };
  25058. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  25059. var nodeName = xmlNode.nodeName.toLowerCase();
  25060. var el;
  25061. var namedFromForSub = namedFrom;
  25062. if (nodeName === 'defs') {
  25063. isInDefs = true;
  25064. }
  25065. if (nodeName === 'text') {
  25066. isInText = true;
  25067. }
  25068. if (nodeName === 'defs' || nodeName === 'switch') {
  25069. el = parentGroup;
  25070. }
  25071. else {
  25072. if (!isInDefs) {
  25073. var parser_1 = nodeParsers[nodeName];
  25074. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  25075. el = parser_1.call(this, xmlNode, parentGroup);
  25076. var nameAttr = xmlNode.getAttribute('name');
  25077. if (nameAttr) {
  25078. var newNamed = {
  25079. name: nameAttr,
  25080. namedFrom: null,
  25081. svgNodeTagLower: nodeName,
  25082. el: el
  25083. };
  25084. named.push(newNamed);
  25085. if (nodeName === 'g') {
  25086. namedFromForSub = newNamed;
  25087. }
  25088. }
  25089. else if (namedFrom) {
  25090. named.push({
  25091. name: namedFrom.name,
  25092. namedFrom: namedFrom,
  25093. svgNodeTagLower: nodeName,
  25094. el: el
  25095. });
  25096. }
  25097. parentGroup.add(el);
  25098. }
  25099. }
  25100. var parser = paintServerParsers[nodeName];
  25101. if (parser && hasOwn(paintServerParsers, nodeName)) {
  25102. var def = parser.call(this, xmlNode);
  25103. var id = xmlNode.getAttribute('id');
  25104. if (id) {
  25105. this._defs[id] = def;
  25106. }
  25107. }
  25108. }
  25109. if (el && el.isGroup) {
  25110. var child = xmlNode.firstChild;
  25111. while (child) {
  25112. if (child.nodeType === 1) {
  25113. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  25114. }
  25115. else if (child.nodeType === 3 && isInText) {
  25116. this._parseText(child, el);
  25117. }
  25118. child = child.nextSibling;
  25119. }
  25120. }
  25121. };
  25122. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  25123. var text = new TSpan({
  25124. style: {
  25125. text: xmlNode.textContent
  25126. },
  25127. silent: true,
  25128. x: this._textX || 0,
  25129. y: this._textY || 0
  25130. });
  25131. inheritStyle(parentGroup, text);
  25132. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  25133. applyTextAlignment(text, parentGroup);
  25134. var textStyle = text.style;
  25135. var fontSize = textStyle.fontSize;
  25136. if (fontSize && fontSize < 9) {
  25137. textStyle.fontSize = 9;
  25138. text.scaleX *= fontSize / 9;
  25139. text.scaleY *= fontSize / 9;
  25140. }
  25141. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  25142. textStyle.fontStyle,
  25143. textStyle.fontWeight,
  25144. (textStyle.fontSize || 12) + 'px',
  25145. textStyle.fontFamily || 'sans-serif'
  25146. ].join(' ');
  25147. textStyle.font = font;
  25148. var rect = text.getBoundingRect();
  25149. this._textX += rect.width;
  25150. parentGroup.add(text);
  25151. return text;
  25152. };
  25153. SVGParser.internalField = (function () {
  25154. nodeParsers = {
  25155. 'g': function (xmlNode, parentGroup) {
  25156. var g = new Group();
  25157. inheritStyle(parentGroup, g);
  25158. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  25159. return g;
  25160. },
  25161. 'rect': function (xmlNode, parentGroup) {
  25162. var rect = new Rect();
  25163. inheritStyle(parentGroup, rect);
  25164. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  25165. rect.setShape({
  25166. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  25167. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  25168. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  25169. height: parseFloat(xmlNode.getAttribute('height') || '0')
  25170. });
  25171. rect.silent = true;
  25172. return rect;
  25173. },
  25174. 'circle': function (xmlNode, parentGroup) {
  25175. var circle = new Circle();
  25176. inheritStyle(parentGroup, circle);
  25177. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  25178. circle.setShape({
  25179. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  25180. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  25181. r: parseFloat(xmlNode.getAttribute('r') || '0')
  25182. });
  25183. circle.silent = true;
  25184. return circle;
  25185. },
  25186. 'line': function (xmlNode, parentGroup) {
  25187. var line = new Line();
  25188. inheritStyle(parentGroup, line);
  25189. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  25190. line.setShape({
  25191. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  25192. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  25193. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  25194. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  25195. });
  25196. line.silent = true;
  25197. return line;
  25198. },
  25199. 'ellipse': function (xmlNode, parentGroup) {
  25200. var ellipse = new Ellipse();
  25201. inheritStyle(parentGroup, ellipse);
  25202. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  25203. ellipse.setShape({
  25204. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  25205. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  25206. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  25207. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  25208. });
  25209. ellipse.silent = true;
  25210. return ellipse;
  25211. },
  25212. 'polygon': function (xmlNode, parentGroup) {
  25213. var pointsStr = xmlNode.getAttribute('points');
  25214. var pointsArr;
  25215. if (pointsStr) {
  25216. pointsArr = parsePoints(pointsStr);
  25217. }
  25218. var polygon = new Polygon({
  25219. shape: {
  25220. points: pointsArr || []
  25221. },
  25222. silent: true
  25223. });
  25224. inheritStyle(parentGroup, polygon);
  25225. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  25226. return polygon;
  25227. },
  25228. 'polyline': function (xmlNode, parentGroup) {
  25229. var pointsStr = xmlNode.getAttribute('points');
  25230. var pointsArr;
  25231. if (pointsStr) {
  25232. pointsArr = parsePoints(pointsStr);
  25233. }
  25234. var polyline = new Polyline({
  25235. shape: {
  25236. points: pointsArr || []
  25237. },
  25238. silent: true
  25239. });
  25240. inheritStyle(parentGroup, polyline);
  25241. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  25242. return polyline;
  25243. },
  25244. 'image': function (xmlNode, parentGroup) {
  25245. var img = new ZRImage();
  25246. inheritStyle(parentGroup, img);
  25247. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  25248. img.setStyle({
  25249. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  25250. x: +xmlNode.getAttribute('x'),
  25251. y: +xmlNode.getAttribute('y'),
  25252. width: +xmlNode.getAttribute('width'),
  25253. height: +xmlNode.getAttribute('height')
  25254. });
  25255. img.silent = true;
  25256. return img;
  25257. },
  25258. 'text': function (xmlNode, parentGroup) {
  25259. var x = xmlNode.getAttribute('x') || '0';
  25260. var y = xmlNode.getAttribute('y') || '0';
  25261. var dx = xmlNode.getAttribute('dx') || '0';
  25262. var dy = xmlNode.getAttribute('dy') || '0';
  25263. this._textX = parseFloat(x) + parseFloat(dx);
  25264. this._textY = parseFloat(y) + parseFloat(dy);
  25265. var g = new Group();
  25266. inheritStyle(parentGroup, g);
  25267. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  25268. return g;
  25269. },
  25270. 'tspan': function (xmlNode, parentGroup) {
  25271. var x = xmlNode.getAttribute('x');
  25272. var y = xmlNode.getAttribute('y');
  25273. if (x != null) {
  25274. this._textX = parseFloat(x);
  25275. }
  25276. if (y != null) {
  25277. this._textY = parseFloat(y);
  25278. }
  25279. var dx = xmlNode.getAttribute('dx') || '0';
  25280. var dy = xmlNode.getAttribute('dy') || '0';
  25281. var g = new Group();
  25282. inheritStyle(parentGroup, g);
  25283. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  25284. this._textX += parseFloat(dx);
  25285. this._textY += parseFloat(dy);
  25286. return g;
  25287. },
  25288. 'path': function (xmlNode, parentGroup) {
  25289. var d = xmlNode.getAttribute('d') || '';
  25290. var path = createFromString(d);
  25291. inheritStyle(parentGroup, path);
  25292. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  25293. path.silent = true;
  25294. return path;
  25295. }
  25296. };
  25297. })();
  25298. return SVGParser;
  25299. }());
  25300. var paintServerParsers = {
  25301. 'lineargradient': function (xmlNode) {
  25302. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  25303. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  25304. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  25305. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  25306. var gradient = new LinearGradient(x1, y1, x2, y2);
  25307. parsePaintServerUnit(xmlNode, gradient);
  25308. parseGradientColorStops(xmlNode, gradient);
  25309. return gradient;
  25310. },
  25311. 'radialgradient': function (xmlNode) {
  25312. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  25313. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  25314. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  25315. var gradient = new RadialGradient(cx, cy, r);
  25316. parsePaintServerUnit(xmlNode, gradient);
  25317. parseGradientColorStops(xmlNode, gradient);
  25318. return gradient;
  25319. }
  25320. };
  25321. function parsePaintServerUnit(xmlNode, gradient) {
  25322. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  25323. if (gradientUnits === 'userSpaceOnUse') {
  25324. gradient.global = true;
  25325. }
  25326. }
  25327. function parseGradientColorStops(xmlNode, gradient) {
  25328. var stop = xmlNode.firstChild;
  25329. while (stop) {
  25330. if (stop.nodeType === 1
  25331. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  25332. var offsetStr = stop.getAttribute('offset');
  25333. var offset = void 0;
  25334. if (offsetStr && offsetStr.indexOf('%') > 0) {
  25335. offset = parseInt(offsetStr, 10) / 100;
  25336. }
  25337. else if (offsetStr) {
  25338. offset = parseFloat(offsetStr);
  25339. }
  25340. else {
  25341. offset = 0;
  25342. }
  25343. var styleVals = {};
  25344. parseInlineStyle(stop, styleVals, styleVals);
  25345. var stopColor = styleVals.stopColor
  25346. || stop.getAttribute('stop-color')
  25347. || '#000000';
  25348. gradient.colorStops.push({
  25349. offset: offset,
  25350. color: stopColor
  25351. });
  25352. }
  25353. stop = stop.nextSibling;
  25354. }
  25355. }
  25356. function inheritStyle(parent, child) {
  25357. if (parent && parent.__inheritedStyle) {
  25358. if (!child.__inheritedStyle) {
  25359. child.__inheritedStyle = {};
  25360. }
  25361. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  25362. }
  25363. }
  25364. function parsePoints(pointsString) {
  25365. var list = splitNumberSequence(pointsString);
  25366. var points = [];
  25367. for (var i = 0; i < list.length; i += 2) {
  25368. var x = parseFloat(list[i]);
  25369. var y = parseFloat(list[i + 1]);
  25370. points.push([x, y]);
  25371. }
  25372. return points;
  25373. }
  25374. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  25375. var disp = el;
  25376. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  25377. var selfStyle = {};
  25378. if (xmlNode.nodeType === 1) {
  25379. parseTransformAttribute(xmlNode, el);
  25380. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  25381. if (!onlyInlineStyle) {
  25382. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  25383. }
  25384. }
  25385. disp.style = disp.style || {};
  25386. if (inheritedStyle.fill != null) {
  25387. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  25388. }
  25389. if (inheritedStyle.stroke != null) {
  25390. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  25391. }
  25392. each([
  25393. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  25394. ], function (propName) {
  25395. if (inheritedStyle[propName] != null) {
  25396. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  25397. }
  25398. });
  25399. each([
  25400. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  25401. ], function (propName) {
  25402. if (inheritedStyle[propName] != null) {
  25403. disp.style[propName] = inheritedStyle[propName];
  25404. }
  25405. });
  25406. if (isTextGroup) {
  25407. disp.__selfStyle = selfStyle;
  25408. }
  25409. if (inheritedStyle.lineDash) {
  25410. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  25411. return parseFloat(str);
  25412. });
  25413. }
  25414. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  25415. disp.invisible = true;
  25416. }
  25417. if (inheritedStyle.display === 'none') {
  25418. disp.ignore = true;
  25419. }
  25420. }
  25421. function applyTextAlignment(text, parentGroup) {
  25422. var parentSelfStyle = parentGroup.__selfStyle;
  25423. if (parentSelfStyle) {
  25424. var textBaseline = parentSelfStyle.textBaseline;
  25425. var zrTextBaseline = textBaseline;
  25426. if (!textBaseline || textBaseline === 'auto') {
  25427. zrTextBaseline = 'alphabetic';
  25428. }
  25429. else if (textBaseline === 'baseline') {
  25430. zrTextBaseline = 'alphabetic';
  25431. }
  25432. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  25433. zrTextBaseline = 'top';
  25434. }
  25435. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  25436. zrTextBaseline = 'bottom';
  25437. }
  25438. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  25439. zrTextBaseline = 'middle';
  25440. }
  25441. text.style.textBaseline = zrTextBaseline;
  25442. }
  25443. var parentInheritedStyle = parentGroup.__inheritedStyle;
  25444. if (parentInheritedStyle) {
  25445. var textAlign = parentInheritedStyle.textAlign;
  25446. var zrTextAlign = textAlign;
  25447. if (textAlign) {
  25448. if (textAlign === 'middle') {
  25449. zrTextAlign = 'center';
  25450. }
  25451. text.style.textAlign = zrTextAlign;
  25452. }
  25453. }
  25454. }
  25455. var urlRegex = /^url\(\s*#(.*?)\)/;
  25456. function getFillStrokeStyle(el, method, str, defsUsePending) {
  25457. var urlMatch = str && str.match(urlRegex);
  25458. if (urlMatch) {
  25459. var url = trim(urlMatch[1]);
  25460. defsUsePending.push([el, method, url]);
  25461. return;
  25462. }
  25463. if (str === 'none') {
  25464. str = null;
  25465. }
  25466. return str;
  25467. }
  25468. function applyDefs(defs, defsUsePending) {
  25469. for (var i = 0; i < defsUsePending.length; i++) {
  25470. var item = defsUsePending[i];
  25471. item[0].style[item[1]] = defs[item[2]];
  25472. }
  25473. }
  25474. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  25475. function splitNumberSequence(rawStr) {
  25476. return rawStr.match(numberReg$1) || [];
  25477. }
  25478. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  25479. var DEGREE_TO_ANGLE = Math.PI / 180;
  25480. function parseTransformAttribute(xmlNode, node) {
  25481. var transform = xmlNode.getAttribute('transform');
  25482. if (transform) {
  25483. transform = transform.replace(/,/g, ' ');
  25484. var transformOps_1 = [];
  25485. var mt = null;
  25486. transform.replace(transformRegex, function (str, type, value) {
  25487. transformOps_1.push(type, value);
  25488. return '';
  25489. });
  25490. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  25491. var value = transformOps_1[i];
  25492. var type = transformOps_1[i - 1];
  25493. var valueArr = splitNumberSequence(value);
  25494. mt = mt || create$1();
  25495. switch (type) {
  25496. case 'translate':
  25497. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  25498. break;
  25499. case 'scale':
  25500. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  25501. break;
  25502. case 'rotate':
  25503. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  25504. break;
  25505. case 'skewX':
  25506. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  25507. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  25508. break;
  25509. case 'skewY':
  25510. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  25511. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  25512. break;
  25513. case 'matrix':
  25514. mt[0] = parseFloat(valueArr[0]);
  25515. mt[1] = parseFloat(valueArr[1]);
  25516. mt[2] = parseFloat(valueArr[2]);
  25517. mt[3] = parseFloat(valueArr[3]);
  25518. mt[4] = parseFloat(valueArr[4]);
  25519. mt[5] = parseFloat(valueArr[5]);
  25520. break;
  25521. }
  25522. }
  25523. node.setLocalTransform(mt);
  25524. }
  25525. }
  25526. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  25527. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  25528. var style = xmlNode.getAttribute('style');
  25529. if (!style) {
  25530. return;
  25531. }
  25532. styleRegex.lastIndex = 0;
  25533. var styleRegResult;
  25534. while ((styleRegResult = styleRegex.exec(style)) != null) {
  25535. var svgStlAttr = styleRegResult[1];
  25536. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  25537. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  25538. : null;
  25539. if (zrInheritableStlAttr) {
  25540. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  25541. }
  25542. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  25543. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  25544. : null;
  25545. if (zrSelfStlAttr) {
  25546. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  25547. }
  25548. }
  25549. }
  25550. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  25551. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  25552. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  25553. var attrValue = xmlNode.getAttribute(svgAttrName);
  25554. if (attrValue != null) {
  25555. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  25556. }
  25557. }
  25558. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  25559. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  25560. var attrValue = xmlNode.getAttribute(svgAttrName);
  25561. if (attrValue != null) {
  25562. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  25563. }
  25564. }
  25565. }
  25566. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  25567. var scaleX = boundingRect.width / viewBoxRect.width;
  25568. var scaleY = boundingRect.height / viewBoxRect.height;
  25569. var scale = Math.min(scaleX, scaleY);
  25570. return {
  25571. scale: scale,
  25572. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  25573. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  25574. };
  25575. }
  25576. function parseSVG(xml, opt) {
  25577. var parser = new SVGParser();
  25578. return parser.parse(xml, opt);
  25579. }
  25580. var EPSILON$3 = 1e-8;
  25581. function isAroundEqual$1(a, b) {
  25582. return Math.abs(a - b) < EPSILON$3;
  25583. }
  25584. function contain$1(points, x, y) {
  25585. var w = 0;
  25586. var p = points[0];
  25587. if (!p) {
  25588. return false;
  25589. }
  25590. for (var i = 1; i < points.length; i++) {
  25591. var p2 = points[i];
  25592. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  25593. p = p2;
  25594. }
  25595. var p0 = points[0];
  25596. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  25597. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  25598. }
  25599. return w !== 0;
  25600. }
  25601. var TMP_TRANSFORM = [];
  25602. var Region =
  25603. /** @class */
  25604. function () {
  25605. function Region(name) {
  25606. this.name = name;
  25607. }
  25608. /**
  25609. * Get center point in data unit. That is,
  25610. * for GeoJSONRegion, the unit is lat/lng,
  25611. * for GeoSVGRegion, the unit is SVG local coord.
  25612. */
  25613. Region.prototype.getCenter = function () {
  25614. return;
  25615. };
  25616. return Region;
  25617. }();
  25618. var GeoJSONRegion =
  25619. /** @class */
  25620. function (_super) {
  25621. __extends(GeoJSONRegion, _super);
  25622. function GeoJSONRegion(name, geometries, cp) {
  25623. var _this = _super.call(this, name) || this;
  25624. _this.type = 'geoJSON';
  25625. _this.geometries = geometries;
  25626. if (!cp) {
  25627. var rect = _this.getBoundingRect();
  25628. cp = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  25629. } else {
  25630. cp = [cp[0], cp[1]];
  25631. }
  25632. _this._center = cp;
  25633. return _this;
  25634. }
  25635. GeoJSONRegion.prototype.getBoundingRect = function () {
  25636. var rect = this._rect;
  25637. if (rect) {
  25638. return rect;
  25639. }
  25640. var MAX_NUMBER = Number.MAX_VALUE;
  25641. var min$1 = [MAX_NUMBER, MAX_NUMBER];
  25642. var max$1 = [-MAX_NUMBER, -MAX_NUMBER];
  25643. var min2 = [];
  25644. var max2 = [];
  25645. var geometries = this.geometries;
  25646. var i = 0;
  25647. for (; i < geometries.length; i++) {
  25648. // Only support polygon
  25649. if (geometries[i].type !== 'polygon') {
  25650. continue;
  25651. } // Doesn't consider hole
  25652. var exterior = geometries[i].exterior;
  25653. fromPoints(exterior, min2, max2);
  25654. min(min$1, min$1, min2);
  25655. max(max$1, max$1, max2);
  25656. } // No data
  25657. if (i === 0) {
  25658. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  25659. }
  25660. return this._rect = new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  25661. };
  25662. GeoJSONRegion.prototype.contain = function (coord) {
  25663. var rect = this.getBoundingRect();
  25664. var geometries = this.geometries;
  25665. if (!rect.contain(coord[0], coord[1])) {
  25666. return false;
  25667. }
  25668. loopGeo: for (var i = 0, len = geometries.length; i < len; i++) {
  25669. // Only support polygon.
  25670. if (geometries[i].type !== 'polygon') {
  25671. continue;
  25672. }
  25673. var exterior = geometries[i].exterior;
  25674. var interiors = geometries[i].interiors;
  25675. if (contain$1(exterior, coord[0], coord[1])) {
  25676. // Not in the region if point is in the hole.
  25677. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  25678. if (contain$1(interiors[k], coord[0], coord[1])) {
  25679. continue loopGeo;
  25680. }
  25681. }
  25682. return true;
  25683. }
  25684. }
  25685. return false;
  25686. };
  25687. GeoJSONRegion.prototype.transformTo = function (x, y, width, height) {
  25688. var rect = this.getBoundingRect();
  25689. var aspect = rect.width / rect.height;
  25690. if (!width) {
  25691. width = aspect * height;
  25692. } else if (!height) {
  25693. height = width / aspect;
  25694. }
  25695. var target = new BoundingRect(x, y, width, height);
  25696. var transform = rect.calculateTransform(target);
  25697. var geometries = this.geometries;
  25698. for (var i = 0; i < geometries.length; i++) {
  25699. // Only support polygon.
  25700. if (geometries[i].type !== 'polygon') {
  25701. continue;
  25702. }
  25703. var exterior = geometries[i].exterior;
  25704. var interiors = geometries[i].interiors;
  25705. for (var p = 0; p < exterior.length; p++) {
  25706. applyTransform(exterior[p], exterior[p], transform);
  25707. }
  25708. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  25709. for (var p = 0; p < interiors[h].length; p++) {
  25710. applyTransform(interiors[h][p], interiors[h][p], transform);
  25711. }
  25712. }
  25713. }
  25714. rect = this._rect;
  25715. rect.copy(target); // Update center
  25716. this._center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  25717. };
  25718. GeoJSONRegion.prototype.cloneShallow = function (name) {
  25719. name == null && (name = this.name);
  25720. var newRegion = new GeoJSONRegion(name, this.geometries, this._center);
  25721. newRegion._rect = this._rect;
  25722. newRegion.transformTo = null; // Simply avoid to be called.
  25723. return newRegion;
  25724. };
  25725. GeoJSONRegion.prototype.getCenter = function () {
  25726. return this._center;
  25727. };
  25728. GeoJSONRegion.prototype.setCenter = function (center) {
  25729. this._center = center;
  25730. };
  25731. return GeoJSONRegion;
  25732. }(Region);
  25733. var GeoSVGRegion =
  25734. /** @class */
  25735. function (_super) {
  25736. __extends(GeoSVGRegion, _super);
  25737. function GeoSVGRegion(name, elOnlyForCalculate) {
  25738. var _this = _super.call(this, name) || this;
  25739. _this.type = 'geoSVG';
  25740. _this._elOnlyForCalculate = elOnlyForCalculate;
  25741. return _this;
  25742. }
  25743. GeoSVGRegion.prototype.getCenter = function () {
  25744. var center = this._center;
  25745. if (!center) {
  25746. // In most cases there are no need to calculate this center.
  25747. // So calculate only when called.
  25748. center = this._center = this._calculateCenter();
  25749. }
  25750. return center;
  25751. };
  25752. GeoSVGRegion.prototype._calculateCenter = function () {
  25753. var el = this._elOnlyForCalculate;
  25754. var rect = el.getBoundingRect();
  25755. var center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  25756. var mat = identity(TMP_TRANSFORM);
  25757. var target = el;
  25758. while (target && !target.isGeoSVGGraphicRoot) {
  25759. mul$1(mat, target.getLocalTransform(), mat);
  25760. target = target.parent;
  25761. }
  25762. invert(mat, mat);
  25763. applyTransform(center, center, mat);
  25764. return center;
  25765. };
  25766. return GeoSVGRegion;
  25767. }(Region);
  25768. /**
  25769. * "region available" means that: enable users to set attribute `name="xxx"` on those tags
  25770. * to make it be a region.
  25771. * 1. region styles and its label styles can be defined in echarts opton:
  25772. * ```js
  25773. * geo: {
  25774. * regions: [{
  25775. * name: 'xxx',
  25776. * itemStyle: { ... },
  25777. * label: { ... }
  25778. * }, {
  25779. * ...
  25780. * },
  25781. * ...]
  25782. * };
  25783. * ```
  25784. * 2. name can be duplicated in different SVG tag. All of the tags with the same name share
  25785. * a region option. For exampel if there are two <path> representing two lung lobes. They have
  25786. * no common parents but both of them need to display label "lung" inside.
  25787. */
  25788. var REGION_AVAILABLE_SVG_TAG_MAP = createHashMap(['rect', 'circle', 'line', 'ellipse', 'polygon', 'polyline', 'path', // <text> <tspan> are also enabled becuase some SVG might paint text itself,
  25789. // but still need to trigger events or tooltip.
  25790. 'text', 'tspan', // <g> is also enabled because this case: if multiple tags share one name
  25791. // and need label displayed, every tags will display the name, which is not
  25792. // expected. So we can put them into a <g name="xxx">. Thereby only one label
  25793. // displayed and located based on the bounding rect of the <g>.
  25794. 'g']);
  25795. var GeoSVGResource =
  25796. /** @class */
  25797. function () {
  25798. function GeoSVGResource(mapName, svg) {
  25799. this.type = 'geoSVG'; // All used graphics. key: hostKey, value: root
  25800. this._usedGraphicMap = createHashMap(); // All unused graphics.
  25801. this._freedGraphics = [];
  25802. this._mapName = mapName; // Only perform parse to XML object here, which might be time
  25803. // consiming for large SVG.
  25804. // Although convert XML to zrender element is also time consiming,
  25805. // if we do it here, the clone of zrender elements has to be
  25806. // required. So we do it once for each geo instance, util real
  25807. // performance issues call for optimizing it.
  25808. this._parsedXML = parseXML(svg);
  25809. }
  25810. GeoSVGResource.prototype.load = function ()
  25811. /* nameMap: NameMap */
  25812. {
  25813. // In the "load" stage, graphic need to be built to
  25814. // get boundingRect for geo coordinate system.
  25815. var firstGraphic = this._firstGraphic; // Create the return data structure only when first graphic created.
  25816. // Because they will be used in geo coordinate system update stage,
  25817. // and `regions` will be mounted at `geo` coordinate system,
  25818. // in which there is no "view" info, so that it should better not to
  25819. // make references to graphic elements.
  25820. if (!firstGraphic) {
  25821. firstGraphic = this._firstGraphic = this._buildGraphic(this._parsedXML);
  25822. this._freedGraphics.push(firstGraphic);
  25823. this._boundingRect = this._firstGraphic.boundingRect.clone(); // PENDING: `nameMap` will not be supported until some real requirement come.
  25824. // if (nameMap) {
  25825. // named = applyNameMap(named, nameMap);
  25826. // }
  25827. var _a = createRegions(firstGraphic.named),
  25828. regions = _a.regions,
  25829. regionsMap = _a.regionsMap;
  25830. this._regions = regions;
  25831. this._regionsMap = regionsMap;
  25832. }
  25833. return {
  25834. boundingRect: this._boundingRect,
  25835. regions: this._regions,
  25836. regionsMap: this._regionsMap
  25837. };
  25838. };
  25839. GeoSVGResource.prototype._buildGraphic = function (svgXML) {
  25840. var result;
  25841. var rootFromParse;
  25842. try {
  25843. result = svgXML && parseSVG(svgXML, {
  25844. ignoreViewBox: true,
  25845. ignoreRootClip: true
  25846. }) || {};
  25847. rootFromParse = result.root;
  25848. assert(rootFromParse != null);
  25849. } catch (e) {
  25850. throw new Error('Invalid svg format\n' + e.message);
  25851. } // Note: we keep the covenant that the root has no transform. So always add an extra root.
  25852. var root = new Group();
  25853. root.add(rootFromParse);
  25854. root.isGeoSVGGraphicRoot = true; // [THE_RULE_OF_VIEWPORT_AND_VIEWBOX]
  25855. //
  25856. // Consider: `<svg width="..." height="..." viewBox="...">`
  25857. // - the `width/height` we call it `svgWidth/svgHeight` for short.
  25858. // - `(0, 0, svgWidth, svgHeight)` defines the viewport of the SVG, or say,
  25859. // "viewport boundingRect", or `boundingRect` for short.
  25860. // - `viewBox` defines the transform from the real content ot the viewport.
  25861. // `viewBox` has the same unit as the content of SVG.
  25862. // If `viewBox` exists, a transform is defined, so the unit of `svgWidth/svgHeight` become
  25863. // different from the content of SVG. Otherwise, they are the same.
  25864. //
  25865. // If both `svgWidth/svgHeight/viewBox` are specified in a SVG file, the transform rule will be:
  25866. // 0. `boundingRect` is `(0, 0, svgWidth, svgHeight)`. Set it to Geo['_rect'] (View['_rect']).
  25867. // 1. Make a transform from `viewBox` to `boundingRect`.
  25868. // Note: only suport `preserveAspectRatio 'xMidYMid'` here. That is, this transform will preserve
  25869. // the aspect ratio.
  25870. // 2. Make a transform from boundingRect to Geo['_viewRect'] (View['_viewRect'])
  25871. // (`Geo`/`View` will do this job).
  25872. // Note: this transform might not preserve aspect radio, which depending on how users specify
  25873. // viewRect in echarts option (e.g., `geo.left/top/width/height` will not preserve aspect ratio,
  25874. // but `geo.layoutCenter/layoutSize` will preserve aspect ratio).
  25875. //
  25876. // If `svgWidth/svgHeight` not specified, we use `viewBox` as the `boundingRect` to make the SVG
  25877. // layout look good.
  25878. //
  25879. // If neither `svgWidth/svgHeight` nor `viewBox` are not specified, we calculate the boundingRect
  25880. // of the SVG content and use them to make SVG layout look good.
  25881. var svgWidth = result.width;
  25882. var svgHeight = result.height;
  25883. var viewBoxRect = result.viewBoxRect;
  25884. var boundingRect = this._boundingRect;
  25885. if (!boundingRect) {
  25886. var bRectX = void 0;
  25887. var bRectY = void 0;
  25888. var bRectWidth = void 0;
  25889. var bRectHeight = void 0;
  25890. if (svgWidth != null) {
  25891. bRectX = 0;
  25892. bRectWidth = svgWidth;
  25893. } else if (viewBoxRect) {
  25894. bRectX = viewBoxRect.x;
  25895. bRectWidth = viewBoxRect.width;
  25896. }
  25897. if (svgHeight != null) {
  25898. bRectY = 0;
  25899. bRectHeight = svgHeight;
  25900. } else if (viewBoxRect) {
  25901. bRectY = viewBoxRect.y;
  25902. bRectHeight = viewBoxRect.height;
  25903. } // If both viewBox and svgWidth/svgHeight not specified,
  25904. // we have to determine how to layout those element to make them look good.
  25905. if (bRectX == null || bRectY == null) {
  25906. var calculatedBoundingRect = rootFromParse.getBoundingRect();
  25907. if (bRectX == null) {
  25908. bRectX = calculatedBoundingRect.x;
  25909. bRectWidth = calculatedBoundingRect.width;
  25910. }
  25911. if (bRectY == null) {
  25912. bRectY = calculatedBoundingRect.y;
  25913. bRectHeight = calculatedBoundingRect.height;
  25914. }
  25915. }
  25916. boundingRect = this._boundingRect = new BoundingRect(bRectX, bRectY, bRectWidth, bRectHeight);
  25917. }
  25918. if (viewBoxRect) {
  25919. var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect); // Only support `preserveAspectRatio 'xMidYMid'`
  25920. rootFromParse.scaleX = rootFromParse.scaleY = viewBoxTransform.scale;
  25921. rootFromParse.x = viewBoxTransform.x;
  25922. rootFromParse.y = viewBoxTransform.y;
  25923. } // SVG needs to clip based on `viewBox`. And some SVG files really rely on this feature.
  25924. // They do not strictly confine all of the content inside a display rect, but deliberately
  25925. // use a `viewBox` to define a displayable rect.
  25926. // PENDING:
  25927. // The drawback of the `setClipPath` here is: the region label (genereted by echarts) near the
  25928. // edge might also be clipped, because region labels are put as `textContent` of the SVG path.
  25929. root.setClipPath(new Rect({
  25930. shape: boundingRect.plain()
  25931. }));
  25932. var named = [];
  25933. each(result.named, function (namedItem) {
  25934. if (REGION_AVAILABLE_SVG_TAG_MAP.get(namedItem.svgNodeTagLower) != null) {
  25935. named.push(namedItem);
  25936. setSilent(namedItem.el);
  25937. }
  25938. });
  25939. return {
  25940. root: root,
  25941. boundingRect: boundingRect,
  25942. named: named
  25943. };
  25944. };
  25945. /**
  25946. * Consider:
  25947. * (1) One graphic element can not be shared by different `geoView` running simultaneously.
  25948. * Notice, also need to consider multiple echarts instances share a `mapRecord`.
  25949. * (2) Converting SVG to graphic elements is time consuming.
  25950. * (3) In the current architecture, `load` should be called frequently to get boundingRect,
  25951. * and it is called without view info.
  25952. * So we maintain graphic elements in this module, and enables `view` to use/return these
  25953. * graphics from/to the pool with it's uid.
  25954. */
  25955. GeoSVGResource.prototype.useGraphic = function (hostKey
  25956. /*, nameMap: NameMap */
  25957. ) {
  25958. var usedRootMap = this._usedGraphicMap;
  25959. var svgGraphic = usedRootMap.get(hostKey);
  25960. if (svgGraphic) {
  25961. return svgGraphic;
  25962. }
  25963. svgGraphic = this._freedGraphics.pop() // use the first boundingRect to avoid duplicated boundingRect calculation.
  25964. || this._buildGraphic(this._parsedXML);
  25965. usedRootMap.set(hostKey, svgGraphic); // PENDING: `nameMap` will not be supported until some real requirement come.
  25966. // `nameMap` can only be obtained from echarts option.
  25967. // The original `named` must not be modified.
  25968. // if (nameMap) {
  25969. // svgGraphic = extend({}, svgGraphic);
  25970. // svgGraphic.named = applyNameMap(svgGraphic.named, nameMap);
  25971. // }
  25972. return svgGraphic;
  25973. };
  25974. GeoSVGResource.prototype.freeGraphic = function (hostKey) {
  25975. var usedRootMap = this._usedGraphicMap;
  25976. var svgGraphic = usedRootMap.get(hostKey);
  25977. if (svgGraphic) {
  25978. usedRootMap.removeKey(hostKey);
  25979. this._freedGraphics.push(svgGraphic);
  25980. }
  25981. };
  25982. return GeoSVGResource;
  25983. }();
  25984. function setSilent(el) {
  25985. // Only named element has silent: false, other elements should
  25986. // act as background and has no user interaction.
  25987. el.silent = false; // text|tspan will be converted to group.
  25988. if (el.isGroup) {
  25989. el.traverse(function (child) {
  25990. child.silent = false;
  25991. });
  25992. }
  25993. }
  25994. function createRegions(named) {
  25995. var regions = [];
  25996. var regionsMap = createHashMap(); // Create resions only for the first graphic.
  25997. each(named, function (namedItem) {
  25998. // Region has feature to calculate center for tooltip or other features.
  25999. // If there is a <g name="xxx">, the center should be the center of the
  26000. // bounding rect of the g.
  26001. if (namedItem.namedFrom != null) {
  26002. return;
  26003. }
  26004. var region = new GeoSVGRegion(namedItem.name, namedItem.el); // PENDING: if `nameMap` supported, this region can not be mounted on
  26005. // `this`, but can only be created each time `load()` called.
  26006. regions.push(region); // PENDING: if multiple tag named with the same name, only one will be
  26007. // found by `_regionsMap`. `_regionsMap` is used to find a coordinate
  26008. // by name. We use `region.getCenter()` as the coordinate.
  26009. regionsMap.set(namedItem.name, region);
  26010. });
  26011. return {
  26012. regions: regions,
  26013. regionsMap: regionsMap
  26014. };
  26015. } // PENDING: `nameMap` will not be supported until some real requirement come.
  26016. // /**
  26017. // * Use the alias in geoNameMap.
  26018. // * The input `named` must not be modified.
  26019. // */
  26020. // function applyNameMap(
  26021. // named: GeoSVGGraphicRecord['named'],
  26022. // nameMap: NameMap
  26023. // ): GeoSVGGraphicRecord['named'] {
  26024. // const result = [] as GeoSVGGraphicRecord['named'];
  26025. // for (let i = 0; i < named.length; i++) {
  26026. // let regionGraphic = named[i];
  26027. // const name = regionGraphic.name;
  26028. // if (nameMap && nameMap.hasOwnProperty(name)) {
  26029. // regionGraphic = extend({}, regionGraphic);
  26030. // regionGraphic.name = name;
  26031. // }
  26032. // result.push(regionGraphic);
  26033. // }
  26034. // return result;
  26035. // }
  26036. function decode(json) {
  26037. if (!json.UTF8Encoding) {
  26038. return json;
  26039. }
  26040. var jsonCompressed = json;
  26041. var encodeScale = jsonCompressed.UTF8Scale;
  26042. if (encodeScale == null) {
  26043. encodeScale = 1024;
  26044. }
  26045. var features = jsonCompressed.features;
  26046. for (var f = 0; f < features.length; f++) {
  26047. var feature = features[f];
  26048. var geometry = feature.geometry;
  26049. if (geometry.type === 'Polygon') {
  26050. var coordinates = geometry.coordinates;
  26051. for (var c = 0; c < coordinates.length; c++) {
  26052. coordinates[c] = decodePolygon(coordinates[c], geometry.encodeOffsets[c], encodeScale);
  26053. }
  26054. } else if (geometry.type === 'MultiPolygon') {
  26055. var coordinates = geometry.coordinates;
  26056. for (var c = 0; c < coordinates.length; c++) {
  26057. var coordinate = coordinates[c];
  26058. for (var c2 = 0; c2 < coordinate.length; c2++) {
  26059. coordinate[c2] = decodePolygon(coordinate[c2], geometry.encodeOffsets[c][c2], encodeScale);
  26060. }
  26061. }
  26062. }
  26063. } // Has been decoded
  26064. jsonCompressed.UTF8Encoding = false;
  26065. return jsonCompressed;
  26066. }
  26067. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  26068. var result = [];
  26069. var prevX = encodeOffsets[0];
  26070. var prevY = encodeOffsets[1];
  26071. for (var i = 0; i < coordinate.length; i += 2) {
  26072. var x = coordinate.charCodeAt(i) - 64;
  26073. var y = coordinate.charCodeAt(i + 1) - 64; // ZigZag decoding
  26074. x = x >> 1 ^ -(x & 1);
  26075. y = y >> 1 ^ -(y & 1); // Delta deocding
  26076. x += prevX;
  26077. y += prevY;
  26078. prevX = x;
  26079. prevY = y; // Dequantize
  26080. result.push([x / encodeScale, y / encodeScale]);
  26081. }
  26082. return result;
  26083. }
  26084. function parseGeoJSON(geoJson, nameProperty) {
  26085. geoJson = decode(geoJson);
  26086. return map(filter(geoJson.features, function (featureObj) {
  26087. // Output of mapshaper may have geometry null
  26088. return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
  26089. }), function (featureObj) {
  26090. var properties = featureObj.properties;
  26091. var geo = featureObj.geometry;
  26092. var geometries = [];
  26093. if (geo.type === 'Polygon') {
  26094. var coordinates = geo.coordinates;
  26095. geometries.push({
  26096. type: 'polygon',
  26097. // According to the GeoJSON specification.
  26098. // First must be exterior, and the rest are all interior(holes).
  26099. exterior: coordinates[0],
  26100. interiors: coordinates.slice(1)
  26101. });
  26102. }
  26103. if (geo.type === 'MultiPolygon') {
  26104. var coordinates = geo.coordinates;
  26105. each(coordinates, function (item) {
  26106. if (item[0]) {
  26107. geometries.push({
  26108. type: 'polygon',
  26109. exterior: item[0],
  26110. interiors: item.slice(1)
  26111. });
  26112. }
  26113. });
  26114. }
  26115. var region = new GeoJSONRegion(properties[nameProperty || 'name'], geometries, properties.cp);
  26116. region.properties = properties;
  26117. return region;
  26118. });
  26119. }
  26120. var geoCoord = [126, 25];
  26121. var nanhaiName = '南海诸岛';
  26122. var points$1 = [[[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7], [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]], [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]], [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]], [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]], [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]], [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]], [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]], [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]], [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]], [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]], [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]], [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4], [1, 92.4], [1, 3.5], [0, 3.5]]];
  26123. for (var i = 0; i < points$1.length; i++) {
  26124. for (var k = 0; k < points$1[i].length; k++) {
  26125. points$1[i][k][0] /= 10.5;
  26126. points$1[i][k][1] /= -10.5 / 0.75;
  26127. points$1[i][k][0] += geoCoord[0];
  26128. points$1[i][k][1] += geoCoord[1];
  26129. }
  26130. }
  26131. function fixNanhai(mapType, regions) {
  26132. if (mapType === 'china') {
  26133. for (var i = 0; i < regions.length; i++) {
  26134. // Already exists.
  26135. if (regions[i].name === nanhaiName) {
  26136. return;
  26137. }
  26138. }
  26139. regions.push(new GeoJSONRegion(nanhaiName, map(points$1, function (exterior) {
  26140. return {
  26141. type: 'polygon',
  26142. exterior: exterior
  26143. };
  26144. }), geoCoord));
  26145. }
  26146. }
  26147. /*
  26148. * Licensed to the Apache Software Foundation (ASF) under one
  26149. * or more contributor license agreements. See the NOTICE file
  26150. * distributed with this work for additional information
  26151. * regarding copyright ownership. The ASF licenses this file
  26152. * to you under the Apache License, Version 2.0 (the
  26153. * "License"); you may not use this file except in compliance
  26154. * with the License. You may obtain a copy of the License at
  26155. *
  26156. * http://www.apache.org/licenses/LICENSE-2.0
  26157. *
  26158. * Unless required by applicable law or agreed to in writing,
  26159. * software distributed under the License is distributed on an
  26160. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26161. * KIND, either express or implied. See the License for the
  26162. * specific language governing permissions and limitations
  26163. * under the License.
  26164. */
  26165. /**
  26166. * AUTO-GENERATED FILE. DO NOT MODIFY.
  26167. */
  26168. /*
  26169. * Licensed to the Apache Software Foundation (ASF) under one
  26170. * or more contributor license agreements. See the NOTICE file
  26171. * distributed with this work for additional information
  26172. * regarding copyright ownership. The ASF licenses this file
  26173. * to you under the Apache License, Version 2.0 (the
  26174. * "License"); you may not use this file except in compliance
  26175. * with the License. You may obtain a copy of the License at
  26176. *
  26177. * http://www.apache.org/licenses/LICENSE-2.0
  26178. *
  26179. * Unless required by applicable law or agreed to in writing,
  26180. * software distributed under the License is distributed on an
  26181. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26182. * KIND, either express or implied. See the License for the
  26183. * specific language governing permissions and limitations
  26184. * under the License.
  26185. */
  26186. var coordsOffsetMap = {
  26187. '南海诸岛': [32, 80],
  26188. // 全国
  26189. '广东': [0, -10],
  26190. '香港': [10, 5],
  26191. '澳门': [-10, 10],
  26192. //'北京': [-10, 0],
  26193. '天津': [5, 5]
  26194. };
  26195. function fixTextCoords(mapType, region) {
  26196. if (mapType === 'china') {
  26197. var coordFix = coordsOffsetMap[region.name];
  26198. if (coordFix) {
  26199. var cp = region.getCenter();
  26200. cp[0] += coordFix[0] / 10.5;
  26201. cp[1] += -coordFix[1] / (10.5 / 0.75);
  26202. region.setCenter(cp);
  26203. }
  26204. }
  26205. }
  26206. /*
  26207. * Licensed to the Apache Software Foundation (ASF) under one
  26208. * or more contributor license agreements. See the NOTICE file
  26209. * distributed with this work for additional information
  26210. * regarding copyright ownership. The ASF licenses this file
  26211. * to you under the Apache License, Version 2.0 (the
  26212. * "License"); you may not use this file except in compliance
  26213. * with the License. You may obtain a copy of the License at
  26214. *
  26215. * http://www.apache.org/licenses/LICENSE-2.0
  26216. *
  26217. * Unless required by applicable law or agreed to in writing,
  26218. * software distributed under the License is distributed on an
  26219. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26220. * KIND, either express or implied. See the License for the
  26221. * specific language governing permissions and limitations
  26222. * under the License.
  26223. */
  26224. /**
  26225. * AUTO-GENERATED FILE. DO NOT MODIFY.
  26226. */
  26227. /*
  26228. * Licensed to the Apache Software Foundation (ASF) under one
  26229. * or more contributor license agreements. See the NOTICE file
  26230. * distributed with this work for additional information
  26231. * regarding copyright ownership. The ASF licenses this file
  26232. * to you under the Apache License, Version 2.0 (the
  26233. * "License"); you may not use this file except in compliance
  26234. * with the License. You may obtain a copy of the License at
  26235. *
  26236. * http://www.apache.org/licenses/LICENSE-2.0
  26237. *
  26238. * Unless required by applicable law or agreed to in writing,
  26239. * software distributed under the License is distributed on an
  26240. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26241. * KIND, either express or implied. See the License for the
  26242. * specific language governing permissions and limitations
  26243. * under the License.
  26244. */
  26245. var geoCoordMap = {
  26246. 'Russia': [100, 60],
  26247. 'United States': [-99, 38],
  26248. 'United States of America': [-99, 38]
  26249. };
  26250. function fixGeoCoords(mapType, region) {
  26251. if (mapType === 'world') {
  26252. var geoCoord = geoCoordMap[region.name];
  26253. if (geoCoord) {
  26254. var cp = [geoCoord[0], geoCoord[1]];
  26255. region.setCenter(cp);
  26256. }
  26257. }
  26258. }
  26259. /*
  26260. * Licensed to the Apache Software Foundation (ASF) under one
  26261. * or more contributor license agreements. See the NOTICE file
  26262. * distributed with this work for additional information
  26263. * regarding copyright ownership. The ASF licenses this file
  26264. * to you under the Apache License, Version 2.0 (the
  26265. * "License"); you may not use this file except in compliance
  26266. * with the License. You may obtain a copy of the License at
  26267. *
  26268. * http://www.apache.org/licenses/LICENSE-2.0
  26269. *
  26270. * Unless required by applicable law or agreed to in writing,
  26271. * software distributed under the License is distributed on an
  26272. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26273. * KIND, either express or implied. See the License for the
  26274. * specific language governing permissions and limitations
  26275. * under the License.
  26276. */
  26277. /**
  26278. * AUTO-GENERATED FILE. DO NOT MODIFY.
  26279. */
  26280. /*
  26281. * Licensed to the Apache Software Foundation (ASF) under one
  26282. * or more contributor license agreements. See the NOTICE file
  26283. * distributed with this work for additional information
  26284. * regarding copyright ownership. The ASF licenses this file
  26285. * to you under the Apache License, Version 2.0 (the
  26286. * "License"); you may not use this file except in compliance
  26287. * with the License. You may obtain a copy of the License at
  26288. *
  26289. * http://www.apache.org/licenses/LICENSE-2.0
  26290. *
  26291. * Unless required by applicable law or agreed to in writing,
  26292. * software distributed under the License is distributed on an
  26293. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26294. * KIND, either express or implied. See the License for the
  26295. * specific language governing permissions and limitations
  26296. * under the License.
  26297. */
  26298. // Fix for 钓鱼岛
  26299. // let Region = require('../Region');
  26300. // let zrUtil = require('zrender/lib/core/util');
  26301. // let geoCoord = [126, 25];
  26302. var points$2 = [[[123.45165252685547, 25.73527164402261], [123.49731445312499, 25.73527164402261], [123.49731445312499, 25.750734064600884], [123.45165252685547, 25.750734064600884], [123.45165252685547, 25.73527164402261]]];
  26303. function fixDiaoyuIsland(mapType, region) {
  26304. if (mapType === 'china' && region.name === '台湾') {
  26305. region.geometries.push({
  26306. type: 'polygon',
  26307. exterior: points$2[0]
  26308. });
  26309. }
  26310. }
  26311. var DEFAULT_NAME_PROPERTY = 'name';
  26312. var GeoJSONResource =
  26313. /** @class */
  26314. function () {
  26315. function GeoJSONResource(mapName, geoJSON, specialAreas) {
  26316. this.type = 'geoJSON';
  26317. this._parsedMap = createHashMap();
  26318. this._mapName = mapName;
  26319. this._specialAreas = specialAreas; // PENDING: delay the parse to the first usage to rapid up the FMP?
  26320. this._geoJSON = parseInput(geoJSON);
  26321. }
  26322. /**
  26323. * @param nameMap can be null/undefined
  26324. * @param nameProperty can be null/undefined
  26325. */
  26326. GeoJSONResource.prototype.load = function (nameMap, nameProperty) {
  26327. nameProperty = nameProperty || DEFAULT_NAME_PROPERTY;
  26328. var parsed = this._parsedMap.get(nameProperty);
  26329. if (!parsed) {
  26330. var rawRegions = this._parseToRegions(nameProperty);
  26331. parsed = this._parsedMap.set(nameProperty, {
  26332. regions: rawRegions,
  26333. boundingRect: calculateBoundingRect(rawRegions)
  26334. });
  26335. }
  26336. var regionsMap = createHashMap();
  26337. var finalRegions = [];
  26338. each(parsed.regions, function (region) {
  26339. var regionName = region.name; // Try use the alias in geoNameMap
  26340. if (nameMap && nameMap.hasOwnProperty(regionName)) {
  26341. region = region.cloneShallow(regionName = nameMap[regionName]);
  26342. }
  26343. finalRegions.push(region);
  26344. regionsMap.set(regionName, region);
  26345. });
  26346. return {
  26347. regions: finalRegions,
  26348. boundingRect: parsed.boundingRect || new BoundingRect(0, 0, 0, 0),
  26349. regionsMap: regionsMap
  26350. };
  26351. };
  26352. GeoJSONResource.prototype._parseToRegions = function (nameProperty) {
  26353. var mapName = this._mapName;
  26354. var geoJSON = this._geoJSON;
  26355. var rawRegions; // https://jsperf.com/try-catch-performance-overhead
  26356. try {
  26357. rawRegions = geoJSON ? parseGeoJSON(geoJSON, nameProperty) : [];
  26358. } catch (e) {
  26359. throw new Error('Invalid geoJson format\n' + e.message);
  26360. }
  26361. fixNanhai(mapName, rawRegions);
  26362. each(rawRegions, function (region) {
  26363. var regionName = region.name;
  26364. fixTextCoords(mapName, region);
  26365. fixGeoCoords(mapName, region);
  26366. fixDiaoyuIsland(mapName, region); // Some area like Alaska in USA map needs to be tansformed
  26367. // to look better
  26368. var specialArea = this._specialAreas && this._specialAreas[regionName];
  26369. if (specialArea) {
  26370. region.transformTo(specialArea.left, specialArea.top, specialArea.width, specialArea.height);
  26371. }
  26372. }, this);
  26373. return rawRegions;
  26374. };
  26375. /**
  26376. * Only for exporting to users.
  26377. * **MUST NOT** used internally.
  26378. */
  26379. GeoJSONResource.prototype.getMapForUser = function () {
  26380. return {
  26381. // For backward compatibility, use geoJson
  26382. // PENDING: it has been returning them without clone.
  26383. // do we need to avoid outsite modification?
  26384. geoJson: this._geoJSON,
  26385. geoJSON: this._geoJSON,
  26386. specialAreas: this._specialAreas
  26387. };
  26388. };
  26389. return GeoJSONResource;
  26390. }();
  26391. function calculateBoundingRect(regions) {
  26392. var rect;
  26393. for (var i = 0; i < regions.length; i++) {
  26394. var regionRect = regions[i].getBoundingRect();
  26395. rect = rect || regionRect.clone();
  26396. rect.union(regionRect);
  26397. }
  26398. return rect;
  26399. }
  26400. function parseInput(source) {
  26401. return !isString(source) ? source : typeof JSON !== 'undefined' && JSON.parse ? JSON.parse(source) : new Function('return (' + source + ');')();
  26402. }
  26403. var storage = createHashMap();
  26404. var geoSourceManager = {
  26405. /**
  26406. * Compatible with previous `echarts.registerMap`.
  26407. *
  26408. * @usage
  26409. * ```js
  26410. *
  26411. * echarts.registerMap('USA', geoJson, specialAreas);
  26412. *
  26413. * echarts.registerMap('USA', {
  26414. * geoJson: geoJson,
  26415. * specialAreas: {...}
  26416. * });
  26417. * echarts.registerMap('USA', {
  26418. * geoJSON: geoJson,
  26419. * specialAreas: {...}
  26420. * });
  26421. *
  26422. * echarts.registerMap('airport', {
  26423. * svg: svg
  26424. * }
  26425. * ```
  26426. *
  26427. * Note:
  26428. * Do not support that register multiple geoJSON or SVG
  26429. * one map name. Because different geoJSON and SVG have
  26430. * different unit. It's not easy to make sure how those
  26431. * units are mapping/normalize.
  26432. * If intending to use multiple geoJSON or SVG, we can
  26433. * use multiple geo coordinate system.
  26434. */
  26435. registerMap: function (mapName, rawDef, rawSpecialAreas) {
  26436. if (rawDef.svg) {
  26437. var resource = new GeoSVGResource(mapName, rawDef.svg);
  26438. storage.set(mapName, resource);
  26439. } else {
  26440. // Recommend:
  26441. // echarts.registerMap('eu', { geoJSON: xxx, specialAreas: xxx });
  26442. // Backward compatibility:
  26443. // echarts.registerMap('eu', geoJSON, specialAreas);
  26444. // echarts.registerMap('eu', { geoJson: xxx, specialAreas: xxx });
  26445. var geoJSON = rawDef.geoJson || rawDef.geoJSON;
  26446. if (geoJSON && !rawDef.features) {
  26447. rawSpecialAreas = rawDef.specialAreas;
  26448. } else {
  26449. geoJSON = rawDef;
  26450. }
  26451. var resource = new GeoJSONResource(mapName, geoJSON, rawSpecialAreas);
  26452. storage.set(mapName, resource);
  26453. }
  26454. },
  26455. getGeoResource: function (mapName) {
  26456. return storage.get(mapName);
  26457. },
  26458. /**
  26459. * Only for exporting to users.
  26460. * **MUST NOT** used internally.
  26461. */
  26462. getMapForUser: function (mapName) {
  26463. var resource = storage.get(mapName); // Do not support return SVG until some real requirement come.
  26464. return resource && resource.type === 'geoJSON' && resource.getMapForUser();
  26465. },
  26466. load: function (mapName, nameMap, nameProperty) {
  26467. var resource = storage.get(mapName);
  26468. if (!resource) {
  26469. if ("development" !== 'production') {
  26470. console.error('Map ' + mapName + ' not exists. The GeoJSON of the map must be provided.');
  26471. }
  26472. return;
  26473. }
  26474. return resource.load(nameMap, nameProperty);
  26475. }
  26476. };
  26477. var lifecycle = new Eventful();
  26478. var hasWindow = typeof window !== 'undefined';
  26479. var version$1 = '5.2.2';
  26480. var dependencies = {
  26481. zrender: '5.2.1'
  26482. };
  26483. var TEST_FRAME_REMAIN_TIME = 1;
  26484. var PRIORITY_PROCESSOR_SERIES_FILTER = 800; // Some data processors depends on the stack result dimension (to calculate data extent).
  26485. // So data stack stage should be in front of data processing stage.
  26486. var PRIORITY_PROCESSOR_DATASTACK = 900; // "Data filter" will block the stream, so it should be
  26487. // put at the begining of data processing.
  26488. var PRIORITY_PROCESSOR_FILTER = 1000;
  26489. var PRIORITY_PROCESSOR_DEFAULT = 2000;
  26490. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  26491. var PRIORITY_VISUAL_LAYOUT = 1000;
  26492. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  26493. var PRIORITY_VISUAL_GLOBAL = 2000;
  26494. var PRIORITY_VISUAL_CHART = 3000;
  26495. var PRIORITY_VISUAL_COMPONENT = 4000; // Visual property in data. Greater than `PRIORITY_VISUAL_COMPONENT` to enable to
  26496. // overwrite the viusal result of component (like `visualMap`)
  26497. // using data item specific setting (like itemStyle.xxx on data item)
  26498. var PRIORITY_VISUAL_CHART_DATA_CUSTOM = 4500; // Greater than `PRIORITY_VISUAL_CHART_DATA_CUSTOM` to enable to layout based on
  26499. // visual result like `symbolSize`.
  26500. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 4600;
  26501. var PRIORITY_VISUAL_BRUSH = 5000;
  26502. var PRIORITY_VISUAL_ARIA = 6000;
  26503. var PRIORITY_VISUAL_DECAL = 7000;
  26504. var PRIORITY = {
  26505. PROCESSOR: {
  26506. FILTER: PRIORITY_PROCESSOR_FILTER,
  26507. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  26508. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  26509. },
  26510. VISUAL: {
  26511. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  26512. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  26513. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  26514. CHART: PRIORITY_VISUAL_CHART,
  26515. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  26516. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  26517. BRUSH: PRIORITY_VISUAL_BRUSH,
  26518. CHART_ITEM: PRIORITY_VISUAL_CHART_DATA_CUSTOM,
  26519. ARIA: PRIORITY_VISUAL_ARIA,
  26520. DECAL: PRIORITY_VISUAL_DECAL
  26521. }
  26522. }; // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  26523. // where they must not be invoked nestedly, except the only case: invoke
  26524. // dispatchAction with updateMethod "none" in main process.
  26525. // This flag is used to carry out this rule.
  26526. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  26527. var IN_MAIN_PROCESS_KEY = '__flagInMainProcess';
  26528. var PENDING_UPDATE = '__pendingUpdate';
  26529. var STATUS_NEEDS_UPDATE_KEY = '__needsUpdateStatus';
  26530. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  26531. var CONNECT_STATUS_KEY = '__connectUpdateStatus';
  26532. var CONNECT_STATUS_PENDING = 0;
  26533. var CONNECT_STATUS_UPDATING = 1;
  26534. var CONNECT_STATUS_UPDATED = 2;
  26535. function createRegisterEventWithLowercaseECharts(method) {
  26536. return function () {
  26537. var args = [];
  26538. for (var _i = 0; _i < arguments.length; _i++) {
  26539. args[_i] = arguments[_i];
  26540. }
  26541. if (this.isDisposed()) {
  26542. disposedWarning(this.id);
  26543. return;
  26544. }
  26545. return toLowercaseNameAndCallEventful(this, method, args);
  26546. };
  26547. }
  26548. function createRegisterEventWithLowercaseMessageCenter(method) {
  26549. return function () {
  26550. var args = [];
  26551. for (var _i = 0; _i < arguments.length; _i++) {
  26552. args[_i] = arguments[_i];
  26553. }
  26554. return toLowercaseNameAndCallEventful(this, method, args);
  26555. };
  26556. }
  26557. function toLowercaseNameAndCallEventful(host, method, args) {
  26558. // `args[0]` is event name. Event name is all lowercase.
  26559. args[0] = args[0] && args[0].toLowerCase();
  26560. return Eventful.prototype[method].apply(host, args);
  26561. }
  26562. var MessageCenter =
  26563. /** @class */
  26564. function (_super) {
  26565. __extends(MessageCenter, _super);
  26566. function MessageCenter() {
  26567. return _super !== null && _super.apply(this, arguments) || this;
  26568. }
  26569. return MessageCenter;
  26570. }(Eventful);
  26571. var messageCenterProto = MessageCenter.prototype;
  26572. messageCenterProto.on = createRegisterEventWithLowercaseMessageCenter('on');
  26573. messageCenterProto.off = createRegisterEventWithLowercaseMessageCenter('off'); // ---------------------------------------
  26574. // Internal method names for class ECharts
  26575. // ---------------------------------------
  26576. var prepare;
  26577. var prepareView;
  26578. var updateDirectly;
  26579. var updateMethods;
  26580. var doConvertPixel;
  26581. var updateStreamModes;
  26582. var doDispatchAction;
  26583. var flushPendingActions;
  26584. var triggerUpdatedEvent;
  26585. var bindRenderedEvent;
  26586. var bindMouseEvent;
  26587. var clearColorPalette;
  26588. var render;
  26589. var renderComponents;
  26590. var renderSeries;
  26591. var createExtensionAPI;
  26592. var enableConnect;
  26593. var markStatusToUpdate;
  26594. var applyChangedStates;
  26595. var ECharts =
  26596. /** @class */
  26597. function (_super) {
  26598. __extends(ECharts, _super);
  26599. function ECharts(dom, // Theme name or themeOption.
  26600. theme, opts) {
  26601. var _this = _super.call(this, new ECEventProcessor()) || this;
  26602. _this._chartsViews = [];
  26603. _this._chartsMap = {};
  26604. _this._componentsViews = [];
  26605. _this._componentsMap = {}; // Can't dispatch action during rendering procedure
  26606. _this._pendingActions = [];
  26607. opts = opts || {}; // Get theme by name
  26608. if (typeof theme === 'string') {
  26609. theme = themeStorage[theme];
  26610. }
  26611. _this._dom = dom;
  26612. var defaultRenderer = 'canvas';
  26613. var defaultUseDirtyRect = false;
  26614. if ("development" !== 'production') {
  26615. var root =
  26616. /* eslint-disable-next-line */
  26617. hasWindow ? window : global;
  26618. defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  26619. var devUseDirtyRect = root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__;
  26620. defaultUseDirtyRect = devUseDirtyRect == null ? defaultUseDirtyRect : devUseDirtyRect;
  26621. }
  26622. var zr = _this._zr = init(dom, {
  26623. renderer: opts.renderer || defaultRenderer,
  26624. devicePixelRatio: opts.devicePixelRatio,
  26625. width: opts.width,
  26626. height: opts.height,
  26627. useDirtyRect: opts.useDirtyRect == null ? defaultUseDirtyRect : opts.useDirtyRect
  26628. }); // Expect 60 fps.
  26629. _this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  26630. theme = clone(theme);
  26631. theme && globalBackwardCompat(theme, true);
  26632. _this._theme = theme;
  26633. _this._locale = createLocaleObject(opts.locale || SYSTEM_LANG);
  26634. _this._coordSysMgr = new CoordinateSystemManager();
  26635. var api = _this._api = createExtensionAPI(_this); // Sort on demand
  26636. function prioritySortFunc(a, b) {
  26637. return a.__prio - b.__prio;
  26638. }
  26639. sort(visualFuncs, prioritySortFunc);
  26640. sort(dataProcessorFuncs, prioritySortFunc);
  26641. _this._scheduler = new Scheduler(_this, api, dataProcessorFuncs, visualFuncs);
  26642. _this._messageCenter = new MessageCenter(); // Init mouse events
  26643. _this._initEvents(); // In case some people write `window.onresize = chart.resize`
  26644. _this.resize = bind(_this.resize, _this);
  26645. zr.animation.on('frame', _this._onframe, _this);
  26646. bindRenderedEvent(zr, _this);
  26647. bindMouseEvent(zr, _this); // ECharts instance can be used as value.
  26648. setAsPrimitive(_this);
  26649. return _this;
  26650. }
  26651. ECharts.prototype._onframe = function () {
  26652. if (this._disposed) {
  26653. return;
  26654. }
  26655. applyChangedStates(this);
  26656. var scheduler = this._scheduler; // Lazy update
  26657. if (this[PENDING_UPDATE]) {
  26658. var silent = this[PENDING_UPDATE].silent;
  26659. this[IN_MAIN_PROCESS_KEY] = true;
  26660. prepare(this);
  26661. updateMethods.update.call(this, null, this[PENDING_UPDATE].updateParams); // At present, in each frame, zrender performs:
  26662. // (1) animation step forward.
  26663. // (2) trigger('frame') (where this `_onframe` is called)
  26664. // (3) zrender flush (render).
  26665. // If we do nothing here, since we use `setToFinal: true`, the step (3) above
  26666. // will render the final state of the elements before the real animation started.
  26667. this._zr.flush();
  26668. this[IN_MAIN_PROCESS_KEY] = false;
  26669. this[PENDING_UPDATE] = null;
  26670. flushPendingActions.call(this, silent);
  26671. triggerUpdatedEvent.call(this, silent);
  26672. } // Avoid do both lazy update and progress in one frame.
  26673. else if (scheduler.unfinished) {
  26674. // Stream progress.
  26675. var remainTime = TEST_FRAME_REMAIN_TIME;
  26676. var ecModel = this._model;
  26677. var api = this._api;
  26678. scheduler.unfinished = false;
  26679. do {
  26680. var startTime = +new Date();
  26681. scheduler.performSeriesTasks(ecModel); // Currently dataProcessorFuncs do not check threshold.
  26682. scheduler.performDataProcessorTasks(ecModel);
  26683. updateStreamModes(this, ecModel); // Do not update coordinate system here. Because that coord system update in
  26684. // each frame is not a good user experience. So we follow the rule that
  26685. // the extent of the coordinate system is determin in the first frame (the
  26686. // frame is executed immedietely after task reset.
  26687. // this._coordSysMgr.update(ecModel, api);
  26688. // console.log('--- ec frame visual ---', remainTime);
  26689. scheduler.performVisualTasks(ecModel);
  26690. renderSeries(this, this._model, api, 'remain', {});
  26691. remainTime -= +new Date() - startTime;
  26692. } while (remainTime > 0 && scheduler.unfinished); // Call flush explicitly for trigger finished event.
  26693. if (!scheduler.unfinished) {
  26694. this._zr.flush();
  26695. } // Else, zr flushing be ensue within the same frame,
  26696. // because zr flushing is after onframe event.
  26697. }
  26698. };
  26699. ECharts.prototype.getDom = function () {
  26700. return this._dom;
  26701. };
  26702. ECharts.prototype.getId = function () {
  26703. return this.id;
  26704. };
  26705. ECharts.prototype.getZr = function () {
  26706. return this._zr;
  26707. };
  26708. /* eslint-disable-next-line */
  26709. ECharts.prototype.setOption = function (option, notMerge, lazyUpdate) {
  26710. if ("development" !== 'production') {
  26711. assert(!this[IN_MAIN_PROCESS_KEY], '`setOption` should not be called during main process.');
  26712. }
  26713. if (this._disposed) {
  26714. disposedWarning(this.id);
  26715. return;
  26716. }
  26717. var silent;
  26718. var replaceMerge;
  26719. var transitionOpt;
  26720. if (isObject(notMerge)) {
  26721. lazyUpdate = notMerge.lazyUpdate;
  26722. silent = notMerge.silent;
  26723. replaceMerge = notMerge.replaceMerge;
  26724. transitionOpt = notMerge.transition;
  26725. notMerge = notMerge.notMerge;
  26726. }
  26727. this[IN_MAIN_PROCESS_KEY] = true;
  26728. if (!this._model || notMerge) {
  26729. var optionManager = new OptionManager(this._api);
  26730. var theme = this._theme;
  26731. var ecModel = this._model = new GlobalModel();
  26732. ecModel.scheduler = this._scheduler;
  26733. ecModel.init(null, null, null, theme, this._locale, optionManager);
  26734. }
  26735. this._model.setOption(option, {
  26736. replaceMerge: replaceMerge
  26737. }, optionPreprocessorFuncs);
  26738. var updateParams = {
  26739. seriesTransition: transitionOpt,
  26740. optionChanged: true
  26741. };
  26742. if (lazyUpdate) {
  26743. this[PENDING_UPDATE] = {
  26744. silent: silent,
  26745. updateParams: updateParams
  26746. };
  26747. this[IN_MAIN_PROCESS_KEY] = false; // `setOption(option, {lazyMode: true})` may be called when zrender has been slept.
  26748. // It should wake it up to make sure zrender start to render at the next frame.
  26749. this.getZr().wakeUp();
  26750. } else {
  26751. prepare(this);
  26752. updateMethods.update.call(this, null, updateParams); // Ensure zr refresh sychronously, and then pixel in canvas can be
  26753. // fetched after `setOption`.
  26754. this._zr.flush();
  26755. this[PENDING_UPDATE] = null;
  26756. this[IN_MAIN_PROCESS_KEY] = false;
  26757. flushPendingActions.call(this, silent);
  26758. triggerUpdatedEvent.call(this, silent);
  26759. }
  26760. };
  26761. /**
  26762. * @DEPRECATED
  26763. */
  26764. ECharts.prototype.setTheme = function () {
  26765. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  26766. }; // We don't want developers to use getModel directly.
  26767. ECharts.prototype.getModel = function () {
  26768. return this._model;
  26769. };
  26770. ECharts.prototype.getOption = function () {
  26771. return this._model && this._model.getOption();
  26772. };
  26773. ECharts.prototype.getWidth = function () {
  26774. return this._zr.getWidth();
  26775. };
  26776. ECharts.prototype.getHeight = function () {
  26777. return this._zr.getHeight();
  26778. };
  26779. ECharts.prototype.getDevicePixelRatio = function () {
  26780. return this._zr.painter.dpr
  26781. /* eslint-disable-next-line */
  26782. || hasWindow && window.devicePixelRatio || 1;
  26783. };
  26784. /**
  26785. * Get canvas which has all thing rendered
  26786. */
  26787. ECharts.prototype.getRenderedCanvas = function (opts) {
  26788. if (!env.canvasSupported) {
  26789. return;
  26790. }
  26791. opts = opts || {};
  26792. return this._zr.painter.getRenderedCanvas({
  26793. backgroundColor: opts.backgroundColor || this._model.get('backgroundColor'),
  26794. pixelRatio: opts.pixelRatio || this.getDevicePixelRatio()
  26795. });
  26796. };
  26797. /**
  26798. * Get svg data url
  26799. */
  26800. ECharts.prototype.getSvgDataURL = function () {
  26801. if (!env.svgSupported) {
  26802. return;
  26803. }
  26804. var zr = this._zr;
  26805. var list = zr.storage.getDisplayList(); // Stop animations
  26806. each(list, function (el) {
  26807. el.stopAnimation(null, true);
  26808. });
  26809. return zr.painter.toDataURL();
  26810. };
  26811. ECharts.prototype.getDataURL = function (opts) {
  26812. if (this._disposed) {
  26813. disposedWarning(this.id);
  26814. return;
  26815. }
  26816. opts = opts || {};
  26817. var excludeComponents = opts.excludeComponents;
  26818. var ecModel = this._model;
  26819. var excludesComponentViews = [];
  26820. var self = this;
  26821. each(excludeComponents, function (componentType) {
  26822. ecModel.eachComponent({
  26823. mainType: componentType
  26824. }, function (component) {
  26825. var view = self._componentsMap[component.__viewId];
  26826. if (!view.group.ignore) {
  26827. excludesComponentViews.push(view);
  26828. view.group.ignore = true;
  26829. }
  26830. });
  26831. });
  26832. var url = this._zr.painter.getType() === 'svg' ? this.getSvgDataURL() : this.getRenderedCanvas(opts).toDataURL('image/' + (opts && opts.type || 'png'));
  26833. each(excludesComponentViews, function (view) {
  26834. view.group.ignore = false;
  26835. });
  26836. return url;
  26837. };
  26838. ECharts.prototype.getConnectedDataURL = function (opts) {
  26839. if (this._disposed) {
  26840. disposedWarning(this.id);
  26841. return;
  26842. }
  26843. if (!env.canvasSupported) {
  26844. return;
  26845. }
  26846. var isSvg = opts.type === 'svg';
  26847. var groupId = this.group;
  26848. var mathMin = Math.min;
  26849. var mathMax = Math.max;
  26850. var MAX_NUMBER = Infinity;
  26851. if (connectedGroups[groupId]) {
  26852. var left_1 = MAX_NUMBER;
  26853. var top_1 = MAX_NUMBER;
  26854. var right_1 = -MAX_NUMBER;
  26855. var bottom_1 = -MAX_NUMBER;
  26856. var canvasList_1 = [];
  26857. var dpr_1 = opts && opts.pixelRatio || this.getDevicePixelRatio();
  26858. each(instances$1, function (chart, id) {
  26859. if (chart.group === groupId) {
  26860. var canvas = isSvg ? chart.getZr().painter.getSvgDom().innerHTML : chart.getRenderedCanvas(clone(opts));
  26861. var boundingRect = chart.getDom().getBoundingClientRect();
  26862. left_1 = mathMin(boundingRect.left, left_1);
  26863. top_1 = mathMin(boundingRect.top, top_1);
  26864. right_1 = mathMax(boundingRect.right, right_1);
  26865. bottom_1 = mathMax(boundingRect.bottom, bottom_1);
  26866. canvasList_1.push({
  26867. dom: canvas,
  26868. left: boundingRect.left,
  26869. top: boundingRect.top
  26870. });
  26871. }
  26872. });
  26873. left_1 *= dpr_1;
  26874. top_1 *= dpr_1;
  26875. right_1 *= dpr_1;
  26876. bottom_1 *= dpr_1;
  26877. var width = right_1 - left_1;
  26878. var height = bottom_1 - top_1;
  26879. var targetCanvas = createCanvas();
  26880. var zr_1 = init(targetCanvas, {
  26881. renderer: isSvg ? 'svg' : 'canvas'
  26882. });
  26883. zr_1.resize({
  26884. width: width,
  26885. height: height
  26886. });
  26887. if (isSvg) {
  26888. var content_1 = '';
  26889. each(canvasList_1, function (item) {
  26890. var x = item.left - left_1;
  26891. var y = item.top - top_1;
  26892. content_1 += '<g transform="translate(' + x + ',' + y + ')">' + item.dom + '</g>';
  26893. });
  26894. zr_1.painter.getSvgRoot().innerHTML = content_1;
  26895. if (opts.connectedBackgroundColor) {
  26896. zr_1.painter.setBackgroundColor(opts.connectedBackgroundColor);
  26897. }
  26898. zr_1.refreshImmediately();
  26899. return zr_1.painter.toDataURL();
  26900. } else {
  26901. // Background between the charts
  26902. if (opts.connectedBackgroundColor) {
  26903. zr_1.add(new Rect({
  26904. shape: {
  26905. x: 0,
  26906. y: 0,
  26907. width: width,
  26908. height: height
  26909. },
  26910. style: {
  26911. fill: opts.connectedBackgroundColor
  26912. }
  26913. }));
  26914. }
  26915. each(canvasList_1, function (item) {
  26916. var img = new ZRImage({
  26917. style: {
  26918. x: item.left * dpr_1 - left_1,
  26919. y: item.top * dpr_1 - top_1,
  26920. image: item.dom
  26921. }
  26922. });
  26923. zr_1.add(img);
  26924. });
  26925. zr_1.refreshImmediately();
  26926. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  26927. }
  26928. } else {
  26929. return this.getDataURL(opts);
  26930. }
  26931. };
  26932. ECharts.prototype.convertToPixel = function (finder, value) {
  26933. return doConvertPixel(this, 'convertToPixel', finder, value);
  26934. };
  26935. ECharts.prototype.convertFromPixel = function (finder, value) {
  26936. return doConvertPixel(this, 'convertFromPixel', finder, value);
  26937. };
  26938. /**
  26939. * Is the specified coordinate systems or components contain the given pixel point.
  26940. * @param {Array|number} value
  26941. * @return {boolean} result
  26942. */
  26943. ECharts.prototype.containPixel = function (finder, value) {
  26944. if (this._disposed) {
  26945. disposedWarning(this.id);
  26946. return;
  26947. }
  26948. var ecModel = this._model;
  26949. var result;
  26950. var findResult = parseFinder(ecModel, finder);
  26951. each(findResult, function (models, key) {
  26952. key.indexOf('Models') >= 0 && each(models, function (model) {
  26953. var coordSys = model.coordinateSystem;
  26954. if (coordSys && coordSys.containPoint) {
  26955. result = result || !!coordSys.containPoint(value);
  26956. } else if (key === 'seriesModels') {
  26957. var view = this._chartsMap[model.__viewId];
  26958. if (view && view.containPoint) {
  26959. result = result || view.containPoint(value, model);
  26960. } else {
  26961. if ("development" !== 'production') {
  26962. console.warn(key + ': ' + (view ? 'The found component do not support containPoint.' : 'No view mapping to the found component.'));
  26963. }
  26964. }
  26965. } else {
  26966. if ("development" !== 'production') {
  26967. console.warn(key + ': containPoint is not supported');
  26968. }
  26969. }
  26970. }, this);
  26971. }, this);
  26972. return !!result;
  26973. };
  26974. /**
  26975. * Get visual from series or data.
  26976. * @param finder
  26977. * If string, e.g., 'series', means {seriesIndex: 0}.
  26978. * If Object, could contain some of these properties below:
  26979. * {
  26980. * seriesIndex / seriesId / seriesName,
  26981. * dataIndex / dataIndexInside
  26982. * }
  26983. * If dataIndex is not specified, series visual will be fetched,
  26984. * but not data item visual.
  26985. * If all of seriesIndex, seriesId, seriesName are not specified,
  26986. * visual will be fetched from first series.
  26987. * @param visualType 'color', 'symbol', 'symbolSize'
  26988. */
  26989. ECharts.prototype.getVisual = function (finder, visualType) {
  26990. var ecModel = this._model;
  26991. var parsedFinder = parseFinder(ecModel, finder, {
  26992. defaultMainType: 'series'
  26993. });
  26994. var seriesModel = parsedFinder.seriesModel;
  26995. if ("development" !== 'production') {
  26996. if (!seriesModel) {
  26997. console.warn('There is no specified seires model');
  26998. }
  26999. }
  27000. var data = seriesModel.getData();
  27001. var dataIndexInside = parsedFinder.hasOwnProperty('dataIndexInside') ? parsedFinder.dataIndexInside : parsedFinder.hasOwnProperty('dataIndex') ? data.indexOfRawIndex(parsedFinder.dataIndex) : null;
  27002. return dataIndexInside != null ? getItemVisualFromData(data, dataIndexInside, visualType) : getVisualFromData(data, visualType);
  27003. };
  27004. /**
  27005. * Get view of corresponding component model
  27006. */
  27007. ECharts.prototype.getViewOfComponentModel = function (componentModel) {
  27008. return this._componentsMap[componentModel.__viewId];
  27009. };
  27010. /**
  27011. * Get view of corresponding series model
  27012. */
  27013. ECharts.prototype.getViewOfSeriesModel = function (seriesModel) {
  27014. return this._chartsMap[seriesModel.__viewId];
  27015. };
  27016. ECharts.prototype._initEvents = function () {
  27017. var _this = this;
  27018. each(MOUSE_EVENT_NAMES, function (eveName) {
  27019. var handler = function (e) {
  27020. var ecModel = _this.getModel();
  27021. var el = e.target;
  27022. var params;
  27023. var isGlobalOut = eveName === 'globalout'; // no e.target when 'globalout'.
  27024. if (isGlobalOut) {
  27025. params = {};
  27026. } else {
  27027. el && findEventDispatcher(el, function (parent) {
  27028. var ecData = getECData(parent);
  27029. if (ecData && ecData.dataIndex != null) {
  27030. var dataModel = ecData.dataModel || ecModel.getSeriesByIndex(ecData.seriesIndex);
  27031. params = dataModel && dataModel.getDataParams(ecData.dataIndex, ecData.dataType) || {};
  27032. return true;
  27033. } // If element has custom eventData of components
  27034. else if (ecData.eventData) {
  27035. params = extend({}, ecData.eventData);
  27036. return true;
  27037. }
  27038. }, true);
  27039. } // Contract: if params prepared in mouse event,
  27040. // these properties must be specified:
  27041. // {
  27042. // componentType: string (component main type)
  27043. // componentIndex: number
  27044. // }
  27045. // Otherwise event query can not work.
  27046. if (params) {
  27047. var componentType = params.componentType;
  27048. var componentIndex = params.componentIndex; // Special handling for historic reason: when trigger by
  27049. // markLine/markPoint/markArea, the componentType is
  27050. // 'markLine'/'markPoint'/'markArea', but we should better
  27051. // enable them to be queried by seriesIndex, since their
  27052. // option is set in each series.
  27053. if (componentType === 'markLine' || componentType === 'markPoint' || componentType === 'markArea') {
  27054. componentType = 'series';
  27055. componentIndex = params.seriesIndex;
  27056. }
  27057. var model = componentType && componentIndex != null && ecModel.getComponent(componentType, componentIndex);
  27058. var view = model && _this[model.mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId];
  27059. if ("development" !== 'production') {
  27060. // `event.componentType` and `event[componentTpype + 'Index']` must not
  27061. // be missed, otherwise there is no way to distinguish source component.
  27062. // See `dataFormat.getDataParams`.
  27063. if (!isGlobalOut && !(model && view)) {
  27064. console.warn('model or view can not be found by params');
  27065. }
  27066. }
  27067. params.event = e;
  27068. params.type = eveName;
  27069. _this._$eventProcessor.eventInfo = {
  27070. targetEl: el,
  27071. packedEvent: params,
  27072. model: model,
  27073. view: view
  27074. };
  27075. _this.trigger(eveName, params);
  27076. }
  27077. }; // Consider that some component (like tooltip, brush, ...)
  27078. // register zr event handler, but user event handler might
  27079. // do anything, such as call `setOption` or `dispatchAction`,
  27080. // which probably update any of the content and probably
  27081. // cause problem if it is called previous other inner handlers.
  27082. handler.zrEventfulCallAtLast = true;
  27083. _this._zr.on(eveName, handler, _this);
  27084. });
  27085. each(eventActionMap, function (actionType, eventType) {
  27086. _this._messageCenter.on(eventType, function (event) {
  27087. this.trigger(eventType, event);
  27088. }, _this);
  27089. }); // Extra events
  27090. // TODO register?
  27091. each(['selectchanged'], function (eventType) {
  27092. _this._messageCenter.on(eventType, function (event) {
  27093. this.trigger(eventType, event);
  27094. }, _this);
  27095. });
  27096. handleLegacySelectEvents(this._messageCenter, this, this._api);
  27097. };
  27098. ECharts.prototype.isDisposed = function () {
  27099. return this._disposed;
  27100. };
  27101. ECharts.prototype.clear = function () {
  27102. if (this._disposed) {
  27103. disposedWarning(this.id);
  27104. return;
  27105. }
  27106. this.setOption({
  27107. series: []
  27108. }, true);
  27109. };
  27110. ECharts.prototype.dispose = function () {
  27111. if (this._disposed) {
  27112. disposedWarning(this.id);
  27113. return;
  27114. }
  27115. this._disposed = true;
  27116. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  27117. var chart = this;
  27118. var api = chart._api;
  27119. var ecModel = chart._model;
  27120. each(chart._componentsViews, function (component) {
  27121. component.dispose(ecModel, api);
  27122. });
  27123. each(chart._chartsViews, function (chart) {
  27124. chart.dispose(ecModel, api);
  27125. }); // Dispose after all views disposed
  27126. chart._zr.dispose(); // Set properties to null.
  27127. // To reduce the memory cost in case the top code still holds this instance unexpectedly.
  27128. 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;
  27129. delete instances$1[chart.id];
  27130. };
  27131. /**
  27132. * Resize the chart
  27133. */
  27134. ECharts.prototype.resize = function (opts) {
  27135. if ("development" !== 'production') {
  27136. assert(!this[IN_MAIN_PROCESS_KEY], '`resize` should not be called during main process.');
  27137. }
  27138. if (this._disposed) {
  27139. disposedWarning(this.id);
  27140. return;
  27141. }
  27142. this._zr.resize(opts);
  27143. var ecModel = this._model; // Resize loading effect
  27144. this._loadingFX && this._loadingFX.resize();
  27145. if (!ecModel) {
  27146. return;
  27147. }
  27148. var needPrepare = ecModel.resetOption('media');
  27149. var silent = opts && opts.silent; // There is some real cases that:
  27150. // chart.setOption(option, { lazyUpdate: true });
  27151. // chart.resize();
  27152. if (this[PENDING_UPDATE]) {
  27153. if (silent == null) {
  27154. silent = this[PENDING_UPDATE].silent;
  27155. }
  27156. needPrepare = true;
  27157. this[PENDING_UPDATE] = null;
  27158. }
  27159. this[IN_MAIN_PROCESS_KEY] = true;
  27160. needPrepare && prepare(this);
  27161. updateMethods.update.call(this, {
  27162. type: 'resize',
  27163. animation: extend({
  27164. // Disable animation
  27165. duration: 0
  27166. }, opts && opts.animation)
  27167. });
  27168. this[IN_MAIN_PROCESS_KEY] = false;
  27169. flushPendingActions.call(this, silent);
  27170. triggerUpdatedEvent.call(this, silent);
  27171. };
  27172. ECharts.prototype.showLoading = function (name, cfg) {
  27173. if (this._disposed) {
  27174. disposedWarning(this.id);
  27175. return;
  27176. }
  27177. if (isObject(name)) {
  27178. cfg = name;
  27179. name = '';
  27180. }
  27181. name = name || 'default';
  27182. this.hideLoading();
  27183. if (!loadingEffects[name]) {
  27184. if ("development" !== 'production') {
  27185. console.warn('Loading effects ' + name + ' not exists.');
  27186. }
  27187. return;
  27188. }
  27189. var el = loadingEffects[name](this._api, cfg);
  27190. var zr = this._zr;
  27191. this._loadingFX = el;
  27192. zr.add(el);
  27193. };
  27194. /**
  27195. * Hide loading effect
  27196. */
  27197. ECharts.prototype.hideLoading = function () {
  27198. if (this._disposed) {
  27199. disposedWarning(this.id);
  27200. return;
  27201. }
  27202. this._loadingFX && this._zr.remove(this._loadingFX);
  27203. this._loadingFX = null;
  27204. };
  27205. ECharts.prototype.makeActionFromEvent = function (eventObj) {
  27206. var payload = extend({}, eventObj);
  27207. payload.type = eventActionMap[eventObj.type];
  27208. return payload;
  27209. };
  27210. /**
  27211. * @param opt If pass boolean, means opt.silent
  27212. * @param opt.silent Default `false`. Whether trigger events.
  27213. * @param opt.flush Default `undefined`.
  27214. * true: Flush immediately, and then pixel in canvas can be fetched
  27215. * immediately. Caution: it might affect performance.
  27216. * false: Not flush.
  27217. * undefined: Auto decide whether perform flush.
  27218. */
  27219. ECharts.prototype.dispatchAction = function (payload, opt) {
  27220. if (this._disposed) {
  27221. disposedWarning(this.id);
  27222. return;
  27223. }
  27224. if (!isObject(opt)) {
  27225. opt = {
  27226. silent: !!opt
  27227. };
  27228. }
  27229. if (!actions[payload.type]) {
  27230. return;
  27231. } // Avoid dispatch action before setOption. Especially in `connect`.
  27232. if (!this._model) {
  27233. return;
  27234. } // May dispatchAction in rendering procedure
  27235. if (this[IN_MAIN_PROCESS_KEY]) {
  27236. this._pendingActions.push(payload);
  27237. return;
  27238. }
  27239. var silent = opt.silent;
  27240. doDispatchAction.call(this, payload, silent);
  27241. var flush = opt.flush;
  27242. if (flush) {
  27243. this._zr.flush();
  27244. } else if (flush !== false && env.browser.weChat) {
  27245. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  27246. // hang when sliding page (on touch event), which cause that zr does not
  27247. // refresh util user interaction finished, which is not expected.
  27248. // But `dispatchAction` may be called too frequently when pan on touch
  27249. // screen, which impacts performance if do not throttle them.
  27250. this._throttledZrFlush();
  27251. }
  27252. flushPendingActions.call(this, silent);
  27253. triggerUpdatedEvent.call(this, silent);
  27254. };
  27255. ECharts.prototype.updateLabelLayout = function () {
  27256. lifecycle.trigger('series:layoutlabels', this._model, this._api, {
  27257. // Not adding series labels.
  27258. // TODO
  27259. updatedSeries: []
  27260. });
  27261. };
  27262. ECharts.prototype.appendData = function (params) {
  27263. if (this._disposed) {
  27264. disposedWarning(this.id);
  27265. return;
  27266. }
  27267. var seriesIndex = params.seriesIndex;
  27268. var ecModel = this.getModel();
  27269. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  27270. if ("development" !== 'production') {
  27271. assert(params.data && seriesModel);
  27272. }
  27273. seriesModel.appendData(params); // Note: `appendData` does not support that update extent of coordinate
  27274. // system, util some scenario require that. In the expected usage of
  27275. // `appendData`, the initial extent of coordinate system should better
  27276. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  27277. // the extent changed while `appendData`, the location of the painted
  27278. // graphic elements have to be changed, which make the usage of
  27279. // `appendData` meaningless.
  27280. this._scheduler.unfinished = true;
  27281. this.getZr().wakeUp();
  27282. }; // A work around for no `internal` modifier in ts yet but
  27283. // need to strictly hide private methods to JS users.
  27284. ECharts.internalField = function () {
  27285. prepare = function (ecIns) {
  27286. var scheduler = ecIns._scheduler;
  27287. scheduler.restorePipelines(ecIns._model);
  27288. scheduler.prepareStageTasks();
  27289. prepareView(ecIns, true);
  27290. prepareView(ecIns, false);
  27291. scheduler.plan();
  27292. };
  27293. /**
  27294. * Prepare view instances of charts and components
  27295. */
  27296. prepareView = function (ecIns, isComponent) {
  27297. var ecModel = ecIns._model;
  27298. var scheduler = ecIns._scheduler;
  27299. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  27300. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  27301. var zr = ecIns._zr;
  27302. var api = ecIns._api;
  27303. for (var i = 0; i < viewList.length; i++) {
  27304. viewList[i].__alive = false;
  27305. }
  27306. isComponent ? ecModel.eachComponent(function (componentType, model) {
  27307. componentType !== 'series' && doPrepare(model);
  27308. }) : ecModel.eachSeries(doPrepare);
  27309. function doPrepare(model) {
  27310. // By defaut view will be reused if possible for the case that `setOption` with "notMerge"
  27311. // mode and need to enable transition animation. (Usually, when they have the same id, or
  27312. // especially no id but have the same type & name & index. See the `model.id` generation
  27313. // rule in `makeIdAndName` and `viewId` generation rule here).
  27314. // But in `replaceMerge` mode, this feature should be able to disabled when it is clear that
  27315. // the new model has nothing to do with the old model.
  27316. var requireNewView = model.__requireNewView; // This command should not work twice.
  27317. model.__requireNewView = false; // Consider: id same and type changed.
  27318. var viewId = '_ec_' + model.id + '_' + model.type;
  27319. var view = !requireNewView && viewMap[viewId];
  27320. if (!view) {
  27321. var classType = parseClassType(model.type);
  27322. var Clazz = isComponent ? ComponentView.getClass(classType.main, classType.sub) : // FIXME:TS
  27323. // (ChartView as ChartViewConstructor).getClass('series', classType.sub)
  27324. // For backward compat, still support a chart type declared as only subType
  27325. // like "liquidfill", but recommend "series.liquidfill"
  27326. // But need a base class to make a type series.
  27327. ChartView.getClass(classType.sub);
  27328. if ("development" !== 'production') {
  27329. assert(Clazz, classType.sub + ' does not exist.');
  27330. }
  27331. view = new Clazz();
  27332. view.init(ecModel, api);
  27333. viewMap[viewId] = view;
  27334. viewList.push(view);
  27335. zr.add(view.group);
  27336. }
  27337. model.__viewId = view.__id = viewId;
  27338. view.__alive = true;
  27339. view.__model = model;
  27340. view.group.__ecComponentInfo = {
  27341. mainType: model.mainType,
  27342. index: model.componentIndex
  27343. };
  27344. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  27345. }
  27346. for (var i = 0; i < viewList.length;) {
  27347. var view = viewList[i];
  27348. if (!view.__alive) {
  27349. !isComponent && view.renderTask.dispose();
  27350. zr.remove(view.group);
  27351. view.dispose(ecModel, api);
  27352. viewList.splice(i, 1);
  27353. if (viewMap[view.__id] === view) {
  27354. delete viewMap[view.__id];
  27355. }
  27356. view.__id = view.group.__ecComponentInfo = null;
  27357. } else {
  27358. i++;
  27359. }
  27360. }
  27361. };
  27362. updateDirectly = function (ecIns, method, payload, mainType, subType) {
  27363. var ecModel = ecIns._model;
  27364. ecModel.setUpdatePayload(payload); // broadcast
  27365. if (!mainType) {
  27366. // FIXME
  27367. // Chart will not be update directly here, except set dirty.
  27368. // But there is no such scenario now.
  27369. each([].concat(ecIns._componentsViews).concat(ecIns._chartsViews), callView);
  27370. return;
  27371. }
  27372. var query = {};
  27373. query[mainType + 'Id'] = payload[mainType + 'Id'];
  27374. query[mainType + 'Index'] = payload[mainType + 'Index'];
  27375. query[mainType + 'Name'] = payload[mainType + 'Name'];
  27376. var condition = {
  27377. mainType: mainType,
  27378. query: query
  27379. };
  27380. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  27381. var excludeSeriesId = payload.excludeSeriesId;
  27382. var excludeSeriesIdMap;
  27383. if (excludeSeriesId != null) {
  27384. excludeSeriesIdMap = createHashMap();
  27385. each(normalizeToArray(excludeSeriesId), function (id) {
  27386. var modelId = convertOptionIdName(id, null);
  27387. if (modelId != null) {
  27388. excludeSeriesIdMap.set(modelId, true);
  27389. }
  27390. });
  27391. }
  27392. if (isHighDownPayload(payload)) {
  27393. allLeaveBlur(ecIns._api);
  27394. } // If dispatchAction before setOption, do nothing.
  27395. ecModel && ecModel.eachComponent(condition, function (model) {
  27396. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) !== null;
  27397. if (isExcluded) {
  27398. return;
  27399. }
  27400. if (isHighDownPayload(payload)) {
  27401. if (model instanceof SeriesModel) {
  27402. if (payload.type === HIGHLIGHT_ACTION_TYPE && !payload.notBlur) {
  27403. blurSeriesFromHighlightPayload(model, payload, ecIns._api);
  27404. }
  27405. } else {
  27406. var _a = findComponentHighDownDispatchers(model.mainType, model.componentIndex, payload.name, ecIns._api),
  27407. focusSelf = _a.focusSelf,
  27408. dispatchers = _a.dispatchers;
  27409. if (payload.type === HIGHLIGHT_ACTION_TYPE && focusSelf && !payload.notBlur) {
  27410. blurComponent(model.mainType, model.componentIndex, ecIns._api);
  27411. } // PENDING:
  27412. // Whether to put this "enter emphasis" code in `ComponentView`,
  27413. // which will be the same as `ChartView` but might be not necessary
  27414. // and will be far from this logic.
  27415. if (dispatchers) {
  27416. each(dispatchers, function (dispatcher) {
  27417. payload.type === HIGHLIGHT_ACTION_TYPE ? enterEmphasis(dispatcher) : leaveEmphasis(dispatcher);
  27418. });
  27419. }
  27420. }
  27421. } else if (isSelectChangePayload(payload)) {
  27422. // TODO geo
  27423. if (model instanceof SeriesModel) {
  27424. toggleSelectionFromPayload(model, payload, ecIns._api);
  27425. updateSeriesElementSelection(model);
  27426. markStatusToUpdate(ecIns);
  27427. }
  27428. }
  27429. }, ecIns);
  27430. ecModel && ecModel.eachComponent(condition, function (model) {
  27431. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) !== null;
  27432. if (isExcluded) {
  27433. return;
  27434. }
  27435. callView(ecIns[mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId]);
  27436. }, ecIns);
  27437. function callView(view) {
  27438. view && view.__alive && view[method] && view[method](view.__model, ecModel, ecIns._api, payload);
  27439. }
  27440. };
  27441. updateMethods = {
  27442. prepareAndUpdate: function (payload) {
  27443. prepare(this);
  27444. updateMethods.update.call(this, payload, {
  27445. // Needs to mark option changed if newOption is given.
  27446. // It's from MagicType.
  27447. // TODO If use a separate flag optionChanged in payload?
  27448. optionChanged: payload.newOption != null
  27449. });
  27450. },
  27451. update: function (payload, updateParams) {
  27452. var ecModel = this._model;
  27453. var api = this._api;
  27454. var zr = this._zr;
  27455. var coordSysMgr = this._coordSysMgr;
  27456. var scheduler = this._scheduler; // update before setOption
  27457. if (!ecModel) {
  27458. return;
  27459. }
  27460. ecModel.setUpdatePayload(payload);
  27461. scheduler.restoreData(ecModel, payload);
  27462. scheduler.performSeriesTasks(ecModel); // TODO
  27463. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  27464. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  27465. // Create new coordinate system each update
  27466. // In LineView may save the old coordinate system and use it to get the orignal point
  27467. coordSysMgr.create(ecModel, api);
  27468. scheduler.performDataProcessorTasks(ecModel, payload); // Current stream render is not supported in data process. So we can update
  27469. // stream modes after data processing, where the filtered data is used to
  27470. // deteming whether use progressive rendering.
  27471. updateStreamModes(this, ecModel); // We update stream modes before coordinate system updated, then the modes info
  27472. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  27473. // the drawback is the full coord info can not be fetched. Fortunately this full
  27474. // coord is not requied in stream mode updater currently.
  27475. coordSysMgr.update(ecModel, api);
  27476. clearColorPalette(ecModel);
  27477. scheduler.performVisualTasks(ecModel, payload);
  27478. render(this, ecModel, api, payload, updateParams); // Set background
  27479. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  27480. var darkMode = ecModel.get('darkMode'); // In IE8
  27481. if (!env.canvasSupported) {
  27482. var colorArr = parse(backgroundColor);
  27483. backgroundColor = stringify(colorArr, 'rgb');
  27484. if (colorArr[3] === 0) {
  27485. backgroundColor = 'transparent';
  27486. }
  27487. } else {
  27488. zr.setBackgroundColor(backgroundColor); // Force set dark mode.
  27489. if (darkMode != null && darkMode !== 'auto') {
  27490. zr.setDarkMode(darkMode);
  27491. }
  27492. }
  27493. lifecycle.trigger('afterupdate', ecModel, api);
  27494. },
  27495. updateTransform: function (payload) {
  27496. var _this = this;
  27497. var ecModel = this._model;
  27498. var api = this._api; // update before setOption
  27499. if (!ecModel) {
  27500. return;
  27501. }
  27502. ecModel.setUpdatePayload(payload); // ChartView.markUpdateMethod(payload, 'updateTransform');
  27503. var componentDirtyList = [];
  27504. ecModel.eachComponent(function (componentType, componentModel) {
  27505. if (componentType === 'series') {
  27506. return;
  27507. }
  27508. var componentView = _this.getViewOfComponentModel(componentModel);
  27509. if (componentView && componentView.__alive) {
  27510. if (componentView.updateTransform) {
  27511. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  27512. result && result.update && componentDirtyList.push(componentView);
  27513. } else {
  27514. componentDirtyList.push(componentView);
  27515. }
  27516. }
  27517. });
  27518. var seriesDirtyMap = createHashMap();
  27519. ecModel.eachSeries(function (seriesModel) {
  27520. var chartView = _this._chartsMap[seriesModel.__viewId];
  27521. if (chartView.updateTransform) {
  27522. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  27523. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  27524. } else {
  27525. seriesDirtyMap.set(seriesModel.uid, 1);
  27526. }
  27527. });
  27528. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27529. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  27530. this._scheduler.performVisualTasks(ecModel, payload, {
  27531. setDirty: true,
  27532. dirtyMap: seriesDirtyMap
  27533. }); // Currently, not call render of components. Geo render cost a lot.
  27534. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  27535. renderSeries(this, ecModel, api, payload, {}, seriesDirtyMap);
  27536. lifecycle.trigger('afterupdate', ecModel, api);
  27537. },
  27538. updateView: function (payload) {
  27539. var ecModel = this._model; // update before setOption
  27540. if (!ecModel) {
  27541. return;
  27542. }
  27543. ecModel.setUpdatePayload(payload);
  27544. ChartView.markUpdateMethod(payload, 'updateView');
  27545. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27546. this._scheduler.performVisualTasks(ecModel, payload, {
  27547. setDirty: true
  27548. });
  27549. render(this, ecModel, this._api, payload, {});
  27550. lifecycle.trigger('afterupdate', ecModel, this._api);
  27551. },
  27552. updateVisual: function (payload) {
  27553. // updateMethods.update.call(this, payload);
  27554. var _this = this;
  27555. var ecModel = this._model; // update before setOption
  27556. if (!ecModel) {
  27557. return;
  27558. }
  27559. ecModel.setUpdatePayload(payload); // clear all visual
  27560. ecModel.eachSeries(function (seriesModel) {
  27561. seriesModel.getData().clearAllVisual();
  27562. }); // Perform visual
  27563. ChartView.markUpdateMethod(payload, 'updateVisual');
  27564. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  27565. this._scheduler.performVisualTasks(ecModel, payload, {
  27566. visualType: 'visual',
  27567. setDirty: true
  27568. });
  27569. ecModel.eachComponent(function (componentType, componentModel) {
  27570. if (componentType !== 'series') {
  27571. var componentView = _this.getViewOfComponentModel(componentModel);
  27572. componentView && componentView.__alive && componentView.updateVisual(componentModel, ecModel, _this._api, payload);
  27573. }
  27574. });
  27575. ecModel.eachSeries(function (seriesModel) {
  27576. var chartView = _this._chartsMap[seriesModel.__viewId];
  27577. chartView.updateVisual(seriesModel, ecModel, _this._api, payload);
  27578. });
  27579. lifecycle.trigger('afterupdate', ecModel, this._api);
  27580. },
  27581. updateLayout: function (payload) {
  27582. updateMethods.update.call(this, payload);
  27583. }
  27584. };
  27585. doConvertPixel = function (ecIns, methodName, finder, value) {
  27586. if (ecIns._disposed) {
  27587. disposedWarning(ecIns.id);
  27588. return;
  27589. }
  27590. var ecModel = ecIns._model;
  27591. var coordSysList = ecIns._coordSysMgr.getCoordinateSystems();
  27592. var result;
  27593. var parsedFinder = parseFinder(ecModel, finder);
  27594. for (var i = 0; i < coordSysList.length; i++) {
  27595. var coordSys = coordSysList[i];
  27596. if (coordSys[methodName] && (result = coordSys[methodName](ecModel, parsedFinder, value)) != null) {
  27597. return result;
  27598. }
  27599. }
  27600. if ("development" !== 'production') {
  27601. console.warn('No coordinate system that supports ' + methodName + ' found by the given finder.');
  27602. }
  27603. };
  27604. updateStreamModes = function (ecIns, ecModel) {
  27605. var chartsMap = ecIns._chartsMap;
  27606. var scheduler = ecIns._scheduler;
  27607. ecModel.eachSeries(function (seriesModel) {
  27608. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  27609. });
  27610. };
  27611. doDispatchAction = function (payload, silent) {
  27612. var _this = this;
  27613. var ecModel = this.getModel();
  27614. var payloadType = payload.type;
  27615. var escapeConnect = payload.escapeConnect;
  27616. var actionWrap = actions[payloadType];
  27617. var actionInfo = actionWrap.actionInfo;
  27618. var cptTypeTmp = (actionInfo.update || 'update').split(':');
  27619. var updateMethod = cptTypeTmp.pop();
  27620. var cptType = cptTypeTmp[0] != null && parseClassType(cptTypeTmp[0]);
  27621. this[IN_MAIN_PROCESS_KEY] = true;
  27622. var payloads = [payload];
  27623. var batched = false; // Batch action
  27624. if (payload.batch) {
  27625. batched = true;
  27626. payloads = map(payload.batch, function (item) {
  27627. item = defaults(extend({}, item), payload);
  27628. item.batch = null;
  27629. return item;
  27630. });
  27631. }
  27632. var eventObjBatch = [];
  27633. var eventObj;
  27634. var isSelectChange = isSelectChangePayload(payload);
  27635. var isHighDown = isHighDownPayload(payload);
  27636. each(payloads, function (batchItem) {
  27637. // Action can specify the event by return it.
  27638. eventObj = actionWrap.action(batchItem, _this._model, _this._api); // Emit event outside
  27639. eventObj = eventObj || extend({}, batchItem); // Convert type to eventType
  27640. eventObj.type = actionInfo.event || eventObj.type;
  27641. eventObjBatch.push(eventObj); // light update does not perform data process, layout and visual.
  27642. if (isHighDown) {
  27643. var _a = preParseFinder(payload),
  27644. queryOptionMap = _a.queryOptionMap,
  27645. mainTypeSpecified = _a.mainTypeSpecified;
  27646. var componentMainType = mainTypeSpecified ? queryOptionMap.keys()[0] : 'series';
  27647. updateDirectly(_this, updateMethod, batchItem, componentMainType);
  27648. markStatusToUpdate(_this);
  27649. } else if (isSelectChange) {
  27650. // At present `dispatchAction({ type: 'select', ... })` is not supported on components.
  27651. // geo still use 'geoselect'.
  27652. updateDirectly(_this, updateMethod, batchItem, 'series');
  27653. markStatusToUpdate(_this);
  27654. } else if (cptType) {
  27655. updateDirectly(_this, updateMethod, batchItem, cptType.main, cptType.sub);
  27656. }
  27657. });
  27658. if (updateMethod !== 'none' && !isHighDown && !isSelectChange && !cptType) {
  27659. // Still dirty
  27660. if (this[PENDING_UPDATE]) {
  27661. prepare(this);
  27662. updateMethods.update.call(this, payload);
  27663. this[PENDING_UPDATE] = null;
  27664. } else {
  27665. updateMethods[updateMethod].call(this, payload);
  27666. }
  27667. } // Follow the rule of action batch
  27668. if (batched) {
  27669. eventObj = {
  27670. type: actionInfo.event || payloadType,
  27671. escapeConnect: escapeConnect,
  27672. batch: eventObjBatch
  27673. };
  27674. } else {
  27675. eventObj = eventObjBatch[0];
  27676. }
  27677. this[IN_MAIN_PROCESS_KEY] = false;
  27678. if (!silent) {
  27679. var messageCenter = this._messageCenter;
  27680. messageCenter.trigger(eventObj.type, eventObj); // Extra triggered 'selectchanged' event
  27681. if (isSelectChange) {
  27682. var newObj = {
  27683. type: 'selectchanged',
  27684. escapeConnect: escapeConnect,
  27685. selected: getAllSelectedIndices(ecModel),
  27686. isFromClick: payload.isFromClick || false,
  27687. fromAction: payload.type,
  27688. fromActionPayload: payload
  27689. };
  27690. messageCenter.trigger(newObj.type, newObj);
  27691. }
  27692. }
  27693. };
  27694. flushPendingActions = function (silent) {
  27695. var pendingActions = this._pendingActions;
  27696. while (pendingActions.length) {
  27697. var payload = pendingActions.shift();
  27698. doDispatchAction.call(this, payload, silent);
  27699. }
  27700. };
  27701. triggerUpdatedEvent = function (silent) {
  27702. !silent && this.trigger('updated');
  27703. };
  27704. /**
  27705. * Event `rendered` is triggered when zr
  27706. * rendered. It is useful for realtime
  27707. * snapshot (reflect animation).
  27708. *
  27709. * Event `finished` is triggered when:
  27710. * (1) zrender rendering finished.
  27711. * (2) initial animation finished.
  27712. * (3) progressive rendering finished.
  27713. * (4) no pending action.
  27714. * (5) no delayed setOption needs to be processed.
  27715. */
  27716. bindRenderedEvent = function (zr, ecIns) {
  27717. zr.on('rendered', function (params) {
  27718. ecIns.trigger('rendered', params); // The `finished` event should not be triggered repeatly,
  27719. // so it should only be triggered when rendering indeed happend
  27720. // in zrender. (Consider the case that dipatchAction is keep
  27721. // triggering when mouse move).
  27722. if ( // Although zr is dirty if initial animation is not finished
  27723. // and this checking is called on frame, we also check
  27724. // animation finished for robustness.
  27725. zr.animation.isFinished() && !ecIns[PENDING_UPDATE] && !ecIns._scheduler.unfinished && !ecIns._pendingActions.length) {
  27726. ecIns.trigger('finished');
  27727. }
  27728. });
  27729. };
  27730. bindMouseEvent = function (zr, ecIns) {
  27731. zr.on('mouseover', function (e) {
  27732. var el = e.target;
  27733. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  27734. if (dispatcher) {
  27735. handleGlobalMouseOverForHighDown(dispatcher, e, ecIns._api);
  27736. markStatusToUpdate(ecIns);
  27737. }
  27738. }).on('mouseout', function (e) {
  27739. var el = e.target;
  27740. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  27741. if (dispatcher) {
  27742. handleGlboalMouseOutForHighDown(dispatcher, e, ecIns._api);
  27743. markStatusToUpdate(ecIns);
  27744. }
  27745. }).on('click', function (e) {
  27746. var el = e.target;
  27747. var dispatcher = findEventDispatcher(el, function (target) {
  27748. return getECData(target).dataIndex != null;
  27749. }, true);
  27750. if (dispatcher) {
  27751. var actionType = dispatcher.selected ? 'unselect' : 'select';
  27752. var ecData = getECData(dispatcher);
  27753. ecIns._api.dispatchAction({
  27754. type: actionType,
  27755. dataType: ecData.dataType,
  27756. dataIndexInside: ecData.dataIndex,
  27757. seriesIndex: ecData.seriesIndex,
  27758. isFromClick: true
  27759. });
  27760. }
  27761. });
  27762. };
  27763. clearColorPalette = function (ecModel) {
  27764. ecModel.clearColorPalette();
  27765. ecModel.eachSeries(function (seriesModel) {
  27766. seriesModel.clearColorPalette();
  27767. });
  27768. };
  27769. render = function (ecIns, ecModel, api, payload, updateParams) {
  27770. renderComponents(ecIns, ecModel, api, payload, updateParams);
  27771. each(ecIns._chartsViews, function (chart) {
  27772. chart.__alive = false;
  27773. });
  27774. renderSeries(ecIns, ecModel, api, payload, updateParams); // Remove groups of unrendered charts
  27775. each(ecIns._chartsViews, function (chart) {
  27776. if (!chart.__alive) {
  27777. chart.remove(ecModel, api);
  27778. }
  27779. });
  27780. };
  27781. renderComponents = function (ecIns, ecModel, api, payload, updateParams, dirtyList) {
  27782. each(dirtyList || ecIns._componentsViews, function (componentView) {
  27783. var componentModel = componentView.__model;
  27784. clearStates(componentModel, componentView);
  27785. componentView.render(componentModel, ecModel, api, payload);
  27786. updateZ(componentModel, componentView);
  27787. updateStates(componentModel, componentView);
  27788. });
  27789. };
  27790. /**
  27791. * Render each chart and component
  27792. */
  27793. renderSeries = function (ecIns, ecModel, api, payload, updateParams, dirtyMap) {
  27794. // Render all charts
  27795. var scheduler = ecIns._scheduler;
  27796. updateParams = extend(updateParams || {}, {
  27797. updatedSeries: ecModel.getSeries()
  27798. }); // TODO progressive?
  27799. lifecycle.trigger('series:beforeupdate', ecModel, api, updateParams);
  27800. var unfinished = false;
  27801. ecModel.eachSeries(function (seriesModel) {
  27802. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  27803. chartView.__alive = true;
  27804. var renderTask = chartView.renderTask;
  27805. scheduler.updatePayload(renderTask, payload); // TODO states on marker.
  27806. clearStates(seriesModel, chartView);
  27807. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  27808. renderTask.dirty();
  27809. }
  27810. if (renderTask.perform(scheduler.getPerformArgs(renderTask))) {
  27811. unfinished = true;
  27812. }
  27813. chartView.group.silent = !!seriesModel.get('silent'); // Should not call markRedraw on group, because it will disable zrender
  27814. // increamental render (alway render from the __startIndex each frame)
  27815. // chartView.group.markRedraw();
  27816. updateBlend(seriesModel, chartView);
  27817. updateSeriesElementSelection(seriesModel);
  27818. });
  27819. scheduler.unfinished = unfinished || scheduler.unfinished;
  27820. lifecycle.trigger('series:layoutlabels', ecModel, api, updateParams); // transition after label is layouted.
  27821. lifecycle.trigger('series:transition', ecModel, api, updateParams);
  27822. ecModel.eachSeries(function (seriesModel) {
  27823. var chartView = ecIns._chartsMap[seriesModel.__viewId]; // Update Z after labels updated. Before applying states.
  27824. updateZ(seriesModel, chartView); // NOTE: Update states after label is updated.
  27825. // label should be in normal status when layouting.
  27826. updateStates(seriesModel, chartView);
  27827. }); // If use hover layer
  27828. updateHoverLayerStatus(ecIns, ecModel);
  27829. lifecycle.trigger('series:afterupdate', ecModel, api, updateParams);
  27830. };
  27831. markStatusToUpdate = function (ecIns) {
  27832. ecIns[STATUS_NEEDS_UPDATE_KEY] = true; // Wake up zrender if it's sleep. Let it update states in the next frame.
  27833. ecIns.getZr().wakeUp();
  27834. };
  27835. applyChangedStates = function (ecIns) {
  27836. if (!ecIns[STATUS_NEEDS_UPDATE_KEY]) {
  27837. return;
  27838. }
  27839. ecIns.getZr().storage.traverse(function (el) {
  27840. // Not applied on removed elements, it may still in fading.
  27841. if (isElementRemoved(el)) {
  27842. return;
  27843. }
  27844. applyElementStates(el);
  27845. });
  27846. ecIns[STATUS_NEEDS_UPDATE_KEY] = false;
  27847. };
  27848. function applyElementStates(el) {
  27849. var newStates = [];
  27850. var oldStates = el.currentStates; // Keep other states.
  27851. for (var i = 0; i < oldStates.length; i++) {
  27852. var stateName = oldStates[i];
  27853. if (!(stateName === 'emphasis' || stateName === 'blur' || stateName === 'select')) {
  27854. newStates.push(stateName);
  27855. }
  27856. } // Only use states when it's exists.
  27857. if (el.selected && el.states.select) {
  27858. newStates.push('select');
  27859. }
  27860. if (el.hoverState === HOVER_STATE_EMPHASIS && el.states.emphasis) {
  27861. newStates.push('emphasis');
  27862. } else if (el.hoverState === HOVER_STATE_BLUR && el.states.blur) {
  27863. newStates.push('blur');
  27864. }
  27865. el.useStates(newStates);
  27866. }
  27867. function updateHoverLayerStatus(ecIns, ecModel) {
  27868. var zr = ecIns._zr;
  27869. var storage = zr.storage;
  27870. var elCount = 0;
  27871. storage.traverse(function (el) {
  27872. if (!el.isGroup) {
  27873. elCount++;
  27874. }
  27875. });
  27876. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node && !env.worker) {
  27877. ecModel.eachSeries(function (seriesModel) {
  27878. if (seriesModel.preventUsingHoverLayer) {
  27879. return;
  27880. }
  27881. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  27882. if (chartView.__alive) {
  27883. chartView.group.traverse(function (el) {
  27884. if (el.states.emphasis) {
  27885. el.states.emphasis.hoverLayer = true;
  27886. }
  27887. });
  27888. }
  27889. });
  27890. }
  27891. }
  27892. /**
  27893. * Update chart and blend.
  27894. */
  27895. function updateBlend(seriesModel, chartView) {
  27896. var blendMode = seriesModel.get('blendMode') || null;
  27897. if ("development" !== 'production') {
  27898. if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
  27899. console.warn('Only canvas support blendMode');
  27900. }
  27901. }
  27902. chartView.group.traverse(function (el) {
  27903. // FIXME marker and other components
  27904. if (!el.isGroup) {
  27905. // DONT mark the element dirty. In case element is incremental and don't wan't to rerender.
  27906. el.style.blend = blendMode;
  27907. }
  27908. if (el.eachPendingDisplayable) {
  27909. el.eachPendingDisplayable(function (displayable) {
  27910. displayable.style.blend = blendMode;
  27911. });
  27912. }
  27913. });
  27914. }
  27915. function updateZ(model, view) {
  27916. if (model.preventAutoZ) {
  27917. return;
  27918. } // Set z and zlevel
  27919. _updateZ(view.group, model.get('z') || 0, model.get('zlevel') || 0, -Infinity);
  27920. }
  27921. function _updateZ(el, z, zlevel, maxZ2) {
  27922. // Group may also have textContent
  27923. var label = el.getTextContent();
  27924. var labelLine = el.getTextGuideLine();
  27925. var isGroup = el.isGroup;
  27926. if (isGroup) {
  27927. // set z & zlevel of children elements of Group
  27928. // el.traverse((childEl: Element) => _updateZ(childEl, z, zlevel));
  27929. var children = el.childrenRef();
  27930. for (var i = 0; i < children.length; i++) {
  27931. maxZ2 = Math.max(_updateZ(children[i], z, zlevel, maxZ2), maxZ2);
  27932. }
  27933. } else {
  27934. // not Group
  27935. el.z = z;
  27936. el.zlevel = zlevel;
  27937. maxZ2 = Math.max(el.z2, maxZ2);
  27938. } // always set z and zlevel if label/labelLine exists
  27939. if (label) {
  27940. label.z = z;
  27941. label.zlevel = zlevel; // lift z2 of text content
  27942. // TODO if el.emphasis.z2 is spcefied, what about textContent.
  27943. isFinite(maxZ2) && (label.z2 = maxZ2 + 2);
  27944. }
  27945. if (labelLine) {
  27946. var textGuideLineConfig = el.textGuideLineConfig;
  27947. labelLine.z = z;
  27948. labelLine.zlevel = zlevel;
  27949. isFinite(maxZ2) && (labelLine.z2 = maxZ2 + (textGuideLineConfig && textGuideLineConfig.showAbove ? 1 : -1));
  27950. }
  27951. return maxZ2;
  27952. } // Clear states without animation.
  27953. // TODO States on component.
  27954. function clearStates(model, view) {
  27955. view.group.traverse(function (el) {
  27956. // Not applied on removed elements, it may still in fading.
  27957. if (isElementRemoved(el)) {
  27958. return;
  27959. }
  27960. var textContent = el.getTextContent();
  27961. var textGuide = el.getTextGuideLine();
  27962. if (el.stateTransition) {
  27963. el.stateTransition = null;
  27964. }
  27965. if (textContent && textContent.stateTransition) {
  27966. textContent.stateTransition = null;
  27967. }
  27968. if (textGuide && textGuide.stateTransition) {
  27969. textGuide.stateTransition = null;
  27970. } // TODO If el is incremental.
  27971. if (el.hasState()) {
  27972. el.prevStates = el.currentStates;
  27973. el.clearStates();
  27974. } else if (el.prevStates) {
  27975. el.prevStates = null;
  27976. }
  27977. });
  27978. }
  27979. function updateStates(model, view) {
  27980. var stateAnimationModel = model.getModel('stateAnimation');
  27981. var enableAnimation = model.isAnimationEnabled();
  27982. var duration = stateAnimationModel.get('duration');
  27983. var stateTransition = duration > 0 ? {
  27984. duration: duration,
  27985. delay: stateAnimationModel.get('delay'),
  27986. easing: stateAnimationModel.get('easing') // additive: stateAnimationModel.get('additive')
  27987. } : null;
  27988. view.group.traverse(function (el) {
  27989. if (el.states && el.states.emphasis) {
  27990. // Not applied on removed elements, it may still in fading.
  27991. if (isElementRemoved(el)) {
  27992. return;
  27993. }
  27994. if (el instanceof Path) {
  27995. savePathStates(el);
  27996. } // Only updated on changed element. In case element is incremental and don't wan't to rerender.
  27997. // TODO, a more proper way?
  27998. if (el.__dirty) {
  27999. var prevStates = el.prevStates; // Restore states without animation
  28000. if (prevStates) {
  28001. el.useStates(prevStates);
  28002. }
  28003. } // Update state transition and enable animation again.
  28004. if (enableAnimation) {
  28005. el.stateTransition = stateTransition;
  28006. var textContent = el.getTextContent();
  28007. var textGuide = el.getTextGuideLine(); // TODO Is it necessary to animate label?
  28008. if (textContent) {
  28009. textContent.stateTransition = stateTransition;
  28010. }
  28011. if (textGuide) {
  28012. textGuide.stateTransition = stateTransition;
  28013. }
  28014. } // The use higlighted and selected flag to toggle states.
  28015. if (el.__dirty) {
  28016. applyElementStates(el);
  28017. }
  28018. }
  28019. });
  28020. }
  28021. createExtensionAPI = function (ecIns) {
  28022. return new (
  28023. /** @class */
  28024. function (_super) {
  28025. __extends(class_1, _super);
  28026. function class_1() {
  28027. return _super !== null && _super.apply(this, arguments) || this;
  28028. }
  28029. class_1.prototype.getCoordinateSystems = function () {
  28030. return ecIns._coordSysMgr.getCoordinateSystems();
  28031. };
  28032. class_1.prototype.getComponentByElement = function (el) {
  28033. while (el) {
  28034. var modelInfo = el.__ecComponentInfo;
  28035. if (modelInfo != null) {
  28036. return ecIns._model.getComponent(modelInfo.mainType, modelInfo.index);
  28037. }
  28038. el = el.parent;
  28039. }
  28040. };
  28041. class_1.prototype.enterEmphasis = function (el, highlightDigit) {
  28042. enterEmphasis(el, highlightDigit);
  28043. markStatusToUpdate(ecIns);
  28044. };
  28045. class_1.prototype.leaveEmphasis = function (el, highlightDigit) {
  28046. leaveEmphasis(el, highlightDigit);
  28047. markStatusToUpdate(ecIns);
  28048. };
  28049. class_1.prototype.enterBlur = function (el) {
  28050. enterBlur(el);
  28051. markStatusToUpdate(ecIns);
  28052. };
  28053. class_1.prototype.leaveBlur = function (el) {
  28054. leaveBlur(el);
  28055. markStatusToUpdate(ecIns);
  28056. };
  28057. class_1.prototype.enterSelect = function (el) {
  28058. enterSelect(el);
  28059. markStatusToUpdate(ecIns);
  28060. };
  28061. class_1.prototype.leaveSelect = function (el) {
  28062. leaveSelect(el);
  28063. markStatusToUpdate(ecIns);
  28064. };
  28065. class_1.prototype.getModel = function () {
  28066. return ecIns.getModel();
  28067. };
  28068. class_1.prototype.getViewOfComponentModel = function (componentModel) {
  28069. return ecIns.getViewOfComponentModel(componentModel);
  28070. };
  28071. class_1.prototype.getViewOfSeriesModel = function (seriesModel) {
  28072. return ecIns.getViewOfSeriesModel(seriesModel);
  28073. };
  28074. return class_1;
  28075. }(ExtensionAPI))(ecIns);
  28076. };
  28077. enableConnect = function (chart) {
  28078. function updateConnectedChartsStatus(charts, status) {
  28079. for (var i = 0; i < charts.length; i++) {
  28080. var otherChart = charts[i];
  28081. otherChart[CONNECT_STATUS_KEY] = status;
  28082. }
  28083. }
  28084. each(eventActionMap, function (actionType, eventType) {
  28085. chart._messageCenter.on(eventType, function (event) {
  28086. if (connectedGroups[chart.group] && chart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_PENDING) {
  28087. if (event && event.escapeConnect) {
  28088. return;
  28089. }
  28090. var action_1 = chart.makeActionFromEvent(event);
  28091. var otherCharts_1 = [];
  28092. each(instances$1, function (otherChart) {
  28093. if (otherChart !== chart && otherChart.group === chart.group) {
  28094. otherCharts_1.push(otherChart);
  28095. }
  28096. });
  28097. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_PENDING);
  28098. each(otherCharts_1, function (otherChart) {
  28099. if (otherChart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_UPDATING) {
  28100. otherChart.dispatchAction(action_1);
  28101. }
  28102. });
  28103. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_UPDATED);
  28104. }
  28105. });
  28106. });
  28107. };
  28108. }();
  28109. return ECharts;
  28110. }(Eventful);
  28111. var echartsProto = ECharts.prototype;
  28112. echartsProto.on = createRegisterEventWithLowercaseECharts('on');
  28113. echartsProto.off = createRegisterEventWithLowercaseECharts('off');
  28114. /**
  28115. * @deprecated
  28116. */
  28117. // @ts-ignore
  28118. echartsProto.one = function (eventName, cb, ctx) {
  28119. var self = this;
  28120. deprecateLog('ECharts#one is deprecated.');
  28121. function wrapped() {
  28122. var args2 = [];
  28123. for (var _i = 0; _i < arguments.length; _i++) {
  28124. args2[_i] = arguments[_i];
  28125. }
  28126. cb && cb.apply && cb.apply(this, args2); // @ts-ignore
  28127. self.off(eventName, wrapped);
  28128. }
  28129. this.on.call(this, eventName, wrapped, ctx);
  28130. }; // /**
  28131. // * Encode visual infomation from data after data processing
  28132. // *
  28133. // * @param {module:echarts/model/Global} ecModel
  28134. // * @param {object} layout
  28135. // * @param {boolean} [layoutFilter] `true`: only layout,
  28136. // * `false`: only not layout,
  28137. // * `null`/`undefined`: all.
  28138. // * @param {string} taskBaseTag
  28139. // * @private
  28140. // */
  28141. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  28142. // each(visualFuncs, function (visual, index) {
  28143. // let isLayout = visual.isLayout;
  28144. // if (layoutFilter == null
  28145. // || (layoutFilter === false && !isLayout)
  28146. // || (layoutFilter === true && isLayout)
  28147. // ) {
  28148. // visual.func(ecModel, api, payload);
  28149. // }
  28150. // });
  28151. // }
  28152. var MOUSE_EVENT_NAMES = ['click', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'globalout', 'contextmenu'];
  28153. function disposedWarning(id) {
  28154. if ("development" !== 'production') {
  28155. console.warn('Instance ' + id + ' has been disposed');
  28156. }
  28157. }
  28158. var actions = {};
  28159. /**
  28160. * Map eventType to actionType
  28161. */
  28162. var eventActionMap = {};
  28163. var dataProcessorFuncs = [];
  28164. var optionPreprocessorFuncs = [];
  28165. var visualFuncs = [];
  28166. var themeStorage = {};
  28167. var loadingEffects = {};
  28168. var instances$1 = {};
  28169. var connectedGroups = {};
  28170. var idBase = +new Date() - 0;
  28171. var groupIdBase = +new Date() - 0;
  28172. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  28173. /**
  28174. * @param opts.devicePixelRatio Use window.devicePixelRatio by default
  28175. * @param opts.renderer Can choose 'canvas' or 'svg' to render the chart.
  28176. * @param opts.width Use clientWidth of the input `dom` by default.
  28177. * Can be 'auto' (the same as null/undefined)
  28178. * @param opts.height Use clientHeight of the input `dom` by default.
  28179. * Can be 'auto' (the same as null/undefined)
  28180. * @param opts.locale Specify the locale.
  28181. * @param opts.useDirtyRect Enable dirty rectangle rendering or not.
  28182. */
  28183. function init$1(dom, theme, opts) {
  28184. if ("development" !== 'production') {
  28185. if (!dom) {
  28186. throw new Error('Initialize failed: invalid dom.');
  28187. }
  28188. }
  28189. var existInstance = getInstanceByDom(dom);
  28190. if (existInstance) {
  28191. if ("development" !== 'production') {
  28192. console.warn('There is a chart instance already initialized on the dom.');
  28193. }
  28194. return existInstance;
  28195. }
  28196. if ("development" !== 'production') {
  28197. if (isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth && (!opts || opts.width == null) || !dom.clientHeight && (!opts || opts.height == null))) {
  28198. console.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.');
  28199. }
  28200. }
  28201. var chart = new ECharts(dom, theme, opts);
  28202. chart.id = 'ec_' + idBase++;
  28203. instances$1[chart.id] = chart;
  28204. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  28205. enableConnect(chart);
  28206. lifecycle.trigger('afterinit', chart);
  28207. return chart;
  28208. }
  28209. /**
  28210. * @usage
  28211. * (A)
  28212. * ```js
  28213. * let chart1 = echarts.init(dom1);
  28214. * let chart2 = echarts.init(dom2);
  28215. * chart1.group = 'xxx';
  28216. * chart2.group = 'xxx';
  28217. * echarts.connect('xxx');
  28218. * ```
  28219. * (B)
  28220. * ```js
  28221. * let chart1 = echarts.init(dom1);
  28222. * let chart2 = echarts.init(dom2);
  28223. * echarts.connect('xxx', [chart1, chart2]);
  28224. * ```
  28225. */
  28226. function connect(groupId) {
  28227. // Is array of charts
  28228. if (isArray(groupId)) {
  28229. var charts = groupId;
  28230. groupId = null; // If any chart has group
  28231. each(charts, function (chart) {
  28232. if (chart.group != null) {
  28233. groupId = chart.group;
  28234. }
  28235. });
  28236. groupId = groupId || 'g_' + groupIdBase++;
  28237. each(charts, function (chart) {
  28238. chart.group = groupId;
  28239. });
  28240. }
  28241. connectedGroups[groupId] = true;
  28242. return groupId;
  28243. }
  28244. /**
  28245. * @deprecated
  28246. */
  28247. function disConnect(groupId) {
  28248. connectedGroups[groupId] = false;
  28249. }
  28250. /**
  28251. * Alias and backword compat
  28252. */
  28253. var disconnect = disConnect;
  28254. /**
  28255. * Dispose a chart instance
  28256. */
  28257. function dispose$1(chart) {
  28258. if (typeof chart === 'string') {
  28259. chart = instances$1[chart];
  28260. } else if (!(chart instanceof ECharts)) {
  28261. // Try to treat as dom
  28262. chart = getInstanceByDom(chart);
  28263. }
  28264. if (chart instanceof ECharts && !chart.isDisposed()) {
  28265. chart.dispose();
  28266. }
  28267. }
  28268. function getInstanceByDom(dom) {
  28269. return instances$1[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  28270. }
  28271. function getInstanceById(key) {
  28272. return instances$1[key];
  28273. }
  28274. /**
  28275. * Register theme
  28276. */
  28277. function registerTheme(name, theme) {
  28278. themeStorage[name] = theme;
  28279. }
  28280. /**
  28281. * Register option preprocessor
  28282. */
  28283. function registerPreprocessor(preprocessorFunc) {
  28284. if (indexOf(optionPreprocessorFuncs, preprocessorFunc) < 0) {
  28285. optionPreprocessorFuncs.push(preprocessorFunc);
  28286. }
  28287. }
  28288. function registerProcessor(priority, processor) {
  28289. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_DEFAULT);
  28290. }
  28291. /**
  28292. * Register postIniter
  28293. * @param {Function} postInitFunc
  28294. */
  28295. function registerPostInit(postInitFunc) {
  28296. registerUpdateLifecycle('afterinit', postInitFunc);
  28297. }
  28298. /**
  28299. * Register postUpdater
  28300. * @param {Function} postUpdateFunc
  28301. */
  28302. function registerPostUpdate(postUpdateFunc) {
  28303. registerUpdateLifecycle('afterupdate', postUpdateFunc);
  28304. }
  28305. function registerUpdateLifecycle(name, cb) {
  28306. lifecycle.on(name, cb);
  28307. }
  28308. function registerAction(actionInfo, eventName, action) {
  28309. if (typeof eventName === 'function') {
  28310. action = eventName;
  28311. eventName = '';
  28312. }
  28313. var actionType = isObject(actionInfo) ? actionInfo.type : [actionInfo, actionInfo = {
  28314. event: eventName
  28315. }][0]; // Event name is all lowercase
  28316. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  28317. eventName = actionInfo.event;
  28318. if (eventActionMap[eventName]) {
  28319. // Already registered.
  28320. return;
  28321. } // Validate action type and event name.
  28322. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  28323. if (!actions[actionType]) {
  28324. actions[actionType] = {
  28325. action: action,
  28326. actionInfo: actionInfo
  28327. };
  28328. }
  28329. eventActionMap[eventName] = actionType;
  28330. }
  28331. function registerCoordinateSystem(type, coordSysCreator) {
  28332. CoordinateSystemManager.register(type, coordSysCreator);
  28333. }
  28334. /**
  28335. * Get dimensions of specified coordinate system.
  28336. * @param {string} type
  28337. * @return {Array.<string|Object>}
  28338. */
  28339. function getCoordinateSystemDimensions(type) {
  28340. var coordSysCreator = CoordinateSystemManager.get(type);
  28341. if (coordSysCreator) {
  28342. return coordSysCreator.getDimensionsInfo ? coordSysCreator.getDimensionsInfo() : coordSysCreator.dimensions.slice();
  28343. }
  28344. }
  28345. function registerLayout(priority, layoutTask) {
  28346. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  28347. }
  28348. function registerVisual(priority, visualTask) {
  28349. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  28350. }
  28351. var registeredTasks = [];
  28352. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  28353. if (isFunction(priority) || isObject(priority)) {
  28354. fn = priority;
  28355. priority = defaultPriority;
  28356. }
  28357. if ("development" !== 'production') {
  28358. if (isNaN(priority) || priority == null) {
  28359. throw new Error('Illegal priority');
  28360. } // Check duplicate
  28361. each(targetList, function (wrap) {
  28362. assert(wrap.__raw !== fn);
  28363. });
  28364. } // Already registered
  28365. if (indexOf(registeredTasks, fn) >= 0) {
  28366. return;
  28367. }
  28368. registeredTasks.push(fn);
  28369. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  28370. stageHandler.__prio = priority;
  28371. stageHandler.__raw = fn;
  28372. targetList.push(stageHandler);
  28373. }
  28374. function registerLoading(name, loadingFx) {
  28375. loadingEffects[name] = loadingFx;
  28376. }
  28377. /**
  28378. * ZRender need a canvas context to do measureText.
  28379. * But in node environment canvas may be created by node-canvas.
  28380. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  28381. *
  28382. * Be careful of using it in the browser.
  28383. *
  28384. * @example
  28385. * let Canvas = require('canvas');
  28386. * let echarts = require('echarts');
  28387. * echarts.setCanvasCreator(function () {
  28388. * // Small size is enough.
  28389. * return new Canvas(32, 32);
  28390. * });
  28391. */
  28392. function setCanvasCreator(creator) {
  28393. $override('createCanvas', creator);
  28394. }
  28395. /**
  28396. * The parameters and usage: see `geoSourceManager.registerMap`.
  28397. * Compatible with previous `echarts.registerMap`.
  28398. */
  28399. function registerMap(mapName, geoJson, specialAreas) {
  28400. geoSourceManager.registerMap(mapName, geoJson, specialAreas);
  28401. }
  28402. function getMap(mapName) {
  28403. return geoSourceManager.getMapForUser(mapName);
  28404. }
  28405. var registerTransform = registerExternalTransform;
  28406. /**
  28407. * Globa dispatchAction to a specified chart instance.
  28408. */
  28409. // export function dispatchAction(payload: { chartId: string } & Payload, opt?: Parameters<ECharts['dispatchAction']>[1]) {
  28410. // if (!payload || !payload.chartId) {
  28411. // // Must have chartId to find chart
  28412. // return;
  28413. // }
  28414. // const chart = instances[payload.chartId];
  28415. // if (chart) {
  28416. // chart.dispatchAction(payload, opt);
  28417. // }
  28418. // }
  28419. // Buitlin global visual
  28420. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesStyleTask);
  28421. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataStyleTask);
  28422. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataColorPaletteTask);
  28423. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesSymbolTask);
  28424. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataSymbolTask);
  28425. registerVisual(PRIORITY_VISUAL_DECAL, decalVisual);
  28426. registerPreprocessor(globalBackwardCompat);
  28427. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  28428. registerLoading('default', defaultLoading); // Default actions
  28429. registerAction({
  28430. type: HIGHLIGHT_ACTION_TYPE,
  28431. event: HIGHLIGHT_ACTION_TYPE,
  28432. update: HIGHLIGHT_ACTION_TYPE
  28433. }, noop);
  28434. registerAction({
  28435. type: DOWNPLAY_ACTION_TYPE,
  28436. event: DOWNPLAY_ACTION_TYPE,
  28437. update: DOWNPLAY_ACTION_TYPE
  28438. }, noop);
  28439. registerAction({
  28440. type: SELECT_ACTION_TYPE,
  28441. event: SELECT_ACTION_TYPE,
  28442. update: SELECT_ACTION_TYPE
  28443. }, noop);
  28444. registerAction({
  28445. type: UNSELECT_ACTION_TYPE,
  28446. event: UNSELECT_ACTION_TYPE,
  28447. update: UNSELECT_ACTION_TYPE
  28448. }, noop);
  28449. registerAction({
  28450. type: TOGGLE_SELECT_ACTION_TYPE,
  28451. event: TOGGLE_SELECT_ACTION_TYPE,
  28452. update: TOGGLE_SELECT_ACTION_TYPE
  28453. }, noop); // Default theme
  28454. registerTheme('light', lightTheme);
  28455. registerTheme('dark', theme); // For backward compatibility, where the namespace `dataTool` will
  28456. // be mounted on `echarts` is the extension `dataTool` is imported.
  28457. var dataTool = {};
  28458. var extensions = [];
  28459. var extensionRegisters = {
  28460. registerPreprocessor: registerPreprocessor,
  28461. registerProcessor: registerProcessor,
  28462. registerPostInit: registerPostInit,
  28463. registerPostUpdate: registerPostUpdate,
  28464. registerUpdateLifecycle: registerUpdateLifecycle,
  28465. registerAction: registerAction,
  28466. registerCoordinateSystem: registerCoordinateSystem,
  28467. registerLayout: registerLayout,
  28468. registerVisual: registerVisual,
  28469. registerTransform: registerTransform,
  28470. registerLoading: registerLoading,
  28471. registerMap: registerMap,
  28472. PRIORITY: PRIORITY,
  28473. ComponentModel: ComponentModel,
  28474. ComponentView: ComponentView,
  28475. SeriesModel: SeriesModel,
  28476. ChartView: ChartView,
  28477. // TODO Use ComponentModel and SeriesModel instead of Constructor
  28478. registerComponentModel: function (ComponentModelClass) {
  28479. ComponentModel.registerClass(ComponentModelClass);
  28480. },
  28481. registerComponentView: function (ComponentViewClass) {
  28482. ComponentView.registerClass(ComponentViewClass);
  28483. },
  28484. registerSeriesModel: function (SeriesModelClass) {
  28485. SeriesModel.registerClass(SeriesModelClass);
  28486. },
  28487. registerChartView: function (ChartViewClass) {
  28488. ChartView.registerClass(ChartViewClass);
  28489. },
  28490. registerSubTypeDefaulter: function (componentType, defaulter) {
  28491. ComponentModel.registerSubTypeDefaulter(componentType, defaulter);
  28492. },
  28493. registerPainter: function (painterType, PainterCtor) {
  28494. registerPainter(painterType, PainterCtor);
  28495. }
  28496. };
  28497. function use(ext) {
  28498. if (isArray(ext)) {
  28499. // use([ChartLine, ChartBar]);
  28500. each(ext, function (singleExt) {
  28501. use(singleExt);
  28502. });
  28503. return;
  28504. }
  28505. if (indexOf(extensions, ext) >= 0) {
  28506. return;
  28507. }
  28508. extensions.push(ext);
  28509. if (isFunction(ext)) {
  28510. ext = {
  28511. install: ext
  28512. };
  28513. }
  28514. ext.install(extensionRegisters);
  28515. }
  28516. /*
  28517. * Licensed to the Apache Software Foundation (ASF) under one
  28518. * or more contributor license agreements. See the NOTICE file
  28519. * distributed with this work for additional information
  28520. * regarding copyright ownership. The ASF licenses this file
  28521. * to you under the Apache License, Version 2.0 (the
  28522. * "License"); you may not use this file except in compliance
  28523. * with the License. You may obtain a copy of the License at
  28524. *
  28525. * http://www.apache.org/licenses/LICENSE-2.0
  28526. *
  28527. * Unless required by applicable law or agreed to in writing,
  28528. * software distributed under the License is distributed on an
  28529. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28530. * KIND, either express or implied. See the License for the
  28531. * specific language governing permissions and limitations
  28532. * under the License.
  28533. */
  28534. /**
  28535. * AUTO-GENERATED FILE. DO NOT MODIFY.
  28536. */
  28537. /*
  28538. * Licensed to the Apache Software Foundation (ASF) under one
  28539. * or more contributor license agreements. See the NOTICE file
  28540. * distributed with this work for additional information
  28541. * regarding copyright ownership. The ASF licenses this file
  28542. * to you under the Apache License, Version 2.0 (the
  28543. * "License"); you may not use this file except in compliance
  28544. * with the License. You may obtain a copy of the License at
  28545. *
  28546. * http://www.apache.org/licenses/LICENSE-2.0
  28547. *
  28548. * Unless required by applicable law or agreed to in writing,
  28549. * software distributed under the License is distributed on an
  28550. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28551. * KIND, either express or implied. See the License for the
  28552. * specific language governing permissions and limitations
  28553. * under the License.
  28554. */
  28555. function dataIndexMapValueLength(valNumOrArrLengthMoreThan2) {
  28556. return valNumOrArrLengthMoreThan2 == null ? 0 : valNumOrArrLengthMoreThan2.length || 1;
  28557. }
  28558. function defaultKeyGetter(item) {
  28559. return item;
  28560. }
  28561. var DataDiffer =
  28562. /** @class */
  28563. function () {
  28564. /**
  28565. * @param context Can be visited by this.context in callback.
  28566. */
  28567. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context, // By default: 'oneToOne'.
  28568. diffMode) {
  28569. this._old = oldArr;
  28570. this._new = newArr;
  28571. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  28572. this._newKeyGetter = newKeyGetter || defaultKeyGetter; // Visible in callback via `this.context`;
  28573. this.context = context;
  28574. this._diffModeMultiple = diffMode === 'multiple';
  28575. }
  28576. /**
  28577. * Callback function when add a data
  28578. */
  28579. DataDiffer.prototype.add = function (func) {
  28580. this._add = func;
  28581. return this;
  28582. };
  28583. /**
  28584. * Callback function when update a data
  28585. */
  28586. DataDiffer.prototype.update = function (func) {
  28587. this._update = func;
  28588. return this;
  28589. };
  28590. /**
  28591. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28592. */
  28593. DataDiffer.prototype.updateManyToOne = function (func) {
  28594. this._updateManyToOne = func;
  28595. return this;
  28596. };
  28597. /**
  28598. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28599. */
  28600. DataDiffer.prototype.updateOneToMany = function (func) {
  28601. this._updateOneToMany = func;
  28602. return this;
  28603. };
  28604. /**
  28605. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  28606. */
  28607. DataDiffer.prototype.updateManyToMany = function (func) {
  28608. this._updateManyToMany = func;
  28609. return this;
  28610. };
  28611. /**
  28612. * Callback function when remove a data
  28613. */
  28614. DataDiffer.prototype.remove = function (func) {
  28615. this._remove = func;
  28616. return this;
  28617. };
  28618. DataDiffer.prototype.execute = function () {
  28619. this[this._diffModeMultiple ? '_executeMultiple' : '_executeOneToOne']();
  28620. };
  28621. DataDiffer.prototype._executeOneToOne = function () {
  28622. var oldArr = this._old;
  28623. var newArr = this._new;
  28624. var newDataIndexMap = {};
  28625. var oldDataKeyArr = new Array(oldArr.length);
  28626. var newDataKeyArr = new Array(newArr.length);
  28627. this._initIndexMap(oldArr, null, oldDataKeyArr, '_oldKeyGetter');
  28628. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  28629. for (var i = 0; i < oldArr.length; i++) {
  28630. var oldKey = oldDataKeyArr[i];
  28631. var newIdxMapVal = newDataIndexMap[oldKey];
  28632. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal); // idx can never be empty array here. see 'set null' logic below.
  28633. if (newIdxMapValLen > 1) {
  28634. // Consider there is duplicate key (for example, use dataItem.name as key).
  28635. // We should make sure every item in newArr and oldArr can be visited.
  28636. var newIdx = newIdxMapVal.shift();
  28637. if (newIdxMapVal.length === 1) {
  28638. newDataIndexMap[oldKey] = newIdxMapVal[0];
  28639. }
  28640. this._update && this._update(newIdx, i);
  28641. } else if (newIdxMapValLen === 1) {
  28642. newDataIndexMap[oldKey] = null;
  28643. this._update && this._update(newIdxMapVal, i);
  28644. } else {
  28645. this._remove && this._remove(i);
  28646. }
  28647. }
  28648. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  28649. };
  28650. /**
  28651. * For example, consider the case:
  28652. * oldData: [o0, o1, o2, o3, o4, o5, o6, o7],
  28653. * newData: [n0, n1, n2, n3, n4, n5, n6, n7, n8],
  28654. * Where:
  28655. * o0, o1, n0 has key 'a' (many to one)
  28656. * o5, n4, n5, n6 has key 'b' (one to many)
  28657. * o2, n1 has key 'c' (one to one)
  28658. * n2, n3 has key 'd' (add)
  28659. * o3, o4 has key 'e' (remove)
  28660. * o6, o7, n7, n8 has key 'f' (many to many, treated as add and remove)
  28661. * Then:
  28662. * (The order of the following directives are not ensured.)
  28663. * this._updateManyToOne(n0, [o0, o1]);
  28664. * this._updateOneToMany([n4, n5, n6], o5);
  28665. * this._update(n1, o2);
  28666. * this._remove(o3);
  28667. * this._remove(o4);
  28668. * this._remove(o6);
  28669. * this._remove(o7);
  28670. * this._add(n2);
  28671. * this._add(n3);
  28672. * this._add(n7);
  28673. * this._add(n8);
  28674. */
  28675. DataDiffer.prototype._executeMultiple = function () {
  28676. var oldArr = this._old;
  28677. var newArr = this._new;
  28678. var oldDataIndexMap = {};
  28679. var newDataIndexMap = {};
  28680. var oldDataKeyArr = [];
  28681. var newDataKeyArr = [];
  28682. this._initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter');
  28683. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  28684. for (var i = 0; i < oldDataKeyArr.length; i++) {
  28685. var oldKey = oldDataKeyArr[i];
  28686. var oldIdxMapVal = oldDataIndexMap[oldKey];
  28687. var newIdxMapVal = newDataIndexMap[oldKey];
  28688. var oldIdxMapValLen = dataIndexMapValueLength(oldIdxMapVal);
  28689. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  28690. if (oldIdxMapValLen > 1 && newIdxMapValLen === 1) {
  28691. this._updateManyToOne && this._updateManyToOne(newIdxMapVal, oldIdxMapVal);
  28692. newDataIndexMap[oldKey] = null;
  28693. } else if (oldIdxMapValLen === 1 && newIdxMapValLen > 1) {
  28694. this._updateOneToMany && this._updateOneToMany(newIdxMapVal, oldIdxMapVal);
  28695. newDataIndexMap[oldKey] = null;
  28696. } else if (oldIdxMapValLen === 1 && newIdxMapValLen === 1) {
  28697. this._update && this._update(newIdxMapVal, oldIdxMapVal);
  28698. newDataIndexMap[oldKey] = null;
  28699. } else if (oldIdxMapValLen > 1 && newIdxMapValLen > 1) {
  28700. this._updateManyToMany && this._updateManyToMany(newIdxMapVal, oldIdxMapVal);
  28701. newDataIndexMap[oldKey] = null;
  28702. } else if (oldIdxMapValLen > 1) {
  28703. for (var i_1 = 0; i_1 < oldIdxMapValLen; i_1++) {
  28704. this._remove && this._remove(oldIdxMapVal[i_1]);
  28705. }
  28706. } else {
  28707. this._remove && this._remove(oldIdxMapVal);
  28708. }
  28709. }
  28710. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  28711. };
  28712. DataDiffer.prototype._performRestAdd = function (newDataKeyArr, newDataIndexMap) {
  28713. for (var i = 0; i < newDataKeyArr.length; i++) {
  28714. var newKey = newDataKeyArr[i];
  28715. var newIdxMapVal = newDataIndexMap[newKey];
  28716. var idxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  28717. if (idxMapValLen > 1) {
  28718. for (var j = 0; j < idxMapValLen; j++) {
  28719. this._add && this._add(newIdxMapVal[j]);
  28720. }
  28721. } else if (idxMapValLen === 1) {
  28722. this._add && this._add(newIdxMapVal);
  28723. } // Support both `newDataKeyArr` are duplication removed or not removed.
  28724. newDataIndexMap[newKey] = null;
  28725. }
  28726. };
  28727. DataDiffer.prototype._initIndexMap = function (arr, // Can be null.
  28728. map, // In 'byKey', the output `keyArr` is duplication removed.
  28729. // In 'byIndex', the output `keyArr` is not duplication removed and
  28730. // its indices are accurately corresponding to `arr`.
  28731. keyArr, keyGetterName) {
  28732. var cbModeMultiple = this._diffModeMultiple;
  28733. for (var i = 0; i < arr.length; i++) {
  28734. // Add prefix to avoid conflict with Object.prototype.
  28735. var key = '_ec_' + this[keyGetterName](arr[i], i);
  28736. if (!cbModeMultiple) {
  28737. keyArr[i] = key;
  28738. }
  28739. if (!map) {
  28740. continue;
  28741. }
  28742. var idxMapVal = map[key];
  28743. var idxMapValLen = dataIndexMapValueLength(idxMapVal);
  28744. if (idxMapValLen === 0) {
  28745. // Simple optimize: in most cases, one index has one key,
  28746. // do not need array.
  28747. map[key] = i;
  28748. if (cbModeMultiple) {
  28749. keyArr.push(key);
  28750. }
  28751. } else if (idxMapValLen === 1) {
  28752. map[key] = [idxMapVal, i];
  28753. } else {
  28754. idxMapVal.push(i);
  28755. }
  28756. }
  28757. };
  28758. return DataDiffer;
  28759. }();
  28760. var DimensionUserOuput =
  28761. /** @class */
  28762. function () {
  28763. function DimensionUserOuput(encode, dimRequest) {
  28764. this._encode = encode;
  28765. this._schema = dimRequest;
  28766. }
  28767. DimensionUserOuput.prototype.get = function () {
  28768. return {
  28769. // Do not generate full dimension name until fist used.
  28770. fullDimensions: this._getFullDimensionNames(),
  28771. encode: this._encode
  28772. };
  28773. };
  28774. /**
  28775. * Get all data store dimension names.
  28776. * Theoretically a series data store is defined both by series and used dataset (if any).
  28777. * If some dimensions are omitted for performance reason in `this.dimensions`,
  28778. * the dimension name may not be auto-generated if user does not specify a dimension name.
  28779. * In this case, the dimension name is `null`/`undefined`.
  28780. */
  28781. DimensionUserOuput.prototype._getFullDimensionNames = function () {
  28782. if (!this._cachedDimNames) {
  28783. this._cachedDimNames = this._schema ? this._schema.makeOutputDimensionNames() : [];
  28784. }
  28785. return this._cachedDimNames;
  28786. };
  28787. return DimensionUserOuput;
  28788. }();
  28789. function summarizeDimensions(data, schema) {
  28790. var summary = {};
  28791. var encode = summary.encode = {};
  28792. var notExtraCoordDimMap = createHashMap();
  28793. var defaultedLabel = [];
  28794. var defaultedTooltip = [];
  28795. var userOutputEncode = {};
  28796. each(data.dimensions, function (dimName) {
  28797. var dimItem = data.getDimensionInfo(dimName);
  28798. var coordDim = dimItem.coordDim;
  28799. if (coordDim) {
  28800. if ("development" !== 'production') {
  28801. assert(VISUAL_DIMENSIONS.get(coordDim) == null);
  28802. }
  28803. var coordDimIndex = dimItem.coordDimIndex;
  28804. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  28805. if (!dimItem.isExtraCoord) {
  28806. notExtraCoordDimMap.set(coordDim, 1); // Use the last coord dim (and label friendly) as default label,
  28807. // because when dataset is used, it is hard to guess which dimension
  28808. // can be value dimension. If both show x, y on label is not look good,
  28809. // and conventionally y axis is focused more.
  28810. if (mayLabelDimType(dimItem.type)) {
  28811. defaultedLabel[0] = dimName;
  28812. } // User output encode do not contain generated coords.
  28813. // And it only has index. User can use index to retrieve value from the raw item array.
  28814. getOrCreateEncodeArr(userOutputEncode, coordDim)[coordDimIndex] = data.getDimensionIndex(dimItem.name);
  28815. }
  28816. if (dimItem.defaultTooltip) {
  28817. defaultedTooltip.push(dimName);
  28818. }
  28819. }
  28820. VISUAL_DIMENSIONS.each(function (v, otherDim) {
  28821. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  28822. var dimIndex = dimItem.otherDims[otherDim];
  28823. if (dimIndex != null && dimIndex !== false) {
  28824. encodeArr[dimIndex] = dimItem.name;
  28825. }
  28826. });
  28827. });
  28828. var dataDimsOnCoord = [];
  28829. var encodeFirstDimNotExtra = {};
  28830. notExtraCoordDimMap.each(function (v, coordDim) {
  28831. var dimArr = encode[coordDim];
  28832. encodeFirstDimNotExtra[coordDim] = dimArr[0]; // Not necessary to remove duplicate, because a data
  28833. // dim canot on more than one coordDim.
  28834. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  28835. });
  28836. summary.dataDimsOnCoord = dataDimsOnCoord;
  28837. summary.dataDimIndicesOnCoord = map(dataDimsOnCoord, function (dimName) {
  28838. return data.getDimensionInfo(dimName).storeDimIndex;
  28839. });
  28840. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  28841. var encodeLabel = encode.label; // FIXME `encode.label` is not recommanded, because formatter can not be set
  28842. // in this way. Use label.formatter instead. May be remove this approach someday.
  28843. if (encodeLabel && encodeLabel.length) {
  28844. defaultedLabel = encodeLabel.slice();
  28845. }
  28846. var encodeTooltip = encode.tooltip;
  28847. if (encodeTooltip && encodeTooltip.length) {
  28848. defaultedTooltip = encodeTooltip.slice();
  28849. } else if (!defaultedTooltip.length) {
  28850. defaultedTooltip = defaultedLabel.slice();
  28851. }
  28852. encode.defaultedLabel = defaultedLabel;
  28853. encode.defaultedTooltip = defaultedTooltip;
  28854. summary.userOutput = new DimensionUserOuput(userOutputEncode, schema);
  28855. return summary;
  28856. }
  28857. function getOrCreateEncodeArr(encode, dim) {
  28858. if (!encode.hasOwnProperty(dim)) {
  28859. encode[dim] = [];
  28860. }
  28861. return encode[dim];
  28862. } // FIXME:TS should be type `AxisType`
  28863. function getDimensionTypeByAxis(axisType) {
  28864. return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
  28865. }
  28866. function mayLabelDimType(dimType) {
  28867. // In most cases, ordinal and time do not suitable for label.
  28868. // Ordinal info can be displayed on axis. Time is too long.
  28869. return !(dimType === 'ordinal' || dimType === 'time');
  28870. } // function findTheLastDimMayLabel(data) {
  28871. // // Get last value dim
  28872. // let dimensions = data.dimensions.slice();
  28873. // let valueType;
  28874. // let valueDim;
  28875. // while (dimensions.length && (
  28876. // valueDim = dimensions.pop(),
  28877. // valueType = data.getDimensionInfo(valueDim).type,
  28878. // valueType === 'ordinal' || valueType === 'time'
  28879. // )) {} // jshint ignore:line
  28880. // return valueDim;
  28881. // }
  28882. var SeriesDimensionDefine =
  28883. /** @class */
  28884. function () {
  28885. /**
  28886. * @param opt All of the fields will be shallow copied.
  28887. */
  28888. function SeriesDimensionDefine(opt) {
  28889. /**
  28890. * The format of `otherDims` is:
  28891. * ```js
  28892. * {
  28893. * tooltip?: number
  28894. * label?: number
  28895. * itemName?: number
  28896. * seriesName?: number
  28897. * }
  28898. * ```
  28899. *
  28900. * A `series.encode` can specified these fields:
  28901. * ```js
  28902. * encode: {
  28903. * // "3, 1, 5" is the index of data dimension.
  28904. * tooltip: [3, 1, 5],
  28905. * label: [0, 3],
  28906. * ...
  28907. * }
  28908. * ```
  28909. * `otherDims` is the parse result of the `series.encode` above, like:
  28910. * ```js
  28911. * // Suppose the index of this data dimension is `3`.
  28912. * this.otherDims = {
  28913. * // `3` is at the index `0` of the `encode.tooltip`
  28914. * tooltip: 0,
  28915. * // `3` is at the index `1` of the `encode.label`
  28916. * label: 1
  28917. * };
  28918. * ```
  28919. *
  28920. * This prop should never be `null`/`undefined` after initialized.
  28921. */
  28922. this.otherDims = {};
  28923. if (opt != null) {
  28924. extend(this, opt);
  28925. }
  28926. }
  28927. return SeriesDimensionDefine;
  28928. }();
  28929. var inner$4 = makeInner();
  28930. var dimTypeShort = {
  28931. float: 'f',
  28932. int: 'i',
  28933. ordinal: 'o',
  28934. number: 'n',
  28935. time: 't'
  28936. };
  28937. /**
  28938. * Represents the dimension requirement of a series.
  28939. *
  28940. * NOTICE:
  28941. * When there are too many dimensions in dataset and many series, only the used dimensions
  28942. * (i.e., used by coord sys and declared in `series.encode`) are add to `dimensionDefineList`.
  28943. * But users may query data by other unused dimension names.
  28944. * In this case, users can only query data if and only if they have defined dimension names
  28945. * via ec option, so we provide `getDimensionIndexFromSource`, which only query them from
  28946. * `source` dimensions.
  28947. */
  28948. var SeriesDataSchema =
  28949. /** @class */
  28950. function () {
  28951. function SeriesDataSchema(opt) {
  28952. this.dimensions = opt.dimensions;
  28953. this._dimOmitted = opt.dimensionOmitted;
  28954. this.source = opt.source;
  28955. this._fullDimCount = opt.fullDimensionCount;
  28956. this._updateDimOmitted(opt.dimensionOmitted);
  28957. }
  28958. SeriesDataSchema.prototype.isDimensionOmitted = function () {
  28959. return this._dimOmitted;
  28960. };
  28961. SeriesDataSchema.prototype._updateDimOmitted = function (dimensionOmitted) {
  28962. this._dimOmitted = dimensionOmitted;
  28963. if (!dimensionOmitted) {
  28964. return;
  28965. }
  28966. if (!this._dimNameMap) {
  28967. this._dimNameMap = ensureSourceDimNameMap(this.source);
  28968. }
  28969. };
  28970. /**
  28971. * @caution Can only be used when `dimensionOmitted: true`.
  28972. *
  28973. * Get index by user defined dimension name (i.e., not internal generate name).
  28974. * That is, get index from `dimensionsDefine`.
  28975. * If no `dimensionsDefine`, or no name get, return -1.
  28976. */
  28977. SeriesDataSchema.prototype.getSourceDimensionIndex = function (dimName) {
  28978. return retrieve2(this._dimNameMap.get(dimName), -1);
  28979. };
  28980. /**
  28981. * @caution Can only be used when `dimensionOmitted: true`.
  28982. *
  28983. * Notice: may return `null`/`undefined` if user not specify dimension names.
  28984. */
  28985. SeriesDataSchema.prototype.getSourceDimension = function (dimIndex) {
  28986. var dimensionsDefine = this.source.dimensionsDefine;
  28987. if (dimensionsDefine) {
  28988. return dimensionsDefine[dimIndex];
  28989. }
  28990. };
  28991. SeriesDataSchema.prototype.makeStoreSchema = function () {
  28992. var dimCount = this._fullDimCount;
  28993. var willRetrieveDataByName = shouldRetrieveDataByName(this.source);
  28994. var makeHashStrict = !shouldOmitUnusedDimensions(dimCount); // If source don't have dimensions or series don't omit unsed dimensions.
  28995. // Generate from seriesDimList directly
  28996. var dimHash = '';
  28997. var dims = [];
  28998. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < dimCount; fullDimIdx++) {
  28999. var property = void 0;
  29000. var type = void 0;
  29001. var ordinalMeta = void 0;
  29002. var seriesDimDef = this.dimensions[seriesDimIdx]; // The list has been sorted by `storeDimIndex` asc.
  29003. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  29004. property = willRetrieveDataByName ? seriesDimDef.name : null;
  29005. type = seriesDimDef.type;
  29006. ordinalMeta = seriesDimDef.ordinalMeta;
  29007. seriesDimIdx++;
  29008. } else {
  29009. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  29010. if (sourceDimDef) {
  29011. property = willRetrieveDataByName ? sourceDimDef.name : null;
  29012. type = sourceDimDef.type;
  29013. }
  29014. }
  29015. dims.push({
  29016. property: property,
  29017. type: type,
  29018. ordinalMeta: ordinalMeta
  29019. }); // If retrieving data by index,
  29020. // use <index, type, ordinalMeta> to determine whether data can be shared.
  29021. // (Becuase in this case there might be no dimension name defined in dataset, but indices always exists).
  29022. // (indices are always 0, 1, 2, ..., so we can ignore them to shorten the hash).
  29023. // Otherwise if retrieving data by property name (like `data: [{aa: 123, bb: 765}, ...]`),
  29024. // use <property, type, ordinalMeta> in hash.
  29025. if (willRetrieveDataByName && property != null // For data stack, we have make sure each series has its own dim on this store.
  29026. // So we do not add property to hash to make sure they can share this store.
  29027. && (!seriesDimDef || !seriesDimDef.isCalculationCoord)) {
  29028. dimHash += makeHashStrict // Use escape character '`' in case that property name contains '$'.
  29029. ? property.replace(/\`/g, '`1').replace(/\$/g, '`2') // For better performance, when there are large dimensions, tolerant this defects that hardly meet.
  29030. : property;
  29031. }
  29032. dimHash += '$';
  29033. dimHash += dimTypeShort[type] || 'f';
  29034. if (ordinalMeta) {
  29035. dimHash += ordinalMeta.uid;
  29036. }
  29037. dimHash += '$';
  29038. } // Source from endpoint(usually series) will be read differently
  29039. // when seriesLayoutBy or startIndex(which is affected by sourceHeader) are different.
  29040. // So we use this three props as key.
  29041. var source = this.source;
  29042. var hash = [source.seriesLayoutBy, source.startIndex, dimHash].join('$$');
  29043. return {
  29044. dimensions: dims,
  29045. hash: hash
  29046. };
  29047. };
  29048. SeriesDataSchema.prototype.makeOutputDimensionNames = function () {
  29049. var result = [];
  29050. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < this._fullDimCount; fullDimIdx++) {
  29051. var name_1 = void 0;
  29052. var seriesDimDef = this.dimensions[seriesDimIdx]; // The list has been sorted by `storeDimIndex` asc.
  29053. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  29054. if (!seriesDimDef.isCalculationCoord) {
  29055. name_1 = seriesDimDef.name;
  29056. }
  29057. seriesDimIdx++;
  29058. } else {
  29059. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  29060. if (sourceDimDef) {
  29061. name_1 = sourceDimDef.name;
  29062. }
  29063. }
  29064. result.push(name_1);
  29065. }
  29066. return result;
  29067. };
  29068. SeriesDataSchema.prototype.appendCalculationDimension = function (dimDef) {
  29069. this.dimensions.push(dimDef);
  29070. dimDef.isCalculationCoord = true;
  29071. this._fullDimCount++; // If append dimension on a data store, consider the store
  29072. // might be shared by different series, series dimensions not
  29073. // really map to store dimensions.
  29074. this._updateDimOmitted(true);
  29075. };
  29076. return SeriesDataSchema;
  29077. }();
  29078. function isSeriesDataSchema(schema) {
  29079. return schema instanceof SeriesDataSchema;
  29080. }
  29081. function createDimNameMap(dimsDef) {
  29082. var dataDimNameMap = createHashMap();
  29083. for (var i = 0; i < (dimsDef || []).length; i++) {
  29084. var dimDefItemRaw = dimsDef[i];
  29085. var userDimName = isObject(dimDefItemRaw) ? dimDefItemRaw.name : dimDefItemRaw;
  29086. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  29087. dataDimNameMap.set(userDimName, i);
  29088. }
  29089. }
  29090. return dataDimNameMap;
  29091. }
  29092. function ensureSourceDimNameMap(source) {
  29093. var innerSource = inner$4(source);
  29094. return innerSource.dimNameMap || (innerSource.dimNameMap = createDimNameMap(source.dimensionsDefine));
  29095. }
  29096. function shouldOmitUnusedDimensions(dimCount) {
  29097. return dimCount > 30;
  29098. }
  29099. var isObject$2 = isObject;
  29100. var map$1 = map;
  29101. var CtorInt32Array$1 = typeof Int32Array === 'undefined' ? Array : Int32Array; // Use prefix to avoid index to be the same as otherIdList[idx],
  29102. // which will cause weird udpate animation.
  29103. var ID_PREFIX = 'e\0\0';
  29104. var INDEX_NOT_FOUND = -1; // type SeriesDimensionIndex = DimensionIndex;
  29105. var TRANSFERABLE_PROPERTIES = ['hasItemOption', '_nameList', '_idList', '_invertedIndicesMap', '_dimSummary', 'userOutput', '_rawData', '_dimValueGetter', '_nameDimIdx', '_idDimIdx', '_nameRepeatCount'];
  29106. var CLONE_PROPERTIES = ['_approximateExtent']; // -----------------------------
  29107. // Internal method declarations:
  29108. // -----------------------------
  29109. var prepareInvertedIndex;
  29110. var getId;
  29111. var getIdNameFromStore;
  29112. var normalizeDimensions;
  29113. var transferProperties;
  29114. var cloneListForMapAndSample;
  29115. var makeIdFromName;
  29116. var SeriesData =
  29117. /** @class */
  29118. function () {
  29119. /**
  29120. * @param dimensionsInput.dimensions
  29121. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  29122. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  29123. */
  29124. function SeriesData(dimensionsInput, hostModel) {
  29125. this.type = 'list';
  29126. this._dimOmitted = false;
  29127. this._nameList = [];
  29128. this._idList = []; // Models of data option is stored sparse for optimizing memory cost
  29129. // Never used yet (not used yet).
  29130. // private _optionModels: Model[] = [];
  29131. // Global visual properties after visual coding
  29132. this._visual = {}; // Globel layout properties.
  29133. this._layout = {}; // Item visual properties after visual coding
  29134. this._itemVisuals = []; // Item layout properties after layout
  29135. this._itemLayouts = []; // Graphic elemnents
  29136. this._graphicEls = []; // key: dim, value: extent
  29137. this._approximateExtent = {};
  29138. this._calculationInfo = {}; // Having detected that there is data item is non primitive type
  29139. // (in type `OptionDataItemObject`).
  29140. // Like `data: [ { value: xx, itemStyle: {...} }, ...]`
  29141. // At present it only happen in `SOURCE_FORMAT_ORIGINAL`.
  29142. this.hasItemOption = false; // Methods that create a new list based on this list should be listed here.
  29143. // Notice that those method should `RETURN` the new list.
  29144. this.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'lttbDownSample', 'map']; // Methods that change indices of this list should be listed here.
  29145. this.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  29146. this.DOWNSAMPLE_METHODS = ['downSample', 'lttbDownSample'];
  29147. var dimensions;
  29148. var assignStoreDimIdx = false;
  29149. if (isSeriesDataSchema(dimensionsInput)) {
  29150. dimensions = dimensionsInput.dimensions;
  29151. this._dimOmitted = dimensionsInput.isDimensionOmitted();
  29152. this._schema = dimensionsInput;
  29153. } else {
  29154. assignStoreDimIdx = true;
  29155. dimensions = dimensionsInput;
  29156. }
  29157. dimensions = dimensions || ['x', 'y'];
  29158. var dimensionInfos = {};
  29159. var dimensionNames = [];
  29160. var invertedIndicesMap = {};
  29161. var needsHasOwn = false;
  29162. var emptyObj = {};
  29163. for (var i = 0; i < dimensions.length; i++) {
  29164. // Use the original dimensions[i], where other flag props may exists.
  29165. var dimInfoInput = dimensions[i];
  29166. var dimensionInfo = isString(dimInfoInput) ? new SeriesDimensionDefine({
  29167. name: dimInfoInput
  29168. }) : !(dimInfoInput instanceof SeriesDimensionDefine) ? new SeriesDimensionDefine(dimInfoInput) : dimInfoInput;
  29169. var dimensionName = dimensionInfo.name;
  29170. dimensionInfo.type = dimensionInfo.type || 'float';
  29171. if (!dimensionInfo.coordDim) {
  29172. dimensionInfo.coordDim = dimensionName;
  29173. dimensionInfo.coordDimIndex = 0;
  29174. }
  29175. var otherDims = dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  29176. dimensionNames.push(dimensionName);
  29177. dimensionInfos[dimensionName] = dimensionInfo;
  29178. if (emptyObj[dimensionName] != null) {
  29179. needsHasOwn = true;
  29180. }
  29181. if (dimensionInfo.createInvertedIndices) {
  29182. invertedIndicesMap[dimensionName] = [];
  29183. }
  29184. if (otherDims.itemName === 0) {
  29185. this._nameDimIdx = i;
  29186. }
  29187. if (otherDims.itemId === 0) {
  29188. this._idDimIdx = i;
  29189. }
  29190. if ("development" !== 'production') {
  29191. assert(assignStoreDimIdx || dimensionInfo.storeDimIndex >= 0);
  29192. }
  29193. if (assignStoreDimIdx) {
  29194. dimensionInfo.storeDimIndex = i;
  29195. }
  29196. }
  29197. this.dimensions = dimensionNames;
  29198. this._dimInfos = dimensionInfos;
  29199. this._initGetDimensionInfo(needsHasOwn);
  29200. this.hostModel = hostModel;
  29201. this._invertedIndicesMap = invertedIndicesMap;
  29202. if (this._dimOmitted) {
  29203. var dimIdxToName_1 = this._dimIdxToName = createHashMap();
  29204. each(dimensionNames, function (dimName) {
  29205. dimIdxToName_1.set(dimensionInfos[dimName].storeDimIndex, dimName);
  29206. });
  29207. }
  29208. }
  29209. /**
  29210. *
  29211. * Get concrete dimension name by dimension name or dimension index.
  29212. * If input a dimension name, do not validate whether the dimension name exits.
  29213. *
  29214. * @caution
  29215. * @param dim Must make sure the dimension is `SeriesDimensionLoose`.
  29216. * Because only those dimensions will have auto-generated dimension names if not
  29217. * have a user-specified name, and other dimensions will get a return of null/undefined.
  29218. *
  29219. * @notice Becuause of this reason, should better use `getDimensionIndex` instead, for examples:
  29220. * ```js
  29221. * const val = data.getStore().get(data.getDimensionIndex(dim), dataIdx);
  29222. * ```
  29223. *
  29224. * @return Concrete dim name.
  29225. */
  29226. SeriesData.prototype.getDimension = function (dim) {
  29227. var dimIdx = this._recognizeDimIndex(dim);
  29228. if (dimIdx == null) {
  29229. return dim;
  29230. }
  29231. dimIdx = dim;
  29232. if (!this._dimOmitted) {
  29233. return this.dimensions[dimIdx];
  29234. } // Retrieve from series dimension definition becuase it probably contains
  29235. // generated dimension name (like 'x', 'y').
  29236. var dimName = this._dimIdxToName.get(dimIdx);
  29237. if (dimName != null) {
  29238. return dimName;
  29239. }
  29240. var sourceDimDef = this._schema.getSourceDimension(dimIdx);
  29241. if (sourceDimDef) {
  29242. return sourceDimDef.name;
  29243. }
  29244. };
  29245. /**
  29246. * Get dimension index in data store. Return -1 if not found.
  29247. * Can be used to index value from getRawValue.
  29248. */
  29249. SeriesData.prototype.getDimensionIndex = function (dim) {
  29250. var dimIdx = this._recognizeDimIndex(dim);
  29251. if (dimIdx != null) {
  29252. return dimIdx;
  29253. }
  29254. if (dim == null) {
  29255. return -1;
  29256. }
  29257. var dimInfo = this._getDimInfo(dim);
  29258. return dimInfo ? dimInfo.storeDimIndex : this._dimOmitted ? this._schema.getSourceDimensionIndex(dim) : -1;
  29259. };
  29260. /**
  29261. * The meanings of the input parameter `dim`:
  29262. *
  29263. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  29264. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  29265. * + If dim is a number-like string (e.g., `"1"`):
  29266. * + If there is the same concrete dim name defined in `series.dimensions` or `dataset.dimensions`,
  29267. * it means that concrete name.
  29268. * + If not, it will be converted to a number, which means the index of the dimension.
  29269. * (why? because of the backward compatbility. We have been tolerating number-like string in
  29270. * dimension setting, although now it seems that it is not a good idea.)
  29271. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  29272. * if no dimension name is defined as `"1"`.
  29273. * + If dim is a not-number-like string, it means the concrete dim name.
  29274. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  29275. * or customized in `dimensions` property of option like `"age"`.
  29276. *
  29277. * @return recogonized `DimensionIndex`. Otherwise return null/undefined (means that dim is `DimensionName`).
  29278. */
  29279. SeriesData.prototype._recognizeDimIndex = function (dim) {
  29280. if (typeof dim === 'number' // If being a number-like string but not being defined as a dimension name.
  29281. || dim != null && !isNaN(dim) && !this._getDimInfo(dim) && (!this._dimOmitted || this._schema.getSourceDimensionIndex(dim) < 0)) {
  29282. return +dim;
  29283. }
  29284. };
  29285. SeriesData.prototype._getStoreDimIndex = function (dim) {
  29286. var dimIdx = this.getDimensionIndex(dim);
  29287. if ("development" !== 'production') {
  29288. if (dimIdx == null) {
  29289. throw new Error('Unkown dimension ' + dim);
  29290. }
  29291. }
  29292. return dimIdx;
  29293. };
  29294. /**
  29295. * Get type and calculation info of particular dimension
  29296. * @param dim
  29297. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  29298. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  29299. */
  29300. SeriesData.prototype.getDimensionInfo = function (dim) {
  29301. // Do not clone, because there may be categories in dimInfo.
  29302. return this._getDimInfo(this.getDimension(dim));
  29303. };
  29304. SeriesData.prototype._initGetDimensionInfo = function (needsHasOwn) {
  29305. var dimensionInfos = this._dimInfos;
  29306. this._getDimInfo = needsHasOwn ? function (dimName) {
  29307. return dimensionInfos.hasOwnProperty(dimName) ? dimensionInfos[dimName] : undefined;
  29308. } : function (dimName) {
  29309. return dimensionInfos[dimName];
  29310. };
  29311. };
  29312. /**
  29313. * concrete dimension name list on coord.
  29314. */
  29315. SeriesData.prototype.getDimensionsOnCoord = function () {
  29316. return this._dimSummary.dataDimsOnCoord.slice();
  29317. };
  29318. SeriesData.prototype.mapDimension = function (coordDim, idx) {
  29319. var dimensionsSummary = this._dimSummary;
  29320. if (idx == null) {
  29321. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  29322. }
  29323. var dims = dimensionsSummary.encode[coordDim];
  29324. return dims ? dims[idx] : null;
  29325. };
  29326. SeriesData.prototype.mapDimensionsAll = function (coordDim) {
  29327. var dimensionsSummary = this._dimSummary;
  29328. var dims = dimensionsSummary.encode[coordDim];
  29329. return (dims || []).slice();
  29330. };
  29331. SeriesData.prototype.getStore = function () {
  29332. return this._store;
  29333. };
  29334. /**
  29335. * Initialize from data
  29336. * @param data source or data or data store.
  29337. * @param nameList The name of a datum is used on data diff and
  29338. * default label/tooltip.
  29339. * A name can be specified in encode.itemName,
  29340. * or dataItem.name (only for series option data),
  29341. * or provided in nameList from outside.
  29342. */
  29343. SeriesData.prototype.initData = function (data, nameList, dimValueGetter) {
  29344. var _this = this;
  29345. var store;
  29346. if (data instanceof DataStore) {
  29347. store = data;
  29348. }
  29349. if (!store) {
  29350. var dimensions = this.dimensions;
  29351. var provider = isSourceInstance(data) || isArrayLike(data) ? new DefaultDataProvider(data, dimensions.length) : data;
  29352. store = new DataStore();
  29353. var dimensionInfos = map$1(dimensions, function (dimName) {
  29354. return {
  29355. type: _this._dimInfos[dimName].type,
  29356. property: dimName
  29357. };
  29358. });
  29359. store.initData(provider, dimensionInfos, dimValueGetter);
  29360. }
  29361. this._store = store; // Reset
  29362. this._nameList = (nameList || []).slice();
  29363. this._idList = [];
  29364. this._nameRepeatCount = {};
  29365. this._doInit(0, store.count()); // Cache summary info for fast visit. See "dimensionHelper".
  29366. // Needs to be initialized after store is prepared.
  29367. this._dimSummary = summarizeDimensions(this, this._schema);
  29368. this.userOutput = this._dimSummary.userOutput;
  29369. };
  29370. /**
  29371. * Caution: Can be only called on raw data (before `this._indices` created).
  29372. */
  29373. SeriesData.prototype.appendData = function (data) {
  29374. var range = this._store.appendData(data);
  29375. this._doInit(range[0], range[1]);
  29376. };
  29377. /**
  29378. * Caution: Can be only called on raw data (before `this._indices` created).
  29379. * This method does not modify `rawData` (`dataProvider`), but only
  29380. * add values to store.
  29381. *
  29382. * The final count will be increased by `Math.max(values.length, names.length)`.
  29383. *
  29384. * @param values That is the SourceType: 'arrayRows', like
  29385. * [
  29386. * [12, 33, 44],
  29387. * [NaN, 43, 1],
  29388. * ['-', 'asdf', 0]
  29389. * ]
  29390. * Each item is exaclty cooresponding to a dimension.
  29391. */
  29392. SeriesData.prototype.appendValues = function (values, names) {
  29393. var _a = this._store.appendValues(values, names.length),
  29394. start = _a.start,
  29395. end = _a.end;
  29396. var shouldMakeIdFromName = this._shouldMakeIdFromName();
  29397. this._updateOrdinalMeta();
  29398. if (names) {
  29399. for (var idx = start; idx < end; idx++) {
  29400. var sourceIdx = idx - start;
  29401. this._nameList[idx] = names[sourceIdx];
  29402. if (shouldMakeIdFromName) {
  29403. makeIdFromName(this, idx);
  29404. }
  29405. }
  29406. }
  29407. };
  29408. SeriesData.prototype._updateOrdinalMeta = function () {
  29409. var store = this._store;
  29410. var dimensions = this.dimensions;
  29411. for (var i = 0; i < dimensions.length; i++) {
  29412. var dimInfo = this._dimInfos[dimensions[i]];
  29413. if (dimInfo.ordinalMeta) {
  29414. store.collectOrdinalMeta(dimInfo.storeDimIndex, dimInfo.ordinalMeta);
  29415. }
  29416. }
  29417. };
  29418. SeriesData.prototype._shouldMakeIdFromName = function () {
  29419. var provider = this._store.getProvider();
  29420. return this._idDimIdx == null && provider.getSource().sourceFormat !== SOURCE_FORMAT_TYPED_ARRAY && !provider.fillStorage;
  29421. };
  29422. SeriesData.prototype._doInit = function (start, end) {
  29423. if (start >= end) {
  29424. return;
  29425. }
  29426. var store = this._store;
  29427. var provider = store.getProvider();
  29428. this._updateOrdinalMeta();
  29429. var nameList = this._nameList;
  29430. var idList = this._idList;
  29431. var sourceFormat = provider.getSource().sourceFormat;
  29432. var isFormatOriginal = sourceFormat === SOURCE_FORMAT_ORIGINAL; // Each data item is value
  29433. // [1, 2]
  29434. // 2
  29435. // Bar chart, line chart which uses category axis
  29436. // only gives the 'y' value. 'x' value is the indices of category
  29437. // Use a tempValue to normalize the value to be a (x, y) value
  29438. // If dataItem is {name: ...} or {id: ...}, it has highest priority.
  29439. // This kind of ids and names are always stored `_nameList` and `_idList`.
  29440. if (isFormatOriginal && !provider.pure) {
  29441. var sharedDataItem = [];
  29442. for (var idx = start; idx < end; idx++) {
  29443. // NOTICE: Try not to write things into dataItem
  29444. var dataItem = provider.getItem(idx, sharedDataItem);
  29445. if (!this.hasItemOption && isDataItemOption(dataItem)) {
  29446. this.hasItemOption = true;
  29447. }
  29448. if (dataItem) {
  29449. var itemName = dataItem.name;
  29450. if (nameList[idx] == null && itemName != null) {
  29451. nameList[idx] = convertOptionIdName(itemName, null);
  29452. }
  29453. var itemId = dataItem.id;
  29454. if (idList[idx] == null && itemId != null) {
  29455. idList[idx] = convertOptionIdName(itemId, null);
  29456. }
  29457. }
  29458. }
  29459. }
  29460. if (this._shouldMakeIdFromName()) {
  29461. for (var idx = start; idx < end; idx++) {
  29462. makeIdFromName(this, idx);
  29463. }
  29464. }
  29465. prepareInvertedIndex(this);
  29466. };
  29467. /**
  29468. * PENDING: In fact currently this function is only used to short-circuit
  29469. * the calling of `scale.unionExtentFromData` when data have been filtered by modules
  29470. * like "dataZoom". `scale.unionExtentFromData` is used to calculate data extent for series on
  29471. * an axis, but if a "axis related data filter module" is used, the extent of the axis have
  29472. * been fixed and no need to calling `scale.unionExtentFromData` actually.
  29473. * But if we add "custom data filter" in future, which is not "axis related", this method may
  29474. * be still needed.
  29475. *
  29476. * Optimize for the scenario that data is filtered by a given extent.
  29477. * Consider that if data amount is more than hundreds of thousand,
  29478. * extent calculation will cost more than 10ms and the cache will
  29479. * be erased because of the filtering.
  29480. */
  29481. SeriesData.prototype.getApproximateExtent = function (dim) {
  29482. return this._approximateExtent[dim] || this._store.getDataExtent(this._getStoreDimIndex(dim));
  29483. };
  29484. /**
  29485. * Calculate extent on a filtered data might be time consuming.
  29486. * Approximate extent is only used for: calculte extent of filtered data outside.
  29487. */
  29488. SeriesData.prototype.setApproximateExtent = function (extent, dim) {
  29489. dim = this.getDimension(dim);
  29490. this._approximateExtent[dim] = extent.slice();
  29491. };
  29492. SeriesData.prototype.getCalculationInfo = function (key) {
  29493. return this._calculationInfo[key];
  29494. };
  29495. SeriesData.prototype.setCalculationInfo = function (key, value) {
  29496. isObject$2(key) ? extend(this._calculationInfo, key) : this._calculationInfo[key] = value;
  29497. };
  29498. /**
  29499. * @return Never be null/undefined. `number` will be converted to string. Becuase:
  29500. * In most cases, name is used in display, where returning a string is more convenient.
  29501. * In other cases, name is used in query (see `indexOfName`), where we can keep the
  29502. * rule that name `2` equals to name `'2'`.
  29503. */
  29504. SeriesData.prototype.getName = function (idx) {
  29505. var rawIndex = this.getRawIndex(idx);
  29506. var name = this._nameList[rawIndex];
  29507. if (name == null && this._nameDimIdx != null) {
  29508. name = getIdNameFromStore(this, this._nameDimIdx, rawIndex);
  29509. }
  29510. if (name == null) {
  29511. name = '';
  29512. }
  29513. return name;
  29514. };
  29515. SeriesData.prototype._getCategory = function (dimIdx, idx) {
  29516. var ordinal = this._store.get(dimIdx, idx);
  29517. var ordinalMeta = this._store.getOrdinalMeta(dimIdx);
  29518. if (ordinalMeta) {
  29519. return ordinalMeta.categories[ordinal];
  29520. }
  29521. return ordinal;
  29522. };
  29523. /**
  29524. * @return Never null/undefined. `number` will be converted to string. Becuase:
  29525. * In all cases having encountered at present, id is used in making diff comparison, which
  29526. * are usually based on hash map. We can keep the rule that the internal id are always string
  29527. * (treat `2` is the same as `'2'`) to make the related logic simple.
  29528. */
  29529. SeriesData.prototype.getId = function (idx) {
  29530. return getId(this, this.getRawIndex(idx));
  29531. };
  29532. SeriesData.prototype.count = function () {
  29533. return this._store.count();
  29534. };
  29535. /**
  29536. * Get value. Return NaN if idx is out of range.
  29537. *
  29538. * @notice Should better to use `data.getStore().get(dimIndex, dataIdx)` instead.
  29539. */
  29540. SeriesData.prototype.get = function (dim, idx) {
  29541. var store = this._store;
  29542. var dimInfo = this._dimInfos[dim];
  29543. if (dimInfo) {
  29544. return store.get(dimInfo.storeDimIndex, idx);
  29545. }
  29546. };
  29547. /**
  29548. * @notice Should better to use `data.getStore().getByRawIndex(dimIndex, dataIdx)` instead.
  29549. */
  29550. SeriesData.prototype.getByRawIndex = function (dim, rawIdx) {
  29551. var store = this._store;
  29552. var dimInfo = this._dimInfos[dim];
  29553. if (dimInfo) {
  29554. return store.getByRawIndex(dimInfo.storeDimIndex, rawIdx);
  29555. }
  29556. };
  29557. SeriesData.prototype.getIndices = function () {
  29558. return this._store.getIndices();
  29559. };
  29560. SeriesData.prototype.getDataExtent = function (dim) {
  29561. return this._store.getDataExtent(this._getStoreDimIndex(dim));
  29562. };
  29563. SeriesData.prototype.getSum = function (dim) {
  29564. return this._store.getSum(this._getStoreDimIndex(dim));
  29565. };
  29566. SeriesData.prototype.getMedian = function (dim) {
  29567. return this._store.getMedian(this._getStoreDimIndex(dim));
  29568. };
  29569. SeriesData.prototype.getValues = function (dimensions, idx) {
  29570. var _this = this;
  29571. var store = this._store;
  29572. return isArray(dimensions) ? store.getValues(map$1(dimensions, function (dim) {
  29573. return _this._getStoreDimIndex(dim);
  29574. }), idx) : store.getValues(dimensions);
  29575. };
  29576. /**
  29577. * If value is NaN. Inlcuding '-'
  29578. * Only check the coord dimensions.
  29579. */
  29580. SeriesData.prototype.hasValue = function (idx) {
  29581. var dataDimIndicesOnCoord = this._dimSummary.dataDimIndicesOnCoord;
  29582. for (var i = 0, len = dataDimIndicesOnCoord.length; i < len; i++) {
  29583. // Ordinal type originally can be string or number.
  29584. // But when an ordinal type is used on coord, it can
  29585. // not be string but only number. So we can also use isNaN.
  29586. if (isNaN(this._store.get(dataDimIndicesOnCoord[i], idx))) {
  29587. return false;
  29588. }
  29589. }
  29590. return true;
  29591. };
  29592. /**
  29593. * Retreive the index with given name
  29594. */
  29595. SeriesData.prototype.indexOfName = function (name) {
  29596. for (var i = 0, len = this._store.count(); i < len; i++) {
  29597. if (this.getName(i) === name) {
  29598. return i;
  29599. }
  29600. }
  29601. return -1;
  29602. };
  29603. SeriesData.prototype.getRawIndex = function (idx) {
  29604. return this._store.getRawIndex(idx);
  29605. };
  29606. SeriesData.prototype.indexOfRawIndex = function (rawIndex) {
  29607. return this._store.indexOfRawIndex(rawIndex);
  29608. };
  29609. /**
  29610. * Only support the dimension which inverted index created.
  29611. * Do not support other cases until required.
  29612. * @param dim concrete dim
  29613. * @param value ordinal index
  29614. * @return rawIndex
  29615. */
  29616. SeriesData.prototype.rawIndexOf = function (dim, value) {
  29617. var invertedIndices = dim && this._invertedIndicesMap[dim];
  29618. if ("development" !== 'production') {
  29619. if (!invertedIndices) {
  29620. throw new Error('Do not supported yet');
  29621. }
  29622. }
  29623. var rawIndex = invertedIndices[value];
  29624. if (rawIndex == null || isNaN(rawIndex)) {
  29625. return INDEX_NOT_FOUND;
  29626. }
  29627. return rawIndex;
  29628. };
  29629. /**
  29630. * Retreive the index of nearest value
  29631. * @param dim
  29632. * @param value
  29633. * @param [maxDistance=Infinity]
  29634. * @return If and only if multiple indices has
  29635. * the same value, they are put to the result.
  29636. */
  29637. SeriesData.prototype.indicesOfNearest = function (dim, value, maxDistance) {
  29638. return this._store.indicesOfNearest(this._getStoreDimIndex(dim), value, maxDistance);
  29639. };
  29640. SeriesData.prototype.each = function (dims, cb, ctx) {
  29641. if (typeof dims === 'function') {
  29642. ctx = cb;
  29643. cb = dims;
  29644. dims = [];
  29645. } // ctxCompat just for compat echarts3
  29646. var fCtx = ctx || this;
  29647. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29648. this._store.each(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29649. };
  29650. SeriesData.prototype.filterSelf = function (dims, cb, ctx) {
  29651. if (typeof dims === 'function') {
  29652. ctx = cb;
  29653. cb = dims;
  29654. dims = [];
  29655. } // ctxCompat just for compat echarts3
  29656. var fCtx = ctx || this;
  29657. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29658. this._store = this._store.filter(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29659. return this;
  29660. };
  29661. /**
  29662. * Select data in range. (For optimization of filter)
  29663. * (Manually inline code, support 5 million data filtering in data zoom.)
  29664. */
  29665. SeriesData.prototype.selectRange = function (range) {
  29666. var _this = this;
  29667. var innerRange = {};
  29668. var dims = keys(range);
  29669. each(dims, function (dim) {
  29670. var dimIdx = _this._getStoreDimIndex(dim);
  29671. innerRange[dimIdx] = range[dim];
  29672. });
  29673. this._store = this._store.selectRange(innerRange);
  29674. return this;
  29675. };
  29676. /* eslint-enable max-len */
  29677. SeriesData.prototype.mapArray = function (dims, cb, ctx) {
  29678. if (typeof dims === 'function') {
  29679. ctx = cb;
  29680. cb = dims;
  29681. dims = [];
  29682. } // ctxCompat just for compat echarts3
  29683. ctx = ctx || this;
  29684. var result = [];
  29685. this.each(dims, function () {
  29686. result.push(cb && cb.apply(this, arguments));
  29687. }, ctx);
  29688. return result;
  29689. };
  29690. SeriesData.prototype.map = function (dims, cb, ctx, ctxCompat) {
  29691. var fCtx = ctx || ctxCompat || this;
  29692. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  29693. var list = cloneListForMapAndSample(this);
  29694. list._store = this._store.map(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29695. return list;
  29696. };
  29697. SeriesData.prototype.modify = function (dims, cb, ctx, ctxCompat) {
  29698. var _this = this; // ctxCompat just for compat echarts3
  29699. var fCtx = ctx || ctxCompat || this;
  29700. if ("development" !== 'production') {
  29701. each(normalizeDimensions(dims), function (dim) {
  29702. var dimInfo = _this.getDimensionInfo(dim);
  29703. if (!dimInfo.isCalculationCoord) {
  29704. console.error('Danger: only stack dimension can be modified');
  29705. }
  29706. });
  29707. }
  29708. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this); // If do shallow clone here, if there are too many stacked series,
  29709. // it still cost lots of memory, becuase `_store.dimensions` are not shared.
  29710. // We should consider there probably be shallow clone happen in each sereis
  29711. // in consequent filter/map.
  29712. this._store.modify(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  29713. };
  29714. /**
  29715. * Large data down sampling on given dimension
  29716. * @param sampleIndex Sample index for name and id
  29717. */
  29718. SeriesData.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  29719. var list = cloneListForMapAndSample(this);
  29720. list._store = this._store.downSample(this._getStoreDimIndex(dimension), rate, sampleValue, sampleIndex);
  29721. return list;
  29722. };
  29723. /**
  29724. * Large data down sampling using largest-triangle-three-buckets
  29725. * @param {string} valueDimension
  29726. * @param {number} targetCount
  29727. */
  29728. SeriesData.prototype.lttbDownSample = function (valueDimension, rate) {
  29729. var list = cloneListForMapAndSample(this);
  29730. list._store = this._store.lttbDownSample(this._getStoreDimIndex(valueDimension), rate);
  29731. return list;
  29732. };
  29733. SeriesData.prototype.getRawDataItem = function (idx) {
  29734. return this._store.getRawDataItem(idx);
  29735. };
  29736. /**
  29737. * Get model of one data item.
  29738. */
  29739. // TODO: Type of data item
  29740. SeriesData.prototype.getItemModel = function (idx) {
  29741. var hostModel = this.hostModel;
  29742. var dataItem = this.getRawDataItem(idx);
  29743. return new Model(dataItem, hostModel, hostModel && hostModel.ecModel);
  29744. };
  29745. /**
  29746. * Create a data differ
  29747. */
  29748. SeriesData.prototype.diff = function (otherList) {
  29749. var thisList = this;
  29750. return new DataDiffer(otherList ? otherList.getStore().getIndices() : [], this.getStore().getIndices(), function (idx) {
  29751. return getId(otherList, idx);
  29752. }, function (idx) {
  29753. return getId(thisList, idx);
  29754. });
  29755. };
  29756. /**
  29757. * Get visual property.
  29758. */
  29759. SeriesData.prototype.getVisual = function (key) {
  29760. var visual = this._visual;
  29761. return visual && visual[key];
  29762. };
  29763. SeriesData.prototype.setVisual = function (kvObj, val) {
  29764. this._visual = this._visual || {};
  29765. if (isObject$2(kvObj)) {
  29766. extend(this._visual, kvObj);
  29767. } else {
  29768. this._visual[kvObj] = val;
  29769. }
  29770. };
  29771. /**
  29772. * Get visual property of single data item
  29773. */
  29774. // eslint-disable-next-line
  29775. SeriesData.prototype.getItemVisual = function (idx, key) {
  29776. var itemVisual = this._itemVisuals[idx];
  29777. var val = itemVisual && itemVisual[key];
  29778. if (val == null) {
  29779. // Use global visual property
  29780. return this.getVisual(key);
  29781. }
  29782. return val;
  29783. };
  29784. /**
  29785. * If exists visual property of single data item
  29786. */
  29787. SeriesData.prototype.hasItemVisual = function () {
  29788. return this._itemVisuals.length > 0;
  29789. };
  29790. /**
  29791. * Make sure itemVisual property is unique
  29792. */
  29793. // TODO: use key to save visual to reduce memory.
  29794. SeriesData.prototype.ensureUniqueItemVisual = function (idx, key) {
  29795. var itemVisuals = this._itemVisuals;
  29796. var itemVisual = itemVisuals[idx];
  29797. if (!itemVisual) {
  29798. itemVisual = itemVisuals[idx] = {};
  29799. }
  29800. var val = itemVisual[key];
  29801. if (val == null) {
  29802. val = this.getVisual(key); // TODO Performance?
  29803. if (isArray(val)) {
  29804. val = val.slice();
  29805. } else if (isObject$2(val)) {
  29806. val = extend({}, val);
  29807. }
  29808. itemVisual[key] = val;
  29809. }
  29810. return val;
  29811. }; // eslint-disable-next-line
  29812. SeriesData.prototype.setItemVisual = function (idx, key, value) {
  29813. var itemVisual = this._itemVisuals[idx] || {};
  29814. this._itemVisuals[idx] = itemVisual;
  29815. if (isObject$2(key)) {
  29816. extend(itemVisual, key);
  29817. } else {
  29818. itemVisual[key] = value;
  29819. }
  29820. };
  29821. /**
  29822. * Clear itemVisuals and list visual.
  29823. */
  29824. SeriesData.prototype.clearAllVisual = function () {
  29825. this._visual = {};
  29826. this._itemVisuals = [];
  29827. };
  29828. SeriesData.prototype.setLayout = function (key, val) {
  29829. if (isObject$2(key)) {
  29830. for (var name_1 in key) {
  29831. if (key.hasOwnProperty(name_1)) {
  29832. this.setLayout(name_1, key[name_1]);
  29833. }
  29834. }
  29835. return;
  29836. }
  29837. this._layout[key] = val;
  29838. };
  29839. /**
  29840. * Get layout property.
  29841. */
  29842. SeriesData.prototype.getLayout = function (key) {
  29843. return this._layout[key];
  29844. };
  29845. /**
  29846. * Get layout of single data item
  29847. */
  29848. SeriesData.prototype.getItemLayout = function (idx) {
  29849. return this._itemLayouts[idx];
  29850. };
  29851. /**
  29852. * Set layout of single data item
  29853. */
  29854. SeriesData.prototype.setItemLayout = function (idx, layout, merge) {
  29855. this._itemLayouts[idx] = merge ? extend(this._itemLayouts[idx] || {}, layout) : layout;
  29856. };
  29857. /**
  29858. * Clear all layout of single data item
  29859. */
  29860. SeriesData.prototype.clearItemLayouts = function () {
  29861. this._itemLayouts.length = 0;
  29862. };
  29863. /**
  29864. * Set graphic element relative to data. It can be set as null
  29865. */
  29866. SeriesData.prototype.setItemGraphicEl = function (idx, el) {
  29867. var seriesIndex = this.hostModel && this.hostModel.seriesIndex;
  29868. setCommonECData(seriesIndex, this.dataType, idx, el);
  29869. this._graphicEls[idx] = el;
  29870. };
  29871. SeriesData.prototype.getItemGraphicEl = function (idx) {
  29872. return this._graphicEls[idx];
  29873. };
  29874. SeriesData.prototype.eachItemGraphicEl = function (cb, context) {
  29875. each(this._graphicEls, function (el, idx) {
  29876. if (el) {
  29877. cb && cb.call(context, el, idx);
  29878. }
  29879. });
  29880. };
  29881. /**
  29882. * Shallow clone a new list except visual and layout properties, and graph elements.
  29883. * New list only change the indices.
  29884. */
  29885. SeriesData.prototype.cloneShallow = function (list) {
  29886. if (!list) {
  29887. list = new SeriesData(this._schema ? this._schema : map$1(this.dimensions, this._getDimInfo, this), this.hostModel);
  29888. }
  29889. transferProperties(list, this);
  29890. list._store = this._store;
  29891. return list;
  29892. };
  29893. /**
  29894. * Wrap some method to add more feature
  29895. */
  29896. SeriesData.prototype.wrapMethod = function (methodName, injectFunction) {
  29897. var originalMethod = this[methodName];
  29898. if (typeof originalMethod !== 'function') {
  29899. return;
  29900. }
  29901. this.__wrappedMethods = this.__wrappedMethods || [];
  29902. this.__wrappedMethods.push(methodName);
  29903. this[methodName] = function () {
  29904. var res = originalMethod.apply(this, arguments);
  29905. return injectFunction.apply(this, [res].concat(slice(arguments)));
  29906. };
  29907. }; // ----------------------------------------------------------
  29908. // A work around for internal method visiting private member.
  29909. // ----------------------------------------------------------
  29910. SeriesData.internalField = function () {
  29911. prepareInvertedIndex = function (data) {
  29912. var invertedIndicesMap = data._invertedIndicesMap;
  29913. each(invertedIndicesMap, function (invertedIndices, dim) {
  29914. var dimInfo = data._dimInfos[dim]; // Currently, only dimensions that has ordinalMeta can create inverted indices.
  29915. var ordinalMeta = dimInfo.ordinalMeta;
  29916. var store = data._store;
  29917. if (ordinalMeta) {
  29918. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array$1(ordinalMeta.categories.length); // The default value of TypedArray is 0. To avoid miss
  29919. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  29920. for (var i = 0; i < invertedIndices.length; i++) {
  29921. invertedIndices[i] = INDEX_NOT_FOUND;
  29922. }
  29923. for (var i = 0; i < store.count(); i++) {
  29924. // Only support the case that all values are distinct.
  29925. invertedIndices[store.get(dimInfo.storeDimIndex, i)] = i;
  29926. }
  29927. }
  29928. });
  29929. };
  29930. getIdNameFromStore = function (data, dimIdx, idx) {
  29931. return convertOptionIdName(data._getCategory(dimIdx, idx), null);
  29932. };
  29933. /**
  29934. * @see the comment of `List['getId']`.
  29935. */
  29936. getId = function (data, rawIndex) {
  29937. var id = data._idList[rawIndex];
  29938. if (id == null && data._idDimIdx != null) {
  29939. id = getIdNameFromStore(data, data._idDimIdx, rawIndex);
  29940. }
  29941. if (id == null) {
  29942. id = ID_PREFIX + rawIndex;
  29943. }
  29944. return id;
  29945. };
  29946. normalizeDimensions = function (dimensions) {
  29947. if (!isArray(dimensions)) {
  29948. dimensions = dimensions != null ? [dimensions] : [];
  29949. }
  29950. return dimensions;
  29951. };
  29952. /**
  29953. * Data in excludeDimensions is copied, otherwise transfered.
  29954. */
  29955. cloneListForMapAndSample = function (original) {
  29956. var list = new SeriesData(original._schema ? original._schema : map$1(original.dimensions, original._getDimInfo, original), original.hostModel); // FIXME If needs stackedOn, value may already been stacked
  29957. transferProperties(list, original);
  29958. return list;
  29959. };
  29960. transferProperties = function (target, source) {
  29961. each(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  29962. if (source.hasOwnProperty(propName)) {
  29963. target[propName] = source[propName];
  29964. }
  29965. });
  29966. target.__wrappedMethods = source.__wrappedMethods;
  29967. each(CLONE_PROPERTIES, function (propName) {
  29968. target[propName] = clone(source[propName]);
  29969. });
  29970. target._calculationInfo = extend({}, source._calculationInfo);
  29971. };
  29972. makeIdFromName = function (data, idx) {
  29973. var nameList = data._nameList;
  29974. var idList = data._idList;
  29975. var nameDimIdx = data._nameDimIdx;
  29976. var idDimIdx = data._idDimIdx;
  29977. var name = nameList[idx];
  29978. var id = idList[idx];
  29979. if (name == null && nameDimIdx != null) {
  29980. nameList[idx] = name = getIdNameFromStore(data, nameDimIdx, idx);
  29981. }
  29982. if (id == null && idDimIdx != null) {
  29983. idList[idx] = id = getIdNameFromStore(data, idDimIdx, idx);
  29984. }
  29985. if (id == null && name != null) {
  29986. var nameRepeatCount = data._nameRepeatCount;
  29987. var nmCnt = nameRepeatCount[name] = (nameRepeatCount[name] || 0) + 1;
  29988. id = name;
  29989. if (nmCnt > 1) {
  29990. id += '__ec__' + nmCnt;
  29991. }
  29992. idList[idx] = id;
  29993. }
  29994. };
  29995. }();
  29996. return SeriesData;
  29997. }();
  29998. /**
  29999. * For outside usage compat (like echarts-gl are using it).
  30000. */
  30001. function createDimensions(source, opt) {
  30002. return prepareSeriesDataSchema(source, opt).dimensions;
  30003. }
  30004. /**
  30005. * This method builds the relationship between:
  30006. * + "what the coord sys or series requires (see `coordDimensions`)",
  30007. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimensionsDefine` and `opt.encodeDefine`)"
  30008. * + "what the data source provids (see `source`)".
  30009. *
  30010. * Some guess strategy will be adapted if user does not define something.
  30011. * If no 'value' dimension specified, the first no-named dimension will be
  30012. * named as 'value'.
  30013. *
  30014. * @return The results are always sorted by `storeDimIndex` asc.
  30015. */
  30016. function prepareSeriesDataSchema( // TODO: TYPE completeDimensions type
  30017. source, opt) {
  30018. if (!isSourceInstance(source)) {
  30019. source = createSourceFromSeriesDataOption(source);
  30020. }
  30021. opt = opt || {};
  30022. var sysDims = opt.coordDimensions || [];
  30023. var dimsDef = opt.dimensionsDefine || source.dimensionsDefine || [];
  30024. var coordDimNameMap = createHashMap();
  30025. var resultList = [];
  30026. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimensionsCount); // Try to ignore unsed dimensions if sharing a high dimension datastore
  30027. // 30 is an experience value.
  30028. var omitUnusedDimensions = opt.canOmitUnusedDimensions && shouldOmitUnusedDimensions(dimCount);
  30029. var isUsingSourceDimensionsDef = dimsDef === source.dimensionsDefine;
  30030. var dataDimNameMap = isUsingSourceDimensionsDef ? ensureSourceDimNameMap(source) : createDimNameMap(dimsDef);
  30031. var encodeDef = opt.encodeDefine;
  30032. if (!encodeDef && opt.encodeDefaulter) {
  30033. encodeDef = opt.encodeDefaulter(source, dimCount);
  30034. }
  30035. var encodeDefMap = createHashMap(encodeDef);
  30036. var indicesMap = new CtorInt32Array(dimCount);
  30037. for (var i = 0; i < indicesMap.length; i++) {
  30038. indicesMap[i] = -1;
  30039. }
  30040. function getResultItem(dimIdx) {
  30041. var idx = indicesMap[dimIdx];
  30042. if (idx < 0) {
  30043. var dimDefItemRaw = dimsDef[dimIdx];
  30044. var dimDefItem = isObject(dimDefItemRaw) ? dimDefItemRaw : {
  30045. name: dimDefItemRaw
  30046. };
  30047. var resultItem = new SeriesDimensionDefine();
  30048. var userDimName = dimDefItem.name;
  30049. if (userDimName != null && dataDimNameMap.get(userDimName) != null) {
  30050. // Only if `series.dimensions` is defined in option
  30051. // displayName, will be set, and dimension will be diplayed vertically in
  30052. // tooltip by default.
  30053. resultItem.name = resultItem.displayName = userDimName;
  30054. }
  30055. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  30056. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  30057. var newIdx = resultList.length;
  30058. indicesMap[dimIdx] = newIdx;
  30059. resultItem.storeDimIndex = dimIdx;
  30060. resultList.push(resultItem);
  30061. return resultItem;
  30062. }
  30063. return resultList[idx];
  30064. }
  30065. if (!omitUnusedDimensions) {
  30066. for (var i = 0; i < dimCount; i++) {
  30067. getResultItem(i);
  30068. }
  30069. } // Set `coordDim` and `coordDimIndex` by `encodeDefMap` and normalize `encodeDefMap`.
  30070. encodeDefMap.each(function (dataDimsRaw, coordDim) {
  30071. var dataDims = normalizeToArray(dataDimsRaw).slice(); // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  30072. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  30073. // this case.
  30074. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  30075. encodeDefMap.set(coordDim, false);
  30076. return;
  30077. }
  30078. var validDataDims = encodeDefMap.set(coordDim, []);
  30079. each(dataDims, function (resultDimIdxOrName, idx) {
  30080. // The input resultDimIdx can be dim name or index.
  30081. var resultDimIdx = isString(resultDimIdxOrName) ? dataDimNameMap.get(resultDimIdxOrName) : resultDimIdxOrName;
  30082. if (resultDimIdx != null && resultDimIdx < dimCount) {
  30083. validDataDims[idx] = resultDimIdx;
  30084. applyDim(getResultItem(resultDimIdx), coordDim, idx);
  30085. }
  30086. });
  30087. }); // Apply templetes and default order from `sysDims`.
  30088. var availDimIdx = 0;
  30089. each(sysDims, function (sysDimItemRaw) {
  30090. var coordDim;
  30091. var sysDimItemDimsDef;
  30092. var sysDimItemOtherDims;
  30093. var sysDimItem;
  30094. if (isString(sysDimItemRaw)) {
  30095. coordDim = sysDimItemRaw;
  30096. sysDimItem = {};
  30097. } else {
  30098. sysDimItem = sysDimItemRaw;
  30099. coordDim = sysDimItem.name;
  30100. var ordinalMeta = sysDimItem.ordinalMeta;
  30101. sysDimItem.ordinalMeta = null;
  30102. sysDimItem = extend({}, sysDimItem);
  30103. sysDimItem.ordinalMeta = ordinalMeta; // `coordDimIndex` should not be set directly.
  30104. sysDimItemDimsDef = sysDimItem.dimsDef;
  30105. sysDimItemOtherDims = sysDimItem.otherDims;
  30106. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  30107. }
  30108. var dataDims = encodeDefMap.get(coordDim); // negative resultDimIdx means no need to mapping.
  30109. if (dataDims === false) {
  30110. return;
  30111. }
  30112. dataDims = normalizeToArray(dataDims); // dimensions provides default dim sequences.
  30113. if (!dataDims.length) {
  30114. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  30115. while (availDimIdx < dimCount && getResultItem(availDimIdx).coordDim != null) {
  30116. availDimIdx++;
  30117. }
  30118. availDimIdx < dimCount && dataDims.push(availDimIdx++);
  30119. }
  30120. } // Apply templates.
  30121. each(dataDims, function (resultDimIdx, coordDimIndex) {
  30122. var resultItem = getResultItem(resultDimIdx); // Coordinate system has a higher priority on dim type than source.
  30123. if (isUsingSourceDimensionsDef && sysDimItem.type != null) {
  30124. resultItem.type = sysDimItem.type;
  30125. }
  30126. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  30127. if (resultItem.name == null && sysDimItemDimsDef) {
  30128. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  30129. !isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
  30130. name: sysDimItemDimsDefItem
  30131. });
  30132. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  30133. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  30134. } // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  30135. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  30136. });
  30137. });
  30138. function applyDim(resultItem, coordDim, coordDimIndex) {
  30139. if (VISUAL_DIMENSIONS.get(coordDim) != null) {
  30140. resultItem.otherDims[coordDim] = coordDimIndex;
  30141. } else {
  30142. resultItem.coordDim = coordDim;
  30143. resultItem.coordDimIndex = coordDimIndex;
  30144. coordDimNameMap.set(coordDim, true);
  30145. }
  30146. } // Make sure the first extra dim is 'value'.
  30147. var generateCoord = opt.generateCoord;
  30148. var generateCoordCount = opt.generateCoordCount;
  30149. var fromZero = generateCoordCount != null;
  30150. generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
  30151. var extra = generateCoord || 'value';
  30152. function ifNoNameFillWithCoordName(resultItem) {
  30153. if (resultItem.name == null) {
  30154. // Duplication will be removed in the next step.
  30155. resultItem.name = resultItem.coordDim;
  30156. }
  30157. } // Set dim `name` and other `coordDim` and other props.
  30158. if (!omitUnusedDimensions) {
  30159. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  30160. var resultItem = getResultItem(resultDimIdx);
  30161. var coordDim = resultItem.coordDim;
  30162. if (coordDim == null) {
  30163. // TODO no need to generate coordDim for isExtraCoord?
  30164. resultItem.coordDim = genCoordDimName(extra, coordDimNameMap, fromZero);
  30165. resultItem.coordDimIndex = 0; // Series specified generateCoord is using out.
  30166. if (!generateCoord || generateCoordCount <= 0) {
  30167. resultItem.isExtraCoord = true;
  30168. }
  30169. generateCoordCount--;
  30170. }
  30171. ifNoNameFillWithCoordName(resultItem);
  30172. if (resultItem.type == null && (guessOrdinal(source, resultDimIdx) === BE_ORDINAL.Must // Consider the case:
  30173. // {
  30174. // dataset: {source: [
  30175. // ['2001', 123],
  30176. // ['2002', 456],
  30177. // ...
  30178. // ['The others', 987],
  30179. // ]},
  30180. // series: {type: 'pie'}
  30181. // }
  30182. // The first colum should better be treated as a "ordinal" although it
  30183. // might not able to be detected as an "ordinal" by `guessOrdinal`.
  30184. || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
  30185. resultItem.type = 'ordinal';
  30186. }
  30187. }
  30188. } else {
  30189. each(resultList, function (resultItem) {
  30190. // PENDING: guessOrdinal or let user specify type: 'ordinal' manually?
  30191. ifNoNameFillWithCoordName(resultItem);
  30192. }); // Sort dimensions: there are some rule that use the last dim as label,
  30193. // and for some latter travel process easier.
  30194. resultList.sort(function (item0, item1) {
  30195. return item0.storeDimIndex - item1.storeDimIndex;
  30196. });
  30197. }
  30198. removeDuplication(resultList);
  30199. return new SeriesDataSchema({
  30200. source: source,
  30201. dimensions: resultList,
  30202. fullDimensionCount: dimCount,
  30203. dimensionOmitted: omitUnusedDimensions
  30204. });
  30205. }
  30206. function removeDuplication(result) {
  30207. var duplicationMap = createHashMap();
  30208. for (var i = 0; i < result.length; i++) {
  30209. var dim = result[i];
  30210. var dimOriginalName = dim.name;
  30211. var count = duplicationMap.get(dimOriginalName) || 0;
  30212. if (count > 0) {
  30213. // Starts from 0.
  30214. dim.name = dimOriginalName + (count - 1);
  30215. }
  30216. count++;
  30217. duplicationMap.set(dimOriginalName, count);
  30218. }
  30219. } // ??? TODO
  30220. // Originally detect dimCount by data[0]. Should we
  30221. // optimize it to only by sysDims and dimensions and encode.
  30222. // So only necessary dims will be initialized.
  30223. // But
  30224. // (1) custom series should be considered. where other dims
  30225. // may be visited.
  30226. // (2) sometimes user need to calcualte bubble size or use visualMap
  30227. // on other dimensions besides coordSys needed.
  30228. // So, dims that is not used by system, should be shared in data store?
  30229. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  30230. // Note that the result dimCount should not small than columns count
  30231. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  30232. var dimCount = Math.max(source.dimensionsDetectedCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
  30233. each(sysDims, function (sysDimItem) {
  30234. var sysDimItemDimsDef;
  30235. if (isObject(sysDimItem) && (sysDimItemDimsDef = sysDimItem.dimsDef)) {
  30236. dimCount = Math.max(dimCount, sysDimItemDimsDef.length);
  30237. }
  30238. });
  30239. return dimCount;
  30240. }
  30241. function genCoordDimName(name, map, fromZero) {
  30242. var mapData = map.data;
  30243. if (fromZero || mapData.hasOwnProperty(name)) {
  30244. var i = 0;
  30245. while (mapData.hasOwnProperty(name + i)) {
  30246. i++;
  30247. }
  30248. name += i;
  30249. }
  30250. map.set(name, true);
  30251. return name;
  30252. }
  30253. /**
  30254. * @class
  30255. * For example:
  30256. * {
  30257. * coordSysName: 'cartesian2d',
  30258. * coordSysDims: ['x', 'y', ...],
  30259. * axisMap: HashMap({
  30260. * x: xAxisModel,
  30261. * y: yAxisModel
  30262. * }),
  30263. * categoryAxisMap: HashMap({
  30264. * x: xAxisModel,
  30265. * y: undefined
  30266. * }),
  30267. * // The index of the first category axis in `coordSysDims`.
  30268. * // `null/undefined` means no category axis exists.
  30269. * firstCategoryDimIndex: 1,
  30270. * // To replace user specified encode.
  30271. * }
  30272. */
  30273. var CoordSysInfo =
  30274. /** @class */
  30275. function () {
  30276. function CoordSysInfo(coordSysName) {
  30277. this.coordSysDims = [];
  30278. this.axisMap = createHashMap();
  30279. this.categoryAxisMap = createHashMap();
  30280. this.coordSysName = coordSysName;
  30281. }
  30282. return CoordSysInfo;
  30283. }();
  30284. function getCoordSysInfoBySeries(seriesModel) {
  30285. var coordSysName = seriesModel.get('coordinateSystem');
  30286. var result = new CoordSysInfo(coordSysName);
  30287. var fetch = fetchers[coordSysName];
  30288. if (fetch) {
  30289. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  30290. return result;
  30291. }
  30292. }
  30293. var fetchers = {
  30294. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  30295. var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  30296. var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  30297. if ("development" !== 'production') {
  30298. if (!xAxisModel) {
  30299. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  30300. }
  30301. if (!yAxisModel) {
  30302. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  30303. }
  30304. }
  30305. result.coordSysDims = ['x', 'y'];
  30306. axisMap.set('x', xAxisModel);
  30307. axisMap.set('y', yAxisModel);
  30308. if (isCategory(xAxisModel)) {
  30309. categoryAxisMap.set('x', xAxisModel);
  30310. result.firstCategoryDimIndex = 0;
  30311. }
  30312. if (isCategory(yAxisModel)) {
  30313. categoryAxisMap.set('y', yAxisModel);
  30314. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  30315. }
  30316. },
  30317. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  30318. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  30319. if ("development" !== 'production') {
  30320. if (!singleAxisModel) {
  30321. throw new Error('singleAxis should be specified.');
  30322. }
  30323. }
  30324. result.coordSysDims = ['single'];
  30325. axisMap.set('single', singleAxisModel);
  30326. if (isCategory(singleAxisModel)) {
  30327. categoryAxisMap.set('single', singleAxisModel);
  30328. result.firstCategoryDimIndex = 0;
  30329. }
  30330. },
  30331. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  30332. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  30333. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  30334. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  30335. if ("development" !== 'production') {
  30336. if (!angleAxisModel) {
  30337. throw new Error('angleAxis option not found');
  30338. }
  30339. if (!radiusAxisModel) {
  30340. throw new Error('radiusAxis option not found');
  30341. }
  30342. }
  30343. result.coordSysDims = ['radius', 'angle'];
  30344. axisMap.set('radius', radiusAxisModel);
  30345. axisMap.set('angle', angleAxisModel);
  30346. if (isCategory(radiusAxisModel)) {
  30347. categoryAxisMap.set('radius', radiusAxisModel);
  30348. result.firstCategoryDimIndex = 0;
  30349. }
  30350. if (isCategory(angleAxisModel)) {
  30351. categoryAxisMap.set('angle', angleAxisModel);
  30352. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  30353. }
  30354. },
  30355. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  30356. result.coordSysDims = ['lng', 'lat'];
  30357. },
  30358. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  30359. var ecModel = seriesModel.ecModel;
  30360. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  30361. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  30362. each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  30363. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  30364. var axisDim = coordSysDims[index];
  30365. axisMap.set(axisDim, axisModel);
  30366. if (isCategory(axisModel)) {
  30367. categoryAxisMap.set(axisDim, axisModel);
  30368. if (result.firstCategoryDimIndex == null) {
  30369. result.firstCategoryDimIndex = index;
  30370. }
  30371. }
  30372. });
  30373. }
  30374. };
  30375. function isCategory(axisModel) {
  30376. return axisModel.get('type') === 'category';
  30377. }
  30378. /**
  30379. * Note that it is too complicated to support 3d stack by value
  30380. * (have to create two-dimension inverted index), so in 3d case
  30381. * we just support that stacked by index.
  30382. *
  30383. * @param seriesModel
  30384. * @param dimensionsInput The same as the input of <module:echarts/data/SeriesData>.
  30385. * The input will be modified.
  30386. * @param opt
  30387. * @param opt.stackedCoordDimension Specify a coord dimension if needed.
  30388. * @param opt.byIndex=false
  30389. * @return calculationInfo
  30390. * {
  30391. * stackedDimension: string
  30392. * stackedByDimension: string
  30393. * isStackedByIndex: boolean
  30394. * stackedOverDimension: string
  30395. * stackResultDimension: string
  30396. * }
  30397. */
  30398. function enableDataStack(seriesModel, dimensionsInput, opt) {
  30399. opt = opt || {};
  30400. var byIndex = opt.byIndex;
  30401. var stackedCoordDimension = opt.stackedCoordDimension;
  30402. var dimensionDefineList;
  30403. var schema;
  30404. var store;
  30405. if (isLegacyDimensionsInput(dimensionsInput)) {
  30406. dimensionDefineList = dimensionsInput;
  30407. } else {
  30408. schema = dimensionsInput.schema;
  30409. dimensionDefineList = schema.dimensions;
  30410. store = dimensionsInput.store;
  30411. } // Compatibal: when `stack` is set as '', do not stack.
  30412. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  30413. var stackedByDimInfo;
  30414. var stackedDimInfo;
  30415. var stackResultDimension;
  30416. var stackedOverDimension;
  30417. each(dimensionDefineList, function (dimensionInfo, index) {
  30418. if (isString(dimensionInfo)) {
  30419. dimensionDefineList[index] = dimensionInfo = {
  30420. name: dimensionInfo
  30421. };
  30422. }
  30423. if (mayStack && !dimensionInfo.isExtraCoord) {
  30424. // Find the first ordinal dimension as the stackedByDimInfo.
  30425. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  30426. stackedByDimInfo = dimensionInfo;
  30427. } // Find the first stackable dimension as the stackedDimInfo.
  30428. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  30429. stackedDimInfo = dimensionInfo;
  30430. }
  30431. }
  30432. });
  30433. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  30434. // Compatible with previous design, value axis (time axis) only stack by index.
  30435. // It may make sense if the user provides elaborately constructed data.
  30436. byIndex = true;
  30437. } // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  30438. // That put stack logic in List is for using conveniently in echarts extensions, but it
  30439. // might not be a good way.
  30440. if (stackedDimInfo) {
  30441. // Use a weird name that not duplicated with other names.
  30442. // Also need to use seriesModel.id as postfix because different
  30443. // series may share same data store. The stack dimension needs to be distinguished.
  30444. stackResultDimension = '__\0ecstackresult_' + seriesModel.id;
  30445. stackedOverDimension = '__\0ecstackedover_' + seriesModel.id; // Create inverted index to fast query index by value.
  30446. if (stackedByDimInfo) {
  30447. stackedByDimInfo.createInvertedIndices = true;
  30448. }
  30449. var stackedDimCoordDim_1 = stackedDimInfo.coordDim;
  30450. var stackedDimType = stackedDimInfo.type;
  30451. var stackedDimCoordIndex_1 = 0;
  30452. each(dimensionDefineList, function (dimensionInfo) {
  30453. if (dimensionInfo.coordDim === stackedDimCoordDim_1) {
  30454. stackedDimCoordIndex_1++;
  30455. }
  30456. });
  30457. var stackedOverDimensionDefine = {
  30458. name: stackResultDimension,
  30459. coordDim: stackedDimCoordDim_1,
  30460. coordDimIndex: stackedDimCoordIndex_1,
  30461. type: stackedDimType,
  30462. isExtraCoord: true,
  30463. isCalculationCoord: true,
  30464. storeDimIndex: dimensionDefineList.length
  30465. };
  30466. var stackResultDimensionDefine = {
  30467. name: stackedOverDimension,
  30468. // This dimension contains stack base (generally, 0), so do not set it as
  30469. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  30470. coordDim: stackedOverDimension,
  30471. coordDimIndex: stackedDimCoordIndex_1 + 1,
  30472. type: stackedDimType,
  30473. isExtraCoord: true,
  30474. isCalculationCoord: true,
  30475. storeDimIndex: dimensionDefineList.length + 1
  30476. };
  30477. if (schema) {
  30478. if (store) {
  30479. stackedOverDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackedOverDimension, stackedDimType);
  30480. stackResultDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackResultDimension, stackedDimType);
  30481. }
  30482. schema.appendCalculationDimension(stackedOverDimensionDefine);
  30483. schema.appendCalculationDimension(stackResultDimensionDefine);
  30484. } else {
  30485. dimensionDefineList.push(stackedOverDimensionDefine);
  30486. dimensionDefineList.push(stackResultDimensionDefine);
  30487. }
  30488. }
  30489. return {
  30490. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  30491. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  30492. isStackedByIndex: byIndex,
  30493. stackedOverDimension: stackedOverDimension,
  30494. stackResultDimension: stackResultDimension
  30495. };
  30496. }
  30497. function isLegacyDimensionsInput(dimensionsInput) {
  30498. return !isSeriesDataSchema(dimensionsInput.schema);
  30499. }
  30500. function isDimensionStacked(data, stackedDim) {
  30501. // Each single series only maps to one pair of axis. So we do not need to
  30502. // check stackByDim, whatever stacked by a dimension or stacked by index.
  30503. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  30504. }
  30505. function getStackedDimension(data, targetDim) {
  30506. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  30507. }
  30508. function getCoordSysDimDefs(seriesModel, coordSysInfo) {
  30509. var coordSysName = seriesModel.get('coordinateSystem');
  30510. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  30511. var coordSysDimDefs;
  30512. if (coordSysInfo && coordSysInfo.coordSysDims) {
  30513. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  30514. var dimInfo = {
  30515. name: dim
  30516. };
  30517. var axisModel = coordSysInfo.axisMap.get(dim);
  30518. if (axisModel) {
  30519. var axisType = axisModel.get('type');
  30520. dimInfo.type = getDimensionTypeByAxis(axisType);
  30521. }
  30522. return dimInfo;
  30523. });
  30524. }
  30525. if (!coordSysDimDefs) {
  30526. // Get dimensions from registered coordinate system
  30527. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  30528. }
  30529. return coordSysDimDefs;
  30530. }
  30531. function injectOrdinalMeta(dimInfoList, createInvertedIndices, coordSysInfo) {
  30532. var firstCategoryDimIndex;
  30533. var hasNameEncode;
  30534. coordSysInfo && each(dimInfoList, function (dimInfo, dimIndex) {
  30535. var coordDim = dimInfo.coordDim;
  30536. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  30537. if (categoryAxisModel) {
  30538. if (firstCategoryDimIndex == null) {
  30539. firstCategoryDimIndex = dimIndex;
  30540. }
  30541. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  30542. if (createInvertedIndices) {
  30543. dimInfo.createInvertedIndices = true;
  30544. }
  30545. }
  30546. if (dimInfo.otherDims.itemName != null) {
  30547. hasNameEncode = true;
  30548. }
  30549. });
  30550. if (!hasNameEncode && firstCategoryDimIndex != null) {
  30551. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  30552. }
  30553. return firstCategoryDimIndex;
  30554. }
  30555. /**
  30556. * Caution: there are side effects to `sourceManager` in this method.
  30557. * Should better only be called in `Series['getInitialData']`.
  30558. */
  30559. function createSeriesData(sourceRaw, seriesModel, opt) {
  30560. opt = opt || {};
  30561. var sourceManager = seriesModel.getSourceManager();
  30562. var source;
  30563. var isOriginalSource = false;
  30564. if (sourceRaw) {
  30565. isOriginalSource = true;
  30566. source = createSourceFromSeriesDataOption(sourceRaw);
  30567. } else {
  30568. source = sourceManager.getSource(); // Is series.data. not dataset.
  30569. isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
  30570. }
  30571. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  30572. var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
  30573. var useEncodeDefaulter = opt.useEncodeDefaulter;
  30574. var encodeDefaulter = isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
  30575. var createDimensionOptions = {
  30576. coordDimensions: coordSysDimDefs,
  30577. generateCoord: opt.generateCoord,
  30578. encodeDefine: seriesModel.getEncode(),
  30579. encodeDefaulter: encodeDefaulter,
  30580. canOmitUnusedDimensions: !isOriginalSource
  30581. };
  30582. var schema = prepareSeriesDataSchema(source, createDimensionOptions);
  30583. var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
  30584. var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
  30585. var stackCalculationInfo = enableDataStack(seriesModel, {
  30586. schema: schema,
  30587. store: store
  30588. });
  30589. var data = new SeriesData(schema, seriesModel);
  30590. data.setCalculationInfo(stackCalculationInfo);
  30591. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
  30592. // Use dataIndex as ordinal value in categoryAxis
  30593. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  30594. } : null;
  30595. data.hasItemOption = false;
  30596. data.initData( // Try to reuse the data store in sourceManager if using dataset.
  30597. isOriginalSource ? source : store, null, dimValueGetter);
  30598. return data;
  30599. }
  30600. function isNeedCompleteOrdinalData(source) {
  30601. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  30602. var sampleItem = firstDataNotNull(source.data || []);
  30603. return sampleItem != null && !isArray(getDataItemValue(sampleItem));
  30604. }
  30605. }
  30606. function firstDataNotNull(arr) {
  30607. var i = 0;
  30608. while (i < arr.length && arr[i] == null) {
  30609. i++;
  30610. }
  30611. return arr[i];
  30612. }
  30613. var Scale =
  30614. /** @class */
  30615. function () {
  30616. function Scale(setting) {
  30617. this._setting = setting || {};
  30618. this._extent = [Infinity, -Infinity];
  30619. }
  30620. Scale.prototype.getSetting = function (name) {
  30621. return this._setting[name];
  30622. };
  30623. /**
  30624. * Set extent from data
  30625. */
  30626. Scale.prototype.unionExtent = function (other) {
  30627. var extent = this._extent;
  30628. other[0] < extent[0] && (extent[0] = other[0]);
  30629. other[1] > extent[1] && (extent[1] = other[1]); // not setExtent because in log axis it may transformed to power
  30630. // this.setExtent(extent[0], extent[1]);
  30631. };
  30632. /**
  30633. * Set extent from data
  30634. */
  30635. Scale.prototype.unionExtentFromData = function (data, dim) {
  30636. this.unionExtent(data.getApproximateExtent(dim));
  30637. };
  30638. /**
  30639. * Get extent
  30640. *
  30641. * Extent is always in increase order.
  30642. */
  30643. Scale.prototype.getExtent = function () {
  30644. return this._extent.slice();
  30645. };
  30646. /**
  30647. * Set extent
  30648. */
  30649. Scale.prototype.setExtent = function (start, end) {
  30650. var thisExtent = this._extent;
  30651. if (!isNaN(start)) {
  30652. thisExtent[0] = start;
  30653. }
  30654. if (!isNaN(end)) {
  30655. thisExtent[1] = end;
  30656. }
  30657. };
  30658. /**
  30659. * If value is in extent range
  30660. */
  30661. Scale.prototype.isInExtentRange = function (value) {
  30662. return this._extent[0] <= value && this._extent[1] >= value;
  30663. };
  30664. /**
  30665. * When axis extent depends on data and no data exists,
  30666. * axis ticks should not be drawn, which is named 'blank'.
  30667. */
  30668. Scale.prototype.isBlank = function () {
  30669. return this._isBlank;
  30670. };
  30671. /**
  30672. * When axis extent depends on data and no data exists,
  30673. * axis ticks should not be drawn, which is named 'blank'.
  30674. */
  30675. Scale.prototype.setBlank = function (isBlank) {
  30676. this._isBlank = isBlank;
  30677. };
  30678. return Scale;
  30679. }();
  30680. enableClassManagement(Scale);
  30681. var uidBase = 0;
  30682. var OrdinalMeta =
  30683. /** @class */
  30684. function () {
  30685. function OrdinalMeta(opt) {
  30686. this.categories = opt.categories || [];
  30687. this._needCollect = opt.needCollect;
  30688. this._deduplication = opt.deduplication;
  30689. this.uid = ++uidBase;
  30690. }
  30691. OrdinalMeta.createByAxisModel = function (axisModel) {
  30692. var option = axisModel.option;
  30693. var data = option.data;
  30694. var categories = data && map(data, getName);
  30695. return new OrdinalMeta({
  30696. categories: categories,
  30697. needCollect: !categories,
  30698. // deduplication is default in axis.
  30699. deduplication: option.dedplication !== false
  30700. });
  30701. };
  30702. OrdinalMeta.prototype.getOrdinal = function (category) {
  30703. // @ts-ignore
  30704. return this._getOrCreateMap().get(category);
  30705. };
  30706. /**
  30707. * @return The ordinal. If not found, return NaN.
  30708. */
  30709. OrdinalMeta.prototype.parseAndCollect = function (category) {
  30710. var index;
  30711. var needCollect = this._needCollect; // The value of category dim can be the index of the given category set.
  30712. // This feature is only supported when !needCollect, because we should
  30713. // consider a common case: a value is 2017, which is a number but is
  30714. // expected to be tread as a category. This case usually happen in dataset,
  30715. // where it happent to be no need of the index feature.
  30716. if (typeof category !== 'string' && !needCollect) {
  30717. return category;
  30718. } // Optimize for the scenario:
  30719. // category is ['2012-01-01', '2012-01-02', ...], where the input
  30720. // data has been ensured not duplicate and is large data.
  30721. // Notice, if a dataset dimension provide categroies, usually echarts
  30722. // should remove duplication except user tell echarts dont do that
  30723. // (set axis.deduplication = false), because echarts do not know whether
  30724. // the values in the category dimension has duplication (consider the
  30725. // parallel-aqi example)
  30726. if (needCollect && !this._deduplication) {
  30727. index = this.categories.length;
  30728. this.categories[index] = category;
  30729. return index;
  30730. }
  30731. var map = this._getOrCreateMap(); // @ts-ignore
  30732. index = map.get(category);
  30733. if (index == null) {
  30734. if (needCollect) {
  30735. index = this.categories.length;
  30736. this.categories[index] = category; // @ts-ignore
  30737. map.set(category, index);
  30738. } else {
  30739. index = NaN;
  30740. }
  30741. }
  30742. return index;
  30743. }; // Consider big data, do not create map until needed.
  30744. OrdinalMeta.prototype._getOrCreateMap = function () {
  30745. return this._map || (this._map = createHashMap(this.categories));
  30746. };
  30747. return OrdinalMeta;
  30748. }();
  30749. function getName(obj) {
  30750. if (isObject(obj) && obj.value != null) {
  30751. return obj.value;
  30752. } else {
  30753. return obj + '';
  30754. }
  30755. }
  30756. var roundNumber = round;
  30757. /**
  30758. * @param extent Both extent[0] and extent[1] should be valid number.
  30759. * Should be extent[0] < extent[1].
  30760. * @param splitNumber splitNumber should be >= 1.
  30761. */
  30762. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  30763. var result = {};
  30764. var span = extent[1] - extent[0];
  30765. var interval = result.interval = nice(span / splitNumber, true);
  30766. if (minInterval != null && interval < minInterval) {
  30767. interval = result.interval = minInterval;
  30768. }
  30769. if (maxInterval != null && interval > maxInterval) {
  30770. interval = result.interval = maxInterval;
  30771. } // Tow more digital for tick.
  30772. var precision = result.intervalPrecision = getIntervalPrecision(interval); // Niced extent inside original extent
  30773. var niceTickExtent = result.niceTickExtent = [roundNumber(Math.ceil(extent[0] / interval) * interval, precision), roundNumber(Math.floor(extent[1] / interval) * interval, precision)];
  30774. fixExtent(niceTickExtent, extent);
  30775. return result;
  30776. }
  30777. /**
  30778. * @return interval precision
  30779. */
  30780. function getIntervalPrecision(interval) {
  30781. // Tow more digital for tick.
  30782. return getPrecision(interval) + 2;
  30783. }
  30784. function clamp(niceTickExtent, idx, extent) {
  30785. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  30786. } // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  30787. function fixExtent(niceTickExtent, extent) {
  30788. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  30789. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  30790. clamp(niceTickExtent, 0, extent);
  30791. clamp(niceTickExtent, 1, extent);
  30792. if (niceTickExtent[0] > niceTickExtent[1]) {
  30793. niceTickExtent[0] = niceTickExtent[1];
  30794. }
  30795. }
  30796. function contain$2(val, extent) {
  30797. return val >= extent[0] && val <= extent[1];
  30798. }
  30799. function normalize$1(val, extent) {
  30800. if (extent[1] === extent[0]) {
  30801. return 0.5;
  30802. }
  30803. return (val - extent[0]) / (extent[1] - extent[0]);
  30804. }
  30805. function scale$2(val, extent) {
  30806. return val * (extent[1] - extent[0]) + extent[0];
  30807. }
  30808. var OrdinalScale =
  30809. /** @class */
  30810. function (_super) {
  30811. __extends(OrdinalScale, _super);
  30812. function OrdinalScale(setting) {
  30813. var _this = _super.call(this, setting) || this;
  30814. _this.type = 'ordinal';
  30815. var ordinalMeta = _this.getSetting('ordinalMeta'); // Caution: Should not use instanceof, consider ec-extensions using
  30816. // import approach to get OrdinalMeta class.
  30817. if (!ordinalMeta) {
  30818. ordinalMeta = new OrdinalMeta({});
  30819. }
  30820. if (isArray(ordinalMeta)) {
  30821. ordinalMeta = new OrdinalMeta({
  30822. categories: map(ordinalMeta, function (item) {
  30823. return isObject(item) ? item.value : item;
  30824. })
  30825. });
  30826. }
  30827. _this._ordinalMeta = ordinalMeta;
  30828. _this._extent = _this.getSetting('extent') || [0, ordinalMeta.categories.length - 1];
  30829. return _this;
  30830. }
  30831. OrdinalScale.prototype.parse = function (val) {
  30832. return typeof val === 'string' ? this._ordinalMeta.getOrdinal(val) // val might be float.
  30833. : Math.round(val);
  30834. };
  30835. OrdinalScale.prototype.contain = function (rank) {
  30836. rank = this.parse(rank);
  30837. return contain$2(rank, this._extent) && this._ordinalMeta.categories[rank] != null;
  30838. };
  30839. /**
  30840. * Normalize given rank or name to linear [0, 1]
  30841. * @param val raw ordinal number.
  30842. * @return normalized value in [0, 1].
  30843. */
  30844. OrdinalScale.prototype.normalize = function (val) {
  30845. val = this._getTickNumber(this.parse(val));
  30846. return normalize$1(val, this._extent);
  30847. };
  30848. /**
  30849. * @param val normalized value in [0, 1].
  30850. * @return raw ordinal number.
  30851. */
  30852. OrdinalScale.prototype.scale = function (val) {
  30853. val = Math.round(scale$2(val, this._extent));
  30854. return this.getRawOrdinalNumber(val);
  30855. };
  30856. OrdinalScale.prototype.getTicks = function () {
  30857. var ticks = [];
  30858. var extent = this._extent;
  30859. var rank = extent[0];
  30860. while (rank <= extent[1]) {
  30861. ticks.push({
  30862. value: rank
  30863. });
  30864. rank++;
  30865. }
  30866. return ticks;
  30867. };
  30868. OrdinalScale.prototype.getMinorTicks = function (splitNumber) {
  30869. // Not support.
  30870. return;
  30871. };
  30872. /**
  30873. * @see `Ordinal['_ordinalNumbersByTick']`
  30874. */
  30875. OrdinalScale.prototype.setSortInfo = function (info) {
  30876. if (info == null) {
  30877. this._ordinalNumbersByTick = this._ticksByOrdinalNumber = null;
  30878. return;
  30879. }
  30880. var infoOrdinalNumbers = info.ordinalNumbers;
  30881. var ordinalsByTick = this._ordinalNumbersByTick = [];
  30882. var ticksByOrdinal = this._ticksByOrdinalNumber = []; // Unnecessary support negative tick in `realtimeSort`.
  30883. var tickNum = 0;
  30884. var allCategoryLen = this._ordinalMeta.categories.length;
  30885. for (var len = Math.min(allCategoryLen, infoOrdinalNumbers.length); tickNum < len; ++tickNum) {
  30886. var ordinalNumber = infoOrdinalNumbers[tickNum];
  30887. ordinalsByTick[tickNum] = ordinalNumber;
  30888. ticksByOrdinal[ordinalNumber] = tickNum;
  30889. } // Handle that `series.data` only covers part of the `axis.category.data`.
  30890. var unusedOrdinal = 0;
  30891. for (; tickNum < allCategoryLen; ++tickNum) {
  30892. while (ticksByOrdinal[unusedOrdinal] != null) {
  30893. unusedOrdinal++;
  30894. }
  30895. ordinalsByTick.push(unusedOrdinal);
  30896. ticksByOrdinal[unusedOrdinal] = tickNum;
  30897. }
  30898. };
  30899. OrdinalScale.prototype._getTickNumber = function (ordinal) {
  30900. var ticksByOrdinalNumber = this._ticksByOrdinalNumber; // also support ordinal out of range of `ordinalMeta.categories.length`,
  30901. // where ordinal numbers are used as tick value directly.
  30902. return ticksByOrdinalNumber && ordinal >= 0 && ordinal < ticksByOrdinalNumber.length ? ticksByOrdinalNumber[ordinal] : ordinal;
  30903. };
  30904. /**
  30905. * @usage
  30906. * ```js
  30907. * const ordinalNumber = ordinalScale.getRawOrdinalNumber(tickVal);
  30908. *
  30909. * // case0
  30910. * const rawOrdinalValue = axisModel.getCategories()[ordinalNumber];
  30911. * // case1
  30912. * const rawOrdinalValue = this._ordinalMeta.categories[ordinalNumber];
  30913. * // case2
  30914. * const coord = axis.dataToCoord(ordinalNumber);
  30915. * ```
  30916. *
  30917. * @param {OrdinalNumber} tickNumber index of display
  30918. */
  30919. OrdinalScale.prototype.getRawOrdinalNumber = function (tickNumber) {
  30920. var ordinalNumbersByTick = this._ordinalNumbersByTick; // tickNumber may be out of range, e.g., when axis max is larger than `ordinalMeta.categories.length`.,
  30921. // where ordinal numbers are used as tick value directly.
  30922. return ordinalNumbersByTick && tickNumber >= 0 && tickNumber < ordinalNumbersByTick.length ? ordinalNumbersByTick[tickNumber] : tickNumber;
  30923. };
  30924. /**
  30925. * Get item on tick
  30926. */
  30927. OrdinalScale.prototype.getLabel = function (tick) {
  30928. if (!this.isBlank()) {
  30929. var ordinalNumber = this.getRawOrdinalNumber(tick.value);
  30930. var cateogry = this._ordinalMeta.categories[ordinalNumber]; // Note that if no data, ordinalMeta.categories is an empty array.
  30931. // Return empty if it's not exist.
  30932. return cateogry == null ? '' : cateogry + '';
  30933. }
  30934. };
  30935. OrdinalScale.prototype.count = function () {
  30936. return this._extent[1] - this._extent[0] + 1;
  30937. };
  30938. OrdinalScale.prototype.unionExtentFromData = function (data, dim) {
  30939. this.unionExtent(data.getApproximateExtent(dim));
  30940. };
  30941. /**
  30942. * @override
  30943. * If value is in extent range
  30944. */
  30945. OrdinalScale.prototype.isInExtentRange = function (value) {
  30946. value = this._getTickNumber(value);
  30947. return this._extent[0] <= value && this._extent[1] >= value;
  30948. };
  30949. OrdinalScale.prototype.getOrdinalMeta = function () {
  30950. return this._ordinalMeta;
  30951. };
  30952. OrdinalScale.prototype.niceTicks = function () {};
  30953. OrdinalScale.prototype.niceExtent = function () {};
  30954. OrdinalScale.type = 'ordinal';
  30955. return OrdinalScale;
  30956. }(Scale);
  30957. Scale.registerClass(OrdinalScale);
  30958. var roundNumber$1 = round;
  30959. var IntervalScale =
  30960. /** @class */
  30961. function (_super) {
  30962. __extends(IntervalScale, _super);
  30963. function IntervalScale() {
  30964. var _this = _super !== null && _super.apply(this, arguments) || this;
  30965. _this.type = 'interval'; // Step is calculated in adjustExtent.
  30966. _this._interval = 0;
  30967. _this._intervalPrecision = 2;
  30968. return _this;
  30969. }
  30970. IntervalScale.prototype.parse = function (val) {
  30971. return val;
  30972. };
  30973. IntervalScale.prototype.contain = function (val) {
  30974. return contain$2(val, this._extent);
  30975. };
  30976. IntervalScale.prototype.normalize = function (val) {
  30977. return normalize$1(val, this._extent);
  30978. };
  30979. IntervalScale.prototype.scale = function (val) {
  30980. return scale$2(val, this._extent);
  30981. };
  30982. IntervalScale.prototype.setExtent = function (start, end) {
  30983. var thisExtent = this._extent; // start,end may be a Number like '25',so...
  30984. if (!isNaN(start)) {
  30985. thisExtent[0] = parseFloat(start);
  30986. }
  30987. if (!isNaN(end)) {
  30988. thisExtent[1] = parseFloat(end);
  30989. }
  30990. };
  30991. IntervalScale.prototype.unionExtent = function (other) {
  30992. var extent = this._extent;
  30993. other[0] < extent[0] && (extent[0] = other[0]);
  30994. other[1] > extent[1] && (extent[1] = other[1]); // unionExtent may called by it's sub classes
  30995. this.setExtent(extent[0], extent[1]);
  30996. };
  30997. IntervalScale.prototype.getInterval = function () {
  30998. return this._interval;
  30999. };
  31000. IntervalScale.prototype.setInterval = function (interval) {
  31001. this._interval = interval; // Dropped auto calculated niceExtent and use user setted extent
  31002. // We assume user wan't to set both interval, min, max to get a better result
  31003. this._niceExtent = this._extent.slice();
  31004. this._intervalPrecision = getIntervalPrecision(interval);
  31005. };
  31006. /**
  31007. * @param expandToNicedExtent Whether expand the ticks to niced extent.
  31008. */
  31009. IntervalScale.prototype.getTicks = function (expandToNicedExtent) {
  31010. var interval = this._interval;
  31011. var extent = this._extent;
  31012. var niceTickExtent = this._niceExtent;
  31013. var intervalPrecision = this._intervalPrecision;
  31014. var ticks = []; // If interval is 0, return [];
  31015. if (!interval) {
  31016. return ticks;
  31017. } // Consider this case: using dataZoom toolbox, zoom and zoom.
  31018. var safeLimit = 10000;
  31019. if (extent[0] < niceTickExtent[0]) {
  31020. if (expandToNicedExtent) {
  31021. ticks.push({
  31022. value: roundNumber$1(niceTickExtent[0] - interval, intervalPrecision)
  31023. });
  31024. } else {
  31025. ticks.push({
  31026. value: extent[0]
  31027. });
  31028. }
  31029. }
  31030. var tick = niceTickExtent[0];
  31031. while (tick <= niceTickExtent[1]) {
  31032. ticks.push({
  31033. value: tick
  31034. }); // Avoid rounding error
  31035. tick = roundNumber$1(tick + interval, intervalPrecision);
  31036. if (tick === ticks[ticks.length - 1].value) {
  31037. // Consider out of safe float point, e.g.,
  31038. // -3711126.9907707 + 2e-10 === -3711126.9907707
  31039. break;
  31040. }
  31041. if (ticks.length > safeLimit) {
  31042. return [];
  31043. }
  31044. } // Consider this case: the last item of ticks is smaller
  31045. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  31046. var lastNiceTick = ticks.length ? ticks[ticks.length - 1].value : niceTickExtent[1];
  31047. if (extent[1] > lastNiceTick) {
  31048. if (expandToNicedExtent) {
  31049. ticks.push({
  31050. value: roundNumber$1(lastNiceTick + interval, intervalPrecision)
  31051. });
  31052. } else {
  31053. ticks.push({
  31054. value: extent[1]
  31055. });
  31056. }
  31057. }
  31058. return ticks;
  31059. };
  31060. IntervalScale.prototype.getMinorTicks = function (splitNumber) {
  31061. var ticks = this.getTicks(true);
  31062. var minorTicks = [];
  31063. var extent = this.getExtent();
  31064. for (var i = 1; i < ticks.length; i++) {
  31065. var nextTick = ticks[i];
  31066. var prevTick = ticks[i - 1];
  31067. var count = 0;
  31068. var minorTicksGroup = [];
  31069. var interval = nextTick.value - prevTick.value;
  31070. var minorInterval = interval / splitNumber;
  31071. while (count < splitNumber - 1) {
  31072. var minorTick = roundNumber$1(prevTick.value + (count + 1) * minorInterval); // For the first and last interval. The count may be less than splitNumber.
  31073. if (minorTick > extent[0] && minorTick < extent[1]) {
  31074. minorTicksGroup.push(minorTick);
  31075. }
  31076. count++;
  31077. }
  31078. minorTicks.push(minorTicksGroup);
  31079. }
  31080. return minorTicks;
  31081. };
  31082. /**
  31083. * @param opt.precision If 'auto', use nice presision.
  31084. * @param opt.pad returns 1.50 but not 1.5 if precision is 2.
  31085. */
  31086. IntervalScale.prototype.getLabel = function (data, opt) {
  31087. if (data == null) {
  31088. return '';
  31089. }
  31090. var precision = opt && opt.precision;
  31091. if (precision == null) {
  31092. precision = getPrecision(data.value) || 0;
  31093. } else if (precision === 'auto') {
  31094. // Should be more precise then tick.
  31095. precision = this._intervalPrecision;
  31096. } // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  31097. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  31098. var dataNum = roundNumber$1(data.value, precision, true);
  31099. return addCommas(dataNum);
  31100. };
  31101. /**
  31102. * @param splitNumber By default `5`.
  31103. */
  31104. IntervalScale.prototype.niceTicks = function (splitNumber, minInterval, maxInterval) {
  31105. splitNumber = splitNumber || 5;
  31106. var extent = this._extent;
  31107. var span = extent[1] - extent[0];
  31108. if (!isFinite(span)) {
  31109. return;
  31110. } // User may set axis min 0 and data are all negative
  31111. // FIXME If it needs to reverse ?
  31112. if (span < 0) {
  31113. span = -span;
  31114. extent.reverse();
  31115. }
  31116. var result = intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval);
  31117. this._intervalPrecision = result.intervalPrecision;
  31118. this._interval = result.interval;
  31119. this._niceExtent = result.niceTickExtent;
  31120. };
  31121. IntervalScale.prototype.niceExtent = function (opt) {
  31122. var extent = this._extent; // If extent start and end are same, expand them
  31123. if (extent[0] === extent[1]) {
  31124. if (extent[0] !== 0) {
  31125. // Expand extent
  31126. var expandSize = extent[0]; // In the fowllowing case
  31127. // Axis has been fixed max 100
  31128. // Plus data are all 100 and axis extent are [100, 100].
  31129. // Extend to the both side will cause expanded max is larger than fixed max.
  31130. // So only expand to the smaller side.
  31131. if (!opt.fixMax) {
  31132. extent[1] += expandSize / 2;
  31133. extent[0] -= expandSize / 2;
  31134. } else {
  31135. extent[0] -= expandSize / 2;
  31136. }
  31137. } else {
  31138. extent[1] = 1;
  31139. }
  31140. }
  31141. var span = extent[1] - extent[0]; // If there are no data and extent are [Infinity, -Infinity]
  31142. if (!isFinite(span)) {
  31143. extent[0] = 0;
  31144. extent[1] = 1;
  31145. }
  31146. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // let extent = this._extent;
  31147. var interval = this._interval;
  31148. if (!opt.fixMin) {
  31149. extent[0] = roundNumber$1(Math.floor(extent[0] / interval) * interval);
  31150. }
  31151. if (!opt.fixMax) {
  31152. extent[1] = roundNumber$1(Math.ceil(extent[1] / interval) * interval);
  31153. }
  31154. };
  31155. IntervalScale.type = 'interval';
  31156. return IntervalScale;
  31157. }(Scale);
  31158. Scale.registerClass(IntervalScale);
  31159. var STACK_PREFIX = '__ec_stack_';
  31160. var LARGE_BAR_MIN_WIDTH = 0.5;
  31161. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  31162. function getSeriesStackId(seriesModel) {
  31163. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  31164. }
  31165. function getAxisKey(axis) {
  31166. return axis.dim + axis.index;
  31167. }
  31168. function prepareLayoutBarSeries(seriesType, ecModel) {
  31169. var seriesModels = [];
  31170. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  31171. // Check series coordinate, do layout for cartesian2d only
  31172. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  31173. seriesModels.push(seriesModel);
  31174. }
  31175. });
  31176. return seriesModels;
  31177. }
  31178. /**
  31179. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  31180. * values.
  31181. * This works for time axes, value axes, and log axes.
  31182. * For a single time axis, return value is in the form like
  31183. * {'x_0': [1000000]}.
  31184. * The value of 1000000 is in milliseconds.
  31185. */
  31186. function getValueAxesMinGaps(barSeries) {
  31187. /**
  31188. * Map from axis.index to values.
  31189. * For a single time axis, axisValues is in the form like
  31190. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  31191. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  31192. * series.
  31193. */
  31194. var axisValues = {};
  31195. each(barSeries, function (seriesModel) {
  31196. var cartesian = seriesModel.coordinateSystem;
  31197. var baseAxis = cartesian.getBaseAxis();
  31198. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  31199. return;
  31200. }
  31201. var data = seriesModel.getData();
  31202. var key = baseAxis.dim + '_' + baseAxis.index;
  31203. var dimIdx = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  31204. var store = data.getStore();
  31205. for (var i = 0, cnt = store.count(); i < cnt; ++i) {
  31206. var value = store.get(dimIdx, i);
  31207. if (!axisValues[key]) {
  31208. // No previous data for the axis
  31209. axisValues[key] = [value];
  31210. } else {
  31211. // No value in previous series
  31212. axisValues[key].push(value);
  31213. } // Ignore duplicated time values in the same axis
  31214. }
  31215. });
  31216. var axisMinGaps = {};
  31217. for (var key in axisValues) {
  31218. if (axisValues.hasOwnProperty(key)) {
  31219. var valuesInAxis = axisValues[key];
  31220. if (valuesInAxis) {
  31221. // Sort axis values into ascending order to calculate gaps
  31222. valuesInAxis.sort(function (a, b) {
  31223. return a - b;
  31224. });
  31225. var min = null;
  31226. for (var j = 1; j < valuesInAxis.length; ++j) {
  31227. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  31228. if (delta > 0) {
  31229. // Ignore 0 delta because they are of the same axis value
  31230. min = min === null ? delta : Math.min(min, delta);
  31231. }
  31232. } // Set to null if only have one data
  31233. axisMinGaps[key] = min;
  31234. }
  31235. }
  31236. }
  31237. return axisMinGaps;
  31238. }
  31239. function makeColumnLayout(barSeries) {
  31240. var axisMinGaps = getValueAxesMinGaps(barSeries);
  31241. var seriesInfoList = [];
  31242. each(barSeries, function (seriesModel) {
  31243. var cartesian = seriesModel.coordinateSystem;
  31244. var baseAxis = cartesian.getBaseAxis();
  31245. var axisExtent = baseAxis.getExtent();
  31246. var bandWidth;
  31247. if (baseAxis.type === 'category') {
  31248. bandWidth = baseAxis.getBandWidth();
  31249. } else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  31250. var key = baseAxis.dim + '_' + baseAxis.index;
  31251. var minGap = axisMinGaps[key];
  31252. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  31253. var scale = baseAxis.scale.getExtent();
  31254. var scaleSpan = Math.abs(scale[1] - scale[0]);
  31255. bandWidth = minGap ? extentSpan / scaleSpan * minGap : extentSpan; // When there is only one data value
  31256. } else {
  31257. var data = seriesModel.getData();
  31258. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  31259. }
  31260. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  31261. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  31262. var barMinWidth = parsePercent$1( // barMinWidth by default is 1 in cartesian. Because in value axis,
  31263. // the auto-calculated bar width might be less than 1.
  31264. seriesModel.get('barMinWidth') || 1, bandWidth);
  31265. var barGap = seriesModel.get('barGap');
  31266. var barCategoryGap = seriesModel.get('barCategoryGap');
  31267. seriesInfoList.push({
  31268. bandWidth: bandWidth,
  31269. barWidth: barWidth,
  31270. barMaxWidth: barMaxWidth,
  31271. barMinWidth: barMinWidth,
  31272. barGap: barGap,
  31273. barCategoryGap: barCategoryGap,
  31274. axisKey: getAxisKey(baseAxis),
  31275. stackId: getSeriesStackId(seriesModel)
  31276. });
  31277. });
  31278. return doCalBarWidthAndOffset(seriesInfoList);
  31279. }
  31280. function doCalBarWidthAndOffset(seriesInfoList) {
  31281. // Columns info on each category axis. Key is cartesian name
  31282. var columnsMap = {};
  31283. each(seriesInfoList, function (seriesInfo, idx) {
  31284. var axisKey = seriesInfo.axisKey;
  31285. var bandWidth = seriesInfo.bandWidth;
  31286. var columnsOnAxis = columnsMap[axisKey] || {
  31287. bandWidth: bandWidth,
  31288. remainedWidth: bandWidth,
  31289. autoWidthCount: 0,
  31290. categoryGap: null,
  31291. gap: '20%',
  31292. stacks: {}
  31293. };
  31294. var stacks = columnsOnAxis.stacks;
  31295. columnsMap[axisKey] = columnsOnAxis;
  31296. var stackId = seriesInfo.stackId;
  31297. if (!stacks[stackId]) {
  31298. columnsOnAxis.autoWidthCount++;
  31299. }
  31300. stacks[stackId] = stacks[stackId] || {
  31301. width: 0,
  31302. maxWidth: 0
  31303. }; // Caution: In a single coordinate system, these barGrid attributes
  31304. // will be shared by series. Consider that they have default values,
  31305. // only the attributes set on the last series will work.
  31306. // Do not change this fact unless there will be a break change.
  31307. var barWidth = seriesInfo.barWidth;
  31308. if (barWidth && !stacks[stackId].width) {
  31309. // See #6312, do not restrict width.
  31310. stacks[stackId].width = barWidth;
  31311. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  31312. columnsOnAxis.remainedWidth -= barWidth;
  31313. }
  31314. var barMaxWidth = seriesInfo.barMaxWidth;
  31315. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  31316. var barMinWidth = seriesInfo.barMinWidth;
  31317. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  31318. var barGap = seriesInfo.barGap;
  31319. barGap != null && (columnsOnAxis.gap = barGap);
  31320. var barCategoryGap = seriesInfo.barCategoryGap;
  31321. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  31322. });
  31323. var result = {};
  31324. each(columnsMap, function (columnsOnAxis, coordSysName) {
  31325. result[coordSysName] = {};
  31326. var stacks = columnsOnAxis.stacks;
  31327. var bandWidth = columnsOnAxis.bandWidth;
  31328. var categoryGapPercent = columnsOnAxis.categoryGap;
  31329. if (categoryGapPercent == null) {
  31330. var columnCount = keys(stacks).length; // More columns in one group
  31331. // the spaces between group is smaller. Or the column will be too thin.
  31332. categoryGapPercent = Math.max(35 - columnCount * 4, 15) + '%';
  31333. }
  31334. var categoryGap = parsePercent$1(categoryGapPercent, bandWidth);
  31335. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  31336. var remainedWidth = columnsOnAxis.remainedWidth;
  31337. var autoWidthCount = columnsOnAxis.autoWidthCount;
  31338. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  31339. autoWidth = Math.max(autoWidth, 0); // Find if any auto calculated bar exceeded maxBarWidth
  31340. each(stacks, function (column) {
  31341. var maxWidth = column.maxWidth;
  31342. var minWidth = column.minWidth;
  31343. if (!column.width) {
  31344. var finalWidth = autoWidth;
  31345. if (maxWidth && maxWidth < finalWidth) {
  31346. finalWidth = Math.min(maxWidth, remainedWidth);
  31347. } // `minWidth` has higher priority. `minWidth` decide that wheter the
  31348. // bar is able to be visible. So `minWidth` should not be restricted
  31349. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  31350. // the extreme cases for `value` axis, bars are allowed to overlap
  31351. // with each other if `minWidth` specified.
  31352. if (minWidth && minWidth > finalWidth) {
  31353. finalWidth = minWidth;
  31354. }
  31355. if (finalWidth !== autoWidth) {
  31356. column.width = finalWidth;
  31357. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  31358. autoWidthCount--;
  31359. }
  31360. } else {
  31361. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  31362. // CSS does. Becuase barWidth can be a percent value, where
  31363. // `barMaxWidth` can be used to restrict the final width.
  31364. var finalWidth = column.width;
  31365. if (maxWidth) {
  31366. finalWidth = Math.min(finalWidth, maxWidth);
  31367. } // `minWidth` has higher priority, as described above
  31368. if (minWidth) {
  31369. finalWidth = Math.max(finalWidth, minWidth);
  31370. }
  31371. column.width = finalWidth;
  31372. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  31373. autoWidthCount--;
  31374. }
  31375. }); // Recalculate width again
  31376. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  31377. autoWidth = Math.max(autoWidth, 0);
  31378. var widthSum = 0;
  31379. var lastColumn;
  31380. each(stacks, function (column, idx) {
  31381. if (!column.width) {
  31382. column.width = autoWidth;
  31383. }
  31384. lastColumn = column;
  31385. widthSum += column.width * (1 + barGapPercent);
  31386. });
  31387. if (lastColumn) {
  31388. widthSum -= lastColumn.width * barGapPercent;
  31389. }
  31390. var offset = -widthSum / 2;
  31391. each(stacks, function (column, stackId) {
  31392. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  31393. bandWidth: bandWidth,
  31394. offset: offset,
  31395. width: column.width
  31396. };
  31397. offset += column.width * (1 + barGapPercent);
  31398. });
  31399. });
  31400. return result;
  31401. }
  31402. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  31403. if (barWidthAndOffset && axis) {
  31404. var result = barWidthAndOffset[getAxisKey(axis)];
  31405. if (result != null && seriesModel != null) {
  31406. return result[getSeriesStackId(seriesModel)];
  31407. }
  31408. return result;
  31409. }
  31410. }
  31411. function layout(seriesType, ecModel) {
  31412. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  31413. var barWidthAndOffset = makeColumnLayout(seriesModels);
  31414. var lastStackCoords = {};
  31415. each(seriesModels, function (seriesModel) {
  31416. var data = seriesModel.getData();
  31417. var cartesian = seriesModel.coordinateSystem;
  31418. var baseAxis = cartesian.getBaseAxis();
  31419. var stackId = getSeriesStackId(seriesModel);
  31420. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  31421. var columnOffset = columnLayoutInfo.offset;
  31422. var columnWidth = columnLayoutInfo.width;
  31423. var valueAxis = cartesian.getOtherAxis(baseAxis);
  31424. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  31425. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  31426. data.setLayout({
  31427. bandWidth: columnLayoutInfo.bandWidth,
  31428. offset: columnOffset,
  31429. size: columnWidth
  31430. });
  31431. var valueDim = data.mapDimension(valueAxis.dim);
  31432. var baseDim = data.mapDimension(baseAxis.dim);
  31433. var stacked = isDimensionStacked(data, valueDim);
  31434. var isValueAxisH = valueAxis.isHorizontal();
  31435. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis);
  31436. var store = data.getStore();
  31437. var valueDimIdx = data.getDimensionIndex(valueDim);
  31438. var baseDimIdx = data.getDimensionIndex(baseDim);
  31439. for (var idx = 0, len = store.count(); idx < len; idx++) {
  31440. var value = store.get(valueDimIdx, idx);
  31441. var baseValue = store.get(baseDimIdx, idx);
  31442. var sign = value >= 0 ? 'p' : 'n';
  31443. var baseCoord = valueAxisStart; // Because of the barMinHeight, we can not use the value in
  31444. // stackResultDimension directly.
  31445. if (stacked) {
  31446. // Only ordinal axis can be stacked.
  31447. if (!lastStackCoords[stackId][baseValue]) {
  31448. lastStackCoords[stackId][baseValue] = {
  31449. p: valueAxisStart,
  31450. n: valueAxisStart // Negative stack
  31451. };
  31452. } // Should also consider #4243
  31453. baseCoord = lastStackCoords[stackId][baseValue][sign];
  31454. }
  31455. var x = void 0;
  31456. var y = void 0;
  31457. var width = void 0;
  31458. var height = void 0;
  31459. if (isValueAxisH) {
  31460. var coord = cartesian.dataToPoint([value, baseValue]);
  31461. x = baseCoord;
  31462. y = coord[1] + columnOffset;
  31463. width = coord[0] - valueAxisStart;
  31464. height = columnWidth;
  31465. if (Math.abs(width) < barMinHeight) {
  31466. width = (width < 0 ? -1 : 1) * barMinHeight;
  31467. } // Ignore stack from NaN value
  31468. if (!isNaN(width)) {
  31469. stacked && (lastStackCoords[stackId][baseValue][sign] += width);
  31470. }
  31471. } else {
  31472. var coord = cartesian.dataToPoint([baseValue, value]);
  31473. x = coord[0] + columnOffset;
  31474. y = baseCoord;
  31475. width = columnWidth;
  31476. height = coord[1] - valueAxisStart;
  31477. if (Math.abs(height) < barMinHeight) {
  31478. // Include zero to has a positive bar
  31479. height = (height <= 0 ? -1 : 1) * barMinHeight;
  31480. } // Ignore stack from NaN value
  31481. if (!isNaN(height)) {
  31482. stacked && (lastStackCoords[stackId][baseValue][sign] += height);
  31483. }
  31484. }
  31485. data.setItemLayout(idx, {
  31486. x: x,
  31487. y: y,
  31488. width: width,
  31489. height: height
  31490. });
  31491. }
  31492. });
  31493. } // TODO: Do not support stack in large mode yet.
  31494. var largeLayout = {
  31495. seriesType: 'bar',
  31496. plan: createRenderPlanner(),
  31497. reset: function (seriesModel) {
  31498. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  31499. return;
  31500. }
  31501. var data = seriesModel.getData();
  31502. var cartesian = seriesModel.coordinateSystem;
  31503. var coordLayout = cartesian.master.getRect();
  31504. var baseAxis = cartesian.getBaseAxis();
  31505. var valueAxis = cartesian.getOtherAxis(baseAxis);
  31506. var valueDimI = data.getDimensionIndex(data.mapDimension(valueAxis.dim));
  31507. var baseDimI = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  31508. var valueAxisHorizontal = valueAxis.isHorizontal();
  31509. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  31510. var barWidth = retrieveColumnLayout(makeColumnLayout([seriesModel]), baseAxis, seriesModel).width;
  31511. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) {
  31512. // jshint ignore:line
  31513. barWidth = LARGE_BAR_MIN_WIDTH;
  31514. }
  31515. return {
  31516. progress: function (params, data) {
  31517. var count = params.count;
  31518. var largePoints = new LargeArr(count * 2);
  31519. var largeBackgroundPoints = new LargeArr(count * 2);
  31520. var largeDataIndices = new LargeArr(count);
  31521. var dataIndex;
  31522. var coord = [];
  31523. var valuePair = [];
  31524. var pointsOffset = 0;
  31525. var idxOffset = 0;
  31526. var store = data.getStore();
  31527. while ((dataIndex = params.next()) != null) {
  31528. valuePair[valueDimIdx] = store.get(valueDimI, dataIndex);
  31529. valuePair[1 - valueDimIdx] = store.get(baseDimI, dataIndex);
  31530. coord = cartesian.dataToPoint(valuePair, null); // Data index might not be in order, depends on `progressiveChunkMode`.
  31531. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coordLayout.x + coordLayout.width : coord[0];
  31532. largePoints[pointsOffset++] = coord[0];
  31533. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coord[1] : coordLayout.y + coordLayout.height;
  31534. largePoints[pointsOffset++] = coord[1];
  31535. largeDataIndices[idxOffset++] = dataIndex;
  31536. }
  31537. data.setLayout({
  31538. largePoints: largePoints,
  31539. largeDataIndices: largeDataIndices,
  31540. largeBackgroundPoints: largeBackgroundPoints,
  31541. barWidth: barWidth,
  31542. valueAxisStart: getValueAxisStart(baseAxis, valueAxis),
  31543. backgroundStart: valueAxisHorizontal ? coordLayout.x : coordLayout.y,
  31544. valueAxisHorizontal: valueAxisHorizontal
  31545. });
  31546. }
  31547. };
  31548. }
  31549. };
  31550. function isOnCartesian(seriesModel) {
  31551. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  31552. }
  31553. function isInLargeMode(seriesModel) {
  31554. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  31555. } // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  31556. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  31557. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? 1 : 0));
  31558. }
  31559. var bisect = function (a, x, lo, hi) {
  31560. while (lo < hi) {
  31561. var mid = lo + hi >>> 1;
  31562. if (a[mid][1] < x) {
  31563. lo = mid + 1;
  31564. } else {
  31565. hi = mid;
  31566. }
  31567. }
  31568. return lo;
  31569. };
  31570. var TimeScale =
  31571. /** @class */
  31572. function (_super) {
  31573. __extends(TimeScale, _super);
  31574. function TimeScale(settings) {
  31575. var _this = _super.call(this, settings) || this;
  31576. _this.type = 'time';
  31577. return _this;
  31578. }
  31579. /**
  31580. * Get label is mainly for other components like dataZoom, tooltip.
  31581. */
  31582. TimeScale.prototype.getLabel = function (tick) {
  31583. var useUTC = this.getSetting('useUTC');
  31584. return format(tick.value, fullLeveledFormatter[getDefaultFormatPrecisionOfInterval(getPrimaryTimeUnit(this._minLevelUnit))] || fullLeveledFormatter.second, useUTC, this.getSetting('locale'));
  31585. };
  31586. TimeScale.prototype.getFormattedLabel = function (tick, idx, labelFormatter) {
  31587. var isUTC = this.getSetting('useUTC');
  31588. var lang = this.getSetting('locale');
  31589. return leveledFormat(tick, idx, labelFormatter, lang, isUTC);
  31590. };
  31591. /**
  31592. * @override
  31593. * @param expandToNicedExtent Whether expand the ticks to niced extent.
  31594. */
  31595. TimeScale.prototype.getTicks = function (expandToNicedExtent) {
  31596. var interval = this._interval;
  31597. var extent = this._extent;
  31598. var ticks = []; // If interval is 0, return [];
  31599. if (!interval) {
  31600. return ticks;
  31601. }
  31602. ticks.push({
  31603. value: extent[0],
  31604. level: 0
  31605. });
  31606. var useUTC = this.getSetting('useUTC');
  31607. var innerTicks = getIntervalTicks(this._minLevelUnit, this._approxInterval, useUTC, extent);
  31608. ticks = ticks.concat(innerTicks);
  31609. ticks.push({
  31610. value: extent[1],
  31611. level: 0
  31612. });
  31613. return ticks;
  31614. };
  31615. TimeScale.prototype.niceExtent = function (opt) {
  31616. var extent = this._extent; // If extent start and end are same, expand them
  31617. if (extent[0] === extent[1]) {
  31618. // Expand extent
  31619. extent[0] -= ONE_DAY;
  31620. extent[1] += ONE_DAY;
  31621. } // If there are no data and extent are [Infinity, -Infinity]
  31622. if (extent[1] === -Infinity && extent[0] === Infinity) {
  31623. var d = new Date();
  31624. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  31625. extent[0] = extent[1] - ONE_DAY;
  31626. }
  31627. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  31628. };
  31629. TimeScale.prototype.niceTicks = function (approxTickNum, minInterval, maxInterval) {
  31630. approxTickNum = approxTickNum || 10;
  31631. var extent = this._extent;
  31632. var span = extent[1] - extent[0];
  31633. this._approxInterval = span / approxTickNum;
  31634. if (minInterval != null && this._approxInterval < minInterval) {
  31635. this._approxInterval = minInterval;
  31636. }
  31637. if (maxInterval != null && this._approxInterval > maxInterval) {
  31638. this._approxInterval = maxInterval;
  31639. }
  31640. var scaleIntervalsLen = scaleIntervals.length;
  31641. var idx = Math.min(bisect(scaleIntervals, this._approxInterval, 0, scaleIntervalsLen), scaleIntervalsLen - 1); // Interval that can be used to calculate ticks
  31642. this._interval = scaleIntervals[idx][1]; // Min level used when picking ticks from top down.
  31643. // We check one more level to avoid the ticks are to sparse in some case.
  31644. this._minLevelUnit = scaleIntervals[Math.max(idx - 1, 0)][0];
  31645. };
  31646. TimeScale.prototype.parse = function (val) {
  31647. // val might be float.
  31648. return typeof val === 'number' ? val : +parseDate(val);
  31649. };
  31650. TimeScale.prototype.contain = function (val) {
  31651. return contain$2(this.parse(val), this._extent);
  31652. };
  31653. TimeScale.prototype.normalize = function (val) {
  31654. return normalize$1(this.parse(val), this._extent);
  31655. };
  31656. TimeScale.prototype.scale = function (val) {
  31657. return scale$2(val, this._extent);
  31658. };
  31659. TimeScale.type = 'time';
  31660. return TimeScale;
  31661. }(IntervalScale);
  31662. /**
  31663. * This implementation was originally copied from "d3.js"
  31664. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  31665. * with some modifications made for this program.
  31666. * See the license statement at the head of this file.
  31667. */
  31668. var scaleIntervals = [// Format interval
  31669. ['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
  31670. ];
  31671. function isUnitValueSame(unit, valueA, valueB, isUTC) {
  31672. var dateA = parseDate(valueA);
  31673. var dateB = parseDate(valueB);
  31674. var isSame = function (unit) {
  31675. return getUnitValue(dateA, unit, isUTC) === getUnitValue(dateB, unit, isUTC);
  31676. };
  31677. var isSameYear = function () {
  31678. return isSame('year');
  31679. }; // const isSameHalfYear = () => isSameYear() && isSame('half-year');
  31680. // const isSameQuater = () => isSameYear() && isSame('quarter');
  31681. var isSameMonth = function () {
  31682. return isSameYear() && isSame('month');
  31683. };
  31684. var isSameDay = function () {
  31685. return isSameMonth() && isSame('day');
  31686. }; // const isSameHalfDay = () => isSameDay() && isSame('half-day');
  31687. var isSameHour = function () {
  31688. return isSameDay() && isSame('hour');
  31689. };
  31690. var isSameMinute = function () {
  31691. return isSameHour() && isSame('minute');
  31692. };
  31693. var isSameSecond = function () {
  31694. return isSameMinute() && isSame('second');
  31695. };
  31696. var isSameMilliSecond = function () {
  31697. return isSameSecond() && isSame('millisecond');
  31698. };
  31699. switch (unit) {
  31700. case 'year':
  31701. return isSameYear();
  31702. case 'month':
  31703. return isSameMonth();
  31704. case 'day':
  31705. return isSameDay();
  31706. case 'hour':
  31707. return isSameHour();
  31708. case 'minute':
  31709. return isSameMinute();
  31710. case 'second':
  31711. return isSameSecond();
  31712. case 'millisecond':
  31713. return isSameMilliSecond();
  31714. }
  31715. } // const primaryUnitGetters = {
  31716. // year: fullYearGetterName(),
  31717. // month: monthGetterName(),
  31718. // day: dateGetterName(),
  31719. // hour: hoursGetterName(),
  31720. // minute: minutesGetterName(),
  31721. // second: secondsGetterName(),
  31722. // millisecond: millisecondsGetterName()
  31723. // };
  31724. // const primaryUnitUTCGetters = {
  31725. // year: fullYearGetterName(true),
  31726. // month: monthGetterName(true),
  31727. // day: dateGetterName(true),
  31728. // hour: hoursGetterName(true),
  31729. // minute: minutesGetterName(true),
  31730. // second: secondsGetterName(true),
  31731. // millisecond: millisecondsGetterName(true)
  31732. // };
  31733. // function moveTick(date: Date, unitName: TimeUnit, step: number, isUTC: boolean) {
  31734. // step = step || 1;
  31735. // switch (getPrimaryTimeUnit(unitName)) {
  31736. // case 'year':
  31737. // date[fullYearSetterName(isUTC)](date[fullYearGetterName(isUTC)]() + step);
  31738. // break;
  31739. // case 'month':
  31740. // date[monthSetterName(isUTC)](date[monthGetterName(isUTC)]() + step);
  31741. // break;
  31742. // case 'day':
  31743. // date[dateSetterName(isUTC)](date[dateGetterName(isUTC)]() + step);
  31744. // break;
  31745. // case 'hour':
  31746. // date[hoursSetterName(isUTC)](date[hoursGetterName(isUTC)]() + step);
  31747. // break;
  31748. // case 'minute':
  31749. // date[minutesSetterName(isUTC)](date[minutesGetterName(isUTC)]() + step);
  31750. // break;
  31751. // case 'second':
  31752. // date[secondsSetterName(isUTC)](date[secondsGetterName(isUTC)]() + step);
  31753. // break;
  31754. // case 'millisecond':
  31755. // date[millisecondsSetterName(isUTC)](date[millisecondsGetterName(isUTC)]() + step);
  31756. // break;
  31757. // }
  31758. // return date.getTime();
  31759. // }
  31760. // const DATE_INTERVALS = [[8, 7.5], [4, 3.5], [2, 1.5]];
  31761. // const MONTH_INTERVALS = [[6, 5.5], [3, 2.5], [2, 1.5]];
  31762. // const MINUTES_SECONDS_INTERVALS = [[30, 30], [20, 20], [15, 15], [10, 10], [5, 5], [2, 2]];
  31763. function getDateInterval(approxInterval, daysInMonth) {
  31764. approxInterval /= ONE_DAY;
  31765. return approxInterval > 16 ? 16 // Math.floor(daysInMonth / 2) + 1 // In this case we only want one tick betwen two month.
  31766. : approxInterval > 7.5 ? 7 // TODO week 7 or day 8?
  31767. : approxInterval > 3.5 ? 4 : approxInterval > 1.5 ? 2 : 1;
  31768. }
  31769. function getMonthInterval(approxInterval) {
  31770. var APPROX_ONE_MONTH = 30 * ONE_DAY;
  31771. approxInterval /= APPROX_ONE_MONTH;
  31772. return approxInterval > 6 ? 6 : approxInterval > 3 ? 3 : approxInterval > 2 ? 2 : 1;
  31773. }
  31774. function getHourInterval(approxInterval) {
  31775. approxInterval /= ONE_HOUR;
  31776. return approxInterval > 12 ? 12 : approxInterval > 6 ? 6 : approxInterval > 3.5 ? 4 : approxInterval > 2 ? 2 : 1;
  31777. }
  31778. function getMinutesAndSecondsInterval(approxInterval, isMinutes) {
  31779. approxInterval /= isMinutes ? ONE_MINUTE : ONE_SECOND;
  31780. return approxInterval > 30 ? 30 : approxInterval > 20 ? 20 : approxInterval > 15 ? 15 : approxInterval > 10 ? 10 : approxInterval > 5 ? 5 : approxInterval > 2 ? 2 : 1;
  31781. }
  31782. function getMillisecondsInterval(approxInterval) {
  31783. return nice(approxInterval, true);
  31784. }
  31785. function getFirstTimestampOfUnit(date, unitName, isUTC) {
  31786. var outDate = new Date(date);
  31787. switch (getPrimaryTimeUnit(unitName)) {
  31788. case 'year':
  31789. case 'month':
  31790. outDate[monthSetterName(isUTC)](0);
  31791. case 'day':
  31792. outDate[dateSetterName(isUTC)](1);
  31793. case 'hour':
  31794. outDate[hoursSetterName(isUTC)](0);
  31795. case 'minute':
  31796. outDate[minutesSetterName(isUTC)](0);
  31797. case 'second':
  31798. outDate[secondsSetterName(isUTC)](0);
  31799. outDate[millisecondsSetterName(isUTC)](0);
  31800. }
  31801. return outDate.getTime();
  31802. }
  31803. function getIntervalTicks(bottomUnitName, approxInterval, isUTC, extent) {
  31804. var safeLimit = 10000;
  31805. var unitNames = timeUnits;
  31806. var iter = 0;
  31807. function addTicksInSpan(interval, minTimestamp, maxTimestamp, getMethodName, setMethodName, isDate, out) {
  31808. var date = new Date(minTimestamp);
  31809. var dateTime = minTimestamp;
  31810. var d = date[getMethodName](); // if (isDate) {
  31811. // d -= 1; // Starts with 0; PENDING
  31812. // }
  31813. while (dateTime < maxTimestamp && dateTime <= extent[1]) {
  31814. out.push({
  31815. value: dateTime
  31816. });
  31817. d += interval;
  31818. date[setMethodName](d);
  31819. dateTime = date.getTime();
  31820. } // This extra tick is for calcuating ticks of next level. Will not been added to the final result
  31821. out.push({
  31822. value: dateTime,
  31823. notAdd: true
  31824. });
  31825. }
  31826. function addLevelTicks(unitName, lastLevelTicks, levelTicks) {
  31827. var newAddedTicks = [];
  31828. var isFirstLevel = !lastLevelTicks.length;
  31829. if (isUnitValueSame(getPrimaryTimeUnit(unitName), extent[0], extent[1], isUTC)) {
  31830. return;
  31831. }
  31832. if (isFirstLevel) {
  31833. lastLevelTicks = [{
  31834. // TODO Optimize. Not include so may ticks.
  31835. value: getFirstTimestampOfUnit(new Date(extent[0]), unitName, isUTC)
  31836. }, {
  31837. value: extent[1]
  31838. }];
  31839. }
  31840. for (var i = 0; i < lastLevelTicks.length - 1; i++) {
  31841. var startTick = lastLevelTicks[i].value;
  31842. var endTick = lastLevelTicks[i + 1].value;
  31843. if (startTick === endTick) {
  31844. continue;
  31845. }
  31846. var interval = void 0;
  31847. var getterName = void 0;
  31848. var setterName = void 0;
  31849. var isDate = false;
  31850. switch (unitName) {
  31851. case 'year':
  31852. interval = Math.max(1, Math.round(approxInterval / ONE_DAY / 365));
  31853. getterName = fullYearGetterName(isUTC);
  31854. setterName = fullYearSetterName(isUTC);
  31855. break;
  31856. case 'half-year':
  31857. case 'quarter':
  31858. case 'month':
  31859. interval = getMonthInterval(approxInterval);
  31860. getterName = monthGetterName(isUTC);
  31861. setterName = monthSetterName(isUTC);
  31862. break;
  31863. case 'week': // PENDING If week is added. Ignore day.
  31864. case 'half-week':
  31865. case 'day':
  31866. interval = getDateInterval(approxInterval); // Use 32 days and let interval been 16
  31867. getterName = dateGetterName(isUTC);
  31868. setterName = dateSetterName(isUTC);
  31869. isDate = true;
  31870. break;
  31871. case 'half-day':
  31872. case 'quarter-day':
  31873. case 'hour':
  31874. interval = getHourInterval(approxInterval);
  31875. getterName = hoursGetterName(isUTC);
  31876. setterName = hoursSetterName(isUTC);
  31877. break;
  31878. case 'minute':
  31879. interval = getMinutesAndSecondsInterval(approxInterval, true);
  31880. getterName = minutesGetterName(isUTC);
  31881. setterName = minutesSetterName(isUTC);
  31882. break;
  31883. case 'second':
  31884. interval = getMinutesAndSecondsInterval(approxInterval, false);
  31885. getterName = secondsGetterName(isUTC);
  31886. setterName = secondsSetterName(isUTC);
  31887. break;
  31888. case 'millisecond':
  31889. interval = getMillisecondsInterval(approxInterval);
  31890. getterName = millisecondsGetterName(isUTC);
  31891. setterName = millisecondsSetterName(isUTC);
  31892. break;
  31893. }
  31894. addTicksInSpan(interval, startTick, endTick, getterName, setterName, isDate, newAddedTicks);
  31895. if (unitName === 'year' && levelTicks.length > 1 && i === 0) {
  31896. // Add nearest years to the left extent.
  31897. levelTicks.unshift({
  31898. value: levelTicks[0].value - interval
  31899. });
  31900. }
  31901. }
  31902. for (var i = 0; i < newAddedTicks.length; i++) {
  31903. levelTicks.push(newAddedTicks[i]);
  31904. } // newAddedTicks.length && console.log(unitName, newAddedTicks);
  31905. return newAddedTicks;
  31906. }
  31907. var levelsTicks = [];
  31908. var currentLevelTicks = [];
  31909. var tickCount = 0;
  31910. var lastLevelTickCount = 0;
  31911. for (var i = 0; i < unitNames.length && iter++ < safeLimit; ++i) {
  31912. var primaryTimeUnit = getPrimaryTimeUnit(unitNames[i]);
  31913. if (!isPrimaryTimeUnit(unitNames[i])) {
  31914. // TODO
  31915. continue;
  31916. }
  31917. addLevelTicks(unitNames[i], levelsTicks[levelsTicks.length - 1] || [], currentLevelTicks);
  31918. var nextPrimaryTimeUnit = unitNames[i + 1] ? getPrimaryTimeUnit(unitNames[i + 1]) : null;
  31919. if (primaryTimeUnit !== nextPrimaryTimeUnit) {
  31920. if (currentLevelTicks.length) {
  31921. lastLevelTickCount = tickCount; // Remove the duplicate so the tick count can be precisely.
  31922. currentLevelTicks.sort(function (a, b) {
  31923. return a.value - b.value;
  31924. });
  31925. var levelTicksRemoveDuplicated = [];
  31926. for (var i_1 = 0; i_1 < currentLevelTicks.length; ++i_1) {
  31927. var tickValue = currentLevelTicks[i_1].value;
  31928. if (i_1 === 0 || currentLevelTicks[i_1 - 1].value !== tickValue) {
  31929. levelTicksRemoveDuplicated.push(currentLevelTicks[i_1]);
  31930. if (tickValue >= extent[0] && tickValue <= extent[1]) {
  31931. tickCount++;
  31932. }
  31933. }
  31934. }
  31935. var targetTickNum = (extent[1] - extent[0]) / approxInterval; // Added too much in this level and not too less in last level
  31936. if (tickCount > targetTickNum * 1.5 && lastLevelTickCount > targetTickNum / 1.5) {
  31937. break;
  31938. } // Only treat primary time unit as one level.
  31939. levelsTicks.push(levelTicksRemoveDuplicated);
  31940. if (tickCount > targetTickNum || bottomUnitName === unitNames[i]) {
  31941. break;
  31942. }
  31943. } // Reset if next unitName is primary
  31944. currentLevelTicks = [];
  31945. }
  31946. }
  31947. if ("development" !== 'production') {
  31948. if (iter >= safeLimit) {
  31949. warn('Exceed safe limit.');
  31950. }
  31951. }
  31952. var levelsTicksInExtent = filter(map(levelsTicks, function (levelTicks) {
  31953. return filter(levelTicks, function (tick) {
  31954. return tick.value >= extent[0] && tick.value <= extent[1] && !tick.notAdd;
  31955. });
  31956. }), function (levelTicks) {
  31957. return levelTicks.length > 0;
  31958. });
  31959. var ticks = [];
  31960. var maxLevel = levelsTicksInExtent.length - 1;
  31961. for (var i = 0; i < levelsTicksInExtent.length; ++i) {
  31962. var levelTicks = levelsTicksInExtent[i];
  31963. for (var k = 0; k < levelTicks.length; ++k) {
  31964. ticks.push({
  31965. value: levelTicks[k].value,
  31966. level: maxLevel - i
  31967. });
  31968. }
  31969. }
  31970. ticks.sort(function (a, b) {
  31971. return a.value - b.value;
  31972. }); // Remove duplicates
  31973. var result = [];
  31974. for (var i = 0; i < ticks.length; ++i) {
  31975. if (i === 0 || ticks[i].value !== ticks[i - 1].value) {
  31976. result.push(ticks[i]);
  31977. }
  31978. }
  31979. return result;
  31980. }
  31981. Scale.registerClass(TimeScale);
  31982. var scaleProto = Scale.prototype; // FIXME:TS refactor: not good to call it directly with `this`?
  31983. var intervalScaleProto = IntervalScale.prototype;
  31984. var roundingErrorFix = round;
  31985. var mathFloor = Math.floor;
  31986. var mathCeil = Math.ceil;
  31987. var mathPow$1 = Math.pow;
  31988. var mathLog = Math.log;
  31989. var LogScale =
  31990. /** @class */
  31991. function (_super) {
  31992. __extends(LogScale, _super);
  31993. function LogScale() {
  31994. var _this = _super !== null && _super.apply(this, arguments) || this;
  31995. _this.type = 'log';
  31996. _this.base = 10;
  31997. _this._originalScale = new IntervalScale(); // FIXME:TS actually used by `IntervalScale`
  31998. _this._interval = 0;
  31999. return _this;
  32000. }
  32001. /**
  32002. * @param Whether expand the ticks to niced extent.
  32003. */
  32004. LogScale.prototype.getTicks = function (expandToNicedExtent) {
  32005. var originalScale = this._originalScale;
  32006. var extent = this._extent;
  32007. var originalExtent = originalScale.getExtent();
  32008. var ticks = intervalScaleProto.getTicks.call(this, expandToNicedExtent);
  32009. return map(ticks, function (tick) {
  32010. var val = tick.value;
  32011. var powVal = round(mathPow$1(this.base, val)); // Fix #4158
  32012. powVal = val === extent[0] && this._fixMin ? fixRoundingError(powVal, originalExtent[0]) : powVal;
  32013. powVal = val === extent[1] && this._fixMax ? fixRoundingError(powVal, originalExtent[1]) : powVal;
  32014. return {
  32015. value: powVal
  32016. };
  32017. }, this);
  32018. };
  32019. LogScale.prototype.setExtent = function (start, end) {
  32020. var base = this.base;
  32021. start = mathLog(start) / mathLog(base);
  32022. end = mathLog(end) / mathLog(base);
  32023. intervalScaleProto.setExtent.call(this, start, end);
  32024. };
  32025. /**
  32026. * @return {number} end
  32027. */
  32028. LogScale.prototype.getExtent = function () {
  32029. var base = this.base;
  32030. var extent = scaleProto.getExtent.call(this);
  32031. extent[0] = mathPow$1(base, extent[0]);
  32032. extent[1] = mathPow$1(base, extent[1]); // Fix #4158
  32033. var originalScale = this._originalScale;
  32034. var originalExtent = originalScale.getExtent();
  32035. this._fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  32036. this._fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  32037. return extent;
  32038. };
  32039. LogScale.prototype.unionExtent = function (extent) {
  32040. this._originalScale.unionExtent(extent);
  32041. var base = this.base;
  32042. extent[0] = mathLog(extent[0]) / mathLog(base);
  32043. extent[1] = mathLog(extent[1]) / mathLog(base);
  32044. scaleProto.unionExtent.call(this, extent);
  32045. };
  32046. LogScale.prototype.unionExtentFromData = function (data, dim) {
  32047. // TODO
  32048. // filter value that <= 0
  32049. this.unionExtent(data.getApproximateExtent(dim));
  32050. };
  32051. /**
  32052. * Update interval and extent of intervals for nice ticks
  32053. * @param approxTickNum default 10 Given approx tick number
  32054. */
  32055. LogScale.prototype.niceTicks = function (approxTickNum) {
  32056. approxTickNum = approxTickNum || 10;
  32057. var extent = this._extent;
  32058. var span = extent[1] - extent[0];
  32059. if (span === Infinity || span <= 0) {
  32060. return;
  32061. }
  32062. var interval = quantity(span);
  32063. var err = approxTickNum / span * interval; // Filter ticks to get closer to the desired count.
  32064. if (err <= 0.5) {
  32065. interval *= 10;
  32066. } // Interval should be integer
  32067. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  32068. interval *= 10;
  32069. }
  32070. var niceExtent = [round(mathCeil(extent[0] / interval) * interval), round(mathFloor(extent[1] / interval) * interval)];
  32071. this._interval = interval;
  32072. this._niceExtent = niceExtent;
  32073. };
  32074. LogScale.prototype.niceExtent = function (opt) {
  32075. intervalScaleProto.niceExtent.call(this, opt);
  32076. this._fixMin = opt.fixMin;
  32077. this._fixMax = opt.fixMax;
  32078. };
  32079. LogScale.prototype.parse = function (val) {
  32080. return val;
  32081. };
  32082. LogScale.prototype.contain = function (val) {
  32083. val = mathLog(val) / mathLog(this.base);
  32084. return contain$2(val, this._extent);
  32085. };
  32086. LogScale.prototype.normalize = function (val) {
  32087. val = mathLog(val) / mathLog(this.base);
  32088. return normalize$1(val, this._extent);
  32089. };
  32090. LogScale.prototype.scale = function (val) {
  32091. val = scale$2(val, this._extent);
  32092. return mathPow$1(this.base, val);
  32093. };
  32094. LogScale.type = 'log';
  32095. return LogScale;
  32096. }(Scale);
  32097. var proto = LogScale.prototype;
  32098. proto.getMinorTicks = intervalScaleProto.getMinorTicks;
  32099. proto.getLabel = intervalScaleProto.getLabel;
  32100. function fixRoundingError(val, originalVal) {
  32101. return roundingErrorFix(val, getPrecision(originalVal));
  32102. }
  32103. Scale.registerClass(LogScale);
  32104. var ScaleRawExtentInfo =
  32105. /** @class */
  32106. function () {
  32107. function ScaleRawExtentInfo(scale, model, // Usually: data extent from all series on this axis.
  32108. originalExtent) {
  32109. this._prepareParams(scale, model, originalExtent);
  32110. }
  32111. /**
  32112. * Parameters depending on ouside (like model, user callback)
  32113. * are prepared and fixed here.
  32114. */
  32115. ScaleRawExtentInfo.prototype._prepareParams = function (scale, model, // Usually: data extent from all series on this axis.
  32116. dataExtent) {
  32117. if (dataExtent[1] < dataExtent[0]) {
  32118. dataExtent = [NaN, NaN];
  32119. }
  32120. this._dataMin = dataExtent[0];
  32121. this._dataMax = dataExtent[1];
  32122. var isOrdinal = this._isOrdinal = scale.type === 'ordinal';
  32123. this._needCrossZero = model.getNeedCrossZero && model.getNeedCrossZero();
  32124. var modelMinRaw = this._modelMinRaw = model.get('min', true);
  32125. if (isFunction(modelMinRaw)) {
  32126. // This callback alway provide users the full data extent (before data filtered).
  32127. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw({
  32128. min: dataExtent[0],
  32129. max: dataExtent[1]
  32130. }));
  32131. } else if (modelMinRaw !== 'dataMin') {
  32132. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw);
  32133. }
  32134. var modelMaxRaw = this._modelMaxRaw = model.get('max', true);
  32135. if (isFunction(modelMaxRaw)) {
  32136. // This callback alway provide users the full data extent (before data filtered).
  32137. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw({
  32138. min: dataExtent[0],
  32139. max: dataExtent[1]
  32140. }));
  32141. } else if (modelMaxRaw !== 'dataMax') {
  32142. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw);
  32143. }
  32144. if (isOrdinal) {
  32145. // FIXME: there is a flaw here: if there is no "block" data processor like `dataZoom`,
  32146. // and progressive rendering is using, here the category result might just only contain
  32147. // the processed chunk rather than the entire result.
  32148. this._axisDataLen = model.getCategories().length;
  32149. } else {
  32150. var boundaryGap = model.get('boundaryGap');
  32151. var boundaryGapArr = isArray(boundaryGap) ? boundaryGap : [boundaryGap || 0, boundaryGap || 0];
  32152. if (typeof boundaryGapArr[0] === 'boolean' || typeof boundaryGapArr[1] === 'boolean') {
  32153. if ("development" !== 'production') {
  32154. 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.');
  32155. }
  32156. this._boundaryGapInner = [0, 0];
  32157. } else {
  32158. this._boundaryGapInner = [parsePercent(boundaryGapArr[0], 1), parsePercent(boundaryGapArr[1], 1)];
  32159. }
  32160. }
  32161. };
  32162. /**
  32163. * Calculate extent by prepared parameters.
  32164. * This method has no external dependency and can be called duplicatedly,
  32165. * getting the same result.
  32166. * If parameters changed, should call this method to recalcuate.
  32167. */
  32168. ScaleRawExtentInfo.prototype.calculate = function () {
  32169. // Notice: When min/max is not set (that is, when there are null/undefined,
  32170. // which is the most common case), these cases should be ensured:
  32171. // (1) For 'ordinal', show all axis.data.
  32172. // (2) For others:
  32173. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  32174. // disabled).
  32175. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  32176. // be the result that originalExtent enlarged by boundaryGap.
  32177. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  32178. var isOrdinal = this._isOrdinal;
  32179. var dataMin = this._dataMin;
  32180. var dataMax = this._dataMax;
  32181. var axisDataLen = this._axisDataLen;
  32182. var boundaryGapInner = this._boundaryGapInner;
  32183. var span = !isOrdinal ? dataMax - dataMin || Math.abs(dataMin) : null; // Currently if a `'value'` axis model min is specified as 'dataMin'/'dataMax',
  32184. // `boundaryGap` will not be used. It's the different from specifying as `null`/`undefined`.
  32185. var min = this._modelMinRaw === 'dataMin' ? dataMin : this._modelMinNum;
  32186. var max = this._modelMaxRaw === 'dataMax' ? dataMax : this._modelMaxNum; // If `_modelMinNum`/`_modelMaxNum` is `null`/`undefined`, should not be fixed.
  32187. var minFixed = min != null;
  32188. var maxFixed = max != null;
  32189. if (min == null) {
  32190. min = isOrdinal ? axisDataLen ? 0 : NaN : dataMin - boundaryGapInner[0] * span;
  32191. }
  32192. if (max == null) {
  32193. max = isOrdinal ? axisDataLen ? axisDataLen - 1 : NaN : dataMax + boundaryGapInner[1] * span;
  32194. }
  32195. (min == null || !isFinite(min)) && (min = NaN);
  32196. (max == null || !isFinite(max)) && (max = NaN);
  32197. var isBlank = eqNaN(min) || eqNaN(max) || isOrdinal && !axisDataLen; // If data extent modified, need to recalculated to ensure cross zero.
  32198. if (this._needCrossZero) {
  32199. // Axis is over zero and min is not set
  32200. if (min > 0 && max > 0 && !minFixed) {
  32201. min = 0; // minFixed = true;
  32202. } // Axis is under zero and max is not set
  32203. if (min < 0 && max < 0 && !maxFixed) {
  32204. max = 0; // maxFixed = true;
  32205. } // PENDING:
  32206. // When `needCrossZero` and all data is positive/negative, should it be ensured
  32207. // that the results processed by boundaryGap are positive/negative?
  32208. // If so, here `minFixed`/`maxFixed` need to be set.
  32209. }
  32210. var determinedMin = this._determinedMin;
  32211. var determinedMax = this._determinedMax;
  32212. if (determinedMin != null) {
  32213. min = determinedMin;
  32214. minFixed = true;
  32215. }
  32216. if (determinedMax != null) {
  32217. max = determinedMax;
  32218. maxFixed = true;
  32219. } // Ensure min/max be finite number or NaN here. (not to be null/undefined)
  32220. // `NaN` means min/max axis is blank.
  32221. return {
  32222. min: min,
  32223. max: max,
  32224. minFixed: minFixed,
  32225. maxFixed: maxFixed,
  32226. isBlank: isBlank
  32227. };
  32228. };
  32229. ScaleRawExtentInfo.prototype.modifyDataMinMax = function (minMaxName, val) {
  32230. if ("development" !== 'production') {
  32231. assert(!this.frozen);
  32232. }
  32233. this[DATA_MIN_MAX_ATTR[minMaxName]] = val;
  32234. };
  32235. ScaleRawExtentInfo.prototype.setDeterminedMinMax = function (minMaxName, val) {
  32236. var attr = DETERMINED_MIN_MAX_ATTR[minMaxName];
  32237. if ("development" !== 'production') {
  32238. assert(!this.frozen // Earse them usually means logic flaw.
  32239. && this[attr] == null);
  32240. }
  32241. this[attr] = val;
  32242. };
  32243. ScaleRawExtentInfo.prototype.freeze = function () {
  32244. // @ts-ignore
  32245. this.frozen = true;
  32246. };
  32247. return ScaleRawExtentInfo;
  32248. }();
  32249. var DETERMINED_MIN_MAX_ATTR = {
  32250. min: '_determinedMin',
  32251. max: '_determinedMax'
  32252. };
  32253. var DATA_MIN_MAX_ATTR = {
  32254. min: '_dataMin',
  32255. max: '_dataMax'
  32256. };
  32257. /**
  32258. * Get scale min max and related info only depends on model settings.
  32259. * This method can be called after coordinate system created.
  32260. * For example, in data processing stage.
  32261. *
  32262. * Scale extent info probably be required multiple times during a workflow.
  32263. * For example:
  32264. * (1) `dataZoom` depends it to get the axis extent in "100%" state.
  32265. * (2) `processor/extentCalculator` depends it to make sure whether axis extent is specified.
  32266. * (3) `coordSys.update` use it to finally decide the scale extent.
  32267. * But the callback of `min`/`max` should not be called multiple times.
  32268. * The code below should not be implemented repeatedly either.
  32269. * So we cache the result in the scale instance, which will be recreated at the begining
  32270. * of the workflow (because `scale` instance will be recreated each round of the workflow).
  32271. */
  32272. function ensureScaleRawExtentInfo(scale, model, // Usually: data extent from all series on this axis.
  32273. originalExtent) {
  32274. // Do not permit to recreate.
  32275. var rawExtentInfo = scale.rawExtentInfo;
  32276. if (rawExtentInfo) {
  32277. return rawExtentInfo;
  32278. }
  32279. rawExtentInfo = new ScaleRawExtentInfo(scale, model, originalExtent); // @ts-ignore
  32280. scale.rawExtentInfo = rawExtentInfo;
  32281. return rawExtentInfo;
  32282. }
  32283. function parseAxisModelMinMax(scale, minMax) {
  32284. return minMax == null ? null : eqNaN(minMax) ? NaN : scale.parse(minMax);
  32285. }
  32286. /**
  32287. * Get axis scale extent before niced.
  32288. * Item of returned array can only be number (including Infinity and NaN).
  32289. *
  32290. * Caution:
  32291. * Precondition of calling this method:
  32292. * The scale extent has been initialized using series data extent via
  32293. * `scale.setExtent` or `scale.unionExtentFromData`;
  32294. */
  32295. function getScaleExtent(scale, model) {
  32296. var scaleType = scale.type;
  32297. var rawExtentResult = ensureScaleRawExtentInfo(scale, model, scale.getExtent()).calculate();
  32298. scale.setBlank(rawExtentResult.isBlank);
  32299. var min = rawExtentResult.min;
  32300. var max = rawExtentResult.max; // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  32301. // is base axis
  32302. // FIXME
  32303. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  32304. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  32305. // Should not depend on series type `bar`?
  32306. // (3) Fix that might overlap when using dataZoom.
  32307. // (4) Consider other chart types using `barGrid`?
  32308. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  32309. var ecModel = model.ecModel;
  32310. if (ecModel && scaleType === 'time'
  32311. /*|| scaleType === 'interval' */
  32312. ) {
  32313. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  32314. var isBaseAxisAndHasBarSeries_1 = false;
  32315. each(barSeriesModels, function (seriesModel) {
  32316. isBaseAxisAndHasBarSeries_1 = isBaseAxisAndHasBarSeries_1 || seriesModel.getBaseAxis() === model.axis;
  32317. });
  32318. if (isBaseAxisAndHasBarSeries_1) {
  32319. // Calculate placement of bars on axis. TODO should be decoupled
  32320. // with barLayout
  32321. var barWidthAndOffset = makeColumnLayout(barSeriesModels); // Adjust axis min and max to account for overflow
  32322. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  32323. min = adjustedScale.min;
  32324. max = adjustedScale.max;
  32325. }
  32326. }
  32327. return {
  32328. extent: [min, max],
  32329. // "fix" means "fixed", the value should not be
  32330. // changed in the subsequent steps.
  32331. fixMin: rawExtentResult.minFixed,
  32332. fixMax: rawExtentResult.maxFixed
  32333. };
  32334. }
  32335. function adjustScaleForOverflow(min, max, model, // Only support cartesian coord yet.
  32336. barWidthAndOffset) {
  32337. // Get Axis Length
  32338. var axisExtent = model.axis.getExtent();
  32339. var axisLength = axisExtent[1] - axisExtent[0]; // Get bars on current base axis and calculate min and max overflow
  32340. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  32341. if (barsOnCurrentAxis === undefined) {
  32342. return {
  32343. min: min,
  32344. max: max
  32345. };
  32346. }
  32347. var minOverflow = Infinity;
  32348. each(barsOnCurrentAxis, function (item) {
  32349. minOverflow = Math.min(item.offset, minOverflow);
  32350. });
  32351. var maxOverflow = -Infinity;
  32352. each(barsOnCurrentAxis, function (item) {
  32353. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  32354. });
  32355. minOverflow = Math.abs(minOverflow);
  32356. maxOverflow = Math.abs(maxOverflow);
  32357. var totalOverFlow = minOverflow + maxOverflow; // Calculate required buffer based on old range and overflow
  32358. var oldRange = max - min;
  32359. var oldRangePercentOfNew = 1 - (minOverflow + maxOverflow) / axisLength;
  32360. var overflowBuffer = oldRange / oldRangePercentOfNew - oldRange;
  32361. max += overflowBuffer * (maxOverflow / totalOverFlow);
  32362. min -= overflowBuffer * (minOverflow / totalOverFlow);
  32363. return {
  32364. min: min,
  32365. max: max
  32366. };
  32367. } // Precondition of calling this method:
  32368. // The scale extent has been initailized using series data extent via
  32369. // `scale.setExtent` or `scale.unionExtentFromData`;
  32370. function niceScaleExtent(scale, inModel) {
  32371. var model = inModel;
  32372. var extentInfo = getScaleExtent(scale, model);
  32373. var extent = extentInfo.extent;
  32374. var splitNumber = model.get('splitNumber');
  32375. if (scale instanceof LogScale) {
  32376. scale.base = model.get('logBase');
  32377. }
  32378. var scaleType = scale.type;
  32379. scale.setExtent(extent[0], extent[1]);
  32380. scale.niceExtent({
  32381. splitNumber: splitNumber,
  32382. fixMin: extentInfo.fixMin,
  32383. fixMax: extentInfo.fixMax,
  32384. minInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('minInterval') : null,
  32385. maxInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('maxInterval') : null
  32386. }); // If some one specified the min, max. And the default calculated interval
  32387. // is not good enough. He can specify the interval. It is often appeared
  32388. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  32389. // to be 60.
  32390. // FIXME
  32391. var interval = model.get('interval');
  32392. if (interval != null) {
  32393. scale.setInterval && scale.setInterval(interval);
  32394. }
  32395. }
  32396. /**
  32397. * @param axisType Default retrieve from model.type
  32398. */
  32399. function createScaleByModel(model, axisType) {
  32400. axisType = axisType || model.get('type');
  32401. if (axisType) {
  32402. switch (axisType) {
  32403. // Buildin scale
  32404. case 'category':
  32405. return new OrdinalScale({
  32406. ordinalMeta: model.getOrdinalMeta ? model.getOrdinalMeta() : model.getCategories(),
  32407. extent: [Infinity, -Infinity]
  32408. });
  32409. case 'time':
  32410. return new TimeScale({
  32411. locale: model.ecModel.getLocaleModel(),
  32412. useUTC: model.ecModel.get('useUTC')
  32413. });
  32414. default:
  32415. // case 'value'/'interval', 'log', or others.
  32416. return new (Scale.getClass(axisType) || IntervalScale)();
  32417. }
  32418. }
  32419. }
  32420. /**
  32421. * Check if the axis cross 0
  32422. */
  32423. function ifAxisCrossZero(axis) {
  32424. var dataExtent = axis.scale.getExtent();
  32425. var min = dataExtent[0];
  32426. var max = dataExtent[1];
  32427. return !(min > 0 && max > 0 || min < 0 && max < 0);
  32428. }
  32429. /**
  32430. * @param axis
  32431. * @return Label formatter function.
  32432. * param: {number} tickValue,
  32433. * param: {number} idx, the index in all ticks.
  32434. * If category axis, this param is not required.
  32435. * return: {string} label string.
  32436. */
  32437. function makeLabelFormatter(axis) {
  32438. var labelFormatter = axis.getLabelModel().get('formatter');
  32439. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  32440. if (axis.scale.type === 'time') {
  32441. return function (tpl) {
  32442. return function (tick, idx) {
  32443. return axis.scale.getFormattedLabel(tick, idx, tpl);
  32444. };
  32445. }(labelFormatter);
  32446. } else if (typeof labelFormatter === 'string') {
  32447. return function (tpl) {
  32448. return function (tick) {
  32449. // For category axis, get raw value; for numeric axis,
  32450. // get formatted label like '1,333,444'.
  32451. var label = axis.scale.getLabel(tick);
  32452. var text = tpl.replace('{value}', label != null ? label : '');
  32453. return text;
  32454. };
  32455. }(labelFormatter);
  32456. } else if (typeof labelFormatter === 'function') {
  32457. return function (cb) {
  32458. return function (tick, idx) {
  32459. // The original intention of `idx` is "the index of the tick in all ticks".
  32460. // But the previous implementation of category axis do not consider the
  32461. // `axisLabel.interval`, which cause that, for example, the `interval` is
  32462. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  32463. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  32464. // the definition here for back compatibility.
  32465. if (categoryTickStart != null) {
  32466. idx = tick.value - categoryTickStart;
  32467. }
  32468. return cb(getAxisRawValue(axis, tick), idx, tick.level != null ? {
  32469. level: tick.level
  32470. } : null);
  32471. };
  32472. }(labelFormatter);
  32473. } else {
  32474. return function (tick) {
  32475. return axis.scale.getLabel(tick);
  32476. };
  32477. }
  32478. }
  32479. function getAxisRawValue(axis, tick) {
  32480. // In category axis with data zoom, tick is not the original
  32481. // index of axis.data. So tick should not be exposed to user
  32482. // in category axis.
  32483. return axis.type === 'category' ? axis.scale.getLabel(tick) : tick.value;
  32484. }
  32485. /**
  32486. * @param axis
  32487. * @return Be null/undefined if no labels.
  32488. */
  32489. function estimateLabelUnionRect(axis) {
  32490. var axisModel = axis.model;
  32491. var scale = axis.scale;
  32492. if (!axisModel.get(['axisLabel', 'show']) || scale.isBlank()) {
  32493. return;
  32494. }
  32495. var realNumberScaleTicks;
  32496. var tickCount;
  32497. var categoryScaleExtent = scale.getExtent(); // Optimize for large category data, avoid call `getTicks()`.
  32498. if (scale instanceof OrdinalScale) {
  32499. tickCount = scale.count();
  32500. } else {
  32501. realNumberScaleTicks = scale.getTicks();
  32502. tickCount = realNumberScaleTicks.length;
  32503. }
  32504. var axisLabelModel = axis.getLabelModel();
  32505. var labelFormatter = makeLabelFormatter(axis);
  32506. var rect;
  32507. var step = 1; // Simple optimization for large amount of labels
  32508. if (tickCount > 40) {
  32509. step = Math.ceil(tickCount / 40);
  32510. }
  32511. for (var i = 0; i < tickCount; i += step) {
  32512. var tick = realNumberScaleTicks ? realNumberScaleTicks[i] : {
  32513. value: categoryScaleExtent[0] + i
  32514. };
  32515. var label = labelFormatter(tick, i);
  32516. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  32517. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  32518. rect ? rect.union(singleRect) : rect = singleRect;
  32519. }
  32520. return rect;
  32521. }
  32522. function rotateTextRect(textRect, rotate) {
  32523. var rotateRadians = rotate * Math.PI / 180;
  32524. var beforeWidth = textRect.width;
  32525. var beforeHeight = textRect.height;
  32526. var afterWidth = beforeWidth * Math.abs(Math.cos(rotateRadians)) + Math.abs(beforeHeight * Math.sin(rotateRadians));
  32527. var afterHeight = beforeWidth * Math.abs(Math.sin(rotateRadians)) + Math.abs(beforeHeight * Math.cos(rotateRadians));
  32528. var rotatedRect = new BoundingRect(textRect.x, textRect.y, afterWidth, afterHeight);
  32529. return rotatedRect;
  32530. }
  32531. /**
  32532. * @param model axisLabelModel or axisTickModel
  32533. * @return {number|String} Can be null|'auto'|number|function
  32534. */
  32535. function getOptionCategoryInterval(model) {
  32536. var interval = model.get('interval');
  32537. return interval == null ? 'auto' : interval;
  32538. }
  32539. /**
  32540. * Set `categoryInterval` as 0 implicitly indicates that
  32541. * show all labels reguardless of overlap.
  32542. * @param {Object} axis axisModel.axis
  32543. */
  32544. function shouldShowAllLabels(axis) {
  32545. return axis.type === 'category' && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  32546. }
  32547. function getDataDimensionsOnAxis(data, axisDim) {
  32548. // Remove duplicated dat dimensions caused by `getStackedDimension`.
  32549. var dataDimMap = {}; // Currently `mapDimensionsAll` will contain stack result dimension ('__\0ecstackresult').
  32550. // PENDING: is it reasonable? Do we need to remove the original dim from "coord dim" since
  32551. // there has been stacked result dim?
  32552. each(data.mapDimensionsAll(axisDim), function (dataDim) {
  32553. // For example, the extent of the original dimension
  32554. // is [0.1, 0.5], the extent of the `stackResultDimension`
  32555. // is [7, 9], the final extent should NOT include [0.1, 0.5],
  32556. // because there is no graphic corresponding to [0.1, 0.5].
  32557. // See the case in `test/area-stack.html` `main1`, where area line
  32558. // stack needs `yAxis` not start from 0.
  32559. dataDimMap[getStackedDimension(data, dataDim)] = true;
  32560. });
  32561. return keys(dataDimMap);
  32562. }
  32563. function unionAxisExtentFromData(dataExtent, data, axisDim) {
  32564. if (data) {
  32565. each(getDataDimensionsOnAxis(data, axisDim), function (dim) {
  32566. var seriesExtent = data.getApproximateExtent(dim);
  32567. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  32568. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  32569. });
  32570. }
  32571. }
  32572. /*
  32573. * Licensed to the Apache Software Foundation (ASF) under one
  32574. * or more contributor license agreements. See the NOTICE file
  32575. * distributed with this work for additional information
  32576. * regarding copyright ownership. The ASF licenses this file
  32577. * to you under the Apache License, Version 2.0 (the
  32578. * "License"); you may not use this file except in compliance
  32579. * with the License. You may obtain a copy of the License at
  32580. *
  32581. * http://www.apache.org/licenses/LICENSE-2.0
  32582. *
  32583. * Unless required by applicable law or agreed to in writing,
  32584. * software distributed under the License is distributed on an
  32585. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32586. * KIND, either express or implied. See the License for the
  32587. * specific language governing permissions and limitations
  32588. * under the License.
  32589. */
  32590. /**
  32591. * AUTO-GENERATED FILE. DO NOT MODIFY.
  32592. */
  32593. /*
  32594. * Licensed to the Apache Software Foundation (ASF) under one
  32595. * or more contributor license agreements. See the NOTICE file
  32596. * distributed with this work for additional information
  32597. * regarding copyright ownership. The ASF licenses this file
  32598. * to you under the Apache License, Version 2.0 (the
  32599. * "License"); you may not use this file except in compliance
  32600. * with the License. You may obtain a copy of the License at
  32601. *
  32602. * http://www.apache.org/licenses/LICENSE-2.0
  32603. *
  32604. * Unless required by applicable law or agreed to in writing,
  32605. * software distributed under the License is distributed on an
  32606. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32607. * KIND, either express or implied. See the License for the
  32608. * specific language governing permissions and limitations
  32609. * under the License.
  32610. */
  32611. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  32612. var AxisModelCommonMixin =
  32613. /** @class */
  32614. function () {
  32615. function AxisModelCommonMixin() {}
  32616. AxisModelCommonMixin.prototype.getNeedCrossZero = function () {
  32617. var option = this.option;
  32618. return !option.scale;
  32619. };
  32620. /**
  32621. * Should be implemented by each axis model if necessary.
  32622. * @return coordinate system model
  32623. */
  32624. AxisModelCommonMixin.prototype.getCoordSysModel = function () {
  32625. return;
  32626. };
  32627. return AxisModelCommonMixin;
  32628. }();
  32629. /**
  32630. * Create a muti dimension List structure from seriesModel.
  32631. */
  32632. function createList(seriesModel) {
  32633. return createSeriesData(null, seriesModel);
  32634. } // export function createGraph(seriesModel) {
  32635. var dataStack$1 = {
  32636. isDimensionStacked: isDimensionStacked,
  32637. enableDataStack: enableDataStack,
  32638. getStackedDimension: getStackedDimension
  32639. };
  32640. /**
  32641. * Create scale
  32642. * @param {Array.<number>} dataExtent
  32643. * @param {Object|module:echarts/Model} option If `optoin.type`
  32644. * is secified, it can only be `'value'` currently.
  32645. */
  32646. function createScale(dataExtent, option) {
  32647. var axisModel = option;
  32648. if (!(option instanceof Model)) {
  32649. axisModel = new Model(option); // FIXME
  32650. // Currently AxisModelCommonMixin has nothing to do with the
  32651. // the requirements of `axisHelper.createScaleByModel`. For
  32652. // example the method `getCategories` and `getOrdinalMeta`
  32653. // are required for `'category'` axis, and ecModel are required
  32654. // for `'time'` axis. But occationally echarts-gl happened
  32655. // to only use `'value'` axis.
  32656. // zrUtil.mixin(axisModel, AxisModelCommonMixin);
  32657. }
  32658. var scale = createScaleByModel(axisModel);
  32659. scale.setExtent(dataExtent[0], dataExtent[1]);
  32660. niceScaleExtent(scale, axisModel);
  32661. return scale;
  32662. }
  32663. /**
  32664. * Mixin common methods to axis model,
  32665. *
  32666. * Inlcude methods
  32667. * `getFormattedLabels() => Array.<string>`
  32668. * `getCategories() => Array.<string>`
  32669. * `getMin(origin: boolean) => number`
  32670. * `getMax(origin: boolean) => number`
  32671. * `getNeedCrossZero() => boolean`
  32672. */
  32673. function mixinAxisModelCommonMethods(Model) {
  32674. mixin(Model, AxisModelCommonMixin);
  32675. }
  32676. function createTextStyle$1(textStyleModel, opts) {
  32677. opts = opts || {};
  32678. return createTextStyle(textStyleModel, null, null, opts.state !== 'normal');
  32679. }
  32680. var helper = /*#__PURE__*/Object.freeze({
  32681. __proto__: null,
  32682. createList: createList,
  32683. getLayoutRect: getLayoutRect,
  32684. dataStack: dataStack$1,
  32685. createScale: createScale,
  32686. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  32687. getECData: getECData,
  32688. createTextStyle: createTextStyle$1,
  32689. createDimensions: createDimensions,
  32690. createSymbol: createSymbol,
  32691. enableHoverEmphasis: enableHoverEmphasis
  32692. });
  32693. var number = /*#__PURE__*/Object.freeze({
  32694. __proto__: null,
  32695. linearMap: linearMap,
  32696. round: round,
  32697. asc: asc,
  32698. getPrecision: getPrecision,
  32699. getPrecisionSafe: getPrecisionSafe,
  32700. getPixelPrecision: getPixelPrecision,
  32701. getPercentWithPrecision: getPercentWithPrecision,
  32702. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  32703. remRadian: remRadian,
  32704. isRadianAroundZero: isRadianAroundZero,
  32705. parseDate: parseDate,
  32706. quantity: quantity,
  32707. quantityExponent: quantityExponent,
  32708. nice: nice,
  32709. quantile: quantile,
  32710. reformIntervals: reformIntervals,
  32711. isNumeric: isNumeric,
  32712. numericToNumber: numericToNumber
  32713. });
  32714. var time = /*#__PURE__*/Object.freeze({
  32715. __proto__: null,
  32716. parse: parseDate,
  32717. format: format
  32718. });
  32719. var graphic$1 = /*#__PURE__*/Object.freeze({
  32720. __proto__: null,
  32721. extendShape: extendShape,
  32722. extendPath: extendPath,
  32723. makePath: makePath,
  32724. makeImage: makeImage,
  32725. mergePath: mergePath$1,
  32726. resizePath: resizePath,
  32727. createIcon: createIcon,
  32728. updateProps: updateProps,
  32729. initProps: initProps,
  32730. getTransform: getTransform,
  32731. clipPointsByRect: clipPointsByRect,
  32732. clipRectByRect: clipRectByRect,
  32733. registerShape: registerShape,
  32734. getShapeClass: getShapeClass,
  32735. Group: Group,
  32736. Image: ZRImage,
  32737. Text: ZRText,
  32738. Circle: Circle,
  32739. Ellipse: Ellipse,
  32740. Sector: Sector,
  32741. Ring: Ring,
  32742. Polygon: Polygon,
  32743. Polyline: Polyline,
  32744. Rect: Rect,
  32745. Line: Line,
  32746. BezierCurve: BezierCurve,
  32747. Arc: Arc,
  32748. IncrementalDisplayable: IncrementalDisplayable,
  32749. CompoundPath: CompoundPath,
  32750. LinearGradient: LinearGradient,
  32751. RadialGradient: RadialGradient,
  32752. BoundingRect: BoundingRect
  32753. });
  32754. var format$1 = /*#__PURE__*/Object.freeze({
  32755. __proto__: null,
  32756. addCommas: addCommas,
  32757. toCamelCase: toCamelCase,
  32758. normalizeCssArray: normalizeCssArray$1,
  32759. encodeHTML: encodeHTML,
  32760. formatTpl: formatTpl,
  32761. getTooltipMarker: getTooltipMarker,
  32762. formatTime: formatTime,
  32763. capitalFirst: capitalFirst,
  32764. truncateText: truncateText,
  32765. getTextRect: getTextRect
  32766. });
  32767. var util$1 = /*#__PURE__*/Object.freeze({
  32768. __proto__: null,
  32769. map: map,
  32770. each: each,
  32771. indexOf: indexOf,
  32772. inherits: inherits,
  32773. reduce: reduce,
  32774. filter: filter,
  32775. bind: bind,
  32776. curry: curry,
  32777. isArray: isArray,
  32778. isString: isString,
  32779. isObject: isObject,
  32780. isFunction: isFunction,
  32781. extend: extend,
  32782. defaults: defaults,
  32783. clone: clone,
  32784. merge: merge
  32785. });
  32786. var inner$5 = makeInner();
  32787. function createAxisLabels(axis) {
  32788. // Only ordinal scale support tick interval
  32789. return axis.type === 'category' ? makeCategoryLabels(axis) : makeRealNumberLabels(axis);
  32790. }
  32791. /**
  32792. * @param {module:echats/coord/Axis} axis
  32793. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  32794. * @return {Object} {
  32795. * ticks: Array.<number>
  32796. * tickCategoryInterval: number
  32797. * }
  32798. */
  32799. function createAxisTicks(axis, tickModel) {
  32800. // Only ordinal scale support tick interval
  32801. return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
  32802. ticks: map(axis.scale.getTicks(), function (tick) {
  32803. return tick.value;
  32804. })
  32805. };
  32806. }
  32807. function makeCategoryLabels(axis) {
  32808. var labelModel = axis.getLabelModel();
  32809. var result = makeCategoryLabelsActually(axis, labelModel);
  32810. return !labelModel.get('show') || axis.scale.isBlank() ? {
  32811. labels: [],
  32812. labelCategoryInterval: result.labelCategoryInterval
  32813. } : result;
  32814. }
  32815. function makeCategoryLabelsActually(axis, labelModel) {
  32816. var labelsCache = getListCache(axis, 'labels');
  32817. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  32818. var result = listCacheGet(labelsCache, optionLabelInterval);
  32819. if (result) {
  32820. return result;
  32821. }
  32822. var labels;
  32823. var numericLabelInterval;
  32824. if (isFunction(optionLabelInterval)) {
  32825. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  32826. } else {
  32827. numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  32828. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  32829. } // Cache to avoid calling interval function repeatly.
  32830. return listCacheSet(labelsCache, optionLabelInterval, {
  32831. labels: labels,
  32832. labelCategoryInterval: numericLabelInterval
  32833. });
  32834. }
  32835. function makeCategoryTicks(axis, tickModel) {
  32836. var ticksCache = getListCache(axis, 'ticks');
  32837. var optionTickInterval = getOptionCategoryInterval(tickModel);
  32838. var result = listCacheGet(ticksCache, optionTickInterval);
  32839. if (result) {
  32840. return result;
  32841. }
  32842. var ticks;
  32843. var tickCategoryInterval; // Optimize for the case that large category data and no label displayed,
  32844. // we should not return all ticks.
  32845. if (!tickModel.get('show') || axis.scale.isBlank()) {
  32846. ticks = [];
  32847. }
  32848. if (isFunction(optionTickInterval)) {
  32849. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  32850. } // Always use label interval by default despite label show. Consider this
  32851. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  32852. // labels. `splitLine` and `axisTick` should be consistent in this case.
  32853. else if (optionTickInterval === 'auto') {
  32854. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  32855. tickCategoryInterval = labelsResult.labelCategoryInterval;
  32856. ticks = map(labelsResult.labels, function (labelItem) {
  32857. return labelItem.tickValue;
  32858. });
  32859. } else {
  32860. tickCategoryInterval = optionTickInterval;
  32861. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  32862. } // Cache to avoid calling interval function repeatly.
  32863. return listCacheSet(ticksCache, optionTickInterval, {
  32864. ticks: ticks,
  32865. tickCategoryInterval: tickCategoryInterval
  32866. });
  32867. }
  32868. function makeRealNumberLabels(axis) {
  32869. var ticks = axis.scale.getTicks();
  32870. var labelFormatter = makeLabelFormatter(axis);
  32871. return {
  32872. labels: map(ticks, function (tick, idx) {
  32873. return {
  32874. level: tick.level,
  32875. formattedLabel: labelFormatter(tick, idx),
  32876. rawLabel: axis.scale.getLabel(tick),
  32877. tickValue: tick.value
  32878. };
  32879. })
  32880. };
  32881. }
  32882. function getListCache(axis, prop) {
  32883. // Because key can be funciton, and cache size always be small, we use array cache.
  32884. return inner$5(axis)[prop] || (inner$5(axis)[prop] = []);
  32885. }
  32886. function listCacheGet(cache, key) {
  32887. for (var i = 0; i < cache.length; i++) {
  32888. if (cache[i].key === key) {
  32889. return cache[i].value;
  32890. }
  32891. }
  32892. }
  32893. function listCacheSet(cache, key, value) {
  32894. cache.push({
  32895. key: key,
  32896. value: value
  32897. });
  32898. return value;
  32899. }
  32900. function makeAutoCategoryInterval(axis) {
  32901. var result = inner$5(axis).autoInterval;
  32902. return result != null ? result : inner$5(axis).autoInterval = axis.calculateCategoryInterval();
  32903. }
  32904. /**
  32905. * Calculate interval for category axis ticks and labels.
  32906. * To get precise result, at least one of `getRotate` and `isHorizontal`
  32907. * should be implemented in axis.
  32908. */
  32909. function calculateCategoryInterval(axis) {
  32910. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  32911. var labelFormatter = makeLabelFormatter(axis);
  32912. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  32913. var ordinalScale = axis.scale;
  32914. var ordinalExtent = ordinalScale.getExtent(); // Providing this method is for optimization:
  32915. // avoid generating a long array by `getTicks`
  32916. // in large category data case.
  32917. var tickCount = ordinalScale.count();
  32918. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  32919. return 0;
  32920. }
  32921. var step = 1; // Simple optimization. Empirical value: tick count should less than 40.
  32922. if (tickCount > 40) {
  32923. step = Math.max(1, Math.floor(tickCount / 40));
  32924. }
  32925. var tickValue = ordinalExtent[0];
  32926. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  32927. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  32928. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  32929. var maxW = 0;
  32930. var maxH = 0; // Caution: Performance sensitive for large category data.
  32931. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  32932. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  32933. var width = 0;
  32934. var height = 0; // Not precise, do not consider align and vertical align
  32935. // and each distance from axis line yet.
  32936. var rect = getBoundingRect(labelFormatter({
  32937. value: tickValue
  32938. }), params.font, 'center', 'top'); // Magic number
  32939. width = rect.width * 1.3;
  32940. height = rect.height * 1.3; // Min size, void long loop.
  32941. maxW = Math.max(maxW, width, 7);
  32942. maxH = Math.max(maxH, height, 7);
  32943. }
  32944. var dw = maxW / unitW;
  32945. var dh = maxH / unitH; // 0/0 is NaN, 1/0 is Infinity.
  32946. isNaN(dw) && (dw = Infinity);
  32947. isNaN(dh) && (dh = Infinity);
  32948. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  32949. var cache = inner$5(axis.model);
  32950. var axisExtent = axis.getExtent();
  32951. var lastAutoInterval = cache.lastAutoInterval;
  32952. var lastTickCount = cache.lastTickCount; // Use cache to keep interval stable while moving zoom window,
  32953. // otherwise the calculated interval might jitter when the zoom
  32954. // window size is close to the interval-changing size.
  32955. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  32956. // The jitter will cause that sometimes the displayed labels are
  32957. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  32958. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1 // Always choose the bigger one, otherwise the critical
  32959. // point is not the same when zooming in or zooming out.
  32960. && lastAutoInterval > interval // If the axis change is caused by chart resize, the cache should not
  32961. // be used. Otherwise some hiden labels might not be shown again.
  32962. && cache.axisExtent0 === axisExtent[0] && cache.axisExtent1 === axisExtent[1]) {
  32963. interval = lastAutoInterval;
  32964. } // Only update cache if cache not used, otherwise the
  32965. // changing of interval is too insensitive.
  32966. else {
  32967. cache.lastTickCount = tickCount;
  32968. cache.lastAutoInterval = interval;
  32969. cache.axisExtent0 = axisExtent[0];
  32970. cache.axisExtent1 = axisExtent[1];
  32971. }
  32972. return interval;
  32973. }
  32974. function fetchAutoCategoryIntervalCalculationParams(axis) {
  32975. var labelModel = axis.getLabelModel();
  32976. return {
  32977. axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
  32978. labelRotate: labelModel.get('rotate') || 0,
  32979. font: labelModel.getFont()
  32980. };
  32981. }
  32982. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  32983. var labelFormatter = makeLabelFormatter(axis);
  32984. var ordinalScale = axis.scale;
  32985. var ordinalExtent = ordinalScale.getExtent();
  32986. var labelModel = axis.getLabelModel();
  32987. var result = []; // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  32988. var step = Math.max((categoryInterval || 0) + 1, 1);
  32989. var startTick = ordinalExtent[0];
  32990. var tickCount = ordinalScale.count(); // Calculate start tick based on zero if possible to keep label consistent
  32991. // while zooming and moving while interval > 0. Otherwise the selection
  32992. // of displayable ticks and symbols probably keep changing.
  32993. // 3 is empirical value.
  32994. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  32995. startTick = Math.round(Math.ceil(startTick / step) * step);
  32996. } // (1) Only add min max label here but leave overlap checking
  32997. // to render stage, which also ensure the returned list
  32998. // suitable for splitLine and splitArea rendering.
  32999. // (2) Scales except category always contain min max label so
  33000. // do not need to perform this process.
  33001. var showAllLabel = shouldShowAllLabels(axis);
  33002. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  33003. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  33004. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  33005. addItem(ordinalExtent[0]);
  33006. } // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  33007. var tickValue = startTick;
  33008. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  33009. addItem(tickValue);
  33010. }
  33011. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  33012. addItem(ordinalExtent[1]);
  33013. }
  33014. function addItem(tickValue) {
  33015. var tickObj = {
  33016. value: tickValue
  33017. };
  33018. result.push(onlyTick ? tickValue : {
  33019. formattedLabel: labelFormatter(tickObj),
  33020. rawLabel: ordinalScale.getLabel(tickObj),
  33021. tickValue: tickValue
  33022. });
  33023. }
  33024. return result;
  33025. }
  33026. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  33027. var ordinalScale = axis.scale;
  33028. var labelFormatter = makeLabelFormatter(axis);
  33029. var result = [];
  33030. each(ordinalScale.getTicks(), function (tick) {
  33031. var rawLabel = ordinalScale.getLabel(tick);
  33032. var tickValue = tick.value;
  33033. if (categoryInterval(tick.value, rawLabel)) {
  33034. result.push(onlyTick ? tickValue : {
  33035. formattedLabel: labelFormatter(tick),
  33036. rawLabel: rawLabel,
  33037. tickValue: tickValue
  33038. });
  33039. }
  33040. });
  33041. return result;
  33042. }
  33043. var NORMALIZED_EXTENT = [0, 1];
  33044. /**
  33045. * Base class of Axis.
  33046. */
  33047. var Axis =
  33048. /** @class */
  33049. function () {
  33050. function Axis(dim, scale, extent) {
  33051. this.onBand = false;
  33052. this.inverse = false;
  33053. this.dim = dim;
  33054. this.scale = scale;
  33055. this._extent = extent || [0, 0];
  33056. }
  33057. /**
  33058. * If axis extent contain given coord
  33059. */
  33060. Axis.prototype.contain = function (coord) {
  33061. var extent = this._extent;
  33062. var min = Math.min(extent[0], extent[1]);
  33063. var max = Math.max(extent[0], extent[1]);
  33064. return coord >= min && coord <= max;
  33065. };
  33066. /**
  33067. * If axis extent contain given data
  33068. */
  33069. Axis.prototype.containData = function (data) {
  33070. return this.scale.contain(data);
  33071. };
  33072. /**
  33073. * Get coord extent.
  33074. */
  33075. Axis.prototype.getExtent = function () {
  33076. return this._extent.slice();
  33077. };
  33078. /**
  33079. * Get precision used for formatting
  33080. */
  33081. Axis.prototype.getPixelPrecision = function (dataExtent) {
  33082. return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
  33083. };
  33084. /**
  33085. * Set coord extent
  33086. */
  33087. Axis.prototype.setExtent = function (start, end) {
  33088. var extent = this._extent;
  33089. extent[0] = start;
  33090. extent[1] = end;
  33091. };
  33092. /**
  33093. * Convert data to coord. Data is the rank if it has an ordinal scale
  33094. */
  33095. Axis.prototype.dataToCoord = function (data, clamp) {
  33096. var extent = this._extent;
  33097. var scale = this.scale;
  33098. data = scale.normalize(data);
  33099. if (this.onBand && scale.type === 'ordinal') {
  33100. extent = extent.slice();
  33101. fixExtentWithBands(extent, scale.count());
  33102. }
  33103. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  33104. };
  33105. /**
  33106. * Convert coord to data. Data is the rank if it has an ordinal scale
  33107. */
  33108. Axis.prototype.coordToData = function (coord, clamp) {
  33109. var extent = this._extent;
  33110. var scale = this.scale;
  33111. if (this.onBand && scale.type === 'ordinal') {
  33112. extent = extent.slice();
  33113. fixExtentWithBands(extent, scale.count());
  33114. }
  33115. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  33116. return this.scale.scale(t);
  33117. };
  33118. /**
  33119. * Convert pixel point to data in axis
  33120. */
  33121. Axis.prototype.pointToData = function (point, clamp) {
  33122. // Should be implemented in derived class if necessary.
  33123. return;
  33124. };
  33125. /**
  33126. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  33127. * `axis.getTicksCoords` considers `onBand`, which is used by
  33128. * `boundaryGap:true` of category axis and splitLine and splitArea.
  33129. * @param opt.tickModel default: axis.model.getModel('axisTick')
  33130. * @param opt.clamp If `true`, the first and the last
  33131. * tick must be at the axis end points. Otherwise, clip ticks
  33132. * that outside the axis extent.
  33133. */
  33134. Axis.prototype.getTicksCoords = function (opt) {
  33135. opt = opt || {};
  33136. var tickModel = opt.tickModel || this.getTickModel();
  33137. var result = createAxisTicks(this, tickModel);
  33138. var ticks = result.ticks;
  33139. var ticksCoords = map(ticks, function (tickVal) {
  33140. return {
  33141. coord: this.dataToCoord(this.scale.type === 'ordinal' ? this.scale.getRawOrdinalNumber(tickVal) : tickVal),
  33142. tickValue: tickVal
  33143. };
  33144. }, this);
  33145. var alignWithLabel = tickModel.get('alignWithLabel');
  33146. fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
  33147. return ticksCoords;
  33148. };
  33149. Axis.prototype.getMinorTicksCoords = function () {
  33150. if (this.scale.type === 'ordinal') {
  33151. // Category axis doesn't support minor ticks
  33152. return [];
  33153. }
  33154. var minorTickModel = this.model.getModel('minorTick');
  33155. var splitNumber = minorTickModel.get('splitNumber'); // Protection.
  33156. if (!(splitNumber > 0 && splitNumber < 100)) {
  33157. splitNumber = 5;
  33158. }
  33159. var minorTicks = this.scale.getMinorTicks(splitNumber);
  33160. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  33161. return map(minorTicksGroup, function (minorTick) {
  33162. return {
  33163. coord: this.dataToCoord(minorTick),
  33164. tickValue: minorTick
  33165. };
  33166. }, this);
  33167. }, this);
  33168. return minorTicksCoords;
  33169. };
  33170. Axis.prototype.getViewLabels = function () {
  33171. return createAxisLabels(this).labels;
  33172. };
  33173. Axis.prototype.getLabelModel = function () {
  33174. return this.model.getModel('axisLabel');
  33175. };
  33176. /**
  33177. * Notice here we only get the default tick model. For splitLine
  33178. * or splitArea, we should pass the splitLineModel or splitAreaModel
  33179. * manually when calling `getTicksCoords`.
  33180. * In GL, this method may be overrided to:
  33181. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  33182. */
  33183. Axis.prototype.getTickModel = function () {
  33184. return this.model.getModel('axisTick');
  33185. };
  33186. /**
  33187. * Get width of band
  33188. */
  33189. Axis.prototype.getBandWidth = function () {
  33190. var axisExtent = this._extent;
  33191. var dataExtent = this.scale.getExtent();
  33192. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0); // Fix #2728, avoid NaN when only one data.
  33193. len === 0 && (len = 1);
  33194. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  33195. return Math.abs(size) / len;
  33196. };
  33197. /**
  33198. * Only be called in category axis.
  33199. * Can be overrided, consider other axes like in 3D.
  33200. * @return Auto interval for cateogry axis tick and label
  33201. */
  33202. Axis.prototype.calculateCategoryInterval = function () {
  33203. return calculateCategoryInterval(this);
  33204. };
  33205. return Axis;
  33206. }();
  33207. function fixExtentWithBands(extent, nTick) {
  33208. var size = extent[1] - extent[0];
  33209. var len = nTick;
  33210. var margin = size / len / 2;
  33211. extent[0] += margin;
  33212. extent[1] -= margin;
  33213. } // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  33214. // |---1---|---2---|---3---|---4---|.
  33215. // So the displayed ticks and splitLine/splitArea should between
  33216. // each data item, otherwise cause misleading (e.g., split tow bars
  33217. // of a single data item when there are two bar series).
  33218. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  33219. // splitLine/spliteArea should layout appropriately corresponding
  33220. // to displayed labels. (So we should not use `getBandWidth` in this
  33221. // case).
  33222. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  33223. var ticksLen = ticksCoords.length;
  33224. if (!axis.onBand || alignWithLabel || !ticksLen) {
  33225. return;
  33226. }
  33227. var axisExtent = axis.getExtent();
  33228. var last;
  33229. var diffSize;
  33230. if (ticksLen === 1) {
  33231. ticksCoords[0].coord = axisExtent[0];
  33232. last = ticksCoords[1] = {
  33233. coord: axisExtent[0]
  33234. };
  33235. } else {
  33236. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  33237. var shift_1 = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  33238. each(ticksCoords, function (ticksItem) {
  33239. ticksItem.coord -= shift_1 / 2;
  33240. });
  33241. var dataExtent = axis.scale.getExtent();
  33242. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  33243. last = {
  33244. coord: ticksCoords[ticksLen - 1].coord + shift_1 * diffSize
  33245. };
  33246. ticksCoords.push(last);
  33247. }
  33248. var inverse = axisExtent[0] > axisExtent[1]; // Handling clamp.
  33249. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  33250. clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
  33251. }
  33252. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  33253. ticksCoords.unshift({
  33254. coord: axisExtent[0]
  33255. });
  33256. }
  33257. if (littleThan(axisExtent[1], last.coord)) {
  33258. clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
  33259. }
  33260. if (clamp && littleThan(last.coord, axisExtent[1])) {
  33261. ticksCoords.push({
  33262. coord: axisExtent[1]
  33263. });
  33264. }
  33265. function littleThan(a, b) {
  33266. // Avoid rounding error cause calculated tick coord different with extent.
  33267. // It may cause an extra unecessary tick added.
  33268. a = round(a);
  33269. b = round(b);
  33270. return inverse ? a > b : a < b;
  33271. }
  33272. }
  33273. // Should use `ComponentModel.extend` or `class XXXX extend ComponentModel` to create class.
  33274. // Then use `registerComponentModel` in `install` parameter when `use` this extension. For example:
  33275. // class Bar3DModel extends ComponentModel {}
  33276. // export function install(registers) { regsiters.registerComponentModel(Bar3DModel); }
  33277. // echarts.use(install);
  33278. function extendComponentModel(proto) {
  33279. var Model = ComponentModel.extend(proto);
  33280. ComponentModel.registerClass(Model);
  33281. return Model;
  33282. }
  33283. function extendComponentView(proto) {
  33284. var View = ComponentView.extend(proto);
  33285. ComponentView.registerClass(View);
  33286. return View;
  33287. }
  33288. function extendSeriesModel(proto) {
  33289. var Model = SeriesModel.extend(proto);
  33290. SeriesModel.registerClass(Model);
  33291. return Model;
  33292. }
  33293. function extendChartView(proto) {
  33294. var View = ChartView.extend(proto);
  33295. ChartView.registerClass(View);
  33296. return View;
  33297. }
  33298. function projectPointToLine(x1, y1, x2, y2, x, y, out, limitToEnds) {
  33299. var dx = x - x1;
  33300. var dy = y - y1;
  33301. var dx1 = x2 - x1;
  33302. var dy1 = y2 - y1;
  33303. var lineLen = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  33304. dx1 /= lineLen;
  33305. dy1 /= lineLen; // dot product
  33306. var projectedLen = dx * dx1 + dy * dy1;
  33307. var t = projectedLen / lineLen;
  33308. if (limitToEnds) {
  33309. t = Math.min(Math.max(t, 0), 1);
  33310. }
  33311. t *= lineLen;
  33312. var ox = out[0] = x1 + t * dx1;
  33313. var oy = out[1] = y1 + t * dy1;
  33314. return Math.sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
  33315. }
  33316. var pt0 = new Point();
  33317. var pt1 = new Point();
  33318. var pt2 = new Point();
  33319. var dir = new Point();
  33320. var dir2 = new Point();
  33321. var tmpArr = [];
  33322. var tmpProjPoint = new Point();
  33323. /**
  33324. * Reduce the line segment attached to the label to limit the turn angle between two segments.
  33325. * @param linePoints
  33326. * @param minTurnAngle Radian of minimum turn angle. 0 - 180
  33327. */
  33328. function limitTurnAngle(linePoints, minTurnAngle) {
  33329. if (!(minTurnAngle <= 180 && minTurnAngle > 0)) {
  33330. return;
  33331. }
  33332. minTurnAngle = minTurnAngle / 180 * Math.PI; // The line points can be
  33333. // /pt1----pt2 (label)
  33334. // /
  33335. // pt0/
  33336. pt0.fromArray(linePoints[0]);
  33337. pt1.fromArray(linePoints[1]);
  33338. pt2.fromArray(linePoints[2]);
  33339. Point.sub(dir, pt0, pt1);
  33340. Point.sub(dir2, pt2, pt1);
  33341. var len1 = dir.len();
  33342. var len2 = dir2.len();
  33343. if (len1 < 1e-3 || len2 < 1e-3) {
  33344. return;
  33345. }
  33346. dir.scale(1 / len1);
  33347. dir2.scale(1 / len2);
  33348. var angleCos = dir.dot(dir2);
  33349. var minTurnAngleCos = Math.cos(minTurnAngle);
  33350. if (minTurnAngleCos < angleCos) {
  33351. // Smaller than minTurnAngle
  33352. // Calculate project point of pt0 on pt1-pt2
  33353. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  33354. tmpProjPoint.fromArray(tmpArr); // Calculate new projected length with limited minTurnAngle and get the new connect point
  33355. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI - minTurnAngle)); // Limit the new calculated connect point between pt1 and pt2.
  33356. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  33357. if (isNaN(t)) {
  33358. return;
  33359. }
  33360. if (t < 0) {
  33361. Point.copy(tmpProjPoint, pt1);
  33362. } else if (t > 1) {
  33363. Point.copy(tmpProjPoint, pt2);
  33364. }
  33365. tmpProjPoint.toArray(linePoints[1]);
  33366. }
  33367. }
  33368. /**
  33369. * Limit the angle of line and the surface
  33370. * @param maxSurfaceAngle Radian of minimum turn angle. 0 - 180. 0 is same direction to normal. 180 is opposite
  33371. */
  33372. function limitSurfaceAngle(linePoints, surfaceNormal, maxSurfaceAngle) {
  33373. if (!(maxSurfaceAngle <= 180 && maxSurfaceAngle > 0)) {
  33374. return;
  33375. }
  33376. maxSurfaceAngle = maxSurfaceAngle / 180 * Math.PI;
  33377. pt0.fromArray(linePoints[0]);
  33378. pt1.fromArray(linePoints[1]);
  33379. pt2.fromArray(linePoints[2]);
  33380. Point.sub(dir, pt1, pt0);
  33381. Point.sub(dir2, pt2, pt1);
  33382. var len1 = dir.len();
  33383. var len2 = dir2.len();
  33384. if (len1 < 1e-3 || len2 < 1e-3) {
  33385. return;
  33386. }
  33387. dir.scale(1 / len1);
  33388. dir2.scale(1 / len2);
  33389. var angleCos = dir.dot(surfaceNormal);
  33390. var maxSurfaceAngleCos = Math.cos(maxSurfaceAngle);
  33391. if (angleCos < maxSurfaceAngleCos) {
  33392. // Calculate project point of pt0 on pt1-pt2
  33393. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  33394. tmpProjPoint.fromArray(tmpArr);
  33395. var HALF_PI = Math.PI / 2;
  33396. var angle2 = Math.acos(dir2.dot(surfaceNormal));
  33397. var newAngle = HALF_PI + angle2 - maxSurfaceAngle;
  33398. if (newAngle >= HALF_PI) {
  33399. // parallel
  33400. Point.copy(tmpProjPoint, pt2);
  33401. } else {
  33402. // Calculate new projected length with limited minTurnAngle and get the new connect point
  33403. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI / 2 - newAngle)); // Limit the new calculated connect point between pt1 and pt2.
  33404. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  33405. if (isNaN(t)) {
  33406. return;
  33407. }
  33408. if (t < 0) {
  33409. Point.copy(tmpProjPoint, pt1);
  33410. } else if (t > 1) {
  33411. Point.copy(tmpProjPoint, pt2);
  33412. }
  33413. }
  33414. tmpProjPoint.toArray(linePoints[1]);
  33415. }
  33416. }
  33417. function setLabelLineState(labelLine, ignore, stateName, stateModel) {
  33418. var isNormal = stateName === 'normal';
  33419. var stateObj = isNormal ? labelLine : labelLine.ensureState(stateName); // Make sure display.
  33420. stateObj.ignore = ignore; // Set smooth
  33421. var smooth = stateModel.get('smooth');
  33422. if (smooth && smooth === true) {
  33423. smooth = 0.3;
  33424. }
  33425. stateObj.shape = stateObj.shape || {};
  33426. if (smooth > 0) {
  33427. stateObj.shape.smooth = smooth;
  33428. }
  33429. var styleObj = stateModel.getModel('lineStyle').getLineStyle();
  33430. isNormal ? labelLine.useStyle(styleObj) : stateObj.style = styleObj;
  33431. }
  33432. function buildLabelLinePath(path, shape) {
  33433. var smooth = shape.smooth;
  33434. var points = shape.points;
  33435. if (!points) {
  33436. return;
  33437. }
  33438. path.moveTo(points[0][0], points[0][1]);
  33439. if (smooth > 0 && points.length >= 3) {
  33440. var len1 = dist(points[0], points[1]);
  33441. var len2 = dist(points[1], points[2]);
  33442. if (!len1 || !len2) {
  33443. path.lineTo(points[1][0], points[1][1]);
  33444. path.lineTo(points[2][0], points[2][1]);
  33445. return;
  33446. }
  33447. var moveLen = Math.min(len1, len2) * smooth;
  33448. var midPoint0 = lerp([], points[1], points[0], moveLen / len1);
  33449. var midPoint2 = lerp([], points[1], points[2], moveLen / len2);
  33450. var midPoint1 = lerp([], midPoint0, midPoint2, 0.5);
  33451. path.bezierCurveTo(midPoint0[0], midPoint0[1], midPoint0[0], midPoint0[1], midPoint1[0], midPoint1[1]);
  33452. path.bezierCurveTo(midPoint2[0], midPoint2[1], midPoint2[0], midPoint2[1], points[2][0], points[2][1]);
  33453. } else {
  33454. for (var i = 1; i < points.length; i++) {
  33455. path.lineTo(points[i][0], points[i][1]);
  33456. }
  33457. }
  33458. }
  33459. /**
  33460. * Create a label line if necessary and set it's style.
  33461. */
  33462. function setLabelLineStyle(targetEl, statesModels, defaultStyle) {
  33463. var labelLine = targetEl.getTextGuideLine();
  33464. var label = targetEl.getTextContent();
  33465. if (!label) {
  33466. // Not show label line if there is no label.
  33467. if (labelLine) {
  33468. targetEl.removeTextGuideLine();
  33469. }
  33470. return;
  33471. }
  33472. var normalModel = statesModels.normal;
  33473. var showNormal = normalModel.get('show');
  33474. var labelIgnoreNormal = label.ignore;
  33475. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  33476. var stateName = DISPLAY_STATES[i];
  33477. var stateModel = statesModels[stateName];
  33478. var isNormal = stateName === 'normal';
  33479. if (stateModel) {
  33480. var stateShow = stateModel.get('show');
  33481. var isLabelIgnored = isNormal ? labelIgnoreNormal : retrieve2(label.states[stateName] && label.states[stateName].ignore, labelIgnoreNormal);
  33482. if (isLabelIgnored // Not show when label is not shown in this state.
  33483. || !retrieve2(stateShow, showNormal) // Use normal state by default if not set.
  33484. ) {
  33485. var stateObj = isNormal ? labelLine : labelLine && labelLine.states.normal;
  33486. if (stateObj) {
  33487. stateObj.ignore = true;
  33488. }
  33489. continue;
  33490. } // Create labelLine if not exists
  33491. if (!labelLine) {
  33492. labelLine = new Polyline();
  33493. targetEl.setTextGuideLine(labelLine); // Reset state of normal because it's new created.
  33494. // NOTE: NORMAL should always been the first!
  33495. if (!isNormal && (labelIgnoreNormal || !showNormal)) {
  33496. setLabelLineState(labelLine, true, 'normal', statesModels.normal);
  33497. } // Use same state proxy.
  33498. if (targetEl.stateProxy) {
  33499. labelLine.stateProxy = targetEl.stateProxy;
  33500. }
  33501. }
  33502. setLabelLineState(labelLine, false, stateName, stateModel);
  33503. }
  33504. }
  33505. if (labelLine) {
  33506. defaults(labelLine.style, defaultStyle); // Not fill.
  33507. labelLine.style.fill = null;
  33508. var showAbove = normalModel.get('showAbove');
  33509. var labelLineConfig = targetEl.textGuideLineConfig = targetEl.textGuideLineConfig || {};
  33510. labelLineConfig.showAbove = showAbove || false; // Custom the buildPath.
  33511. labelLine.buildPath = buildLabelLinePath;
  33512. }
  33513. }
  33514. function getLabelLineStatesModels(itemModel, labelLineName) {
  33515. labelLineName = labelLineName || 'labelLine';
  33516. var statesModels = {
  33517. normal: itemModel.getModel(labelLineName)
  33518. };
  33519. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  33520. var stateName = SPECIAL_STATES[i];
  33521. statesModels[stateName] = itemModel.getModel([stateName, labelLineName]);
  33522. }
  33523. return statesModels;
  33524. }
  33525. function prepareLayoutList(input) {
  33526. var list = [];
  33527. for (var i = 0; i < input.length; i++) {
  33528. var rawItem = input[i];
  33529. if (rawItem.defaultAttr.ignore) {
  33530. continue;
  33531. }
  33532. var label = rawItem.label;
  33533. var transform = label.getComputedTransform(); // NOTE: Get bounding rect after getComputedTransform, or label may not been updated by the host el.
  33534. var localRect = label.getBoundingRect();
  33535. var isAxisAligned = !transform || transform[1] < 1e-5 && transform[2] < 1e-5;
  33536. var minMargin = label.style.margin || 0;
  33537. var globalRect = localRect.clone();
  33538. globalRect.applyTransform(transform);
  33539. globalRect.x -= minMargin / 2;
  33540. globalRect.y -= minMargin / 2;
  33541. globalRect.width += minMargin;
  33542. globalRect.height += minMargin;
  33543. var obb = isAxisAligned ? new OrientedBoundingRect(localRect, transform) : null;
  33544. list.push({
  33545. label: label,
  33546. labelLine: rawItem.labelLine,
  33547. rect: globalRect,
  33548. localRect: localRect,
  33549. obb: obb,
  33550. priority: rawItem.priority,
  33551. defaultAttr: rawItem.defaultAttr,
  33552. layoutOption: rawItem.computedLayoutOption,
  33553. axisAligned: isAxisAligned,
  33554. transform: transform
  33555. });
  33556. }
  33557. return list;
  33558. }
  33559. function shiftLayout(list, xyDim, sizeDim, minBound, maxBound, balanceShift) {
  33560. var len = list.length;
  33561. if (len < 2) {
  33562. return;
  33563. }
  33564. list.sort(function (a, b) {
  33565. return a.rect[xyDim] - b.rect[xyDim];
  33566. });
  33567. var lastPos = 0;
  33568. var delta;
  33569. var adjusted = false;
  33570. var totalShifts = 0;
  33571. for (var i = 0; i < len; i++) {
  33572. var item = list[i];
  33573. var rect = item.rect;
  33574. delta = rect[xyDim] - lastPos;
  33575. if (delta < 0) {
  33576. // shiftForward(i, len, -delta);
  33577. rect[xyDim] -= delta;
  33578. item.label[xyDim] -= delta;
  33579. adjusted = true;
  33580. }
  33581. var shift = Math.max(-delta, 0);
  33582. totalShifts += shift;
  33583. lastPos = rect[xyDim] + rect[sizeDim];
  33584. }
  33585. if (totalShifts > 0 && balanceShift) {
  33586. // Shift back to make the distribution more equally.
  33587. shiftList(-totalShifts / len, 0, len);
  33588. } // TODO bleedMargin?
  33589. var first = list[0];
  33590. var last = list[len - 1];
  33591. var minGap;
  33592. var maxGap;
  33593. updateMinMaxGap(); // If ends exceed two bounds, squeeze at most 80%, then take the gap of two bounds.
  33594. minGap < 0 && squeezeGaps(-minGap, 0.8);
  33595. maxGap < 0 && squeezeGaps(maxGap, 0.8);
  33596. updateMinMaxGap();
  33597. takeBoundsGap(minGap, maxGap, 1);
  33598. takeBoundsGap(maxGap, minGap, -1); // Handle bailout when there is not enough space.
  33599. updateMinMaxGap();
  33600. if (minGap < 0) {
  33601. squeezeWhenBailout(-minGap);
  33602. }
  33603. if (maxGap < 0) {
  33604. squeezeWhenBailout(maxGap);
  33605. }
  33606. function updateMinMaxGap() {
  33607. minGap = first.rect[xyDim] - minBound;
  33608. maxGap = maxBound - last.rect[xyDim] - last.rect[sizeDim];
  33609. }
  33610. function takeBoundsGap(gapThisBound, gapOtherBound, moveDir) {
  33611. if (gapThisBound < 0) {
  33612. // Move from other gap if can.
  33613. var moveFromMaxGap = Math.min(gapOtherBound, -gapThisBound);
  33614. if (moveFromMaxGap > 0) {
  33615. shiftList(moveFromMaxGap * moveDir, 0, len);
  33616. var remained = moveFromMaxGap + gapThisBound;
  33617. if (remained < 0) {
  33618. squeezeGaps(-remained * moveDir, 1);
  33619. }
  33620. } else {
  33621. squeezeGaps(-gapThisBound * moveDir, 1);
  33622. }
  33623. }
  33624. }
  33625. function shiftList(delta, start, end) {
  33626. if (delta !== 0) {
  33627. adjusted = true;
  33628. }
  33629. for (var i = start; i < end; i++) {
  33630. var item = list[i];
  33631. var rect = item.rect;
  33632. rect[xyDim] += delta;
  33633. item.label[xyDim] += delta;
  33634. }
  33635. } // Squeeze gaps if the labels exceed margin.
  33636. function squeezeGaps(delta, maxSqeezePercent) {
  33637. var gaps = [];
  33638. var totalGaps = 0;
  33639. for (var i = 1; i < len; i++) {
  33640. var prevItemRect = list[i - 1].rect;
  33641. var gap = Math.max(list[i].rect[xyDim] - prevItemRect[xyDim] - prevItemRect[sizeDim], 0);
  33642. gaps.push(gap);
  33643. totalGaps += gap;
  33644. }
  33645. if (!totalGaps) {
  33646. return;
  33647. }
  33648. var squeezePercent = Math.min(Math.abs(delta) / totalGaps, maxSqeezePercent);
  33649. if (delta > 0) {
  33650. for (var i = 0; i < len - 1; i++) {
  33651. // Distribute the shift delta to all gaps.
  33652. var movement = gaps[i] * squeezePercent; // Forward
  33653. shiftList(movement, 0, i + 1);
  33654. }
  33655. } else {
  33656. // Backward
  33657. for (var i = len - 1; i > 0; i--) {
  33658. // Distribute the shift delta to all gaps.
  33659. var movement = gaps[i - 1] * squeezePercent;
  33660. shiftList(-movement, i, len);
  33661. }
  33662. }
  33663. }
  33664. /**
  33665. * Squeeze to allow overlap if there is no more space available.
  33666. * Let other overlapping strategy like hideOverlap do the job instead of keep exceeding the bounds.
  33667. */
  33668. function squeezeWhenBailout(delta) {
  33669. var dir = delta < 0 ? -1 : 1;
  33670. delta = Math.abs(delta);
  33671. var moveForEachLabel = Math.ceil(delta / (len - 1));
  33672. for (var i = 0; i < len - 1; i++) {
  33673. if (dir > 0) {
  33674. // Forward
  33675. shiftList(moveForEachLabel, 0, i + 1);
  33676. } else {
  33677. // Backward
  33678. shiftList(-moveForEachLabel, len - i - 1, len);
  33679. }
  33680. delta -= moveForEachLabel;
  33681. if (delta <= 0) {
  33682. return;
  33683. }
  33684. }
  33685. }
  33686. return adjusted;
  33687. }
  33688. /**
  33689. * Adjust labels on y direction to avoid overlap.
  33690. */
  33691. function shiftLayoutOnY(list, topBound, bottomBound, // If average the shifts on all labels and add them to 0
  33692. balanceShift) {
  33693. return shiftLayout(list, 'y', 'height', topBound, bottomBound, balanceShift);
  33694. }
  33695. function hideOverlap(labelList) {
  33696. var displayedLabels = []; // TODO, render overflow visible first, put in the displayedLabels.
  33697. labelList.sort(function (a, b) {
  33698. return b.priority - a.priority;
  33699. });
  33700. var globalRect = new BoundingRect(0, 0, 0, 0);
  33701. function hideEl(el) {
  33702. if (!el.ignore) {
  33703. // Show on emphasis.
  33704. var emphasisState = el.ensureState('emphasis');
  33705. if (emphasisState.ignore == null) {
  33706. emphasisState.ignore = false;
  33707. }
  33708. }
  33709. el.ignore = true;
  33710. }
  33711. for (var i = 0; i < labelList.length; i++) {
  33712. var labelItem = labelList[i];
  33713. var isAxisAligned = labelItem.axisAligned;
  33714. var localRect = labelItem.localRect;
  33715. var transform = labelItem.transform;
  33716. var label = labelItem.label;
  33717. var labelLine = labelItem.labelLine;
  33718. globalRect.copy(labelItem.rect); // Add a threshold because layout may be aligned precisely.
  33719. globalRect.width -= 0.1;
  33720. globalRect.height -= 0.1;
  33721. globalRect.x += 0.05;
  33722. globalRect.y += 0.05;
  33723. var obb = labelItem.obb;
  33724. var overlapped = false;
  33725. for (var j = 0; j < displayedLabels.length; j++) {
  33726. var existsTextCfg = displayedLabels[j]; // Fast rejection.
  33727. if (!globalRect.intersect(existsTextCfg.rect)) {
  33728. continue;
  33729. }
  33730. if (isAxisAligned && existsTextCfg.axisAligned) {
  33731. // Is overlapped
  33732. overlapped = true;
  33733. break;
  33734. }
  33735. if (!existsTextCfg.obb) {
  33736. // If self is not axis aligned. But other is.
  33737. existsTextCfg.obb = new OrientedBoundingRect(existsTextCfg.localRect, existsTextCfg.transform);
  33738. }
  33739. if (!obb) {
  33740. // If self is axis aligned. But other is not.
  33741. obb = new OrientedBoundingRect(localRect, transform);
  33742. }
  33743. if (obb.intersect(existsTextCfg.obb)) {
  33744. overlapped = true;
  33745. break;
  33746. }
  33747. } // TODO Callback to determine if this overlap should be handled?
  33748. if (overlapped) {
  33749. hideEl(label);
  33750. labelLine && hideEl(labelLine);
  33751. } else {
  33752. label.attr('ignore', labelItem.defaultAttr.ignore);
  33753. labelLine && labelLine.attr('ignore', labelItem.defaultAttr.labelGuideIgnore);
  33754. displayedLabels.push(labelItem);
  33755. }
  33756. }
  33757. }
  33758. function createElement(name) {
  33759. return document.createElementNS('http://www.w3.org/2000/svg', name);
  33760. }
  33761. function normalizeColor(color) {
  33762. var opacity;
  33763. if (!color || color === 'transparent') {
  33764. color = 'none';
  33765. }
  33766. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  33767. var arr = parse(color);
  33768. if (arr) {
  33769. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  33770. opacity = arr[3];
  33771. }
  33772. }
  33773. return {
  33774. color: color,
  33775. opacity: opacity == null ? 1 : opacity
  33776. };
  33777. }
  33778. function diff(oldArr, newArr, equals) {
  33779. if (!equals) {
  33780. equals = function (a, b) {
  33781. return a === b;
  33782. };
  33783. }
  33784. oldArr = oldArr.slice();
  33785. newArr = newArr.slice();
  33786. var newLen = newArr.length;
  33787. var oldLen = oldArr.length;
  33788. var editLength = 1;
  33789. var maxEditLength = newLen + oldLen;
  33790. var bestPath = [{ newPos: -1, components: [] }];
  33791. var oldPos = extractCommon(bestPath[0], newArr, oldArr, 0, equals);
  33792. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  33793. var indices = [];
  33794. for (var i = 0; i < newArr.length; i++) {
  33795. indices.push(i);
  33796. }
  33797. return [{
  33798. indices: indices,
  33799. count: newArr.length,
  33800. added: false,
  33801. removed: false
  33802. }];
  33803. }
  33804. function execEditLength() {
  33805. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  33806. var basePath;
  33807. var addPath = bestPath[diagonalPath - 1];
  33808. var removePath = bestPath[diagonalPath + 1];
  33809. var oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  33810. if (addPath) {
  33811. bestPath[diagonalPath - 1] = undefined;
  33812. }
  33813. var canAdd = addPath && addPath.newPos + 1 < newLen;
  33814. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  33815. if (!canAdd && !canRemove) {
  33816. bestPath[diagonalPath] = undefined;
  33817. continue;
  33818. }
  33819. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  33820. basePath = clonePath(removePath);
  33821. pushComponent(basePath.components, false, true);
  33822. }
  33823. else {
  33824. basePath = addPath;
  33825. basePath.newPos++;
  33826. pushComponent(basePath.components, true, false);
  33827. }
  33828. oldPos = extractCommon(basePath, newArr, oldArr, diagonalPath, equals);
  33829. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  33830. return buildValues(basePath.components);
  33831. }
  33832. else {
  33833. bestPath[diagonalPath] = basePath;
  33834. }
  33835. }
  33836. editLength++;
  33837. }
  33838. while (editLength <= maxEditLength) {
  33839. var ret = execEditLength();
  33840. if (ret) {
  33841. return ret;
  33842. }
  33843. }
  33844. }
  33845. function extractCommon(basePath, newArr, oldArr, diagonalPath, equals) {
  33846. var newLen = newArr.length;
  33847. var oldLen = oldArr.length;
  33848. var newPos = basePath.newPos;
  33849. var oldPos = newPos - diagonalPath;
  33850. var commonCount = 0;
  33851. while (newPos + 1 < newLen && oldPos + 1 < oldLen && equals(newArr[newPos + 1], oldArr[oldPos + 1])) {
  33852. newPos++;
  33853. oldPos++;
  33854. commonCount++;
  33855. }
  33856. if (commonCount) {
  33857. basePath.components.push({
  33858. count: commonCount,
  33859. added: false,
  33860. removed: false,
  33861. indices: []
  33862. });
  33863. }
  33864. basePath.newPos = newPos;
  33865. return oldPos;
  33866. }
  33867. function pushComponent(components, added, removed) {
  33868. var last = components[components.length - 1];
  33869. if (last && last.added === added && last.removed === removed) {
  33870. components[components.length - 1] = {
  33871. count: last.count + 1,
  33872. added: added,
  33873. removed: removed,
  33874. indices: []
  33875. };
  33876. }
  33877. else {
  33878. components.push({
  33879. count: 1,
  33880. added: added,
  33881. removed: removed,
  33882. indices: []
  33883. });
  33884. }
  33885. }
  33886. function buildValues(components) {
  33887. var componentPos = 0;
  33888. var componentLen = components.length;
  33889. var newPos = 0;
  33890. var oldPos = 0;
  33891. for (; componentPos < componentLen; componentPos++) {
  33892. var component = components[componentPos];
  33893. if (!component.removed) {
  33894. var indices = [];
  33895. for (var i = newPos; i < newPos + component.count; i++) {
  33896. indices.push(i);
  33897. }
  33898. component.indices = indices;
  33899. newPos += component.count;
  33900. if (!component.added) {
  33901. oldPos += component.count;
  33902. }
  33903. }
  33904. else {
  33905. for (var i = oldPos; i < oldPos + component.count; i++) {
  33906. component.indices.push(i);
  33907. }
  33908. oldPos += component.count;
  33909. }
  33910. }
  33911. return components;
  33912. }
  33913. function clonePath(path) {
  33914. return { newPos: path.newPos, components: path.components.slice(0) };
  33915. }
  33916. function arrayDiff(oldArr, newArr, equal) {
  33917. return diff(oldArr, newArr, equal);
  33918. }
  33919. var NONE = 'none';
  33920. var mathRound = Math.round;
  33921. var mathSin$4 = Math.sin;
  33922. var mathCos$4 = Math.cos;
  33923. var PI$4 = Math.PI;
  33924. var PI2$6 = Math.PI * 2;
  33925. var degree = 180 / PI$4;
  33926. var EPSILON$4 = 1e-4;
  33927. function round3(val) {
  33928. return mathRound(val * 1e3) / 1e3;
  33929. }
  33930. function round4(val) {
  33931. return mathRound(val * 1e4) / 1e4;
  33932. }
  33933. function isAroundZero$1(val) {
  33934. return val < EPSILON$4 && val > -EPSILON$4;
  33935. }
  33936. function pathHasFill(style) {
  33937. var fill = style.fill;
  33938. return fill != null && fill !== NONE;
  33939. }
  33940. function pathHasStroke(style) {
  33941. var stroke = style.stroke;
  33942. return stroke != null && stroke !== NONE;
  33943. }
  33944. function setTransform(svgEl, m) {
  33945. if (m) {
  33946. attr(svgEl, 'transform', 'matrix('
  33947. + round3(m[0]) + ','
  33948. + round3(m[1]) + ','
  33949. + round3(m[2]) + ','
  33950. + round3(m[3]) + ','
  33951. + round4(m[4]) + ','
  33952. + round4(m[5])
  33953. + ')');
  33954. }
  33955. }
  33956. function attr(el, key, val) {
  33957. if (!val || val.type !== 'linear' && val.type !== 'radial') {
  33958. el.setAttribute(key, val);
  33959. }
  33960. }
  33961. function attrXLink(el, key, val) {
  33962. el.setAttributeNS('http://www.w3.org/1999/xlink', key, val);
  33963. }
  33964. function attrXML(el, key, val) {
  33965. el.setAttributeNS('http://www.w3.org/XML/1998/namespace', key, val);
  33966. }
  33967. function bindStyle(svgEl, style, el) {
  33968. var opacity = style.opacity == null ? 1 : style.opacity;
  33969. if (el instanceof ZRImage) {
  33970. attr(svgEl, 'opacity', opacity + '');
  33971. return;
  33972. }
  33973. if (pathHasFill(style)) {
  33974. var fill = normalizeColor(style.fill);
  33975. attr(svgEl, 'fill', fill.color);
  33976. attr(svgEl, 'fill-opacity', (style.fillOpacity != null
  33977. ? style.fillOpacity * fill.opacity * opacity
  33978. : fill.opacity * opacity) + '');
  33979. }
  33980. else {
  33981. attr(svgEl, 'fill', NONE);
  33982. }
  33983. if (pathHasStroke(style)) {
  33984. var stroke = normalizeColor(style.stroke);
  33985. attr(svgEl, 'stroke', stroke.color);
  33986. var strokeWidth = style.lineWidth;
  33987. var strokeScale_1 = style.strokeNoScale
  33988. ? el.getLineScale()
  33989. : 1;
  33990. attr(svgEl, 'stroke-width', (strokeScale_1 ? strokeWidth / strokeScale_1 : 0) + '');
  33991. attr(svgEl, 'paint-order', style.strokeFirst ? 'stroke' : 'fill');
  33992. attr(svgEl, 'stroke-opacity', (style.strokeOpacity != null
  33993. ? style.strokeOpacity * stroke.opacity * opacity
  33994. : stroke.opacity * opacity) + '');
  33995. var lineDash = style.lineDash && strokeWidth > 0 && normalizeLineDash(style.lineDash, strokeWidth);
  33996. if (lineDash) {
  33997. var lineDashOffset = style.lineDashOffset;
  33998. if (strokeScale_1 && strokeScale_1 !== 1) {
  33999. lineDash = map(lineDash, function (rawVal) {
  34000. return rawVal / strokeScale_1;
  34001. });
  34002. if (lineDashOffset) {
  34003. lineDashOffset /= strokeScale_1;
  34004. lineDashOffset = mathRound(lineDashOffset);
  34005. }
  34006. }
  34007. attr(svgEl, 'stroke-dasharray', lineDash.join(','));
  34008. attr(svgEl, 'stroke-dashoffset', (lineDashOffset || 0) + '');
  34009. }
  34010. else {
  34011. attr(svgEl, 'stroke-dasharray', NONE);
  34012. }
  34013. style.lineCap && attr(svgEl, 'stroke-linecap', style.lineCap);
  34014. style.lineJoin && attr(svgEl, 'stroke-linejoin', style.lineJoin);
  34015. style.miterLimit && attr(svgEl, 'stroke-miterlimit', style.miterLimit + '');
  34016. }
  34017. else {
  34018. attr(svgEl, 'stroke', NONE);
  34019. }
  34020. }
  34021. var SVGPathRebuilder = (function () {
  34022. function SVGPathRebuilder() {
  34023. }
  34024. SVGPathRebuilder.prototype.reset = function () {
  34025. this._d = [];
  34026. this._str = '';
  34027. };
  34028. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  34029. this._add('M', x, y);
  34030. };
  34031. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  34032. this._add('L', x, y);
  34033. };
  34034. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  34035. this._add('C', x, y, x2, y2, x3, y3);
  34036. };
  34037. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  34038. this._add('Q', x, y, x2, y2);
  34039. };
  34040. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  34041. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  34042. };
  34043. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  34044. var firstCmd = this._d.length === 0;
  34045. var dTheta = endAngle - startAngle;
  34046. var clockwise = !anticlockwise;
  34047. var dThetaPositive = Math.abs(dTheta);
  34048. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  34049. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  34050. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  34051. var large = false;
  34052. if (isCircle) {
  34053. large = true;
  34054. }
  34055. else if (isAroundZero$1(dThetaPositive)) {
  34056. large = false;
  34057. }
  34058. else {
  34059. large = (unifiedTheta >= PI$4) === !!clockwise;
  34060. }
  34061. var x0 = round4(cx + rx * mathCos$4(startAngle));
  34062. var y0 = round4(cy + ry * mathSin$4(startAngle));
  34063. if (isCircle) {
  34064. if (clockwise) {
  34065. dTheta = PI2$6 - 1e-4;
  34066. }
  34067. else {
  34068. dTheta = -PI2$6 + 1e-4;
  34069. }
  34070. large = true;
  34071. if (firstCmd) {
  34072. this._d.push('M', x0, y0);
  34073. }
  34074. }
  34075. var x = round4(cx + rx * mathCos$4(startAngle + dTheta));
  34076. var y = round4(cy + ry * mathSin$4(startAngle + dTheta));
  34077. if (isNaN(x0) || isNaN(y0) || isNaN(rx) || isNaN(ry) || isNaN(psi) || isNaN(degree) || isNaN(x) || isNaN(y)) {
  34078. return '';
  34079. }
  34080. this._d.push('A', round4(rx), round4(ry), mathRound(psi * degree), +large, +clockwise, x, y);
  34081. };
  34082. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  34083. this._add('M', x, y);
  34084. this._add('L', x + w, y);
  34085. this._add('L', x + w, y + h);
  34086. this._add('L', x, y + h);
  34087. this._add('L', x, y);
  34088. this._add('Z');
  34089. };
  34090. SVGPathRebuilder.prototype.closePath = function () {
  34091. if (this._d.length > 0) {
  34092. this._add('Z');
  34093. }
  34094. };
  34095. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  34096. this._d.push(cmd);
  34097. for (var i = 1; i < arguments.length; i++) {
  34098. var val = arguments[i];
  34099. if (isNaN(val)) {
  34100. this._invalid = true;
  34101. return;
  34102. }
  34103. this._d.push(round4(val));
  34104. }
  34105. };
  34106. SVGPathRebuilder.prototype.generateStr = function () {
  34107. this._str = this._invalid ? '' : this._d.join(' ');
  34108. this._d = [];
  34109. };
  34110. SVGPathRebuilder.prototype.getStr = function () {
  34111. return this._str;
  34112. };
  34113. return SVGPathRebuilder;
  34114. }());
  34115. var svgPath = {
  34116. brush: function (el) {
  34117. var style = el.style;
  34118. var svgEl = el.__svgEl;
  34119. if (!svgEl) {
  34120. svgEl = createElement('path');
  34121. el.__svgEl = svgEl;
  34122. }
  34123. if (!el.path) {
  34124. el.createPathProxy();
  34125. }
  34126. var path = el.path;
  34127. if (el.shapeChanged()) {
  34128. path.beginPath();
  34129. el.buildPath(path, el.shape);
  34130. el.pathUpdated();
  34131. }
  34132. var pathVersion = path.getVersion();
  34133. var elExt = el;
  34134. var svgPathBuilder = elExt.__svgPathBuilder;
  34135. if (elExt.__svgPathVersion !== pathVersion || !svgPathBuilder || el.style.strokePercent < 1) {
  34136. if (!svgPathBuilder) {
  34137. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  34138. }
  34139. svgPathBuilder.reset();
  34140. path.rebuildPath(svgPathBuilder, el.style.strokePercent);
  34141. svgPathBuilder.generateStr();
  34142. elExt.__svgPathVersion = pathVersion;
  34143. }
  34144. attr(svgEl, 'd', svgPathBuilder.getStr());
  34145. bindStyle(svgEl, style, el);
  34146. setTransform(svgEl, el.transform);
  34147. }
  34148. };
  34149. var svgImage = {
  34150. brush: function (el) {
  34151. var style = el.style;
  34152. var image = style.image;
  34153. if (image instanceof HTMLImageElement) {
  34154. image = image.src;
  34155. }
  34156. else if (image instanceof HTMLCanvasElement) {
  34157. image = image.toDataURL();
  34158. }
  34159. if (!image) {
  34160. return;
  34161. }
  34162. var x = style.x || 0;
  34163. var y = style.y || 0;
  34164. var dw = style.width;
  34165. var dh = style.height;
  34166. var svgEl = el.__svgEl;
  34167. if (!svgEl) {
  34168. svgEl = createElement('image');
  34169. el.__svgEl = svgEl;
  34170. }
  34171. if (image !== el.__imageSrc) {
  34172. attrXLink(svgEl, 'href', image);
  34173. el.__imageSrc = image;
  34174. }
  34175. attr(svgEl, 'width', dw + '');
  34176. attr(svgEl, 'height', dh + '');
  34177. attr(svgEl, 'x', x + '');
  34178. attr(svgEl, 'y', y + '');
  34179. bindStyle(svgEl, style, el);
  34180. setTransform(svgEl, el.transform);
  34181. }
  34182. };
  34183. var TEXT_ALIGN_TO_ANCHOR = {
  34184. left: 'start',
  34185. right: 'end',
  34186. center: 'middle',
  34187. middle: 'middle'
  34188. };
  34189. function adjustTextY$1(y, lineHeight, textBaseline) {
  34190. if (textBaseline === 'top') {
  34191. y += lineHeight / 2;
  34192. }
  34193. else if (textBaseline === 'bottom') {
  34194. y -= lineHeight / 2;
  34195. }
  34196. return y;
  34197. }
  34198. var svgText = {
  34199. brush: function (el) {
  34200. var style = el.style;
  34201. var text = style.text;
  34202. text != null && (text += '');
  34203. if (!text || isNaN(style.x) || isNaN(style.y)) {
  34204. return;
  34205. }
  34206. var textSvgEl = el.__svgEl;
  34207. if (!textSvgEl) {
  34208. textSvgEl = createElement('text');
  34209. attrXML(textSvgEl, 'xml:space', 'preserve');
  34210. el.__svgEl = textSvgEl;
  34211. }
  34212. var font = style.font || DEFAULT_FONT;
  34213. var textSvgElStyle = textSvgEl.style;
  34214. textSvgElStyle.font = font;
  34215. textSvgEl.textContent = text;
  34216. bindStyle(textSvgEl, style, el);
  34217. setTransform(textSvgEl, el.transform);
  34218. var x = style.x || 0;
  34219. var y = adjustTextY$1(style.y || 0, getLineHeight(font), style.textBaseline);
  34220. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  34221. || style.textAlign;
  34222. attr(textSvgEl, 'dominant-baseline', 'central');
  34223. attr(textSvgEl, 'text-anchor', textAlign);
  34224. attr(textSvgEl, 'x', x + '');
  34225. attr(textSvgEl, 'y', y + '');
  34226. }
  34227. };
  34228. var MARK_UNUSED = '0';
  34229. var MARK_USED = '1';
  34230. var Definable = (function () {
  34231. function Definable(zrId, svgRoot, tagNames, markLabel, domName) {
  34232. this.nextId = 0;
  34233. this._domName = '_dom';
  34234. this.createElement = createElement;
  34235. this._zrId = zrId;
  34236. this._svgRoot = svgRoot;
  34237. this._tagNames = typeof tagNames === 'string' ? [tagNames] : tagNames;
  34238. this._markLabel = markLabel;
  34239. if (domName) {
  34240. this._domName = domName;
  34241. }
  34242. }
  34243. Definable.prototype.getDefs = function (isForceCreating) {
  34244. var svgRoot = this._svgRoot;
  34245. var defs = this._svgRoot.getElementsByTagName('defs');
  34246. if (defs.length === 0) {
  34247. if (isForceCreating) {
  34248. var defs_1 = svgRoot.insertBefore(this.createElement('defs'), svgRoot.firstChild);
  34249. if (!defs_1.contains) {
  34250. defs_1.contains = function (el) {
  34251. var children = defs_1.children;
  34252. if (!children) {
  34253. return false;
  34254. }
  34255. for (var i = children.length - 1; i >= 0; --i) {
  34256. if (children[i] === el) {
  34257. return true;
  34258. }
  34259. }
  34260. return false;
  34261. };
  34262. }
  34263. return defs_1;
  34264. }
  34265. else {
  34266. return null;
  34267. }
  34268. }
  34269. else {
  34270. return defs[0];
  34271. }
  34272. };
  34273. Definable.prototype.doUpdate = function (target, onUpdate) {
  34274. if (!target) {
  34275. return;
  34276. }
  34277. var defs = this.getDefs(false);
  34278. if (target[this._domName] && defs.contains(target[this._domName])) {
  34279. if (typeof onUpdate === 'function') {
  34280. onUpdate(target);
  34281. }
  34282. }
  34283. else {
  34284. var dom = this.add(target);
  34285. if (dom) {
  34286. target[this._domName] = dom;
  34287. }
  34288. }
  34289. };
  34290. Definable.prototype.add = function (target) {
  34291. return null;
  34292. };
  34293. Definable.prototype.addDom = function (dom) {
  34294. var defs = this.getDefs(true);
  34295. if (dom.parentNode !== defs) {
  34296. defs.appendChild(dom);
  34297. }
  34298. };
  34299. Definable.prototype.removeDom = function (target) {
  34300. var defs = this.getDefs(false);
  34301. if (defs && target[this._domName]) {
  34302. defs.removeChild(target[this._domName]);
  34303. target[this._domName] = null;
  34304. }
  34305. };
  34306. Definable.prototype.getDoms = function () {
  34307. var defs = this.getDefs(false);
  34308. if (!defs) {
  34309. return [];
  34310. }
  34311. var doms = [];
  34312. each(this._tagNames, function (tagName) {
  34313. var tags = defs.getElementsByTagName(tagName);
  34314. for (var i = 0; i < tags.length; i++) {
  34315. doms.push(tags[i]);
  34316. }
  34317. });
  34318. return doms;
  34319. };
  34320. Definable.prototype.markAllUnused = function () {
  34321. var doms = this.getDoms();
  34322. var that = this;
  34323. each(doms, function (dom) {
  34324. dom[that._markLabel] = MARK_UNUSED;
  34325. });
  34326. };
  34327. Definable.prototype.markDomUsed = function (dom) {
  34328. dom && (dom[this._markLabel] = MARK_USED);
  34329. };
  34330. Definable.prototype.markDomUnused = function (dom) {
  34331. dom && (dom[this._markLabel] = MARK_UNUSED);
  34332. };
  34333. Definable.prototype.isDomUnused = function (dom) {
  34334. return dom && dom[this._markLabel] !== MARK_USED;
  34335. };
  34336. Definable.prototype.removeUnused = function () {
  34337. var _this = this;
  34338. var defs = this.getDefs(false);
  34339. if (!defs) {
  34340. return;
  34341. }
  34342. var doms = this.getDoms();
  34343. each(doms, function (dom) {
  34344. if (_this.isDomUnused(dom)) {
  34345. defs.removeChild(dom);
  34346. }
  34347. });
  34348. };
  34349. Definable.prototype.getSvgProxy = function (displayable) {
  34350. if (displayable instanceof Path) {
  34351. return svgPath;
  34352. }
  34353. else if (displayable instanceof ZRImage) {
  34354. return svgImage;
  34355. }
  34356. else if (displayable instanceof TSpan) {
  34357. return svgText;
  34358. }
  34359. else {
  34360. return svgPath;
  34361. }
  34362. };
  34363. Definable.prototype.getSvgElement = function (displayable) {
  34364. return displayable.__svgEl;
  34365. };
  34366. return Definable;
  34367. }());
  34368. function isLinearGradient(value) {
  34369. return value.type === 'linear';
  34370. }
  34371. function isRadialGradient(value) {
  34372. return value.type === 'radial';
  34373. }
  34374. function isGradient(value) {
  34375. return value && (value.type === 'linear'
  34376. || value.type === 'radial');
  34377. }
  34378. var GradientManager = (function (_super) {
  34379. __extends(GradientManager, _super);
  34380. function GradientManager(zrId, svgRoot) {
  34381. return _super.call(this, zrId, svgRoot, ['linearGradient', 'radialGradient'], '__gradient_in_use__') || this;
  34382. }
  34383. GradientManager.prototype.addWithoutUpdate = function (svgElement, displayable) {
  34384. if (displayable && displayable.style) {
  34385. var that_1 = this;
  34386. each(['fill', 'stroke'], function (fillOrStroke) {
  34387. var value = displayable.style[fillOrStroke];
  34388. if (isGradient(value)) {
  34389. var gradient = value;
  34390. var defs = that_1.getDefs(true);
  34391. var dom = void 0;
  34392. if (gradient.__dom) {
  34393. dom = gradient.__dom;
  34394. if (!defs.contains(gradient.__dom)) {
  34395. that_1.addDom(dom);
  34396. }
  34397. }
  34398. else {
  34399. dom = that_1.add(gradient);
  34400. }
  34401. that_1.markUsed(displayable);
  34402. var id = dom.getAttribute('id');
  34403. svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
  34404. }
  34405. });
  34406. }
  34407. };
  34408. GradientManager.prototype.add = function (gradient) {
  34409. var dom;
  34410. if (isLinearGradient(gradient)) {
  34411. dom = this.createElement('linearGradient');
  34412. }
  34413. else if (isRadialGradient(gradient)) {
  34414. dom = this.createElement('radialGradient');
  34415. }
  34416. else {
  34417. logError('Illegal gradient type.');
  34418. return null;
  34419. }
  34420. gradient.id = gradient.id || this.nextId++;
  34421. dom.setAttribute('id', 'zr' + this._zrId
  34422. + '-gradient-' + gradient.id);
  34423. this.updateDom(gradient, dom);
  34424. this.addDom(dom);
  34425. return dom;
  34426. };
  34427. GradientManager.prototype.update = function (gradient) {
  34428. if (!isGradient(gradient)) {
  34429. return;
  34430. }
  34431. var that = this;
  34432. this.doUpdate(gradient, function () {
  34433. var dom = gradient.__dom;
  34434. if (!dom) {
  34435. return;
  34436. }
  34437. var tagName = dom.tagName;
  34438. var type = gradient.type;
  34439. if (type === 'linear' && tagName === 'linearGradient'
  34440. || type === 'radial' && tagName === 'radialGradient') {
  34441. that.updateDom(gradient, gradient.__dom);
  34442. }
  34443. else {
  34444. that.removeDom(gradient);
  34445. that.add(gradient);
  34446. }
  34447. });
  34448. };
  34449. GradientManager.prototype.updateDom = function (gradient, dom) {
  34450. if (isLinearGradient(gradient)) {
  34451. dom.setAttribute('x1', gradient.x + '');
  34452. dom.setAttribute('y1', gradient.y + '');
  34453. dom.setAttribute('x2', gradient.x2 + '');
  34454. dom.setAttribute('y2', gradient.y2 + '');
  34455. }
  34456. else if (isRadialGradient(gradient)) {
  34457. dom.setAttribute('cx', gradient.x + '');
  34458. dom.setAttribute('cy', gradient.y + '');
  34459. dom.setAttribute('r', gradient.r + '');
  34460. }
  34461. else {
  34462. logError('Illegal gradient type.');
  34463. return;
  34464. }
  34465. if (gradient.global) {
  34466. dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  34467. }
  34468. else {
  34469. dom.setAttribute('gradientUnits', 'objectBoundingBox');
  34470. }
  34471. dom.innerHTML = '';
  34472. var colors = gradient.colorStops;
  34473. for (var i = 0, len = colors.length; i < len; ++i) {
  34474. var stop_1 = this.createElement('stop');
  34475. stop_1.setAttribute('offset', colors[i].offset * 100 + '%');
  34476. var color$1 = colors[i].color;
  34477. if (color$1.indexOf('rgba') > -1) {
  34478. var opacity = parse(color$1)[3];
  34479. var hex = toHex(color$1);
  34480. stop_1.setAttribute('stop-color', '#' + hex);
  34481. stop_1.setAttribute('stop-opacity', opacity + '');
  34482. }
  34483. else {
  34484. stop_1.setAttribute('stop-color', colors[i].color);
  34485. }
  34486. dom.appendChild(stop_1);
  34487. }
  34488. gradient.__dom = dom;
  34489. };
  34490. GradientManager.prototype.markUsed = function (displayable) {
  34491. if (displayable.style) {
  34492. var gradient = displayable.style.fill;
  34493. if (gradient && gradient.__dom) {
  34494. _super.prototype.markDomUsed.call(this, gradient.__dom);
  34495. }
  34496. gradient = displayable.style.stroke;
  34497. if (gradient && gradient.__dom) {
  34498. _super.prototype.markDomUsed.call(this, gradient.__dom);
  34499. }
  34500. }
  34501. };
  34502. return GradientManager;
  34503. }(Definable));
  34504. function isPattern(value) {
  34505. return value && (!!value.image || !!value.svgElement);
  34506. }
  34507. var patternDomMap = new WeakMap();
  34508. var PatternManager = (function (_super) {
  34509. __extends(PatternManager, _super);
  34510. function PatternManager(zrId, svgRoot) {
  34511. return _super.call(this, zrId, svgRoot, ['pattern'], '__pattern_in_use__') || this;
  34512. }
  34513. PatternManager.prototype.addWithoutUpdate = function (svgElement, displayable) {
  34514. if (displayable && displayable.style) {
  34515. var that_1 = this;
  34516. each(['fill', 'stroke'], function (fillOrStroke) {
  34517. var pattern = displayable.style[fillOrStroke];
  34518. if (isPattern(pattern)) {
  34519. var defs = that_1.getDefs(true);
  34520. var dom = patternDomMap.get(pattern);
  34521. if (dom) {
  34522. if (!defs.contains(dom)) {
  34523. that_1.addDom(dom);
  34524. }
  34525. }
  34526. else {
  34527. dom = that_1.add(pattern);
  34528. }
  34529. that_1.markUsed(displayable);
  34530. var id = dom.getAttribute('id');
  34531. svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
  34532. }
  34533. });
  34534. }
  34535. };
  34536. PatternManager.prototype.add = function (pattern) {
  34537. if (!isPattern(pattern)) {
  34538. return;
  34539. }
  34540. var dom = this.createElement('pattern');
  34541. pattern.id = pattern.id == null ? this.nextId++ : pattern.id;
  34542. dom.setAttribute('id', 'zr' + this._zrId
  34543. + '-pattern-' + pattern.id);
  34544. dom.setAttribute('x', '0');
  34545. dom.setAttribute('y', '0');
  34546. dom.setAttribute('patternUnits', 'userSpaceOnUse');
  34547. this.updateDom(pattern, dom);
  34548. this.addDom(dom);
  34549. return dom;
  34550. };
  34551. PatternManager.prototype.update = function (pattern) {
  34552. if (!isPattern(pattern)) {
  34553. return;
  34554. }
  34555. var that = this;
  34556. this.doUpdate(pattern, function () {
  34557. var dom = patternDomMap.get(pattern);
  34558. that.updateDom(pattern, dom);
  34559. });
  34560. };
  34561. PatternManager.prototype.updateDom = function (pattern, patternDom) {
  34562. var svgElement = pattern.svgElement;
  34563. if (svgElement instanceof SVGElement) {
  34564. if (svgElement.parentNode !== patternDom) {
  34565. patternDom.innerHTML = '';
  34566. patternDom.appendChild(svgElement);
  34567. patternDom.setAttribute('width', pattern.svgWidth + '');
  34568. patternDom.setAttribute('height', pattern.svgHeight + '');
  34569. }
  34570. }
  34571. else {
  34572. var img = void 0;
  34573. var prevImage = patternDom.getElementsByTagName('image');
  34574. if (prevImage.length) {
  34575. if (pattern.image) {
  34576. img = prevImage[0];
  34577. }
  34578. else {
  34579. patternDom.removeChild(prevImage[0]);
  34580. return;
  34581. }
  34582. }
  34583. else if (pattern.image) {
  34584. img = this.createElement('image');
  34585. }
  34586. if (img) {
  34587. var imageSrc = void 0;
  34588. var patternImage = pattern.image;
  34589. if (typeof patternImage === 'string') {
  34590. imageSrc = patternImage;
  34591. }
  34592. else if (patternImage instanceof HTMLImageElement) {
  34593. imageSrc = patternImage.src;
  34594. }
  34595. else if (patternImage instanceof HTMLCanvasElement) {
  34596. imageSrc = patternImage.toDataURL();
  34597. }
  34598. if (imageSrc) {
  34599. img.setAttribute('href', imageSrc);
  34600. img.setAttribute('x', '0');
  34601. img.setAttribute('y', '0');
  34602. var hostEl = {
  34603. dirty: function () { }
  34604. };
  34605. var createdImage = createOrUpdateImage(imageSrc, img, hostEl, function (img) {
  34606. patternDom.setAttribute('width', img.width + '');
  34607. patternDom.setAttribute('height', img.height + '');
  34608. });
  34609. if (createdImage && createdImage.width && createdImage.height) {
  34610. patternDom.setAttribute('width', createdImage.width + '');
  34611. patternDom.setAttribute('height', createdImage.height + '');
  34612. }
  34613. patternDom.appendChild(img);
  34614. }
  34615. }
  34616. }
  34617. var x = pattern.x || 0;
  34618. var y = pattern.y || 0;
  34619. var rotation = (pattern.rotation || 0) / Math.PI * 180;
  34620. var scaleX = pattern.scaleX || 1;
  34621. var scaleY = pattern.scaleY || 1;
  34622. var transform = "translate(" + x + ", " + y + ") rotate(" + rotation + ") scale(" + scaleX + ", " + scaleY + ")";
  34623. patternDom.setAttribute('patternTransform', transform);
  34624. patternDomMap.set(pattern, patternDom);
  34625. };
  34626. PatternManager.prototype.markUsed = function (displayable) {
  34627. if (displayable.style) {
  34628. if (isPattern(displayable.style.fill)) {
  34629. _super.prototype.markDomUsed.call(this, patternDomMap.get(displayable.style.fill));
  34630. }
  34631. if (isPattern(displayable.style.stroke)) {
  34632. _super.prototype.markDomUsed.call(this, patternDomMap.get(displayable.style.stroke));
  34633. }
  34634. }
  34635. };
  34636. return PatternManager;
  34637. }(Definable));
  34638. function generateClipPathsKey(clipPaths) {
  34639. var key = [];
  34640. if (clipPaths) {
  34641. for (var i = 0; i < clipPaths.length; i++) {
  34642. var clipPath = clipPaths[i];
  34643. key.push(clipPath.id);
  34644. }
  34645. }
  34646. return key.join(',');
  34647. }
  34648. function hasClipPath(displayable) {
  34649. var clipPaths = displayable.__clipPaths;
  34650. return clipPaths && clipPaths.length > 0;
  34651. }
  34652. var ClippathManager = (function (_super) {
  34653. __extends(ClippathManager, _super);
  34654. function ClippathManager(zrId, svgRoot) {
  34655. var _this = _super.call(this, zrId, svgRoot, 'clipPath', '__clippath_in_use__') || this;
  34656. _this._refGroups = {};
  34657. _this._keyDuplicateCount = {};
  34658. return _this;
  34659. }
  34660. ClippathManager.prototype.markAllUnused = function () {
  34661. _super.prototype.markAllUnused.call(this);
  34662. var refGroups = this._refGroups;
  34663. for (var key in refGroups) {
  34664. if (refGroups.hasOwnProperty(key)) {
  34665. this.markDomUnused(refGroups[key]);
  34666. }
  34667. }
  34668. this._keyDuplicateCount = {};
  34669. };
  34670. ClippathManager.prototype._getClipPathGroup = function (displayable, prevDisplayable) {
  34671. if (!hasClipPath(displayable)) {
  34672. return;
  34673. }
  34674. var clipPaths = displayable.__clipPaths;
  34675. var keyDuplicateCount = this._keyDuplicateCount;
  34676. var clipPathKey = generateClipPathsKey(clipPaths);
  34677. if (isClipPathChanged(clipPaths, prevDisplayable && prevDisplayable.__clipPaths)) {
  34678. keyDuplicateCount[clipPathKey] = keyDuplicateCount[clipPathKey] || 0;
  34679. keyDuplicateCount[clipPathKey] && (clipPathKey += '-' + keyDuplicateCount[clipPathKey]);
  34680. keyDuplicateCount[clipPathKey]++;
  34681. }
  34682. return this._refGroups[clipPathKey]
  34683. || (this._refGroups[clipPathKey] = this.createElement('g'));
  34684. };
  34685. ClippathManager.prototype.update = function (displayable, prevDisplayable) {
  34686. var clipGroup = this._getClipPathGroup(displayable, prevDisplayable);
  34687. if (clipGroup) {
  34688. this.markDomUsed(clipGroup);
  34689. this.updateDom(clipGroup, displayable.__clipPaths);
  34690. }
  34691. return clipGroup;
  34692. };
  34693. ClippathManager.prototype.updateDom = function (parentEl, clipPaths) {
  34694. if (clipPaths && clipPaths.length > 0) {
  34695. var defs = this.getDefs(true);
  34696. var clipPath = clipPaths[0];
  34697. var clipPathEl = void 0;
  34698. var id = void 0;
  34699. if (clipPath._dom) {
  34700. id = clipPath._dom.getAttribute('id');
  34701. clipPathEl = clipPath._dom;
  34702. if (!defs.contains(clipPathEl)) {
  34703. defs.appendChild(clipPathEl);
  34704. }
  34705. }
  34706. else {
  34707. id = 'zr' + this._zrId + '-clip-' + this.nextId;
  34708. ++this.nextId;
  34709. clipPathEl = this.createElement('clipPath');
  34710. clipPathEl.setAttribute('id', id);
  34711. defs.appendChild(clipPathEl);
  34712. clipPath._dom = clipPathEl;
  34713. }
  34714. var svgProxy = this.getSvgProxy(clipPath);
  34715. svgProxy.brush(clipPath);
  34716. var pathEl = this.getSvgElement(clipPath);
  34717. clipPathEl.innerHTML = '';
  34718. clipPathEl.appendChild(pathEl);
  34719. parentEl.setAttribute('clip-path', 'url(#' + id + ')');
  34720. if (clipPaths.length > 1) {
  34721. this.updateDom(clipPathEl, clipPaths.slice(1));
  34722. }
  34723. }
  34724. else {
  34725. if (parentEl) {
  34726. parentEl.setAttribute('clip-path', 'none');
  34727. }
  34728. }
  34729. };
  34730. ClippathManager.prototype.markUsed = function (displayable) {
  34731. var _this = this;
  34732. if (displayable.__clipPaths) {
  34733. each(displayable.__clipPaths, function (clipPath) {
  34734. if (clipPath._dom) {
  34735. _super.prototype.markDomUsed.call(_this, clipPath._dom);
  34736. }
  34737. });
  34738. }
  34739. };
  34740. ClippathManager.prototype.removeUnused = function () {
  34741. _super.prototype.removeUnused.call(this);
  34742. var newRefGroupsMap = {};
  34743. var refGroups = this._refGroups;
  34744. for (var key in refGroups) {
  34745. if (refGroups.hasOwnProperty(key)) {
  34746. var group = refGroups[key];
  34747. if (!this.isDomUnused(group)) {
  34748. newRefGroupsMap[key] = group;
  34749. }
  34750. else if (group.parentNode) {
  34751. group.parentNode.removeChild(group);
  34752. }
  34753. }
  34754. }
  34755. this._refGroups = newRefGroupsMap;
  34756. };
  34757. return ClippathManager;
  34758. }(Definable));
  34759. var ShadowManager = (function (_super) {
  34760. __extends(ShadowManager, _super);
  34761. function ShadowManager(zrId, svgRoot) {
  34762. var _this = _super.call(this, zrId, svgRoot, ['filter'], '__filter_in_use__', '_shadowDom') || this;
  34763. _this._shadowDomMap = {};
  34764. _this._shadowDomPool = [];
  34765. return _this;
  34766. }
  34767. ShadowManager.prototype._getFromPool = function () {
  34768. var shadowDom = this._shadowDomPool.pop();
  34769. if (!shadowDom) {
  34770. shadowDom = this.createElement('filter');
  34771. shadowDom.setAttribute('id', 'zr' + this._zrId + '-shadow-' + this.nextId++);
  34772. var domChild = this.createElement('feDropShadow');
  34773. shadowDom.appendChild(domChild);
  34774. this.addDom(shadowDom);
  34775. }
  34776. return shadowDom;
  34777. };
  34778. ShadowManager.prototype.update = function (svgElement, displayable) {
  34779. var style = displayable.style;
  34780. if (hasShadow(style)) {
  34781. var shadowKey = getShadowKey(displayable);
  34782. var shadowDom = displayable._shadowDom = this._shadowDomMap[shadowKey];
  34783. if (!shadowDom) {
  34784. shadowDom = this._getFromPool();
  34785. this._shadowDomMap[shadowKey] = shadowDom;
  34786. }
  34787. this.updateDom(svgElement, displayable, shadowDom);
  34788. }
  34789. else {
  34790. this.remove(svgElement, displayable);
  34791. }
  34792. };
  34793. ShadowManager.prototype.remove = function (svgElement, displayable) {
  34794. if (displayable._shadowDom != null) {
  34795. displayable._shadowDom = null;
  34796. svgElement.removeAttribute('filter');
  34797. }
  34798. };
  34799. ShadowManager.prototype.updateDom = function (svgElement, displayable, shadowDom) {
  34800. var domChild = shadowDom.children[0];
  34801. var style = displayable.style;
  34802. var globalScale = displayable.getGlobalScale();
  34803. var scaleX = globalScale[0];
  34804. var scaleY = globalScale[1];
  34805. if (!scaleX || !scaleY) {
  34806. return;
  34807. }
  34808. var offsetX = style.shadowOffsetX || 0;
  34809. var offsetY = style.shadowOffsetY || 0;
  34810. var blur = style.shadowBlur;
  34811. var normalizedColor = normalizeColor(style.shadowColor);
  34812. domChild.setAttribute('dx', offsetX / scaleX + '');
  34813. domChild.setAttribute('dy', offsetY / scaleY + '');
  34814. domChild.setAttribute('flood-color', normalizedColor.color);
  34815. domChild.setAttribute('flood-opacity', normalizedColor.opacity + '');
  34816. var stdDx = blur / 2 / scaleX;
  34817. var stdDy = blur / 2 / scaleY;
  34818. var stdDeviation = stdDx + ' ' + stdDy;
  34819. domChild.setAttribute('stdDeviation', stdDeviation);
  34820. shadowDom.setAttribute('x', '-100%');
  34821. shadowDom.setAttribute('y', '-100%');
  34822. shadowDom.setAttribute('width', '300%');
  34823. shadowDom.setAttribute('height', '300%');
  34824. displayable._shadowDom = shadowDom;
  34825. var id = shadowDom.getAttribute('id');
  34826. svgElement.setAttribute('filter', 'url(#' + id + ')');
  34827. };
  34828. ShadowManager.prototype.removeUnused = function () {
  34829. var defs = this.getDefs(false);
  34830. if (!defs) {
  34831. return;
  34832. }
  34833. var shadowDomsPool = this._shadowDomPool;
  34834. var shadowDomMap = this._shadowDomMap;
  34835. for (var key in shadowDomMap) {
  34836. if (shadowDomMap.hasOwnProperty(key)) {
  34837. shadowDomsPool.push(shadowDomMap[key]);
  34838. }
  34839. }
  34840. this._shadowDomMap = {};
  34841. };
  34842. return ShadowManager;
  34843. }(Definable));
  34844. function hasShadow(style) {
  34845. return style
  34846. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  34847. }
  34848. function getShadowKey(displayable) {
  34849. var style = displayable.style;
  34850. var globalScale = displayable.getGlobalScale();
  34851. return [
  34852. style.shadowColor,
  34853. (style.shadowBlur || 0).toFixed(2),
  34854. (style.shadowOffsetX || 0).toFixed(2),
  34855. (style.shadowOffsetY || 0).toFixed(2),
  34856. globalScale[0],
  34857. globalScale[1]
  34858. ].join(',');
  34859. }
  34860. function parseInt10(val) {
  34861. return parseInt(val, 10);
  34862. }
  34863. function getSvgProxy(el) {
  34864. if (el instanceof Path) {
  34865. return svgPath;
  34866. }
  34867. else if (el instanceof ZRImage) {
  34868. return svgImage;
  34869. }
  34870. else if (el instanceof TSpan) {
  34871. return svgText;
  34872. }
  34873. else {
  34874. return svgPath;
  34875. }
  34876. }
  34877. function checkParentAvailable(parent, child) {
  34878. return child && parent && child.parentNode !== parent;
  34879. }
  34880. function insertAfter(parent, child, prevSibling) {
  34881. if (checkParentAvailable(parent, child) && prevSibling) {
  34882. var nextSibling = prevSibling.nextSibling;
  34883. nextSibling ? parent.insertBefore(child, nextSibling)
  34884. : parent.appendChild(child);
  34885. }
  34886. }
  34887. function prepend(parent, child) {
  34888. if (checkParentAvailable(parent, child)) {
  34889. var firstChild = parent.firstChild;
  34890. firstChild ? parent.insertBefore(child, firstChild)
  34891. : parent.appendChild(child);
  34892. }
  34893. }
  34894. function remove(parent, child) {
  34895. if (child && parent && child.parentNode === parent) {
  34896. parent.removeChild(child);
  34897. }
  34898. }
  34899. function removeFromMyParent(child) {
  34900. if (child && child.parentNode) {
  34901. child.parentNode.removeChild(child);
  34902. }
  34903. }
  34904. function getSvgElement(displayable) {
  34905. return displayable.__svgEl;
  34906. }
  34907. var SVGPainter = (function () {
  34908. function SVGPainter(root, storage, opts, zrId) {
  34909. this.type = 'svg';
  34910. this.refreshHover = createMethodNotSupport('refreshHover');
  34911. this.pathToImage = createMethodNotSupport('pathToImage');
  34912. this.configLayer = createMethodNotSupport('configLayer');
  34913. this.root = root;
  34914. this.storage = storage;
  34915. this._opts = opts = extend({}, opts || {});
  34916. var svgDom = createElement('svg');
  34917. svgDom.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
  34918. svgDom.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
  34919. svgDom.setAttribute('version', '1.1');
  34920. svgDom.setAttribute('baseProfile', 'full');
  34921. svgDom.style.cssText = 'user-select:none;position:absolute;left:0;top:0;';
  34922. var bgRoot = createElement('g');
  34923. svgDom.appendChild(bgRoot);
  34924. var svgRoot = createElement('g');
  34925. svgDom.appendChild(svgRoot);
  34926. this._gradientManager = new GradientManager(zrId, svgRoot);
  34927. this._patternManager = new PatternManager(zrId, svgRoot);
  34928. this._clipPathManager = new ClippathManager(zrId, svgRoot);
  34929. this._shadowManager = new ShadowManager(zrId, svgRoot);
  34930. var viewport = document.createElement('div');
  34931. viewport.style.cssText = 'overflow:hidden;position:relative';
  34932. this._svgDom = svgDom;
  34933. this._svgRoot = svgRoot;
  34934. this._backgroundRoot = bgRoot;
  34935. this._viewport = viewport;
  34936. root.appendChild(viewport);
  34937. viewport.appendChild(svgDom);
  34938. this.resize(opts.width, opts.height);
  34939. this._visibleList = [];
  34940. }
  34941. SVGPainter.prototype.getType = function () {
  34942. return 'svg';
  34943. };
  34944. SVGPainter.prototype.getViewportRoot = function () {
  34945. return this._viewport;
  34946. };
  34947. SVGPainter.prototype.getSvgDom = function () {
  34948. return this._svgDom;
  34949. };
  34950. SVGPainter.prototype.getSvgRoot = function () {
  34951. return this._svgRoot;
  34952. };
  34953. SVGPainter.prototype.getViewportRootOffset = function () {
  34954. var viewportRoot = this.getViewportRoot();
  34955. if (viewportRoot) {
  34956. return {
  34957. offsetLeft: viewportRoot.offsetLeft || 0,
  34958. offsetTop: viewportRoot.offsetTop || 0
  34959. };
  34960. }
  34961. };
  34962. SVGPainter.prototype.refresh = function () {
  34963. var list = this.storage.getDisplayList(true);
  34964. this._paintList(list);
  34965. };
  34966. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  34967. if (this._backgroundRoot && this._backgroundNode) {
  34968. this._backgroundRoot.removeChild(this._backgroundNode);
  34969. }
  34970. var bgNode = createElement('rect');
  34971. bgNode.setAttribute('width', this.getWidth());
  34972. bgNode.setAttribute('height', this.getHeight());
  34973. bgNode.setAttribute('x', 0);
  34974. bgNode.setAttribute('y', 0);
  34975. bgNode.setAttribute('id', 0);
  34976. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  34977. bgNode.setAttribute('fill', color);
  34978. bgNode.setAttribute('fill-opacity', opacity);
  34979. this._backgroundRoot.appendChild(bgNode);
  34980. this._backgroundNode = bgNode;
  34981. };
  34982. SVGPainter.prototype.createSVGElement = function (tag) {
  34983. return createElement(tag);
  34984. };
  34985. SVGPainter.prototype.paintOne = function (el) {
  34986. var svgProxy = getSvgProxy(el);
  34987. svgProxy && svgProxy.brush(el);
  34988. return getSvgElement(el);
  34989. };
  34990. SVGPainter.prototype._paintList = function (list) {
  34991. var gradientManager = this._gradientManager;
  34992. var patternManager = this._patternManager;
  34993. var clipPathManager = this._clipPathManager;
  34994. var shadowManager = this._shadowManager;
  34995. gradientManager.markAllUnused();
  34996. patternManager.markAllUnused();
  34997. clipPathManager.markAllUnused();
  34998. shadowManager.markAllUnused();
  34999. var svgRoot = this._svgRoot;
  35000. var visibleList = this._visibleList;
  35001. var listLen = list.length;
  35002. var newVisibleList = [];
  35003. for (var i = 0; i < listLen; i++) {
  35004. var displayable = list[i];
  35005. var svgProxy = getSvgProxy(displayable);
  35006. var svgElement = getSvgElement(displayable);
  35007. if (!displayable.invisible) {
  35008. if (displayable.__dirty || !svgElement) {
  35009. svgProxy && svgProxy.brush(displayable);
  35010. svgElement = getSvgElement(displayable);
  35011. if (svgElement && displayable.style) {
  35012. gradientManager.update(displayable.style.fill);
  35013. gradientManager.update(displayable.style.stroke);
  35014. patternManager.update(displayable.style.fill);
  35015. patternManager.update(displayable.style.stroke);
  35016. shadowManager.update(svgElement, displayable);
  35017. }
  35018. displayable.__dirty = 0;
  35019. }
  35020. if (svgElement) {
  35021. newVisibleList.push(displayable);
  35022. }
  35023. }
  35024. }
  35025. var diff = arrayDiff(visibleList, newVisibleList);
  35026. var prevSvgElement;
  35027. var topPrevSvgElement;
  35028. for (var i = 0; i < diff.length; i++) {
  35029. var item = diff[i];
  35030. if (item.removed) {
  35031. for (var k = 0; k < item.count; k++) {
  35032. var displayable = visibleList[item.indices[k]];
  35033. var svgElement = getSvgElement(displayable);
  35034. hasClipPath(displayable) ? removeFromMyParent(svgElement)
  35035. : remove(svgRoot, svgElement);
  35036. }
  35037. }
  35038. }
  35039. var prevDisplayable;
  35040. var currentClipGroup;
  35041. for (var i = 0; i < diff.length; i++) {
  35042. var item = diff[i];
  35043. if (item.removed) {
  35044. continue;
  35045. }
  35046. for (var k = 0; k < item.count; k++) {
  35047. var displayable = newVisibleList[item.indices[k]];
  35048. var clipGroup = clipPathManager.update(displayable, prevDisplayable);
  35049. if (clipGroup !== currentClipGroup) {
  35050. prevSvgElement = topPrevSvgElement;
  35051. if (clipGroup) {
  35052. prevSvgElement ? insertAfter(svgRoot, clipGroup, prevSvgElement)
  35053. : prepend(svgRoot, clipGroup);
  35054. topPrevSvgElement = clipGroup;
  35055. prevSvgElement = null;
  35056. }
  35057. currentClipGroup = clipGroup;
  35058. }
  35059. var svgElement = getSvgElement(displayable);
  35060. prevSvgElement
  35061. ? insertAfter(currentClipGroup || svgRoot, svgElement, prevSvgElement)
  35062. : prepend(currentClipGroup || svgRoot, svgElement);
  35063. prevSvgElement = svgElement || prevSvgElement;
  35064. if (!currentClipGroup) {
  35065. topPrevSvgElement = prevSvgElement;
  35066. }
  35067. gradientManager.markUsed(displayable);
  35068. gradientManager.addWithoutUpdate(svgElement, displayable);
  35069. patternManager.markUsed(displayable);
  35070. patternManager.addWithoutUpdate(svgElement, displayable);
  35071. clipPathManager.markUsed(displayable);
  35072. prevDisplayable = displayable;
  35073. }
  35074. }
  35075. gradientManager.removeUnused();
  35076. patternManager.removeUnused();
  35077. clipPathManager.removeUnused();
  35078. shadowManager.removeUnused();
  35079. this._visibleList = newVisibleList;
  35080. };
  35081. SVGPainter.prototype.resize = function (width, height) {
  35082. var viewport = this._viewport;
  35083. viewport.style.display = 'none';
  35084. var opts = this._opts;
  35085. width != null && (opts.width = width);
  35086. height != null && (opts.height = height);
  35087. width = this._getSize(0);
  35088. height = this._getSize(1);
  35089. viewport.style.display = '';
  35090. if (this._width !== width || this._height !== height) {
  35091. this._width = width;
  35092. this._height = height;
  35093. var viewportStyle = viewport.style;
  35094. viewportStyle.width = width + 'px';
  35095. viewportStyle.height = height + 'px';
  35096. var svgRoot = this._svgDom;
  35097. svgRoot.setAttribute('width', width + '');
  35098. svgRoot.setAttribute('height', height + '');
  35099. }
  35100. if (this._backgroundNode) {
  35101. this._backgroundNode.setAttribute('width', width);
  35102. this._backgroundNode.setAttribute('height', height);
  35103. }
  35104. };
  35105. SVGPainter.prototype.getWidth = function () {
  35106. return this._width;
  35107. };
  35108. SVGPainter.prototype.getHeight = function () {
  35109. return this._height;
  35110. };
  35111. SVGPainter.prototype._getSize = function (whIdx) {
  35112. var opts = this._opts;
  35113. var wh = ['width', 'height'][whIdx];
  35114. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  35115. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  35116. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  35117. if (opts[wh] != null && opts[wh] !== 'auto') {
  35118. return parseFloat(opts[wh]);
  35119. }
  35120. var root = this.root;
  35121. var stl = document.defaultView.getComputedStyle(root);
  35122. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  35123. - (parseInt10(stl[plt]) || 0)
  35124. - (parseInt10(stl[prb]) || 0)) | 0;
  35125. };
  35126. SVGPainter.prototype.dispose = function () {
  35127. this.root.innerHTML = '';
  35128. this._svgRoot =
  35129. this._backgroundRoot =
  35130. this._svgDom =
  35131. this._backgroundNode =
  35132. this._viewport = this.storage = null;
  35133. };
  35134. SVGPainter.prototype.clear = function () {
  35135. var viewportNode = this._viewport;
  35136. if (viewportNode && viewportNode.parentNode) {
  35137. viewportNode.parentNode.removeChild(viewportNode);
  35138. }
  35139. };
  35140. SVGPainter.prototype.toDataURL = function () {
  35141. this.refresh();
  35142. var svgDom = this._svgDom;
  35143. var outerHTML = svgDom.outerHTML
  35144. || (svgDom.parentNode && svgDom.parentNode).innerHTML;
  35145. var html = encodeURIComponent(outerHTML.replace(/></g, '>\n\r<'));
  35146. return 'data:image/svg+xml;charset=UTF-8,' + html;
  35147. };
  35148. return SVGPainter;
  35149. }());
  35150. function createMethodNotSupport(method) {
  35151. return function () {
  35152. logError('In SVG mode painter not support method "' + method + '"');
  35153. };
  35154. }
  35155. function install(registers) {
  35156. registers.registerPainter('svg', SVGPainter);
  35157. }
  35158. function returnFalse() {
  35159. return false;
  35160. }
  35161. function createDom(id, painter, dpr) {
  35162. var newDom = createCanvas();
  35163. var width = painter.getWidth();
  35164. var height = painter.getHeight();
  35165. var newDomStyle = newDom.style;
  35166. if (newDomStyle) {
  35167. newDomStyle.position = 'absolute';
  35168. newDomStyle.left = '0';
  35169. newDomStyle.top = '0';
  35170. newDomStyle.width = width + 'px';
  35171. newDomStyle.height = height + 'px';
  35172. newDom.setAttribute('data-zr-dom-id', id);
  35173. }
  35174. newDom.width = width * dpr;
  35175. newDom.height = height * dpr;
  35176. return newDom;
  35177. }
  35178. var Layer = (function (_super) {
  35179. __extends(Layer, _super);
  35180. function Layer(id, painter, dpr) {
  35181. var _this = _super.call(this) || this;
  35182. _this.motionBlur = false;
  35183. _this.lastFrameAlpha = 0.7;
  35184. _this.dpr = 1;
  35185. _this.virtual = false;
  35186. _this.config = {};
  35187. _this.incremental = false;
  35188. _this.zlevel = 0;
  35189. _this.maxRepaintRectCount = 5;
  35190. _this.__dirty = true;
  35191. _this.__firstTimePaint = true;
  35192. _this.__used = false;
  35193. _this.__drawIndex = 0;
  35194. _this.__startIndex = 0;
  35195. _this.__endIndex = 0;
  35196. _this.__prevStartIndex = null;
  35197. _this.__prevEndIndex = null;
  35198. var dom;
  35199. dpr = dpr || devicePixelRatio;
  35200. if (typeof id === 'string') {
  35201. dom = createDom(id, painter, dpr);
  35202. }
  35203. else if (isObject(id)) {
  35204. dom = id;
  35205. id = dom.id;
  35206. }
  35207. _this.id = id;
  35208. _this.dom = dom;
  35209. var domStyle = dom.style;
  35210. if (domStyle) {
  35211. dom.onselectstart = returnFalse;
  35212. domStyle.webkitUserSelect = 'none';
  35213. domStyle.userSelect = 'none';
  35214. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  35215. domStyle['-webkit-touch-callout'] = 'none';
  35216. domStyle.padding = '0';
  35217. domStyle.margin = '0';
  35218. domStyle.borderWidth = '0';
  35219. }
  35220. _this.domBack = null;
  35221. _this.ctxBack = null;
  35222. _this.painter = painter;
  35223. _this.config = null;
  35224. _this.dpr = dpr;
  35225. return _this;
  35226. }
  35227. Layer.prototype.getElementCount = function () {
  35228. return this.__endIndex - this.__startIndex;
  35229. };
  35230. Layer.prototype.afterBrush = function () {
  35231. this.__prevStartIndex = this.__startIndex;
  35232. this.__prevEndIndex = this.__endIndex;
  35233. };
  35234. Layer.prototype.initContext = function () {
  35235. this.ctx = this.dom.getContext('2d');
  35236. this.ctx.dpr = this.dpr;
  35237. };
  35238. Layer.prototype.setUnpainted = function () {
  35239. this.__firstTimePaint = true;
  35240. };
  35241. Layer.prototype.createBackBuffer = function () {
  35242. var dpr = this.dpr;
  35243. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  35244. this.ctxBack = this.domBack.getContext('2d');
  35245. if (dpr !== 1) {
  35246. this.ctxBack.scale(dpr, dpr);
  35247. }
  35248. };
  35249. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  35250. if (this.__firstTimePaint) {
  35251. this.__firstTimePaint = false;
  35252. return null;
  35253. }
  35254. var mergedRepaintRects = [];
  35255. var maxRepaintRectCount = this.maxRepaintRectCount;
  35256. var full = false;
  35257. var pendingRect = new BoundingRect(0, 0, 0, 0);
  35258. function addRectToMergePool(rect) {
  35259. if (!rect.isFinite() || rect.isZero()) {
  35260. return;
  35261. }
  35262. if (mergedRepaintRects.length === 0) {
  35263. var boundingRect = new BoundingRect(0, 0, 0, 0);
  35264. boundingRect.copy(rect);
  35265. mergedRepaintRects.push(boundingRect);
  35266. }
  35267. else {
  35268. var isMerged = false;
  35269. var minDeltaArea = Infinity;
  35270. var bestRectToMergeIdx = 0;
  35271. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  35272. var mergedRect = mergedRepaintRects[i];
  35273. if (mergedRect.intersect(rect)) {
  35274. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  35275. pendingRect_1.copy(mergedRect);
  35276. pendingRect_1.union(rect);
  35277. mergedRepaintRects[i] = pendingRect_1;
  35278. isMerged = true;
  35279. break;
  35280. }
  35281. else if (full) {
  35282. pendingRect.copy(rect);
  35283. pendingRect.union(mergedRect);
  35284. var aArea = rect.width * rect.height;
  35285. var bArea = mergedRect.width * mergedRect.height;
  35286. var pendingArea = pendingRect.width * pendingRect.height;
  35287. var deltaArea = pendingArea - aArea - bArea;
  35288. if (deltaArea < minDeltaArea) {
  35289. minDeltaArea = deltaArea;
  35290. bestRectToMergeIdx = i;
  35291. }
  35292. }
  35293. }
  35294. if (full) {
  35295. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  35296. isMerged = true;
  35297. }
  35298. if (!isMerged) {
  35299. var boundingRect = new BoundingRect(0, 0, 0, 0);
  35300. boundingRect.copy(rect);
  35301. mergedRepaintRects.push(boundingRect);
  35302. }
  35303. if (!full) {
  35304. full = mergedRepaintRects.length >= maxRepaintRectCount;
  35305. }
  35306. }
  35307. }
  35308. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  35309. var el = displayList[i];
  35310. if (el) {
  35311. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  35312. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  35313. ? el.getPrevPaintRect()
  35314. : null;
  35315. if (prevRect) {
  35316. addRectToMergePool(prevRect);
  35317. }
  35318. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  35319. ? el.getPaintRect()
  35320. : null;
  35321. if (curRect) {
  35322. addRectToMergePool(curRect);
  35323. }
  35324. }
  35325. }
  35326. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  35327. var el = prevList[i];
  35328. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  35329. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  35330. var prevRect = el.getPrevPaintRect();
  35331. if (prevRect) {
  35332. addRectToMergePool(prevRect);
  35333. }
  35334. }
  35335. }
  35336. var hasIntersections;
  35337. do {
  35338. hasIntersections = false;
  35339. for (var i = 0; i < mergedRepaintRects.length;) {
  35340. if (mergedRepaintRects[i].isZero()) {
  35341. mergedRepaintRects.splice(i, 1);
  35342. continue;
  35343. }
  35344. for (var j = i + 1; j < mergedRepaintRects.length;) {
  35345. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  35346. hasIntersections = true;
  35347. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  35348. mergedRepaintRects.splice(j, 1);
  35349. }
  35350. else {
  35351. j++;
  35352. }
  35353. }
  35354. i++;
  35355. }
  35356. } while (hasIntersections);
  35357. this._paintRects = mergedRepaintRects;
  35358. return mergedRepaintRects;
  35359. };
  35360. Layer.prototype.debugGetPaintRects = function () {
  35361. return (this._paintRects || []).slice();
  35362. };
  35363. Layer.prototype.resize = function (width, height) {
  35364. var dpr = this.dpr;
  35365. var dom = this.dom;
  35366. var domStyle = dom.style;
  35367. var domBack = this.domBack;
  35368. if (domStyle) {
  35369. domStyle.width = width + 'px';
  35370. domStyle.height = height + 'px';
  35371. }
  35372. dom.width = width * dpr;
  35373. dom.height = height * dpr;
  35374. if (domBack) {
  35375. domBack.width = width * dpr;
  35376. domBack.height = height * dpr;
  35377. if (dpr !== 1) {
  35378. this.ctxBack.scale(dpr, dpr);
  35379. }
  35380. }
  35381. };
  35382. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  35383. var dom = this.dom;
  35384. var ctx = this.ctx;
  35385. var width = dom.width;
  35386. var height = dom.height;
  35387. clearColor = clearColor || this.clearColor;
  35388. var haveMotionBLur = this.motionBlur && !clearAll;
  35389. var lastFrameAlpha = this.lastFrameAlpha;
  35390. var dpr = this.dpr;
  35391. var self = this;
  35392. if (haveMotionBLur) {
  35393. if (!this.domBack) {
  35394. this.createBackBuffer();
  35395. }
  35396. this.ctxBack.globalCompositeOperation = 'copy';
  35397. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  35398. }
  35399. var domBack = this.domBack;
  35400. function doClear(x, y, width, height) {
  35401. ctx.clearRect(x, y, width, height);
  35402. if (clearColor && clearColor !== 'transparent') {
  35403. var clearColorGradientOrPattern = void 0;
  35404. if (isGradientObject(clearColor)) {
  35405. clearColorGradientOrPattern = clearColor.__canvasGradient
  35406. || getCanvasGradient(ctx, clearColor, {
  35407. x: 0,
  35408. y: 0,
  35409. width: width,
  35410. height: height
  35411. });
  35412. clearColor.__canvasGradient = clearColorGradientOrPattern;
  35413. }
  35414. else if (isImagePatternObject(clearColor)) {
  35415. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  35416. dirty: function () {
  35417. self.setUnpainted();
  35418. self.__painter.refresh();
  35419. }
  35420. });
  35421. }
  35422. ctx.save();
  35423. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  35424. ctx.fillRect(x, y, width, height);
  35425. ctx.restore();
  35426. }
  35427. if (haveMotionBLur) {
  35428. ctx.save();
  35429. ctx.globalAlpha = lastFrameAlpha;
  35430. ctx.drawImage(domBack, x, y, width, height);
  35431. ctx.restore();
  35432. }
  35433. }
  35434. if (!repaintRects || haveMotionBLur) {
  35435. doClear(0, 0, width, height);
  35436. }
  35437. else if (repaintRects.length) {
  35438. each(repaintRects, function (rect) {
  35439. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  35440. });
  35441. }
  35442. };
  35443. return Layer;
  35444. }(Eventful));
  35445. var HOVER_LAYER_ZLEVEL = 1e5;
  35446. var CANVAS_ZLEVEL = 314159;
  35447. var EL_AFTER_INCREMENTAL_INC = 0.01;
  35448. var INCREMENTAL_INC = 0.001;
  35449. function parseInt10$1(val) {
  35450. return parseInt(val, 10);
  35451. }
  35452. function isLayerValid(layer) {
  35453. if (!layer) {
  35454. return false;
  35455. }
  35456. if (layer.__builtin__) {
  35457. return true;
  35458. }
  35459. if (typeof (layer.resize) !== 'function'
  35460. || typeof (layer.refresh) !== 'function') {
  35461. return false;
  35462. }
  35463. return true;
  35464. }
  35465. function createRoot(width, height) {
  35466. var domRoot = document.createElement('div');
  35467. domRoot.style.cssText = [
  35468. 'position:relative',
  35469. 'width:' + width + 'px',
  35470. 'height:' + height + 'px',
  35471. 'padding:0',
  35472. 'margin:0',
  35473. 'border-width:0'
  35474. ].join(';') + ';';
  35475. return domRoot;
  35476. }
  35477. var CanvasPainter = (function () {
  35478. function CanvasPainter(root, storage, opts, id) {
  35479. this.type = 'canvas';
  35480. this._zlevelList = [];
  35481. this._prevDisplayList = [];
  35482. this._layers = {};
  35483. this._layerConfig = {};
  35484. this._needsManuallyCompositing = false;
  35485. this.type = 'canvas';
  35486. var singleCanvas = !root.nodeName
  35487. || root.nodeName.toUpperCase() === 'CANVAS';
  35488. this._opts = opts = extend({}, opts || {});
  35489. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  35490. this._singleCanvas = singleCanvas;
  35491. this.root = root;
  35492. var rootStyle = root.style;
  35493. if (rootStyle) {
  35494. rootStyle.webkitTapHighlightColor = 'transparent';
  35495. rootStyle.webkitUserSelect = 'none';
  35496. rootStyle.userSelect = 'none';
  35497. rootStyle['-webkit-touch-callout'] = 'none';
  35498. root.innerHTML = '';
  35499. }
  35500. this.storage = storage;
  35501. var zlevelList = this._zlevelList;
  35502. this._prevDisplayList = [];
  35503. var layers = this._layers;
  35504. if (!singleCanvas) {
  35505. this._width = this._getSize(0);
  35506. this._height = this._getSize(1);
  35507. var domRoot = this._domRoot = createRoot(this._width, this._height);
  35508. root.appendChild(domRoot);
  35509. }
  35510. else {
  35511. var rootCanvas = root;
  35512. var width = rootCanvas.width;
  35513. var height = rootCanvas.height;
  35514. if (opts.width != null) {
  35515. width = opts.width;
  35516. }
  35517. if (opts.height != null) {
  35518. height = opts.height;
  35519. }
  35520. this.dpr = opts.devicePixelRatio || 1;
  35521. rootCanvas.width = width * this.dpr;
  35522. rootCanvas.height = height * this.dpr;
  35523. this._width = width;
  35524. this._height = height;
  35525. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  35526. mainLayer.__builtin__ = true;
  35527. mainLayer.initContext();
  35528. layers[CANVAS_ZLEVEL] = mainLayer;
  35529. mainLayer.zlevel = CANVAS_ZLEVEL;
  35530. zlevelList.push(CANVAS_ZLEVEL);
  35531. this._domRoot = root;
  35532. }
  35533. }
  35534. CanvasPainter.prototype.getType = function () {
  35535. return 'canvas';
  35536. };
  35537. CanvasPainter.prototype.isSingleCanvas = function () {
  35538. return this._singleCanvas;
  35539. };
  35540. CanvasPainter.prototype.getViewportRoot = function () {
  35541. return this._domRoot;
  35542. };
  35543. CanvasPainter.prototype.getViewportRootOffset = function () {
  35544. var viewportRoot = this.getViewportRoot();
  35545. if (viewportRoot) {
  35546. return {
  35547. offsetLeft: viewportRoot.offsetLeft || 0,
  35548. offsetTop: viewportRoot.offsetTop || 0
  35549. };
  35550. }
  35551. };
  35552. CanvasPainter.prototype.refresh = function (paintAll) {
  35553. var list = this.storage.getDisplayList(true);
  35554. var prevList = this._prevDisplayList;
  35555. var zlevelList = this._zlevelList;
  35556. this._redrawId = Math.random();
  35557. this._paintList(list, prevList, paintAll, this._redrawId);
  35558. for (var i = 0; i < zlevelList.length; i++) {
  35559. var z = zlevelList[i];
  35560. var layer = this._layers[z];
  35561. if (!layer.__builtin__ && layer.refresh) {
  35562. var clearColor = i === 0 ? this._backgroundColor : null;
  35563. layer.refresh(clearColor);
  35564. }
  35565. }
  35566. if (this._opts.useDirtyRect) {
  35567. this._prevDisplayList = list.slice();
  35568. }
  35569. return this;
  35570. };
  35571. CanvasPainter.prototype.refreshHover = function () {
  35572. this._paintHoverList(this.storage.getDisplayList(false));
  35573. };
  35574. CanvasPainter.prototype._paintHoverList = function (list) {
  35575. var len = list.length;
  35576. var hoverLayer = this._hoverlayer;
  35577. hoverLayer && hoverLayer.clear();
  35578. if (!len) {
  35579. return;
  35580. }
  35581. var scope = {
  35582. inHover: true,
  35583. viewWidth: this._width,
  35584. viewHeight: this._height
  35585. };
  35586. var ctx;
  35587. for (var i = 0; i < len; i++) {
  35588. var el = list[i];
  35589. if (el.__inHover) {
  35590. if (!hoverLayer) {
  35591. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  35592. }
  35593. if (!ctx) {
  35594. ctx = hoverLayer.ctx;
  35595. ctx.save();
  35596. }
  35597. brush(ctx, el, scope, i === len - 1);
  35598. }
  35599. }
  35600. if (ctx) {
  35601. ctx.restore();
  35602. }
  35603. };
  35604. CanvasPainter.prototype.getHoverLayer = function () {
  35605. return this.getLayer(HOVER_LAYER_ZLEVEL);
  35606. };
  35607. CanvasPainter.prototype.paintOne = function (ctx, el) {
  35608. brushSingle(ctx, el);
  35609. };
  35610. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  35611. if (this._redrawId !== redrawId) {
  35612. return;
  35613. }
  35614. paintAll = paintAll || false;
  35615. this._updateLayerStatus(list);
  35616. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  35617. if (this._needsManuallyCompositing) {
  35618. this._compositeManually();
  35619. }
  35620. if (needsRefreshHover) {
  35621. this._paintHoverList(list);
  35622. }
  35623. if (!finished) {
  35624. var self_1 = this;
  35625. requestAnimationFrame$1(function () {
  35626. self_1._paintList(list, prevList, paintAll, redrawId);
  35627. });
  35628. }
  35629. else {
  35630. this.eachLayer(function (layer) {
  35631. layer.afterBrush && layer.afterBrush();
  35632. });
  35633. }
  35634. };
  35635. CanvasPainter.prototype._compositeManually = function () {
  35636. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  35637. var width = this._domRoot.width;
  35638. var height = this._domRoot.height;
  35639. ctx.clearRect(0, 0, width, height);
  35640. this.eachBuiltinLayer(function (layer) {
  35641. if (layer.virtual) {
  35642. ctx.drawImage(layer.dom, 0, 0, width, height);
  35643. }
  35644. });
  35645. };
  35646. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  35647. var _this = this;
  35648. var layerList = [];
  35649. var useDirtyRect = this._opts.useDirtyRect;
  35650. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  35651. var zlevel = this._zlevelList[zi];
  35652. var layer = this._layers[zlevel];
  35653. if (layer.__builtin__
  35654. && layer !== this._hoverlayer
  35655. && (layer.__dirty || paintAll)) {
  35656. layerList.push(layer);
  35657. }
  35658. }
  35659. var finished = true;
  35660. var needsRefreshHover = false;
  35661. var _loop_1 = function (k) {
  35662. var layer = layerList[k];
  35663. var ctx = layer.ctx;
  35664. var repaintRects = useDirtyRect
  35665. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  35666. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  35667. var useTimer = !paintAll && layer.incremental && Date.now;
  35668. var startTime = useTimer && Date.now();
  35669. var clearColor = layer.zlevel === this_1._zlevelList[0]
  35670. ? this_1._backgroundColor : null;
  35671. if (layer.__startIndex === layer.__endIndex) {
  35672. layer.clear(false, clearColor, repaintRects);
  35673. }
  35674. else if (start === layer.__startIndex) {
  35675. var firstEl = list[start];
  35676. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  35677. layer.clear(false, clearColor, repaintRects);
  35678. }
  35679. }
  35680. if (start === -1) {
  35681. console.error('For some unknown reason. drawIndex is -1');
  35682. start = layer.__startIndex;
  35683. }
  35684. var i;
  35685. var repaint = function (repaintRect) {
  35686. var scope = {
  35687. inHover: false,
  35688. allClipped: false,
  35689. prevEl: null,
  35690. viewWidth: _this._width,
  35691. viewHeight: _this._height
  35692. };
  35693. for (i = start; i < layer.__endIndex; i++) {
  35694. var el = list[i];
  35695. if (el.__inHover) {
  35696. needsRefreshHover = true;
  35697. }
  35698. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  35699. if (useTimer) {
  35700. var dTime = Date.now() - startTime;
  35701. if (dTime > 15) {
  35702. break;
  35703. }
  35704. }
  35705. }
  35706. if (scope.prevElClipPaths) {
  35707. ctx.restore();
  35708. }
  35709. };
  35710. if (repaintRects) {
  35711. if (repaintRects.length === 0) {
  35712. i = layer.__endIndex;
  35713. }
  35714. else {
  35715. var dpr = this_1.dpr;
  35716. for (var r = 0; r < repaintRects.length; ++r) {
  35717. var rect = repaintRects[r];
  35718. ctx.save();
  35719. ctx.beginPath();
  35720. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  35721. ctx.clip();
  35722. repaint(rect);
  35723. ctx.restore();
  35724. }
  35725. }
  35726. }
  35727. else {
  35728. ctx.save();
  35729. repaint();
  35730. ctx.restore();
  35731. }
  35732. layer.__drawIndex = i;
  35733. if (layer.__drawIndex < layer.__endIndex) {
  35734. finished = false;
  35735. }
  35736. };
  35737. var this_1 = this;
  35738. for (var k = 0; k < layerList.length; k++) {
  35739. _loop_1(k);
  35740. }
  35741. if (env.wxa) {
  35742. each(this._layers, function (layer) {
  35743. if (layer && layer.ctx && layer.ctx.draw) {
  35744. layer.ctx.draw();
  35745. }
  35746. });
  35747. }
  35748. return {
  35749. finished: finished,
  35750. needsRefreshHover: needsRefreshHover
  35751. };
  35752. };
  35753. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  35754. var ctx = currentLayer.ctx;
  35755. if (useDirtyRect) {
  35756. var paintRect = el.getPaintRect();
  35757. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  35758. brush(ctx, el, scope, isLast);
  35759. el.setPrevPaintRect(paintRect);
  35760. }
  35761. }
  35762. else {
  35763. brush(ctx, el, scope, isLast);
  35764. }
  35765. };
  35766. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  35767. if (this._singleCanvas && !this._needsManuallyCompositing) {
  35768. zlevel = CANVAS_ZLEVEL;
  35769. }
  35770. var layer = this._layers[zlevel];
  35771. if (!layer) {
  35772. layer = new Layer('zr_' + zlevel, this, this.dpr);
  35773. layer.zlevel = zlevel;
  35774. layer.__builtin__ = true;
  35775. if (this._layerConfig[zlevel]) {
  35776. merge(layer, this._layerConfig[zlevel], true);
  35777. }
  35778. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  35779. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  35780. }
  35781. if (virtual) {
  35782. layer.virtual = virtual;
  35783. }
  35784. this.insertLayer(zlevel, layer);
  35785. layer.initContext();
  35786. }
  35787. return layer;
  35788. };
  35789. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  35790. var layersMap = this._layers;
  35791. var zlevelList = this._zlevelList;
  35792. var len = zlevelList.length;
  35793. var domRoot = this._domRoot;
  35794. var prevLayer = null;
  35795. var i = -1;
  35796. if (layersMap[zlevel]) {
  35797. logError('ZLevel ' + zlevel + ' has been used already');
  35798. return;
  35799. }
  35800. if (!isLayerValid(layer)) {
  35801. logError('Layer of zlevel ' + zlevel + ' is not valid');
  35802. return;
  35803. }
  35804. if (len > 0 && zlevel > zlevelList[0]) {
  35805. for (i = 0; i < len - 1; i++) {
  35806. if (zlevelList[i] < zlevel
  35807. && zlevelList[i + 1] > zlevel) {
  35808. break;
  35809. }
  35810. }
  35811. prevLayer = layersMap[zlevelList[i]];
  35812. }
  35813. zlevelList.splice(i + 1, 0, zlevel);
  35814. layersMap[zlevel] = layer;
  35815. if (!layer.virtual) {
  35816. if (prevLayer) {
  35817. var prevDom = prevLayer.dom;
  35818. if (prevDom.nextSibling) {
  35819. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  35820. }
  35821. else {
  35822. domRoot.appendChild(layer.dom);
  35823. }
  35824. }
  35825. else {
  35826. if (domRoot.firstChild) {
  35827. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  35828. }
  35829. else {
  35830. domRoot.appendChild(layer.dom);
  35831. }
  35832. }
  35833. }
  35834. layer.__painter = this;
  35835. };
  35836. CanvasPainter.prototype.eachLayer = function (cb, context) {
  35837. var zlevelList = this._zlevelList;
  35838. for (var i = 0; i < zlevelList.length; i++) {
  35839. var z = zlevelList[i];
  35840. cb.call(context, this._layers[z], z);
  35841. }
  35842. };
  35843. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  35844. var zlevelList = this._zlevelList;
  35845. for (var i = 0; i < zlevelList.length; i++) {
  35846. var z = zlevelList[i];
  35847. var layer = this._layers[z];
  35848. if (layer.__builtin__) {
  35849. cb.call(context, layer, z);
  35850. }
  35851. }
  35852. };
  35853. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  35854. var zlevelList = this._zlevelList;
  35855. for (var i = 0; i < zlevelList.length; i++) {
  35856. var z = zlevelList[i];
  35857. var layer = this._layers[z];
  35858. if (!layer.__builtin__) {
  35859. cb.call(context, layer, z);
  35860. }
  35861. }
  35862. };
  35863. CanvasPainter.prototype.getLayers = function () {
  35864. return this._layers;
  35865. };
  35866. CanvasPainter.prototype._updateLayerStatus = function (list) {
  35867. this.eachBuiltinLayer(function (layer, z) {
  35868. layer.__dirty = layer.__used = false;
  35869. });
  35870. function updatePrevLayer(idx) {
  35871. if (prevLayer) {
  35872. if (prevLayer.__endIndex !== idx) {
  35873. prevLayer.__dirty = true;
  35874. }
  35875. prevLayer.__endIndex = idx;
  35876. }
  35877. }
  35878. if (this._singleCanvas) {
  35879. for (var i_1 = 1; i_1 < list.length; i_1++) {
  35880. var el = list[i_1];
  35881. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  35882. this._needsManuallyCompositing = true;
  35883. break;
  35884. }
  35885. }
  35886. }
  35887. var prevLayer = null;
  35888. var incrementalLayerCount = 0;
  35889. var prevZlevel;
  35890. var i;
  35891. for (i = 0; i < list.length; i++) {
  35892. var el = list[i];
  35893. var zlevel = el.zlevel;
  35894. var layer = void 0;
  35895. if (prevZlevel !== zlevel) {
  35896. prevZlevel = zlevel;
  35897. incrementalLayerCount = 0;
  35898. }
  35899. if (el.incremental) {
  35900. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  35901. layer.incremental = true;
  35902. incrementalLayerCount = 1;
  35903. }
  35904. else {
  35905. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  35906. }
  35907. if (!layer.__builtin__) {
  35908. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  35909. }
  35910. if (layer !== prevLayer) {
  35911. layer.__used = true;
  35912. if (layer.__startIndex !== i) {
  35913. layer.__dirty = true;
  35914. }
  35915. layer.__startIndex = i;
  35916. if (!layer.incremental) {
  35917. layer.__drawIndex = i;
  35918. }
  35919. else {
  35920. layer.__drawIndex = -1;
  35921. }
  35922. updatePrevLayer(i);
  35923. prevLayer = layer;
  35924. }
  35925. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  35926. layer.__dirty = true;
  35927. if (layer.incremental && layer.__drawIndex < 0) {
  35928. layer.__drawIndex = i;
  35929. }
  35930. }
  35931. }
  35932. updatePrevLayer(i);
  35933. this.eachBuiltinLayer(function (layer, z) {
  35934. if (!layer.__used && layer.getElementCount() > 0) {
  35935. layer.__dirty = true;
  35936. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  35937. }
  35938. if (layer.__dirty && layer.__drawIndex < 0) {
  35939. layer.__drawIndex = layer.__startIndex;
  35940. }
  35941. });
  35942. };
  35943. CanvasPainter.prototype.clear = function () {
  35944. this.eachBuiltinLayer(this._clearLayer);
  35945. return this;
  35946. };
  35947. CanvasPainter.prototype._clearLayer = function (layer) {
  35948. layer.clear();
  35949. };
  35950. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  35951. this._backgroundColor = backgroundColor;
  35952. each(this._layers, function (layer) {
  35953. layer.setUnpainted();
  35954. });
  35955. };
  35956. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  35957. if (config) {
  35958. var layerConfig = this._layerConfig;
  35959. if (!layerConfig[zlevel]) {
  35960. layerConfig[zlevel] = config;
  35961. }
  35962. else {
  35963. merge(layerConfig[zlevel], config, true);
  35964. }
  35965. for (var i = 0; i < this._zlevelList.length; i++) {
  35966. var _zlevel = this._zlevelList[i];
  35967. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  35968. var layer = this._layers[_zlevel];
  35969. merge(layer, layerConfig[zlevel], true);
  35970. }
  35971. }
  35972. }
  35973. };
  35974. CanvasPainter.prototype.delLayer = function (zlevel) {
  35975. var layers = this._layers;
  35976. var zlevelList = this._zlevelList;
  35977. var layer = layers[zlevel];
  35978. if (!layer) {
  35979. return;
  35980. }
  35981. layer.dom.parentNode.removeChild(layer.dom);
  35982. delete layers[zlevel];
  35983. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  35984. };
  35985. CanvasPainter.prototype.resize = function (width, height) {
  35986. if (!this._domRoot.style) {
  35987. if (width == null || height == null) {
  35988. return;
  35989. }
  35990. this._width = width;
  35991. this._height = height;
  35992. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  35993. }
  35994. else {
  35995. var domRoot = this._domRoot;
  35996. domRoot.style.display = 'none';
  35997. var opts = this._opts;
  35998. width != null && (opts.width = width);
  35999. height != null && (opts.height = height);
  36000. width = this._getSize(0);
  36001. height = this._getSize(1);
  36002. domRoot.style.display = '';
  36003. if (this._width !== width || height !== this._height) {
  36004. domRoot.style.width = width + 'px';
  36005. domRoot.style.height = height + 'px';
  36006. for (var id in this._layers) {
  36007. if (this._layers.hasOwnProperty(id)) {
  36008. this._layers[id].resize(width, height);
  36009. }
  36010. }
  36011. this.refresh(true);
  36012. }
  36013. this._width = width;
  36014. this._height = height;
  36015. }
  36016. return this;
  36017. };
  36018. CanvasPainter.prototype.clearLayer = function (zlevel) {
  36019. var layer = this._layers[zlevel];
  36020. if (layer) {
  36021. layer.clear();
  36022. }
  36023. };
  36024. CanvasPainter.prototype.dispose = function () {
  36025. this.root.innerHTML = '';
  36026. this.root =
  36027. this.storage =
  36028. this._domRoot =
  36029. this._layers = null;
  36030. };
  36031. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  36032. opts = opts || {};
  36033. if (this._singleCanvas && !this._compositeManually) {
  36034. return this._layers[CANVAS_ZLEVEL].dom;
  36035. }
  36036. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  36037. imageLayer.initContext();
  36038. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  36039. var ctx = imageLayer.ctx;
  36040. if (opts.pixelRatio <= this.dpr) {
  36041. this.refresh();
  36042. var width_1 = imageLayer.dom.width;
  36043. var height_1 = imageLayer.dom.height;
  36044. this.eachLayer(function (layer) {
  36045. if (layer.__builtin__) {
  36046. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  36047. }
  36048. else if (layer.renderToCanvas) {
  36049. ctx.save();
  36050. layer.renderToCanvas(ctx);
  36051. ctx.restore();
  36052. }
  36053. });
  36054. }
  36055. else {
  36056. var scope = {
  36057. inHover: false,
  36058. viewWidth: this._width,
  36059. viewHeight: this._height
  36060. };
  36061. var displayList = this.storage.getDisplayList(true);
  36062. for (var i = 0, len = displayList.length; i < len; i++) {
  36063. var el = displayList[i];
  36064. brush(ctx, el, scope, i === len - 1);
  36065. }
  36066. }
  36067. return imageLayer.dom;
  36068. };
  36069. CanvasPainter.prototype.getWidth = function () {
  36070. return this._width;
  36071. };
  36072. CanvasPainter.prototype.getHeight = function () {
  36073. return this._height;
  36074. };
  36075. CanvasPainter.prototype._getSize = function (whIdx) {
  36076. var opts = this._opts;
  36077. var wh = ['width', 'height'][whIdx];
  36078. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  36079. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  36080. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  36081. if (opts[wh] != null && opts[wh] !== 'auto') {
  36082. return parseFloat(opts[wh]);
  36083. }
  36084. var root = this.root;
  36085. var stl = document.defaultView.getComputedStyle(root);
  36086. return ((root[cwh] || parseInt10$1(stl[wh]) || parseInt10$1(root.style[wh]))
  36087. - (parseInt10$1(stl[plt]) || 0)
  36088. - (parseInt10$1(stl[prb]) || 0)) | 0;
  36089. };
  36090. CanvasPainter.prototype.pathToImage = function (path, dpr) {
  36091. dpr = dpr || this.dpr;
  36092. var canvas = document.createElement('canvas');
  36093. var ctx = canvas.getContext('2d');
  36094. var rect = path.getBoundingRect();
  36095. var style = path.style;
  36096. var shadowBlurSize = style.shadowBlur * dpr;
  36097. var shadowOffsetX = style.shadowOffsetX * dpr;
  36098. var shadowOffsetY = style.shadowOffsetY * dpr;
  36099. var lineWidth = path.hasStroke() ? style.lineWidth : 0;
  36100. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  36101. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  36102. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  36103. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  36104. var width = rect.width + leftMargin + rightMargin;
  36105. var height = rect.height + topMargin + bottomMargin;
  36106. canvas.width = width * dpr;
  36107. canvas.height = height * dpr;
  36108. ctx.scale(dpr, dpr);
  36109. ctx.clearRect(0, 0, width, height);
  36110. ctx.dpr = dpr;
  36111. var pathTransform = {
  36112. x: path.x,
  36113. y: path.y,
  36114. scaleX: path.scaleX,
  36115. scaleY: path.scaleY,
  36116. rotation: path.rotation,
  36117. originX: path.originX,
  36118. originY: path.originY
  36119. };
  36120. path.x = leftMargin - rect.x;
  36121. path.y = topMargin - rect.y;
  36122. path.rotation = 0;
  36123. path.scaleX = 1;
  36124. path.scaleY = 1;
  36125. path.updateTransform();
  36126. if (path) {
  36127. brush(ctx, path, {
  36128. inHover: false,
  36129. viewWidth: this._width,
  36130. viewHeight: this._height
  36131. }, true);
  36132. }
  36133. var imgShape = new ZRImage({
  36134. style: {
  36135. x: 0,
  36136. y: 0,
  36137. image: canvas
  36138. }
  36139. });
  36140. extend(path, pathTransform);
  36141. return imgShape;
  36142. };
  36143. return CanvasPainter;
  36144. }());
  36145. function install$1(registers) {
  36146. registers.registerPainter('canvas', CanvasPainter);
  36147. }
  36148. var LineSeriesModel =
  36149. /** @class */
  36150. function (_super) {
  36151. __extends(LineSeriesModel, _super);
  36152. function LineSeriesModel() {
  36153. var _this = _super !== null && _super.apply(this, arguments) || this;
  36154. _this.type = LineSeriesModel.type;
  36155. _this.hasSymbolVisual = true;
  36156. return _this;
  36157. }
  36158. LineSeriesModel.prototype.getInitialData = function (option) {
  36159. if ("development" !== 'production') {
  36160. var coordSys = option.coordinateSystem;
  36161. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  36162. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  36163. }
  36164. }
  36165. return createSeriesData(null, this, {
  36166. useEncodeDefaulter: true
  36167. });
  36168. };
  36169. LineSeriesModel.prototype.getLegendIcon = function (opt) {
  36170. var group = new Group();
  36171. var line = createSymbol('line', 0, opt.itemHeight / 2, opt.itemWidth, 0, opt.lineStyle.stroke, false);
  36172. group.add(line);
  36173. line.setStyle(opt.lineStyle);
  36174. var visualType = this.getData().getVisual('symbol');
  36175. var visualRotate = this.getData().getVisual('symbolRotate');
  36176. var symbolType = visualType === 'none' ? 'circle' : visualType; // Symbol size is 80% when there is a line
  36177. var size = opt.itemHeight * 0.8;
  36178. var symbol = createSymbol(symbolType, (opt.itemWidth - size) / 2, (opt.itemHeight - size) / 2, size, size, opt.itemStyle.fill);
  36179. group.add(symbol);
  36180. symbol.setStyle(opt.itemStyle);
  36181. var symbolRotate = opt.iconRotate === 'inherit' ? visualRotate : opt.iconRotate || 0;
  36182. symbol.rotation = symbolRotate * Math.PI / 180;
  36183. symbol.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
  36184. if (symbolType.indexOf('empty') > -1) {
  36185. symbol.style.stroke = symbol.style.fill;
  36186. symbol.style.fill = '#fff';
  36187. symbol.style.lineWidth = 2;
  36188. }
  36189. return group;
  36190. };
  36191. LineSeriesModel.type = 'series.line';
  36192. LineSeriesModel.dependencies = ['grid', 'polar'];
  36193. LineSeriesModel.defaultOption = {
  36194. zlevel: 0,
  36195. z: 3,
  36196. coordinateSystem: 'cartesian2d',
  36197. legendHoverLink: true,
  36198. clip: true,
  36199. label: {
  36200. position: 'top'
  36201. },
  36202. // itemStyle: {
  36203. // },
  36204. endLabel: {
  36205. show: false,
  36206. valueAnimation: true,
  36207. distance: 8
  36208. },
  36209. lineStyle: {
  36210. width: 2,
  36211. type: 'solid'
  36212. },
  36213. emphasis: {
  36214. scale: true,
  36215. lineStyle: {
  36216. width: 'bolder'
  36217. }
  36218. },
  36219. // areaStyle: {
  36220. // origin of areaStyle. Valid values:
  36221. // `'auto'/null/undefined`: from axisLine to data
  36222. // `'start'`: from min to data
  36223. // `'end'`: from data to max
  36224. // origin: 'auto'
  36225. // },
  36226. // false, 'start', 'end', 'middle'
  36227. step: false,
  36228. // Disabled if step is true
  36229. smooth: false,
  36230. smoothMonotone: null,
  36231. symbol: 'emptyCircle',
  36232. symbolSize: 4,
  36233. symbolRotate: null,
  36234. showSymbol: true,
  36235. // `false`: follow the label interval strategy.
  36236. // `true`: show all symbols.
  36237. // `'auto'`: If possible, show all symbols, otherwise
  36238. // follow the label interval strategy.
  36239. showAllSymbol: 'auto',
  36240. // Whether to connect break point.
  36241. connectNulls: false,
  36242. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum', 'lttb'.
  36243. sampling: 'none',
  36244. animationEasing: 'linear',
  36245. // Disable progressive
  36246. progressive: 0,
  36247. hoverLayerThreshold: Infinity,
  36248. universalTransition: {
  36249. divideShape: 'clone'
  36250. },
  36251. triggerLineEvent: false
  36252. };
  36253. return LineSeriesModel;
  36254. }(SeriesModel);
  36255. /**
  36256. * @return label string. Not null/undefined
  36257. */
  36258. function getDefaultLabel(data, dataIndex) {
  36259. var labelDims = data.mapDimensionsAll('defaultedLabel');
  36260. var len = labelDims.length; // Simple optimization (in lots of cases, label dims length is 1)
  36261. if (len === 1) {
  36262. var rawVal = retrieveRawValue(data, dataIndex, labelDims[0]);
  36263. return rawVal != null ? rawVal + '' : null;
  36264. } else if (len) {
  36265. var vals = [];
  36266. for (var i = 0; i < labelDims.length; i++) {
  36267. vals.push(retrieveRawValue(data, dataIndex, labelDims[i]));
  36268. }
  36269. return vals.join(' ');
  36270. }
  36271. }
  36272. function getDefaultInterpolatedLabel(data, interpolatedValue) {
  36273. var labelDims = data.mapDimensionsAll('defaultedLabel');
  36274. if (!isArray(interpolatedValue)) {
  36275. return interpolatedValue + '';
  36276. }
  36277. var vals = [];
  36278. for (var i = 0; i < labelDims.length; i++) {
  36279. var dimIndex = data.getDimensionIndex(labelDims[i]);
  36280. if (dimIndex >= 0) {
  36281. vals.push(interpolatedValue[dimIndex]);
  36282. }
  36283. }
  36284. return vals.join(' ');
  36285. }
  36286. var Symbol =
  36287. /** @class */
  36288. function (_super) {
  36289. __extends(Symbol, _super);
  36290. function Symbol(data, idx, seriesScope, opts) {
  36291. var _this = _super.call(this) || this;
  36292. _this.updateData(data, idx, seriesScope, opts);
  36293. return _this;
  36294. }
  36295. Symbol.prototype._createSymbol = function (symbolType, data, idx, symbolSize, keepAspect) {
  36296. // Remove paths created before
  36297. this.removeAll(); // let symbolPath = createSymbol(
  36298. // symbolType, -0.5, -0.5, 1, 1, color
  36299. // );
  36300. // If width/height are set too small (e.g., set to 1) on ios10
  36301. // and macOS Sierra, a circle stroke become a rect, no matter what
  36302. // the scale is set. So we set width/height as 2. See #4150.
  36303. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, null, keepAspect);
  36304. symbolPath.attr({
  36305. z2: 100,
  36306. culling: true,
  36307. scaleX: symbolSize[0] / 2,
  36308. scaleY: symbolSize[1] / 2
  36309. }); // Rewrite drift method
  36310. symbolPath.drift = driftSymbol;
  36311. this._symbolType = symbolType;
  36312. this.add(symbolPath);
  36313. };
  36314. /**
  36315. * Stop animation
  36316. * @param {boolean} toLastFrame
  36317. */
  36318. Symbol.prototype.stopSymbolAnimation = function (toLastFrame) {
  36319. this.childAt(0).stopAnimation(null, toLastFrame);
  36320. };
  36321. Symbol.prototype.getSymbolType = function () {
  36322. return this._symbolType;
  36323. };
  36324. /**
  36325. * FIXME:
  36326. * Caution: This method breaks the encapsulation of this module,
  36327. * but it indeed brings convenience. So do not use the method
  36328. * unless you detailedly know all the implements of `Symbol`,
  36329. * especially animation.
  36330. *
  36331. * Get symbol path element.
  36332. */
  36333. Symbol.prototype.getSymbolPath = function () {
  36334. return this.childAt(0);
  36335. };
  36336. /**
  36337. * Highlight symbol
  36338. */
  36339. Symbol.prototype.highlight = function () {
  36340. enterEmphasis(this.childAt(0));
  36341. };
  36342. /**
  36343. * Downplay symbol
  36344. */
  36345. Symbol.prototype.downplay = function () {
  36346. leaveEmphasis(this.childAt(0));
  36347. };
  36348. /**
  36349. * @param {number} zlevel
  36350. * @param {number} z
  36351. */
  36352. Symbol.prototype.setZ = function (zlevel, z) {
  36353. var symbolPath = this.childAt(0);
  36354. symbolPath.zlevel = zlevel;
  36355. symbolPath.z = z;
  36356. };
  36357. Symbol.prototype.setDraggable = function (draggable) {
  36358. var symbolPath = this.childAt(0);
  36359. symbolPath.draggable = draggable;
  36360. symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
  36361. };
  36362. /**
  36363. * Update symbol properties
  36364. */
  36365. Symbol.prototype.updateData = function (data, idx, seriesScope, opts) {
  36366. this.silent = false;
  36367. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  36368. var seriesModel = data.hostModel;
  36369. var symbolSize = Symbol.getSymbolSize(data, idx);
  36370. var isInit = symbolType !== this._symbolType;
  36371. var disableAnimation = opts && opts.disableAnimation;
  36372. if (isInit) {
  36373. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  36374. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  36375. } else {
  36376. var symbolPath = this.childAt(0);
  36377. symbolPath.silent = false;
  36378. var target = {
  36379. scaleX: symbolSize[0] / 2,
  36380. scaleY: symbolSize[1] / 2
  36381. };
  36382. disableAnimation ? symbolPath.attr(target) : updateProps(symbolPath, target, seriesModel, idx);
  36383. saveOldStyle(symbolPath);
  36384. }
  36385. this._updateCommon(data, idx, symbolSize, seriesScope, opts);
  36386. if (isInit) {
  36387. var symbolPath = this.childAt(0);
  36388. if (!disableAnimation) {
  36389. var target = {
  36390. scaleX: this._sizeX,
  36391. scaleY: this._sizeY,
  36392. style: {
  36393. // Always fadeIn. Because it has fadeOut animation when symbol is removed..
  36394. opacity: symbolPath.style.opacity
  36395. }
  36396. };
  36397. symbolPath.scaleX = symbolPath.scaleY = 0;
  36398. symbolPath.style.opacity = 0;
  36399. initProps(symbolPath, target, seriesModel, idx);
  36400. }
  36401. }
  36402. if (disableAnimation) {
  36403. // Must stop remove animation manually if don't call initProps or updateProps.
  36404. this.childAt(0).stopAnimation('remove');
  36405. }
  36406. this._seriesModel = seriesModel;
  36407. };
  36408. Symbol.prototype._updateCommon = function (data, idx, symbolSize, seriesScope, opts) {
  36409. var symbolPath = this.childAt(0);
  36410. var seriesModel = data.hostModel;
  36411. var emphasisItemStyle;
  36412. var blurItemStyle;
  36413. var selectItemStyle;
  36414. var focus;
  36415. var blurScope;
  36416. var labelStatesModels;
  36417. var hoverScale;
  36418. var cursorStyle;
  36419. if (seriesScope) {
  36420. emphasisItemStyle = seriesScope.emphasisItemStyle;
  36421. blurItemStyle = seriesScope.blurItemStyle;
  36422. selectItemStyle = seriesScope.selectItemStyle;
  36423. focus = seriesScope.focus;
  36424. blurScope = seriesScope.blurScope;
  36425. labelStatesModels = seriesScope.labelStatesModels;
  36426. hoverScale = seriesScope.hoverScale;
  36427. cursorStyle = seriesScope.cursorStyle;
  36428. }
  36429. if (!seriesScope || data.hasItemOption) {
  36430. var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx);
  36431. var emphasisModel = itemModel.getModel('emphasis');
  36432. emphasisItemStyle = emphasisModel.getModel('itemStyle').getItemStyle();
  36433. selectItemStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
  36434. blurItemStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
  36435. focus = emphasisModel.get('focus');
  36436. blurScope = emphasisModel.get('blurScope');
  36437. labelStatesModels = getLabelStatesModels(itemModel);
  36438. hoverScale = emphasisModel.getShallow('scale');
  36439. cursorStyle = itemModel.getShallow('cursor');
  36440. }
  36441. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  36442. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  36443. var symbolOffset = normalizeSymbolOffset(data.getItemVisual(idx, 'symbolOffset'), symbolSize);
  36444. if (symbolOffset) {
  36445. symbolPath.x = symbolOffset[0];
  36446. symbolPath.y = symbolOffset[1];
  36447. }
  36448. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  36449. var symbolStyle = data.getItemVisual(idx, 'style');
  36450. var visualColor = symbolStyle.fill;
  36451. if (symbolPath instanceof ZRImage) {
  36452. var pathStyle = symbolPath.style;
  36453. symbolPath.useStyle(extend({
  36454. // TODO other properties like x, y ?
  36455. image: pathStyle.image,
  36456. x: pathStyle.x,
  36457. y: pathStyle.y,
  36458. width: pathStyle.width,
  36459. height: pathStyle.height
  36460. }, symbolStyle));
  36461. } else {
  36462. if (symbolPath.__isEmptyBrush) {
  36463. // fill and stroke will be swapped if it's empty.
  36464. // So we cloned a new style to avoid it affecting the original style in visual storage.
  36465. // TODO Better implementation. No empty logic!
  36466. symbolPath.useStyle(extend({}, symbolStyle));
  36467. } else {
  36468. symbolPath.useStyle(symbolStyle);
  36469. } // Disable decal because symbol scale will been applied on the decal.
  36470. symbolPath.style.decal = null;
  36471. symbolPath.setColor(visualColor, opts && opts.symbolInnerColor);
  36472. symbolPath.style.strokeNoScale = true;
  36473. }
  36474. var liftZ = data.getItemVisual(idx, 'liftZ');
  36475. var z2Origin = this._z2;
  36476. if (liftZ != null) {
  36477. if (z2Origin == null) {
  36478. this._z2 = symbolPath.z2;
  36479. symbolPath.z2 += liftZ;
  36480. }
  36481. } else if (z2Origin != null) {
  36482. symbolPath.z2 = z2Origin;
  36483. this._z2 = null;
  36484. }
  36485. var useNameLabel = opts && opts.useNameLabel;
  36486. setLabelStyle(symbolPath, labelStatesModels, {
  36487. labelFetcher: seriesModel,
  36488. labelDataIndex: idx,
  36489. defaultText: getLabelDefaultText,
  36490. inheritColor: visualColor,
  36491. defaultOpacity: symbolStyle.opacity
  36492. }); // Do not execute util needed.
  36493. function getLabelDefaultText(idx) {
  36494. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  36495. }
  36496. this._sizeX = symbolSize[0] / 2;
  36497. this._sizeY = symbolSize[1] / 2;
  36498. var emphasisState = symbolPath.ensureState('emphasis');
  36499. emphasisState.style = emphasisItemStyle;
  36500. symbolPath.ensureState('select').style = selectItemStyle;
  36501. symbolPath.ensureState('blur').style = blurItemStyle;
  36502. if (hoverScale) {
  36503. var scaleRatio = Math.max(1.1, 3 / this._sizeY);
  36504. emphasisState.scaleX = this._sizeX * scaleRatio;
  36505. emphasisState.scaleY = this._sizeY * scaleRatio;
  36506. }
  36507. this.setSymbolScale(1);
  36508. enableHoverEmphasis(this, focus, blurScope);
  36509. };
  36510. Symbol.prototype.setSymbolScale = function (scale) {
  36511. this.scaleX = this.scaleY = scale;
  36512. };
  36513. Symbol.prototype.fadeOut = function (cb, opt) {
  36514. var symbolPath = this.childAt(0);
  36515. var seriesModel = this._seriesModel;
  36516. var dataIndex = getECData(this).dataIndex;
  36517. var animationOpt = opt && opt.animation; // Avoid mistaken hover when fading out
  36518. this.silent = symbolPath.silent = true; // Not show text when animating
  36519. if (opt && opt.fadeLabel) {
  36520. var textContent = symbolPath.getTextContent();
  36521. if (textContent) {
  36522. removeElement(textContent, {
  36523. style: {
  36524. opacity: 0
  36525. }
  36526. }, seriesModel, {
  36527. dataIndex: dataIndex,
  36528. removeOpt: animationOpt,
  36529. cb: function () {
  36530. symbolPath.removeTextContent();
  36531. }
  36532. });
  36533. }
  36534. } else {
  36535. symbolPath.removeTextContent();
  36536. }
  36537. removeElement(symbolPath, {
  36538. style: {
  36539. opacity: 0
  36540. },
  36541. scaleX: 0,
  36542. scaleY: 0
  36543. }, seriesModel, {
  36544. dataIndex: dataIndex,
  36545. cb: cb,
  36546. removeOpt: animationOpt
  36547. });
  36548. };
  36549. Symbol.getSymbolSize = function (data, idx) {
  36550. return normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  36551. };
  36552. return Symbol;
  36553. }(Group);
  36554. function driftSymbol(dx, dy) {
  36555. this.parent.drift(dx, dy);
  36556. }
  36557. function symbolNeedsDraw(data, point, idx, opt) {
  36558. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(opt.isIgnore && opt.isIgnore(idx)) // We do not set clipShape on group, because it will cut part of
  36559. // the symbol element shape. We use the same clip shape here as
  36560. // the line clip.
  36561. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1])) && data.getItemVisual(idx, 'symbol') !== 'none';
  36562. }
  36563. function normalizeUpdateOpt(opt) {
  36564. if (opt != null && !isObject(opt)) {
  36565. opt = {
  36566. isIgnore: opt
  36567. };
  36568. }
  36569. return opt || {};
  36570. }
  36571. function makeSeriesScope(data) {
  36572. var seriesModel = data.hostModel;
  36573. var emphasisModel = seriesModel.getModel('emphasis');
  36574. return {
  36575. emphasisItemStyle: emphasisModel.getModel('itemStyle').getItemStyle(),
  36576. blurItemStyle: seriesModel.getModel(['blur', 'itemStyle']).getItemStyle(),
  36577. selectItemStyle: seriesModel.getModel(['select', 'itemStyle']).getItemStyle(),
  36578. focus: emphasisModel.get('focus'),
  36579. blurScope: emphasisModel.get('blurScope'),
  36580. hoverScale: emphasisModel.get('scale'),
  36581. labelStatesModels: getLabelStatesModels(seriesModel),
  36582. cursorStyle: seriesModel.get('cursor')
  36583. };
  36584. }
  36585. var SymbolDraw =
  36586. /** @class */
  36587. function () {
  36588. function SymbolDraw(SymbolCtor) {
  36589. this.group = new Group();
  36590. this._SymbolCtor = SymbolCtor || Symbol;
  36591. }
  36592. /**
  36593. * Update symbols draw by new data
  36594. */
  36595. SymbolDraw.prototype.updateData = function (data, opt) {
  36596. opt = normalizeUpdateOpt(opt);
  36597. var group = this.group;
  36598. var seriesModel = data.hostModel;
  36599. var oldData = this._data;
  36600. var SymbolCtor = this._SymbolCtor;
  36601. var disableAnimation = opt.disableAnimation;
  36602. var seriesScope = makeSeriesScope(data);
  36603. var symbolUpdateOpt = {
  36604. disableAnimation: disableAnimation
  36605. };
  36606. var getSymbolPoint = opt.getSymbolPoint || function (idx) {
  36607. return data.getItemLayout(idx);
  36608. }; // There is no oldLineData only when first rendering or switching from
  36609. // stream mode to normal mode, where previous elements should be removed.
  36610. if (!oldData) {
  36611. group.removeAll();
  36612. }
  36613. data.diff(oldData).add(function (newIdx) {
  36614. var point = getSymbolPoint(newIdx);
  36615. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  36616. var symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  36617. symbolEl.setPosition(point);
  36618. data.setItemGraphicEl(newIdx, symbolEl);
  36619. group.add(symbolEl);
  36620. }
  36621. }).update(function (newIdx, oldIdx) {
  36622. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  36623. var point = getSymbolPoint(newIdx);
  36624. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  36625. group.remove(symbolEl);
  36626. return;
  36627. }
  36628. var newSymbolType = data.getItemVisual(newIdx, 'symbol') || 'circle';
  36629. var oldSymbolType = symbolEl && symbolEl.getSymbolType && symbolEl.getSymbolType();
  36630. if (!symbolEl // Create a new if symbol type changed.
  36631. || oldSymbolType && oldSymbolType !== newSymbolType) {
  36632. group.remove(symbolEl);
  36633. symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  36634. symbolEl.setPosition(point);
  36635. } else {
  36636. symbolEl.updateData(data, newIdx, seriesScope, symbolUpdateOpt);
  36637. var target = {
  36638. x: point[0],
  36639. y: point[1]
  36640. };
  36641. disableAnimation ? symbolEl.attr(target) : updateProps(symbolEl, target, seriesModel);
  36642. } // Add back
  36643. group.add(symbolEl);
  36644. data.setItemGraphicEl(newIdx, symbolEl);
  36645. }).remove(function (oldIdx) {
  36646. var el = oldData.getItemGraphicEl(oldIdx);
  36647. el && el.fadeOut(function () {
  36648. group.remove(el);
  36649. });
  36650. }).execute();
  36651. this._getSymbolPoint = getSymbolPoint;
  36652. this._data = data;
  36653. };
  36654. SymbolDraw.prototype.isPersistent = function () {
  36655. return true;
  36656. };
  36657. SymbolDraw.prototype.updateLayout = function () {
  36658. var _this = this;
  36659. var data = this._data;
  36660. if (data) {
  36661. // Not use animation
  36662. data.eachItemGraphicEl(function (el, idx) {
  36663. var point = _this._getSymbolPoint(idx);
  36664. el.setPosition(point);
  36665. el.markRedraw();
  36666. });
  36667. }
  36668. };
  36669. SymbolDraw.prototype.incrementalPrepareUpdate = function (data) {
  36670. this._seriesScope = makeSeriesScope(data);
  36671. this._data = null;
  36672. this.group.removeAll();
  36673. };
  36674. /**
  36675. * Update symbols draw by new data
  36676. */
  36677. SymbolDraw.prototype.incrementalUpdate = function (taskParams, data, opt) {
  36678. opt = normalizeUpdateOpt(opt);
  36679. function updateIncrementalAndHover(el) {
  36680. if (!el.isGroup) {
  36681. el.incremental = true;
  36682. el.ensureState('emphasis').hoverLayer = true;
  36683. }
  36684. }
  36685. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  36686. var point = data.getItemLayout(idx);
  36687. if (symbolNeedsDraw(data, point, idx, opt)) {
  36688. var el = new this._SymbolCtor(data, idx, this._seriesScope);
  36689. el.traverse(updateIncrementalAndHover);
  36690. el.setPosition(point);
  36691. this.group.add(el);
  36692. data.setItemGraphicEl(idx, el);
  36693. }
  36694. }
  36695. };
  36696. SymbolDraw.prototype.remove = function (enableAnimation) {
  36697. var group = this.group;
  36698. var data = this._data; // Incremental model do not have this._data.
  36699. if (data && enableAnimation) {
  36700. data.eachItemGraphicEl(function (el) {
  36701. el.fadeOut(function () {
  36702. group.remove(el);
  36703. });
  36704. });
  36705. } else {
  36706. group.removeAll();
  36707. }
  36708. };
  36709. return SymbolDraw;
  36710. }();
  36711. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  36712. var baseAxis = coordSys.getBaseAxis();
  36713. var valueAxis = coordSys.getOtherAxis(baseAxis);
  36714. var valueStart = getValueStart(valueAxis, valueOrigin);
  36715. var baseAxisDim = baseAxis.dim;
  36716. var valueAxisDim = valueAxis.dim;
  36717. var valueDim = data.mapDimension(valueAxisDim);
  36718. var baseDim = data.mapDimension(baseAxisDim);
  36719. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  36720. var dims = map(coordSys.dimensions, function (coordDim) {
  36721. return data.mapDimension(coordDim);
  36722. });
  36723. var stacked = false;
  36724. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  36725. if (isDimensionStacked(data, dims[0]
  36726. /*, dims[1]*/
  36727. )) {
  36728. // jshint ignore:line
  36729. stacked = true;
  36730. dims[0] = stackResultDim;
  36731. }
  36732. if (isDimensionStacked(data, dims[1]
  36733. /*, dims[0]*/
  36734. )) {
  36735. // jshint ignore:line
  36736. stacked = true;
  36737. dims[1] = stackResultDim;
  36738. }
  36739. return {
  36740. dataDimsForPoint: dims,
  36741. valueStart: valueStart,
  36742. valueAxisDim: valueAxisDim,
  36743. baseAxisDim: baseAxisDim,
  36744. stacked: !!stacked,
  36745. valueDim: valueDim,
  36746. baseDim: baseDim,
  36747. baseDataOffset: baseDataOffset,
  36748. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  36749. };
  36750. }
  36751. function getValueStart(valueAxis, valueOrigin) {
  36752. var valueStart = 0;
  36753. var extent = valueAxis.scale.getExtent();
  36754. if (valueOrigin === 'start') {
  36755. valueStart = extent[0];
  36756. } else if (valueOrigin === 'end') {
  36757. valueStart = extent[1];
  36758. } // auto
  36759. else {
  36760. // Both positive
  36761. if (extent[0] > 0) {
  36762. valueStart = extent[0];
  36763. } // Both negative
  36764. else if (extent[1] < 0) {
  36765. valueStart = extent[1];
  36766. } // If is one positive, and one negative, onZero shall be true
  36767. }
  36768. return valueStart;
  36769. }
  36770. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  36771. var value = NaN;
  36772. if (dataCoordInfo.stacked) {
  36773. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  36774. }
  36775. if (isNaN(value)) {
  36776. value = dataCoordInfo.valueStart;
  36777. }
  36778. var baseDataOffset = dataCoordInfo.baseDataOffset;
  36779. var stackedData = [];
  36780. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  36781. stackedData[1 - baseDataOffset] = value;
  36782. return coordSys.dataToPoint(stackedData);
  36783. }
  36784. /* global Float32Array */
  36785. var supportFloat32Array = typeof Float32Array !== 'undefined';
  36786. var Float32ArrayCtor = !supportFloat32Array ? Array : Float32Array;
  36787. function createFloat32Array(arg) {
  36788. if (isArray(arg)) {
  36789. // Return self directly if don't support TypedArray.
  36790. return supportFloat32Array ? new Float32Array(arg) : arg;
  36791. } // Else is number
  36792. return new Float32ArrayCtor(arg);
  36793. }
  36794. function diffData(oldData, newData) {
  36795. var diffResult = [];
  36796. newData.diff(oldData).add(function (idx) {
  36797. diffResult.push({
  36798. cmd: '+',
  36799. idx: idx
  36800. });
  36801. }).update(function (newIdx, oldIdx) {
  36802. diffResult.push({
  36803. cmd: '=',
  36804. idx: oldIdx,
  36805. idx1: newIdx
  36806. });
  36807. }).remove(function (idx) {
  36808. diffResult.push({
  36809. cmd: '-',
  36810. idx: idx
  36811. });
  36812. }).execute();
  36813. return diffResult;
  36814. }
  36815. function lineAnimationDiff(oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  36816. var diff = diffData(oldData, newData); // let newIdList = newData.mapArray(newData.getId);
  36817. // let oldIdList = oldData.mapArray(oldData.getId);
  36818. // convertToIntId(newIdList, oldIdList);
  36819. // // FIXME One data ?
  36820. // diff = arrayDiff(oldIdList, newIdList);
  36821. var currPoints = [];
  36822. var nextPoints = []; // Points for stacking base line
  36823. var currStackedPoints = [];
  36824. var nextStackedPoints = [];
  36825. var status = [];
  36826. var sortedIndices = [];
  36827. var rawIndices = [];
  36828. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin); // const oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  36829. var oldPoints = oldData.getLayout('points') || [];
  36830. var newPoints = newData.getLayout('points') || [];
  36831. for (var i = 0; i < diff.length; i++) {
  36832. var diffItem = diff[i];
  36833. var pointAdded = true;
  36834. var oldIdx2 = void 0;
  36835. var newIdx2 = void 0; // FIXME, animation is not so perfect when dataZoom window moves fast
  36836. // Which is in case remvoing or add more than one data in the tail or head
  36837. switch (diffItem.cmd) {
  36838. case '=':
  36839. oldIdx2 = diffItem.idx * 2;
  36840. newIdx2 = diffItem.idx1 * 2;
  36841. var currentX = oldPoints[oldIdx2];
  36842. var currentY = oldPoints[oldIdx2 + 1];
  36843. var nextX = newPoints[newIdx2];
  36844. var nextY = newPoints[newIdx2 + 1]; // If previous data is NaN, use next point directly
  36845. if (isNaN(currentX) || isNaN(currentY)) {
  36846. currentX = nextX;
  36847. currentY = nextY;
  36848. }
  36849. currPoints.push(currentX, currentY);
  36850. nextPoints.push(nextX, nextY);
  36851. currStackedPoints.push(oldStackedOnPoints[oldIdx2], oldStackedOnPoints[oldIdx2 + 1]);
  36852. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  36853. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  36854. break;
  36855. case '+':
  36856. var newIdx = diffItem.idx;
  36857. var newDataDimsForPoint = newDataOldCoordInfo.dataDimsForPoint;
  36858. var oldPt = oldCoordSys.dataToPoint([newData.get(newDataDimsForPoint[0], newIdx), newData.get(newDataDimsForPoint[1], newIdx)]);
  36859. newIdx2 = newIdx * 2;
  36860. currPoints.push(oldPt[0], oldPt[1]);
  36861. nextPoints.push(newPoints[newIdx2], newPoints[newIdx2 + 1]);
  36862. var stackedOnPoint = getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, newIdx);
  36863. currStackedPoints.push(stackedOnPoint[0], stackedOnPoint[1]);
  36864. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  36865. rawIndices.push(newData.getRawIndex(newIdx));
  36866. break;
  36867. case '-':
  36868. pointAdded = false;
  36869. } // Original indices
  36870. if (pointAdded) {
  36871. status.push(diffItem);
  36872. sortedIndices.push(sortedIndices.length);
  36873. }
  36874. } // Diff result may be crossed if all items are changed
  36875. // Sort by data index
  36876. sortedIndices.sort(function (a, b) {
  36877. return rawIndices[a] - rawIndices[b];
  36878. });
  36879. var len = currPoints.length;
  36880. var sortedCurrPoints = createFloat32Array(len);
  36881. var sortedNextPoints = createFloat32Array(len);
  36882. var sortedCurrStackedPoints = createFloat32Array(len);
  36883. var sortedNextStackedPoints = createFloat32Array(len);
  36884. var sortedStatus = [];
  36885. for (var i = 0; i < sortedIndices.length; i++) {
  36886. var idx = sortedIndices[i];
  36887. var i2 = i * 2;
  36888. var idx2 = idx * 2;
  36889. sortedCurrPoints[i2] = currPoints[idx2];
  36890. sortedCurrPoints[i2 + 1] = currPoints[idx2 + 1];
  36891. sortedNextPoints[i2] = nextPoints[idx2];
  36892. sortedNextPoints[i2 + 1] = nextPoints[idx2 + 1];
  36893. sortedCurrStackedPoints[i2] = currStackedPoints[idx2];
  36894. sortedCurrStackedPoints[i2 + 1] = currStackedPoints[idx2 + 1];
  36895. sortedNextStackedPoints[i2] = nextStackedPoints[idx2];
  36896. sortedNextStackedPoints[i2 + 1] = nextStackedPoints[idx2 + 1];
  36897. sortedStatus[i] = status[idx];
  36898. }
  36899. return {
  36900. current: sortedCurrPoints,
  36901. next: sortedNextPoints,
  36902. stackedOnCurrent: sortedCurrStackedPoints,
  36903. stackedOnNext: sortedNextStackedPoints,
  36904. status: sortedStatus
  36905. };
  36906. }
  36907. var mathMin$5 = Math.min;
  36908. var mathMax$5 = Math.max;
  36909. function isPointNull(x, y) {
  36910. return isNaN(x) || isNaN(y);
  36911. }
  36912. /**
  36913. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  36914. * situations. This should be used when points are non-monotone neither in x or
  36915. * y dimension.
  36916. */
  36917. function drawSegment(ctx, points, start, segLen, allLen, dir, smooth, smoothMonotone, connectNulls) {
  36918. var prevX;
  36919. var prevY;
  36920. var cpx0;
  36921. var cpy0;
  36922. var cpx1;
  36923. var cpy1;
  36924. var idx = start;
  36925. var k = 0;
  36926. for (; k < segLen; k++) {
  36927. var x = points[idx * 2];
  36928. var y = points[idx * 2 + 1];
  36929. if (idx >= allLen || idx < 0) {
  36930. break;
  36931. }
  36932. if (isPointNull(x, y)) {
  36933. if (connectNulls) {
  36934. idx += dir;
  36935. continue;
  36936. }
  36937. break;
  36938. }
  36939. if (idx === start) {
  36940. ctx[dir > 0 ? 'moveTo' : 'lineTo'](x, y);
  36941. cpx0 = x;
  36942. cpy0 = y;
  36943. } else {
  36944. var dx = x - prevX;
  36945. var dy = y - prevY; // Ignore tiny segment.
  36946. if (dx * dx + dy * dy < 0.5) {
  36947. idx += dir;
  36948. continue;
  36949. }
  36950. if (smooth > 0) {
  36951. var nextIdx = idx + dir;
  36952. var nextX = points[nextIdx * 2];
  36953. var nextY = points[nextIdx * 2 + 1]; // Ignore duplicate point
  36954. while (nextX === x && nextY === y && k < segLen) {
  36955. k++;
  36956. nextIdx += dir;
  36957. idx += dir;
  36958. nextX = points[nextIdx * 2];
  36959. nextY = points[nextIdx * 2 + 1];
  36960. x = points[idx * 2];
  36961. y = points[idx * 2 + 1];
  36962. dx = x - prevX;
  36963. dy = y - prevY;
  36964. }
  36965. var tmpK = k + 1;
  36966. if (connectNulls) {
  36967. // Find next point not null
  36968. while (isPointNull(nextX, nextY) && tmpK < segLen) {
  36969. tmpK++;
  36970. nextIdx += dir;
  36971. nextX = points[nextIdx * 2];
  36972. nextY = points[nextIdx * 2 + 1];
  36973. }
  36974. }
  36975. var ratioNextSeg = 0.5;
  36976. var vx = 0;
  36977. var vy = 0;
  36978. var nextCpx0 = void 0;
  36979. var nextCpy0 = void 0; // Is last point
  36980. if (tmpK >= segLen || isPointNull(nextX, nextY)) {
  36981. cpx1 = x;
  36982. cpy1 = y;
  36983. } else {
  36984. vx = nextX - prevX;
  36985. vy = nextY - prevY;
  36986. var dx0 = x - prevX;
  36987. var dx1 = nextX - x;
  36988. var dy0 = y - prevY;
  36989. var dy1 = nextY - y;
  36990. var lenPrevSeg = void 0;
  36991. var lenNextSeg = void 0;
  36992. if (smoothMonotone === 'x') {
  36993. lenPrevSeg = Math.abs(dx0);
  36994. lenNextSeg = Math.abs(dx1);
  36995. cpx1 = x - lenPrevSeg * smooth;
  36996. cpy1 = y;
  36997. nextCpx0 = x + lenPrevSeg * smooth;
  36998. nextCpy0 = y;
  36999. } else if (smoothMonotone === 'y') {
  37000. lenPrevSeg = Math.abs(dy0);
  37001. lenNextSeg = Math.abs(dy1);
  37002. cpx1 = x;
  37003. cpy1 = y - lenPrevSeg * smooth;
  37004. nextCpx0 = x;
  37005. nextCpy0 = y + lenPrevSeg * smooth;
  37006. } else {
  37007. lenPrevSeg = Math.sqrt(dx0 * dx0 + dy0 * dy0);
  37008. lenNextSeg = Math.sqrt(dx1 * dx1 + dy1 * dy1); // Use ratio of seg length
  37009. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  37010. cpx1 = x - vx * smooth * (1 - ratioNextSeg);
  37011. cpy1 = y - vy * smooth * (1 - ratioNextSeg); // cp0 of next segment
  37012. nextCpx0 = x + vx * smooth * ratioNextSeg;
  37013. nextCpy0 = y + vy * smooth * ratioNextSeg; // Smooth constraint between point and next point.
  37014. // Avoid exceeding extreme after smoothing.
  37015. nextCpx0 = mathMin$5(nextCpx0, mathMax$5(nextX, x));
  37016. nextCpy0 = mathMin$5(nextCpy0, mathMax$5(nextY, y));
  37017. nextCpx0 = mathMax$5(nextCpx0, mathMin$5(nextX, x));
  37018. nextCpy0 = mathMax$5(nextCpy0, mathMin$5(nextY, y)); // Reclaculate cp1 based on the adjusted cp0 of next seg.
  37019. vx = nextCpx0 - x;
  37020. vy = nextCpy0 - y;
  37021. cpx1 = x - vx * lenPrevSeg / lenNextSeg;
  37022. cpy1 = y - vy * lenPrevSeg / lenNextSeg; // Smooth constraint between point and prev point.
  37023. // Avoid exceeding extreme after smoothing.
  37024. cpx1 = mathMin$5(cpx1, mathMax$5(prevX, x));
  37025. cpy1 = mathMin$5(cpy1, mathMax$5(prevY, y));
  37026. cpx1 = mathMax$5(cpx1, mathMin$5(prevX, x));
  37027. cpy1 = mathMax$5(cpy1, mathMin$5(prevY, y)); // Adjust next cp0 again.
  37028. vx = x - cpx1;
  37029. vy = y - cpy1;
  37030. nextCpx0 = x + vx * lenNextSeg / lenPrevSeg;
  37031. nextCpy0 = y + vy * lenNextSeg / lenPrevSeg;
  37032. }
  37033. }
  37034. ctx.bezierCurveTo(cpx0, cpy0, cpx1, cpy1, x, y);
  37035. cpx0 = nextCpx0;
  37036. cpy0 = nextCpy0;
  37037. } else {
  37038. ctx.lineTo(x, y);
  37039. }
  37040. }
  37041. prevX = x;
  37042. prevY = y;
  37043. idx += dir;
  37044. }
  37045. return k;
  37046. }
  37047. var ECPolylineShape =
  37048. /** @class */
  37049. function () {
  37050. function ECPolylineShape() {
  37051. this.smooth = 0;
  37052. this.smoothConstraint = true;
  37053. }
  37054. return ECPolylineShape;
  37055. }();
  37056. var ECPolyline =
  37057. /** @class */
  37058. function (_super) {
  37059. __extends(ECPolyline, _super);
  37060. function ECPolyline(opts) {
  37061. var _this = _super.call(this, opts) || this;
  37062. _this.type = 'ec-polyline';
  37063. return _this;
  37064. }
  37065. ECPolyline.prototype.getDefaultStyle = function () {
  37066. return {
  37067. stroke: '#000',
  37068. fill: null
  37069. };
  37070. };
  37071. ECPolyline.prototype.getDefaultShape = function () {
  37072. return new ECPolylineShape();
  37073. };
  37074. ECPolyline.prototype.buildPath = function (ctx, shape) {
  37075. var points = shape.points;
  37076. var i = 0;
  37077. var len = points.length / 2; // const result = getBoundingBox(points, shape.smoothConstraint);
  37078. if (shape.connectNulls) {
  37079. // Must remove first and last null values avoid draw error in polygon
  37080. for (; len > 0; len--) {
  37081. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  37082. break;
  37083. }
  37084. }
  37085. for (; i < len; i++) {
  37086. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  37087. break;
  37088. }
  37089. }
  37090. }
  37091. while (i < len) {
  37092. i += drawSegment(ctx, points, i, len, len, 1, shape.smooth, shape.smoothMonotone, shape.connectNulls) + 1;
  37093. }
  37094. };
  37095. ECPolyline.prototype.getPointOn = function (xOrY, dim) {
  37096. if (!this.path) {
  37097. this.createPathProxy();
  37098. this.buildPath(this.path, this.shape);
  37099. }
  37100. var path = this.path;
  37101. var data = path.data;
  37102. var CMD = PathProxy.CMD;
  37103. var x0;
  37104. var y0;
  37105. var isDimX = dim === 'x';
  37106. var roots = [];
  37107. for (var i = 0; i < data.length;) {
  37108. var cmd = data[i++];
  37109. var x = void 0;
  37110. var y = void 0;
  37111. var x2 = void 0;
  37112. var y2 = void 0;
  37113. var x3 = void 0;
  37114. var y3 = void 0;
  37115. var t = void 0;
  37116. switch (cmd) {
  37117. case CMD.M:
  37118. x0 = data[i++];
  37119. y0 = data[i++];
  37120. break;
  37121. case CMD.L:
  37122. x = data[i++];
  37123. y = data[i++];
  37124. t = isDimX ? (xOrY - x0) / (x - x0) : (xOrY - y0) / (y - y0);
  37125. if (t <= 1 && t >= 0) {
  37126. var val = isDimX ? (y - y0) * t + y0 : (x - x0) * t + x0;
  37127. return isDimX ? [xOrY, val] : [val, xOrY];
  37128. }
  37129. x0 = x;
  37130. y0 = y;
  37131. break;
  37132. case CMD.C:
  37133. x = data[i++];
  37134. y = data[i++];
  37135. x2 = data[i++];
  37136. y2 = data[i++];
  37137. x3 = data[i++];
  37138. y3 = data[i++];
  37139. var nRoot = isDimX ? cubicRootAt(x0, x, x2, x3, xOrY, roots) : cubicRootAt(y0, y, y2, y3, xOrY, roots);
  37140. if (nRoot > 0) {
  37141. for (var i_1 = 0; i_1 < nRoot; i_1++) {
  37142. var t_1 = roots[i_1];
  37143. if (t_1 <= 1 && t_1 >= 0) {
  37144. var val = isDimX ? cubicAt(y0, y, y2, y3, t_1) : cubicAt(x0, x, x2, x3, t_1);
  37145. return isDimX ? [xOrY, val] : [val, xOrY];
  37146. }
  37147. }
  37148. }
  37149. x0 = x3;
  37150. y0 = y3;
  37151. break;
  37152. }
  37153. }
  37154. };
  37155. return ECPolyline;
  37156. }(Path);
  37157. var ECPolygonShape =
  37158. /** @class */
  37159. function (_super) {
  37160. __extends(ECPolygonShape, _super);
  37161. function ECPolygonShape() {
  37162. return _super !== null && _super.apply(this, arguments) || this;
  37163. }
  37164. return ECPolygonShape;
  37165. }(ECPolylineShape);
  37166. var ECPolygon =
  37167. /** @class */
  37168. function (_super) {
  37169. __extends(ECPolygon, _super);
  37170. function ECPolygon(opts) {
  37171. var _this = _super.call(this, opts) || this;
  37172. _this.type = 'ec-polygon';
  37173. return _this;
  37174. }
  37175. ECPolygon.prototype.getDefaultShape = function () {
  37176. return new ECPolygonShape();
  37177. };
  37178. ECPolygon.prototype.buildPath = function (ctx, shape) {
  37179. var points = shape.points;
  37180. var stackedOnPoints = shape.stackedOnPoints;
  37181. var i = 0;
  37182. var len = points.length / 2;
  37183. var smoothMonotone = shape.smoothMonotone;
  37184. if (shape.connectNulls) {
  37185. // Must remove first and last null values avoid draw error in polygon
  37186. for (; len > 0; len--) {
  37187. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  37188. break;
  37189. }
  37190. }
  37191. for (; i < len; i++) {
  37192. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  37193. break;
  37194. }
  37195. }
  37196. }
  37197. while (i < len) {
  37198. var k = drawSegment(ctx, points, i, len, len, 1, shape.smooth, smoothMonotone, shape.connectNulls);
  37199. drawSegment(ctx, stackedOnPoints, i + k - 1, k, len, -1, shape.stackedOnSmooth, smoothMonotone, shape.connectNulls);
  37200. i += k + 1;
  37201. ctx.closePath();
  37202. }
  37203. };
  37204. return ECPolygon;
  37205. }(Path);
  37206. function createGridClipPath(cartesian, hasAnimation, seriesModel, done, during) {
  37207. var rect = cartesian.getArea();
  37208. var x = rect.x;
  37209. var y = rect.y;
  37210. var width = rect.width;
  37211. var height = rect.height;
  37212. var lineWidth = seriesModel.get(['lineStyle', 'width']) || 2; // Expand the clip path a bit to avoid the border is clipped and looks thinner
  37213. x -= lineWidth / 2;
  37214. y -= lineWidth / 2;
  37215. width += lineWidth;
  37216. height += lineWidth; // fix: https://github.com/apache/incubator-echarts/issues/11369
  37217. x = Math.floor(x);
  37218. width = Math.round(width);
  37219. var clipPath = new Rect({
  37220. shape: {
  37221. x: x,
  37222. y: y,
  37223. width: width,
  37224. height: height
  37225. }
  37226. });
  37227. if (hasAnimation) {
  37228. var baseAxis = cartesian.getBaseAxis();
  37229. var isHorizontal = baseAxis.isHorizontal();
  37230. var isAxisInversed = baseAxis.inverse;
  37231. if (isHorizontal) {
  37232. if (isAxisInversed) {
  37233. clipPath.shape.x += width;
  37234. }
  37235. clipPath.shape.width = 0;
  37236. } else {
  37237. if (!isAxisInversed) {
  37238. clipPath.shape.y += height;
  37239. }
  37240. clipPath.shape.height = 0;
  37241. }
  37242. var duringCb = typeof during === 'function' ? function (percent) {
  37243. during(percent, clipPath);
  37244. } : null;
  37245. initProps(clipPath, {
  37246. shape: {
  37247. width: width,
  37248. height: height,
  37249. x: x,
  37250. y: y
  37251. }
  37252. }, seriesModel, null, done, duringCb);
  37253. }
  37254. return clipPath;
  37255. }
  37256. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  37257. var sectorArea = polar.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  37258. var r0 = round(sectorArea.r0, 1);
  37259. var r = round(sectorArea.r, 1);
  37260. var clipPath = new Sector({
  37261. shape: {
  37262. cx: round(polar.cx, 1),
  37263. cy: round(polar.cy, 1),
  37264. r0: r0,
  37265. r: r,
  37266. startAngle: sectorArea.startAngle,
  37267. endAngle: sectorArea.endAngle,
  37268. clockwise: sectorArea.clockwise
  37269. }
  37270. });
  37271. if (hasAnimation) {
  37272. var isRadial = polar.getBaseAxis().dim === 'angle';
  37273. if (isRadial) {
  37274. clipPath.shape.endAngle = sectorArea.startAngle;
  37275. } else {
  37276. clipPath.shape.r = r0;
  37277. }
  37278. initProps(clipPath, {
  37279. shape: {
  37280. endAngle: sectorArea.endAngle,
  37281. r: r
  37282. }
  37283. }, seriesModel);
  37284. }
  37285. return clipPath;
  37286. }
  37287. function createClipPath(coordSys, hasAnimation, seriesModel, done, during) {
  37288. if (!coordSys) {
  37289. return null;
  37290. } else if (coordSys.type === 'polar') {
  37291. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  37292. } else if (coordSys.type === 'cartesian2d') {
  37293. return createGridClipPath(coordSys, hasAnimation, seriesModel, done, during);
  37294. }
  37295. return null;
  37296. }
  37297. /*
  37298. * Licensed to the Apache Software Foundation (ASF) under one
  37299. * or more contributor license agreements. See the NOTICE file
  37300. * distributed with this work for additional information
  37301. * regarding copyright ownership. The ASF licenses this file
  37302. * to you under the Apache License, Version 2.0 (the
  37303. * "License"); you may not use this file except in compliance
  37304. * with the License. You may obtain a copy of the License at
  37305. *
  37306. * http://www.apache.org/licenses/LICENSE-2.0
  37307. *
  37308. * Unless required by applicable law or agreed to in writing,
  37309. * software distributed under the License is distributed on an
  37310. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37311. * KIND, either express or implied. See the License for the
  37312. * specific language governing permissions and limitations
  37313. * under the License.
  37314. */
  37315. /**
  37316. * AUTO-GENERATED FILE. DO NOT MODIFY.
  37317. */
  37318. /*
  37319. * Licensed to the Apache Software Foundation (ASF) under one
  37320. * or more contributor license agreements. See the NOTICE file
  37321. * distributed with this work for additional information
  37322. * regarding copyright ownership. The ASF licenses this file
  37323. * to you under the Apache License, Version 2.0 (the
  37324. * "License"); you may not use this file except in compliance
  37325. * with the License. You may obtain a copy of the License at
  37326. *
  37327. * http://www.apache.org/licenses/LICENSE-2.0
  37328. *
  37329. * Unless required by applicable law or agreed to in writing,
  37330. * software distributed under the License is distributed on an
  37331. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37332. * KIND, either express or implied. See the License for the
  37333. * specific language governing permissions and limitations
  37334. * under the License.
  37335. */
  37336. function isCoordinateSystemType(coordSys, type) {
  37337. return coordSys.type === type;
  37338. }
  37339. function isPointsSame(points1, points2) {
  37340. if (points1.length !== points2.length) {
  37341. return;
  37342. }
  37343. for (var i = 0; i < points1.length; i++) {
  37344. if (points1[i] !== points2[i]) {
  37345. return;
  37346. }
  37347. }
  37348. return true;
  37349. }
  37350. function bboxFromPoints(points) {
  37351. var minX = Infinity;
  37352. var minY = Infinity;
  37353. var maxX = -Infinity;
  37354. var maxY = -Infinity;
  37355. for (var i = 0; i < points.length;) {
  37356. var x = points[i++];
  37357. var y = points[i++];
  37358. if (!isNaN(x)) {
  37359. minX = Math.min(x, minX);
  37360. maxX = Math.max(x, maxX);
  37361. }
  37362. if (!isNaN(y)) {
  37363. minY = Math.min(y, minY);
  37364. maxY = Math.max(y, maxY);
  37365. }
  37366. }
  37367. return [[minX, minY], [maxX, maxY]];
  37368. }
  37369. function getBoundingDiff(points1, points2) {
  37370. var _a = bboxFromPoints(points1),
  37371. min1 = _a[0],
  37372. max1 = _a[1];
  37373. var _b = bboxFromPoints(points2),
  37374. min2 = _b[0],
  37375. max2 = _b[1]; // Get a max value from each corner of two boundings.
  37376. 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]));
  37377. }
  37378. function getSmooth(smooth) {
  37379. return typeof smooth === 'number' ? smooth : smooth ? 0.5 : 0;
  37380. }
  37381. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  37382. if (!dataCoordInfo.valueDim) {
  37383. return [];
  37384. }
  37385. var len = data.count();
  37386. var points = createFloat32Array(len * 2);
  37387. for (var idx = 0; idx < len; idx++) {
  37388. var pt = getStackedOnPoint(dataCoordInfo, coordSys, data, idx);
  37389. points[idx * 2] = pt[0];
  37390. points[idx * 2 + 1] = pt[1];
  37391. }
  37392. return points;
  37393. }
  37394. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  37395. var baseAxis = coordSys.getBaseAxis();
  37396. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  37397. var stepPoints = [];
  37398. var i = 0;
  37399. var stepPt = [];
  37400. var pt = [];
  37401. var nextPt = [];
  37402. for (; i < points.length - 2; i += 2) {
  37403. nextPt[0] = points[i + 2];
  37404. nextPt[1] = points[i + 3];
  37405. pt[0] = points[i];
  37406. pt[1] = points[i + 1];
  37407. stepPoints.push(pt[0], pt[1]);
  37408. switch (stepTurnAt) {
  37409. case 'end':
  37410. stepPt[baseIndex] = nextPt[baseIndex];
  37411. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  37412. stepPoints.push(stepPt[0], stepPt[1]);
  37413. break;
  37414. case 'middle':
  37415. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  37416. var stepPt2 = [];
  37417. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  37418. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  37419. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  37420. stepPoints.push(stepPt[0], stepPt[1]);
  37421. stepPoints.push(stepPt2[0], stepPt2[1]);
  37422. break;
  37423. default:
  37424. // default is start
  37425. stepPt[baseIndex] = pt[baseIndex];
  37426. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  37427. stepPoints.push(stepPt[0], stepPt[1]);
  37428. }
  37429. } // Last points
  37430. stepPoints.push(points[i++], points[i++]);
  37431. return stepPoints;
  37432. }
  37433. /**
  37434. * Clip color stops to edge. Avoid creating too large gradients.
  37435. * Which may lead to blurry when GPU acceleration is enabled. See #15680
  37436. *
  37437. * The stops has been sorted from small to large.
  37438. */
  37439. function clipColorStops(colorStops, maxSize) {
  37440. var newColorStops = [];
  37441. var len = colorStops.length; // coord will always < 0 in prevOutOfRangeColorStop.
  37442. var prevOutOfRangeColorStop;
  37443. var prevInRangeColorStop;
  37444. function lerpStop(stop0, stop1, clippedCoord) {
  37445. var coord0 = stop0.coord;
  37446. var p = (clippedCoord - coord0) / (stop1.coord - coord0);
  37447. var color = lerp$1(p, [stop0.color, stop1.color]);
  37448. return {
  37449. coord: clippedCoord,
  37450. color: color
  37451. };
  37452. }
  37453. for (var i = 0; i < len; i++) {
  37454. var stop_1 = colorStops[i];
  37455. var coord = stop_1.coord;
  37456. if (coord < 0) {
  37457. prevOutOfRangeColorStop = stop_1;
  37458. } else if (coord > maxSize) {
  37459. if (prevInRangeColorStop) {
  37460. newColorStops.push(lerpStop(prevInRangeColorStop, stop_1, maxSize));
  37461. } else if (prevOutOfRangeColorStop) {
  37462. // If there are two stops and coord range is between these two stops
  37463. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0), lerpStop(prevOutOfRangeColorStop, stop_1, maxSize));
  37464. } // All following stop will be out of range. So just ignore them.
  37465. break;
  37466. } else {
  37467. if (prevOutOfRangeColorStop) {
  37468. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0)); // Reset
  37469. prevOutOfRangeColorStop = null;
  37470. }
  37471. newColorStops.push(stop_1);
  37472. prevInRangeColorStop = stop_1;
  37473. }
  37474. }
  37475. return newColorStops;
  37476. }
  37477. function getVisualGradient(data, coordSys, api) {
  37478. var visualMetaList = data.getVisual('visualMeta');
  37479. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  37480. // When data.count() is 0, gradient range can not be calculated.
  37481. return;
  37482. }
  37483. if (coordSys.type !== 'cartesian2d') {
  37484. if ("development" !== 'production') {
  37485. console.warn('Visual map on line style is only supported on cartesian2d.');
  37486. }
  37487. return;
  37488. }
  37489. var coordDim;
  37490. var visualMeta;
  37491. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  37492. var dimInfo = data.getDimensionInfo(visualMetaList[i].dimension);
  37493. coordDim = dimInfo && dimInfo.coordDim; // Can only be x or y
  37494. if (coordDim === 'x' || coordDim === 'y') {
  37495. visualMeta = visualMetaList[i];
  37496. break;
  37497. }
  37498. }
  37499. if (!visualMeta) {
  37500. if ("development" !== 'production') {
  37501. console.warn('Visual map on line style only support x or y dimension.');
  37502. }
  37503. return;
  37504. } // If the area to be rendered is bigger than area defined by LinearGradient,
  37505. // the canvas spec prescribes that the color of the first stop and the last
  37506. // stop should be used. But if two stops are added at offset 0, in effect
  37507. // browsers use the color of the second stop to render area outside
  37508. // LinearGradient. So we can only infinitesimally extend area defined in
  37509. // LinearGradient to render `outerColors`.
  37510. var axis = coordSys.getAxis(coordDim); // dataToCoord mapping may not be linear, but must be monotonic.
  37511. var colorStops = map(visualMeta.stops, function (stop) {
  37512. // offset will be calculated later.
  37513. return {
  37514. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  37515. color: stop.color
  37516. };
  37517. });
  37518. var stopLen = colorStops.length;
  37519. var outerColors = visualMeta.outerColors.slice();
  37520. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  37521. colorStops.reverse();
  37522. outerColors.reverse();
  37523. }
  37524. var colorStopsInRange = clipColorStops(colorStops, coordDim === 'x' ? api.getWidth() : api.getHeight());
  37525. var inRangeStopLen = colorStopsInRange.length;
  37526. if (!inRangeStopLen && stopLen) {
  37527. // All stops are out of range. All will be the same color.
  37528. return colorStops[0].coord < 0 ? outerColors[1] ? outerColors[1] : colorStops[stopLen - 1].color : outerColors[0] ? outerColors[0] : colorStops[0].color;
  37529. }
  37530. var tinyExtent = 10; // Arbitrary value: 10px
  37531. var minCoord = colorStopsInRange[0].coord - tinyExtent;
  37532. var maxCoord = colorStopsInRange[inRangeStopLen - 1].coord + tinyExtent;
  37533. var coordSpan = maxCoord - minCoord;
  37534. if (coordSpan < 1e-3) {
  37535. return 'transparent';
  37536. }
  37537. each(colorStopsInRange, function (stop) {
  37538. stop.offset = (stop.coord - minCoord) / coordSpan;
  37539. });
  37540. colorStopsInRange.push({
  37541. // NOTE: inRangeStopLen may still be 0 if stoplen is zero.
  37542. offset: inRangeStopLen ? colorStopsInRange[inRangeStopLen - 1].offset : 0.5,
  37543. color: outerColors[1] || 'transparent'
  37544. });
  37545. colorStopsInRange.unshift({
  37546. offset: inRangeStopLen ? colorStopsInRange[0].offset : 0.5,
  37547. color: outerColors[0] || 'transparent'
  37548. });
  37549. var gradient = new LinearGradient(0, 0, 0, 0, colorStopsInRange, true);
  37550. gradient[coordDim] = minCoord;
  37551. gradient[coordDim + '2'] = maxCoord;
  37552. return gradient;
  37553. }
  37554. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  37555. var showAllSymbol = seriesModel.get('showAllSymbol');
  37556. var isAuto = showAllSymbol === 'auto';
  37557. if (showAllSymbol && !isAuto) {
  37558. return;
  37559. }
  37560. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  37561. if (!categoryAxis) {
  37562. return;
  37563. } // Note that category label interval strategy might bring some weird effect
  37564. // in some scenario: users may wonder why some of the symbols are not
  37565. // displayed. So we show all symbols as possible as we can.
  37566. if (isAuto // Simplify the logic, do not determine label overlap here.
  37567. && canShowAllSymbolForCategory(categoryAxis, data)) {
  37568. return;
  37569. } // Otherwise follow the label interval strategy on category axis.
  37570. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  37571. var labelMap = {};
  37572. each(categoryAxis.getViewLabels(), function (labelItem) {
  37573. var ordinalNumber = categoryAxis.scale.getRawOrdinalNumber(labelItem.tickValue);
  37574. labelMap[ordinalNumber] = 1;
  37575. });
  37576. return function (dataIndex) {
  37577. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  37578. };
  37579. }
  37580. function canShowAllSymbolForCategory(categoryAxis, data) {
  37581. // In mose cases, line is monotonous on category axis, and the label size
  37582. // is close with each other. So we check the symbol size and some of the
  37583. // label size alone with the category axis to estimate whether all symbol
  37584. // can be shown without overlap.
  37585. var axisExtent = categoryAxis.getExtent();
  37586. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  37587. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  37588. // Sampling some points, max 5.
  37589. var dataLen = data.count();
  37590. var step = Math.max(1, Math.round(dataLen / 5));
  37591. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  37592. if (Symbol.getSymbolSize(data, dataIndex // Only for cartesian, where `isHorizontal` exists.
  37593. )[categoryAxis.isHorizontal() ? 1 : 0] // Empirical number
  37594. * 1.5 > availSize) {
  37595. return false;
  37596. }
  37597. }
  37598. return true;
  37599. }
  37600. function isPointNull$1(x, y) {
  37601. return isNaN(x) || isNaN(y);
  37602. }
  37603. function getLastIndexNotNull(points) {
  37604. var len = points.length / 2;
  37605. for (; len > 0; len--) {
  37606. if (!isPointNull$1(points[len * 2 - 2], points[len * 2 - 1])) {
  37607. break;
  37608. }
  37609. }
  37610. return len - 1;
  37611. }
  37612. function getPointAtIndex(points, idx) {
  37613. return [points[idx * 2], points[idx * 2 + 1]];
  37614. }
  37615. function getIndexRange(points, xOrY, dim) {
  37616. var len = points.length / 2;
  37617. var dimIdx = dim === 'x' ? 0 : 1;
  37618. var a;
  37619. var b;
  37620. var prevIndex = 0;
  37621. var nextIndex = -1;
  37622. for (var i = 0; i < len; i++) {
  37623. b = points[i * 2 + dimIdx];
  37624. if (isNaN(b) || isNaN(points[i * 2 + 1 - dimIdx])) {
  37625. continue;
  37626. }
  37627. if (i === 0) {
  37628. a = b;
  37629. continue;
  37630. }
  37631. if (a <= xOrY && b >= xOrY || a >= xOrY && b <= xOrY) {
  37632. nextIndex = i;
  37633. break;
  37634. }
  37635. prevIndex = i;
  37636. a = b;
  37637. }
  37638. return {
  37639. range: [prevIndex, nextIndex],
  37640. t: (xOrY - a) / (b - a)
  37641. };
  37642. }
  37643. function anyStateShowEndLabel(seriesModel) {
  37644. if (seriesModel.get(['endLabel', 'show'])) {
  37645. return true;
  37646. }
  37647. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  37648. if (seriesModel.get([SPECIAL_STATES[i], 'endLabel', 'show'])) {
  37649. return true;
  37650. }
  37651. }
  37652. return false;
  37653. }
  37654. function createLineClipPath(lineView, coordSys, hasAnimation, seriesModel) {
  37655. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  37656. var endLabelModel_1 = seriesModel.getModel('endLabel');
  37657. var valueAnimation_1 = endLabelModel_1.get('valueAnimation');
  37658. var data_1 = seriesModel.getData();
  37659. var labelAnimationRecord_1 = {
  37660. lastFrameIndex: 0
  37661. };
  37662. var during = anyStateShowEndLabel(seriesModel) ? function (percent, clipRect) {
  37663. lineView._endLabelOnDuring(percent, clipRect, data_1, labelAnimationRecord_1, valueAnimation_1, endLabelModel_1, coordSys);
  37664. } : null;
  37665. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  37666. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, function () {
  37667. var endLabel = lineView._endLabel;
  37668. if (endLabel && hasAnimation) {
  37669. if (labelAnimationRecord_1.originalX != null) {
  37670. endLabel.attr({
  37671. x: labelAnimationRecord_1.originalX,
  37672. y: labelAnimationRecord_1.originalY
  37673. });
  37674. }
  37675. }
  37676. }, during); // Expand clip shape to avoid clipping when line value exceeds axis
  37677. if (!seriesModel.get('clip', true)) {
  37678. var rectShape = clipPath.shape;
  37679. var expandSize = Math.max(rectShape.width, rectShape.height);
  37680. if (isHorizontal) {
  37681. rectShape.y -= expandSize;
  37682. rectShape.height += expandSize * 2;
  37683. } else {
  37684. rectShape.x -= expandSize;
  37685. rectShape.width += expandSize * 2;
  37686. }
  37687. } // Set to the final frame. To make sure label layout is right.
  37688. if (during) {
  37689. during(1, clipPath);
  37690. }
  37691. return clipPath;
  37692. } else {
  37693. if ("development" !== 'production') {
  37694. if (seriesModel.get(['endLabel', 'show'])) {
  37695. console.warn('endLabel is not supported for lines in polar systems.');
  37696. }
  37697. }
  37698. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  37699. }
  37700. }
  37701. function getEndLabelStateSpecified(endLabelModel, coordSys) {
  37702. var baseAxis = coordSys.getBaseAxis();
  37703. var isHorizontal = baseAxis.isHorizontal();
  37704. var isBaseInversed = baseAxis.inverse;
  37705. var align = isHorizontal ? isBaseInversed ? 'right' : 'left' : 'center';
  37706. var verticalAlign = isHorizontal ? 'middle' : isBaseInversed ? 'top' : 'bottom';
  37707. return {
  37708. normal: {
  37709. align: endLabelModel.get('align') || align,
  37710. verticalAlign: endLabelModel.get('verticalAlign') || verticalAlign
  37711. }
  37712. };
  37713. }
  37714. var LineView =
  37715. /** @class */
  37716. function (_super) {
  37717. __extends(LineView, _super);
  37718. function LineView() {
  37719. return _super !== null && _super.apply(this, arguments) || this;
  37720. }
  37721. LineView.prototype.init = function () {
  37722. var lineGroup = new Group();
  37723. var symbolDraw = new SymbolDraw();
  37724. this.group.add(symbolDraw.group);
  37725. this._symbolDraw = symbolDraw;
  37726. this._lineGroup = lineGroup;
  37727. };
  37728. LineView.prototype.render = function (seriesModel, ecModel, api) {
  37729. var _this = this;
  37730. var coordSys = seriesModel.coordinateSystem;
  37731. var group = this.group;
  37732. var data = seriesModel.getData();
  37733. var lineStyleModel = seriesModel.getModel('lineStyle');
  37734. var areaStyleModel = seriesModel.getModel('areaStyle');
  37735. var points = data.getLayout('points') || [];
  37736. var isCoordSysPolar = coordSys.type === 'polar';
  37737. var prevCoordSys = this._coordSys;
  37738. var symbolDraw = this._symbolDraw;
  37739. var polyline = this._polyline;
  37740. var polygon = this._polygon;
  37741. var lineGroup = this._lineGroup;
  37742. var hasAnimation = seriesModel.get('animation');
  37743. var isAreaChart = !areaStyleModel.isEmpty();
  37744. var valueOrigin = areaStyleModel.get('origin');
  37745. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  37746. var stackedOnPoints = isAreaChart && getStackedOnPoints(coordSys, data, dataCoordInfo);
  37747. var showSymbol = seriesModel.get('showSymbol');
  37748. var isIgnoreFunc = showSymbol && !isCoordSysPolar && getIsIgnoreFunc(seriesModel, data, coordSys); // Remove temporary symbols
  37749. var oldData = this._data;
  37750. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  37751. if (el.__temp) {
  37752. group.remove(el);
  37753. oldData.setItemGraphicEl(idx, null);
  37754. }
  37755. }); // Remove previous created symbols if showSymbol changed to false
  37756. if (!showSymbol) {
  37757. symbolDraw.remove();
  37758. }
  37759. group.add(lineGroup); // FIXME step not support polar
  37760. var step = !isCoordSysPolar ? seriesModel.get('step') : false;
  37761. var clipShapeForSymbol;
  37762. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  37763. clipShapeForSymbol = coordSys.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  37764. // See #7913 and `test/dataZoom-clip.html`.
  37765. if (clipShapeForSymbol.width != null) {
  37766. clipShapeForSymbol.x -= 0.1;
  37767. clipShapeForSymbol.y -= 0.1;
  37768. clipShapeForSymbol.width += 0.2;
  37769. clipShapeForSymbol.height += 0.2;
  37770. } else if (clipShapeForSymbol.r0) {
  37771. clipShapeForSymbol.r0 -= 0.5;
  37772. clipShapeForSymbol.r += 0.5;
  37773. }
  37774. }
  37775. this._clipShapeForSymbol = clipShapeForSymbol;
  37776. var visualColor = getVisualGradient(data, coordSys, api) || data.getVisual('style')[data.getVisual('drawType')]; // Initialization animation or coordinate system changed
  37777. if (!(polyline && prevCoordSys.type === coordSys.type && step === this._step)) {
  37778. showSymbol && symbolDraw.updateData(data, {
  37779. isIgnore: isIgnoreFunc,
  37780. clipShape: clipShapeForSymbol,
  37781. disableAnimation: true,
  37782. getSymbolPoint: function (idx) {
  37783. return [points[idx * 2], points[idx * 2 + 1]];
  37784. }
  37785. });
  37786. hasAnimation && this._initSymbolLabelAnimation(data, coordSys, clipShapeForSymbol);
  37787. if (step) {
  37788. // TODO If stacked series is not step
  37789. points = turnPointsIntoStep(points, coordSys, step);
  37790. if (stackedOnPoints) {
  37791. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  37792. }
  37793. }
  37794. polyline = this._newPolyline(points);
  37795. if (isAreaChart) {
  37796. polygon = this._newPolygon(points, stackedOnPoints);
  37797. } // NOTE: Must update _endLabel before setClipPath.
  37798. if (!isCoordSysPolar) {
  37799. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  37800. }
  37801. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  37802. } else {
  37803. if (isAreaChart && !polygon) {
  37804. // If areaStyle is added
  37805. polygon = this._newPolygon(points, stackedOnPoints);
  37806. } else if (polygon && !isAreaChart) {
  37807. // If areaStyle is removed
  37808. lineGroup.remove(polygon);
  37809. polygon = this._polygon = null;
  37810. } // NOTE: Must update _endLabel before setClipPath.
  37811. if (!isCoordSysPolar) {
  37812. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  37813. } // Update clipPath
  37814. var oldClipPath = lineGroup.getClipPath();
  37815. if (oldClipPath) {
  37816. var newClipPath = createLineClipPath(this, coordSys, false, seriesModel);
  37817. initProps(oldClipPath, {
  37818. shape: newClipPath.shape
  37819. }, seriesModel);
  37820. } else {
  37821. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  37822. } // Always update, or it is wrong in the case turning on legend
  37823. // because points are not changed
  37824. showSymbol && symbolDraw.updateData(data, {
  37825. isIgnore: isIgnoreFunc,
  37826. clipShape: clipShapeForSymbol,
  37827. disableAnimation: true,
  37828. getSymbolPoint: function (idx) {
  37829. return [points[idx * 2], points[idx * 2 + 1]];
  37830. }
  37831. }); // In the case data zoom triggerred refreshing frequently
  37832. // Data may not change if line has a category axis. So it should animate nothing
  37833. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints) || !isPointsSame(this._points, points)) {
  37834. if (hasAnimation) {
  37835. this._doUpdateAnimation(data, stackedOnPoints, coordSys, api, step, valueOrigin);
  37836. } else {
  37837. // Not do it in update with animation
  37838. if (step) {
  37839. // TODO If stacked series is not step
  37840. points = turnPointsIntoStep(points, coordSys, step);
  37841. if (stackedOnPoints) {
  37842. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  37843. }
  37844. }
  37845. polyline.setShape({
  37846. points: points
  37847. });
  37848. polygon && polygon.setShape({
  37849. points: points,
  37850. stackedOnPoints: stackedOnPoints
  37851. });
  37852. }
  37853. }
  37854. }
  37855. var focus = seriesModel.get(['emphasis', 'focus']);
  37856. var blurScope = seriesModel.get(['emphasis', 'blurScope']);
  37857. polyline.useStyle(defaults( // Use color in lineStyle first
  37858. lineStyleModel.getLineStyle(), {
  37859. fill: 'none',
  37860. stroke: visualColor,
  37861. lineJoin: 'bevel'
  37862. }));
  37863. setStatesStylesFromModel(polyline, seriesModel, 'lineStyle');
  37864. if (polyline.style.lineWidth > 0 && seriesModel.get(['emphasis', 'lineStyle', 'width']) === 'bolder') {
  37865. var emphasisLineStyle = polyline.getState('emphasis').style;
  37866. emphasisLineStyle.lineWidth = +polyline.style.lineWidth + 1;
  37867. } // Needs seriesIndex for focus
  37868. getECData(polyline).seriesIndex = seriesModel.seriesIndex;
  37869. enableHoverEmphasis(polyline, focus, blurScope);
  37870. var smooth = getSmooth(seriesModel.get('smooth'));
  37871. var smoothMonotone = seriesModel.get('smoothMonotone');
  37872. var connectNulls = seriesModel.get('connectNulls');
  37873. polyline.setShape({
  37874. smooth: smooth,
  37875. smoothMonotone: smoothMonotone,
  37876. connectNulls: connectNulls
  37877. });
  37878. if (polygon) {
  37879. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  37880. var stackedOnSmooth = 0;
  37881. polygon.useStyle(defaults(areaStyleModel.getAreaStyle(), {
  37882. fill: visualColor,
  37883. opacity: 0.7,
  37884. lineJoin: 'bevel',
  37885. decal: data.getVisual('style').decal
  37886. }));
  37887. if (stackedOnSeries) {
  37888. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  37889. }
  37890. polygon.setShape({
  37891. smooth: smooth,
  37892. stackedOnSmooth: stackedOnSmooth,
  37893. smoothMonotone: smoothMonotone,
  37894. connectNulls: connectNulls
  37895. });
  37896. setStatesStylesFromModel(polygon, seriesModel, 'areaStyle'); // Needs seriesIndex for focus
  37897. getECData(polygon).seriesIndex = seriesModel.seriesIndex;
  37898. enableHoverEmphasis(polygon, focus, blurScope);
  37899. }
  37900. var changePolyState = function (toState) {
  37901. _this._changePolyState(toState);
  37902. };
  37903. data.eachItemGraphicEl(function (el) {
  37904. // Switch polyline / polygon state if element changed its state.
  37905. el && (el.onHoverStateChange = changePolyState);
  37906. });
  37907. this._polyline.onHoverStateChange = changePolyState;
  37908. this._data = data; // Save the coordinate system for transition animation when data changed
  37909. this._coordSys = coordSys;
  37910. this._stackedOnPoints = stackedOnPoints;
  37911. this._points = points;
  37912. this._step = step;
  37913. this._valueOrigin = valueOrigin;
  37914. if (seriesModel.get('triggerLineEvent')) {
  37915. this.packEventData(seriesModel, polyline);
  37916. polygon && this.packEventData(seriesModel, polygon);
  37917. }
  37918. };
  37919. LineView.prototype.packEventData = function (seriesModel, el) {
  37920. getECData(el).eventData = {
  37921. componentType: 'series',
  37922. componentSubType: 'line',
  37923. componentIndex: seriesModel.componentIndex,
  37924. seriesIndex: seriesModel.seriesIndex,
  37925. seriesName: seriesModel.name,
  37926. seriesType: 'line'
  37927. };
  37928. };
  37929. LineView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  37930. var data = seriesModel.getData();
  37931. var dataIndex = queryDataIndex(data, payload);
  37932. this._changePolyState('emphasis');
  37933. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  37934. var points = data.getLayout('points');
  37935. var symbol = data.getItemGraphicEl(dataIndex);
  37936. if (!symbol) {
  37937. // Create a temporary symbol if it is not exists
  37938. var x = points[dataIndex * 2];
  37939. var y = points[dataIndex * 2 + 1];
  37940. if (isNaN(x) || isNaN(y)) {
  37941. // Null data
  37942. return;
  37943. } // fix #11360: should't draw symbol outside clipShapeForSymbol
  37944. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(x, y)) {
  37945. return;
  37946. }
  37947. var zlevel = seriesModel.get('zlevel');
  37948. var z = seriesModel.get('z');
  37949. symbol = new Symbol(data, dataIndex);
  37950. symbol.x = x;
  37951. symbol.y = y;
  37952. symbol.setZ(zlevel, z); // ensure label text of the temporary symbol is in front of line and area polygon
  37953. var symbolLabel = symbol.getSymbolPath().getTextContent();
  37954. if (symbolLabel) {
  37955. symbolLabel.zlevel = zlevel;
  37956. symbolLabel.z = z;
  37957. symbolLabel.z2 = this._polyline.z2 + 1;
  37958. }
  37959. symbol.__temp = true;
  37960. data.setItemGraphicEl(dataIndex, symbol); // Stop scale animation
  37961. symbol.stopSymbolAnimation(true);
  37962. this.group.add(symbol);
  37963. }
  37964. symbol.highlight();
  37965. } else {
  37966. // Highlight whole series
  37967. ChartView.prototype.highlight.call(this, seriesModel, ecModel, api, payload);
  37968. }
  37969. };
  37970. LineView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  37971. var data = seriesModel.getData();
  37972. var dataIndex = queryDataIndex(data, payload);
  37973. this._changePolyState('normal');
  37974. if (dataIndex != null && dataIndex >= 0) {
  37975. var symbol = data.getItemGraphicEl(dataIndex);
  37976. if (symbol) {
  37977. if (symbol.__temp) {
  37978. data.setItemGraphicEl(dataIndex, null);
  37979. this.group.remove(symbol);
  37980. } else {
  37981. symbol.downplay();
  37982. }
  37983. }
  37984. } else {
  37985. // FIXME
  37986. // can not downplay completely.
  37987. // Downplay whole series
  37988. ChartView.prototype.downplay.call(this, seriesModel, ecModel, api, payload);
  37989. }
  37990. };
  37991. LineView.prototype._changePolyState = function (toState) {
  37992. var polygon = this._polygon;
  37993. setStatesFlag(this._polyline, toState);
  37994. polygon && setStatesFlag(polygon, toState);
  37995. };
  37996. LineView.prototype._newPolyline = function (points) {
  37997. var polyline = this._polyline; // Remove previous created polyline
  37998. if (polyline) {
  37999. this._lineGroup.remove(polyline);
  38000. }
  38001. polyline = new ECPolyline({
  38002. shape: {
  38003. points: points
  38004. },
  38005. segmentIgnoreThreshold: 2,
  38006. z2: 10
  38007. });
  38008. this._lineGroup.add(polyline);
  38009. this._polyline = polyline;
  38010. return polyline;
  38011. };
  38012. LineView.prototype._newPolygon = function (points, stackedOnPoints) {
  38013. var polygon = this._polygon; // Remove previous created polygon
  38014. if (polygon) {
  38015. this._lineGroup.remove(polygon);
  38016. }
  38017. polygon = new ECPolygon({
  38018. shape: {
  38019. points: points,
  38020. stackedOnPoints: stackedOnPoints
  38021. },
  38022. segmentIgnoreThreshold: 2
  38023. });
  38024. this._lineGroup.add(polygon);
  38025. this._polygon = polygon;
  38026. return polygon;
  38027. };
  38028. LineView.prototype._initSymbolLabelAnimation = function (data, coordSys, clipShape) {
  38029. var isHorizontalOrRadial;
  38030. var isCoordSysPolar;
  38031. var baseAxis = coordSys.getBaseAxis();
  38032. var isAxisInverse = baseAxis.inverse;
  38033. if (coordSys.type === 'cartesian2d') {
  38034. isHorizontalOrRadial = baseAxis.isHorizontal();
  38035. isCoordSysPolar = false;
  38036. } else if (coordSys.type === 'polar') {
  38037. isHorizontalOrRadial = baseAxis.dim === 'angle';
  38038. isCoordSysPolar = true;
  38039. }
  38040. var seriesModel = data.hostModel;
  38041. var seriesDuration = seriesModel.get('animationDuration');
  38042. if (typeof seriesDuration === 'function') {
  38043. seriesDuration = seriesDuration(null);
  38044. }
  38045. var seriesDalay = seriesModel.get('animationDelay') || 0;
  38046. var seriesDalayValue = typeof seriesDalay === 'function' ? seriesDalay(null) : seriesDalay;
  38047. data.eachItemGraphicEl(function (symbol, idx) {
  38048. var el = symbol;
  38049. if (el) {
  38050. var point = [symbol.x, symbol.y];
  38051. var start = void 0;
  38052. var end = void 0;
  38053. var current = void 0;
  38054. if (clipShape) {
  38055. if (isCoordSysPolar) {
  38056. var polarClip = clipShape;
  38057. var coord = coordSys.pointToCoord(point);
  38058. if (isHorizontalOrRadial) {
  38059. start = polarClip.startAngle;
  38060. end = polarClip.endAngle;
  38061. current = -coord[1] / 180 * Math.PI;
  38062. } else {
  38063. start = polarClip.r0;
  38064. end = polarClip.r;
  38065. current = coord[0];
  38066. }
  38067. } else {
  38068. var gridClip = clipShape;
  38069. if (isHorizontalOrRadial) {
  38070. start = gridClip.x;
  38071. end = gridClip.x + gridClip.width;
  38072. current = symbol.x;
  38073. } else {
  38074. start = gridClip.y + gridClip.height;
  38075. end = gridClip.y;
  38076. current = symbol.y;
  38077. }
  38078. }
  38079. }
  38080. var ratio = end === start ? 0 : (current - start) / (end - start);
  38081. if (isAxisInverse) {
  38082. ratio = 1 - ratio;
  38083. }
  38084. var delay = typeof seriesDalay === 'function' ? seriesDalay(idx) : seriesDuration * ratio + seriesDalayValue;
  38085. var symbolPath = el.getSymbolPath();
  38086. var text = symbolPath.getTextContent();
  38087. el.attr({
  38088. scaleX: 0,
  38089. scaleY: 0
  38090. });
  38091. el.animateTo({
  38092. scaleX: 1,
  38093. scaleY: 1
  38094. }, {
  38095. duration: 200,
  38096. setToFinal: true,
  38097. delay: delay
  38098. });
  38099. if (text) {
  38100. text.animateFrom({
  38101. style: {
  38102. opacity: 0
  38103. }
  38104. }, {
  38105. duration: 300,
  38106. delay: delay
  38107. });
  38108. }
  38109. symbolPath.disableLabelAnimation = true;
  38110. }
  38111. });
  38112. };
  38113. LineView.prototype._initOrUpdateEndLabel = function (seriesModel, coordSys, inheritColor) {
  38114. var endLabelModel = seriesModel.getModel('endLabel');
  38115. if (anyStateShowEndLabel(seriesModel)) {
  38116. var data_2 = seriesModel.getData();
  38117. var polyline = this._polyline;
  38118. var endLabel = this._endLabel;
  38119. if (!endLabel) {
  38120. endLabel = this._endLabel = new ZRText({
  38121. z2: 200 // should be higher than item symbol
  38122. });
  38123. endLabel.ignoreClip = true;
  38124. polyline.setTextContent(this._endLabel);
  38125. polyline.disableLabelAnimation = true;
  38126. } // Find last non-NaN data to display data
  38127. var dataIndex = getLastIndexNotNull(data_2.getLayout('points'));
  38128. if (dataIndex >= 0) {
  38129. setLabelStyle(polyline, getLabelStatesModels(seriesModel, 'endLabel'), {
  38130. inheritColor: inheritColor,
  38131. labelFetcher: seriesModel,
  38132. labelDataIndex: dataIndex,
  38133. defaultText: function (dataIndex, opt, interpolatedValue) {
  38134. return interpolatedValue != null ? getDefaultInterpolatedLabel(data_2, interpolatedValue) : getDefaultLabel(data_2, dataIndex);
  38135. },
  38136. enableTextSetter: true
  38137. }, getEndLabelStateSpecified(endLabelModel, coordSys));
  38138. polyline.textConfig.position = null;
  38139. }
  38140. } else if (this._endLabel) {
  38141. this._polyline.removeTextContent();
  38142. this._endLabel = null;
  38143. }
  38144. };
  38145. LineView.prototype._endLabelOnDuring = function (percent, clipRect, data, animationRecord, valueAnimation, endLabelModel, coordSys) {
  38146. var endLabel = this._endLabel;
  38147. var polyline = this._polyline;
  38148. if (endLabel) {
  38149. // NOTE: Don't remove percent < 1. percent === 1 means the first frame during render.
  38150. // The label is not prepared at this time.
  38151. if (percent < 1 && animationRecord.originalX == null) {
  38152. animationRecord.originalX = endLabel.x;
  38153. animationRecord.originalY = endLabel.y;
  38154. }
  38155. var points = data.getLayout('points');
  38156. var seriesModel = data.hostModel;
  38157. var connectNulls = seriesModel.get('connectNulls');
  38158. var precision = endLabelModel.get('precision');
  38159. var distance = endLabelModel.get('distance') || 0;
  38160. var baseAxis = coordSys.getBaseAxis();
  38161. var isHorizontal = baseAxis.isHorizontal();
  38162. var isBaseInversed = baseAxis.inverse;
  38163. var clipShape = clipRect.shape;
  38164. var xOrY = isBaseInversed ? isHorizontal ? clipShape.x : clipShape.y + clipShape.height : isHorizontal ? clipShape.x + clipShape.width : clipShape.y;
  38165. var distanceX = (isHorizontal ? distance : 0) * (isBaseInversed ? -1 : 1);
  38166. var distanceY = (isHorizontal ? 0 : -distance) * (isBaseInversed ? -1 : 1);
  38167. var dim = isHorizontal ? 'x' : 'y';
  38168. var dataIndexRange = getIndexRange(points, xOrY, dim);
  38169. var indices = dataIndexRange.range;
  38170. var diff = indices[1] - indices[0];
  38171. var value = void 0;
  38172. if (diff >= 1) {
  38173. // diff > 1 && connectNulls, which is on the null data.
  38174. if (diff > 1 && !connectNulls) {
  38175. var pt = getPointAtIndex(points, indices[0]);
  38176. endLabel.attr({
  38177. x: pt[0] + distanceX,
  38178. y: pt[1] + distanceY
  38179. });
  38180. valueAnimation && (value = seriesModel.getRawValue(indices[0]));
  38181. } else {
  38182. var pt = polyline.getPointOn(xOrY, dim);
  38183. pt && endLabel.attr({
  38184. x: pt[0] + distanceX,
  38185. y: pt[1] + distanceY
  38186. });
  38187. var startValue = seriesModel.getRawValue(indices[0]);
  38188. var endValue = seriesModel.getRawValue(indices[1]);
  38189. valueAnimation && (value = interpolateRawValues(data, precision, startValue, endValue, dataIndexRange.t));
  38190. }
  38191. animationRecord.lastFrameIndex = indices[0];
  38192. } else {
  38193. // If diff <= 0, which is the range is not found(Include NaN)
  38194. // Choose the first point or last point.
  38195. var idx = percent === 1 || animationRecord.lastFrameIndex > 0 ? indices[0] : 0;
  38196. var pt = getPointAtIndex(points, idx);
  38197. valueAnimation && (value = seriesModel.getRawValue(idx));
  38198. endLabel.attr({
  38199. x: pt[0] + distanceX,
  38200. y: pt[1] + distanceY
  38201. });
  38202. }
  38203. if (valueAnimation) {
  38204. labelInner(endLabel).setLabelText(value);
  38205. }
  38206. }
  38207. };
  38208. /**
  38209. * @private
  38210. */
  38211. // FIXME Two value axis
  38212. LineView.prototype._doUpdateAnimation = function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  38213. var polyline = this._polyline;
  38214. var polygon = this._polygon;
  38215. var seriesModel = data.hostModel;
  38216. var diff = lineAnimationDiff(this._data, data, this._stackedOnPoints, stackedOnPoints, this._coordSys, coordSys, this._valueOrigin);
  38217. var current = diff.current;
  38218. var stackedOnCurrent = diff.stackedOnCurrent;
  38219. var next = diff.next;
  38220. var stackedOnNext = diff.stackedOnNext;
  38221. if (step) {
  38222. // TODO If stacked series is not step
  38223. current = turnPointsIntoStep(diff.current, coordSys, step);
  38224. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  38225. next = turnPointsIntoStep(diff.next, coordSys, step);
  38226. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  38227. } // Don't apply animation if diff is large.
  38228. // For better result and avoid memory explosion problems like
  38229. // https://github.com/apache/incubator-echarts/issues/12229
  38230. if (getBoundingDiff(current, next) > 3000 || polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000) {
  38231. polyline.stopAnimation();
  38232. polyline.setShape({
  38233. points: next
  38234. });
  38235. if (polygon) {
  38236. polygon.stopAnimation();
  38237. polygon.setShape({
  38238. points: next,
  38239. stackedOnPoints: stackedOnNext
  38240. });
  38241. }
  38242. return;
  38243. }
  38244. polyline.shape.__points = diff.current;
  38245. polyline.shape.points = current;
  38246. var target = {
  38247. shape: {
  38248. points: next
  38249. }
  38250. }; // Also animate the original points.
  38251. // If points reference is changed when turning into step line.
  38252. if (diff.current !== current) {
  38253. target.shape.__points = diff.next;
  38254. } // Stop previous animation.
  38255. polyline.stopAnimation();
  38256. updateProps(polyline, target, seriesModel);
  38257. if (polygon) {
  38258. polygon.setShape({
  38259. // Reuse the points with polyline.
  38260. points: current,
  38261. stackedOnPoints: stackedOnCurrent
  38262. });
  38263. polygon.stopAnimation();
  38264. updateProps(polygon, {
  38265. shape: {
  38266. stackedOnPoints: stackedOnNext
  38267. }
  38268. }, seriesModel); // If use attr directly in updateProps.
  38269. if (polyline.shape.points !== polygon.shape.points) {
  38270. polygon.shape.points = polyline.shape.points;
  38271. }
  38272. }
  38273. var updatedDataInfo = [];
  38274. var diffStatus = diff.status;
  38275. for (var i = 0; i < diffStatus.length; i++) {
  38276. var cmd = diffStatus[i].cmd;
  38277. if (cmd === '=') {
  38278. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  38279. if (el) {
  38280. updatedDataInfo.push({
  38281. el: el,
  38282. ptIdx: i // Index of points
  38283. });
  38284. }
  38285. }
  38286. }
  38287. if (polyline.animators && polyline.animators.length) {
  38288. polyline.animators[0].during(function () {
  38289. polygon && polygon.dirtyShape();
  38290. var points = polyline.shape.__points;
  38291. for (var i = 0; i < updatedDataInfo.length; i++) {
  38292. var el = updatedDataInfo[i].el;
  38293. var offset = updatedDataInfo[i].ptIdx * 2;
  38294. el.x = points[offset];
  38295. el.y = points[offset + 1];
  38296. el.markRedraw();
  38297. }
  38298. });
  38299. }
  38300. };
  38301. LineView.prototype.remove = function (ecModel) {
  38302. var group = this.group;
  38303. var oldData = this._data;
  38304. this._lineGroup.removeAll();
  38305. this._symbolDraw.remove(true); // Remove temporary created elements when highlighting
  38306. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  38307. if (el.__temp) {
  38308. group.remove(el);
  38309. oldData.setItemGraphicEl(idx, null);
  38310. }
  38311. });
  38312. this._polyline = this._polygon = this._coordSys = this._points = this._stackedOnPoints = this._endLabel = this._data = null;
  38313. };
  38314. LineView.type = 'line';
  38315. return LineView;
  38316. }(ChartView);
  38317. function pointsLayout(seriesType, forceStoreInTypedArray) {
  38318. return {
  38319. seriesType: seriesType,
  38320. plan: createRenderPlanner(),
  38321. reset: function (seriesModel) {
  38322. var data = seriesModel.getData();
  38323. var coordSys = seriesModel.coordinateSystem;
  38324. var pipelineContext = seriesModel.pipelineContext;
  38325. var useTypedArray = forceStoreInTypedArray || pipelineContext.large;
  38326. if (!coordSys) {
  38327. return;
  38328. }
  38329. var dims = map(coordSys.dimensions, function (dim) {
  38330. return data.mapDimension(dim);
  38331. }).slice(0, 2);
  38332. var dimLen = dims.length;
  38333. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  38334. if (isDimensionStacked(data, dims[0]
  38335. /*, dims[1]*/
  38336. )) {
  38337. dims[0] = stackResultDim;
  38338. }
  38339. if (isDimensionStacked(data, dims[1]
  38340. /*, dims[0]*/
  38341. )) {
  38342. dims[1] = stackResultDim;
  38343. }
  38344. var store = data.getStore();
  38345. var dimIdx0 = data.getDimensionIndex(dims[0]);
  38346. var dimIdx1 = data.getDimensionIndex(dims[1]);
  38347. return dimLen && {
  38348. progress: function (params, data) {
  38349. var segCount = params.end - params.start;
  38350. var points = useTypedArray && createFloat32Array(segCount * dimLen);
  38351. var tmpIn = [];
  38352. var tmpOut = [];
  38353. for (var i = params.start, offset = 0; i < params.end; i++) {
  38354. var point = void 0;
  38355. if (dimLen === 1) {
  38356. var x = store.get(dimIdx0, i); // NOTE: Make sure the second parameter is null to use default strategy.
  38357. point = coordSys.dataToPoint(x, null, tmpOut);
  38358. } else {
  38359. tmpIn[0] = store.get(dimIdx0, i);
  38360. tmpIn[1] = store.get(dimIdx1, i); // Let coordinate system to handle the NaN data.
  38361. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  38362. }
  38363. if (useTypedArray) {
  38364. points[offset++] = point[0];
  38365. points[offset++] = point[1];
  38366. } else {
  38367. data.setItemLayout(i, point.slice());
  38368. }
  38369. }
  38370. useTypedArray && data.setLayout('points', points);
  38371. }
  38372. };
  38373. }
  38374. };
  38375. }
  38376. /*
  38377. * Licensed to the Apache Software Foundation (ASF) under one
  38378. * or more contributor license agreements. See the NOTICE file
  38379. * distributed with this work for additional information
  38380. * regarding copyright ownership. The ASF licenses this file
  38381. * to you under the Apache License, Version 2.0 (the
  38382. * "License"); you may not use this file except in compliance
  38383. * with the License. You may obtain a copy of the License at
  38384. *
  38385. * http://www.apache.org/licenses/LICENSE-2.0
  38386. *
  38387. * Unless required by applicable law or agreed to in writing,
  38388. * software distributed under the License is distributed on an
  38389. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38390. * KIND, either express or implied. See the License for the
  38391. * specific language governing permissions and limitations
  38392. * under the License.
  38393. */
  38394. /**
  38395. * AUTO-GENERATED FILE. DO NOT MODIFY.
  38396. */
  38397. /*
  38398. * Licensed to the Apache Software Foundation (ASF) under one
  38399. * or more contributor license agreements. See the NOTICE file
  38400. * distributed with this work for additional information
  38401. * regarding copyright ownership. The ASF licenses this file
  38402. * to you under the Apache License, Version 2.0 (the
  38403. * "License"); you may not use this file except in compliance
  38404. * with the License. You may obtain a copy of the License at
  38405. *
  38406. * http://www.apache.org/licenses/LICENSE-2.0
  38407. *
  38408. * Unless required by applicable law or agreed to in writing,
  38409. * software distributed under the License is distributed on an
  38410. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38411. * KIND, either express or implied. See the License for the
  38412. * specific language governing permissions and limitations
  38413. * under the License.
  38414. */
  38415. var samplers = {
  38416. average: function (frame) {
  38417. var sum = 0;
  38418. var count = 0;
  38419. for (var i = 0; i < frame.length; i++) {
  38420. if (!isNaN(frame[i])) {
  38421. sum += frame[i];
  38422. count++;
  38423. }
  38424. } // Return NaN if count is 0
  38425. return count === 0 ? NaN : sum / count;
  38426. },
  38427. sum: function (frame) {
  38428. var sum = 0;
  38429. for (var i = 0; i < frame.length; i++) {
  38430. // Ignore NaN
  38431. sum += frame[i] || 0;
  38432. }
  38433. return sum;
  38434. },
  38435. max: function (frame) {
  38436. var max = -Infinity;
  38437. for (var i = 0; i < frame.length; i++) {
  38438. frame[i] > max && (max = frame[i]);
  38439. } // NaN will cause illegal axis extent.
  38440. return isFinite(max) ? max : NaN;
  38441. },
  38442. min: function (frame) {
  38443. var min = Infinity;
  38444. for (var i = 0; i < frame.length; i++) {
  38445. frame[i] < min && (min = frame[i]);
  38446. } // NaN will cause illegal axis extent.
  38447. return isFinite(min) ? min : NaN;
  38448. },
  38449. // TODO
  38450. // Median
  38451. nearest: function (frame) {
  38452. return frame[0];
  38453. }
  38454. };
  38455. var indexSampler = function (frame) {
  38456. return Math.round(frame.length / 2);
  38457. };
  38458. function dataSample(seriesType) {
  38459. return {
  38460. seriesType: seriesType,
  38461. // FIXME:TS never used, so comment it
  38462. // modifyOutputEnd: true,
  38463. reset: function (seriesModel, ecModel, api) {
  38464. var data = seriesModel.getData();
  38465. var sampling = seriesModel.get('sampling');
  38466. var coordSys = seriesModel.coordinateSystem;
  38467. var count = data.count(); // Only cartesian2d support down sampling. Disable it when there is few data.
  38468. if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
  38469. var baseAxis = coordSys.getBaseAxis();
  38470. var valueAxis = coordSys.getOtherAxis(baseAxis);
  38471. var extent = baseAxis.getExtent();
  38472. var dpr = api.getDevicePixelRatio(); // Coordinste system has been resized
  38473. var size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
  38474. var rate = Math.round(count / size);
  38475. if (rate > 1) {
  38476. if (sampling === 'lttb') {
  38477. seriesModel.setData(data.lttbDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
  38478. }
  38479. var sampler = void 0;
  38480. if (typeof sampling === 'string') {
  38481. sampler = samplers[sampling];
  38482. } else if (typeof sampling === 'function') {
  38483. sampler = sampling;
  38484. }
  38485. if (sampler) {
  38486. // Only support sample the first dim mapped from value axis.
  38487. seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
  38488. }
  38489. }
  38490. }
  38491. }
  38492. };
  38493. }
  38494. function install$2(registers) {
  38495. registers.registerChartView(LineView);
  38496. registers.registerSeriesModel(LineSeriesModel);
  38497. registers.registerLayout(pointsLayout('line', true));
  38498. registers.registerVisual({
  38499. seriesType: 'line',
  38500. reset: function (seriesModel) {
  38501. var data = seriesModel.getData(); // Visual coding for legend
  38502. var lineStyle = seriesModel.getModel('lineStyle').getLineStyle();
  38503. if (lineStyle && !lineStyle.stroke) {
  38504. // Fill in visual should be palette color if
  38505. // has color callback
  38506. lineStyle.stroke = data.getVisual('style').fill;
  38507. }
  38508. data.setVisual('legendLineStyle', lineStyle);
  38509. }
  38510. }); // Down sample after filter
  38511. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('line'));
  38512. }
  38513. var BaseBarSeriesModel =
  38514. /** @class */
  38515. function (_super) {
  38516. __extends(BaseBarSeriesModel, _super);
  38517. function BaseBarSeriesModel() {
  38518. var _this = _super !== null && _super.apply(this, arguments) || this;
  38519. _this.type = BaseBarSeriesModel.type;
  38520. return _this;
  38521. }
  38522. BaseBarSeriesModel.prototype.getInitialData = function (option, ecModel) {
  38523. return createSeriesData(null, this, {
  38524. useEncodeDefaulter: true
  38525. });
  38526. };
  38527. BaseBarSeriesModel.prototype.getMarkerPosition = function (value) {
  38528. var coordSys = this.coordinateSystem;
  38529. if (coordSys && coordSys.clampData) {
  38530. // PENDING if clamp ?
  38531. var pt = coordSys.dataToPoint(coordSys.clampData(value));
  38532. var data = this.getData();
  38533. var offset = data.getLayout('offset');
  38534. var size = data.getLayout('size');
  38535. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  38536. pt[offsetIndex] += offset + size / 2;
  38537. return pt;
  38538. }
  38539. return [NaN, NaN];
  38540. };
  38541. BaseBarSeriesModel.type = 'series.__base_bar__';
  38542. BaseBarSeriesModel.defaultOption = {
  38543. zlevel: 0,
  38544. z: 2,
  38545. coordinateSystem: 'cartesian2d',
  38546. legendHoverLink: true,
  38547. // stack: null
  38548. // Cartesian coordinate system
  38549. // xAxisIndex: 0,
  38550. // yAxisIndex: 0,
  38551. barMinHeight: 0,
  38552. barMinAngle: 0,
  38553. // cursor: null,
  38554. large: false,
  38555. largeThreshold: 400,
  38556. progressive: 3e3,
  38557. progressiveChunkMode: 'mod'
  38558. };
  38559. return BaseBarSeriesModel;
  38560. }(SeriesModel);
  38561. SeriesModel.registerClass(BaseBarSeriesModel);
  38562. var BarSeriesModel =
  38563. /** @class */
  38564. function (_super) {
  38565. __extends(BarSeriesModel, _super);
  38566. function BarSeriesModel() {
  38567. var _this = _super !== null && _super.apply(this, arguments) || this;
  38568. _this.type = BarSeriesModel.type;
  38569. return _this;
  38570. }
  38571. BarSeriesModel.prototype.getInitialData = function () {
  38572. return createSeriesData(null, this, {
  38573. useEncodeDefaulter: true,
  38574. createInvertedIndices: !!this.get('realtimeSort', true) || null
  38575. });
  38576. };
  38577. /**
  38578. * @override
  38579. */
  38580. BarSeriesModel.prototype.getProgressive = function () {
  38581. // Do not support progressive in normal mode.
  38582. return this.get('large') ? this.get('progressive') : false;
  38583. };
  38584. /**
  38585. * @override
  38586. */
  38587. BarSeriesModel.prototype.getProgressiveThreshold = function () {
  38588. // Do not support progressive in normal mode.
  38589. var progressiveThreshold = this.get('progressiveThreshold');
  38590. var largeThreshold = this.get('largeThreshold');
  38591. if (largeThreshold > progressiveThreshold) {
  38592. progressiveThreshold = largeThreshold;
  38593. }
  38594. return progressiveThreshold;
  38595. };
  38596. BarSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  38597. return selectors.rect(data.getItemLayout(dataIndex));
  38598. };
  38599. BarSeriesModel.type = 'series.bar';
  38600. BarSeriesModel.dependencies = ['grid', 'polar'];
  38601. BarSeriesModel.defaultOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
  38602. // If clipped
  38603. // Only available on cartesian2d
  38604. clip: true,
  38605. roundCap: false,
  38606. showBackground: false,
  38607. backgroundStyle: {
  38608. color: 'rgba(180, 180, 180, 0.2)',
  38609. borderColor: null,
  38610. borderWidth: 0,
  38611. borderType: 'solid',
  38612. borderRadius: 0,
  38613. shadowBlur: 0,
  38614. shadowColor: null,
  38615. shadowOffsetX: 0,
  38616. shadowOffsetY: 0,
  38617. opacity: 1
  38618. },
  38619. select: {
  38620. itemStyle: {
  38621. borderColor: '#212121'
  38622. }
  38623. },
  38624. realtimeSort: false
  38625. });
  38626. return BarSeriesModel;
  38627. }(BaseBarSeriesModel);
  38628. /**
  38629. * Sausage: similar to sector, but have half circle on both sides
  38630. */
  38631. var SausageShape =
  38632. /** @class */
  38633. function () {
  38634. function SausageShape() {
  38635. this.cx = 0;
  38636. this.cy = 0;
  38637. this.r0 = 0;
  38638. this.r = 0;
  38639. this.startAngle = 0;
  38640. this.endAngle = Math.PI * 2;
  38641. this.clockwise = true;
  38642. }
  38643. return SausageShape;
  38644. }();
  38645. var SausagePath =
  38646. /** @class */
  38647. function (_super) {
  38648. __extends(SausagePath, _super);
  38649. function SausagePath(opts) {
  38650. var _this = _super.call(this, opts) || this;
  38651. _this.type = 'sausage';
  38652. return _this;
  38653. }
  38654. SausagePath.prototype.getDefaultShape = function () {
  38655. return new SausageShape();
  38656. };
  38657. SausagePath.prototype.buildPath = function (ctx, shape) {
  38658. var x = shape.cx;
  38659. var y = shape.cy;
  38660. var r0 = Math.max(shape.r0 || 0, 0);
  38661. var r = Math.max(shape.r, 0);
  38662. var dr = (r - r0) * 0.5;
  38663. var rCenter = r0 + dr;
  38664. var startAngle = shape.startAngle;
  38665. var endAngle = shape.endAngle;
  38666. var clockwise = shape.clockwise;
  38667. var unitStartX = Math.cos(startAngle);
  38668. var unitStartY = Math.sin(startAngle);
  38669. var unitEndX = Math.cos(endAngle);
  38670. var unitEndY = Math.sin(endAngle);
  38671. var lessThanCircle = clockwise ? endAngle - startAngle < Math.PI * 2 : startAngle - endAngle < Math.PI * 2;
  38672. if (lessThanCircle) {
  38673. ctx.moveTo(unitStartX * r0 + x, unitStartY * r0 + y);
  38674. ctx.arc(unitStartX * rCenter + x, unitStartY * rCenter + y, dr, -Math.PI + startAngle, startAngle, !clockwise);
  38675. }
  38676. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  38677. ctx.moveTo(unitEndX * r + x, unitEndY * r + y);
  38678. ctx.arc(unitEndX * rCenter + x, unitEndY * rCenter + y, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
  38679. if (r0 !== 0) {
  38680. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  38681. ctx.moveTo(unitStartX * r0 + x, unitEndY * r0 + y);
  38682. }
  38683. ctx.closePath();
  38684. };
  38685. return SausagePath;
  38686. }(Path);
  38687. function createSectorCalculateTextPosition(positionMapping, opts) {
  38688. opts = opts || {};
  38689. var isRoundCap = opts.isRoundCap;
  38690. return function (out, opts, boundingRect) {
  38691. var textPosition = opts.position;
  38692. if (!textPosition || textPosition instanceof Array) {
  38693. return calculateTextPosition(out, opts, boundingRect);
  38694. }
  38695. var mappedSectorPosition = positionMapping(textPosition);
  38696. var distance = opts.distance != null ? opts.distance : 5;
  38697. var sector = this.shape;
  38698. var cx = sector.cx;
  38699. var cy = sector.cy;
  38700. var r = sector.r;
  38701. var r0 = sector.r0;
  38702. var middleR = (r + r0) / 2;
  38703. var startAngle = sector.startAngle;
  38704. var endAngle = sector.endAngle;
  38705. var middleAngle = (startAngle + endAngle) / 2;
  38706. var extraDist = isRoundCap ? Math.abs(r - r0) / 2 : 0;
  38707. var mathCos = Math.cos;
  38708. var mathSin = Math.sin; // base position: top-left
  38709. var x = cx + r * mathCos(startAngle);
  38710. var y = cy + r * mathSin(startAngle);
  38711. var textAlign = 'left';
  38712. var textVerticalAlign = 'top';
  38713. switch (mappedSectorPosition) {
  38714. case 'startArc':
  38715. x = cx + (r0 - distance) * mathCos(middleAngle);
  38716. y = cy + (r0 - distance) * mathSin(middleAngle);
  38717. textAlign = 'center';
  38718. textVerticalAlign = 'top';
  38719. break;
  38720. case 'insideStartArc':
  38721. x = cx + (r0 + distance) * mathCos(middleAngle);
  38722. y = cy + (r0 + distance) * mathSin(middleAngle);
  38723. textAlign = 'center';
  38724. textVerticalAlign = 'bottom';
  38725. break;
  38726. case 'startAngle':
  38727. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, distance + extraDist, false);
  38728. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, distance + extraDist, false);
  38729. textAlign = 'right';
  38730. textVerticalAlign = 'middle';
  38731. break;
  38732. case 'insideStartAngle':
  38733. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, -distance + extraDist, false);
  38734. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, -distance + extraDist, false);
  38735. textAlign = 'left';
  38736. textVerticalAlign = 'middle';
  38737. break;
  38738. case 'middle':
  38739. x = cx + middleR * mathCos(middleAngle);
  38740. y = cy + middleR * mathSin(middleAngle);
  38741. textAlign = 'center';
  38742. textVerticalAlign = 'middle';
  38743. break;
  38744. case 'endArc':
  38745. x = cx + (r + distance) * mathCos(middleAngle);
  38746. y = cy + (r + distance) * mathSin(middleAngle);
  38747. textAlign = 'center';
  38748. textVerticalAlign = 'bottom';
  38749. break;
  38750. case 'insideEndArc':
  38751. x = cx + (r - distance) * mathCos(middleAngle);
  38752. y = cy + (r - distance) * mathSin(middleAngle);
  38753. textAlign = 'center';
  38754. textVerticalAlign = 'top';
  38755. break;
  38756. case 'endAngle':
  38757. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, distance + extraDist, true);
  38758. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, distance + extraDist, true);
  38759. textAlign = 'left';
  38760. textVerticalAlign = 'middle';
  38761. break;
  38762. case 'insideEndAngle':
  38763. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, -distance + extraDist, true);
  38764. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, -distance + extraDist, true);
  38765. textAlign = 'right';
  38766. textVerticalAlign = 'middle';
  38767. break;
  38768. default:
  38769. return calculateTextPosition(out, opts, boundingRect);
  38770. }
  38771. out = out || {};
  38772. out.x = x;
  38773. out.y = y;
  38774. out.align = textAlign;
  38775. out.verticalAlign = textVerticalAlign;
  38776. return out;
  38777. };
  38778. }
  38779. function setSectorTextRotation(sector, textPosition, positionMapping, rotateType) {
  38780. if (typeof rotateType === 'number') {
  38781. // user-set rotation
  38782. sector.setTextConfig({
  38783. rotation: rotateType
  38784. });
  38785. return;
  38786. } else if (isArray(textPosition)) {
  38787. // user-set position, use 0 as auto rotation
  38788. sector.setTextConfig({
  38789. rotation: 0
  38790. });
  38791. return;
  38792. }
  38793. var shape = sector.shape;
  38794. var startAngle = shape.clockwise ? shape.startAngle : shape.endAngle;
  38795. var endAngle = shape.clockwise ? shape.endAngle : shape.startAngle;
  38796. var middleAngle = (startAngle + endAngle) / 2;
  38797. var anchorAngle;
  38798. var mappedSectorPosition = positionMapping(textPosition);
  38799. switch (mappedSectorPosition) {
  38800. case 'startArc':
  38801. case 'insideStartArc':
  38802. case 'middle':
  38803. case 'insideEndArc':
  38804. case 'endArc':
  38805. anchorAngle = middleAngle;
  38806. break;
  38807. case 'startAngle':
  38808. case 'insideStartAngle':
  38809. anchorAngle = startAngle;
  38810. break;
  38811. case 'endAngle':
  38812. case 'insideEndAngle':
  38813. anchorAngle = endAngle;
  38814. break;
  38815. default:
  38816. sector.setTextConfig({
  38817. rotation: 0
  38818. });
  38819. return;
  38820. }
  38821. var rotate = Math.PI * 1.5 - anchorAngle;
  38822. /**
  38823. * TODO: labels with rotate > Math.PI / 2 should be rotate another
  38824. * half round flipped to increase readability. However, only middle
  38825. * position supports this for now, because in other positions, the
  38826. * anchor point is not at the center of the text, so the positions
  38827. * after rotating is not as expected.
  38828. */
  38829. if (mappedSectorPosition === 'middle' && rotate > Math.PI / 2 && rotate < Math.PI * 1.5) {
  38830. rotate -= Math.PI;
  38831. }
  38832. sector.setTextConfig({
  38833. rotation: rotate
  38834. });
  38835. }
  38836. function adjustAngleDistanceX(angle, distance, isEnd) {
  38837. return distance * Math.sin(angle) * (isEnd ? -1 : 1);
  38838. }
  38839. function adjustAngleDistanceY(angle, distance, isEnd) {
  38840. return distance * Math.cos(angle) * (isEnd ? 1 : -1);
  38841. }
  38842. var _eventPos = [0, 0];
  38843. var mathMax$6 = Math.max;
  38844. var mathMin$6 = Math.min;
  38845. function getClipArea(coord, data) {
  38846. var coordSysClipArea = coord.getArea && coord.getArea();
  38847. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  38848. var baseAxis = coord.getBaseAxis(); // When boundaryGap is false or using time axis. bar may exceed the grid.
  38849. // We should not clip this part.
  38850. // See test/bar2.html
  38851. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  38852. var expandWidth = data.getLayout('bandWidth');
  38853. if (baseAxis.isHorizontal()) {
  38854. coordSysClipArea.x -= expandWidth;
  38855. coordSysClipArea.width += expandWidth * 2;
  38856. } else {
  38857. coordSysClipArea.y -= expandWidth;
  38858. coordSysClipArea.height += expandWidth * 2;
  38859. }
  38860. }
  38861. }
  38862. return coordSysClipArea;
  38863. }
  38864. var BarView =
  38865. /** @class */
  38866. function (_super) {
  38867. __extends(BarView, _super);
  38868. function BarView() {
  38869. var _this = _super.call(this) || this;
  38870. _this.type = BarView.type;
  38871. _this._isFirstFrame = true;
  38872. return _this;
  38873. }
  38874. BarView.prototype.render = function (seriesModel, ecModel, api, payload) {
  38875. this._model = seriesModel;
  38876. this._removeOnRenderedListener(api);
  38877. this._updateDrawMode(seriesModel);
  38878. var coordinateSystemType = seriesModel.get('coordinateSystem');
  38879. if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
  38880. this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api, payload);
  38881. } else if ("development" !== 'production') {
  38882. warn('Only cartesian2d and polar supported for bar.');
  38883. }
  38884. };
  38885. BarView.prototype.incrementalPrepareRender = function (seriesModel) {
  38886. this._clear();
  38887. this._updateDrawMode(seriesModel); // incremental also need to clip, otherwise might be overlow.
  38888. // But must not set clip in each frame, otherwise all of the children will be marked redraw.
  38889. this._updateLargeClip(seriesModel);
  38890. };
  38891. BarView.prototype.incrementalRender = function (params, seriesModel) {
  38892. // Do not support progressive in normal mode.
  38893. this._incrementalRenderLarge(params, seriesModel);
  38894. };
  38895. BarView.prototype._updateDrawMode = function (seriesModel) {
  38896. var isLargeDraw = seriesModel.pipelineContext.large;
  38897. if (this._isLargeDraw == null || isLargeDraw !== this._isLargeDraw) {
  38898. this._isLargeDraw = isLargeDraw;
  38899. this._clear();
  38900. }
  38901. };
  38902. BarView.prototype._renderNormal = function (seriesModel, ecModel, api, payload) {
  38903. var group = this.group;
  38904. var data = seriesModel.getData();
  38905. var oldData = this._data;
  38906. var coord = seriesModel.coordinateSystem;
  38907. var baseAxis = coord.getBaseAxis();
  38908. var isHorizontalOrRadial;
  38909. if (coord.type === 'cartesian2d') {
  38910. isHorizontalOrRadial = baseAxis.isHorizontal();
  38911. } else if (coord.type === 'polar') {
  38912. isHorizontalOrRadial = baseAxis.dim === 'angle';
  38913. }
  38914. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  38915. var realtimeSortCfg = shouldRealtimeSort(seriesModel, coord);
  38916. if (realtimeSortCfg) {
  38917. this._enableRealtimeSort(realtimeSortCfg, data, api);
  38918. }
  38919. var needsClip = seriesModel.get('clip', true) || realtimeSortCfg;
  38920. var coordSysClipArea = getClipArea(coord, data); // If there is clipPath created in large mode. Remove it.
  38921. group.removeClipPath(); // We don't use clipPath in normal mode because we needs a perfect animation
  38922. // And don't want the label are clipped.
  38923. var roundCap = seriesModel.get('roundCap', true);
  38924. var drawBackground = seriesModel.get('showBackground', true);
  38925. var backgroundModel = seriesModel.getModel('backgroundStyle');
  38926. var barBorderRadius = backgroundModel.get('borderRadius') || 0;
  38927. var bgEls = [];
  38928. var oldBgEls = this._backgroundEls;
  38929. var isInitSort = payload && payload.isInitSort;
  38930. var isChangeOrder = payload && payload.type === 'changeAxisOrder';
  38931. function createBackground(dataIndex) {
  38932. var bgLayout = getLayout[coord.type](data, dataIndex);
  38933. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  38934. bgEl.useStyle(backgroundModel.getItemStyle()); // Only cartesian2d support borderRadius.
  38935. if (coord.type === 'cartesian2d') {
  38936. bgEl.setShape('r', barBorderRadius);
  38937. }
  38938. bgEls[dataIndex] = bgEl;
  38939. return bgEl;
  38940. }
  38941. data.diff(oldData).add(function (dataIndex) {
  38942. var itemModel = data.getItemModel(dataIndex);
  38943. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  38944. if (drawBackground) {
  38945. createBackground(dataIndex);
  38946. } // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  38947. if (!data.hasValue(dataIndex) || !isValidLayout[coord.type](layout)) {
  38948. return;
  38949. }
  38950. var isClipped = false;
  38951. if (needsClip) {
  38952. // Clip will modify the layout params.
  38953. // And return a boolean to determine if the shape are fully clipped.
  38954. isClipped = clip[coord.type](coordSysClipArea, layout);
  38955. }
  38956. var el = elementCreator[coord.type](seriesModel, data, dataIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, false, roundCap);
  38957. if (realtimeSortCfg) {
  38958. /**
  38959. * Force label animation because even if the element is
  38960. * ignored because it's clipped, it may not be clipped after
  38961. * changing order. Then, if not using forceLabelAnimation,
  38962. * the label animation was never started, in which case,
  38963. * the label will be the final value and doesn't have label
  38964. * animation.
  38965. */
  38966. el.forceLabelAnimation = true;
  38967. }
  38968. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  38969. if (isInitSort) {
  38970. el.attr({
  38971. shape: layout
  38972. });
  38973. } else if (realtimeSortCfg) {
  38974. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, dataIndex, isHorizontalOrRadial, false, false);
  38975. } else {
  38976. initProps(el, {
  38977. shape: layout
  38978. }, seriesModel, dataIndex);
  38979. }
  38980. data.setItemGraphicEl(dataIndex, el);
  38981. group.add(el);
  38982. el.ignore = isClipped;
  38983. }).update(function (newIndex, oldIndex) {
  38984. var itemModel = data.getItemModel(newIndex);
  38985. var layout = getLayout[coord.type](data, newIndex, itemModel);
  38986. if (drawBackground) {
  38987. var bgEl = void 0;
  38988. if (oldBgEls.length === 0) {
  38989. bgEl = createBackground(oldIndex);
  38990. } else {
  38991. bgEl = oldBgEls[oldIndex];
  38992. bgEl.useStyle(backgroundModel.getItemStyle()); // Only cartesian2d support borderRadius.
  38993. if (coord.type === 'cartesian2d') {
  38994. bgEl.setShape('r', barBorderRadius);
  38995. }
  38996. bgEls[newIndex] = bgEl;
  38997. }
  38998. var bgLayout = getLayout[coord.type](data, newIndex);
  38999. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  39000. updateProps(bgEl, {
  39001. shape: shape
  39002. }, animationModel, newIndex);
  39003. }
  39004. var el = oldData.getItemGraphicEl(oldIndex);
  39005. if (!data.hasValue(newIndex) || !isValidLayout[coord.type](layout)) {
  39006. group.remove(el);
  39007. return;
  39008. }
  39009. var isClipped = false;
  39010. if (needsClip) {
  39011. isClipped = clip[coord.type](coordSysClipArea, layout);
  39012. if (isClipped) {
  39013. group.remove(el);
  39014. }
  39015. }
  39016. if (!el) {
  39017. el = elementCreator[coord.type](seriesModel, data, newIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, !!el, roundCap);
  39018. } else {
  39019. saveOldStyle(el);
  39020. }
  39021. if (realtimeSortCfg) {
  39022. el.forceLabelAnimation = true;
  39023. }
  39024. if (isChangeOrder) {
  39025. var textEl = el.getTextContent();
  39026. if (textEl) {
  39027. var labelInnerStore = labelInner(textEl);
  39028. if (labelInnerStore.prevValue != null) {
  39029. /**
  39030. * Set preValue to be value so that no new label
  39031. * should be started, otherwise, it will take a full
  39032. * `animationDurationUpdate` time to finish the
  39033. * animation, which is not expected.
  39034. */
  39035. labelInnerStore.prevValue = labelInnerStore.value;
  39036. }
  39037. }
  39038. } // Not change anything if only order changed.
  39039. // Especially not change label.
  39040. if (!isChangeOrder) {
  39041. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  39042. }
  39043. if (isInitSort) {
  39044. el.attr({
  39045. shape: layout
  39046. });
  39047. } else if (realtimeSortCfg) {
  39048. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, newIndex, isHorizontalOrRadial, true, isChangeOrder);
  39049. } else {
  39050. updateProps(el, {
  39051. shape: layout
  39052. }, seriesModel, newIndex, null);
  39053. }
  39054. data.setItemGraphicEl(newIndex, el);
  39055. el.ignore = isClipped;
  39056. group.add(el);
  39057. }).remove(function (dataIndex) {
  39058. var el = oldData.getItemGraphicEl(dataIndex);
  39059. el && removeElementWithFadeOut(el, seriesModel, dataIndex);
  39060. }).execute();
  39061. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  39062. bgGroup.removeAll();
  39063. for (var i = 0; i < bgEls.length; ++i) {
  39064. bgGroup.add(bgEls[i]);
  39065. }
  39066. group.add(bgGroup);
  39067. this._backgroundEls = bgEls;
  39068. this._data = data;
  39069. };
  39070. BarView.prototype._renderLarge = function (seriesModel, ecModel, api) {
  39071. this._clear();
  39072. createLarge(seriesModel, this.group);
  39073. this._updateLargeClip(seriesModel);
  39074. };
  39075. BarView.prototype._incrementalRenderLarge = function (params, seriesModel) {
  39076. this._removeBackground();
  39077. createLarge(seriesModel, this.group, true);
  39078. };
  39079. BarView.prototype._updateLargeClip = function (seriesModel) {
  39080. // Use clipPath in large mode.
  39081. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  39082. if (clipPath) {
  39083. this.group.setClipPath(clipPath);
  39084. } else {
  39085. this.group.removeClipPath();
  39086. }
  39087. };
  39088. BarView.prototype._enableRealtimeSort = function (realtimeSortCfg, data, api) {
  39089. var _this = this; // If no data in the first frame, wait for data to initSort
  39090. if (!data.count()) {
  39091. return;
  39092. }
  39093. var baseAxis = realtimeSortCfg.baseAxis;
  39094. if (this._isFirstFrame) {
  39095. this._dispatchInitSort(data, realtimeSortCfg, api);
  39096. this._isFirstFrame = false;
  39097. } else {
  39098. var orderMapping_1 = function (idx) {
  39099. var el = data.getItemGraphicEl(idx);
  39100. if (el) {
  39101. var shape = el.shape; // If data is NaN, shape.xxx may be NaN, so use || 0 here in case
  39102. return (baseAxis.isHorizontal() // The result should be consistent with the initial sort by data value.
  39103. // Do not support the case that both positive and negative exist.
  39104. ? Math.abs(shape.height) : Math.abs(shape.width)) || 0;
  39105. } else {
  39106. return 0;
  39107. }
  39108. };
  39109. this._onRendered = function () {
  39110. _this._updateSortWithinSameData(data, orderMapping_1, baseAxis, api);
  39111. };
  39112. api.getZr().on('rendered', this._onRendered);
  39113. }
  39114. };
  39115. BarView.prototype._dataSort = function (data, baseAxis, orderMapping) {
  39116. var info = [];
  39117. data.each(data.mapDimension(baseAxis.dim), function (ordinalNumber, dataIdx) {
  39118. var mappedValue = orderMapping(dataIdx);
  39119. mappedValue = mappedValue == null ? NaN : mappedValue;
  39120. info.push({
  39121. dataIndex: dataIdx,
  39122. mappedValue: mappedValue,
  39123. ordinalNumber: ordinalNumber
  39124. });
  39125. });
  39126. info.sort(function (a, b) {
  39127. // If NaN, it will be treated as min val.
  39128. return b.mappedValue - a.mappedValue;
  39129. });
  39130. return {
  39131. ordinalNumbers: map(info, function (item) {
  39132. return item.ordinalNumber;
  39133. })
  39134. };
  39135. };
  39136. BarView.prototype._isOrderChangedWithinSameData = function (data, orderMapping, baseAxis) {
  39137. var scale = baseAxis.scale;
  39138. var ordinalDataDim = data.mapDimension(baseAxis.dim);
  39139. var lastValue = Number.MAX_VALUE;
  39140. for (var tickNum = 0, len = scale.getOrdinalMeta().categories.length; tickNum < len; ++tickNum) {
  39141. var rawIdx = data.rawIndexOf(ordinalDataDim, scale.getRawOrdinalNumber(tickNum));
  39142. var value = rawIdx < 0 // If some tick have no bar, the tick will be treated as min.
  39143. ? Number.MIN_VALUE // PENDING: if dataZoom on baseAxis exits, is it a performance issue?
  39144. : orderMapping(data.indexOfRawIndex(rawIdx));
  39145. if (value > lastValue) {
  39146. return true;
  39147. }
  39148. lastValue = value;
  39149. }
  39150. return false;
  39151. };
  39152. /*
  39153. * Consider the case when A and B changed order, whose representing
  39154. * bars are both out of sight, we don't wish to trigger reorder action
  39155. * as long as the order in the view doesn't change.
  39156. */
  39157. BarView.prototype._isOrderDifferentInView = function (orderInfo, baseAxis) {
  39158. var scale = baseAxis.scale;
  39159. var extent = scale.getExtent();
  39160. var tickNum = Math.max(0, extent[0]);
  39161. var tickMax = Math.min(extent[1], scale.getOrdinalMeta().categories.length - 1);
  39162. for (; tickNum <= tickMax; ++tickNum) {
  39163. if (orderInfo.ordinalNumbers[tickNum] !== scale.getRawOrdinalNumber(tickNum)) {
  39164. return true;
  39165. }
  39166. }
  39167. };
  39168. BarView.prototype._updateSortWithinSameData = function (data, orderMapping, baseAxis, api) {
  39169. if (!this._isOrderChangedWithinSameData(data, orderMapping, baseAxis)) {
  39170. return;
  39171. }
  39172. var sortInfo = this._dataSort(data, baseAxis, orderMapping);
  39173. if (this._isOrderDifferentInView(sortInfo, baseAxis)) {
  39174. this._removeOnRenderedListener(api);
  39175. api.dispatchAction({
  39176. type: 'changeAxisOrder',
  39177. componentType: baseAxis.dim + 'Axis',
  39178. axisId: baseAxis.index,
  39179. sortInfo: sortInfo
  39180. });
  39181. }
  39182. };
  39183. BarView.prototype._dispatchInitSort = function (data, realtimeSortCfg, api) {
  39184. var baseAxis = realtimeSortCfg.baseAxis;
  39185. var sortResult = this._dataSort(data, baseAxis, function (dataIdx) {
  39186. return data.get(data.mapDimension(realtimeSortCfg.otherAxis.dim), dataIdx);
  39187. });
  39188. api.dispatchAction({
  39189. type: 'changeAxisOrder',
  39190. componentType: baseAxis.dim + 'Axis',
  39191. isInitSort: true,
  39192. axisId: baseAxis.index,
  39193. sortInfo: sortResult
  39194. });
  39195. };
  39196. BarView.prototype.remove = function (ecModel, api) {
  39197. this._clear(this._model);
  39198. this._removeOnRenderedListener(api);
  39199. };
  39200. BarView.prototype.dispose = function (ecModel, api) {
  39201. this._removeOnRenderedListener(api);
  39202. };
  39203. BarView.prototype._removeOnRenderedListener = function (api) {
  39204. if (this._onRendered) {
  39205. api.getZr().off('rendered', this._onRendered);
  39206. this._onRendered = null;
  39207. }
  39208. };
  39209. BarView.prototype._clear = function (model) {
  39210. var group = this.group;
  39211. var data = this._data;
  39212. if (model && model.isAnimationEnabled() && data && !this._isLargeDraw) {
  39213. this._removeBackground();
  39214. this._backgroundEls = [];
  39215. data.eachItemGraphicEl(function (el) {
  39216. removeElementWithFadeOut(el, model, getECData(el).dataIndex);
  39217. });
  39218. } else {
  39219. group.removeAll();
  39220. }
  39221. this._data = null;
  39222. this._isFirstFrame = true;
  39223. };
  39224. BarView.prototype._removeBackground = function () {
  39225. this.group.remove(this._backgroundGroup);
  39226. this._backgroundGroup = null;
  39227. };
  39228. BarView.type = 'bar';
  39229. return BarView;
  39230. }(ChartView);
  39231. var clip = {
  39232. cartesian2d: function (coordSysBoundingRect, layout) {
  39233. var signWidth = layout.width < 0 ? -1 : 1;
  39234. var signHeight = layout.height < 0 ? -1 : 1; // Needs positive width and height
  39235. if (signWidth < 0) {
  39236. layout.x += layout.width;
  39237. layout.width = -layout.width;
  39238. }
  39239. if (signHeight < 0) {
  39240. layout.y += layout.height;
  39241. layout.height = -layout.height;
  39242. }
  39243. var coordSysX2 = coordSysBoundingRect.x + coordSysBoundingRect.width;
  39244. var coordSysY2 = coordSysBoundingRect.y + coordSysBoundingRect.height;
  39245. var x = mathMax$6(layout.x, coordSysBoundingRect.x);
  39246. var x2 = mathMin$6(layout.x + layout.width, coordSysX2);
  39247. var y = mathMax$6(layout.y, coordSysBoundingRect.y);
  39248. var y2 = mathMin$6(layout.y + layout.height, coordSysY2);
  39249. var xClipped = x2 < x;
  39250. var yClipped = y2 < y; // When xClipped or yClipped, the element will be marked as `ignore`.
  39251. // But we should also place the element at the edge of the coord sys bounding rect.
  39252. // Beause if data changed and the bar show again, its transition animaiton
  39253. // will begin at this place.
  39254. layout.x = xClipped && x > coordSysX2 ? x2 : x;
  39255. layout.y = yClipped && y > coordSysY2 ? y2 : y;
  39256. layout.width = xClipped ? 0 : x2 - x;
  39257. layout.height = yClipped ? 0 : y2 - y; // Reverse back
  39258. if (signWidth < 0) {
  39259. layout.x += layout.width;
  39260. layout.width = -layout.width;
  39261. }
  39262. if (signHeight < 0) {
  39263. layout.y += layout.height;
  39264. layout.height = -layout.height;
  39265. }
  39266. return xClipped || yClipped;
  39267. },
  39268. polar: function (coordSysClipArea, layout) {
  39269. var signR = layout.r0 <= layout.r ? 1 : -1; // Make sure r is larger than r0
  39270. if (signR < 0) {
  39271. var tmp = layout.r;
  39272. layout.r = layout.r0;
  39273. layout.r0 = tmp;
  39274. }
  39275. var r = mathMin$6(layout.r, coordSysClipArea.r);
  39276. var r0 = mathMax$6(layout.r0, coordSysClipArea.r0);
  39277. layout.r = r;
  39278. layout.r0 = r0;
  39279. var clipped = r - r0 < 0; // Reverse back
  39280. if (signR < 0) {
  39281. var tmp = layout.r;
  39282. layout.r = layout.r0;
  39283. layout.r0 = tmp;
  39284. }
  39285. return clipped;
  39286. }
  39287. };
  39288. var elementCreator = {
  39289. cartesian2d: function (seriesModel, data, newIndex, layout, isHorizontal, animationModel, axisModel, isUpdate, roundCap) {
  39290. var rect = new Rect({
  39291. shape: extend({}, layout),
  39292. z2: 1
  39293. });
  39294. rect.__dataIndex = newIndex;
  39295. rect.name = 'item';
  39296. if (animationModel) {
  39297. var rectShape = rect.shape;
  39298. var animateProperty = isHorizontal ? 'height' : 'width';
  39299. rectShape[animateProperty] = 0;
  39300. }
  39301. return rect;
  39302. },
  39303. polar: function (seriesModel, data, newIndex, layout, isRadial, animationModel, axisModel, isUpdate, roundCap) {
  39304. var ShapeClass = !isRadial && roundCap ? SausagePath : Sector;
  39305. var sector = new ShapeClass({
  39306. shape: layout,
  39307. z2: 1
  39308. });
  39309. sector.name = 'item';
  39310. var positionMap = createPolarPositionMapping(isRadial);
  39311. sector.calculateTextPosition = createSectorCalculateTextPosition(positionMap, {
  39312. isRoundCap: ShapeClass === SausagePath
  39313. }); // Animation
  39314. if (animationModel) {
  39315. var sectorShape = sector.shape;
  39316. var animateProperty = isRadial ? 'r' : 'endAngle';
  39317. var animateTarget = {};
  39318. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  39319. animateTarget[animateProperty] = layout[animateProperty];
  39320. (isUpdate ? updateProps : initProps)(sector, {
  39321. shape: animateTarget // __value: typeof dataValue === 'string' ? parseInt(dataValue, 10) : dataValue
  39322. }, animationModel);
  39323. }
  39324. return sector;
  39325. }
  39326. };
  39327. function shouldRealtimeSort(seriesModel, coordSys) {
  39328. var realtimeSortOption = seriesModel.get('realtimeSort', true);
  39329. var baseAxis = coordSys.getBaseAxis();
  39330. if ("development" !== 'production') {
  39331. if (realtimeSortOption) {
  39332. if (baseAxis.type !== 'category') {
  39333. warn('`realtimeSort` will not work because this bar series is not based on a category axis.');
  39334. }
  39335. if (coordSys.type !== 'cartesian2d') {
  39336. warn('`realtimeSort` will not work because this bar series is not on cartesian2d.');
  39337. }
  39338. }
  39339. }
  39340. if (realtimeSortOption && baseAxis.type === 'category' && coordSys.type === 'cartesian2d') {
  39341. return {
  39342. baseAxis: baseAxis,
  39343. otherAxis: coordSys.getOtherAxis(baseAxis)
  39344. };
  39345. }
  39346. }
  39347. function updateRealtimeAnimation(realtimeSortCfg, seriesAnimationModel, el, layout, newIndex, isHorizontal, isUpdate, isChangeOrder) {
  39348. var seriesTarget;
  39349. var axisTarget;
  39350. if (isHorizontal) {
  39351. axisTarget = {
  39352. x: layout.x,
  39353. width: layout.width
  39354. };
  39355. seriesTarget = {
  39356. y: layout.y,
  39357. height: layout.height
  39358. };
  39359. } else {
  39360. axisTarget = {
  39361. y: layout.y,
  39362. height: layout.height
  39363. };
  39364. seriesTarget = {
  39365. x: layout.x,
  39366. width: layout.width
  39367. };
  39368. }
  39369. if (!isChangeOrder) {
  39370. // Keep the original growth animation if only axis order changed.
  39371. // Not start a new animation.
  39372. (isUpdate ? updateProps : initProps)(el, {
  39373. shape: seriesTarget
  39374. }, seriesAnimationModel, newIndex, null);
  39375. }
  39376. var axisAnimationModel = seriesAnimationModel ? realtimeSortCfg.baseAxis.model : null;
  39377. (isUpdate ? updateProps : initProps)(el, {
  39378. shape: axisTarget
  39379. }, axisAnimationModel, newIndex);
  39380. }
  39381. function checkPropertiesNotValid(obj, props) {
  39382. for (var i = 0; i < props.length; i++) {
  39383. if (!isFinite(obj[props[i]])) {
  39384. return true;
  39385. }
  39386. }
  39387. return false;
  39388. }
  39389. var rectPropties = ['x', 'y', 'width', 'height'];
  39390. var polarPropties = ['cx', 'cy', 'r', 'startAngle', 'endAngle'];
  39391. var isValidLayout = {
  39392. cartesian2d: function (layout) {
  39393. return !checkPropertiesNotValid(layout, rectPropties);
  39394. },
  39395. polar: function (layout) {
  39396. return !checkPropertiesNotValid(layout, polarPropties);
  39397. }
  39398. };
  39399. var getLayout = {
  39400. // itemModel is only used to get borderWidth, which is not needed
  39401. // when calculating bar background layout.
  39402. cartesian2d: function (data, dataIndex, itemModel) {
  39403. var layout = data.getItemLayout(dataIndex);
  39404. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0; // fix layout with lineWidth
  39405. var signX = layout.width > 0 ? 1 : -1;
  39406. var signY = layout.height > 0 ? 1 : -1;
  39407. return {
  39408. x: layout.x + signX * fixedLineWidth / 2,
  39409. y: layout.y + signY * fixedLineWidth / 2,
  39410. width: layout.width - signX * fixedLineWidth,
  39411. height: layout.height - signY * fixedLineWidth
  39412. };
  39413. },
  39414. polar: function (data, dataIndex, itemModel) {
  39415. var layout = data.getItemLayout(dataIndex);
  39416. return {
  39417. cx: layout.cx,
  39418. cy: layout.cy,
  39419. r0: layout.r0,
  39420. r: layout.r,
  39421. startAngle: layout.startAngle,
  39422. endAngle: layout.endAngle,
  39423. clockwise: layout.clockwise
  39424. };
  39425. }
  39426. };
  39427. function isZeroOnPolar(layout) {
  39428. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  39429. }
  39430. function createPolarPositionMapping(isRadial) {
  39431. return function (isRadial) {
  39432. var arcOrAngle = isRadial ? 'Arc' : 'Angle';
  39433. return function (position) {
  39434. switch (position) {
  39435. case 'start':
  39436. case 'insideStart':
  39437. case 'end':
  39438. case 'insideEnd':
  39439. return position + arcOrAngle;
  39440. default:
  39441. return position;
  39442. }
  39443. };
  39444. }(isRadial);
  39445. }
  39446. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, isPolar) {
  39447. var style = data.getItemVisual(dataIndex, 'style');
  39448. if (!isPolar) {
  39449. el.setShape('r', itemModel.get(['itemStyle', 'borderRadius']) || 0);
  39450. }
  39451. el.useStyle(style);
  39452. var cursorStyle = itemModel.getShallow('cursor');
  39453. cursorStyle && el.attr('cursor', cursorStyle);
  39454. 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';
  39455. var labelStatesModels = getLabelStatesModels(itemModel);
  39456. setLabelStyle(el, labelStatesModels, {
  39457. labelFetcher: seriesModel,
  39458. labelDataIndex: dataIndex,
  39459. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  39460. inheritColor: style.fill,
  39461. defaultOpacity: style.opacity,
  39462. defaultOutsidePosition: labelPositionOutside
  39463. });
  39464. var label = el.getTextContent();
  39465. if (isPolar && label) {
  39466. var position = itemModel.get(['label', 'position']);
  39467. el.textConfig.inside = position === 'middle' ? true : null;
  39468. setSectorTextRotation(el, position === 'outside' ? labelPositionOutside : position, createPolarPositionMapping(isHorizontalOrRadial), itemModel.get(['label', 'rotate']));
  39469. }
  39470. setLabelValueAnimation(label, labelStatesModels, seriesModel.getRawValue(dataIndex), function (value) {
  39471. return getDefaultInterpolatedLabel(data, value);
  39472. });
  39473. var emphasisModel = itemModel.getModel(['emphasis']);
  39474. enableHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
  39475. setStatesStylesFromModel(el, itemModel);
  39476. if (isZeroOnPolar(layout)) {
  39477. el.style.fill = 'none';
  39478. el.style.stroke = 'none';
  39479. each(el.states, function (state) {
  39480. if (state.style) {
  39481. state.style.fill = state.style.stroke = 'none';
  39482. }
  39483. });
  39484. }
  39485. } // In case width or height are too small.
  39486. function getLineWidth(itemModel, rawLayout) {
  39487. // Has no border.
  39488. var borderColor = itemModel.get(['itemStyle', 'borderColor']);
  39489. if (!borderColor || borderColor === 'none') {
  39490. return 0;
  39491. }
  39492. var lineWidth = itemModel.get(['itemStyle', 'borderWidth']) || 0; // width or height may be NaN for empty data
  39493. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  39494. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  39495. return Math.min(lineWidth, width, height);
  39496. }
  39497. var LagePathShape =
  39498. /** @class */
  39499. function () {
  39500. function LagePathShape() {}
  39501. return LagePathShape;
  39502. }();
  39503. var LargePath =
  39504. /** @class */
  39505. function (_super) {
  39506. __extends(LargePath, _super);
  39507. function LargePath(opts) {
  39508. var _this = _super.call(this, opts) || this;
  39509. _this.type = 'largeBar';
  39510. return _this;
  39511. }
  39512. LargePath.prototype.getDefaultShape = function () {
  39513. return new LagePathShape();
  39514. };
  39515. LargePath.prototype.buildPath = function (ctx, shape) {
  39516. // Drawing lines is more efficient than drawing
  39517. // a whole line or drawing rects.
  39518. var points = shape.points;
  39519. var startPoint = this.__startPoint;
  39520. var baseDimIdx = this.__baseDimIdx;
  39521. for (var i = 0; i < points.length; i += 2) {
  39522. startPoint[baseDimIdx] = points[i + baseDimIdx];
  39523. ctx.moveTo(startPoint[0], startPoint[1]);
  39524. ctx.lineTo(points[i], points[i + 1]);
  39525. }
  39526. };
  39527. return LargePath;
  39528. }(Path);
  39529. function createLarge(seriesModel, group, incremental) {
  39530. // TODO support polar
  39531. var data = seriesModel.getData();
  39532. var startPoint = [];
  39533. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  39534. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  39535. var largeDataIndices = data.getLayout('largeDataIndices');
  39536. var barWidth = data.getLayout('barWidth');
  39537. var backgroundModel = seriesModel.getModel('backgroundStyle');
  39538. var drawBackground = seriesModel.get('showBackground', true);
  39539. if (drawBackground) {
  39540. var points = data.getLayout('largeBackgroundPoints');
  39541. var backgroundStartPoint = [];
  39542. backgroundStartPoint[1 - baseDimIdx] = data.getLayout('backgroundStart');
  39543. var bgEl = new LargePath({
  39544. shape: {
  39545. points: points
  39546. },
  39547. incremental: !!incremental,
  39548. silent: true,
  39549. z2: 0
  39550. });
  39551. bgEl.__startPoint = backgroundStartPoint;
  39552. bgEl.__baseDimIdx = baseDimIdx;
  39553. bgEl.__largeDataIndices = largeDataIndices;
  39554. bgEl.__barWidth = barWidth;
  39555. setLargeBackgroundStyle(bgEl, backgroundModel, data);
  39556. group.add(bgEl);
  39557. }
  39558. var el = new LargePath({
  39559. shape: {
  39560. points: data.getLayout('largePoints')
  39561. },
  39562. incremental: !!incremental
  39563. });
  39564. el.__startPoint = startPoint;
  39565. el.__baseDimIdx = baseDimIdx;
  39566. el.__largeDataIndices = largeDataIndices;
  39567. el.__barWidth = barWidth;
  39568. group.add(el);
  39569. setLargeStyle(el, seriesModel, data); // Enable tooltip and user mouse/touch event handlers.
  39570. getECData(el).seriesIndex = seriesModel.seriesIndex;
  39571. if (!seriesModel.get('silent')) {
  39572. el.on('mousedown', largePathUpdateDataIndex);
  39573. el.on('mousemove', largePathUpdateDataIndex);
  39574. }
  39575. } // Use throttle to avoid frequently traverse to find dataIndex.
  39576. var largePathUpdateDataIndex = throttle(function (event) {
  39577. var largePath = this;
  39578. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  39579. getECData(largePath).dataIndex = dataIndex >= 0 ? dataIndex : null;
  39580. }, 30, false);
  39581. function largePathFindDataIndex(largePath, x, y) {
  39582. var baseDimIdx = largePath.__baseDimIdx;
  39583. var valueDimIdx = 1 - baseDimIdx;
  39584. var points = largePath.shape.points;
  39585. var largeDataIndices = largePath.__largeDataIndices;
  39586. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  39587. var startValueVal = largePath.__startPoint[valueDimIdx];
  39588. _eventPos[0] = x;
  39589. _eventPos[1] = y;
  39590. var pointerBaseVal = _eventPos[baseDimIdx];
  39591. var pointerValueVal = _eventPos[1 - baseDimIdx];
  39592. var baseLowerBound = pointerBaseVal - barWidthHalf;
  39593. var baseUpperBound = pointerBaseVal + barWidthHalf;
  39594. for (var i = 0, len = points.length / 2; i < len; i++) {
  39595. var ii = i * 2;
  39596. var barBaseVal = points[ii + baseDimIdx];
  39597. var barValueVal = points[ii + valueDimIdx];
  39598. if (barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound && (startValueVal <= barValueVal ? pointerValueVal >= startValueVal && pointerValueVal <= barValueVal : pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)) {
  39599. return largeDataIndices[i];
  39600. }
  39601. }
  39602. return -1;
  39603. }
  39604. function setLargeStyle(el, seriesModel, data) {
  39605. var globalStyle = data.getVisual('style');
  39606. el.useStyle(extend({}, globalStyle)); // Use stroke instead of fill.
  39607. el.style.fill = null;
  39608. el.style.stroke = globalStyle.fill;
  39609. el.style.lineWidth = data.getLayout('barWidth');
  39610. }
  39611. function setLargeBackgroundStyle(el, backgroundModel, data) {
  39612. var borderColor = backgroundModel.get('borderColor') || backgroundModel.get('color');
  39613. var itemStyle = backgroundModel.getItemStyle();
  39614. el.useStyle(itemStyle);
  39615. el.style.fill = null;
  39616. el.style.stroke = borderColor;
  39617. el.style.lineWidth = data.getLayout('barWidth');
  39618. }
  39619. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  39620. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  39621. var rectShape = layout;
  39622. var coordLayout = coord.getArea();
  39623. return {
  39624. x: isHorizontalOrRadial ? rectShape.x : coordLayout.x,
  39625. y: isHorizontalOrRadial ? coordLayout.y : rectShape.y,
  39626. width: isHorizontalOrRadial ? rectShape.width : coordLayout.width,
  39627. height: isHorizontalOrRadial ? coordLayout.height : rectShape.height
  39628. };
  39629. } else {
  39630. var coordLayout = coord.getArea();
  39631. var sectorShape = layout;
  39632. return {
  39633. cx: coordLayout.cx,
  39634. cy: coordLayout.cy,
  39635. r0: isHorizontalOrRadial ? coordLayout.r0 : sectorShape.r0,
  39636. r: isHorizontalOrRadial ? coordLayout.r : sectorShape.r,
  39637. startAngle: isHorizontalOrRadial ? sectorShape.startAngle : 0,
  39638. endAngle: isHorizontalOrRadial ? sectorShape.endAngle : Math.PI * 2
  39639. };
  39640. }
  39641. }
  39642. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  39643. var ElementClz = coord.type === 'polar' ? Sector : Rect;
  39644. return new ElementClz({
  39645. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  39646. silent: true,
  39647. z2: 0
  39648. });
  39649. }
  39650. function install$3(registers) {
  39651. registers.registerChartView(BarView);
  39652. registers.registerSeriesModel(BarSeriesModel);
  39653. registers.registerLayout(registers.PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar')); // Use higher prority to avoid to be blocked by other overall layout, which do not
  39654. // only exist in this module, but probably also exist in other modules, like `barPolar`.
  39655. registers.registerLayout(registers.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, largeLayout); // Down sample after filter
  39656. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('bar'));
  39657. /**
  39658. * @payload
  39659. * @property {string} [componentType=series]
  39660. * @property {number} [dx]
  39661. * @property {number} [dy]
  39662. * @property {number} [zoom]
  39663. * @property {number} [originX]
  39664. * @property {number} [originY]
  39665. */
  39666. registers.registerAction({
  39667. type: 'changeAxisOrder',
  39668. event: 'changeAxisOrder',
  39669. update: 'update'
  39670. }, function (payload, ecModel) {
  39671. var componentType = payload.componentType || 'series';
  39672. ecModel.eachComponent({
  39673. mainType: componentType,
  39674. query: payload
  39675. }, function (componentModel) {
  39676. if (payload.sortInfo) {
  39677. componentModel.axis.setCategorySortInfo(payload.sortInfo);
  39678. }
  39679. });
  39680. });
  39681. }
  39682. var PI2$7 = Math.PI * 2;
  39683. var RADIAN = Math.PI / 180;
  39684. function getViewRect(seriesModel, api) {
  39685. return getLayoutRect(seriesModel.getBoxLayoutParams(), {
  39686. width: api.getWidth(),
  39687. height: api.getHeight()
  39688. });
  39689. }
  39690. function getBasicPieLayout(seriesModel, api) {
  39691. var viewRect = getViewRect(seriesModel, api);
  39692. var center = seriesModel.get('center');
  39693. var radius = seriesModel.get('radius');
  39694. if (!isArray(radius)) {
  39695. radius = [0, radius];
  39696. }
  39697. if (!isArray(center)) {
  39698. center = [center, center];
  39699. }
  39700. var width = parsePercent$1(viewRect.width, api.getWidth());
  39701. var height = parsePercent$1(viewRect.height, api.getHeight());
  39702. var size = Math.min(width, height);
  39703. var cx = parsePercent$1(center[0], width) + viewRect.x;
  39704. var cy = parsePercent$1(center[1], height) + viewRect.y;
  39705. var r0 = parsePercent$1(radius[0], size / 2);
  39706. var r = parsePercent$1(radius[1], size / 2);
  39707. return {
  39708. cx: cx,
  39709. cy: cy,
  39710. r0: r0,
  39711. r: r
  39712. };
  39713. }
  39714. function pieLayout(seriesType, ecModel, api) {
  39715. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  39716. var data = seriesModel.getData();
  39717. var valueDim = data.mapDimension('value');
  39718. var viewRect = getViewRect(seriesModel, api);
  39719. var _a = getBasicPieLayout(seriesModel, api),
  39720. cx = _a.cx,
  39721. cy = _a.cy,
  39722. r = _a.r,
  39723. r0 = _a.r0;
  39724. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  39725. var minAngle = seriesModel.get('minAngle') * RADIAN;
  39726. var validDataCount = 0;
  39727. data.each(valueDim, function (value) {
  39728. !isNaN(value) && validDataCount++;
  39729. });
  39730. var sum = data.getSum(valueDim); // Sum may be 0
  39731. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  39732. var clockwise = seriesModel.get('clockwise');
  39733. var roseType = seriesModel.get('roseType');
  39734. var stillShowZeroSum = seriesModel.get('stillShowZeroSum'); // [0...max]
  39735. var extent = data.getDataExtent(valueDim);
  39736. extent[0] = 0; // In the case some sector angle is smaller than minAngle
  39737. var restAngle = PI2$7;
  39738. var valueSumLargerThanMinAngle = 0;
  39739. var currentAngle = startAngle;
  39740. var dir = clockwise ? 1 : -1;
  39741. data.setLayout({
  39742. viewRect: viewRect,
  39743. r: r
  39744. });
  39745. data.each(valueDim, function (value, idx) {
  39746. var angle;
  39747. if (isNaN(value)) {
  39748. data.setItemLayout(idx, {
  39749. angle: NaN,
  39750. startAngle: NaN,
  39751. endAngle: NaN,
  39752. clockwise: clockwise,
  39753. cx: cx,
  39754. cy: cy,
  39755. r0: r0,
  39756. r: roseType ? NaN : r
  39757. });
  39758. return;
  39759. } // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  39760. if (roseType !== 'area') {
  39761. angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
  39762. } else {
  39763. angle = PI2$7 / validDataCount;
  39764. }
  39765. if (angle < minAngle) {
  39766. angle = minAngle;
  39767. restAngle -= minAngle;
  39768. } else {
  39769. valueSumLargerThanMinAngle += value;
  39770. }
  39771. var endAngle = currentAngle + dir * angle;
  39772. data.setItemLayout(idx, {
  39773. angle: angle,
  39774. startAngle: currentAngle,
  39775. endAngle: endAngle,
  39776. clockwise: clockwise,
  39777. cx: cx,
  39778. cy: cy,
  39779. r0: r0,
  39780. r: roseType ? linearMap(value, extent, [r0, r]) : r
  39781. });
  39782. currentAngle = endAngle;
  39783. }); // Some sector is constrained by minAngle
  39784. // Rest sectors needs recalculate angle
  39785. if (restAngle < PI2$7 && validDataCount) {
  39786. // Average the angle if rest angle is not enough after all angles is
  39787. // Constrained by minAngle
  39788. if (restAngle <= 1e-3) {
  39789. var angle_1 = PI2$7 / validDataCount;
  39790. data.each(valueDim, function (value, idx) {
  39791. if (!isNaN(value)) {
  39792. var layout_1 = data.getItemLayout(idx);
  39793. layout_1.angle = angle_1;
  39794. layout_1.startAngle = startAngle + dir * idx * angle_1;
  39795. layout_1.endAngle = startAngle + dir * (idx + 1) * angle_1;
  39796. }
  39797. });
  39798. } else {
  39799. unitRadian = restAngle / valueSumLargerThanMinAngle;
  39800. currentAngle = startAngle;
  39801. data.each(valueDim, function (value, idx) {
  39802. if (!isNaN(value)) {
  39803. var layout_2 = data.getItemLayout(idx);
  39804. var angle = layout_2.angle === minAngle ? minAngle : value * unitRadian;
  39805. layout_2.startAngle = currentAngle;
  39806. layout_2.endAngle = currentAngle + dir * angle;
  39807. currentAngle += dir * angle;
  39808. }
  39809. });
  39810. }
  39811. }
  39812. });
  39813. }
  39814. /*
  39815. * Licensed to the Apache Software Foundation (ASF) under one
  39816. * or more contributor license agreements. See the NOTICE file
  39817. * distributed with this work for additional information
  39818. * regarding copyright ownership. The ASF licenses this file
  39819. * to you under the Apache License, Version 2.0 (the
  39820. * "License"); you may not use this file except in compliance
  39821. * with the License. You may obtain a copy of the License at
  39822. *
  39823. * http://www.apache.org/licenses/LICENSE-2.0
  39824. *
  39825. * Unless required by applicable law or agreed to in writing,
  39826. * software distributed under the License is distributed on an
  39827. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39828. * KIND, either express or implied. See the License for the
  39829. * specific language governing permissions and limitations
  39830. * under the License.
  39831. */
  39832. /**
  39833. * AUTO-GENERATED FILE. DO NOT MODIFY.
  39834. */
  39835. /*
  39836. * Licensed to the Apache Software Foundation (ASF) under one
  39837. * or more contributor license agreements. See the NOTICE file
  39838. * distributed with this work for additional information
  39839. * regarding copyright ownership. The ASF licenses this file
  39840. * to you under the Apache License, Version 2.0 (the
  39841. * "License"); you may not use this file except in compliance
  39842. * with the License. You may obtain a copy of the License at
  39843. *
  39844. * http://www.apache.org/licenses/LICENSE-2.0
  39845. *
  39846. * Unless required by applicable law or agreed to in writing,
  39847. * software distributed under the License is distributed on an
  39848. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39849. * KIND, either express or implied. See the License for the
  39850. * specific language governing permissions and limitations
  39851. * under the License.
  39852. */
  39853. function dataFilter(seriesType) {
  39854. return {
  39855. seriesType: seriesType,
  39856. reset: function (seriesModel, ecModel) {
  39857. var legendModels = ecModel.findComponents({
  39858. mainType: 'legend'
  39859. });
  39860. if (!legendModels || !legendModels.length) {
  39861. return;
  39862. }
  39863. var data = seriesModel.getData();
  39864. data.filterSelf(function (idx) {
  39865. var name = data.getName(idx); // If in any legend component the status is not selected.
  39866. for (var i = 0; i < legendModels.length; i++) {
  39867. // @ts-ignore FIXME: LegendModel
  39868. if (!legendModels[i].isSelected(name)) {
  39869. return false;
  39870. }
  39871. }
  39872. return true;
  39873. });
  39874. }
  39875. };
  39876. }
  39877. var RADIAN$1 = Math.PI / 180;
  39878. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
  39879. if (list.length < 2) {
  39880. return;
  39881. }
  39882. function recalculateXOnSemiToAlignOnEllipseCurve(semi) {
  39883. var rB = semi.rB;
  39884. var rB2 = rB * rB;
  39885. for (var i = 0; i < semi.list.length; i++) {
  39886. var item = semi.list[i];
  39887. var dy = Math.abs(item.label.y - cy); // horizontal r is always same with original r because x is not changed.
  39888. var rA = r + item.len;
  39889. var rA2 = rA * rA; // Use ellipse implicit function to calculate x
  39890. var dx = Math.sqrt((1 - Math.abs(dy * dy / rB2)) * rA2);
  39891. item.label.x = cx + (dx + item.len2) * dir;
  39892. }
  39893. } // Adjust X based on the shifted y. Make tight labels aligned on an ellipse curve.
  39894. function recalculateX(items) {
  39895. // Extremes of
  39896. var topSemi = {
  39897. list: [],
  39898. maxY: 0
  39899. };
  39900. var bottomSemi = {
  39901. list: [],
  39902. maxY: 0
  39903. };
  39904. for (var i = 0; i < items.length; i++) {
  39905. if (items[i].labelAlignTo !== 'none') {
  39906. continue;
  39907. }
  39908. var item = items[i];
  39909. var semi = item.label.y > cy ? bottomSemi : topSemi;
  39910. var dy = Math.abs(item.label.y - cy);
  39911. if (dy > semi.maxY) {
  39912. var dx = item.label.x - cx - item.len2 * dir; // horizontal r is always same with original r because x is not changed.
  39913. var rA = r + item.len; // Canculate rB based on the topest / bottemest label.
  39914. var rB = Math.abs(dx) < rA ? Math.sqrt(dy * dy / (1 - dx * dx / rA / rA)) : rA;
  39915. semi.rB = rB;
  39916. semi.maxY = dy;
  39917. }
  39918. semi.list.push(item);
  39919. }
  39920. recalculateXOnSemiToAlignOnEllipseCurve(topSemi);
  39921. recalculateXOnSemiToAlignOnEllipseCurve(bottomSemi);
  39922. }
  39923. var len = list.length;
  39924. for (var i = 0; i < len; i++) {
  39925. if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
  39926. var dx = list[i].label.x - farthestX;
  39927. list[i].linePoints[1][0] += dx;
  39928. list[i].label.x = farthestX;
  39929. }
  39930. }
  39931. if (shiftLayoutOnY(list, viewTop, viewTop + viewHeight)) {
  39932. recalculateX(list);
  39933. }
  39934. }
  39935. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
  39936. var leftList = [];
  39937. var rightList = [];
  39938. var leftmostX = Number.MAX_VALUE;
  39939. var rightmostX = -Number.MAX_VALUE;
  39940. for (var i = 0; i < labelLayoutList.length; i++) {
  39941. var label = labelLayoutList[i].label;
  39942. if (isPositionCenter(labelLayoutList[i])) {
  39943. continue;
  39944. }
  39945. if (label.x < cx) {
  39946. leftmostX = Math.min(leftmostX, label.x);
  39947. leftList.push(labelLayoutList[i]);
  39948. } else {
  39949. rightmostX = Math.max(rightmostX, label.x);
  39950. rightList.push(labelLayoutList[i]);
  39951. }
  39952. }
  39953. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
  39954. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
  39955. for (var i = 0; i < labelLayoutList.length; i++) {
  39956. var layout = labelLayoutList[i];
  39957. var label = layout.label;
  39958. if (isPositionCenter(layout)) {
  39959. continue;
  39960. }
  39961. var linePoints = layout.linePoints;
  39962. if (linePoints) {
  39963. var isAlignToEdge = layout.labelAlignTo === 'edge';
  39964. var realTextWidth = layout.rect.width;
  39965. var targetTextWidth = void 0;
  39966. if (isAlignToEdge) {
  39967. if (label.x < cx) {
  39968. targetTextWidth = linePoints[2][0] - layout.labelDistance - viewLeft - layout.edgeDistance;
  39969. } else {
  39970. targetTextWidth = viewLeft + viewWidth - layout.edgeDistance - linePoints[2][0] - layout.labelDistance;
  39971. }
  39972. } else {
  39973. if (label.x < cx) {
  39974. targetTextWidth = label.x - viewLeft - layout.bleedMargin;
  39975. } else {
  39976. targetTextWidth = viewLeft + viewWidth - label.x - layout.bleedMargin;
  39977. }
  39978. }
  39979. if (targetTextWidth < layout.rect.width) {
  39980. // TODOTODO
  39981. // layout.text = textContain.truncateText(layout.text, targetTextWidth, layout.font);
  39982. layout.label.style.width = targetTextWidth;
  39983. if (layout.labelAlignTo === 'edge') {
  39984. realTextWidth = targetTextWidth; // realTextWidth = textContain.getWidth(layout.text, layout.font);
  39985. }
  39986. }
  39987. var dist = linePoints[1][0] - linePoints[2][0];
  39988. if (isAlignToEdge) {
  39989. if (label.x < cx) {
  39990. linePoints[2][0] = viewLeft + layout.edgeDistance + realTextWidth + layout.labelDistance;
  39991. } else {
  39992. linePoints[2][0] = viewLeft + viewWidth - layout.edgeDistance - realTextWidth - layout.labelDistance;
  39993. }
  39994. } else {
  39995. if (label.x < cx) {
  39996. linePoints[2][0] = label.x + layout.labelDistance;
  39997. } else {
  39998. linePoints[2][0] = label.x - layout.labelDistance;
  39999. }
  40000. linePoints[1][0] = linePoints[2][0] + dist;
  40001. }
  40002. linePoints[1][1] = linePoints[2][1] = label.y;
  40003. }
  40004. }
  40005. }
  40006. function isPositionCenter(sectorShape) {
  40007. // Not change x for center label
  40008. return sectorShape.position === 'center';
  40009. }
  40010. function pieLabelLayout(seriesModel) {
  40011. var data = seriesModel.getData();
  40012. var labelLayoutList = [];
  40013. var cx;
  40014. var cy;
  40015. var hasLabelRotate = false;
  40016. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  40017. var viewRect = data.getLayout('viewRect');
  40018. var r = data.getLayout('r');
  40019. var viewWidth = viewRect.width;
  40020. var viewLeft = viewRect.x;
  40021. var viewTop = viewRect.y;
  40022. var viewHeight = viewRect.height;
  40023. function setNotShow(el) {
  40024. el.ignore = true;
  40025. }
  40026. function isLabelShown(label) {
  40027. if (!label.ignore) {
  40028. return true;
  40029. }
  40030. for (var key in label.states) {
  40031. if (label.states[key].ignore === false) {
  40032. return true;
  40033. }
  40034. }
  40035. return false;
  40036. }
  40037. data.each(function (idx) {
  40038. var sector = data.getItemGraphicEl(idx);
  40039. var sectorShape = sector.shape;
  40040. var label = sector.getTextContent();
  40041. var labelLine = sector.getTextGuideLine();
  40042. var itemModel = data.getItemModel(idx);
  40043. var labelModel = itemModel.getModel('label'); // Use position in normal or emphasis
  40044. var labelPosition = labelModel.get('position') || itemModel.get(['emphasis', 'label', 'position']);
  40045. var labelDistance = labelModel.get('distanceToLabelLine');
  40046. var labelAlignTo = labelModel.get('alignTo');
  40047. var edgeDistance = parsePercent$1(labelModel.get('edgeDistance'), viewWidth);
  40048. var bleedMargin = labelModel.get('bleedMargin');
  40049. var labelLineModel = itemModel.getModel('labelLine');
  40050. var labelLineLen = labelLineModel.get('length');
  40051. labelLineLen = parsePercent$1(labelLineLen, viewWidth);
  40052. var labelLineLen2 = labelLineModel.get('length2');
  40053. labelLineLen2 = parsePercent$1(labelLineLen2, viewWidth);
  40054. if (Math.abs(sectorShape.endAngle - sectorShape.startAngle) < minShowLabelRadian) {
  40055. each(label.states, setNotShow);
  40056. label.ignore = true;
  40057. return;
  40058. }
  40059. if (!isLabelShown(label)) {
  40060. return;
  40061. }
  40062. var midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2;
  40063. var nx = Math.cos(midAngle);
  40064. var ny = Math.sin(midAngle);
  40065. var textX;
  40066. var textY;
  40067. var linePoints;
  40068. var textAlign;
  40069. cx = sectorShape.cx;
  40070. cy = sectorShape.cy;
  40071. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  40072. if (labelPosition === 'center') {
  40073. textX = sectorShape.cx;
  40074. textY = sectorShape.cy;
  40075. textAlign = 'center';
  40076. } else {
  40077. var x1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * nx : sectorShape.r * nx) + cx;
  40078. var y1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * ny : sectorShape.r * ny) + cy;
  40079. textX = x1 + nx * 3;
  40080. textY = y1 + ny * 3;
  40081. if (!isLabelInside) {
  40082. // For roseType
  40083. var x2 = x1 + nx * (labelLineLen + r - sectorShape.r);
  40084. var y2 = y1 + ny * (labelLineLen + r - sectorShape.r);
  40085. var x3 = x2 + (nx < 0 ? -1 : 1) * labelLineLen2;
  40086. var y3 = y2;
  40087. if (labelAlignTo === 'edge') {
  40088. // Adjust textX because text align of edge is opposite
  40089. textX = nx < 0 ? viewLeft + edgeDistance : viewLeft + viewWidth - edgeDistance;
  40090. } else {
  40091. textX = x3 + (nx < 0 ? -labelDistance : labelDistance);
  40092. }
  40093. textY = y3;
  40094. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  40095. }
  40096. textAlign = isLabelInside ? 'center' : labelAlignTo === 'edge' ? nx > 0 ? 'right' : 'left' : nx > 0 ? 'left' : 'right';
  40097. }
  40098. var labelRotate;
  40099. var rotate = labelModel.get('rotate');
  40100. if (typeof rotate === 'number') {
  40101. labelRotate = rotate * (Math.PI / 180);
  40102. } else if (labelPosition === 'center') {
  40103. labelRotate = 0;
  40104. } else {
  40105. var radialAngle = nx < 0 ? -midAngle + Math.PI : -midAngle;
  40106. if (rotate === 'radial' || rotate === true) {
  40107. labelRotate = radialAngle;
  40108. } else if (rotate === 'tangential' && labelPosition !== 'outside' && labelPosition !== 'outer') {
  40109. labelRotate = radialAngle + Math.PI / 2;
  40110. if (labelRotate > Math.PI / 2) {
  40111. labelRotate -= Math.PI;
  40112. }
  40113. } else {
  40114. labelRotate = 0;
  40115. }
  40116. }
  40117. hasLabelRotate = !!labelRotate;
  40118. label.x = textX;
  40119. label.y = textY;
  40120. label.rotation = labelRotate;
  40121. label.setStyle({
  40122. verticalAlign: 'middle'
  40123. }); // Not sectorShape the inside label
  40124. if (!isLabelInside) {
  40125. var textRect = label.getBoundingRect().clone();
  40126. textRect.applyTransform(label.getComputedTransform()); // Text has a default 1px stroke. Exclude this.
  40127. var margin = (label.style.margin || 0) + 2.1;
  40128. textRect.y -= margin / 2;
  40129. textRect.height += margin;
  40130. labelLayoutList.push({
  40131. label: label,
  40132. labelLine: labelLine,
  40133. position: labelPosition,
  40134. len: labelLineLen,
  40135. len2: labelLineLen2,
  40136. minTurnAngle: labelLineModel.get('minTurnAngle'),
  40137. maxSurfaceAngle: labelLineModel.get('maxSurfaceAngle'),
  40138. surfaceNormal: new Point(nx, ny),
  40139. linePoints: linePoints,
  40140. textAlign: textAlign,
  40141. labelDistance: labelDistance,
  40142. labelAlignTo: labelAlignTo,
  40143. edgeDistance: edgeDistance,
  40144. bleedMargin: bleedMargin,
  40145. rect: textRect
  40146. });
  40147. } else {
  40148. label.setStyle({
  40149. align: textAlign
  40150. });
  40151. var selectState = label.states.select;
  40152. if (selectState) {
  40153. selectState.x += label.x;
  40154. selectState.y += label.y;
  40155. }
  40156. }
  40157. sector.setTextConfig({
  40158. inside: isLabelInside
  40159. });
  40160. });
  40161. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  40162. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
  40163. }
  40164. for (var i = 0; i < labelLayoutList.length; i++) {
  40165. var layout = labelLayoutList[i];
  40166. var label = layout.label;
  40167. var labelLine = layout.labelLine;
  40168. var notShowLabel = isNaN(label.x) || isNaN(label.y);
  40169. if (label) {
  40170. label.setStyle({
  40171. align: layout.textAlign
  40172. });
  40173. if (notShowLabel) {
  40174. each(label.states, setNotShow);
  40175. label.ignore = true;
  40176. }
  40177. var selectState = label.states.select;
  40178. if (selectState) {
  40179. selectState.x += label.x;
  40180. selectState.y += label.y;
  40181. }
  40182. }
  40183. if (labelLine) {
  40184. var linePoints = layout.linePoints;
  40185. if (notShowLabel || !linePoints) {
  40186. each(labelLine.states, setNotShow);
  40187. labelLine.ignore = true;
  40188. } else {
  40189. limitTurnAngle(linePoints, layout.minTurnAngle);
  40190. limitSurfaceAngle(linePoints, layout.surfaceNormal, layout.maxSurfaceAngle);
  40191. labelLine.setShape({
  40192. points: linePoints
  40193. }); // Set the anchor to the midpoint of sector
  40194. label.__hostTarget.textGuideLineConfig = {
  40195. anchor: new Point(linePoints[0][0], linePoints[0][1])
  40196. };
  40197. }
  40198. }
  40199. }
  40200. }
  40201. function getSectorCornerRadius(model, shape, zeroIfNull) {
  40202. var cornerRadius = model.get('borderRadius');
  40203. if (cornerRadius == null) {
  40204. return zeroIfNull ? {
  40205. innerCornerRadius: 0,
  40206. cornerRadius: 0
  40207. } : null;
  40208. }
  40209. if (!isArray(cornerRadius)) {
  40210. cornerRadius = [cornerRadius, cornerRadius];
  40211. }
  40212. return {
  40213. innerCornerRadius: parsePercent(cornerRadius[0], shape.r0),
  40214. cornerRadius: parsePercent(cornerRadius[1], shape.r)
  40215. };
  40216. }
  40217. /**
  40218. * Piece of pie including Sector, Label, LabelLine
  40219. */
  40220. var PiePiece =
  40221. /** @class */
  40222. function (_super) {
  40223. __extends(PiePiece, _super);
  40224. function PiePiece(data, idx, startAngle) {
  40225. var _this = _super.call(this) || this;
  40226. _this.z2 = 2;
  40227. var text = new ZRText();
  40228. _this.setTextContent(text);
  40229. _this.updateData(data, idx, startAngle, true);
  40230. return _this;
  40231. }
  40232. PiePiece.prototype.updateData = function (data, idx, startAngle, firstCreate) {
  40233. var sector = this;
  40234. var seriesModel = data.hostModel;
  40235. var itemModel = data.getItemModel(idx);
  40236. var emphasisModel = itemModel.getModel('emphasis');
  40237. var layout = data.getItemLayout(idx); // cornerRadius & innerCornerRadius doesn't exist in the item layout. Use `0` if null value is specified.
  40238. // see `setItemLayout` in `pieLayout.ts`.
  40239. var sectorShape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout); // Ignore NaN data.
  40240. if (isNaN(sectorShape.startAngle)) {
  40241. // Use NaN shape to avoid drawing shape.
  40242. sector.setShape(sectorShape);
  40243. return;
  40244. }
  40245. if (firstCreate) {
  40246. sector.setShape(sectorShape);
  40247. var animationType = seriesModel.getShallow('animationType');
  40248. if (animationType === 'scale') {
  40249. sector.shape.r = layout.r0;
  40250. initProps(sector, {
  40251. shape: {
  40252. r: layout.r
  40253. }
  40254. }, seriesModel, idx);
  40255. } // Expansion
  40256. else {
  40257. if (startAngle != null) {
  40258. sector.setShape({
  40259. startAngle: startAngle,
  40260. endAngle: startAngle
  40261. });
  40262. initProps(sector, {
  40263. shape: {
  40264. startAngle: layout.startAngle,
  40265. endAngle: layout.endAngle
  40266. }
  40267. }, seriesModel, idx);
  40268. } else {
  40269. sector.shape.endAngle = layout.startAngle;
  40270. updateProps(sector, {
  40271. shape: {
  40272. endAngle: layout.endAngle
  40273. }
  40274. }, seriesModel, idx);
  40275. }
  40276. }
  40277. } else {
  40278. saveOldStyle(sector); // Transition animation from the old shape
  40279. updateProps(sector, {
  40280. shape: sectorShape
  40281. }, seriesModel, idx);
  40282. }
  40283. sector.useStyle(data.getItemVisual(idx, 'style'));
  40284. setStatesStylesFromModel(sector, itemModel);
  40285. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  40286. var offset = seriesModel.get('selectedOffset');
  40287. var dx = Math.cos(midAngle) * offset;
  40288. var dy = Math.sin(midAngle) * offset;
  40289. var cursorStyle = itemModel.getShallow('cursor');
  40290. cursorStyle && sector.attr('cursor', cursorStyle);
  40291. this._updateLabel(seriesModel, data, idx);
  40292. sector.ensureState('emphasis').shape = __assign({
  40293. r: layout.r + (emphasisModel.get('scale') ? emphasisModel.get('scaleSize') || 0 : 0)
  40294. }, getSectorCornerRadius(emphasisModel.getModel('itemStyle'), layout));
  40295. extend(sector.ensureState('select'), {
  40296. x: dx,
  40297. y: dy,
  40298. shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']), layout)
  40299. });
  40300. extend(sector.ensureState('blur'), {
  40301. shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']), layout)
  40302. });
  40303. var labelLine = sector.getTextGuideLine();
  40304. var labelText = sector.getTextContent();
  40305. labelLine && extend(labelLine.ensureState('select'), {
  40306. x: dx,
  40307. y: dy
  40308. }); // TODO: needs dx, dy in zrender?
  40309. extend(labelText.ensureState('select'), {
  40310. x: dx,
  40311. y: dy
  40312. });
  40313. enableHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
  40314. };
  40315. PiePiece.prototype._updateLabel = function (seriesModel, data, idx) {
  40316. var sector = this;
  40317. var itemModel = data.getItemModel(idx);
  40318. var labelLineModel = itemModel.getModel('labelLine');
  40319. var style = data.getItemVisual(idx, 'style');
  40320. var visualColor = style && style.fill;
  40321. var visualOpacity = style && style.opacity;
  40322. setLabelStyle(sector, getLabelStatesModels(itemModel), {
  40323. labelFetcher: data.hostModel,
  40324. labelDataIndex: idx,
  40325. inheritColor: visualColor,
  40326. defaultOpacity: visualOpacity,
  40327. defaultText: seriesModel.getFormattedLabel(idx, 'normal') || data.getName(idx)
  40328. });
  40329. var labelText = sector.getTextContent(); // Set textConfig on sector.
  40330. sector.setTextConfig({
  40331. // reset position, rotation
  40332. position: null,
  40333. rotation: null
  40334. }); // Make sure update style on labelText after setLabelStyle.
  40335. // Because setLabelStyle will replace a new style on it.
  40336. labelText.attr({
  40337. z2: 10
  40338. });
  40339. var labelPosition = seriesModel.get(['label', 'position']);
  40340. if (labelPosition !== 'outside' && labelPosition !== 'outer') {
  40341. sector.removeTextGuideLine();
  40342. } else {
  40343. var polyline = this.getTextGuideLine();
  40344. if (!polyline) {
  40345. polyline = new Polyline();
  40346. this.setTextGuideLine(polyline);
  40347. } // Default use item visual color
  40348. setLabelLineStyle(this, getLabelLineStatesModels(itemModel), {
  40349. stroke: visualColor,
  40350. opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1)
  40351. });
  40352. }
  40353. };
  40354. return PiePiece;
  40355. }(Sector); // Pie view
  40356. var PieView =
  40357. /** @class */
  40358. function (_super) {
  40359. __extends(PieView, _super);
  40360. function PieView() {
  40361. var _this = _super !== null && _super.apply(this, arguments) || this;
  40362. _this.ignoreLabelLineUpdate = true;
  40363. return _this;
  40364. }
  40365. PieView.prototype.init = function () {
  40366. var sectorGroup = new Group();
  40367. this._sectorGroup = sectorGroup;
  40368. };
  40369. PieView.prototype.render = function (seriesModel, ecModel, api, payload) {
  40370. var data = seriesModel.getData();
  40371. var oldData = this._data;
  40372. var group = this.group;
  40373. var startAngle; // First render
  40374. if (!oldData && data.count() > 0) {
  40375. var shape = data.getItemLayout(0);
  40376. for (var s = 1; isNaN(shape && shape.startAngle) && s < data.count(); ++s) {
  40377. shape = data.getItemLayout(s);
  40378. }
  40379. if (shape) {
  40380. startAngle = shape.startAngle;
  40381. }
  40382. } // remove empty-circle if it exists
  40383. if (this._emptyCircleSector) {
  40384. group.remove(this._emptyCircleSector);
  40385. } // when all data are filtered, show lightgray empty circle
  40386. if (data.count() === 0 && seriesModel.get('showEmptyCircle')) {
  40387. var sector = new Sector({
  40388. shape: getBasicPieLayout(seriesModel, api)
  40389. });
  40390. sector.useStyle(seriesModel.getModel('emptyCircleStyle').getItemStyle());
  40391. this._emptyCircleSector = sector;
  40392. group.add(sector);
  40393. }
  40394. data.diff(oldData).add(function (idx) {
  40395. var piePiece = new PiePiece(data, idx, startAngle);
  40396. data.setItemGraphicEl(idx, piePiece);
  40397. group.add(piePiece);
  40398. }).update(function (newIdx, oldIdx) {
  40399. var piePiece = oldData.getItemGraphicEl(oldIdx);
  40400. piePiece.updateData(data, newIdx, startAngle);
  40401. piePiece.off('click');
  40402. group.add(piePiece);
  40403. data.setItemGraphicEl(newIdx, piePiece);
  40404. }).remove(function (idx) {
  40405. var piePiece = oldData.getItemGraphicEl(idx);
  40406. removeElementWithFadeOut(piePiece, seriesModel, idx);
  40407. }).execute();
  40408. pieLabelLayout(seriesModel); // Always use initial animation.
  40409. if (seriesModel.get('animationTypeUpdate') !== 'expansion') {
  40410. this._data = data;
  40411. }
  40412. };
  40413. PieView.prototype.dispose = function () {};
  40414. PieView.prototype.containPoint = function (point, seriesModel) {
  40415. var data = seriesModel.getData();
  40416. var itemLayout = data.getItemLayout(0);
  40417. if (itemLayout) {
  40418. var dx = point[0] - itemLayout.cx;
  40419. var dy = point[1] - itemLayout.cy;
  40420. var radius = Math.sqrt(dx * dx + dy * dy);
  40421. return radius <= itemLayout.r && radius >= itemLayout.r0;
  40422. }
  40423. };
  40424. PieView.type = 'pie';
  40425. return PieView;
  40426. }(ChartView);
  40427. /**
  40428. * [Usage]:
  40429. * (1)
  40430. * createListSimply(seriesModel, ['value']);
  40431. * (2)
  40432. * createListSimply(seriesModel, {
  40433. * coordDimensions: ['value'],
  40434. * dimensionsCount: 5
  40435. * });
  40436. */
  40437. function createSeriesDataSimply(seriesModel, opt, nameList) {
  40438. opt = isArray(opt) && {
  40439. coordDimensions: opt
  40440. } || extend({
  40441. encodeDefine: seriesModel.getEncode()
  40442. }, opt);
  40443. var source = seriesModel.getSource();
  40444. var dimensions = prepareSeriesDataSchema(source, opt).dimensions;
  40445. var list = new SeriesData(dimensions, seriesModel);
  40446. list.initData(source, nameList);
  40447. return list;
  40448. }
  40449. /*
  40450. * Licensed to the Apache Software Foundation (ASF) under one
  40451. * or more contributor license agreements. See the NOTICE file
  40452. * distributed with this work for additional information
  40453. * regarding copyright ownership. The ASF licenses this file
  40454. * to you under the Apache License, Version 2.0 (the
  40455. * "License"); you may not use this file except in compliance
  40456. * with the License. You may obtain a copy of the License at
  40457. *
  40458. * http://www.apache.org/licenses/LICENSE-2.0
  40459. *
  40460. * Unless required by applicable law or agreed to in writing,
  40461. * software distributed under the License is distributed on an
  40462. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40463. * KIND, either express or implied. See the License for the
  40464. * specific language governing permissions and limitations
  40465. * under the License.
  40466. */
  40467. /**
  40468. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40469. */
  40470. /*
  40471. * Licensed to the Apache Software Foundation (ASF) under one
  40472. * or more contributor license agreements. See the NOTICE file
  40473. * distributed with this work for additional information
  40474. * regarding copyright ownership. The ASF licenses this file
  40475. * to you under the Apache License, Version 2.0 (the
  40476. * "License"); you may not use this file except in compliance
  40477. * with the License. You may obtain a copy of the License at
  40478. *
  40479. * http://www.apache.org/licenses/LICENSE-2.0
  40480. *
  40481. * Unless required by applicable law or agreed to in writing,
  40482. * software distributed under the License is distributed on an
  40483. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40484. * KIND, either express or implied. See the License for the
  40485. * specific language governing permissions and limitations
  40486. * under the License.
  40487. */
  40488. /**
  40489. * LegendVisualProvider is an bridge that pick encoded color from data and
  40490. * provide to the legend component.
  40491. */
  40492. var LegendVisualProvider =
  40493. /** @class */
  40494. function () {
  40495. function LegendVisualProvider( // Function to get data after filtered. It stores all the encoding info
  40496. getDataWithEncodedVisual, // Function to get raw data before filtered.
  40497. getRawData) {
  40498. this._getDataWithEncodedVisual = getDataWithEncodedVisual;
  40499. this._getRawData = getRawData;
  40500. }
  40501. LegendVisualProvider.prototype.getAllNames = function () {
  40502. var rawData = this._getRawData(); // We find the name from the raw data. In case it's filtered by the legend component.
  40503. // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
  40504. return rawData.mapArray(rawData.getName);
  40505. };
  40506. LegendVisualProvider.prototype.containName = function (name) {
  40507. var rawData = this._getRawData();
  40508. return rawData.indexOfName(name) >= 0;
  40509. };
  40510. LegendVisualProvider.prototype.indexOfName = function (name) {
  40511. // Only get data when necessary.
  40512. // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
  40513. // Invoking Series#getData immediately will throw an error.
  40514. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  40515. return dataWithEncodedVisual.indexOfName(name);
  40516. };
  40517. LegendVisualProvider.prototype.getItemVisual = function (dataIndex, key) {
  40518. // Get encoded visual properties from final filtered data.
  40519. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  40520. return dataWithEncodedVisual.getItemVisual(dataIndex, key);
  40521. };
  40522. return LegendVisualProvider;
  40523. }();
  40524. var PieSeriesModel =
  40525. /** @class */
  40526. function (_super) {
  40527. __extends(PieSeriesModel, _super);
  40528. function PieSeriesModel() {
  40529. return _super !== null && _super.apply(this, arguments) || this;
  40530. }
  40531. /**
  40532. * @overwrite
  40533. */
  40534. PieSeriesModel.prototype.init = function (option) {
  40535. _super.prototype.init.apply(this, arguments); // Enable legend selection for each data item
  40536. // Use a function instead of direct access because data reference may changed
  40537. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  40538. this._defaultLabelLine(option);
  40539. };
  40540. /**
  40541. * @overwrite
  40542. */
  40543. PieSeriesModel.prototype.mergeOption = function () {
  40544. _super.prototype.mergeOption.apply(this, arguments);
  40545. };
  40546. /**
  40547. * @overwrite
  40548. */
  40549. PieSeriesModel.prototype.getInitialData = function () {
  40550. return createSeriesDataSimply(this, {
  40551. coordDimensions: ['value'],
  40552. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  40553. });
  40554. };
  40555. /**
  40556. * @overwrite
  40557. */
  40558. PieSeriesModel.prototype.getDataParams = function (dataIndex) {
  40559. var data = this.getData();
  40560. var params = _super.prototype.getDataParams.call(this, dataIndex); // FIXME toFixed?
  40561. var valueList = [];
  40562. data.each(data.mapDimension('value'), function (value) {
  40563. valueList.push(value);
  40564. });
  40565. params.percent = getPercentWithPrecision(valueList, dataIndex, data.hostModel.get('percentPrecision'));
  40566. params.$vars.push('percent');
  40567. return params;
  40568. };
  40569. PieSeriesModel.prototype._defaultLabelLine = function (option) {
  40570. // Extend labelLine emphasis
  40571. defaultEmphasis(option, 'labelLine', ['show']);
  40572. var labelLineNormalOpt = option.labelLine;
  40573. var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
  40574. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  40575. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  40576. };
  40577. PieSeriesModel.type = 'series.pie';
  40578. PieSeriesModel.defaultOption = {
  40579. zlevel: 0,
  40580. z: 2,
  40581. legendHoverLink: true,
  40582. colorBy: 'data',
  40583. // 默认全局居中
  40584. center: ['50%', '50%'],
  40585. radius: [0, '75%'],
  40586. // 默认顺时针
  40587. clockwise: true,
  40588. startAngle: 90,
  40589. // 最小角度改为0
  40590. minAngle: 0,
  40591. // If the angle of a sector less than `minShowLabelAngle`,
  40592. // the label will not be displayed.
  40593. minShowLabelAngle: 0,
  40594. // 选中时扇区偏移量
  40595. selectedOffset: 10,
  40596. // 选择模式,默认关闭,可选single,multiple
  40597. // selectedMode: false,
  40598. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  40599. // roseType: null,
  40600. percentPrecision: 2,
  40601. // If still show when all data zero.
  40602. stillShowZeroSum: true,
  40603. // cursor: null,
  40604. left: 0,
  40605. top: 0,
  40606. right: 0,
  40607. bottom: 0,
  40608. width: null,
  40609. height: null,
  40610. label: {
  40611. // color: 'inherit',
  40612. // If rotate around circle
  40613. rotate: 0,
  40614. show: true,
  40615. overflow: 'truncate',
  40616. // 'outer', 'inside', 'center'
  40617. position: 'outer',
  40618. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  40619. alignTo: 'none',
  40620. // Closest distance between label and chart edge.
  40621. // Works only position is 'outer' and alignTo is 'edge'.
  40622. edgeDistance: '25%',
  40623. // Works only position is 'outer' and alignTo is not 'edge'.
  40624. bleedMargin: 10,
  40625. // Distance between text and label line.
  40626. distanceToLabelLine: 5 // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  40627. // 默认使用全局文本样式,详见TEXTSTYLE
  40628. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  40629. },
  40630. // Enabled when label.normal.position is 'outer'
  40631. labelLine: {
  40632. show: true,
  40633. // 引导线两段中的第一段长度
  40634. length: 15,
  40635. // 引导线两段中的第二段长度
  40636. length2: 15,
  40637. smooth: false,
  40638. minTurnAngle: 90,
  40639. maxSurfaceAngle: 90,
  40640. lineStyle: {
  40641. // color: 各异,
  40642. width: 1,
  40643. type: 'solid'
  40644. }
  40645. },
  40646. itemStyle: {
  40647. borderWidth: 1,
  40648. borderJoin: 'round'
  40649. },
  40650. showEmptyCircle: true,
  40651. emptyCircleStyle: {
  40652. color: 'lightgray',
  40653. opacity: 1
  40654. },
  40655. labelLayout: {
  40656. // Hide the overlapped label.
  40657. hideOverlap: true
  40658. },
  40659. emphasis: {
  40660. scale: true,
  40661. scaleSize: 5
  40662. },
  40663. // If use strategy to avoid label overlapping
  40664. avoidLabelOverlap: true,
  40665. // Animation type. Valid values: expansion, scale
  40666. animationType: 'expansion',
  40667. animationDuration: 1000,
  40668. // Animation type when update. Valid values: transition, expansion
  40669. animationTypeUpdate: 'transition',
  40670. animationEasingUpdate: 'cubicInOut',
  40671. animationDurationUpdate: 500,
  40672. animationEasing: 'cubicInOut'
  40673. };
  40674. return PieSeriesModel;
  40675. }(SeriesModel);
  40676. /*
  40677. * Licensed to the Apache Software Foundation (ASF) under one
  40678. * or more contributor license agreements. See the NOTICE file
  40679. * distributed with this work for additional information
  40680. * regarding copyright ownership. The ASF licenses this file
  40681. * to you under the Apache License, Version 2.0 (the
  40682. * "License"); you may not use this file except in compliance
  40683. * with the License. You may obtain a copy of the License at
  40684. *
  40685. * http://www.apache.org/licenses/LICENSE-2.0
  40686. *
  40687. * Unless required by applicable law or agreed to in writing,
  40688. * software distributed under the License is distributed on an
  40689. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40690. * KIND, either express or implied. See the License for the
  40691. * specific language governing permissions and limitations
  40692. * under the License.
  40693. */
  40694. /**
  40695. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40696. */
  40697. /*
  40698. * Licensed to the Apache Software Foundation (ASF) under one
  40699. * or more contributor license agreements. See the NOTICE file
  40700. * distributed with this work for additional information
  40701. * regarding copyright ownership. The ASF licenses this file
  40702. * to you under the Apache License, Version 2.0 (the
  40703. * "License"); you may not use this file except in compliance
  40704. * with the License. You may obtain a copy of the License at
  40705. *
  40706. * http://www.apache.org/licenses/LICENSE-2.0
  40707. *
  40708. * Unless required by applicable law or agreed to in writing,
  40709. * software distributed under the License is distributed on an
  40710. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40711. * KIND, either express or implied. See the License for the
  40712. * specific language governing permissions and limitations
  40713. * under the License.
  40714. */
  40715. function negativeDataFilter(seriesType) {
  40716. return {
  40717. seriesType: seriesType,
  40718. reset: function (seriesModel, ecModel) {
  40719. var data = seriesModel.getData();
  40720. data.filterSelf(function (idx) {
  40721. // handle negative value condition
  40722. var valueDim = data.mapDimension('value');
  40723. var curValue = data.get(valueDim, idx);
  40724. if (typeof curValue === 'number' && !isNaN(curValue) && curValue < 0) {
  40725. return false;
  40726. }
  40727. return true;
  40728. });
  40729. }
  40730. };
  40731. }
  40732. function install$4(registers) {
  40733. registers.registerChartView(PieView);
  40734. registers.registerSeriesModel(PieSeriesModel);
  40735. createLegacyDataSelectAction('pie', registers.registerAction);
  40736. registers.registerLayout(curry(pieLayout, 'pie'));
  40737. registers.registerProcessor(dataFilter('pie'));
  40738. registers.registerProcessor(negativeDataFilter('pie'));
  40739. }
  40740. var ScatterSeriesModel =
  40741. /** @class */
  40742. function (_super) {
  40743. __extends(ScatterSeriesModel, _super);
  40744. function ScatterSeriesModel() {
  40745. var _this = _super !== null && _super.apply(this, arguments) || this;
  40746. _this.type = ScatterSeriesModel.type;
  40747. _this.hasSymbolVisual = true;
  40748. return _this;
  40749. }
  40750. ScatterSeriesModel.prototype.getInitialData = function (option, ecModel) {
  40751. return createSeriesData(null, this, {
  40752. useEncodeDefaulter: true
  40753. });
  40754. };
  40755. ScatterSeriesModel.prototype.getProgressive = function () {
  40756. var progressive = this.option.progressive;
  40757. if (progressive == null) {
  40758. // PENDING
  40759. return this.option.large ? 5e3 : this.get('progressive');
  40760. }
  40761. return progressive;
  40762. };
  40763. ScatterSeriesModel.prototype.getProgressiveThreshold = function () {
  40764. var progressiveThreshold = this.option.progressiveThreshold;
  40765. if (progressiveThreshold == null) {
  40766. // PENDING
  40767. return this.option.large ? 1e4 : this.get('progressiveThreshold');
  40768. }
  40769. return progressiveThreshold;
  40770. };
  40771. ScatterSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  40772. return selectors.point(data.getItemLayout(dataIndex));
  40773. };
  40774. ScatterSeriesModel.type = 'series.scatter';
  40775. ScatterSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar'];
  40776. ScatterSeriesModel.defaultOption = {
  40777. coordinateSystem: 'cartesian2d',
  40778. zlevel: 0,
  40779. z: 2,
  40780. legendHoverLink: true,
  40781. symbolSize: 10,
  40782. // symbolRotate: null, // 图形旋转控制
  40783. large: false,
  40784. // Available when large is true
  40785. largeThreshold: 2000,
  40786. // cursor: null,
  40787. itemStyle: {
  40788. opacity: 0.8 // color: 各异
  40789. },
  40790. emphasis: {
  40791. scale: true
  40792. },
  40793. // If clip the overflow graphics
  40794. // Works on cartesian / polar series
  40795. clip: true,
  40796. select: {
  40797. itemStyle: {
  40798. borderColor: '#212121'
  40799. }
  40800. },
  40801. universalTransition: {
  40802. divideShape: 'clone'
  40803. } // progressive: null
  40804. };
  40805. return ScatterSeriesModel;
  40806. }(SeriesModel);
  40807. var BOOST_SIZE_THRESHOLD = 4;
  40808. var LargeSymbolPathShape =
  40809. /** @class */
  40810. function () {
  40811. function LargeSymbolPathShape() {}
  40812. return LargeSymbolPathShape;
  40813. }();
  40814. var LargeSymbolPath =
  40815. /** @class */
  40816. function (_super) {
  40817. __extends(LargeSymbolPath, _super);
  40818. function LargeSymbolPath(opts) {
  40819. return _super.call(this, opts) || this;
  40820. }
  40821. LargeSymbolPath.prototype.getDefaultShape = function () {
  40822. return new LargeSymbolPathShape();
  40823. };
  40824. LargeSymbolPath.prototype.buildPath = function (path, shape) {
  40825. var points = shape.points;
  40826. var size = shape.size;
  40827. var symbolProxy = this.symbolProxy;
  40828. var symbolProxyShape = symbolProxy.shape;
  40829. var ctx = path.getContext ? path.getContext() : path;
  40830. var canBoost = ctx && size[0] < BOOST_SIZE_THRESHOLD; // Do draw in afterBrush.
  40831. if (canBoost) {
  40832. this._ctx = ctx;
  40833. return;
  40834. }
  40835. this._ctx = null;
  40836. for (var i = 0; i < points.length;) {
  40837. var x = points[i++];
  40838. var y = points[i++];
  40839. if (isNaN(x) || isNaN(y)) {
  40840. continue;
  40841. }
  40842. if (this.softClipShape && !this.softClipShape.contain(x, y)) {
  40843. continue;
  40844. }
  40845. symbolProxyShape.x = x - size[0] / 2;
  40846. symbolProxyShape.y = y - size[1] / 2;
  40847. symbolProxyShape.width = size[0];
  40848. symbolProxyShape.height = size[1];
  40849. symbolProxy.buildPath(path, symbolProxyShape, true);
  40850. }
  40851. };
  40852. LargeSymbolPath.prototype.afterBrush = function () {
  40853. var shape = this.shape;
  40854. var points = shape.points;
  40855. var size = shape.size;
  40856. var ctx = this._ctx;
  40857. if (!ctx) {
  40858. return;
  40859. } // PENDING If style or other canvas status changed?
  40860. for (var i = 0; i < points.length;) {
  40861. var x = points[i++];
  40862. var y = points[i++];
  40863. if (isNaN(x) || isNaN(y)) {
  40864. continue;
  40865. }
  40866. if (this.softClipShape && !this.softClipShape.contain(x, y)) {
  40867. continue;
  40868. } // fillRect is faster than building a rect path and draw.
  40869. // And it support light globalCompositeOperation.
  40870. ctx.fillRect(x - size[0] / 2, y - size[1] / 2, size[0], size[1]);
  40871. }
  40872. };
  40873. LargeSymbolPath.prototype.findDataIndex = function (x, y) {
  40874. // TODO ???
  40875. // Consider transform
  40876. var shape = this.shape;
  40877. var points = shape.points;
  40878. var size = shape.size;
  40879. var w = Math.max(size[0], 4);
  40880. var h = Math.max(size[1], 4); // Not consider transform
  40881. // Treat each element as a rect
  40882. // top down traverse
  40883. for (var idx = points.length / 2 - 1; idx >= 0; idx--) {
  40884. var i = idx * 2;
  40885. var x0 = points[i] - w / 2;
  40886. var y0 = points[i + 1] - h / 2;
  40887. if (x >= x0 && y >= y0 && x <= x0 + w && y <= y0 + h) {
  40888. return idx;
  40889. }
  40890. }
  40891. return -1;
  40892. };
  40893. return LargeSymbolPath;
  40894. }(Path);
  40895. var LargeSymbolDraw =
  40896. /** @class */
  40897. function () {
  40898. function LargeSymbolDraw() {
  40899. this.group = new Group();
  40900. }
  40901. LargeSymbolDraw.prototype.isPersistent = function () {
  40902. return !this._incremental;
  40903. };
  40904. /**
  40905. * Update symbols draw by new data
  40906. */
  40907. LargeSymbolDraw.prototype.updateData = function (data, opt) {
  40908. this.group.removeAll();
  40909. var symbolEl = new LargeSymbolPath({
  40910. rectHover: true,
  40911. cursor: 'default'
  40912. });
  40913. symbolEl.setShape({
  40914. points: data.getLayout('points')
  40915. });
  40916. this._setCommon(symbolEl, data, false, opt);
  40917. this.group.add(symbolEl);
  40918. this._incremental = null;
  40919. };
  40920. LargeSymbolDraw.prototype.updateLayout = function (data) {
  40921. if (this._incremental) {
  40922. return;
  40923. }
  40924. var points = data.getLayout('points');
  40925. this.group.eachChild(function (child) {
  40926. if (child.startIndex != null) {
  40927. var len = (child.endIndex - child.startIndex) * 2;
  40928. var byteOffset = child.startIndex * 4 * 2;
  40929. points = new Float32Array(points.buffer, byteOffset, len);
  40930. }
  40931. child.setShape('points', points);
  40932. });
  40933. };
  40934. LargeSymbolDraw.prototype.incrementalPrepareUpdate = function (data) {
  40935. this.group.removeAll();
  40936. this._clearIncremental(); // Only use incremental displayables when data amount is larger than 2 million.
  40937. // PENDING Incremental data?
  40938. if (data.count() > 2e6) {
  40939. if (!this._incremental) {
  40940. this._incremental = new IncrementalDisplayable({
  40941. silent: true
  40942. });
  40943. }
  40944. this.group.add(this._incremental);
  40945. } else {
  40946. this._incremental = null;
  40947. }
  40948. };
  40949. LargeSymbolDraw.prototype.incrementalUpdate = function (taskParams, data, opt) {
  40950. var symbolEl;
  40951. if (this._incremental) {
  40952. symbolEl = new LargeSymbolPath();
  40953. this._incremental.addDisplayable(symbolEl, true);
  40954. } else {
  40955. symbolEl = new LargeSymbolPath({
  40956. rectHover: true,
  40957. cursor: 'default',
  40958. startIndex: taskParams.start,
  40959. endIndex: taskParams.end
  40960. });
  40961. symbolEl.incremental = true;
  40962. this.group.add(symbolEl);
  40963. }
  40964. symbolEl.setShape({
  40965. points: data.getLayout('points')
  40966. });
  40967. this._setCommon(symbolEl, data, !!this._incremental, opt);
  40968. };
  40969. LargeSymbolDraw.prototype._setCommon = function (symbolEl, data, isIncremental, opt) {
  40970. var hostModel = data.hostModel;
  40971. opt = opt || {};
  40972. var size = data.getVisual('symbolSize');
  40973. symbolEl.setShape('size', size instanceof Array ? size : [size, size]);
  40974. symbolEl.softClipShape = opt.clipShape || null; // Create symbolProxy to build path for each data
  40975. symbolEl.symbolProxy = createSymbol(data.getVisual('symbol'), 0, 0, 0, 0); // Use symbolProxy setColor method
  40976. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  40977. var extrudeShadow = symbolEl.shape.size[0] < BOOST_SIZE_THRESHOLD;
  40978. symbolEl.useStyle( // Draw shadow when doing fillRect is extremely slow.
  40979. hostModel.getModel('itemStyle').getItemStyle(extrudeShadow ? ['color', 'shadowBlur', 'shadowColor'] : ['color']));
  40980. var globalStyle = data.getVisual('style');
  40981. var visualColor = globalStyle && globalStyle.fill;
  40982. if (visualColor) {
  40983. symbolEl.setColor(visualColor);
  40984. }
  40985. if (!isIncremental) {
  40986. var ecData_1 = getECData(symbolEl); // Enable tooltip
  40987. // PENDING May have performance issue when path is extremely large
  40988. ecData_1.seriesIndex = hostModel.seriesIndex;
  40989. symbolEl.on('mousemove', function (e) {
  40990. ecData_1.dataIndex = null;
  40991. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  40992. if (dataIndex >= 0) {
  40993. // Provide dataIndex for tooltip
  40994. ecData_1.dataIndex = dataIndex + (symbolEl.startIndex || 0);
  40995. }
  40996. });
  40997. }
  40998. };
  40999. LargeSymbolDraw.prototype.remove = function () {
  41000. this._clearIncremental();
  41001. this._incremental = null;
  41002. this.group.removeAll();
  41003. };
  41004. LargeSymbolDraw.prototype._clearIncremental = function () {
  41005. var incremental = this._incremental;
  41006. if (incremental) {
  41007. incremental.clearDisplaybles();
  41008. }
  41009. };
  41010. return LargeSymbolDraw;
  41011. }();
  41012. var ScatterView =
  41013. /** @class */
  41014. function (_super) {
  41015. __extends(ScatterView, _super);
  41016. function ScatterView() {
  41017. var _this = _super !== null && _super.apply(this, arguments) || this;
  41018. _this.type = ScatterView.type;
  41019. return _this;
  41020. }
  41021. ScatterView.prototype.render = function (seriesModel, ecModel, api) {
  41022. var data = seriesModel.getData();
  41023. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  41024. symbolDraw.updateData(data, {
  41025. // TODO
  41026. // If this parameter should be a shape or a bounding volume
  41027. // shape will be more general.
  41028. // But bounding volume like bounding rect will be much faster in the contain calculation
  41029. clipShape: this._getClipShape(seriesModel)
  41030. });
  41031. this._finished = true;
  41032. };
  41033. ScatterView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  41034. var data = seriesModel.getData();
  41035. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  41036. symbolDraw.incrementalPrepareUpdate(data);
  41037. this._finished = false;
  41038. };
  41039. ScatterView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  41040. this._symbolDraw.incrementalUpdate(taskParams, seriesModel.getData(), {
  41041. clipShape: this._getClipShape(seriesModel)
  41042. });
  41043. this._finished = taskParams.end === seriesModel.getData().count();
  41044. };
  41045. ScatterView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  41046. var data = seriesModel.getData(); // Must mark group dirty and make sure the incremental layer will be cleared
  41047. // PENDING
  41048. this.group.dirty();
  41049. if (!this._finished || data.count() > 1e4 || !this._symbolDraw.isPersistent()) {
  41050. return {
  41051. update: true
  41052. };
  41053. } else {
  41054. var res = pointsLayout('').reset(seriesModel, ecModel, api);
  41055. if (res.progress) {
  41056. res.progress({
  41057. start: 0,
  41058. end: data.count(),
  41059. count: data.count()
  41060. }, data);
  41061. }
  41062. this._symbolDraw.updateLayout(data);
  41063. }
  41064. };
  41065. ScatterView.prototype._getClipShape = function (seriesModel) {
  41066. var coordSys = seriesModel.coordinateSystem;
  41067. var clipArea = coordSys && coordSys.getArea && coordSys.getArea();
  41068. return seriesModel.get('clip', true) ? clipArea : null;
  41069. };
  41070. ScatterView.prototype._updateSymbolDraw = function (data, seriesModel) {
  41071. var symbolDraw = this._symbolDraw;
  41072. var pipelineContext = seriesModel.pipelineContext;
  41073. var isLargeDraw = pipelineContext.large;
  41074. if (!symbolDraw || isLargeDraw !== this._isLargeDraw) {
  41075. symbolDraw && symbolDraw.remove();
  41076. symbolDraw = this._symbolDraw = isLargeDraw ? new LargeSymbolDraw() : new SymbolDraw();
  41077. this._isLargeDraw = isLargeDraw;
  41078. this.group.removeAll();
  41079. }
  41080. this.group.add(symbolDraw.group);
  41081. return symbolDraw;
  41082. };
  41083. ScatterView.prototype.remove = function (ecModel, api) {
  41084. this._symbolDraw && this._symbolDraw.remove(true);
  41085. this._symbolDraw = null;
  41086. };
  41087. ScatterView.prototype.dispose = function () {};
  41088. ScatterView.type = 'scatter';
  41089. return ScatterView;
  41090. }(ChartView);
  41091. var GridModel =
  41092. /** @class */
  41093. function (_super) {
  41094. __extends(GridModel, _super);
  41095. function GridModel() {
  41096. return _super !== null && _super.apply(this, arguments) || this;
  41097. }
  41098. GridModel.type = 'grid';
  41099. GridModel.dependencies = ['xAxis', 'yAxis'];
  41100. GridModel.layoutMode = 'box';
  41101. GridModel.defaultOption = {
  41102. show: false,
  41103. zlevel: 0,
  41104. z: 0,
  41105. left: '10%',
  41106. top: 60,
  41107. right: '10%',
  41108. bottom: 70,
  41109. // If grid size contain label
  41110. containLabel: false,
  41111. // width: {totalWidth} - left - right,
  41112. // height: {totalHeight} - top - bottom,
  41113. backgroundColor: 'rgba(0,0,0,0)',
  41114. borderWidth: 1,
  41115. borderColor: '#ccc'
  41116. };
  41117. return GridModel;
  41118. }(ComponentModel);
  41119. var CartesianAxisModel =
  41120. /** @class */
  41121. function (_super) {
  41122. __extends(CartesianAxisModel, _super);
  41123. function CartesianAxisModel() {
  41124. return _super !== null && _super.apply(this, arguments) || this;
  41125. }
  41126. CartesianAxisModel.prototype.getCoordSysModel = function () {
  41127. return this.getReferringComponents('grid', SINGLE_REFERRING).models[0];
  41128. };
  41129. CartesianAxisModel.type = 'cartesian2dAxis';
  41130. return CartesianAxisModel;
  41131. }(ComponentModel);
  41132. mixin(CartesianAxisModel, AxisModelCommonMixin);
  41133. var defaultOption = {
  41134. show: true,
  41135. zlevel: 0,
  41136. z: 0,
  41137. // Inverse the axis.
  41138. inverse: false,
  41139. // Axis name displayed.
  41140. name: '',
  41141. // 'start' | 'middle' | 'end'
  41142. nameLocation: 'end',
  41143. // By degree. By default auto rotate by nameLocation.
  41144. nameRotate: null,
  41145. nameTruncate: {
  41146. maxWidth: null,
  41147. ellipsis: '...',
  41148. placeholder: '.'
  41149. },
  41150. // Use global text style by default.
  41151. nameTextStyle: {},
  41152. // The gap between axisName and axisLine.
  41153. nameGap: 15,
  41154. // Default `false` to support tooltip.
  41155. silent: false,
  41156. // Default `false` to avoid legacy user event listener fail.
  41157. triggerEvent: false,
  41158. tooltip: {
  41159. show: false
  41160. },
  41161. axisPointer: {},
  41162. axisLine: {
  41163. show: true,
  41164. onZero: true,
  41165. onZeroAxisIndex: null,
  41166. lineStyle: {
  41167. color: '#6E7079',
  41168. width: 1,
  41169. type: 'solid'
  41170. },
  41171. // The arrow at both ends the the axis.
  41172. symbol: ['none', 'none'],
  41173. symbolSize: [10, 15]
  41174. },
  41175. axisTick: {
  41176. show: true,
  41177. // Whether axisTick is inside the grid or outside the grid.
  41178. inside: false,
  41179. // The length of axisTick.
  41180. length: 5,
  41181. lineStyle: {
  41182. width: 1
  41183. }
  41184. },
  41185. axisLabel: {
  41186. show: true,
  41187. // Whether axisLabel is inside the grid or outside the grid.
  41188. inside: false,
  41189. rotate: 0,
  41190. // true | false | null/undefined (auto)
  41191. showMinLabel: null,
  41192. // true | false | null/undefined (auto)
  41193. showMaxLabel: null,
  41194. margin: 8,
  41195. // formatter: null,
  41196. fontSize: 12
  41197. },
  41198. splitLine: {
  41199. show: true,
  41200. lineStyle: {
  41201. color: ['#E0E6F1'],
  41202. width: 1,
  41203. type: 'solid'
  41204. }
  41205. },
  41206. splitArea: {
  41207. show: false,
  41208. areaStyle: {
  41209. color: ['rgba(250,250,250,0.2)', 'rgba(210,219,238,0.2)']
  41210. }
  41211. }
  41212. };
  41213. var categoryAxis = merge({
  41214. // The gap at both ends of the axis. For categoryAxis, boolean.
  41215. boundaryGap: true,
  41216. // Set false to faster category collection.
  41217. deduplication: null,
  41218. // splitArea: {
  41219. // show: false
  41220. // },
  41221. splitLine: {
  41222. show: false
  41223. },
  41224. axisTick: {
  41225. // If tick is align with label when boundaryGap is true
  41226. alignWithLabel: false,
  41227. interval: 'auto'
  41228. },
  41229. axisLabel: {
  41230. interval: 'auto'
  41231. }
  41232. }, defaultOption);
  41233. var valueAxis = merge({
  41234. boundaryGap: [0, 0],
  41235. axisLine: {
  41236. // Not shown when other axis is categoryAxis in cartesian
  41237. show: 'auto'
  41238. },
  41239. axisTick: {
  41240. // Not shown when other axis is categoryAxis in cartesian
  41241. show: 'auto'
  41242. },
  41243. // TODO
  41244. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  41245. splitNumber: 5,
  41246. minorTick: {
  41247. // Minor tick, not available for cateogry axis.
  41248. show: false,
  41249. // Split number of minor ticks. The value should be in range of (0, 100)
  41250. splitNumber: 5,
  41251. // Lenght of minor tick
  41252. length: 3,
  41253. // Line style
  41254. lineStyle: {// Default to be same with axisTick
  41255. }
  41256. },
  41257. minorSplitLine: {
  41258. show: false,
  41259. lineStyle: {
  41260. color: '#F4F7FD',
  41261. width: 1
  41262. }
  41263. }
  41264. }, defaultOption);
  41265. var timeAxis = merge({
  41266. scale: true,
  41267. splitNumber: 6,
  41268. axisLabel: {
  41269. // To eliminate labels that are not nice
  41270. showMinLabel: false,
  41271. showMaxLabel: false,
  41272. rich: {
  41273. primary: {
  41274. fontWeight: 'bold'
  41275. }
  41276. }
  41277. },
  41278. splitLine: {
  41279. show: false
  41280. }
  41281. }, valueAxis);
  41282. var logAxis = defaults({
  41283. scale: true,
  41284. logBase: 10
  41285. }, valueAxis);
  41286. var axisDefault = {
  41287. category: categoryAxis,
  41288. value: valueAxis,
  41289. time: timeAxis,
  41290. log: logAxis
  41291. };
  41292. /*
  41293. * Licensed to the Apache Software Foundation (ASF) under one
  41294. * or more contributor license agreements. See the NOTICE file
  41295. * distributed with this work for additional information
  41296. * regarding copyright ownership. The ASF licenses this file
  41297. * to you under the Apache License, Version 2.0 (the
  41298. * "License"); you may not use this file except in compliance
  41299. * with the License. You may obtain a copy of the License at
  41300. *
  41301. * http://www.apache.org/licenses/LICENSE-2.0
  41302. *
  41303. * Unless required by applicable law or agreed to in writing,
  41304. * software distributed under the License is distributed on an
  41305. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41306. * KIND, either express or implied. See the License for the
  41307. * specific language governing permissions and limitations
  41308. * under the License.
  41309. */
  41310. /**
  41311. * AUTO-GENERATED FILE. DO NOT MODIFY.
  41312. */
  41313. /*
  41314. * Licensed to the Apache Software Foundation (ASF) under one
  41315. * or more contributor license agreements. See the NOTICE file
  41316. * distributed with this work for additional information
  41317. * regarding copyright ownership. The ASF licenses this file
  41318. * to you under the Apache License, Version 2.0 (the
  41319. * "License"); you may not use this file except in compliance
  41320. * with the License. You may obtain a copy of the License at
  41321. *
  41322. * http://www.apache.org/licenses/LICENSE-2.0
  41323. *
  41324. * Unless required by applicable law or agreed to in writing,
  41325. * software distributed under the License is distributed on an
  41326. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41327. * KIND, either express or implied. See the License for the
  41328. * specific language governing permissions and limitations
  41329. * under the License.
  41330. */
  41331. var AXIS_TYPES = {
  41332. value: 1,
  41333. category: 1,
  41334. time: 1,
  41335. log: 1
  41336. };
  41337. /**
  41338. * Generate sub axis model class
  41339. * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
  41340. */
  41341. function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
  41342. each(AXIS_TYPES, function (v, axisType) {
  41343. var defaultOption = merge(merge({}, axisDefault[axisType], true), extraDefaultOption, true);
  41344. var AxisModel =
  41345. /** @class */
  41346. function (_super) {
  41347. __extends(AxisModel, _super);
  41348. function AxisModel() {
  41349. var _this = _super !== null && _super.apply(this, arguments) || this;
  41350. _this.type = axisName + 'Axis.' + axisType;
  41351. return _this;
  41352. }
  41353. AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  41354. var layoutMode = fetchLayoutMode(this);
  41355. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  41356. var themeModel = ecModel.getTheme();
  41357. merge(option, themeModel.get(axisType + 'Axis'));
  41358. merge(option, this.getDefaultOption());
  41359. option.type = getAxisType(option);
  41360. if (layoutMode) {
  41361. mergeLayoutParam(option, inputPositionParams, layoutMode);
  41362. }
  41363. };
  41364. AxisModel.prototype.optionUpdated = function () {
  41365. var thisOption = this.option;
  41366. if (thisOption.type === 'category') {
  41367. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  41368. }
  41369. };
  41370. /**
  41371. * Should not be called before all of 'getInitailData' finished.
  41372. * Because categories are collected during initializing data.
  41373. */
  41374. AxisModel.prototype.getCategories = function (rawData) {
  41375. var option = this.option; // FIXME
  41376. // warning if called before all of 'getInitailData' finished.
  41377. if (option.type === 'category') {
  41378. if (rawData) {
  41379. return option.data;
  41380. }
  41381. return this.__ordinalMeta.categories;
  41382. }
  41383. };
  41384. AxisModel.prototype.getOrdinalMeta = function () {
  41385. return this.__ordinalMeta;
  41386. };
  41387. AxisModel.type = axisName + 'Axis.' + axisType;
  41388. AxisModel.defaultOption = defaultOption;
  41389. return AxisModel;
  41390. }(BaseAxisModelClass);
  41391. registers.registerComponentModel(AxisModel);
  41392. });
  41393. registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
  41394. }
  41395. function getAxisType(option) {
  41396. // Default axis with data is category axis
  41397. return option.type || (option.data ? 'category' : 'value');
  41398. }
  41399. var Cartesian =
  41400. /** @class */
  41401. function () {
  41402. function Cartesian(name) {
  41403. this.type = 'cartesian';
  41404. this._dimList = [];
  41405. this._axes = {};
  41406. this.name = name || '';
  41407. }
  41408. Cartesian.prototype.getAxis = function (dim) {
  41409. return this._axes[dim];
  41410. };
  41411. Cartesian.prototype.getAxes = function () {
  41412. return map(this._dimList, function (dim) {
  41413. return this._axes[dim];
  41414. }, this);
  41415. };
  41416. Cartesian.prototype.getAxesByScale = function (scaleType) {
  41417. scaleType = scaleType.toLowerCase();
  41418. return filter(this.getAxes(), function (axis) {
  41419. return axis.scale.type === scaleType;
  41420. });
  41421. };
  41422. Cartesian.prototype.addAxis = function (axis) {
  41423. var dim = axis.dim;
  41424. this._axes[dim] = axis;
  41425. this._dimList.push(dim);
  41426. };
  41427. return Cartesian;
  41428. }();
  41429. var cartesian2DDimensions = ['x', 'y'];
  41430. function canCalculateAffineTransform(scale) {
  41431. return scale.type === 'interval' || scale.type === 'time';
  41432. }
  41433. var Cartesian2D =
  41434. /** @class */
  41435. function (_super) {
  41436. __extends(Cartesian2D, _super);
  41437. function Cartesian2D() {
  41438. var _this = _super !== null && _super.apply(this, arguments) || this;
  41439. _this.type = 'cartesian2d';
  41440. _this.dimensions = cartesian2DDimensions;
  41441. return _this;
  41442. }
  41443. /**
  41444. * Calculate an affine transform matrix if two axes are time or value.
  41445. * It's mainly for accelartion on the large time series data.
  41446. */
  41447. Cartesian2D.prototype.calcAffineTransform = function () {
  41448. this._transform = this._invTransform = null;
  41449. var xAxisScale = this.getAxis('x').scale;
  41450. var yAxisScale = this.getAxis('y').scale;
  41451. if (!canCalculateAffineTransform(xAxisScale) || !canCalculateAffineTransform(yAxisScale)) {
  41452. return;
  41453. }
  41454. var xScaleExtent = xAxisScale.getExtent();
  41455. var yScaleExtent = yAxisScale.getExtent();
  41456. var start = this.dataToPoint([xScaleExtent[0], yScaleExtent[0]]);
  41457. var end = this.dataToPoint([xScaleExtent[1], yScaleExtent[1]]);
  41458. var xScaleSpan = xScaleExtent[1] - xScaleExtent[0];
  41459. var yScaleSpan = yScaleExtent[1] - yScaleExtent[0];
  41460. if (!xScaleSpan || !yScaleSpan) {
  41461. return;
  41462. } // Accelerate data to point calculation on the special large time series data.
  41463. var scaleX = (end[0] - start[0]) / xScaleSpan;
  41464. var scaleY = (end[1] - start[1]) / yScaleSpan;
  41465. var translateX = start[0] - xScaleExtent[0] * scaleX;
  41466. var translateY = start[1] - yScaleExtent[0] * scaleY;
  41467. var m = this._transform = [scaleX, 0, 0, scaleY, translateX, translateY];
  41468. this._invTransform = invert([], m);
  41469. };
  41470. /**
  41471. * Base axis will be used on stacking.
  41472. */
  41473. Cartesian2D.prototype.getBaseAxis = function () {
  41474. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
  41475. };
  41476. Cartesian2D.prototype.containPoint = function (point) {
  41477. var axisX = this.getAxis('x');
  41478. var axisY = this.getAxis('y');
  41479. return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
  41480. };
  41481. Cartesian2D.prototype.containData = function (data) {
  41482. return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
  41483. };
  41484. Cartesian2D.prototype.dataToPoint = function (data, clamp, out) {
  41485. out = out || [];
  41486. var xVal = data[0];
  41487. var yVal = data[1]; // Fast path
  41488. if (this._transform // It's supported that if data is like `[Inifity, 123]`, where only Y pixel calculated.
  41489. && xVal != null && isFinite(xVal) && yVal != null && isFinite(yVal)) {
  41490. return applyTransform(out, data, this._transform);
  41491. }
  41492. var xAxis = this.getAxis('x');
  41493. var yAxis = this.getAxis('y');
  41494. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(xVal, clamp));
  41495. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(yVal, clamp));
  41496. return out;
  41497. };
  41498. Cartesian2D.prototype.clampData = function (data, out) {
  41499. var xScale = this.getAxis('x').scale;
  41500. var yScale = this.getAxis('y').scale;
  41501. var xAxisExtent = xScale.getExtent();
  41502. var yAxisExtent = yScale.getExtent();
  41503. var x = xScale.parse(data[0]);
  41504. var y = yScale.parse(data[1]);
  41505. out = out || [];
  41506. out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
  41507. out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
  41508. return out;
  41509. };
  41510. Cartesian2D.prototype.pointToData = function (point, clamp) {
  41511. var out = [];
  41512. if (this._invTransform) {
  41513. return applyTransform(out, point, this._invTransform);
  41514. }
  41515. var xAxis = this.getAxis('x');
  41516. var yAxis = this.getAxis('y');
  41517. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp);
  41518. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp);
  41519. return out;
  41520. };
  41521. Cartesian2D.prototype.getOtherAxis = function (axis) {
  41522. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  41523. };
  41524. /**
  41525. * Get rect area of cartesian.
  41526. * Area will have a contain function to determine if a point is in the coordinate system.
  41527. */
  41528. Cartesian2D.prototype.getArea = function () {
  41529. var xExtent = this.getAxis('x').getGlobalExtent();
  41530. var yExtent = this.getAxis('y').getGlobalExtent();
  41531. var x = Math.min(xExtent[0], xExtent[1]);
  41532. var y = Math.min(yExtent[0], yExtent[1]);
  41533. var width = Math.max(xExtent[0], xExtent[1]) - x;
  41534. var height = Math.max(yExtent[0], yExtent[1]) - y;
  41535. return new BoundingRect(x, y, width, height);
  41536. };
  41537. return Cartesian2D;
  41538. }(Cartesian);
  41539. var Axis2D =
  41540. /** @class */
  41541. function (_super) {
  41542. __extends(Axis2D, _super);
  41543. function Axis2D(dim, scale, coordExtent, axisType, position) {
  41544. var _this = _super.call(this, dim, scale, coordExtent) || this;
  41545. /**
  41546. * Index of axis, can be used as key
  41547. * Injected outside.
  41548. */
  41549. _this.index = 0;
  41550. _this.type = axisType || 'value';
  41551. _this.position = position || 'bottom';
  41552. return _this;
  41553. }
  41554. Axis2D.prototype.isHorizontal = function () {
  41555. var position = this.position;
  41556. return position === 'top' || position === 'bottom';
  41557. };
  41558. /**
  41559. * Each item cooresponds to this.getExtent(), which
  41560. * means globalExtent[0] may greater than globalExtent[1],
  41561. * unless `asc` is input.
  41562. *
  41563. * @param {boolean} [asc]
  41564. * @return {Array.<number>}
  41565. */
  41566. Axis2D.prototype.getGlobalExtent = function (asc) {
  41567. var ret = this.getExtent();
  41568. ret[0] = this.toGlobalCoord(ret[0]);
  41569. ret[1] = this.toGlobalCoord(ret[1]);
  41570. asc && ret[0] > ret[1] && ret.reverse();
  41571. return ret;
  41572. };
  41573. Axis2D.prototype.pointToData = function (point, clamp) {
  41574. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  41575. };
  41576. /**
  41577. * Set ordinalSortInfo
  41578. * @param info new OrdinalSortInfo
  41579. */
  41580. Axis2D.prototype.setCategorySortInfo = function (info) {
  41581. if (this.type !== 'category') {
  41582. return false;
  41583. }
  41584. this.model.option.categorySortInfo = info;
  41585. this.scale.setSortInfo(info);
  41586. };
  41587. return Axis2D;
  41588. }(Axis);
  41589. /**
  41590. * Can only be called after coordinate system creation stage.
  41591. * (Can be called before coordinate system update stage).
  41592. */
  41593. function layout$1(gridModel, axisModel, opt) {
  41594. opt = opt || {};
  41595. var grid = gridModel.coordinateSystem;
  41596. var axis = axisModel.axis;
  41597. var layout = {};
  41598. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  41599. var rawAxisPosition = axis.position;
  41600. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  41601. var axisDim = axis.dim;
  41602. var rect = grid.getRect();
  41603. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  41604. var idx = {
  41605. left: 0,
  41606. right: 1,
  41607. top: 0,
  41608. bottom: 1,
  41609. onZero: 2
  41610. };
  41611. var axisOffset = axisModel.get('offset') || 0;
  41612. var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  41613. if (otherAxisOnZeroOf) {
  41614. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  41615. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  41616. } // Axis position
  41617. layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]]; // Axis rotation
  41618. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1); // Tick and label direction, x y is axisDim
  41619. var dirMap = {
  41620. top: -1,
  41621. bottom: 1,
  41622. left: -1,
  41623. right: 1
  41624. };
  41625. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  41626. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  41627. if (axisModel.get(['axisTick', 'inside'])) {
  41628. layout.tickDirection = -layout.tickDirection;
  41629. }
  41630. if (retrieve(opt.labelInside, axisModel.get(['axisLabel', 'inside']))) {
  41631. layout.labelDirection = -layout.labelDirection;
  41632. } // Special label rotation
  41633. var labelRotate = axisModel.get(['axisLabel', 'rotate']);
  41634. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate; // Over splitLine and splitArea
  41635. layout.z2 = 1;
  41636. return layout;
  41637. }
  41638. function isCartesian2DSeries(seriesModel) {
  41639. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  41640. }
  41641. function findAxisModels(seriesModel) {
  41642. var axisModelMap = {
  41643. xAxisModel: null,
  41644. yAxisModel: null
  41645. };
  41646. each(axisModelMap, function (v, key) {
  41647. var axisType = key.replace(/Model$/, '');
  41648. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  41649. if ("development" !== 'production') {
  41650. if (!axisModel) {
  41651. throw new Error(axisType + ' "' + retrieve3(seriesModel.get(axisType + 'Index'), seriesModel.get(axisType + 'Id'), 0) + '" not found');
  41652. }
  41653. }
  41654. axisModelMap[key] = axisModel;
  41655. });
  41656. return axisModelMap;
  41657. }
  41658. var Grid =
  41659. /** @class */
  41660. function () {
  41661. function Grid(gridModel, ecModel, api) {
  41662. // FIXME:TS where used (different from registered type 'cartesian2d')?
  41663. this.type = 'grid';
  41664. this._coordsMap = {};
  41665. this._coordsList = [];
  41666. this._axesMap = {};
  41667. this._axesList = [];
  41668. this.axisPointerEnabled = true;
  41669. this.dimensions = cartesian2DDimensions;
  41670. this._initCartesian(gridModel, ecModel, api);
  41671. this.model = gridModel;
  41672. }
  41673. Grid.prototype.getRect = function () {
  41674. return this._rect;
  41675. };
  41676. Grid.prototype.update = function (ecModel, api) {
  41677. var axesMap = this._axesMap;
  41678. this._updateScale(ecModel, this.model);
  41679. each(axesMap.x, function (xAxis) {
  41680. niceScaleExtent(xAxis.scale, xAxis.model);
  41681. });
  41682. each(axesMap.y, function (yAxis) {
  41683. niceScaleExtent(yAxis.scale, yAxis.model);
  41684. }); // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  41685. var onZeroRecords = {};
  41686. each(axesMap.x, function (xAxis) {
  41687. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  41688. });
  41689. each(axesMap.y, function (yAxis) {
  41690. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  41691. }); // Resize again if containLabel is enabled
  41692. // FIXME It may cause getting wrong grid size in data processing stage
  41693. this.resize(this.model, api);
  41694. };
  41695. /**
  41696. * Resize the grid
  41697. */
  41698. Grid.prototype.resize = function (gridModel, api, ignoreContainLabel) {
  41699. var boxLayoutParams = gridModel.getBoxLayoutParams();
  41700. var isContainLabel = !ignoreContainLabel && gridModel.get('containLabel');
  41701. var gridRect = getLayoutRect(boxLayoutParams, {
  41702. width: api.getWidth(),
  41703. height: api.getHeight()
  41704. });
  41705. this._rect = gridRect;
  41706. var axesList = this._axesList;
  41707. adjustAxes(); // Minus label size
  41708. if (isContainLabel) {
  41709. each(axesList, function (axis) {
  41710. if (!axis.model.get(['axisLabel', 'inside'])) {
  41711. var labelUnionRect = estimateLabelUnionRect(axis);
  41712. if (labelUnionRect) {
  41713. var dim = axis.isHorizontal() ? 'height' : 'width';
  41714. var margin = axis.model.get(['axisLabel', 'margin']);
  41715. gridRect[dim] -= labelUnionRect[dim] + margin;
  41716. if (axis.position === 'top') {
  41717. gridRect.y += labelUnionRect.height + margin;
  41718. } else if (axis.position === 'left') {
  41719. gridRect.x += labelUnionRect.width + margin;
  41720. }
  41721. }
  41722. }
  41723. });
  41724. adjustAxes();
  41725. }
  41726. each(this._coordsList, function (coord) {
  41727. // Calculate affine matrix to accelerate the data to point transform.
  41728. // If all the axes scales are time or value.
  41729. coord.calcAffineTransform();
  41730. });
  41731. function adjustAxes() {
  41732. each(axesList, function (axis) {
  41733. var isHorizontal = axis.isHorizontal();
  41734. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  41735. var idx = axis.inverse ? 1 : 0;
  41736. axis.setExtent(extent[idx], extent[1 - idx]);
  41737. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  41738. });
  41739. }
  41740. };
  41741. Grid.prototype.getAxis = function (dim, axisIndex) {
  41742. var axesMapOnDim = this._axesMap[dim];
  41743. if (axesMapOnDim != null) {
  41744. return axesMapOnDim[axisIndex || 0]; // if (axisIndex == null) {
  41745. // Find first axis
  41746. // for (let name in axesMapOnDim) {
  41747. // if (axesMapOnDim.hasOwnProperty(name)) {
  41748. // return axesMapOnDim[name];
  41749. // }
  41750. // }
  41751. // }
  41752. // return axesMapOnDim[axisIndex];
  41753. }
  41754. };
  41755. Grid.prototype.getAxes = function () {
  41756. return this._axesList.slice();
  41757. };
  41758. Grid.prototype.getCartesian = function (xAxisIndex, yAxisIndex) {
  41759. if (xAxisIndex != null && yAxisIndex != null) {
  41760. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  41761. return this._coordsMap[key];
  41762. }
  41763. if (isObject(xAxisIndex)) {
  41764. yAxisIndex = xAxisIndex.yAxisIndex;
  41765. xAxisIndex = xAxisIndex.xAxisIndex;
  41766. }
  41767. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  41768. if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
  41769. return coordList[i];
  41770. }
  41771. }
  41772. };
  41773. Grid.prototype.getCartesians = function () {
  41774. return this._coordsList.slice();
  41775. };
  41776. /**
  41777. * @implements
  41778. */
  41779. Grid.prototype.convertToPixel = function (ecModel, finder, value) {
  41780. var target = this._findConvertTarget(finder);
  41781. return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
  41782. };
  41783. /**
  41784. * @implements
  41785. */
  41786. Grid.prototype.convertFromPixel = function (ecModel, finder, value) {
  41787. var target = this._findConvertTarget(finder);
  41788. return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
  41789. };
  41790. Grid.prototype._findConvertTarget = function (finder) {
  41791. var seriesModel = finder.seriesModel;
  41792. var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  41793. var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  41794. var gridModel = finder.gridModel;
  41795. var coordsList = this._coordsList;
  41796. var cartesian;
  41797. var axis;
  41798. if (seriesModel) {
  41799. cartesian = seriesModel.coordinateSystem;
  41800. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  41801. } else if (xAxisModel && yAxisModel) {
  41802. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  41803. } else if (xAxisModel) {
  41804. axis = this.getAxis('x', xAxisModel.componentIndex);
  41805. } else if (yAxisModel) {
  41806. axis = this.getAxis('y', yAxisModel.componentIndex);
  41807. } // Lowest priority.
  41808. else if (gridModel) {
  41809. var grid = gridModel.coordinateSystem;
  41810. if (grid === this) {
  41811. cartesian = this._coordsList[0];
  41812. }
  41813. }
  41814. return {
  41815. cartesian: cartesian,
  41816. axis: axis
  41817. };
  41818. };
  41819. /**
  41820. * @implements
  41821. */
  41822. Grid.prototype.containPoint = function (point) {
  41823. var coord = this._coordsList[0];
  41824. if (coord) {
  41825. return coord.containPoint(point);
  41826. }
  41827. };
  41828. /**
  41829. * Initialize cartesian coordinate systems
  41830. */
  41831. Grid.prototype._initCartesian = function (gridModel, ecModel, api) {
  41832. var _this = this;
  41833. var grid = this;
  41834. var axisPositionUsed = {
  41835. left: false,
  41836. right: false,
  41837. top: false,
  41838. bottom: false
  41839. };
  41840. var axesMap = {
  41841. x: {},
  41842. y: {}
  41843. };
  41844. var axesCount = {
  41845. x: 0,
  41846. y: 0
  41847. }; /// Create axis
  41848. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  41849. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  41850. if (!axesCount.x || !axesCount.y) {
  41851. // Roll back when there no either x or y axis
  41852. this._axesMap = {};
  41853. this._axesList = [];
  41854. return;
  41855. }
  41856. this._axesMap = axesMap; /// Create cartesian2d
  41857. each(axesMap.x, function (xAxis, xAxisIndex) {
  41858. each(axesMap.y, function (yAxis, yAxisIndex) {
  41859. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  41860. var cartesian = new Cartesian2D(key);
  41861. cartesian.master = _this;
  41862. cartesian.model = gridModel;
  41863. _this._coordsMap[key] = cartesian;
  41864. _this._coordsList.push(cartesian);
  41865. cartesian.addAxis(xAxis);
  41866. cartesian.addAxis(yAxis);
  41867. });
  41868. });
  41869. function createAxisCreator(dimName) {
  41870. return function (axisModel, idx) {
  41871. if (!isAxisUsedInTheGrid(axisModel, gridModel)) {
  41872. return;
  41873. }
  41874. var axisPosition = axisModel.get('position');
  41875. if (dimName === 'x') {
  41876. // Fix position
  41877. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  41878. // Default bottom of X
  41879. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  41880. }
  41881. } else {
  41882. // Fix position
  41883. if (axisPosition !== 'left' && axisPosition !== 'right') {
  41884. // Default left of Y
  41885. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  41886. }
  41887. }
  41888. axisPositionUsed[axisPosition] = true;
  41889. var axis = new Axis2D(dimName, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
  41890. var isCategory = axis.type === 'category';
  41891. axis.onBand = isCategory && axisModel.get('boundaryGap');
  41892. axis.inverse = axisModel.get('inverse'); // Inject axis into axisModel
  41893. axisModel.axis = axis; // Inject axisModel into axis
  41894. axis.model = axisModel; // Inject grid info axis
  41895. axis.grid = grid; // Index of axis, can be used as key
  41896. axis.index = idx;
  41897. grid._axesList.push(axis);
  41898. axesMap[dimName][idx] = axis;
  41899. axesCount[dimName]++;
  41900. };
  41901. }
  41902. };
  41903. /**
  41904. * Update cartesian properties from series.
  41905. */
  41906. Grid.prototype._updateScale = function (ecModel, gridModel) {
  41907. // Reset scale
  41908. each(this._axesList, function (axis) {
  41909. axis.scale.setExtent(Infinity, -Infinity);
  41910. if (axis.type === 'category') {
  41911. var categorySortInfo = axis.model.get('categorySortInfo');
  41912. axis.scale.setSortInfo(categorySortInfo);
  41913. }
  41914. });
  41915. ecModel.eachSeries(function (seriesModel) {
  41916. if (isCartesian2DSeries(seriesModel)) {
  41917. var axesModelMap = findAxisModels(seriesModel);
  41918. var xAxisModel = axesModelMap.xAxisModel;
  41919. var yAxisModel = axesModelMap.yAxisModel;
  41920. if (!isAxisUsedInTheGrid(xAxisModel, gridModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel)) {
  41921. return;
  41922. }
  41923. var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  41924. var data = seriesModel.getData();
  41925. var xAxis = cartesian.getAxis('x');
  41926. var yAxis = cartesian.getAxis('y');
  41927. if (data.type === 'list') {
  41928. unionExtent(data, xAxis);
  41929. unionExtent(data, yAxis);
  41930. }
  41931. }
  41932. }, this);
  41933. function unionExtent(data, axis) {
  41934. each(getDataDimensionsOnAxis(data, axis.dim), function (dim) {
  41935. axis.scale.unionExtentFromData(data, dim);
  41936. });
  41937. }
  41938. };
  41939. /**
  41940. * @param dim 'x' or 'y' or 'auto' or null/undefined
  41941. */
  41942. Grid.prototype.getTooltipAxes = function (dim) {
  41943. var baseAxes = [];
  41944. var otherAxes = [];
  41945. each(this.getCartesians(), function (cartesian) {
  41946. var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  41947. var otherAxis = cartesian.getOtherAxis(baseAxis);
  41948. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  41949. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  41950. });
  41951. return {
  41952. baseAxes: baseAxes,
  41953. otherAxes: otherAxes
  41954. };
  41955. };
  41956. Grid.create = function (ecModel, api) {
  41957. var grids = [];
  41958. ecModel.eachComponent('grid', function (gridModel, idx) {
  41959. var grid = new Grid(gridModel, ecModel, api);
  41960. grid.name = 'grid_' + idx; // dataSampling requires axis extent, so resize
  41961. // should be performed in create stage.
  41962. grid.resize(gridModel, api, true);
  41963. gridModel.coordinateSystem = grid;
  41964. grids.push(grid);
  41965. }); // Inject the coordinateSystems into seriesModel
  41966. ecModel.eachSeries(function (seriesModel) {
  41967. if (!isCartesian2DSeries(seriesModel)) {
  41968. return;
  41969. }
  41970. var axesModelMap = findAxisModels(seriesModel);
  41971. var xAxisModel = axesModelMap.xAxisModel;
  41972. var yAxisModel = axesModelMap.yAxisModel;
  41973. var gridModel = xAxisModel.getCoordSysModel();
  41974. if ("development" !== 'production') {
  41975. if (!gridModel) {
  41976. throw new Error('Grid "' + retrieve3(xAxisModel.get('gridIndex'), xAxisModel.get('gridId'), 0) + '" not found');
  41977. }
  41978. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  41979. throw new Error('xAxis and yAxis must use the same grid');
  41980. }
  41981. }
  41982. var grid = gridModel.coordinateSystem;
  41983. seriesModel.coordinateSystem = grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  41984. });
  41985. return grids;
  41986. }; // For deciding which dimensions to use when creating list data
  41987. Grid.dimensions = cartesian2DDimensions;
  41988. return Grid;
  41989. }();
  41990. /**
  41991. * Check if the axis is used in the specified grid.
  41992. */
  41993. function isAxisUsedInTheGrid(axisModel, gridModel) {
  41994. return axisModel.getCoordSysModel() === gridModel;
  41995. }
  41996. function fixAxisOnZero(axesMap, otherAxisDim, axis, // Key: see `getOnZeroRecordKey`
  41997. onZeroRecords) {
  41998. axis.getAxesOnZeroOf = function () {
  41999. // TODO: onZero of multiple axes.
  42000. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  42001. }; // onZero can not be enabled in these two situations:
  42002. // 1. When any other axis is a category axis.
  42003. // 2. When no axis is cross 0 point.
  42004. var otherAxes = axesMap[otherAxisDim];
  42005. var otherAxisOnZeroOf;
  42006. var axisModel = axis.model;
  42007. var onZero = axisModel.get(['axisLine', 'onZero']);
  42008. var onZeroAxisIndex = axisModel.get(['axisLine', 'onZeroAxisIndex']);
  42009. if (!onZero) {
  42010. return;
  42011. } // If target axis is specified.
  42012. if (onZeroAxisIndex != null) {
  42013. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  42014. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  42015. }
  42016. } else {
  42017. // Find the first available other axis.
  42018. for (var idx in otherAxes) {
  42019. if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx]) // Consider that two Y axes on one value axis,
  42020. // if both onZero, the two Y axes overlap.
  42021. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
  42022. otherAxisOnZeroOf = otherAxes[idx];
  42023. break;
  42024. }
  42025. }
  42026. }
  42027. if (otherAxisOnZeroOf) {
  42028. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  42029. }
  42030. function getOnZeroRecordKey(axis) {
  42031. return axis.dim + '_' + axis.index;
  42032. }
  42033. }
  42034. function canOnZeroToAxis(axis) {
  42035. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  42036. }
  42037. function updateAxisTransform(axis, coordBase) {
  42038. var axisExtent = axis.getExtent();
  42039. var axisExtentSum = axisExtent[0] + axisExtent[1]; // Fast transform
  42040. axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
  42041. return coord + coordBase;
  42042. } : function (coord) {
  42043. return axisExtentSum - coord + coordBase;
  42044. };
  42045. axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
  42046. return coord - coordBase;
  42047. } : function (coord) {
  42048. return axisExtentSum - coord + coordBase;
  42049. };
  42050. }
  42051. var PI$5 = Math.PI;
  42052. /**
  42053. * A final axis is translated and rotated from a "standard axis".
  42054. * So opt.position and opt.rotation is required.
  42055. *
  42056. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  42057. * for example: (0, 0) ------------> (0, 50)
  42058. *
  42059. * nameDirection or tickDirection or labelDirection is 1 means tick
  42060. * or label is below the standard axis, whereas is -1 means above
  42061. * the standard axis. labelOffset means offset between label and axis,
  42062. * which is useful when 'onZero', where axisLabel is in the grid and
  42063. * label in outside grid.
  42064. *
  42065. * Tips: like always,
  42066. * positive rotation represents anticlockwise, and negative rotation
  42067. * represents clockwise.
  42068. * The direction of position coordinate is the same as the direction
  42069. * of screen coordinate.
  42070. *
  42071. * Do not need to consider axis 'inverse', which is auto processed by
  42072. * axis extent.
  42073. */
  42074. var AxisBuilder =
  42075. /** @class */
  42076. function () {
  42077. function AxisBuilder(axisModel, opt) {
  42078. this.group = new Group();
  42079. this.opt = opt;
  42080. this.axisModel = axisModel; // Default value
  42081. defaults(opt, {
  42082. labelOffset: 0,
  42083. nameDirection: 1,
  42084. tickDirection: 1,
  42085. labelDirection: 1,
  42086. silent: true,
  42087. handleAutoShown: function () {
  42088. return true;
  42089. }
  42090. }); // FIXME Not use a seperate text group?
  42091. var transformGroup = new Group({
  42092. x: opt.position[0],
  42093. y: opt.position[1],
  42094. rotation: opt.rotation
  42095. }); // this.group.add(transformGroup);
  42096. // this._transformGroup = transformGroup;
  42097. transformGroup.updateTransform();
  42098. this._transformGroup = transformGroup;
  42099. }
  42100. AxisBuilder.prototype.hasBuilder = function (name) {
  42101. return !!builders[name];
  42102. };
  42103. AxisBuilder.prototype.add = function (name) {
  42104. builders[name](this.opt, this.axisModel, this.group, this._transformGroup);
  42105. };
  42106. AxisBuilder.prototype.getGroup = function () {
  42107. return this.group;
  42108. };
  42109. AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  42110. var rotationDiff = remRadian(textRotation - axisRotation);
  42111. var textAlign;
  42112. var textVerticalAlign;
  42113. if (isRadianAroundZero(rotationDiff)) {
  42114. // Label is parallel with axis line.
  42115. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  42116. textAlign = 'center';
  42117. } else if (isRadianAroundZero(rotationDiff - PI$5)) {
  42118. // Label is inverse parallel with axis line.
  42119. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  42120. textAlign = 'center';
  42121. } else {
  42122. textVerticalAlign = 'middle';
  42123. if (rotationDiff > 0 && rotationDiff < PI$5) {
  42124. textAlign = direction > 0 ? 'right' : 'left';
  42125. } else {
  42126. textAlign = direction > 0 ? 'left' : 'right';
  42127. }
  42128. }
  42129. return {
  42130. rotation: rotationDiff,
  42131. textAlign: textAlign,
  42132. textVerticalAlign: textVerticalAlign
  42133. };
  42134. };
  42135. AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  42136. var eventData = {
  42137. componentType: axisModel.mainType,
  42138. componentIndex: axisModel.componentIndex
  42139. };
  42140. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  42141. return eventData;
  42142. };
  42143. AxisBuilder.isLabelSilent = function (axisModel) {
  42144. var tooltipOpt = axisModel.get('tooltip');
  42145. return axisModel.get('silent') // Consider mouse cursor, add these restrictions.
  42146. || !(axisModel.get('triggerEvent') || tooltipOpt && tooltipOpt.show);
  42147. };
  42148. return AxisBuilder;
  42149. }();
  42150. var builders = {
  42151. axisLine: function (opt, axisModel, group, transformGroup) {
  42152. var shown = axisModel.get(['axisLine', 'show']);
  42153. if (shown === 'auto' && opt.handleAutoShown) {
  42154. shown = opt.handleAutoShown('axisLine');
  42155. }
  42156. if (!shown) {
  42157. return;
  42158. }
  42159. var extent = axisModel.axis.getExtent();
  42160. var matrix = transformGroup.transform;
  42161. var pt1 = [extent[0], 0];
  42162. var pt2 = [extent[1], 0];
  42163. if (matrix) {
  42164. applyTransform(pt1, pt1, matrix);
  42165. applyTransform(pt2, pt2, matrix);
  42166. }
  42167. var lineStyle = extend({
  42168. lineCap: 'round'
  42169. }, axisModel.getModel(['axisLine', 'lineStyle']).getLineStyle());
  42170. var line = new Line({
  42171. // Id for animation
  42172. subPixelOptimize: true,
  42173. shape: {
  42174. x1: pt1[0],
  42175. y1: pt1[1],
  42176. x2: pt2[0],
  42177. y2: pt2[1]
  42178. },
  42179. style: lineStyle,
  42180. strokeContainThreshold: opt.strokeContainThreshold || 5,
  42181. silent: true,
  42182. z2: 1
  42183. });
  42184. line.anid = 'line';
  42185. group.add(line);
  42186. var arrows = axisModel.get(['axisLine', 'symbol']);
  42187. if (arrows != null) {
  42188. var arrowSize = axisModel.get(['axisLine', 'symbolSize']);
  42189. if (typeof arrows === 'string') {
  42190. // Use the same arrow for start and end point
  42191. arrows = [arrows, arrows];
  42192. }
  42193. if (typeof arrowSize === 'string' || typeof arrowSize === 'number') {
  42194. // Use the same size for width and height
  42195. arrowSize = [arrowSize, arrowSize];
  42196. }
  42197. var arrowOffset = normalizeSymbolOffset(axisModel.get(['axisLine', 'symbolOffset']) || 0, arrowSize);
  42198. var symbolWidth_1 = arrowSize[0];
  42199. var symbolHeight_1 = arrowSize[1];
  42200. each([{
  42201. rotate: opt.rotation + Math.PI / 2,
  42202. offset: arrowOffset[0],
  42203. r: 0
  42204. }, {
  42205. rotate: opt.rotation - Math.PI / 2,
  42206. offset: arrowOffset[1],
  42207. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  42208. }], function (point, index) {
  42209. if (arrows[index] !== 'none' && arrows[index] != null) {
  42210. var symbol = createSymbol(arrows[index], -symbolWidth_1 / 2, -symbolHeight_1 / 2, symbolWidth_1, symbolHeight_1, lineStyle.stroke, true); // Calculate arrow position with offset
  42211. var r = point.r + point.offset;
  42212. symbol.attr({
  42213. rotation: point.rotate,
  42214. x: pt1[0] + r * Math.cos(opt.rotation),
  42215. y: pt1[1] - r * Math.sin(opt.rotation),
  42216. silent: true,
  42217. z2: 11
  42218. });
  42219. group.add(symbol);
  42220. }
  42221. });
  42222. }
  42223. },
  42224. axisTickLabel: function (opt, axisModel, group, transformGroup) {
  42225. var ticksEls = buildAxisMajorTicks(group, transformGroup, axisModel, opt);
  42226. var labelEls = buildAxisLabel(group, transformGroup, axisModel, opt);
  42227. fixMinMaxLabelShow(axisModel, labelEls, ticksEls);
  42228. buildAxisMinorTicks(group, transformGroup, axisModel, opt.tickDirection); // This bit fixes the label overlap issue for the time chart.
  42229. // See https://github.com/apache/echarts/issues/14266 for more.
  42230. if (axisModel.get(['axisLabel', 'hideOverlap'])) {
  42231. var labelList = prepareLayoutList(map(labelEls, function (label) {
  42232. return {
  42233. label: label,
  42234. priority: label.z2,
  42235. defaultAttr: {
  42236. ignore: label.ignore
  42237. }
  42238. };
  42239. }));
  42240. hideOverlap(labelList);
  42241. }
  42242. },
  42243. axisName: function (opt, axisModel, group, transformGroup) {
  42244. var name = retrieve(opt.axisName, axisModel.get('name'));
  42245. if (!name) {
  42246. return;
  42247. }
  42248. var nameLocation = axisModel.get('nameLocation');
  42249. var nameDirection = opt.nameDirection;
  42250. var textStyleModel = axisModel.getModel('nameTextStyle');
  42251. var gap = axisModel.get('nameGap') || 0;
  42252. var extent = axisModel.axis.getExtent();
  42253. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  42254. var pos = [nameLocation === 'start' ? extent[0] - gapSignal * gap : nameLocation === 'end' ? extent[1] + gapSignal * gap : (extent[0] + extent[1]) / 2, // Reuse labelOffset.
  42255. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0];
  42256. var labelLayout;
  42257. var nameRotation = axisModel.get('nameRotate');
  42258. if (nameRotation != null) {
  42259. nameRotation = nameRotation * PI$5 / 180; // To radian.
  42260. }
  42261. var axisNameAvailableWidth;
  42262. if (isNameLocationCenter(nameLocation)) {
  42263. labelLayout = AxisBuilder.innerTextLayout(opt.rotation, nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  42264. nameDirection);
  42265. } else {
  42266. labelLayout = endTextLayout(opt.rotation, nameLocation, nameRotation || 0, extent);
  42267. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  42268. if (axisNameAvailableWidth != null) {
  42269. axisNameAvailableWidth = Math.abs(axisNameAvailableWidth / Math.sin(labelLayout.rotation));
  42270. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  42271. }
  42272. }
  42273. var textFont = textStyleModel.getFont();
  42274. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  42275. var ellipsis = truncateOpt.ellipsis;
  42276. var maxWidth = retrieve(opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth);
  42277. var textEl = new ZRText({
  42278. x: pos[0],
  42279. y: pos[1],
  42280. rotation: labelLayout.rotation,
  42281. silent: AxisBuilder.isLabelSilent(axisModel),
  42282. style: createTextStyle(textStyleModel, {
  42283. text: name,
  42284. font: textFont,
  42285. overflow: 'truncate',
  42286. width: maxWidth,
  42287. ellipsis: ellipsis,
  42288. fill: textStyleModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']),
  42289. align: textStyleModel.get('align') || labelLayout.textAlign,
  42290. verticalAlign: textStyleModel.get('verticalAlign') || labelLayout.textVerticalAlign
  42291. }),
  42292. z2: 1
  42293. });
  42294. setTooltipConfig({
  42295. el: textEl,
  42296. componentModel: axisModel,
  42297. itemName: name
  42298. });
  42299. textEl.__fullText = name; // Id for animation
  42300. textEl.anid = 'name';
  42301. if (axisModel.get('triggerEvent')) {
  42302. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  42303. eventData.targetType = 'axisName';
  42304. eventData.name = name;
  42305. getECData(textEl).eventData = eventData;
  42306. } // FIXME
  42307. transformGroup.add(textEl);
  42308. textEl.updateTransform();
  42309. group.add(textEl);
  42310. textEl.decomposeTransform();
  42311. }
  42312. };
  42313. function endTextLayout(rotation, textPosition, textRotate, extent) {
  42314. var rotationDiff = remRadian(textRotate - rotation);
  42315. var textAlign;
  42316. var textVerticalAlign;
  42317. var inverse = extent[0] > extent[1];
  42318. var onLeft = textPosition === 'start' && !inverse || textPosition !== 'start' && inverse;
  42319. if (isRadianAroundZero(rotationDiff - PI$5 / 2)) {
  42320. textVerticalAlign = onLeft ? 'bottom' : 'top';
  42321. textAlign = 'center';
  42322. } else if (isRadianAroundZero(rotationDiff - PI$5 * 1.5)) {
  42323. textVerticalAlign = onLeft ? 'top' : 'bottom';
  42324. textAlign = 'center';
  42325. } else {
  42326. textVerticalAlign = 'middle';
  42327. if (rotationDiff < PI$5 * 1.5 && rotationDiff > PI$5 / 2) {
  42328. textAlign = onLeft ? 'left' : 'right';
  42329. } else {
  42330. textAlign = onLeft ? 'right' : 'left';
  42331. }
  42332. }
  42333. return {
  42334. rotation: rotationDiff,
  42335. textAlign: textAlign,
  42336. textVerticalAlign: textVerticalAlign
  42337. };
  42338. }
  42339. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  42340. if (shouldShowAllLabels(axisModel.axis)) {
  42341. return;
  42342. } // If min or max are user set, we need to check
  42343. // If the tick on min(max) are overlap on their neighbour tick
  42344. // If they are overlapped, we need to hide the min(max) tick label
  42345. var showMinLabel = axisModel.get(['axisLabel', 'showMinLabel']);
  42346. var showMaxLabel = axisModel.get(['axisLabel', 'showMaxLabel']); // FIXME
  42347. // Have not consider onBand yet, where tick els is more than label els.
  42348. labelEls = labelEls || [];
  42349. tickEls = tickEls || [];
  42350. var firstLabel = labelEls[0];
  42351. var nextLabel = labelEls[1];
  42352. var lastLabel = labelEls[labelEls.length - 1];
  42353. var prevLabel = labelEls[labelEls.length - 2];
  42354. var firstTick = tickEls[0];
  42355. var nextTick = tickEls[1];
  42356. var lastTick = tickEls[tickEls.length - 1];
  42357. var prevTick = tickEls[tickEls.length - 2];
  42358. if (showMinLabel === false) {
  42359. ignoreEl(firstLabel);
  42360. ignoreEl(firstTick);
  42361. } else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  42362. if (showMinLabel) {
  42363. ignoreEl(nextLabel);
  42364. ignoreEl(nextTick);
  42365. } else {
  42366. ignoreEl(firstLabel);
  42367. ignoreEl(firstTick);
  42368. }
  42369. }
  42370. if (showMaxLabel === false) {
  42371. ignoreEl(lastLabel);
  42372. ignoreEl(lastTick);
  42373. } else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  42374. if (showMaxLabel) {
  42375. ignoreEl(prevLabel);
  42376. ignoreEl(prevTick);
  42377. } else {
  42378. ignoreEl(lastLabel);
  42379. ignoreEl(lastTick);
  42380. }
  42381. }
  42382. }
  42383. function ignoreEl(el) {
  42384. el && (el.ignore = true);
  42385. }
  42386. function isTwoLabelOverlapped(current, next) {
  42387. // current and next has the same rotation.
  42388. var firstRect = current && current.getBoundingRect().clone();
  42389. var nextRect = next && next.getBoundingRect().clone();
  42390. if (!firstRect || !nextRect) {
  42391. return;
  42392. } // When checking intersect of two rotated labels, we use mRotationBack
  42393. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  42394. var mRotationBack = identity([]);
  42395. rotate(mRotationBack, mRotationBack, -current.rotation);
  42396. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  42397. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  42398. return firstRect.intersect(nextRect);
  42399. }
  42400. function isNameLocationCenter(nameLocation) {
  42401. return nameLocation === 'middle' || nameLocation === 'center';
  42402. }
  42403. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, anidPrefix) {
  42404. var tickEls = [];
  42405. var pt1 = [];
  42406. var pt2 = [];
  42407. for (var i = 0; i < ticksCoords.length; i++) {
  42408. var tickCoord = ticksCoords[i].coord;
  42409. pt1[0] = tickCoord;
  42410. pt1[1] = 0;
  42411. pt2[0] = tickCoord;
  42412. pt2[1] = tickEndCoord;
  42413. if (tickTransform) {
  42414. applyTransform(pt1, pt1, tickTransform);
  42415. applyTransform(pt2, pt2, tickTransform);
  42416. } // Tick line, Not use group transform to have better line draw
  42417. var tickEl = new Line({
  42418. subPixelOptimize: true,
  42419. shape: {
  42420. x1: pt1[0],
  42421. y1: pt1[1],
  42422. x2: pt2[0],
  42423. y2: pt2[1]
  42424. },
  42425. style: tickLineStyle,
  42426. z2: 2,
  42427. autoBatch: true,
  42428. silent: true
  42429. });
  42430. tickEl.anid = anidPrefix + '_' + ticksCoords[i].tickValue;
  42431. tickEls.push(tickEl);
  42432. }
  42433. return tickEls;
  42434. }
  42435. function buildAxisMajorTicks(group, transformGroup, axisModel, opt) {
  42436. var axis = axisModel.axis;
  42437. var tickModel = axisModel.getModel('axisTick');
  42438. var shown = tickModel.get('show');
  42439. if (shown === 'auto' && opt.handleAutoShown) {
  42440. shown = opt.handleAutoShown('axisTick');
  42441. }
  42442. if (!shown || axis.scale.isBlank()) {
  42443. return;
  42444. }
  42445. var lineStyleModel = tickModel.getModel('lineStyle');
  42446. var tickEndCoord = opt.tickDirection * tickModel.get('length');
  42447. var ticksCoords = axis.getTicksCoords();
  42448. var ticksEls = createTicks(ticksCoords, transformGroup.transform, tickEndCoord, defaults(lineStyleModel.getLineStyle(), {
  42449. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  42450. }), 'ticks');
  42451. for (var i = 0; i < ticksEls.length; i++) {
  42452. group.add(ticksEls[i]);
  42453. }
  42454. return ticksEls;
  42455. }
  42456. function buildAxisMinorTicks(group, transformGroup, axisModel, tickDirection) {
  42457. var axis = axisModel.axis;
  42458. var minorTickModel = axisModel.getModel('minorTick');
  42459. if (!minorTickModel.get('show') || axis.scale.isBlank()) {
  42460. return;
  42461. }
  42462. var minorTicksCoords = axis.getMinorTicksCoords();
  42463. if (!minorTicksCoords.length) {
  42464. return;
  42465. }
  42466. var lineStyleModel = minorTickModel.getModel('lineStyle');
  42467. var tickEndCoord = tickDirection * minorTickModel.get('length');
  42468. var minorTickLineStyle = defaults(lineStyleModel.getLineStyle(), defaults(axisModel.getModel('axisTick').getLineStyle(), {
  42469. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  42470. }));
  42471. for (var i = 0; i < minorTicksCoords.length; i++) {
  42472. var minorTicksEls = createTicks(minorTicksCoords[i], transformGroup.transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i);
  42473. for (var k = 0; k < minorTicksEls.length; k++) {
  42474. group.add(minorTicksEls[k]);
  42475. }
  42476. }
  42477. }
  42478. function buildAxisLabel(group, transformGroup, axisModel, opt) {
  42479. var axis = axisModel.axis;
  42480. var show = retrieve(opt.axisLabelShow, axisModel.get(['axisLabel', 'show']));
  42481. if (!show || axis.scale.isBlank()) {
  42482. return;
  42483. }
  42484. var labelModel = axisModel.getModel('axisLabel');
  42485. var labelMargin = labelModel.get('margin');
  42486. var labels = axis.getViewLabels(); // Special label rotate.
  42487. var labelRotation = (retrieve(opt.labelRotate, labelModel.get('rotate')) || 0) * PI$5 / 180;
  42488. var labelLayout = AxisBuilder.innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  42489. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  42490. var labelEls = [];
  42491. var silent = AxisBuilder.isLabelSilent(axisModel);
  42492. var triggerEvent = axisModel.get('triggerEvent');
  42493. each(labels, function (labelItem, index) {
  42494. var tickValue = axis.scale.type === 'ordinal' ? axis.scale.getRawOrdinalNumber(labelItem.tickValue) : labelItem.tickValue;
  42495. var formattedLabel = labelItem.formattedLabel;
  42496. var rawLabel = labelItem.rawLabel;
  42497. var itemLabelModel = labelModel;
  42498. if (rawCategoryData && rawCategoryData[tickValue]) {
  42499. var rawCategoryItem = rawCategoryData[tickValue];
  42500. if (isObject(rawCategoryItem) && rawCategoryItem.textStyle) {
  42501. itemLabelModel = new Model(rawCategoryItem.textStyle, labelModel, axisModel.ecModel);
  42502. }
  42503. }
  42504. var textColor = itemLabelModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']);
  42505. var tickCoord = axis.dataToCoord(tickValue);
  42506. var textEl = new ZRText({
  42507. x: tickCoord,
  42508. y: opt.labelOffset + opt.labelDirection * labelMargin,
  42509. rotation: labelLayout.rotation,
  42510. silent: silent,
  42511. z2: 10 + (labelItem.level || 0),
  42512. style: createTextStyle(itemLabelModel, {
  42513. text: formattedLabel,
  42514. align: itemLabelModel.getShallow('align', true) || labelLayout.textAlign,
  42515. verticalAlign: itemLabelModel.getShallow('verticalAlign', true) || itemLabelModel.getShallow('baseline', true) || labelLayout.textVerticalAlign,
  42516. fill: typeof textColor === 'function' ? textColor( // (1) In category axis with data zoom, tick is not the original
  42517. // index of axis.data. So tick should not be exposed to user
  42518. // in category axis.
  42519. // (2) Compatible with previous version, which always use formatted label as
  42520. // input. But in interval scale the formatted label is like '223,445', which
  42521. // maked user repalce ','. So we modify it to return original val but remain
  42522. // it as 'string' to avoid error in replacing.
  42523. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue, index) : textColor
  42524. })
  42525. });
  42526. textEl.anid = 'label_' + tickValue; // Pack data for mouse event
  42527. if (triggerEvent) {
  42528. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  42529. eventData.targetType = 'axisLabel';
  42530. eventData.value = rawLabel;
  42531. getECData(textEl).eventData = eventData;
  42532. } // FIXME
  42533. transformGroup.add(textEl);
  42534. textEl.updateTransform();
  42535. labelEls.push(textEl);
  42536. group.add(textEl);
  42537. textEl.decomposeTransform();
  42538. });
  42539. return labelEls;
  42540. }
  42541. // allAxesInfo should be updated when setOption performed.
  42542. function collect(ecModel, api) {
  42543. var result = {
  42544. /**
  42545. * key: makeKey(axis.model)
  42546. * value: {
  42547. * axis,
  42548. * coordSys,
  42549. * axisPointerModel,
  42550. * triggerTooltip,
  42551. * involveSeries,
  42552. * snap,
  42553. * seriesModels,
  42554. * seriesDataCount
  42555. * }
  42556. */
  42557. axesInfo: {},
  42558. seriesInvolved: false,
  42559. /**
  42560. * key: makeKey(coordSys.model)
  42561. * value: Object: key makeKey(axis.model), value: axisInfo
  42562. */
  42563. coordSysAxesInfo: {},
  42564. coordSysMap: {}
  42565. };
  42566. collectAxesInfo(result, ecModel, api); // Check seriesInvolved for performance, in case too many series in some chart.
  42567. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  42568. return result;
  42569. }
  42570. function collectAxesInfo(result, ecModel, api) {
  42571. var globalTooltipModel = ecModel.getComponent('tooltip');
  42572. var globalAxisPointerModel = ecModel.getComponent('axisPointer'); // links can only be set on global.
  42573. var linksOption = globalAxisPointerModel.get('link', true) || [];
  42574. var linkGroups = []; // Collect axes info.
  42575. each(api.getCoordinateSystems(), function (coordSys) {
  42576. // Some coordinate system do not support axes, like geo.
  42577. if (!coordSys.axisPointerEnabled) {
  42578. return;
  42579. }
  42580. var coordSysKey = makeKey(coordSys.model);
  42581. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  42582. result.coordSysMap[coordSysKey] = coordSys; // Set tooltip (like 'cross') is a convienent way to show axisPointer
  42583. // for user. So we enable seting tooltip on coordSys model.
  42584. var coordSysModel = coordSys.model;
  42585. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  42586. each(coordSys.getAxes(), curry(saveTooltipAxisInfo, false, null)); // If axis tooltip used, choose tooltip axis for each coordSys.
  42587. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  42588. if (coordSys.getTooltipAxes && globalTooltipModel // If tooltip.showContent is set as false, tooltip will not
  42589. // show but axisPointer will show as normal.
  42590. && baseTooltipModel.get('show')) {
  42591. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  42592. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  42593. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  42594. var cross = baseTooltipModel.get(['axisPointer', 'type']) === 'cross';
  42595. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get(['axisPointer', 'axis']));
  42596. if (triggerAxis || cross) {
  42597. each(tooltipAxes.baseAxes, curry(saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis));
  42598. }
  42599. if (cross) {
  42600. each(tooltipAxes.otherAxes, curry(saveTooltipAxisInfo, 'cross', false));
  42601. }
  42602. } // fromTooltip: true | false | 'cross'
  42603. // triggerTooltip: true | false | null
  42604. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  42605. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  42606. var axisPointerShow = axisPointerModel.get('show');
  42607. if (!axisPointerShow || axisPointerShow === 'auto' && !fromTooltip && !isHandleTrigger(axisPointerModel)) {
  42608. return;
  42609. }
  42610. if (triggerTooltip == null) {
  42611. triggerTooltip = axisPointerModel.get('triggerTooltip');
  42612. }
  42613. axisPointerModel = fromTooltip ? makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) : axisPointerModel;
  42614. var snap = axisPointerModel.get('snap');
  42615. var axisKey = makeKey(axis.model);
  42616. var involveSeries = triggerTooltip || snap || axis.type === 'category'; // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  42617. var axisInfo = result.axesInfo[axisKey] = {
  42618. key: axisKey,
  42619. axis: axis,
  42620. coordSys: coordSys,
  42621. axisPointerModel: axisPointerModel,
  42622. triggerTooltip: triggerTooltip,
  42623. involveSeries: involveSeries,
  42624. snap: snap,
  42625. useHandle: isHandleTrigger(axisPointerModel),
  42626. seriesModels: [],
  42627. linkGroup: null
  42628. };
  42629. axesInfoInCoordSys[axisKey] = axisInfo;
  42630. result.seriesInvolved = result.seriesInvolved || involveSeries;
  42631. var groupIndex = getLinkGroupIndex(linksOption, axis);
  42632. if (groupIndex != null) {
  42633. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {
  42634. axesInfo: {}
  42635. });
  42636. linkGroup.axesInfo[axisKey] = axisInfo;
  42637. linkGroup.mapper = linksOption[groupIndex].mapper;
  42638. axisInfo.linkGroup = linkGroup;
  42639. }
  42640. }
  42641. });
  42642. }
  42643. function makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) {
  42644. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  42645. var fields = ['type', 'snap', 'lineStyle', 'shadowStyle', 'label', 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'];
  42646. var volatileOption = {};
  42647. each(fields, function (field) {
  42648. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  42649. }); // category axis do not auto snap, otherwise some tick that do not
  42650. // has value can not be hovered. value/time/log axis default snap if
  42651. // triggered from tooltip and trigger tooltip.
  42652. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip; // Compatibel with previous behavior, tooltip axis do not show label by default.
  42653. // Only these properties can be overrided from tooltip to axisPointer.
  42654. if (tooltipAxisPointerModel.get('type') === 'cross') {
  42655. volatileOption.type = 'line';
  42656. }
  42657. var labelOption = volatileOption.label || (volatileOption.label = {}); // Follow the convention, do not show label when triggered by tooltip by default.
  42658. labelOption.show == null && (labelOption.show = false);
  42659. if (fromTooltip === 'cross') {
  42660. // When 'cross', both axes show labels.
  42661. var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get(['label', 'show']);
  42662. labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true; // If triggerTooltip, this is a base axis, which should better not use cross style
  42663. // (cross style is dashed by default)
  42664. if (!triggerTooltip) {
  42665. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  42666. crossStyle && defaults(labelOption, crossStyle.textStyle);
  42667. }
  42668. }
  42669. return axis.model.getModel('axisPointer', new Model(volatileOption, globalAxisPointerModel, ecModel));
  42670. }
  42671. function collectSeriesInfo(result, ecModel) {
  42672. // Prepare data for axis trigger
  42673. ecModel.eachSeries(function (seriesModel) {
  42674. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  42675. var coordSys = seriesModel.coordinateSystem;
  42676. var seriesTooltipTrigger = seriesModel.get(['tooltip', 'trigger'], true);
  42677. var seriesTooltipShow = seriesModel.get(['tooltip', 'show'], true);
  42678. if (!coordSys || seriesTooltipTrigger === 'none' || seriesTooltipTrigger === false || seriesTooltipTrigger === 'item' || seriesTooltipShow === false || seriesModel.get(['axisPointer', 'show'], true) === false) {
  42679. return;
  42680. }
  42681. each(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  42682. var axis = axisInfo.axis;
  42683. if (coordSys.getAxis(axis.dim) === axis) {
  42684. axisInfo.seriesModels.push(seriesModel);
  42685. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  42686. axisInfo.seriesDataCount += seriesModel.getData().count();
  42687. }
  42688. });
  42689. });
  42690. }
  42691. /**
  42692. * For example:
  42693. * {
  42694. * axisPointer: {
  42695. * links: [{
  42696. * xAxisIndex: [2, 4],
  42697. * yAxisIndex: 'all'
  42698. * }, {
  42699. * xAxisId: ['a5', 'a7'],
  42700. * xAxisName: 'xxx'
  42701. * }]
  42702. * }
  42703. * }
  42704. */
  42705. function getLinkGroupIndex(linksOption, axis) {
  42706. var axisModel = axis.model;
  42707. var dim = axis.dim;
  42708. for (var i = 0; i < linksOption.length; i++) {
  42709. var linkOption = linksOption[i] || {};
  42710. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id) || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex) || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)) {
  42711. return i;
  42712. }
  42713. }
  42714. }
  42715. function checkPropInLink(linkPropValue, axisPropValue) {
  42716. return linkPropValue === 'all' || isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0 || linkPropValue === axisPropValue;
  42717. }
  42718. function fixValue(axisModel) {
  42719. var axisInfo = getAxisInfo(axisModel);
  42720. if (!axisInfo) {
  42721. return;
  42722. }
  42723. var axisPointerModel = axisInfo.axisPointerModel;
  42724. var scale = axisInfo.axis.scale;
  42725. var option = axisPointerModel.option;
  42726. var status = axisPointerModel.get('status');
  42727. var value = axisPointerModel.get('value'); // Parse init value for category and time axis.
  42728. if (value != null) {
  42729. value = scale.parse(value);
  42730. }
  42731. var useHandle = isHandleTrigger(axisPointerModel); // If `handle` used, `axisPointer` will always be displayed, so value
  42732. // and status should be initialized.
  42733. if (status == null) {
  42734. option.status = useHandle ? 'show' : 'hide';
  42735. }
  42736. var extent = scale.getExtent().slice();
  42737. extent[0] > extent[1] && extent.reverse();
  42738. if ( // Pick a value on axis when initializing.
  42739. value == null // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  42740. // where we should re-pick a value to keep `handle` displaying normally.
  42741. || value > extent[1]) {
  42742. // Make handle displayed on the end of the axis when init, which looks better.
  42743. value = extent[1];
  42744. }
  42745. if (value < extent[0]) {
  42746. value = extent[0];
  42747. }
  42748. option.value = value;
  42749. if (useHandle) {
  42750. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  42751. }
  42752. }
  42753. function getAxisInfo(axisModel) {
  42754. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  42755. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  42756. }
  42757. function getAxisPointerModel(axisModel) {
  42758. var axisInfo = getAxisInfo(axisModel);
  42759. return axisInfo && axisInfo.axisPointerModel;
  42760. }
  42761. function isHandleTrigger(axisPointerModel) {
  42762. return !!axisPointerModel.get(['handle', 'show']);
  42763. }
  42764. /**
  42765. * @param {module:echarts/model/Model} model
  42766. * @return {string} unique key
  42767. */
  42768. function makeKey(model) {
  42769. return model.type + '||' + model.id;
  42770. }
  42771. var axisPointerClazz = {};
  42772. /**
  42773. * Base class of AxisView.
  42774. */
  42775. var AxisView =
  42776. /** @class */
  42777. function (_super) {
  42778. __extends(AxisView, _super);
  42779. function AxisView() {
  42780. var _this = _super !== null && _super.apply(this, arguments) || this;
  42781. _this.type = AxisView.type;
  42782. return _this;
  42783. }
  42784. /**
  42785. * @override
  42786. */
  42787. AxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  42788. // FIXME
  42789. // This process should proformed after coordinate systems updated
  42790. // (axis scale updated), and should be performed each time update.
  42791. // So put it here temporarily, although it is not appropriate to
  42792. // put a model-writing procedure in `view`.
  42793. this.axisPointerClass && fixValue(axisModel);
  42794. _super.prototype.render.apply(this, arguments);
  42795. this._doUpdateAxisPointerClass(axisModel, api, true);
  42796. };
  42797. /**
  42798. * Action handler.
  42799. */
  42800. AxisView.prototype.updateAxisPointer = function (axisModel, ecModel, api, payload) {
  42801. this._doUpdateAxisPointerClass(axisModel, api, false);
  42802. };
  42803. /**
  42804. * @override
  42805. */
  42806. AxisView.prototype.remove = function (ecModel, api) {
  42807. var axisPointer = this._axisPointer;
  42808. axisPointer && axisPointer.remove(api);
  42809. };
  42810. /**
  42811. * @override
  42812. */
  42813. AxisView.prototype.dispose = function (ecModel, api) {
  42814. this._disposeAxisPointer(api);
  42815. _super.prototype.dispose.apply(this, arguments);
  42816. };
  42817. AxisView.prototype._doUpdateAxisPointerClass = function (axisModel, api, forceRender) {
  42818. var Clazz = AxisView.getAxisPointerClass(this.axisPointerClass);
  42819. if (!Clazz) {
  42820. return;
  42821. }
  42822. var axisPointerModel = getAxisPointerModel(axisModel);
  42823. axisPointerModel ? (this._axisPointer || (this._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : this._disposeAxisPointer(api);
  42824. };
  42825. AxisView.prototype._disposeAxisPointer = function (api) {
  42826. this._axisPointer && this._axisPointer.dispose(api);
  42827. this._axisPointer = null;
  42828. };
  42829. AxisView.registerAxisPointerClass = function (type, clazz) {
  42830. if ("development" !== 'production') {
  42831. if (axisPointerClazz[type]) {
  42832. throw new Error('axisPointer ' + type + ' exists');
  42833. }
  42834. }
  42835. axisPointerClazz[type] = clazz;
  42836. };
  42837. AxisView.getAxisPointerClass = function (type) {
  42838. return type && axisPointerClazz[type];
  42839. };
  42840. AxisView.type = 'axis';
  42841. return AxisView;
  42842. }(ComponentView);
  42843. var inner$6 = makeInner();
  42844. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  42845. var axis = axisModel.axis;
  42846. if (axis.scale.isBlank()) {
  42847. return;
  42848. } // TODO: TYPE
  42849. var splitAreaModel = axisModel.getModel('splitArea');
  42850. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  42851. var areaColors = areaStyleModel.get('color');
  42852. var gridRect = gridModel.coordinateSystem.getRect();
  42853. var ticksCoords = axis.getTicksCoords({
  42854. tickModel: splitAreaModel,
  42855. clamp: true
  42856. });
  42857. if (!ticksCoords.length) {
  42858. return;
  42859. } // For Making appropriate splitArea animation, the color and anid
  42860. // should be corresponding to previous one if possible.
  42861. var areaColorsLen = areaColors.length;
  42862. var lastSplitAreaColors = inner$6(axisView).splitAreaColors;
  42863. var newSplitAreaColors = createHashMap();
  42864. var colorIndex = 0;
  42865. if (lastSplitAreaColors) {
  42866. for (var i = 0; i < ticksCoords.length; i++) {
  42867. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  42868. if (cIndex != null) {
  42869. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  42870. break;
  42871. }
  42872. }
  42873. }
  42874. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  42875. var areaStyle = areaStyleModel.getAreaStyle();
  42876. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  42877. for (var i = 1; i < ticksCoords.length; i++) {
  42878. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  42879. var x = void 0;
  42880. var y = void 0;
  42881. var width = void 0;
  42882. var height = void 0;
  42883. if (axis.isHorizontal()) {
  42884. x = prev;
  42885. y = gridRect.y;
  42886. width = tickCoord - x;
  42887. height = gridRect.height;
  42888. prev = x + width;
  42889. } else {
  42890. x = gridRect.x;
  42891. y = prev;
  42892. width = gridRect.width;
  42893. height = tickCoord - y;
  42894. prev = y + height;
  42895. }
  42896. var tickValue = ticksCoords[i - 1].tickValue;
  42897. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  42898. axisGroup.add(new Rect({
  42899. anid: tickValue != null ? 'area_' + tickValue : null,
  42900. shape: {
  42901. x: x,
  42902. y: y,
  42903. width: width,
  42904. height: height
  42905. },
  42906. style: defaults({
  42907. fill: areaColors[colorIndex]
  42908. }, areaStyle),
  42909. autoBatch: true,
  42910. silent: true
  42911. }));
  42912. colorIndex = (colorIndex + 1) % areaColorsLen;
  42913. }
  42914. inner$6(axisView).splitAreaColors = newSplitAreaColors;
  42915. }
  42916. function rectCoordAxisHandleRemove(axisView) {
  42917. inner$6(axisView).splitAreaColors = null;
  42918. }
  42919. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  42920. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine'];
  42921. var CartesianAxisView =
  42922. /** @class */
  42923. function (_super) {
  42924. __extends(CartesianAxisView, _super);
  42925. function CartesianAxisView() {
  42926. var _this = _super !== null && _super.apply(this, arguments) || this;
  42927. _this.type = CartesianAxisView.type;
  42928. _this.axisPointerClass = 'CartesianAxisPointer';
  42929. return _this;
  42930. }
  42931. /**
  42932. * @override
  42933. */
  42934. CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  42935. this.group.removeAll();
  42936. var oldAxisGroup = this._axisGroup;
  42937. this._axisGroup = new Group();
  42938. this.group.add(this._axisGroup);
  42939. if (!axisModel.get('show')) {
  42940. return;
  42941. }
  42942. var gridModel = axisModel.getCoordSysModel();
  42943. var layout = layout$1(gridModel, axisModel);
  42944. var axisBuilder = new AxisBuilder(axisModel, extend({
  42945. handleAutoShown: function (elementType) {
  42946. var cartesians = gridModel.coordinateSystem.getCartesians();
  42947. for (var i = 0; i < cartesians.length; i++) {
  42948. var otherAxisType = cartesians[i].getOtherAxis(axisModel.axis).type;
  42949. if (otherAxisType === 'value' || otherAxisType === 'log') {
  42950. // Still show axis tick or axisLine if other axis is value / log
  42951. return true;
  42952. }
  42953. } // Not show axisTick or axisLine if other axis is category / time
  42954. return false;
  42955. }
  42956. }, layout));
  42957. each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  42958. this._axisGroup.add(axisBuilder.getGroup());
  42959. each(selfBuilderAttrs, function (name) {
  42960. if (axisModel.get([name, 'show'])) {
  42961. axisElementBuilders[name](this, this._axisGroup, axisModel, gridModel);
  42962. }
  42963. }, this); // THIS is a special case for bar racing chart.
  42964. // Update the axis label from the natural initial layout to
  42965. // sorted layout should has no animation.
  42966. var isInitialSortFromBarRacing = payload && payload.type === 'changeAxisOrder' && payload.isInitSort;
  42967. if (!isInitialSortFromBarRacing) {
  42968. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  42969. }
  42970. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  42971. };
  42972. CartesianAxisView.prototype.remove = function () {
  42973. rectCoordAxisHandleRemove(this);
  42974. };
  42975. CartesianAxisView.type = 'cartesianAxis';
  42976. return CartesianAxisView;
  42977. }(AxisView);
  42978. var axisElementBuilders = {
  42979. splitLine: function (axisView, axisGroup, axisModel, gridModel) {
  42980. var axis = axisModel.axis;
  42981. if (axis.scale.isBlank()) {
  42982. return;
  42983. }
  42984. var splitLineModel = axisModel.getModel('splitLine');
  42985. var lineStyleModel = splitLineModel.getModel('lineStyle');
  42986. var lineColors = lineStyleModel.get('color');
  42987. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  42988. var gridRect = gridModel.coordinateSystem.getRect();
  42989. var isHorizontal = axis.isHorizontal();
  42990. var lineCount = 0;
  42991. var ticksCoords = axis.getTicksCoords({
  42992. tickModel: splitLineModel
  42993. });
  42994. var p1 = [];
  42995. var p2 = [];
  42996. var lineStyle = lineStyleModel.getLineStyle();
  42997. for (var i = 0; i < ticksCoords.length; i++) {
  42998. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  42999. if (isHorizontal) {
  43000. p1[0] = tickCoord;
  43001. p1[1] = gridRect.y;
  43002. p2[0] = tickCoord;
  43003. p2[1] = gridRect.y + gridRect.height;
  43004. } else {
  43005. p1[0] = gridRect.x;
  43006. p1[1] = tickCoord;
  43007. p2[0] = gridRect.x + gridRect.width;
  43008. p2[1] = tickCoord;
  43009. }
  43010. var colorIndex = lineCount++ % lineColors.length;
  43011. var tickValue = ticksCoords[i].tickValue;
  43012. axisGroup.add(new Line({
  43013. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  43014. subPixelOptimize: true,
  43015. autoBatch: true,
  43016. shape: {
  43017. x1: p1[0],
  43018. y1: p1[1],
  43019. x2: p2[0],
  43020. y2: p2[1]
  43021. },
  43022. style: defaults({
  43023. stroke: lineColors[colorIndex]
  43024. }, lineStyle),
  43025. silent: true
  43026. }));
  43027. }
  43028. },
  43029. minorSplitLine: function (axisView, axisGroup, axisModel, gridModel) {
  43030. var axis = axisModel.axis;
  43031. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  43032. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  43033. var gridRect = gridModel.coordinateSystem.getRect();
  43034. var isHorizontal = axis.isHorizontal();
  43035. var minorTicksCoords = axis.getMinorTicksCoords();
  43036. if (!minorTicksCoords.length) {
  43037. return;
  43038. }
  43039. var p1 = [];
  43040. var p2 = [];
  43041. var lineStyle = lineStyleModel.getLineStyle();
  43042. for (var i = 0; i < minorTicksCoords.length; i++) {
  43043. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  43044. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  43045. if (isHorizontal) {
  43046. p1[0] = tickCoord;
  43047. p1[1] = gridRect.y;
  43048. p2[0] = tickCoord;
  43049. p2[1] = gridRect.y + gridRect.height;
  43050. } else {
  43051. p1[0] = gridRect.x;
  43052. p1[1] = tickCoord;
  43053. p2[0] = gridRect.x + gridRect.width;
  43054. p2[1] = tickCoord;
  43055. }
  43056. axisGroup.add(new Line({
  43057. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  43058. subPixelOptimize: true,
  43059. autoBatch: true,
  43060. shape: {
  43061. x1: p1[0],
  43062. y1: p1[1],
  43063. x2: p2[0],
  43064. y2: p2[1]
  43065. },
  43066. style: lineStyle,
  43067. silent: true
  43068. }));
  43069. }
  43070. }
  43071. },
  43072. splitArea: function (axisView, axisGroup, axisModel, gridModel) {
  43073. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
  43074. }
  43075. };
  43076. var CartesianXAxisView =
  43077. /** @class */
  43078. function (_super) {
  43079. __extends(CartesianXAxisView, _super);
  43080. function CartesianXAxisView() {
  43081. var _this = _super !== null && _super.apply(this, arguments) || this;
  43082. _this.type = CartesianXAxisView.type;
  43083. return _this;
  43084. }
  43085. CartesianXAxisView.type = 'xAxis';
  43086. return CartesianXAxisView;
  43087. }(CartesianAxisView);
  43088. var CartesianYAxisView =
  43089. /** @class */
  43090. function (_super) {
  43091. __extends(CartesianYAxisView, _super);
  43092. function CartesianYAxisView() {
  43093. var _this = _super !== null && _super.apply(this, arguments) || this;
  43094. _this.type = CartesianXAxisView.type;
  43095. return _this;
  43096. }
  43097. CartesianYAxisView.type = 'yAxis';
  43098. return CartesianYAxisView;
  43099. }(CartesianAxisView);
  43100. var GridView =
  43101. /** @class */
  43102. function (_super) {
  43103. __extends(GridView, _super);
  43104. function GridView() {
  43105. var _this = _super !== null && _super.apply(this, arguments) || this;
  43106. _this.type = 'grid';
  43107. return _this;
  43108. }
  43109. GridView.prototype.render = function (gridModel, ecModel) {
  43110. this.group.removeAll();
  43111. if (gridModel.get('show')) {
  43112. this.group.add(new Rect({
  43113. shape: gridModel.coordinateSystem.getRect(),
  43114. style: defaults({
  43115. fill: gridModel.get('backgroundColor')
  43116. }, gridModel.getItemStyle()),
  43117. silent: true,
  43118. z2: -1
  43119. }));
  43120. }
  43121. };
  43122. GridView.type = 'grid';
  43123. return GridView;
  43124. }(ComponentView);
  43125. var extraOption = {
  43126. // gridIndex: 0,
  43127. // gridId: '',
  43128. offset: 0
  43129. };
  43130. function install$5(registers) {
  43131. registers.registerComponentView(GridView);
  43132. registers.registerComponentModel(GridModel);
  43133. registers.registerCoordinateSystem('cartesian2d', Grid);
  43134. axisModelCreator(registers, 'x', CartesianAxisModel, extraOption);
  43135. axisModelCreator(registers, 'y', CartesianAxisModel, extraOption);
  43136. registers.registerComponentView(CartesianXAxisView);
  43137. registers.registerComponentView(CartesianYAxisView);
  43138. registers.registerPreprocessor(function (option) {
  43139. // Only create grid when need
  43140. if (option.xAxis && option.yAxis && !option.grid) {
  43141. option.grid = {};
  43142. }
  43143. });
  43144. }
  43145. function install$6(registers) {
  43146. // In case developer forget to include grid component
  43147. use(install$5);
  43148. registers.registerSeriesModel(ScatterSeriesModel);
  43149. registers.registerChartView(ScatterView);
  43150. registers.registerLayout(pointsLayout('scatter'));
  43151. }
  43152. var inner$7 = makeInner();
  43153. var clone$3 = clone;
  43154. var bind$1 = bind;
  43155. /**
  43156. * Base axis pointer class in 2D.
  43157. */
  43158. var BaseAxisPointer =
  43159. /** @class */
  43160. function () {
  43161. function BaseAxisPointer() {
  43162. this._dragging = false;
  43163. /**
  43164. * In px, arbitrary value. Do not set too small,
  43165. * no animation is ok for most cases.
  43166. */
  43167. this.animationThreshold = 15;
  43168. }
  43169. /**
  43170. * @implement
  43171. */
  43172. BaseAxisPointer.prototype.render = function (axisModel, axisPointerModel, api, forceRender) {
  43173. var value = axisPointerModel.get('value');
  43174. var status = axisPointerModel.get('status'); // Bind them to `this`, not in closure, otherwise they will not
  43175. // be replaced when user calling setOption in not merge mode.
  43176. this._axisModel = axisModel;
  43177. this._axisPointerModel = axisPointerModel;
  43178. this._api = api; // Optimize: `render` will be called repeatly during mouse move.
  43179. // So it is power consuming if performing `render` each time,
  43180. // especially on mobile device.
  43181. if (!forceRender && this._lastValue === value && this._lastStatus === status) {
  43182. return;
  43183. }
  43184. this._lastValue = value;
  43185. this._lastStatus = status;
  43186. var group = this._group;
  43187. var handle = this._handle;
  43188. if (!status || status === 'hide') {
  43189. // Do not clear here, for animation better.
  43190. group && group.hide();
  43191. handle && handle.hide();
  43192. return;
  43193. }
  43194. group && group.show();
  43195. handle && handle.show(); // Otherwise status is 'show'
  43196. var elOption = {};
  43197. this.makeElOption(elOption, value, axisModel, axisPointerModel, api); // Enable change axis pointer type.
  43198. var graphicKey = elOption.graphicKey;
  43199. if (graphicKey !== this._lastGraphicKey) {
  43200. this.clear(api);
  43201. }
  43202. this._lastGraphicKey = graphicKey;
  43203. var moveAnimation = this._moveAnimation = this.determineAnimation(axisModel, axisPointerModel);
  43204. if (!group) {
  43205. group = this._group = new Group();
  43206. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  43207. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  43208. api.getZr().add(group);
  43209. } else {
  43210. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  43211. this.updatePointerEl(group, elOption, doUpdateProps);
  43212. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  43213. }
  43214. updateMandatoryProps(group, axisPointerModel, true);
  43215. this._renderHandle(value);
  43216. };
  43217. /**
  43218. * @implement
  43219. */
  43220. BaseAxisPointer.prototype.remove = function (api) {
  43221. this.clear(api);
  43222. };
  43223. /**
  43224. * @implement
  43225. */
  43226. BaseAxisPointer.prototype.dispose = function (api) {
  43227. this.clear(api);
  43228. };
  43229. /**
  43230. * @protected
  43231. */
  43232. BaseAxisPointer.prototype.determineAnimation = function (axisModel, axisPointerModel) {
  43233. var animation = axisPointerModel.get('animation');
  43234. var axis = axisModel.axis;
  43235. var isCategoryAxis = axis.type === 'category';
  43236. var useSnap = axisPointerModel.get('snap'); // Value axis without snap always do not snap.
  43237. if (!useSnap && !isCategoryAxis) {
  43238. return false;
  43239. }
  43240. if (animation === 'auto' || animation == null) {
  43241. var animationThreshold = this.animationThreshold;
  43242. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  43243. return true;
  43244. } // It is important to auto animation when snap used. Consider if there is
  43245. // a dataZoom, animation will be disabled when too many points exist, while
  43246. // it will be enabled for better visual effect when little points exist.
  43247. if (useSnap) {
  43248. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  43249. var axisExtent = axis.getExtent(); // Approximate band width
  43250. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  43251. }
  43252. return false;
  43253. }
  43254. return animation === true;
  43255. };
  43256. /**
  43257. * add {pointer, label, graphicKey} to elOption
  43258. * @protected
  43259. */
  43260. BaseAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {// Shoule be implemenented by sub-class.
  43261. };
  43262. /**
  43263. * @protected
  43264. */
  43265. BaseAxisPointer.prototype.createPointerEl = function (group, elOption, axisModel, axisPointerModel) {
  43266. var pointerOption = elOption.pointer;
  43267. if (pointerOption) {
  43268. var pointerEl = inner$7(group).pointerEl = new graphic[pointerOption.type](clone$3(elOption.pointer));
  43269. group.add(pointerEl);
  43270. }
  43271. };
  43272. /**
  43273. * @protected
  43274. */
  43275. BaseAxisPointer.prototype.createLabelEl = function (group, elOption, axisModel, axisPointerModel) {
  43276. if (elOption.label) {
  43277. var labelEl = inner$7(group).labelEl = new ZRText(clone$3(elOption.label));
  43278. group.add(labelEl);
  43279. updateLabelShowHide(labelEl, axisPointerModel);
  43280. }
  43281. };
  43282. /**
  43283. * @protected
  43284. */
  43285. BaseAxisPointer.prototype.updatePointerEl = function (group, elOption, updateProps) {
  43286. var pointerEl = inner$7(group).pointerEl;
  43287. if (pointerEl && elOption.pointer) {
  43288. pointerEl.setStyle(elOption.pointer.style);
  43289. updateProps(pointerEl, {
  43290. shape: elOption.pointer.shape
  43291. });
  43292. }
  43293. };
  43294. /**
  43295. * @protected
  43296. */
  43297. BaseAxisPointer.prototype.updateLabelEl = function (group, elOption, updateProps, axisPointerModel) {
  43298. var labelEl = inner$7(group).labelEl;
  43299. if (labelEl) {
  43300. labelEl.setStyle(elOption.label.style);
  43301. updateProps(labelEl, {
  43302. // Consider text length change in vertical axis, animation should
  43303. // be used on shape, otherwise the effect will be weird.
  43304. // TODOTODO
  43305. // shape: elOption.label.shape,
  43306. x: elOption.label.x,
  43307. y: elOption.label.y
  43308. });
  43309. updateLabelShowHide(labelEl, axisPointerModel);
  43310. }
  43311. };
  43312. /**
  43313. * @private
  43314. */
  43315. BaseAxisPointer.prototype._renderHandle = function (value) {
  43316. if (this._dragging || !this.updateHandleTransform) {
  43317. return;
  43318. }
  43319. var axisPointerModel = this._axisPointerModel;
  43320. var zr = this._api.getZr();
  43321. var handle = this._handle;
  43322. var handleModel = axisPointerModel.getModel('handle');
  43323. var status = axisPointerModel.get('status');
  43324. if (!handleModel.get('show') || !status || status === 'hide') {
  43325. handle && zr.remove(handle);
  43326. this._handle = null;
  43327. return;
  43328. }
  43329. var isInit;
  43330. if (!this._handle) {
  43331. isInit = true;
  43332. handle = this._handle = createIcon(handleModel.get('icon'), {
  43333. cursor: 'move',
  43334. draggable: true,
  43335. onmousemove: function (e) {
  43336. // Fot mobile devicem, prevent screen slider on the button.
  43337. stop(e.event);
  43338. },
  43339. onmousedown: bind$1(this._onHandleDragMove, this, 0, 0),
  43340. drift: bind$1(this._onHandleDragMove, this),
  43341. ondragend: bind$1(this._onHandleDragEnd, this)
  43342. });
  43343. zr.add(handle);
  43344. }
  43345. updateMandatoryProps(handle, axisPointerModel, false); // update style
  43346. handle.setStyle(handleModel.getItemStyle(null, ['color', 'borderColor', 'borderWidth', 'opacity', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'])); // update position
  43347. var handleSize = handleModel.get('size');
  43348. if (!isArray(handleSize)) {
  43349. handleSize = [handleSize, handleSize];
  43350. }
  43351. handle.scaleX = handleSize[0] / 2;
  43352. handle.scaleY = handleSize[1] / 2;
  43353. createOrUpdate(this, '_doDispatchAxisPointer', handleModel.get('throttle') || 0, 'fixRate');
  43354. this._moveHandleToValue(value, isInit);
  43355. };
  43356. BaseAxisPointer.prototype._moveHandleToValue = function (value, isInit) {
  43357. updateProps$1(this._axisPointerModel, !isInit && this._moveAnimation, this._handle, getHandleTransProps(this.getHandleTransform(value, this._axisModel, this._axisPointerModel)));
  43358. };
  43359. BaseAxisPointer.prototype._onHandleDragMove = function (dx, dy) {
  43360. var handle = this._handle;
  43361. if (!handle) {
  43362. return;
  43363. }
  43364. this._dragging = true; // Persistent for throttle.
  43365. var trans = this.updateHandleTransform(getHandleTransProps(handle), [dx, dy], this._axisModel, this._axisPointerModel);
  43366. this._payloadInfo = trans;
  43367. handle.stopAnimation();
  43368. handle.attr(getHandleTransProps(trans));
  43369. inner$7(handle).lastProp = null;
  43370. this._doDispatchAxisPointer();
  43371. };
  43372. /**
  43373. * Throttled method.
  43374. */
  43375. BaseAxisPointer.prototype._doDispatchAxisPointer = function () {
  43376. var handle = this._handle;
  43377. if (!handle) {
  43378. return;
  43379. }
  43380. var payloadInfo = this._payloadInfo;
  43381. var axisModel = this._axisModel;
  43382. this._api.dispatchAction({
  43383. type: 'updateAxisPointer',
  43384. x: payloadInfo.cursorPoint[0],
  43385. y: payloadInfo.cursorPoint[1],
  43386. tooltipOption: payloadInfo.tooltipOption,
  43387. axesInfo: [{
  43388. axisDim: axisModel.axis.dim,
  43389. axisIndex: axisModel.componentIndex
  43390. }]
  43391. });
  43392. };
  43393. BaseAxisPointer.prototype._onHandleDragEnd = function () {
  43394. this._dragging = false;
  43395. var handle = this._handle;
  43396. if (!handle) {
  43397. return;
  43398. }
  43399. var value = this._axisPointerModel.get('value'); // Consider snap or categroy axis, handle may be not consistent with
  43400. // axisPointer. So move handle to align the exact value position when
  43401. // drag ended.
  43402. this._moveHandleToValue(value); // For the effect: tooltip will be shown when finger holding on handle
  43403. // button, and will be hidden after finger left handle button.
  43404. this._api.dispatchAction({
  43405. type: 'hideTip'
  43406. });
  43407. };
  43408. /**
  43409. * @private
  43410. */
  43411. BaseAxisPointer.prototype.clear = function (api) {
  43412. this._lastValue = null;
  43413. this._lastStatus = null;
  43414. var zr = api.getZr();
  43415. var group = this._group;
  43416. var handle = this._handle;
  43417. if (zr && group) {
  43418. this._lastGraphicKey = null;
  43419. group && zr.remove(group);
  43420. handle && zr.remove(handle);
  43421. this._group = null;
  43422. this._handle = null;
  43423. this._payloadInfo = null;
  43424. }
  43425. };
  43426. /**
  43427. * @protected
  43428. */
  43429. BaseAxisPointer.prototype.doClear = function () {// Implemented by sub-class if necessary.
  43430. };
  43431. BaseAxisPointer.prototype.buildLabel = function (xy, wh, xDimIndex) {
  43432. xDimIndex = xDimIndex || 0;
  43433. return {
  43434. x: xy[xDimIndex],
  43435. y: xy[1 - xDimIndex],
  43436. width: wh[xDimIndex],
  43437. height: wh[1 - xDimIndex]
  43438. };
  43439. };
  43440. return BaseAxisPointer;
  43441. }();
  43442. function updateProps$1(animationModel, moveAnimation, el, props) {
  43443. // Animation optimize.
  43444. if (!propsEqual(inner$7(el).lastProp, props)) {
  43445. inner$7(el).lastProp = props;
  43446. moveAnimation ? updateProps(el, props, animationModel) : (el.stopAnimation(), el.attr(props));
  43447. }
  43448. }
  43449. function propsEqual(lastProps, newProps) {
  43450. if (isObject(lastProps) && isObject(newProps)) {
  43451. var equals_1 = true;
  43452. each(newProps, function (item, key) {
  43453. equals_1 = equals_1 && propsEqual(lastProps[key], item);
  43454. });
  43455. return !!equals_1;
  43456. } else {
  43457. return lastProps === newProps;
  43458. }
  43459. }
  43460. function updateLabelShowHide(labelEl, axisPointerModel) {
  43461. labelEl[axisPointerModel.get(['label', 'show']) ? 'show' : 'hide']();
  43462. }
  43463. function getHandleTransProps(trans) {
  43464. return {
  43465. x: trans.x || 0,
  43466. y: trans.y || 0,
  43467. rotation: trans.rotation || 0
  43468. };
  43469. }
  43470. function updateMandatoryProps(group, axisPointerModel, silent) {
  43471. var z = axisPointerModel.get('z');
  43472. var zlevel = axisPointerModel.get('zlevel');
  43473. group && group.traverse(function (el) {
  43474. if (el.type !== 'group') {
  43475. z != null && (el.z = z);
  43476. zlevel != null && (el.zlevel = zlevel);
  43477. el.silent = silent;
  43478. }
  43479. });
  43480. }
  43481. function buildElStyle(axisPointerModel) {
  43482. var axisPointerType = axisPointerModel.get('type');
  43483. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  43484. var style;
  43485. if (axisPointerType === 'line') {
  43486. style = styleModel.getLineStyle();
  43487. style.fill = null;
  43488. } else if (axisPointerType === 'shadow') {
  43489. style = styleModel.getAreaStyle();
  43490. style.stroke = null;
  43491. }
  43492. return style;
  43493. }
  43494. /**
  43495. * @param {Function} labelPos {align, verticalAlign, position}
  43496. */
  43497. function buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos) {
  43498. var value = axisPointerModel.get('value');
  43499. var text = getValueLabel(value, axisModel.axis, axisModel.ecModel, axisPointerModel.get('seriesDataIndices'), {
  43500. precision: axisPointerModel.get(['label', 'precision']),
  43501. formatter: axisPointerModel.get(['label', 'formatter'])
  43502. });
  43503. var labelModel = axisPointerModel.getModel('label');
  43504. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  43505. var font = labelModel.getFont();
  43506. var textRect = getBoundingRect(text, font);
  43507. var position = labelPos.position;
  43508. var width = textRect.width + paddings[1] + paddings[3];
  43509. var height = textRect.height + paddings[0] + paddings[2]; // Adjust by align.
  43510. var align = labelPos.align;
  43511. align === 'right' && (position[0] -= width);
  43512. align === 'center' && (position[0] -= width / 2);
  43513. var verticalAlign = labelPos.verticalAlign;
  43514. verticalAlign === 'bottom' && (position[1] -= height);
  43515. verticalAlign === 'middle' && (position[1] -= height / 2); // Not overflow ec container
  43516. confineInContainer(position, width, height, api);
  43517. var bgColor = labelModel.get('backgroundColor');
  43518. if (!bgColor || bgColor === 'auto') {
  43519. bgColor = axisModel.get(['axisLine', 'lineStyle', 'color']);
  43520. }
  43521. elOption.label = {
  43522. // shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  43523. x: position[0],
  43524. y: position[1],
  43525. style: createTextStyle(labelModel, {
  43526. text: text,
  43527. font: font,
  43528. fill: labelModel.getTextColor(),
  43529. padding: paddings,
  43530. backgroundColor: bgColor
  43531. }),
  43532. // Lable should be over axisPointer.
  43533. z2: 10
  43534. };
  43535. } // Do not overflow ec container
  43536. function confineInContainer(position, width, height, api) {
  43537. var viewWidth = api.getWidth();
  43538. var viewHeight = api.getHeight();
  43539. position[0] = Math.min(position[0] + width, viewWidth) - width;
  43540. position[1] = Math.min(position[1] + height, viewHeight) - height;
  43541. position[0] = Math.max(position[0], 0);
  43542. position[1] = Math.max(position[1], 0);
  43543. }
  43544. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  43545. value = axis.scale.parse(value);
  43546. var text = axis.scale.getLabel({
  43547. value: value
  43548. }, {
  43549. // If `precision` is set, width can be fixed (like '12.00500'), which
  43550. // helps to debounce when when moving label.
  43551. precision: opt.precision
  43552. });
  43553. var formatter = opt.formatter;
  43554. if (formatter) {
  43555. var params_1 = {
  43556. value: getAxisRawValue(axis, {
  43557. value: value
  43558. }),
  43559. axisDimension: axis.dim,
  43560. axisIndex: axis.index,
  43561. seriesData: []
  43562. };
  43563. each(seriesDataIndices, function (idxItem) {
  43564. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  43565. var dataIndex = idxItem.dataIndexInside;
  43566. var dataParams = series && series.getDataParams(dataIndex);
  43567. dataParams && params_1.seriesData.push(dataParams);
  43568. });
  43569. if (isString(formatter)) {
  43570. text = formatter.replace('{value}', text);
  43571. } else if (isFunction(formatter)) {
  43572. text = formatter(params_1);
  43573. }
  43574. }
  43575. return text;
  43576. }
  43577. function getTransformedPosition(axis, value, layoutInfo) {
  43578. var transform = create$1();
  43579. rotate(transform, transform, layoutInfo.rotation);
  43580. translate(transform, transform, layoutInfo.position);
  43581. return applyTransform$1([axis.dataToCoord(value), (layoutInfo.labelOffset || 0) + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)], transform);
  43582. }
  43583. function buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api) {
  43584. // @ts-ignore
  43585. var textLayout = AxisBuilder.innerTextLayout(layoutInfo.rotation, 0, layoutInfo.labelDirection);
  43586. layoutInfo.labelMargin = axisPointerModel.get(['label', 'margin']);
  43587. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  43588. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  43589. align: textLayout.textAlign,
  43590. verticalAlign: textLayout.textVerticalAlign
  43591. });
  43592. }
  43593. function makeLineShape(p1, p2, xDimIndex) {
  43594. xDimIndex = xDimIndex || 0;
  43595. return {
  43596. x1: p1[xDimIndex],
  43597. y1: p1[1 - xDimIndex],
  43598. x2: p2[xDimIndex],
  43599. y2: p2[1 - xDimIndex]
  43600. };
  43601. }
  43602. function makeRectShape(xy, wh, xDimIndex) {
  43603. xDimIndex = xDimIndex || 0;
  43604. return {
  43605. x: xy[xDimIndex],
  43606. y: xy[1 - xDimIndex],
  43607. width: wh[xDimIndex],
  43608. height: wh[1 - xDimIndex]
  43609. };
  43610. }
  43611. var CartesianAxisPointer =
  43612. /** @class */
  43613. function (_super) {
  43614. __extends(CartesianAxisPointer, _super);
  43615. function CartesianAxisPointer() {
  43616. return _super !== null && _super.apply(this, arguments) || this;
  43617. }
  43618. /**
  43619. * @override
  43620. */
  43621. CartesianAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  43622. var axis = axisModel.axis;
  43623. var grid = axis.grid;
  43624. var axisPointerType = axisPointerModel.get('type');
  43625. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  43626. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  43627. if (axisPointerType && axisPointerType !== 'none') {
  43628. var elStyle = buildElStyle(axisPointerModel);
  43629. var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, otherExtent);
  43630. pointerOption.style = elStyle;
  43631. elOption.graphicKey = pointerOption.type;
  43632. elOption.pointer = pointerOption;
  43633. }
  43634. var layoutInfo = layout$1(grid.model, axisModel);
  43635. buildCartesianSingleLabelElOption( // @ts-ignore
  43636. value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  43637. };
  43638. /**
  43639. * @override
  43640. */
  43641. CartesianAxisPointer.prototype.getHandleTransform = function (value, axisModel, axisPointerModel) {
  43642. var layoutInfo = layout$1(axisModel.axis.grid.model, axisModel, {
  43643. labelInside: false
  43644. }); // @ts-ignore
  43645. layoutInfo.labelMargin = axisPointerModel.get(['handle', 'margin']);
  43646. var pos = getTransformedPosition(axisModel.axis, value, layoutInfo);
  43647. return {
  43648. x: pos[0],
  43649. y: pos[1],
  43650. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  43651. };
  43652. };
  43653. /**
  43654. * @override
  43655. */
  43656. CartesianAxisPointer.prototype.updateHandleTransform = function (transform, delta, axisModel, axisPointerModel) {
  43657. var axis = axisModel.axis;
  43658. var grid = axis.grid;
  43659. var axisExtent = axis.getGlobalExtent(true);
  43660. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  43661. var dimIndex = axis.dim === 'x' ? 0 : 1;
  43662. var currPosition = [transform.x, transform.y];
  43663. currPosition[dimIndex] += delta[dimIndex];
  43664. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  43665. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  43666. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  43667. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  43668. cursorPoint[dimIndex] = currPosition[dimIndex]; // Make tooltip do not overlap axisPointer and in the middle of the grid.
  43669. var tooltipOptions = [{
  43670. verticalAlign: 'middle'
  43671. }, {
  43672. align: 'center'
  43673. }];
  43674. return {
  43675. x: currPosition[0],
  43676. y: currPosition[1],
  43677. rotation: transform.rotation,
  43678. cursorPoint: cursorPoint,
  43679. tooltipOption: tooltipOptions[dimIndex]
  43680. };
  43681. };
  43682. return CartesianAxisPointer;
  43683. }(BaseAxisPointer);
  43684. function getCartesian(grid, axis) {
  43685. var opt = {};
  43686. opt[axis.dim + 'AxisIndex'] = axis.index;
  43687. return grid.getCartesian(opt);
  43688. }
  43689. var pointerShapeBuilder = {
  43690. line: function (axis, pixelValue, otherExtent) {
  43691. var targetShape = makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getAxisDimIndex(axis));
  43692. return {
  43693. type: 'Line',
  43694. subPixelOptimize: true,
  43695. shape: targetShape
  43696. };
  43697. },
  43698. shadow: function (axis, pixelValue, otherExtent) {
  43699. var bandWidth = Math.max(1, axis.getBandWidth());
  43700. var span = otherExtent[1] - otherExtent[0];
  43701. return {
  43702. type: 'Rect',
  43703. shape: makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getAxisDimIndex(axis))
  43704. };
  43705. }
  43706. };
  43707. function getAxisDimIndex(axis) {
  43708. return axis.dim === 'x' ? 0 : 1;
  43709. }
  43710. var AxisPointerModel =
  43711. /** @class */
  43712. function (_super) {
  43713. __extends(AxisPointerModel, _super);
  43714. function AxisPointerModel() {
  43715. var _this = _super !== null && _super.apply(this, arguments) || this;
  43716. _this.type = AxisPointerModel.type;
  43717. return _this;
  43718. }
  43719. AxisPointerModel.type = 'axisPointer';
  43720. AxisPointerModel.defaultOption = {
  43721. // 'auto' means that show when triggered by tooltip or handle.
  43722. show: 'auto',
  43723. zlevel: 0,
  43724. z: 50,
  43725. type: 'line',
  43726. // axispointer triggered by tootip determine snap automatically,
  43727. // see `modelHelper`.
  43728. snap: false,
  43729. triggerTooltip: true,
  43730. value: null,
  43731. status: null,
  43732. link: [],
  43733. // Do not set 'auto' here, otherwise global animation: false
  43734. // will not effect at this axispointer.
  43735. animation: null,
  43736. animationDurationUpdate: 200,
  43737. lineStyle: {
  43738. color: '#B9BEC9',
  43739. width: 1,
  43740. type: 'dashed'
  43741. },
  43742. shadowStyle: {
  43743. color: 'rgba(210,219,238,0.2)'
  43744. },
  43745. label: {
  43746. show: true,
  43747. formatter: null,
  43748. precision: 'auto',
  43749. margin: 3,
  43750. color: '#fff',
  43751. padding: [5, 7, 5, 7],
  43752. backgroundColor: 'auto',
  43753. borderColor: null,
  43754. borderWidth: 0,
  43755. borderRadius: 3
  43756. },
  43757. handle: {
  43758. show: false,
  43759. // eslint-disable-next-line
  43760. icon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z',
  43761. size: 45,
  43762. // handle margin is from symbol center to axis, which is stable when circular move.
  43763. margin: 50,
  43764. // color: '#1b8bbd'
  43765. // color: '#2f4554'
  43766. color: '#333',
  43767. shadowBlur: 3,
  43768. shadowColor: '#aaa',
  43769. shadowOffsetX: 0,
  43770. shadowOffsetY: 2,
  43771. // For mobile performance
  43772. throttle: 40
  43773. }
  43774. };
  43775. return AxisPointerModel;
  43776. }(ComponentModel);
  43777. var inner$8 = makeInner();
  43778. var each$3 = each;
  43779. /**
  43780. * @param {string} key
  43781. * @param {module:echarts/ExtensionAPI} api
  43782. * @param {Function} handler
  43783. * param: {string} currTrigger
  43784. * param: {Array.<number>} point
  43785. */
  43786. function register(key, api, handler) {
  43787. if (env.node) {
  43788. return;
  43789. }
  43790. var zr = api.getZr();
  43791. inner$8(zr).records || (inner$8(zr).records = {});
  43792. initGlobalListeners(zr, api);
  43793. var record = inner$8(zr).records[key] || (inner$8(zr).records[key] = {});
  43794. record.handler = handler;
  43795. }
  43796. function initGlobalListeners(zr, api) {
  43797. if (inner$8(zr).initialized) {
  43798. return;
  43799. }
  43800. inner$8(zr).initialized = true;
  43801. useHandler('click', curry(doEnter, 'click'));
  43802. useHandler('mousemove', curry(doEnter, 'mousemove')); // useHandler('mouseout', onLeave);
  43803. useHandler('globalout', onLeave);
  43804. function useHandler(eventType, cb) {
  43805. zr.on(eventType, function (e) {
  43806. var dis = makeDispatchAction(api);
  43807. each$3(inner$8(zr).records, function (record) {
  43808. record && cb(record, e, dis.dispatchAction);
  43809. });
  43810. dispatchTooltipFinally(dis.pendings, api);
  43811. });
  43812. }
  43813. }
  43814. function dispatchTooltipFinally(pendings, api) {
  43815. var showLen = pendings.showTip.length;
  43816. var hideLen = pendings.hideTip.length;
  43817. var actuallyPayload;
  43818. if (showLen) {
  43819. actuallyPayload = pendings.showTip[showLen - 1];
  43820. } else if (hideLen) {
  43821. actuallyPayload = pendings.hideTip[hideLen - 1];
  43822. }
  43823. if (actuallyPayload) {
  43824. actuallyPayload.dispatchAction = null;
  43825. api.dispatchAction(actuallyPayload);
  43826. }
  43827. }
  43828. function onLeave(record, e, dispatchAction) {
  43829. record.handler('leave', null, dispatchAction);
  43830. }
  43831. function doEnter(currTrigger, record, e, dispatchAction) {
  43832. record.handler(currTrigger, e, dispatchAction);
  43833. }
  43834. function makeDispatchAction(api) {
  43835. var pendings = {
  43836. showTip: [],
  43837. hideTip: []
  43838. }; // FIXME
  43839. // better approach?
  43840. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  43841. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  43842. // So we have to add "final stage" to merge those dispatched actions.
  43843. var dispatchAction = function (payload) {
  43844. var pendingList = pendings[payload.type];
  43845. if (pendingList) {
  43846. pendingList.push(payload);
  43847. } else {
  43848. payload.dispatchAction = dispatchAction;
  43849. api.dispatchAction(payload);
  43850. }
  43851. };
  43852. return {
  43853. dispatchAction: dispatchAction,
  43854. pendings: pendings
  43855. };
  43856. }
  43857. function unregister(key, api) {
  43858. if (env.node) {
  43859. return;
  43860. }
  43861. var zr = api.getZr();
  43862. var record = (inner$8(zr).records || {})[key];
  43863. if (record) {
  43864. inner$8(zr).records[key] = null;
  43865. }
  43866. }
  43867. var AxisPointerView =
  43868. /** @class */
  43869. function (_super) {
  43870. __extends(AxisPointerView, _super);
  43871. function AxisPointerView() {
  43872. var _this = _super !== null && _super.apply(this, arguments) || this;
  43873. _this.type = AxisPointerView.type;
  43874. return _this;
  43875. }
  43876. AxisPointerView.prototype.render = function (globalAxisPointerModel, ecModel, api) {
  43877. var globalTooltipModel = ecModel.getComponent('tooltip');
  43878. var triggerOn = globalAxisPointerModel.get('triggerOn') || globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click'; // Register global listener in AxisPointerView to enable
  43879. // AxisPointerView to be independent to Tooltip.
  43880. register('axisPointer', api, function (currTrigger, e, dispatchAction) {
  43881. // If 'none', it is not controlled by mouse totally.
  43882. if (triggerOn !== 'none' && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)) {
  43883. dispatchAction({
  43884. type: 'updateAxisPointer',
  43885. currTrigger: currTrigger,
  43886. x: e && e.offsetX,
  43887. y: e && e.offsetY
  43888. });
  43889. }
  43890. });
  43891. };
  43892. AxisPointerView.prototype.remove = function (ecModel, api) {
  43893. unregister('axisPointer', api);
  43894. };
  43895. AxisPointerView.prototype.dispose = function (ecModel, api) {
  43896. unregister('axisPointer', api);
  43897. };
  43898. AxisPointerView.type = 'axisPointer';
  43899. return AxisPointerView;
  43900. }(ComponentView);
  43901. /**
  43902. * @param finder contains {seriesIndex, dataIndex, dataIndexInside}
  43903. * @param ecModel
  43904. * @return {point: [x, y], el: ...} point Will not be null.
  43905. */
  43906. function findPointFromSeries(finder, ecModel) {
  43907. var point = [];
  43908. var seriesIndex = finder.seriesIndex;
  43909. var seriesModel;
  43910. if (seriesIndex == null || !(seriesModel = ecModel.getSeriesByIndex(seriesIndex))) {
  43911. return {
  43912. point: []
  43913. };
  43914. }
  43915. var data = seriesModel.getData();
  43916. var dataIndex = queryDataIndex(data, finder);
  43917. if (dataIndex == null || dataIndex < 0 || isArray(dataIndex)) {
  43918. return {
  43919. point: []
  43920. };
  43921. }
  43922. var el = data.getItemGraphicEl(dataIndex);
  43923. var coordSys = seriesModel.coordinateSystem;
  43924. if (seriesModel.getTooltipPosition) {
  43925. point = seriesModel.getTooltipPosition(dataIndex) || [];
  43926. } else if (coordSys && coordSys.dataToPoint) {
  43927. if (finder.isStacked) {
  43928. var baseAxis = coordSys.getBaseAxis();
  43929. var valueAxis = coordSys.getOtherAxis(baseAxis);
  43930. var valueAxisDim = valueAxis.dim;
  43931. var baseAxisDim = baseAxis.dim;
  43932. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  43933. var baseDim = data.mapDimension(baseAxisDim);
  43934. var stackedData = [];
  43935. stackedData[baseDataOffset] = data.get(baseDim, dataIndex);
  43936. stackedData[1 - baseDataOffset] = data.get(data.getCalculationInfo('stackResultDimension'), dataIndex);
  43937. point = coordSys.dataToPoint(stackedData) || [];
  43938. } else {
  43939. point = coordSys.dataToPoint(data.getValues(map(coordSys.dimensions, function (dim) {
  43940. return data.mapDimension(dim);
  43941. }), dataIndex)) || [];
  43942. }
  43943. } else if (el) {
  43944. // Use graphic bounding rect
  43945. var rect = el.getBoundingRect().clone();
  43946. rect.applyTransform(el.transform);
  43947. point = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  43948. }
  43949. return {
  43950. point: point,
  43951. el: el
  43952. };
  43953. }
  43954. var inner$9 = makeInner();
  43955. /**
  43956. * Basic logic: check all axis, if they do not demand show/highlight,
  43957. * then hide/downplay them.
  43958. *
  43959. * @return content of event obj for echarts.connect.
  43960. */
  43961. function axisTrigger(payload, ecModel, api) {
  43962. var currTrigger = payload.currTrigger;
  43963. var point = [payload.x, payload.y];
  43964. var finder = payload;
  43965. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  43966. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo; // Pending
  43967. // See #6121. But we are not able to reproduce it yet.
  43968. if (!coordSysAxesInfo) {
  43969. return;
  43970. }
  43971. if (illegalPoint(point)) {
  43972. // Used in the default behavior of `connection`: use the sample seriesIndex
  43973. // and dataIndex. And also used in the tooltipView trigger.
  43974. point = findPointFromSeries({
  43975. seriesIndex: finder.seriesIndex,
  43976. // Do not use dataIndexInside from other ec instance.
  43977. // FIXME: auto detect it?
  43978. dataIndex: finder.dataIndex
  43979. }, ecModel).point;
  43980. }
  43981. var isIllegalPoint = illegalPoint(point); // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  43982. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  43983. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  43984. // and dataIndex.
  43985. var inputAxesInfo = finder.axesInfo;
  43986. var axesInfo = coordSysAxesInfo.axesInfo;
  43987. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  43988. var outputPayload = {};
  43989. var showValueMap = {};
  43990. var dataByCoordSys = {
  43991. list: [],
  43992. map: {}
  43993. };
  43994. var updaters = {
  43995. showPointer: curry(showPointer, showValueMap),
  43996. showTooltip: curry(showTooltip, dataByCoordSys)
  43997. }; // Process for triggered axes.
  43998. each(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  43999. // If a point given, it must be contained by the coordinate system.
  44000. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  44001. each(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  44002. var axis = axisInfo.axis;
  44003. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo); // If no inputAxesInfo, no axis is restricted.
  44004. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  44005. var val = inputAxisInfo && inputAxisInfo.value;
  44006. if (val == null && !isIllegalPoint) {
  44007. val = axis.pointToData(point);
  44008. }
  44009. val != null && processOnAxis(axisInfo, val, updaters, false, outputPayload);
  44010. }
  44011. });
  44012. }); // Process for linked axes.
  44013. var linkTriggers = {};
  44014. each(axesInfo, function (tarAxisInfo, tarKey) {
  44015. var linkGroup = tarAxisInfo.linkGroup; // If axis has been triggered in the previous stage, it should not be triggered by link.
  44016. if (linkGroup && !showValueMap[tarKey]) {
  44017. each(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  44018. var srcValItem = showValueMap[srcKey]; // If srcValItem exist, source axis is triggered, so link to target axis.
  44019. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  44020. var val = srcValItem.value;
  44021. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo))));
  44022. linkTriggers[tarAxisInfo.key] = val;
  44023. }
  44024. });
  44025. }
  44026. });
  44027. each(linkTriggers, function (val, tarKey) {
  44028. processOnAxis(axesInfo[tarKey], val, updaters, true, outputPayload);
  44029. });
  44030. updateModelActually(showValueMap, axesInfo, outputPayload);
  44031. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  44032. dispatchHighDownActually(axesInfo, dispatchAction, api);
  44033. return outputPayload;
  44034. }
  44035. function processOnAxis(axisInfo, newValue, updaters, noSnap, outputFinder) {
  44036. var axis = axisInfo.axis;
  44037. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  44038. return;
  44039. }
  44040. if (!axisInfo.involveSeries) {
  44041. updaters.showPointer(axisInfo, newValue);
  44042. return;
  44043. } // Heavy calculation. So put it after axis.containData checking.
  44044. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  44045. var payloadBatch = payloadInfo.payloadBatch;
  44046. var snapToValue = payloadInfo.snapToValue; // Fill content of event obj for echarts.connect.
  44047. // By default use the first involved series data as a sample to connect.
  44048. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  44049. extend(outputFinder, payloadBatch[0]);
  44050. } // If no linkSource input, this process is for collecting link
  44051. // target, where snap should not be accepted.
  44052. if (!noSnap && axisInfo.snap) {
  44053. if (axis.containData(snapToValue) && snapToValue != null) {
  44054. newValue = snapToValue;
  44055. }
  44056. }
  44057. updaters.showPointer(axisInfo, newValue, payloadBatch); // Tooltip should always be snapToValue, otherwise there will be
  44058. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  44059. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  44060. }
  44061. function buildPayloadsBySeries(value, axisInfo) {
  44062. var axis = axisInfo.axis;
  44063. var dim = axis.dim;
  44064. var snapToValue = value;
  44065. var payloadBatch = [];
  44066. var minDist = Number.MAX_VALUE;
  44067. var minDiff = -1;
  44068. each(axisInfo.seriesModels, function (series, idx) {
  44069. var dataDim = series.getData().mapDimensionsAll(dim);
  44070. var seriesNestestValue;
  44071. var dataIndices;
  44072. if (series.getAxisTooltipData) {
  44073. var result = series.getAxisTooltipData(dataDim, value, axis);
  44074. dataIndices = result.dataIndices;
  44075. seriesNestestValue = result.nestestValue;
  44076. } else {
  44077. dataIndices = series.getData().indicesOfNearest(dataDim[0], value, // Add a threshold to avoid find the wrong dataIndex
  44078. // when data length is not same.
  44079. // false,
  44080. axis.type === 'category' ? 0.5 : null);
  44081. if (!dataIndices.length) {
  44082. return;
  44083. }
  44084. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  44085. }
  44086. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  44087. return;
  44088. }
  44089. var diff = value - seriesNestestValue;
  44090. var dist = Math.abs(diff); // Consider category case
  44091. if (dist <= minDist) {
  44092. if (dist < minDist || diff >= 0 && minDiff < 0) {
  44093. minDist = dist;
  44094. minDiff = diff;
  44095. snapToValue = seriesNestestValue;
  44096. payloadBatch.length = 0;
  44097. }
  44098. each(dataIndices, function (dataIndex) {
  44099. payloadBatch.push({
  44100. seriesIndex: series.seriesIndex,
  44101. dataIndexInside: dataIndex,
  44102. dataIndex: series.getData().getRawIndex(dataIndex)
  44103. });
  44104. });
  44105. }
  44106. });
  44107. return {
  44108. payloadBatch: payloadBatch,
  44109. snapToValue: snapToValue
  44110. };
  44111. }
  44112. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  44113. showValueMap[axisInfo.key] = {
  44114. value: value,
  44115. payloadBatch: payloadBatch
  44116. };
  44117. }
  44118. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  44119. var payloadBatch = payloadInfo.payloadBatch;
  44120. var axis = axisInfo.axis;
  44121. var axisModel = axis.model;
  44122. var axisPointerModel = axisInfo.axisPointerModel; // If no data, do not create anything in dataByCoordSys,
  44123. // whose length will be used to judge whether dispatch action.
  44124. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  44125. return;
  44126. }
  44127. var coordSysModel = axisInfo.coordSys.model;
  44128. var coordSysKey = makeKey(coordSysModel);
  44129. var coordSysItem = dataByCoordSys.map[coordSysKey];
  44130. if (!coordSysItem) {
  44131. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  44132. coordSysId: coordSysModel.id,
  44133. coordSysIndex: coordSysModel.componentIndex,
  44134. coordSysType: coordSysModel.type,
  44135. coordSysMainType: coordSysModel.mainType,
  44136. dataByAxis: []
  44137. };
  44138. dataByCoordSys.list.push(coordSysItem);
  44139. }
  44140. coordSysItem.dataByAxis.push({
  44141. axisDim: axis.dim,
  44142. axisIndex: axisModel.componentIndex,
  44143. axisType: axisModel.type,
  44144. axisId: axisModel.id,
  44145. value: value,
  44146. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  44147. // depends that all models have been updated. So it should not be performed
  44148. // here. Considering axisPointerModel used here is volatile, which is hard
  44149. // to be retrieve in TooltipView, we prepare parameters here.
  44150. valueLabelOpt: {
  44151. precision: axisPointerModel.get(['label', 'precision']),
  44152. formatter: axisPointerModel.get(['label', 'formatter'])
  44153. },
  44154. seriesDataIndices: payloadBatch.slice()
  44155. });
  44156. }
  44157. function updateModelActually(showValueMap, axesInfo, outputPayload) {
  44158. var outputAxesInfo = outputPayload.axesInfo = []; // Basic logic: If no 'show' required, 'hide' this axisPointer.
  44159. each(axesInfo, function (axisInfo, key) {
  44160. var option = axisInfo.axisPointerModel.option;
  44161. var valItem = showValueMap[key];
  44162. if (valItem) {
  44163. !axisInfo.useHandle && (option.status = 'show');
  44164. option.value = valItem.value; // For label formatter param and highlight.
  44165. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  44166. } // When always show (e.g., handle used), remain
  44167. // original value and status.
  44168. else {
  44169. // If hide, value still need to be set, consider
  44170. // click legend to toggle axis blank.
  44171. !axisInfo.useHandle && (option.status = 'hide');
  44172. } // If status is 'hide', should be no info in payload.
  44173. option.status === 'show' && outputAxesInfo.push({
  44174. axisDim: axisInfo.axis.dim,
  44175. axisIndex: axisInfo.axis.model.componentIndex,
  44176. value: option.value
  44177. });
  44178. });
  44179. }
  44180. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  44181. // Basic logic: If no showTip required, hideTip will be dispatched.
  44182. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  44183. dispatchAction({
  44184. type: 'hideTip'
  44185. });
  44186. return;
  44187. } // In most case only one axis (or event one series is used). It is
  44188. // convinient to fetch payload.seriesIndex and payload.dataIndex
  44189. // dirtectly. So put the first seriesIndex and dataIndex of the first
  44190. // axis on the payload.
  44191. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  44192. dispatchAction({
  44193. type: 'showTip',
  44194. escapeConnect: true,
  44195. x: point[0],
  44196. y: point[1],
  44197. tooltipOption: payload.tooltipOption,
  44198. position: payload.position,
  44199. dataIndexInside: sampleItem.dataIndexInside,
  44200. dataIndex: sampleItem.dataIndex,
  44201. seriesIndex: sampleItem.seriesIndex,
  44202. dataByCoordSys: dataByCoordSys.list
  44203. });
  44204. }
  44205. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  44206. // FIXME
  44207. // highlight status modification shoule be a stage of main process?
  44208. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  44209. var zr = api.getZr();
  44210. var highDownKey = 'axisPointerLastHighlights';
  44211. var lastHighlights = inner$9(zr)[highDownKey] || {};
  44212. var newHighlights = inner$9(zr)[highDownKey] = {}; // Update highlight/downplay status according to axisPointer model.
  44213. // Build hash map and remove duplicate incidentally.
  44214. each(axesInfo, function (axisInfo, key) {
  44215. var option = axisInfo.axisPointerModel.option;
  44216. option.status === 'show' && each(option.seriesDataIndices, function (batchItem) {
  44217. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  44218. newHighlights[key] = batchItem;
  44219. });
  44220. }); // Diff.
  44221. var toHighlight = [];
  44222. var toDownplay = [];
  44223. each(lastHighlights, function (batchItem, key) {
  44224. !newHighlights[key] && toDownplay.push(batchItem);
  44225. });
  44226. each(newHighlights, function (batchItem, key) {
  44227. !lastHighlights[key] && toHighlight.push(batchItem);
  44228. });
  44229. toDownplay.length && api.dispatchAction({
  44230. type: 'downplay',
  44231. escapeConnect: true,
  44232. // Not blur others when highlight in axisPointer.
  44233. notBlur: true,
  44234. batch: toDownplay
  44235. });
  44236. toHighlight.length && api.dispatchAction({
  44237. type: 'highlight',
  44238. escapeConnect: true,
  44239. // Not blur others when highlight in axisPointer.
  44240. notBlur: true,
  44241. batch: toHighlight
  44242. });
  44243. }
  44244. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  44245. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  44246. var inputAxisInfo = inputAxesInfo[i];
  44247. if (axisInfo.axis.dim === inputAxisInfo.axisDim && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex) {
  44248. return inputAxisInfo;
  44249. }
  44250. }
  44251. }
  44252. function makeMapperParam(axisInfo) {
  44253. var axisModel = axisInfo.axis.model;
  44254. var item = {};
  44255. var dim = item.axisDim = axisInfo.axis.dim;
  44256. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  44257. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  44258. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  44259. return item;
  44260. }
  44261. function illegalPoint(point) {
  44262. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  44263. }
  44264. function install$7(registers) {
  44265. // CartesianAxisPointer is not supposed to be required here. But consider
  44266. // echarts.simple.js and online build tooltip, which only require gridSimple,
  44267. // CartesianAxisPointer should be able to required somewhere.
  44268. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  44269. registers.registerComponentModel(AxisPointerModel);
  44270. registers.registerComponentView(AxisPointerView);
  44271. registers.registerPreprocessor(function (option) {
  44272. // Always has a global axisPointerModel for default setting.
  44273. if (option) {
  44274. (!option.axisPointer || option.axisPointer.length === 0) && (option.axisPointer = {});
  44275. var link = option.axisPointer.link; // Normalize to array to avoid object mergin. But if link
  44276. // is not set, remain null/undefined, otherwise it will
  44277. // override existent link setting.
  44278. if (link && !isArray(link)) {
  44279. option.axisPointer.link = [link];
  44280. }
  44281. }
  44282. }); // This process should proformed after coordinate systems created
  44283. // and series data processed. So put it on statistic processing stage.
  44284. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  44285. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  44286. // allAxesInfo should be updated when setOption performed.
  44287. ecModel.getComponent('axisPointer').coordSysAxesInfo = collect(ecModel, api);
  44288. }); // Broadcast to all views.
  44289. registers.registerAction({
  44290. type: 'updateAxisPointer',
  44291. event: 'updateAxisPointer',
  44292. update: ':updateAxisPointer'
  44293. }, axisTrigger);
  44294. }
  44295. function install$8(registers) {
  44296. use(install$5);
  44297. use(install$7);
  44298. }
  44299. /**
  44300. * Whether need to call `convertEC4CompatibleStyle`.
  44301. */
  44302. function isEC4CompatibleStyle(style, elType, hasOwnTextContentOption, hasOwnTextConfig) {
  44303. // Since echarts5, `RectText` is separated from its host element and style.text
  44304. // does not exist any more. The compat work brings some extra burden on performance.
  44305. // So we provide:
  44306. // `legacy: true` force make compat.
  44307. // `legacy: false`, force do not compat.
  44308. // `legacy` not set: auto detect wheter legacy.
  44309. // But in this case we do not compat (difficult to detect and rare case):
  44310. // Becuse custom series and graphic component support "merge", users may firstly
  44311. // only set `textStrokeWidth` style or secondly only set `text`.
  44312. return style && (style.legacy || style.legacy !== false && !hasOwnTextContentOption && !hasOwnTextConfig && elType !== 'tspan' // Difficult to detect whether legacy for a "text" el.
  44313. && (elType === 'text' || hasOwn(style, 'text')));
  44314. }
  44315. /**
  44316. * `EC4CompatibleStyle` is style that might be in echarts4 format or echarts5 format.
  44317. * @param hostStyle The properties might be modified.
  44318. * @return If be text el, `textContentStyle` and `textConfig` will not be retured.
  44319. * Otherwise a `textContentStyle` and `textConfig` will be created, whose props area
  44320. * retried from the `hostStyle`.
  44321. */
  44322. function convertFromEC4CompatibleStyle(hostStyle, elType, isNormal) {
  44323. var srcStyle = hostStyle;
  44324. var textConfig;
  44325. var textContent;
  44326. var textContentStyle;
  44327. if (elType === 'text') {
  44328. textContentStyle = srcStyle;
  44329. } else {
  44330. textContentStyle = {};
  44331. hasOwn(srcStyle, 'text') && (textContentStyle.text = srcStyle.text);
  44332. hasOwn(srcStyle, 'rich') && (textContentStyle.rich = srcStyle.rich);
  44333. hasOwn(srcStyle, 'textFill') && (textContentStyle.fill = srcStyle.textFill);
  44334. hasOwn(srcStyle, 'textStroke') && (textContentStyle.stroke = srcStyle.textStroke);
  44335. hasOwn(srcStyle, 'fontFamily') && (textContentStyle.fontFamily = srcStyle.fontFamily);
  44336. hasOwn(srcStyle, 'fontSize') && (textContentStyle.fontSize = srcStyle.fontSize);
  44337. hasOwn(srcStyle, 'fontStyle') && (textContentStyle.fontStyle = srcStyle.fontStyle);
  44338. hasOwn(srcStyle, 'fontWeight') && (textContentStyle.fontWeight = srcStyle.fontWeight);
  44339. textContent = {
  44340. type: 'text',
  44341. style: textContentStyle,
  44342. // ec4 do not support rectText trigger.
  44343. // And when text postion is different in normal and emphasis
  44344. // => hover text trigger emphasis;
  44345. // => text position changed, leave mouse pointer immediately;
  44346. // That might cause state incorrect.
  44347. silent: true
  44348. };
  44349. textConfig = {};
  44350. var hasOwnPos = hasOwn(srcStyle, 'textPosition');
  44351. if (isNormal) {
  44352. textConfig.position = hasOwnPos ? srcStyle.textPosition : 'inside';
  44353. } else {
  44354. hasOwnPos && (textConfig.position = srcStyle.textPosition);
  44355. }
  44356. hasOwn(srcStyle, 'textPosition') && (textConfig.position = srcStyle.textPosition);
  44357. hasOwn(srcStyle, 'textOffset') && (textConfig.offset = srcStyle.textOffset);
  44358. hasOwn(srcStyle, 'textRotation') && (textConfig.rotation = srcStyle.textRotation);
  44359. hasOwn(srcStyle, 'textDistance') && (textConfig.distance = srcStyle.textDistance);
  44360. }
  44361. convertEC4CompatibleRichItem(textContentStyle, hostStyle);
  44362. each(textContentStyle.rich, function (richItem) {
  44363. convertEC4CompatibleRichItem(richItem, richItem);
  44364. });
  44365. return {
  44366. textConfig: textConfig,
  44367. textContent: textContent
  44368. };
  44369. }
  44370. /**
  44371. * The result will be set to `out`.
  44372. */
  44373. function convertEC4CompatibleRichItem(out, richItem) {
  44374. if (!richItem) {
  44375. return;
  44376. } // (1) For simplicity, make textXXX properties (deprecated since ec5) has
  44377. // higher priority. For example, consider in ec4 `borderColor: 5, textBorderColor: 10`
  44378. // on a rect means `borderColor: 4` on the rect and `borderColor: 10` on an attached
  44379. // richText in ec5.
  44380. // (2) `out === richItem` if and only if `out` is text el or rich item.
  44381. // So we can overwite existing props in `out` since textXXX has higher priority.
  44382. richItem.font = richItem.textFont || richItem.font;
  44383. hasOwn(richItem, 'textStrokeWidth') && (out.lineWidth = richItem.textStrokeWidth);
  44384. hasOwn(richItem, 'textAlign') && (out.align = richItem.textAlign);
  44385. hasOwn(richItem, 'textVerticalAlign') && (out.verticalAlign = richItem.textVerticalAlign);
  44386. hasOwn(richItem, 'textLineHeight') && (out.lineHeight = richItem.textLineHeight);
  44387. hasOwn(richItem, 'textWidth') && (out.width = richItem.textWidth);
  44388. hasOwn(richItem, 'textHeight') && (out.height = richItem.textHeight);
  44389. hasOwn(richItem, 'textBackgroundColor') && (out.backgroundColor = richItem.textBackgroundColor);
  44390. hasOwn(richItem, 'textPadding') && (out.padding = richItem.textPadding);
  44391. hasOwn(richItem, 'textBorderColor') && (out.borderColor = richItem.textBorderColor);
  44392. hasOwn(richItem, 'textBorderWidth') && (out.borderWidth = richItem.textBorderWidth);
  44393. hasOwn(richItem, 'textBorderRadius') && (out.borderRadius = richItem.textBorderRadius);
  44394. hasOwn(richItem, 'textBoxShadowColor') && (out.shadowColor = richItem.textBoxShadowColor);
  44395. hasOwn(richItem, 'textBoxShadowBlur') && (out.shadowBlur = richItem.textBoxShadowBlur);
  44396. hasOwn(richItem, 'textBoxShadowOffsetX') && (out.shadowOffsetX = richItem.textBoxShadowOffsetX);
  44397. hasOwn(richItem, 'textBoxShadowOffsetY') && (out.shadowOffsetY = richItem.textBoxShadowOffsetY);
  44398. }
  44399. var inner$a = makeInner();
  44400. var _nonShapeGraphicElements = {
  44401. // Reserved but not supported in graphic component.
  44402. path: null,
  44403. compoundPath: null,
  44404. // Supported in graphic component.
  44405. group: Group,
  44406. image: ZRImage,
  44407. text: ZRText
  44408. }; // ------------------------
  44409. // Preprocessor
  44410. // ------------------------
  44411. var preprocessor = function (option) {
  44412. var graphicOption = option.graphic; // Convert
  44413. // {graphic: [{left: 10, type: 'circle'}, ...]}
  44414. // or
  44415. // {graphic: {left: 10, type: 'circle'}}
  44416. // to
  44417. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  44418. if (isArray(graphicOption)) {
  44419. if (!graphicOption[0] || !graphicOption[0].elements) {
  44420. option.graphic = [{
  44421. elements: graphicOption
  44422. }];
  44423. } else {
  44424. // Only one graphic instance can be instantiated. (We dont
  44425. // want that too many views are created in echarts._viewMap)
  44426. option.graphic = [option.graphic[0]];
  44427. }
  44428. } else if (graphicOption && !graphicOption.elements) {
  44429. option.graphic = [{
  44430. elements: [graphicOption]
  44431. }];
  44432. }
  44433. };
  44434. var GraphicComponentModel =
  44435. /** @class */
  44436. function (_super) {
  44437. __extends(GraphicComponentModel, _super);
  44438. function GraphicComponentModel() {
  44439. var _this = _super !== null && _super.apply(this, arguments) || this;
  44440. _this.type = GraphicComponentModel.type;
  44441. _this.preventAutoZ = true;
  44442. return _this;
  44443. }
  44444. GraphicComponentModel.prototype.mergeOption = function (option, ecModel) {
  44445. // Prevent default merge to elements
  44446. var elements = this.option.elements;
  44447. this.option.elements = null;
  44448. _super.prototype.mergeOption.call(this, option, ecModel);
  44449. this.option.elements = elements;
  44450. };
  44451. GraphicComponentModel.prototype.optionUpdated = function (newOption, isInit) {
  44452. var thisOption = this.option;
  44453. var newList = (isInit ? thisOption : newOption).elements;
  44454. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  44455. var flattenedList = [];
  44456. this._flatten(newList, flattenedList, null);
  44457. var mappingResult = mappingToExists(existList, flattenedList, 'normalMerge'); // Clear elOptionsToUpdate
  44458. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  44459. each(mappingResult, function (resultItem, index) {
  44460. var newElOption = resultItem.newOption;
  44461. if ("development" !== 'production') {
  44462. assert(isObject(newElOption) || resultItem.existing, 'Empty graphic option definition');
  44463. }
  44464. if (!newElOption) {
  44465. return;
  44466. }
  44467. elOptionsToUpdate.push(newElOption);
  44468. setKeyInfoToNewElOption(resultItem, newElOption);
  44469. mergeNewElOptionToExist(existList, index, newElOption);
  44470. setLayoutInfoToExist(existList[index], newElOption);
  44471. }, this); // Clean
  44472. for (var i = existList.length - 1; i >= 0; i--) {
  44473. if (existList[i] == null) {
  44474. existList.splice(i, 1);
  44475. } else {
  44476. // $action should be volatile, otherwise option gotten from
  44477. // `getOption` will contain unexpected $action.
  44478. delete existList[i].$action;
  44479. }
  44480. }
  44481. };
  44482. /**
  44483. * Convert
  44484. * [{
  44485. * type: 'group',
  44486. * id: 'xx',
  44487. * children: [{type: 'circle'}, {type: 'polygon'}]
  44488. * }]
  44489. * to
  44490. * [
  44491. * {type: 'group', id: 'xx'},
  44492. * {type: 'circle', parentId: 'xx'},
  44493. * {type: 'polygon', parentId: 'xx'}
  44494. * ]
  44495. */
  44496. GraphicComponentModel.prototype._flatten = function (optionList, result, parentOption) {
  44497. each(optionList, function (option) {
  44498. if (!option) {
  44499. return;
  44500. }
  44501. if (parentOption) {
  44502. option.parentOption = parentOption;
  44503. }
  44504. result.push(option);
  44505. var children = option.children;
  44506. if (option.type === 'group' && children) {
  44507. this._flatten(children, result, option);
  44508. } // Deleting for JSON output, and for not affecting group creation.
  44509. delete option.children;
  44510. }, this);
  44511. }; // FIXME
  44512. // Pass to view using payload? setOption has a payload?
  44513. GraphicComponentModel.prototype.useElOptionsToUpdate = function () {
  44514. var els = this._elOptionsToUpdate; // Clear to avoid render duplicately when zooming.
  44515. this._elOptionsToUpdate = null;
  44516. return els;
  44517. };
  44518. GraphicComponentModel.type = 'graphic';
  44519. GraphicComponentModel.defaultOption = {
  44520. elements: [] // parentId: null
  44521. };
  44522. return GraphicComponentModel;
  44523. }(ComponentModel); // ------------------------
  44524. // View
  44525. // ------------------------
  44526. var GraphicComponentView =
  44527. /** @class */
  44528. function (_super) {
  44529. __extends(GraphicComponentView, _super);
  44530. function GraphicComponentView() {
  44531. var _this = _super !== null && _super.apply(this, arguments) || this;
  44532. _this.type = GraphicComponentView.type;
  44533. return _this;
  44534. }
  44535. GraphicComponentView.prototype.init = function () {
  44536. this._elMap = createHashMap();
  44537. };
  44538. GraphicComponentView.prototype.render = function (graphicModel, ecModel, api) {
  44539. // Having leveraged between use cases and algorithm complexity, a very
  44540. // simple layout mechanism is used:
  44541. // The size(width/height) can be determined by itself or its parent (not
  44542. // implemented yet), but can not by its children. (Top-down travel)
  44543. // The location(x/y) can be determined by the bounding rect of itself
  44544. // (can including its descendants or not) and the size of its parent.
  44545. // (Bottom-up travel)
  44546. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  44547. // view will be reused.
  44548. if (graphicModel !== this._lastGraphicModel) {
  44549. this._clear();
  44550. }
  44551. this._lastGraphicModel = graphicModel;
  44552. this._updateElements(graphicModel);
  44553. this._relocate(graphicModel, api);
  44554. };
  44555. /**
  44556. * Update graphic elements.
  44557. */
  44558. GraphicComponentView.prototype._updateElements = function (graphicModel) {
  44559. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  44560. if (!elOptionsToUpdate) {
  44561. return;
  44562. }
  44563. var elMap = this._elMap;
  44564. var rootGroup = this.group; // Top-down tranverse to assign graphic settings to each elements.
  44565. each(elOptionsToUpdate, function (elOption) {
  44566. var id = convertOptionIdName(elOption.id, null);
  44567. var elExisting = id != null ? elMap.get(id) : null;
  44568. var parentId = convertOptionIdName(elOption.parentId, null);
  44569. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  44570. var elType = elOption.type;
  44571. var elOptionStyle = elOption.style;
  44572. if (elType === 'text' && elOptionStyle) {
  44573. // In top/bottom mode, textVerticalAlign should not be used, which cause
  44574. // inaccurately locating.
  44575. if (elOption.hv && elOption.hv[1]) {
  44576. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = elOptionStyle.verticalAlign = elOptionStyle.align = null;
  44577. }
  44578. }
  44579. var textContentOption = elOption.textContent;
  44580. var textConfig = elOption.textConfig;
  44581. if (elOptionStyle && isEC4CompatibleStyle(elOptionStyle, elType, !!textConfig, !!textContentOption)) {
  44582. var convertResult = convertFromEC4CompatibleStyle(elOptionStyle, elType, true);
  44583. if (!textConfig && convertResult.textConfig) {
  44584. textConfig = elOption.textConfig = convertResult.textConfig;
  44585. }
  44586. if (!textContentOption && convertResult.textContent) {
  44587. textContentOption = convertResult.textContent;
  44588. }
  44589. } // Remove unnecessary props to avoid potential problems.
  44590. var elOptionCleaned = getCleanedElOption(elOption); // For simple, do not support parent change, otherwise reorder is needed.
  44591. if ("development" !== 'production') {
  44592. elExisting && assert(targetElParent === elExisting.parent, 'Changing parent is not supported.');
  44593. }
  44594. var $action = elOption.$action || 'merge';
  44595. if ($action === 'merge') {
  44596. elExisting ? elExisting.attr(elOptionCleaned) : createEl(id, targetElParent, elOptionCleaned, elMap);
  44597. } else if ($action === 'replace') {
  44598. removeEl(elExisting, elMap);
  44599. createEl(id, targetElParent, elOptionCleaned, elMap);
  44600. } else if ($action === 'remove') {
  44601. removeEl(elExisting, elMap);
  44602. }
  44603. var el = elMap.get(id);
  44604. if (el && textContentOption) {
  44605. if ($action === 'merge') {
  44606. var textContentExisting = el.getTextContent();
  44607. textContentExisting ? textContentExisting.attr(textContentOption) : el.setTextContent(new ZRText(textContentOption));
  44608. } else if ($action === 'replace') {
  44609. el.setTextContent(new ZRText(textContentOption));
  44610. }
  44611. }
  44612. if (el) {
  44613. var elInner = inner$a(el);
  44614. elInner.__ecGraphicWidthOption = elOption.width;
  44615. elInner.__ecGraphicHeightOption = elOption.height;
  44616. setEventData(el, graphicModel, elOption);
  44617. setTooltipConfig({
  44618. el: el,
  44619. componentModel: graphicModel,
  44620. itemName: el.name,
  44621. itemTooltipOption: elOption.tooltip
  44622. });
  44623. }
  44624. });
  44625. };
  44626. /**
  44627. * Locate graphic elements.
  44628. */
  44629. GraphicComponentView.prototype._relocate = function (graphicModel, api) {
  44630. var elOptions = graphicModel.option.elements;
  44631. var rootGroup = this.group;
  44632. var elMap = this._elMap;
  44633. var apiWidth = api.getWidth();
  44634. var apiHeight = api.getHeight(); // Top-down to calculate percentage width/height of group
  44635. for (var i = 0; i < elOptions.length; i++) {
  44636. var elOption = elOptions[i];
  44637. var id = convertOptionIdName(elOption.id, null);
  44638. var el = id != null ? elMap.get(id) : null;
  44639. if (!el || !el.isGroup) {
  44640. continue;
  44641. }
  44642. var parentEl = el.parent;
  44643. var isParentRoot = parentEl === rootGroup; // Like 'position:absolut' in css, default 0.
  44644. var elInner = inner$a(el);
  44645. var parentElInner = inner$a(parentEl);
  44646. elInner.__ecGraphicWidth = parsePercent$1(elInner.__ecGraphicWidthOption, isParentRoot ? apiWidth : parentElInner.__ecGraphicWidth) || 0;
  44647. elInner.__ecGraphicHeight = parsePercent$1(elInner.__ecGraphicHeightOption, isParentRoot ? apiHeight : parentElInner.__ecGraphicHeight) || 0;
  44648. } // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  44649. for (var i = elOptions.length - 1; i >= 0; i--) {
  44650. var elOption = elOptions[i];
  44651. var id = convertOptionIdName(elOption.id, null);
  44652. var el = id != null ? elMap.get(id) : null;
  44653. if (!el) {
  44654. continue;
  44655. }
  44656. var parentEl = el.parent;
  44657. var parentElInner = inner$a(parentEl);
  44658. var containerInfo = parentEl === rootGroup ? {
  44659. width: apiWidth,
  44660. height: apiHeight
  44661. } : {
  44662. width: parentElInner.__ecGraphicWidth,
  44663. height: parentElInner.__ecGraphicHeight
  44664. }; // PENDING
  44665. // Currently, when `bounding: 'all'`, the union bounding rect of the group
  44666. // does not include the rect of [0, 0, group.width, group.height], which
  44667. // is probably weird for users. Should we make a break change for it?
  44668. positionElement(el, elOption, containerInfo, null, {
  44669. hv: elOption.hv,
  44670. boundingMode: elOption.bounding
  44671. });
  44672. }
  44673. };
  44674. /**
  44675. * Clear all elements.
  44676. */
  44677. GraphicComponentView.prototype._clear = function () {
  44678. var elMap = this._elMap;
  44679. elMap.each(function (el) {
  44680. removeEl(el, elMap);
  44681. });
  44682. this._elMap = createHashMap();
  44683. };
  44684. GraphicComponentView.prototype.dispose = function () {
  44685. this._clear();
  44686. };
  44687. GraphicComponentView.type = 'graphic';
  44688. return GraphicComponentView;
  44689. }(ComponentView);
  44690. function createEl(id, targetElParent, elOption, elMap) {
  44691. var graphicType = elOption.type;
  44692. if ("development" !== 'production') {
  44693. assert(graphicType, 'graphic type MUST be set');
  44694. }
  44695. var Clz = hasOwn(_nonShapeGraphicElements, graphicType) // Those graphic elements are not shapes. They should not be
  44696. // overwritten by users, so do them first.
  44697. ? _nonShapeGraphicElements[graphicType] : getShapeClass(graphicType);
  44698. if ("development" !== 'production') {
  44699. assert(Clz, 'graphic type can not be found');
  44700. }
  44701. var el = new Clz(elOption);
  44702. targetElParent.add(el);
  44703. elMap.set(id, el);
  44704. inner$a(el).__ecGraphicId = id;
  44705. }
  44706. function removeEl(elExisting, elMap) {
  44707. var existElParent = elExisting && elExisting.parent;
  44708. if (existElParent) {
  44709. elExisting.type === 'group' && elExisting.traverse(function (el) {
  44710. removeEl(el, elMap);
  44711. });
  44712. elMap.removeKey(inner$a(elExisting).__ecGraphicId);
  44713. existElParent.remove(elExisting);
  44714. }
  44715. } // Remove unnecessary props to avoid potential problems.
  44716. function getCleanedElOption(elOption) {
  44717. elOption = extend({}, elOption);
  44718. each(['id', 'parentId', '$action', 'hv', 'bounding', 'textContent'].concat(LOCATION_PARAMS), function (name) {
  44719. delete elOption[name];
  44720. });
  44721. return elOption;
  44722. }
  44723. function isSetLoc(obj, props) {
  44724. var isSet;
  44725. each(props, function (prop) {
  44726. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  44727. });
  44728. return isSet;
  44729. }
  44730. function setKeyInfoToNewElOption(resultItem, newElOption) {
  44731. var existElOption = resultItem.existing; // Set id and type after id assigned.
  44732. newElOption.id = resultItem.keyInfo.id;
  44733. !newElOption.type && existElOption && (newElOption.type = existElOption.type); // Set parent id if not specified
  44734. if (newElOption.parentId == null) {
  44735. var newElParentOption = newElOption.parentOption;
  44736. if (newElParentOption) {
  44737. newElOption.parentId = newElParentOption.id;
  44738. } else if (existElOption) {
  44739. newElOption.parentId = existElOption.parentId;
  44740. }
  44741. } // Clear
  44742. newElOption.parentOption = null;
  44743. }
  44744. function mergeNewElOptionToExist(existList, index, newElOption) {
  44745. // Update existing options, for `getOption` feature.
  44746. var newElOptCopy = extend({}, newElOption);
  44747. var existElOption = existList[index];
  44748. var $action = newElOption.$action || 'merge';
  44749. if ($action === 'merge') {
  44750. if (existElOption) {
  44751. if ("development" !== 'production') {
  44752. var newType = newElOption.type;
  44753. assert(!newType || existElOption.type === newType, 'Please set $action: "replace" to change `type`');
  44754. } // We can ensure that newElOptCopy and existElOption are not
  44755. // the same object, so `merge` will not change newElOptCopy.
  44756. merge(existElOption, newElOptCopy, true); // Rigid body, use ignoreSize.
  44757. mergeLayoutParam(existElOption, newElOptCopy, {
  44758. ignoreSize: true
  44759. }); // Will be used in render.
  44760. copyLayoutParams(newElOption, existElOption);
  44761. } else {
  44762. existList[index] = newElOptCopy;
  44763. }
  44764. } else if ($action === 'replace') {
  44765. existList[index] = newElOptCopy;
  44766. } else if ($action === 'remove') {
  44767. // null will be cleaned later.
  44768. existElOption && (existList[index] = null);
  44769. }
  44770. }
  44771. function setLayoutInfoToExist(existItem, newElOption) {
  44772. if (!existItem) {
  44773. return;
  44774. }
  44775. existItem.hv = newElOption.hv = [// Rigid body, dont care `width`.
  44776. isSetLoc(newElOption, ['left', 'right']), // Rigid body, dont care `height`.
  44777. isSetLoc(newElOption, ['top', 'bottom'])]; // Give default group size. Otherwise layout error may occur.
  44778. if (existItem.type === 'group') {
  44779. var existingGroupOpt = existItem;
  44780. var newGroupOpt = newElOption;
  44781. existingGroupOpt.width == null && (existingGroupOpt.width = newGroupOpt.width = 0);
  44782. existingGroupOpt.height == null && (existingGroupOpt.height = newGroupOpt.height = 0);
  44783. }
  44784. }
  44785. function setEventData(el, graphicModel, elOption) {
  44786. var eventData = getECData(el).eventData; // Simple optimize for large amount of elements that no need event.
  44787. if (!el.silent && !el.ignore && !eventData) {
  44788. eventData = getECData(el).eventData = {
  44789. componentType: 'graphic',
  44790. componentIndex: graphicModel.componentIndex,
  44791. name: el.name
  44792. };
  44793. } // `elOption.info` enables user to mount some info on
  44794. // elements and use them in event handlers.
  44795. if (eventData) {
  44796. eventData.info = elOption.info;
  44797. }
  44798. }
  44799. function install$9(registers) {
  44800. registers.registerComponentModel(GraphicComponentModel);
  44801. registers.registerComponentView(GraphicComponentView);
  44802. registers.registerPreprocessor(preprocessor);
  44803. }
  44804. var DATA_ZOOM_AXIS_DIMENSIONS = ['x', 'y', 'radius', 'angle', 'single']; // Supported coords.
  44805. // FIXME: polar has been broken (but rarely used).
  44806. var SERIES_COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  44807. function isCoordSupported(seriesModel) {
  44808. var coordType = seriesModel.get('coordinateSystem');
  44809. return indexOf(SERIES_COORDS, coordType) >= 0;
  44810. }
  44811. function getAxisMainType(axisDim) {
  44812. if ("development" !== 'production') {
  44813. assert(axisDim);
  44814. }
  44815. return axisDim + 'Axis';
  44816. }
  44817. /**
  44818. * If two dataZoomModels has the same axis controlled, we say that they are 'linked'.
  44819. * This function finds all linked dataZoomModels start from the given payload.
  44820. */
  44821. function findEffectedDataZooms(ecModel, payload) {
  44822. // Key: `DataZoomAxisDimension`
  44823. var axisRecords = createHashMap();
  44824. var effectedModels = []; // Key: uid of dataZoomModel
  44825. var effectedModelMap = createHashMap(); // Find the dataZooms specified by payload.
  44826. ecModel.eachComponent({
  44827. mainType: 'dataZoom',
  44828. query: payload
  44829. }, function (dataZoomModel) {
  44830. if (!effectedModelMap.get(dataZoomModel.uid)) {
  44831. addToEffected(dataZoomModel);
  44832. }
  44833. }); // Start from the given dataZoomModels, travel the graph to find
  44834. // all of the linked dataZoom models.
  44835. var foundNewLink;
  44836. do {
  44837. foundNewLink = false;
  44838. ecModel.eachComponent('dataZoom', processSingle);
  44839. } while (foundNewLink);
  44840. function processSingle(dataZoomModel) {
  44841. if (!effectedModelMap.get(dataZoomModel.uid) && isLinked(dataZoomModel)) {
  44842. addToEffected(dataZoomModel);
  44843. foundNewLink = true;
  44844. }
  44845. }
  44846. function addToEffected(dataZoom) {
  44847. effectedModelMap.set(dataZoom.uid, true);
  44848. effectedModels.push(dataZoom);
  44849. markAxisControlled(dataZoom);
  44850. }
  44851. function isLinked(dataZoomModel) {
  44852. var isLink = false;
  44853. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  44854. var axisIdxArr = axisRecords.get(axisDim);
  44855. if (axisIdxArr && axisIdxArr[axisIndex]) {
  44856. isLink = true;
  44857. }
  44858. });
  44859. return isLink;
  44860. }
  44861. function markAxisControlled(dataZoomModel) {
  44862. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  44863. (axisRecords.get(axisDim) || axisRecords.set(axisDim, []))[axisIndex] = true;
  44864. });
  44865. }
  44866. return effectedModels;
  44867. }
  44868. /**
  44869. * Find the first target coordinate system.
  44870. * Available after model built.
  44871. *
  44872. * @return Like {
  44873. * grid: [
  44874. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  44875. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  44876. * ...
  44877. * ], // cartesians must not be null/undefined.
  44878. * polar: [
  44879. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  44880. * ...
  44881. * ], // polars must not be null/undefined.
  44882. * singleAxis: [
  44883. * {model: coord0, axisModels: [], coordIndex: 0}
  44884. * ]
  44885. * }
  44886. */
  44887. function collectReferCoordSysModelInfo(dataZoomModel) {
  44888. var ecModel = dataZoomModel.ecModel;
  44889. var coordSysInfoWrap = {
  44890. infoList: [],
  44891. infoMap: createHashMap()
  44892. };
  44893. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  44894. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  44895. if (!axisModel) {
  44896. return;
  44897. }
  44898. var coordSysModel = axisModel.getCoordSysModel();
  44899. if (!coordSysModel) {
  44900. return;
  44901. }
  44902. var coordSysUid = coordSysModel.uid;
  44903. var coordSysInfo = coordSysInfoWrap.infoMap.get(coordSysUid);
  44904. if (!coordSysInfo) {
  44905. coordSysInfo = {
  44906. model: coordSysModel,
  44907. axisModels: []
  44908. };
  44909. coordSysInfoWrap.infoList.push(coordSysInfo);
  44910. coordSysInfoWrap.infoMap.set(coordSysUid, coordSysInfo);
  44911. }
  44912. coordSysInfo.axisModels.push(axisModel);
  44913. });
  44914. return coordSysInfoWrap;
  44915. }
  44916. var DataZoomAxisInfo =
  44917. /** @class */
  44918. function () {
  44919. function DataZoomAxisInfo() {
  44920. this.indexList = [];
  44921. this.indexMap = [];
  44922. }
  44923. DataZoomAxisInfo.prototype.add = function (axisCmptIdx) {
  44924. // Remove duplication.
  44925. if (!this.indexMap[axisCmptIdx]) {
  44926. this.indexList.push(axisCmptIdx);
  44927. this.indexMap[axisCmptIdx] = true;
  44928. }
  44929. };
  44930. return DataZoomAxisInfo;
  44931. }();
  44932. var DataZoomModel =
  44933. /** @class */
  44934. function (_super) {
  44935. __extends(DataZoomModel, _super);
  44936. function DataZoomModel() {
  44937. var _this = _super !== null && _super.apply(this, arguments) || this;
  44938. _this.type = DataZoomModel.type;
  44939. _this._autoThrottle = true;
  44940. _this._noTarget = true;
  44941. /**
  44942. * It is `[rangeModeForMin, rangeModeForMax]`.
  44943. * The optional values for `rangeMode`:
  44944. * + `'value'` mode: the axis extent will always be determined by
  44945. * `dataZoom.startValue` and `dataZoom.endValue`, despite
  44946. * how data like and how `axis.min` and `axis.max` are.
  44947. * + `'percent'` mode: `100` represents 100% of the `[dMin, dMax]`,
  44948. * where `dMin` is `axis.min` if `axis.min` specified, otherwise `data.extent[0]`,
  44949. * and `dMax` is `axis.max` if `axis.max` specified, otherwise `data.extent[1]`.
  44950. * Axis extent will be determined by the result of the percent of `[dMin, dMax]`.
  44951. *
  44952. * For example, when users are using dynamic data (update data periodically via `setOption`),
  44953. * if in `'value`' mode, the window will be kept in a fixed value range despite how
  44954. * data are appended, while if in `'percent'` mode, whe window range will be changed alone with
  44955. * the appended data (suppose `axis.min` and `axis.max` are not specified).
  44956. */
  44957. _this._rangePropMode = ['percent', 'percent'];
  44958. return _this;
  44959. }
  44960. DataZoomModel.prototype.init = function (option, parentModel, ecModel) {
  44961. var inputRawOption = retrieveRawOption(option);
  44962. /**
  44963. * Suppose a "main process" start at the point that model prepared (that is,
  44964. * model initialized or merged or method called in `action`).
  44965. * We should keep the `main process` idempotent, that is, given a set of values
  44966. * on `option`, we get the same result.
  44967. *
  44968. * But sometimes, values on `option` will be updated for providing users
  44969. * a "final calculated value" (`dataZoomProcessor` will do that). Those value
  44970. * should not be the base/input of the `main process`.
  44971. *
  44972. * So in that case we should save and keep the input of the `main process`
  44973. * separately, called `settledOption`.
  44974. *
  44975. * For example, consider the case:
  44976. * (Step_1) brush zoom the grid by `toolbox.dataZoom`,
  44977. * where the original input `option.startValue`, `option.endValue` are earsed by
  44978. * calculated value.
  44979. * (Step)2) click the legend to hide and show a series,
  44980. * where the new range is calculated by the earsed `startValue` and `endValue`,
  44981. * which brings incorrect result.
  44982. */
  44983. this.settledOption = inputRawOption;
  44984. this.mergeDefaultAndTheme(option, ecModel);
  44985. this._doInit(inputRawOption);
  44986. };
  44987. DataZoomModel.prototype.mergeOption = function (newOption) {
  44988. var inputRawOption = retrieveRawOption(newOption); //FIX #2591
  44989. merge(this.option, newOption, true);
  44990. merge(this.settledOption, inputRawOption, true);
  44991. this._doInit(inputRawOption);
  44992. };
  44993. DataZoomModel.prototype._doInit = function (inputRawOption) {
  44994. var thisOption = this.option; // if (!env.canvasSupported) {
  44995. // thisOption.realtime = false;
  44996. // }
  44997. this._setDefaultThrottle(inputRawOption);
  44998. this._updateRangeUse(inputRawOption);
  44999. var settledOption = this.settledOption;
  45000. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  45001. // start/end has higher priority over startValue/endValue if they
  45002. // both set, but we should make chart.setOption({endValue: 1000})
  45003. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  45004. if (this._rangePropMode[index] === 'value') {
  45005. thisOption[names[0]] = settledOption[names[0]] = null;
  45006. } // Otherwise do nothing and use the merge result.
  45007. }, this);
  45008. this._resetTarget();
  45009. };
  45010. DataZoomModel.prototype._resetTarget = function () {
  45011. var optionOrient = this.get('orient', true);
  45012. var targetAxisIndexMap = this._targetAxisInfoMap = createHashMap();
  45013. var hasAxisSpecified = this._fillSpecifiedTargetAxis(targetAxisIndexMap);
  45014. if (hasAxisSpecified) {
  45015. this._orient = optionOrient || this._makeAutoOrientByTargetAxis();
  45016. } else {
  45017. this._orient = optionOrient || 'horizontal';
  45018. this._fillAutoTargetAxisByOrient(targetAxisIndexMap, this._orient);
  45019. }
  45020. this._noTarget = true;
  45021. targetAxisIndexMap.each(function (axisInfo) {
  45022. if (axisInfo.indexList.length) {
  45023. this._noTarget = false;
  45024. }
  45025. }, this);
  45026. };
  45027. DataZoomModel.prototype._fillSpecifiedTargetAxis = function (targetAxisIndexMap) {
  45028. var hasAxisSpecified = false;
  45029. each(DATA_ZOOM_AXIS_DIMENSIONS, function (axisDim) {
  45030. var refering = this.getReferringComponents(getAxisMainType(axisDim), MULTIPLE_REFERRING); // When user set axisIndex as a empty array, we think that user specify axisIndex
  45031. // but do not want use auto mode. Because empty array may be encountered when
  45032. // some error occured.
  45033. if (!refering.specified) {
  45034. return;
  45035. }
  45036. hasAxisSpecified = true;
  45037. var axisInfo = new DataZoomAxisInfo();
  45038. each(refering.models, function (axisModel) {
  45039. axisInfo.add(axisModel.componentIndex);
  45040. });
  45041. targetAxisIndexMap.set(axisDim, axisInfo);
  45042. }, this);
  45043. return hasAxisSpecified;
  45044. };
  45045. DataZoomModel.prototype._fillAutoTargetAxisByOrient = function (targetAxisIndexMap, orient) {
  45046. var ecModel = this.ecModel;
  45047. var needAuto = true; // Find axis that parallel to dataZoom as default.
  45048. if (needAuto) {
  45049. var axisDim = orient === 'vertical' ? 'y' : 'x';
  45050. var axisModels = ecModel.findComponents({
  45051. mainType: axisDim + 'Axis'
  45052. });
  45053. setParallelAxis(axisModels, axisDim);
  45054. } // Find axis that parallel to dataZoom as default.
  45055. if (needAuto) {
  45056. var axisModels = ecModel.findComponents({
  45057. mainType: 'singleAxis',
  45058. filter: function (axisModel) {
  45059. return axisModel.get('orient', true) === orient;
  45060. }
  45061. });
  45062. setParallelAxis(axisModels, 'single');
  45063. }
  45064. function setParallelAxis(axisModels, axisDim) {
  45065. // At least use the first parallel axis as the target axis.
  45066. var axisModel = axisModels[0];
  45067. if (!axisModel) {
  45068. return;
  45069. }
  45070. var axisInfo = new DataZoomAxisInfo();
  45071. axisInfo.add(axisModel.componentIndex);
  45072. targetAxisIndexMap.set(axisDim, axisInfo);
  45073. needAuto = false; // Find parallel axes in the same grid.
  45074. if (axisDim === 'x' || axisDim === 'y') {
  45075. var gridModel_1 = axisModel.getReferringComponents('grid', SINGLE_REFERRING).models[0];
  45076. gridModel_1 && each(axisModels, function (axModel) {
  45077. if (axisModel.componentIndex !== axModel.componentIndex && gridModel_1 === axModel.getReferringComponents('grid', SINGLE_REFERRING).models[0]) {
  45078. axisInfo.add(axModel.componentIndex);
  45079. }
  45080. });
  45081. }
  45082. }
  45083. if (needAuto) {
  45084. // If no parallel axis, find the first category axis as default. (Also consider polar).
  45085. each(DATA_ZOOM_AXIS_DIMENSIONS, function (axisDim) {
  45086. if (!needAuto) {
  45087. return;
  45088. }
  45089. var axisModels = ecModel.findComponents({
  45090. mainType: getAxisMainType(axisDim),
  45091. filter: function (axisModel) {
  45092. return axisModel.get('type', true) === 'category';
  45093. }
  45094. });
  45095. if (axisModels[0]) {
  45096. var axisInfo = new DataZoomAxisInfo();
  45097. axisInfo.add(axisModels[0].componentIndex);
  45098. targetAxisIndexMap.set(axisDim, axisInfo);
  45099. needAuto = false;
  45100. }
  45101. }, this);
  45102. }
  45103. };
  45104. DataZoomModel.prototype._makeAutoOrientByTargetAxis = function () {
  45105. var dim; // Find the first axis
  45106. this.eachTargetAxis(function (axisDim) {
  45107. !dim && (dim = axisDim);
  45108. }, this);
  45109. return dim === 'y' ? 'vertical' : 'horizontal';
  45110. };
  45111. DataZoomModel.prototype._setDefaultThrottle = function (inputRawOption) {
  45112. // When first time user set throttle, auto throttle ends.
  45113. if (inputRawOption.hasOwnProperty('throttle')) {
  45114. this._autoThrottle = false;
  45115. }
  45116. if (this._autoThrottle) {
  45117. var globalOption = this.ecModel.option;
  45118. this.option.throttle = globalOption.animation && globalOption.animationDurationUpdate > 0 ? 100 : 20;
  45119. }
  45120. };
  45121. DataZoomModel.prototype._updateRangeUse = function (inputRawOption) {
  45122. var rangePropMode = this._rangePropMode;
  45123. var rangeModeInOption = this.get('rangeMode');
  45124. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  45125. var percentSpecified = inputRawOption[names[0]] != null;
  45126. var valueSpecified = inputRawOption[names[1]] != null;
  45127. if (percentSpecified && !valueSpecified) {
  45128. rangePropMode[index] = 'percent';
  45129. } else if (!percentSpecified && valueSpecified) {
  45130. rangePropMode[index] = 'value';
  45131. } else if (rangeModeInOption) {
  45132. rangePropMode[index] = rangeModeInOption[index];
  45133. } else if (percentSpecified) {
  45134. // percentSpecified && valueSpecified
  45135. rangePropMode[index] = 'percent';
  45136. } // else remain its original setting.
  45137. });
  45138. };
  45139. DataZoomModel.prototype.noTarget = function () {
  45140. return this._noTarget;
  45141. };
  45142. DataZoomModel.prototype.getFirstTargetAxisModel = function () {
  45143. var firstAxisModel;
  45144. this.eachTargetAxis(function (axisDim, axisIndex) {
  45145. if (firstAxisModel == null) {
  45146. firstAxisModel = this.ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  45147. }
  45148. }, this);
  45149. return firstAxisModel;
  45150. };
  45151. /**
  45152. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  45153. */
  45154. DataZoomModel.prototype.eachTargetAxis = function (callback, context) {
  45155. this._targetAxisInfoMap.each(function (axisInfo, axisDim) {
  45156. each(axisInfo.indexList, function (axisIndex) {
  45157. callback.call(context, axisDim, axisIndex);
  45158. });
  45159. });
  45160. };
  45161. /**
  45162. * @return If not found, return null/undefined.
  45163. */
  45164. DataZoomModel.prototype.getAxisProxy = function (axisDim, axisIndex) {
  45165. var axisModel = this.getAxisModel(axisDim, axisIndex);
  45166. if (axisModel) {
  45167. return axisModel.__dzAxisProxy;
  45168. }
  45169. };
  45170. /**
  45171. * @return If not found, return null/undefined.
  45172. */
  45173. DataZoomModel.prototype.getAxisModel = function (axisDim, axisIndex) {
  45174. if ("development" !== 'production') {
  45175. assert(axisDim && axisIndex != null);
  45176. }
  45177. var axisInfo = this._targetAxisInfoMap.get(axisDim);
  45178. if (axisInfo && axisInfo.indexMap[axisIndex]) {
  45179. return this.ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  45180. }
  45181. };
  45182. /**
  45183. * If not specified, set to undefined.
  45184. */
  45185. DataZoomModel.prototype.setRawRange = function (opt) {
  45186. var thisOption = this.option;
  45187. var settledOption = this.settledOption;
  45188. each([['start', 'startValue'], ['end', 'endValue']], function (names) {
  45189. // Consider the pair <start, startValue>:
  45190. // If one has value and the other one is `null/undefined`, we both set them
  45191. // to `settledOption`. This strategy enables the feature to clear the original
  45192. // value in `settledOption` to `null/undefined`.
  45193. // But if both of them are `null/undefined`, we do not set them to `settledOption`
  45194. // and keep `settledOption` with the original value. This strategy enables users to
  45195. // only set <end or endValue> but not set <start or startValue> when calling
  45196. // `dispatchAction`.
  45197. // The pair <end, endValue> is treated in the same way.
  45198. if (opt[names[0]] != null || opt[names[1]] != null) {
  45199. thisOption[names[0]] = settledOption[names[0]] = opt[names[0]];
  45200. thisOption[names[1]] = settledOption[names[1]] = opt[names[1]];
  45201. }
  45202. }, this);
  45203. this._updateRangeUse(opt);
  45204. };
  45205. DataZoomModel.prototype.setCalculatedRange = function (opt) {
  45206. var option = this.option;
  45207. each(['start', 'startValue', 'end', 'endValue'], function (name) {
  45208. option[name] = opt[name];
  45209. });
  45210. };
  45211. DataZoomModel.prototype.getPercentRange = function () {
  45212. var axisProxy = this.findRepresentativeAxisProxy();
  45213. if (axisProxy) {
  45214. return axisProxy.getDataPercentWindow();
  45215. }
  45216. };
  45217. /**
  45218. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  45219. *
  45220. * @return [startValue, endValue] value can only be '-' or finite number.
  45221. */
  45222. DataZoomModel.prototype.getValueRange = function (axisDim, axisIndex) {
  45223. if (axisDim == null && axisIndex == null) {
  45224. var axisProxy = this.findRepresentativeAxisProxy();
  45225. if (axisProxy) {
  45226. return axisProxy.getDataValueWindow();
  45227. }
  45228. } else {
  45229. return this.getAxisProxy(axisDim, axisIndex).getDataValueWindow();
  45230. }
  45231. };
  45232. /**
  45233. * @param axisModel If axisModel given, find axisProxy
  45234. * corresponding to the axisModel
  45235. */
  45236. DataZoomModel.prototype.findRepresentativeAxisProxy = function (axisModel) {
  45237. if (axisModel) {
  45238. return axisModel.__dzAxisProxy;
  45239. } // Find the first hosted axisProxy
  45240. var firstProxy;
  45241. var axisDimList = this._targetAxisInfoMap.keys();
  45242. for (var i = 0; i < axisDimList.length; i++) {
  45243. var axisDim = axisDimList[i];
  45244. var axisInfo = this._targetAxisInfoMap.get(axisDim);
  45245. for (var j = 0; j < axisInfo.indexList.length; j++) {
  45246. var proxy = this.getAxisProxy(axisDim, axisInfo.indexList[j]);
  45247. if (proxy.hostedBy(this)) {
  45248. return proxy;
  45249. }
  45250. if (!firstProxy) {
  45251. firstProxy = proxy;
  45252. }
  45253. }
  45254. } // If no hosted proxy found, still need to return a proxy.
  45255. // This case always happens in toolbox dataZoom, where axes are all hosted by
  45256. // other dataZooms.
  45257. return firstProxy;
  45258. };
  45259. DataZoomModel.prototype.getRangePropMode = function () {
  45260. return this._rangePropMode.slice();
  45261. };
  45262. DataZoomModel.prototype.getOrient = function () {
  45263. if ("development" !== 'production') {
  45264. // Should not be called before initialized.
  45265. assert(this._orient);
  45266. }
  45267. return this._orient;
  45268. };
  45269. DataZoomModel.type = 'dataZoom';
  45270. DataZoomModel.dependencies = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series', 'toolbox'];
  45271. DataZoomModel.defaultOption = {
  45272. zlevel: 0,
  45273. z: 4,
  45274. filterMode: 'filter',
  45275. start: 0,
  45276. end: 100
  45277. };
  45278. return DataZoomModel;
  45279. }(ComponentModel);
  45280. /**
  45281. * Retrieve the those raw params from option, which will be cached separately.
  45282. * becasue they will be overwritten by normalized/calculated values in the main
  45283. * process.
  45284. */
  45285. function retrieveRawOption(option) {
  45286. var ret = {};
  45287. each(['start', 'end', 'startValue', 'endValue', 'throttle'], function (name) {
  45288. option.hasOwnProperty(name) && (ret[name] = option[name]);
  45289. });
  45290. return ret;
  45291. }
  45292. var SelectDataZoomModel =
  45293. /** @class */
  45294. function (_super) {
  45295. __extends(SelectDataZoomModel, _super);
  45296. function SelectDataZoomModel() {
  45297. var _this = _super !== null && _super.apply(this, arguments) || this;
  45298. _this.type = SelectDataZoomModel.type;
  45299. return _this;
  45300. }
  45301. SelectDataZoomModel.type = 'dataZoom.select';
  45302. return SelectDataZoomModel;
  45303. }(DataZoomModel);
  45304. var DataZoomView =
  45305. /** @class */
  45306. function (_super) {
  45307. __extends(DataZoomView, _super);
  45308. function DataZoomView() {
  45309. var _this = _super !== null && _super.apply(this, arguments) || this;
  45310. _this.type = DataZoomView.type;
  45311. return _this;
  45312. }
  45313. DataZoomView.prototype.render = function (dataZoomModel, ecModel, api, payload) {
  45314. this.dataZoomModel = dataZoomModel;
  45315. this.ecModel = ecModel;
  45316. this.api = api;
  45317. };
  45318. DataZoomView.type = 'dataZoom';
  45319. return DataZoomView;
  45320. }(ComponentView);
  45321. var SelectDataZoomView =
  45322. /** @class */
  45323. function (_super) {
  45324. __extends(SelectDataZoomView, _super);
  45325. function SelectDataZoomView() {
  45326. var _this = _super !== null && _super.apply(this, arguments) || this;
  45327. _this.type = SelectDataZoomView.type;
  45328. return _this;
  45329. }
  45330. SelectDataZoomView.type = 'dataZoom.select';
  45331. return SelectDataZoomView;
  45332. }(DataZoomView);
  45333. /*
  45334. * Licensed to the Apache Software Foundation (ASF) under one
  45335. * or more contributor license agreements. See the NOTICE file
  45336. * distributed with this work for additional information
  45337. * regarding copyright ownership. The ASF licenses this file
  45338. * to you under the Apache License, Version 2.0 (the
  45339. * "License"); you may not use this file except in compliance
  45340. * with the License. You may obtain a copy of the License at
  45341. *
  45342. * http://www.apache.org/licenses/LICENSE-2.0
  45343. *
  45344. * Unless required by applicable law or agreed to in writing,
  45345. * software distributed under the License is distributed on an
  45346. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45347. * KIND, either express or implied. See the License for the
  45348. * specific language governing permissions and limitations
  45349. * under the License.
  45350. */
  45351. /**
  45352. * AUTO-GENERATED FILE. DO NOT MODIFY.
  45353. */
  45354. /*
  45355. * Licensed to the Apache Software Foundation (ASF) under one
  45356. * or more contributor license agreements. See the NOTICE file
  45357. * distributed with this work for additional information
  45358. * regarding copyright ownership. The ASF licenses this file
  45359. * to you under the Apache License, Version 2.0 (the
  45360. * "License"); you may not use this file except in compliance
  45361. * with the License. You may obtain a copy of the License at
  45362. *
  45363. * http://www.apache.org/licenses/LICENSE-2.0
  45364. *
  45365. * Unless required by applicable law or agreed to in writing,
  45366. * software distributed under the License is distributed on an
  45367. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45368. * KIND, either express or implied. See the License for the
  45369. * specific language governing permissions and limitations
  45370. * under the License.
  45371. */
  45372. /**
  45373. * Calculate slider move result.
  45374. * Usage:
  45375. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  45376. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  45377. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  45378. *
  45379. * @param delta Move length.
  45380. * @param handleEnds handleEnds[0] can be bigger then handleEnds[1].
  45381. * handleEnds will be modified in this method.
  45382. * @param extent handleEnds is restricted by extent.
  45383. * extent[0] should less or equals than extent[1].
  45384. * @param handleIndex Can be 'all', means that both move the two handleEnds.
  45385. * @param minSpan The range of dataZoom can not be smaller than that.
  45386. * If not set, handle0 and cross handle1. If set as a non-negative
  45387. * number (including `0`), handles will push each other when reaching
  45388. * the minSpan.
  45389. * @param maxSpan The range of dataZoom can not be larger than that.
  45390. * @return The input handleEnds.
  45391. */
  45392. function sliderMove(delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  45393. delta = delta || 0;
  45394. var extentSpan = extent[1] - extent[0]; // Notice maxSpan and minSpan can be null/undefined.
  45395. if (minSpan != null) {
  45396. minSpan = restrict(minSpan, [0, extentSpan]);
  45397. }
  45398. if (maxSpan != null) {
  45399. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  45400. }
  45401. if (handleIndex === 'all') {
  45402. var handleSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  45403. handleSpan = restrict(handleSpan, [0, extentSpan]);
  45404. minSpan = maxSpan = restrict(handleSpan, [minSpan, maxSpan]);
  45405. handleIndex = 0;
  45406. }
  45407. handleEnds[0] = restrict(handleEnds[0], extent);
  45408. handleEnds[1] = restrict(handleEnds[1], extent);
  45409. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  45410. handleEnds[handleIndex] += delta; // Restrict in extent.
  45411. var extentMinSpan = minSpan || 0;
  45412. var realExtent = extent.slice();
  45413. originalDistSign.sign < 0 ? realExtent[0] += extentMinSpan : realExtent[1] -= extentMinSpan;
  45414. handleEnds[handleIndex] = restrict(handleEnds[handleIndex], realExtent); // Expand span.
  45415. var currDistSign;
  45416. currDistSign = getSpanSign(handleEnds, handleIndex);
  45417. if (minSpan != null && (currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan)) {
  45418. // If minSpan exists, 'cross' is forbidden.
  45419. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  45420. } // Shrink span.
  45421. currDistSign = getSpanSign(handleEnds, handleIndex);
  45422. if (maxSpan != null && currDistSign.span > maxSpan) {
  45423. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  45424. }
  45425. return handleEnds;
  45426. }
  45427. function getSpanSign(handleEnds, handleIndex) {
  45428. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex]; // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  45429. // is at left of handleEnds[1] for non-cross case.
  45430. return {
  45431. span: Math.abs(dist),
  45432. sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1
  45433. };
  45434. }
  45435. function restrict(value, extend) {
  45436. return Math.min(extend[1] != null ? extend[1] : Infinity, Math.max(extend[0] != null ? extend[0] : -Infinity, value));
  45437. }
  45438. var each$4 = each;
  45439. var asc$1 = asc;
  45440. /**
  45441. * Operate single axis.
  45442. * One axis can only operated by one axis operator.
  45443. * Different dataZoomModels may be defined to operate the same axis.
  45444. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  45445. * So dataZoomModels share one axisProxy in that case.
  45446. */
  45447. var AxisProxy =
  45448. /** @class */
  45449. function () {
  45450. function AxisProxy(dimName, axisIndex, dataZoomModel, ecModel) {
  45451. this._dimName = dimName;
  45452. this._axisIndex = axisIndex;
  45453. this.ecModel = ecModel;
  45454. this._dataZoomModel = dataZoomModel; // /**
  45455. // * @readOnly
  45456. // * @private
  45457. // */
  45458. // this.hasSeriesStacked;
  45459. }
  45460. /**
  45461. * Whether the axisProxy is hosted by dataZoomModel.
  45462. */
  45463. AxisProxy.prototype.hostedBy = function (dataZoomModel) {
  45464. return this._dataZoomModel === dataZoomModel;
  45465. };
  45466. /**
  45467. * @return Value can only be NaN or finite value.
  45468. */
  45469. AxisProxy.prototype.getDataValueWindow = function () {
  45470. return this._valueWindow.slice();
  45471. };
  45472. /**
  45473. * @return {Array.<number>}
  45474. */
  45475. AxisProxy.prototype.getDataPercentWindow = function () {
  45476. return this._percentWindow.slice();
  45477. };
  45478. AxisProxy.prototype.getTargetSeriesModels = function () {
  45479. var seriesModels = [];
  45480. this.ecModel.eachSeries(function (seriesModel) {
  45481. if (isCoordSupported(seriesModel)) {
  45482. var axisMainType = getAxisMainType(this._dimName);
  45483. var axisModel = seriesModel.getReferringComponents(axisMainType, SINGLE_REFERRING).models[0];
  45484. if (axisModel && this._axisIndex === axisModel.componentIndex) {
  45485. seriesModels.push(seriesModel);
  45486. }
  45487. }
  45488. }, this);
  45489. return seriesModels;
  45490. };
  45491. AxisProxy.prototype.getAxisModel = function () {
  45492. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  45493. };
  45494. AxisProxy.prototype.getMinMaxSpan = function () {
  45495. return clone(this._minMaxSpan);
  45496. };
  45497. /**
  45498. * Only calculate by given range and this._dataExtent, do not change anything.
  45499. */
  45500. AxisProxy.prototype.calculateDataWindow = function (opt) {
  45501. var dataExtent = this._dataExtent;
  45502. var axisModel = this.getAxisModel();
  45503. var scale = axisModel.axis.scale;
  45504. var rangePropMode = this._dataZoomModel.getRangePropMode();
  45505. var percentExtent = [0, 100];
  45506. var percentWindow = [];
  45507. var valueWindow = [];
  45508. var hasPropModeValue;
  45509. each$4(['start', 'end'], function (prop, idx) {
  45510. var boundPercent = opt[prop];
  45511. var boundValue = opt[prop + 'Value']; // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  45512. // on `valueProp` ('startValue', 'endValue'). (They are based on the data extent
  45513. // but not min/max of axis, which will be calculated by data window then).
  45514. // The former one is suitable for cases that a dataZoom component controls multiple
  45515. // axes with different unit or extent, and the latter one is suitable for accurate
  45516. // zoom by pixel (e.g., in dataZoomSelect).
  45517. // we use `getRangePropMode()` to mark which prop is used. `rangePropMode` is updated
  45518. // only when setOption or dispatchAction, otherwise it remains its original value.
  45519. // (Why not only record `percentProp` and always map to `valueProp`? Because
  45520. // the map `valueProp` -> `percentProp` -> `valueProp` probably not the original
  45521. // `valueProp`. consider two axes constrolled by one dataZoom. They have different
  45522. // data extent. All of values that are overflow the `dataExtent` will be calculated
  45523. // to percent '100%').
  45524. if (rangePropMode[idx] === 'percent') {
  45525. boundPercent == null && (boundPercent = percentExtent[idx]); // Use scale.parse to math round for category or time axis.
  45526. boundValue = scale.parse(linearMap(boundPercent, percentExtent, dataExtent));
  45527. } else {
  45528. hasPropModeValue = true;
  45529. boundValue = boundValue == null ? dataExtent[idx] : scale.parse(boundValue); // Calculating `percent` from `value` may be not accurate, because
  45530. // This calculation can not be inversed, because all of values that
  45531. // are overflow the `dataExtent` will be calculated to percent '100%'
  45532. boundPercent = linearMap(boundValue, dataExtent, percentExtent);
  45533. } // valueWindow[idx] = round(boundValue);
  45534. // percentWindow[idx] = round(boundPercent);
  45535. valueWindow[idx] = boundValue;
  45536. percentWindow[idx] = boundPercent;
  45537. });
  45538. asc$1(valueWindow);
  45539. asc$1(percentWindow); // The windows from user calling of `dispatchAction` might be out of the extent,
  45540. // or do not obey the `min/maxSpan`, `min/maxValueSpan`. But we dont restrict window
  45541. // by `zoomLock` here, because we see `zoomLock` just as a interaction constraint,
  45542. // where API is able to initialize/modify the window size even though `zoomLock`
  45543. // specified.
  45544. var spans = this._minMaxSpan;
  45545. hasPropModeValue ? restrictSet(valueWindow, percentWindow, dataExtent, percentExtent, false) : restrictSet(percentWindow, valueWindow, percentExtent, dataExtent, true);
  45546. function restrictSet(fromWindow, toWindow, fromExtent, toExtent, toValue) {
  45547. var suffix = toValue ? 'Span' : 'ValueSpan';
  45548. sliderMove(0, fromWindow, fromExtent, 'all', spans['min' + suffix], spans['max' + suffix]);
  45549. for (var i = 0; i < 2; i++) {
  45550. toWindow[i] = linearMap(fromWindow[i], fromExtent, toExtent, true);
  45551. toValue && (toWindow[i] = scale.parse(toWindow[i]));
  45552. }
  45553. }
  45554. return {
  45555. valueWindow: valueWindow,
  45556. percentWindow: percentWindow
  45557. };
  45558. };
  45559. /**
  45560. * Notice: reset should not be called before series.restoreData() called,
  45561. * so it is recommanded to be called in "process stage" but not "model init
  45562. * stage".
  45563. */
  45564. AxisProxy.prototype.reset = function (dataZoomModel) {
  45565. if (dataZoomModel !== this._dataZoomModel) {
  45566. return;
  45567. }
  45568. var targetSeries = this.getTargetSeriesModels(); // Culculate data window and data extent, and record them.
  45569. this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries); // `calculateDataWindow` uses min/maxSpan.
  45570. this._updateMinMaxSpan();
  45571. var dataWindow = this.calculateDataWindow(dataZoomModel.settledOption);
  45572. this._valueWindow = dataWindow.valueWindow;
  45573. this._percentWindow = dataWindow.percentWindow; // Update axis setting then.
  45574. this._setAxisModel();
  45575. };
  45576. AxisProxy.prototype.filterData = function (dataZoomModel, api) {
  45577. if (dataZoomModel !== this._dataZoomModel) {
  45578. return;
  45579. }
  45580. var axisDim = this._dimName;
  45581. var seriesModels = this.getTargetSeriesModels();
  45582. var filterMode = dataZoomModel.get('filterMode');
  45583. var valueWindow = this._valueWindow;
  45584. if (filterMode === 'none') {
  45585. return;
  45586. } // FIXME
  45587. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  45588. // with NaN data, NaN will be filtered and stack will be wrong.
  45589. // So we need to force the mode to be set empty.
  45590. // In fect, it is not a big deal that do not support filterMode-'filter'
  45591. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  45592. // selection" some day, which might need "adapt to data extent on the
  45593. // otherAxis", which is disabled by filterMode-'empty'.
  45594. // But currently, stack has been fixed to based on value but not index,
  45595. // so this is not an issue any more.
  45596. // let otherAxisModel = this.getOtherAxisModel();
  45597. // if (dataZoomModel.get('$fromToolbox')
  45598. // && otherAxisModel
  45599. // && otherAxisModel.hasSeriesStacked
  45600. // ) {
  45601. // filterMode = 'empty';
  45602. // }
  45603. // TODO
  45604. // filterMode 'weakFilter' and 'empty' is not optimized for huge data yet.
  45605. each$4(seriesModels, function (seriesModel) {
  45606. var seriesData = seriesModel.getData();
  45607. var dataDims = seriesData.mapDimensionsAll(axisDim);
  45608. if (!dataDims.length) {
  45609. return;
  45610. }
  45611. if (filterMode === 'weakFilter') {
  45612. var store_1 = seriesData.getStore();
  45613. var dataDimIndices_1 = map(dataDims, function (dim) {
  45614. return seriesData.getDimensionIndex(dim);
  45615. }, seriesData);
  45616. seriesData.filterSelf(function (dataIndex) {
  45617. var leftOut;
  45618. var rightOut;
  45619. var hasValue;
  45620. for (var i = 0; i < dataDims.length; i++) {
  45621. var value = store_1.get(dataDimIndices_1[i], dataIndex);
  45622. var thisHasValue = !isNaN(value);
  45623. var thisLeftOut = value < valueWindow[0];
  45624. var thisRightOut = value > valueWindow[1];
  45625. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  45626. return true;
  45627. }
  45628. thisHasValue && (hasValue = true);
  45629. thisLeftOut && (leftOut = true);
  45630. thisRightOut && (rightOut = true);
  45631. } // If both left out and right out, do not filter.
  45632. return hasValue && leftOut && rightOut;
  45633. });
  45634. } else {
  45635. each$4(dataDims, function (dim) {
  45636. if (filterMode === 'empty') {
  45637. seriesModel.setData(seriesData = seriesData.map(dim, function (value) {
  45638. return !isInWindow(value) ? NaN : value;
  45639. }));
  45640. } else {
  45641. var range = {};
  45642. range[dim] = valueWindow; // console.time('select');
  45643. seriesData.selectRange(range); // console.timeEnd('select');
  45644. }
  45645. });
  45646. }
  45647. each$4(dataDims, function (dim) {
  45648. seriesData.setApproximateExtent(valueWindow, dim);
  45649. });
  45650. });
  45651. function isInWindow(value) {
  45652. return value >= valueWindow[0] && value <= valueWindow[1];
  45653. }
  45654. };
  45655. AxisProxy.prototype._updateMinMaxSpan = function () {
  45656. var minMaxSpan = this._minMaxSpan = {};
  45657. var dataZoomModel = this._dataZoomModel;
  45658. var dataExtent = this._dataExtent;
  45659. each$4(['min', 'max'], function (minMax) {
  45660. var percentSpan = dataZoomModel.get(minMax + 'Span');
  45661. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  45662. valueSpan != null && (valueSpan = this.getAxisModel().axis.scale.parse(valueSpan)); // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  45663. if (valueSpan != null) {
  45664. percentSpan = linearMap(dataExtent[0] + valueSpan, dataExtent, [0, 100], true);
  45665. } else if (percentSpan != null) {
  45666. valueSpan = linearMap(percentSpan, [0, 100], dataExtent, true) - dataExtent[0];
  45667. }
  45668. minMaxSpan[minMax + 'Span'] = percentSpan;
  45669. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  45670. }, this);
  45671. };
  45672. AxisProxy.prototype._setAxisModel = function () {
  45673. var axisModel = this.getAxisModel();
  45674. var percentWindow = this._percentWindow;
  45675. var valueWindow = this._valueWindow;
  45676. if (!percentWindow) {
  45677. return;
  45678. } // [0, 500]: arbitrary value, guess axis extent.
  45679. var precision = getPixelPrecision(valueWindow, [0, 500]);
  45680. precision = Math.min(precision, 20); // For value axis, if min/max/scale are not set, we just use the extent obtained
  45681. // by series data, which may be a little different from the extent calculated by
  45682. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  45683. // little when zooming. So it will not be fixed until some users require it strongly.
  45684. var rawExtentInfo = axisModel.axis.scale.rawExtentInfo;
  45685. if (percentWindow[0] !== 0) {
  45686. rawExtentInfo.setDeterminedMinMax('min', +valueWindow[0].toFixed(precision));
  45687. }
  45688. if (percentWindow[1] !== 100) {
  45689. rawExtentInfo.setDeterminedMinMax('max', +valueWindow[1].toFixed(precision));
  45690. }
  45691. rawExtentInfo.freeze();
  45692. };
  45693. return AxisProxy;
  45694. }();
  45695. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  45696. var dataExtent = [Infinity, -Infinity];
  45697. each$4(seriesModels, function (seriesModel) {
  45698. unionAxisExtentFromData(dataExtent, seriesModel.getData(), axisDim);
  45699. }); // It is important to get "consistent" extent when more then one axes is
  45700. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  45701. // when zooming. But it is difficult to know what is "consistent", considering
  45702. // axes have different type or even different meanings (For example, two
  45703. // time axes are used to compare data of the same date in different years).
  45704. // So basically dataZoom just obtains extent by series.data (in category axis
  45705. // extent can be obtained from axis.data).
  45706. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  45707. // consistent.
  45708. var axisModel = axisProxy.getAxisModel();
  45709. var rawExtentResult = ensureScaleRawExtentInfo(axisModel.axis.scale, axisModel, dataExtent).calculate();
  45710. return [rawExtentResult.min, rawExtentResult.max];
  45711. }
  45712. var dataZoomProcessor = {
  45713. // `dataZoomProcessor` will only be performed in needed series. Consider if
  45714. // there is a line series and a pie series, it is better not to update the
  45715. // line series if only pie series is needed to be updated.
  45716. getTargetSeries: function (ecModel) {
  45717. function eachAxisModel(cb) {
  45718. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  45719. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  45720. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  45721. cb(axisDim, axisIndex, axisModel, dataZoomModel);
  45722. });
  45723. });
  45724. } // FIXME: it brings side-effect to `getTargetSeries`.
  45725. // Prepare axis proxies.
  45726. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  45727. // dispose all last axis proxy, in case that some axis are deleted.
  45728. axisModel.__dzAxisProxy = null;
  45729. });
  45730. var proxyList = [];
  45731. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  45732. // Different dataZooms may constrol the same axis. In that case,
  45733. // an axisProxy serves both of them.
  45734. if (!axisModel.__dzAxisProxy) {
  45735. // Use the first dataZoomModel as the main model of axisProxy.
  45736. axisModel.__dzAxisProxy = new AxisProxy(axisDim, axisIndex, dataZoomModel, ecModel);
  45737. proxyList.push(axisModel.__dzAxisProxy);
  45738. }
  45739. });
  45740. var seriesModelMap = createHashMap();
  45741. each(proxyList, function (axisProxy) {
  45742. each(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  45743. seriesModelMap.set(seriesModel.uid, seriesModel);
  45744. });
  45745. });
  45746. return seriesModelMap;
  45747. },
  45748. // Consider appendData, where filter should be performed. Because data process is
  45749. // in block mode currently, it is not need to worry about that the overallProgress
  45750. // execute every frame.
  45751. overallReset: function (ecModel, api) {
  45752. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  45753. // We calculate window and reset axis here but not in model
  45754. // init stage and not after action dispatch handler, because
  45755. // reset should be called after seriesData.restoreData.
  45756. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  45757. dataZoomModel.getAxisProxy(axisDim, axisIndex).reset(dataZoomModel);
  45758. }); // Caution: data zoom filtering is order sensitive when using
  45759. // percent range and no min/max/scale set on axis.
  45760. // For example, we have dataZoom definition:
  45761. // [
  45762. // {xAxisIndex: 0, start: 30, end: 70},
  45763. // {yAxisIndex: 0, start: 20, end: 80}
  45764. // ]
  45765. // In this case, [20, 80] of y-dataZoom should be based on data
  45766. // that have filtered by x-dataZoom using range of [30, 70],
  45767. // but should not be based on full raw data. Thus sliding
  45768. // x-dataZoom will change both ranges of xAxis and yAxis,
  45769. // while sliding y-dataZoom will only change the range of yAxis.
  45770. // So we should filter x-axis after reset x-axis immediately,
  45771. // and then reset y-axis and filter y-axis.
  45772. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  45773. dataZoomModel.getAxisProxy(axisDim, axisIndex).filterData(dataZoomModel, api);
  45774. });
  45775. });
  45776. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  45777. // Fullfill all of the range props so that user
  45778. // is able to get them from chart.getOption().
  45779. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  45780. if (axisProxy) {
  45781. var percentRange = axisProxy.getDataPercentWindow();
  45782. var valueRange = axisProxy.getDataValueWindow();
  45783. dataZoomModel.setCalculatedRange({
  45784. start: percentRange[0],
  45785. end: percentRange[1],
  45786. startValue: valueRange[0],
  45787. endValue: valueRange[1]
  45788. });
  45789. }
  45790. });
  45791. }
  45792. };
  45793. function installDataZoomAction(registers) {
  45794. registers.registerAction('dataZoom', function (payload, ecModel) {
  45795. var effectedModels = findEffectedDataZooms(ecModel, payload);
  45796. each(effectedModels, function (dataZoomModel) {
  45797. dataZoomModel.setRawRange({
  45798. start: payload.start,
  45799. end: payload.end,
  45800. startValue: payload.startValue,
  45801. endValue: payload.endValue
  45802. });
  45803. });
  45804. });
  45805. }
  45806. var installed = false;
  45807. function installCommon(registers) {
  45808. if (installed) {
  45809. return;
  45810. }
  45811. installed = true;
  45812. registers.registerProcessor(registers.PRIORITY.PROCESSOR.FILTER, dataZoomProcessor);
  45813. installDataZoomAction(registers);
  45814. registers.registerSubTypeDefaulter('dataZoom', function () {
  45815. // Default 'slider' when no type specified.
  45816. return 'slider';
  45817. });
  45818. }
  45819. function install$a(registers) {
  45820. registers.registerComponentModel(SelectDataZoomModel);
  45821. registers.registerComponentView(SelectDataZoomView);
  45822. installCommon(registers);
  45823. }
  45824. /*
  45825. * Licensed to the Apache Software Foundation (ASF) under one
  45826. * or more contributor license agreements. See the NOTICE file
  45827. * distributed with this work for additional information
  45828. * regarding copyright ownership. The ASF licenses this file
  45829. * to you under the Apache License, Version 2.0 (the
  45830. * "License"); you may not use this file except in compliance
  45831. * with the License. You may obtain a copy of the License at
  45832. *
  45833. * http://www.apache.org/licenses/LICENSE-2.0
  45834. *
  45835. * Unless required by applicable law or agreed to in writing,
  45836. * software distributed under the License is distributed on an
  45837. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45838. * KIND, either express or implied. See the License for the
  45839. * specific language governing permissions and limitations
  45840. * under the License.
  45841. */
  45842. /**
  45843. * AUTO-GENERATED FILE. DO NOT MODIFY.
  45844. */
  45845. var ToolboxFeature =
  45846. /** @class */
  45847. function () {
  45848. function ToolboxFeature() {}
  45849. return ToolboxFeature;
  45850. }();
  45851. var features = {};
  45852. function registerFeature(name, ctor) {
  45853. features[name] = ctor;
  45854. }
  45855. function getFeature(name) {
  45856. return features[name];
  45857. }
  45858. var ToolboxModel =
  45859. /** @class */
  45860. function (_super) {
  45861. __extends(ToolboxModel, _super);
  45862. function ToolboxModel() {
  45863. var _this = _super !== null && _super.apply(this, arguments) || this;
  45864. _this.type = ToolboxModel.type;
  45865. return _this;
  45866. }
  45867. ToolboxModel.prototype.optionUpdated = function () {
  45868. _super.prototype.optionUpdated.apply(this, arguments);
  45869. var ecModel = this.ecModel;
  45870. each(this.option.feature, function (featureOpt, featureName) {
  45871. var Feature = getFeature(featureName);
  45872. if (Feature) {
  45873. if (Feature.getDefaultOption) {
  45874. Feature.defaultOption = Feature.getDefaultOption(ecModel);
  45875. }
  45876. merge(featureOpt, Feature.defaultOption);
  45877. }
  45878. });
  45879. };
  45880. ToolboxModel.type = 'toolbox';
  45881. ToolboxModel.layoutMode = {
  45882. type: 'box',
  45883. ignoreSize: true
  45884. };
  45885. ToolboxModel.defaultOption = {
  45886. show: true,
  45887. z: 6,
  45888. zlevel: 0,
  45889. orient: 'horizontal',
  45890. left: 'right',
  45891. top: 'top',
  45892. // right
  45893. // bottom
  45894. backgroundColor: 'transparent',
  45895. borderColor: '#ccc',
  45896. borderRadius: 0,
  45897. borderWidth: 0,
  45898. padding: 5,
  45899. itemSize: 15,
  45900. itemGap: 8,
  45901. showTitle: true,
  45902. iconStyle: {
  45903. borderColor: '#666',
  45904. color: 'none'
  45905. },
  45906. emphasis: {
  45907. iconStyle: {
  45908. borderColor: '#3E98C5'
  45909. }
  45910. },
  45911. // textStyle: {},
  45912. // feature
  45913. tooltip: {
  45914. show: false,
  45915. position: 'bottom'
  45916. }
  45917. };
  45918. return ToolboxModel;
  45919. }(ComponentModel);
  45920. /**
  45921. * Layout list like component.
  45922. * It will box layout each items in group of component and then position the whole group in the viewport
  45923. * @param {module:zrender/group/Group} group
  45924. * @param {module:echarts/model/Component} componentModel
  45925. * @param {module:echarts/ExtensionAPI}
  45926. */
  45927. function layout$2(group, componentModel, api) {
  45928. var boxLayoutParams = componentModel.getBoxLayoutParams();
  45929. var padding = componentModel.get('padding');
  45930. var viewportSize = {
  45931. width: api.getWidth(),
  45932. height: api.getHeight()
  45933. };
  45934. var rect = getLayoutRect(boxLayoutParams, viewportSize, padding);
  45935. box(componentModel.get('orient'), group, componentModel.get('itemGap'), rect.width, rect.height);
  45936. positionElement(group, boxLayoutParams, viewportSize, padding);
  45937. }
  45938. function makeBackground(rect, componentModel) {
  45939. var padding = normalizeCssArray$1(componentModel.get('padding'));
  45940. var style = componentModel.getItemStyle(['color', 'opacity']);
  45941. style.fill = componentModel.get('backgroundColor');
  45942. rect = new Rect({
  45943. shape: {
  45944. x: rect.x - padding[3],
  45945. y: rect.y - padding[0],
  45946. width: rect.width + padding[1] + padding[3],
  45947. height: rect.height + padding[0] + padding[2],
  45948. r: componentModel.get('borderRadius')
  45949. },
  45950. style: style,
  45951. silent: true,
  45952. z2: -1
  45953. }); // FIXME
  45954. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  45955. // and background rect when setting like `left: 0`, `top: 0`.
  45956. // graphic.subPixelOptimizeRect(rect);
  45957. return rect;
  45958. }
  45959. var ToolboxView =
  45960. /** @class */
  45961. function (_super) {
  45962. __extends(ToolboxView, _super);
  45963. function ToolboxView() {
  45964. return _super !== null && _super.apply(this, arguments) || this;
  45965. }
  45966. ToolboxView.prototype.render = function (toolboxModel, ecModel, api, payload) {
  45967. var group = this.group;
  45968. group.removeAll();
  45969. if (!toolboxModel.get('show')) {
  45970. return;
  45971. }
  45972. var itemSize = +toolboxModel.get('itemSize');
  45973. var featureOpts = toolboxModel.get('feature') || {};
  45974. var features = this._features || (this._features = {});
  45975. var featureNames = [];
  45976. each(featureOpts, function (opt, name) {
  45977. featureNames.push(name);
  45978. });
  45979. new DataDiffer(this._featureNames || [], featureNames).add(processFeature).update(processFeature).remove(curry(processFeature, null)).execute(); // Keep for diff.
  45980. this._featureNames = featureNames;
  45981. function processFeature(newIndex, oldIndex) {
  45982. var featureName = featureNames[newIndex];
  45983. var oldName = featureNames[oldIndex];
  45984. var featureOpt = featureOpts[featureName];
  45985. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  45986. var feature; // FIX#11236, merge feature title from MagicType newOption. TODO: consider seriesIndex ?
  45987. if (payload && payload.newTitle != null && payload.featureName === featureName) {
  45988. featureOpt.title = payload.newTitle;
  45989. }
  45990. if (featureName && !oldName) {
  45991. // Create
  45992. if (isUserFeatureName(featureName)) {
  45993. feature = {
  45994. onclick: featureModel.option.onclick,
  45995. featureName: featureName
  45996. };
  45997. } else {
  45998. var Feature = getFeature(featureName);
  45999. if (!Feature) {
  46000. return;
  46001. }
  46002. feature = new Feature();
  46003. }
  46004. features[featureName] = feature;
  46005. } else {
  46006. feature = features[oldName]; // If feature does not exsit.
  46007. if (!feature) {
  46008. return;
  46009. }
  46010. }
  46011. feature.uid = getUID('toolbox-feature');
  46012. feature.model = featureModel;
  46013. feature.ecModel = ecModel;
  46014. feature.api = api;
  46015. var isToolboxFeature = feature instanceof ToolboxFeature;
  46016. if (!featureName && oldName) {
  46017. isToolboxFeature && feature.dispose && feature.dispose(ecModel, api);
  46018. return;
  46019. }
  46020. if (!featureModel.get('show') || isToolboxFeature && feature.unusable) {
  46021. isToolboxFeature && feature.remove && feature.remove(ecModel, api);
  46022. return;
  46023. }
  46024. createIconPaths(featureModel, feature, featureName);
  46025. featureModel.setIconStatus = function (iconName, status) {
  46026. var option = this.option;
  46027. var iconPaths = this.iconPaths;
  46028. option.iconStatus = option.iconStatus || {};
  46029. option.iconStatus[iconName] = status;
  46030. if (iconPaths[iconName]) {
  46031. (status === 'emphasis' ? enterEmphasis : leaveEmphasis)(iconPaths[iconName]);
  46032. }
  46033. };
  46034. if (feature instanceof ToolboxFeature) {
  46035. if (feature.render) {
  46036. feature.render(featureModel, ecModel, api, payload);
  46037. }
  46038. }
  46039. }
  46040. function createIconPaths(featureModel, feature, featureName) {
  46041. var iconStyleModel = featureModel.getModel('iconStyle');
  46042. var iconStyleEmphasisModel = featureModel.getModel(['emphasis', 'iconStyle']); // If one feature has mutiple icon. they are orginaized as
  46043. // {
  46044. // icon: {
  46045. // foo: '',
  46046. // bar: ''
  46047. // },
  46048. // title: {
  46049. // foo: '',
  46050. // bar: ''
  46051. // }
  46052. // }
  46053. var icons = feature instanceof ToolboxFeature && feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  46054. var titles = featureModel.get('title') || {};
  46055. var iconsMap;
  46056. var titlesMap;
  46057. if (typeof icons === 'string') {
  46058. iconsMap = {};
  46059. iconsMap[featureName] = icons;
  46060. } else {
  46061. iconsMap = icons;
  46062. }
  46063. if (typeof titles === 'string') {
  46064. titlesMap = {};
  46065. titlesMap[featureName] = titles;
  46066. } else {
  46067. titlesMap = titles;
  46068. }
  46069. var iconPaths = featureModel.iconPaths = {};
  46070. each(iconsMap, function (iconStr, iconName) {
  46071. var path = createIcon(iconStr, {}, {
  46072. x: -itemSize / 2,
  46073. y: -itemSize / 2,
  46074. width: itemSize,
  46075. height: itemSize
  46076. }); // TODO handling image
  46077. path.setStyle(iconStyleModel.getItemStyle());
  46078. var pathEmphasisState = path.ensureState('emphasis');
  46079. pathEmphasisState.style = iconStyleEmphasisModel.getItemStyle(); // Text position calculation
  46080. var textContent = new ZRText({
  46081. style: {
  46082. text: titlesMap[iconName],
  46083. align: iconStyleEmphasisModel.get('textAlign'),
  46084. borderRadius: iconStyleEmphasisModel.get('textBorderRadius'),
  46085. padding: iconStyleEmphasisModel.get('textPadding'),
  46086. fill: null
  46087. },
  46088. ignore: true
  46089. });
  46090. path.setTextContent(textContent);
  46091. setTooltipConfig({
  46092. el: path,
  46093. componentModel: toolboxModel,
  46094. itemName: iconName,
  46095. formatterParamsExtra: {
  46096. title: titlesMap[iconName]
  46097. }
  46098. }); // graphic.enableHoverEmphasis(path);
  46099. path.__title = titlesMap[iconName];
  46100. path.on('mouseover', function () {
  46101. // Should not reuse above hoverStyle, which might be modified.
  46102. var hoverStyle = iconStyleEmphasisModel.getItemStyle();
  46103. var defaultTextPosition = toolboxModel.get('orient') === 'vertical' ? toolboxModel.get('right') == null ? 'right' : 'left' : toolboxModel.get('bottom') == null ? 'bottom' : 'top';
  46104. textContent.setStyle({
  46105. fill: iconStyleEmphasisModel.get('textFill') || hoverStyle.fill || hoverStyle.stroke || '#000',
  46106. backgroundColor: iconStyleEmphasisModel.get('textBackgroundColor')
  46107. });
  46108. path.setTextConfig({
  46109. position: iconStyleEmphasisModel.get('textPosition') || defaultTextPosition
  46110. });
  46111. textContent.ignore = !toolboxModel.get('showTitle'); // Use enterEmphasis and leaveEmphasis provide by ec.
  46112. // There are flags managed by the echarts.
  46113. enterEmphasis(this);
  46114. }).on('mouseout', function () {
  46115. if (featureModel.get(['iconStatus', iconName]) !== 'emphasis') {
  46116. leaveEmphasis(this);
  46117. }
  46118. textContent.hide();
  46119. });
  46120. (featureModel.get(['iconStatus', iconName]) === 'emphasis' ? enterEmphasis : leaveEmphasis)(path);
  46121. group.add(path);
  46122. path.on('click', bind(feature.onclick, feature, ecModel, api, iconName));
  46123. iconPaths[iconName] = path;
  46124. });
  46125. }
  46126. layout$2(group, toolboxModel, api); // Render background after group is layout
  46127. // FIXME
  46128. group.add(makeBackground(group.getBoundingRect(), toolboxModel)); // Adjust icon title positions to avoid them out of screen
  46129. group.eachChild(function (icon) {
  46130. var titleText = icon.__title; // const hoverStyle = icon.hoverStyle;
  46131. // TODO simplify code?
  46132. var emphasisState = icon.ensureState('emphasis');
  46133. var emphasisTextConfig = emphasisState.textConfig || (emphasisState.textConfig = {});
  46134. var textContent = icon.getTextContent();
  46135. var emphasisTextState = textContent && textContent.states.emphasis; // May be background element
  46136. if (emphasisTextState && !isFunction(emphasisTextState) && titleText) {
  46137. var emphasisTextStyle = emphasisTextState.style || (emphasisTextState.style = {});
  46138. var rect = getBoundingRect(titleText, ZRText.makeFont(emphasisTextStyle));
  46139. var offsetX = icon.x + group.x;
  46140. var offsetY = icon.y + group.y + itemSize;
  46141. var needPutOnTop = false;
  46142. if (offsetY + rect.height > api.getHeight()) {
  46143. emphasisTextConfig.position = 'top';
  46144. needPutOnTop = true;
  46145. }
  46146. var topOffset = needPutOnTop ? -5 - rect.height : itemSize + 8;
  46147. if (offsetX + rect.width / 2 > api.getWidth()) {
  46148. emphasisTextConfig.position = ['100%', topOffset];
  46149. emphasisTextStyle.align = 'right';
  46150. } else if (offsetX - rect.width / 2 < 0) {
  46151. emphasisTextConfig.position = [0, topOffset];
  46152. emphasisTextStyle.align = 'left';
  46153. }
  46154. }
  46155. });
  46156. };
  46157. ToolboxView.prototype.updateView = function (toolboxModel, ecModel, api, payload) {
  46158. each(this._features, function (feature) {
  46159. feature instanceof ToolboxFeature && feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  46160. });
  46161. }; // updateLayout(toolboxModel, ecModel, api, payload) {
  46162. // zrUtil.each(this._features, function (feature) {
  46163. // feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  46164. // });
  46165. // },
  46166. ToolboxView.prototype.remove = function (ecModel, api) {
  46167. each(this._features, function (feature) {
  46168. feature instanceof ToolboxFeature && feature.remove && feature.remove(ecModel, api);
  46169. });
  46170. this.group.removeAll();
  46171. };
  46172. ToolboxView.prototype.dispose = function (ecModel, api) {
  46173. each(this._features, function (feature) {
  46174. feature instanceof ToolboxFeature && feature.dispose && feature.dispose(ecModel, api);
  46175. });
  46176. };
  46177. ToolboxView.type = 'toolbox';
  46178. return ToolboxView;
  46179. }(ComponentView);
  46180. function isUserFeatureName(featureName) {
  46181. return featureName.indexOf('my') === 0;
  46182. }
  46183. /* global window, document */
  46184. var SaveAsImage =
  46185. /** @class */
  46186. function (_super) {
  46187. __extends(SaveAsImage, _super);
  46188. function SaveAsImage() {
  46189. return _super !== null && _super.apply(this, arguments) || this;
  46190. }
  46191. SaveAsImage.prototype.onclick = function (ecModel, api) {
  46192. var model = this.model;
  46193. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  46194. var isSvg = api.getZr().painter.getType() === 'svg';
  46195. var type = isSvg ? 'svg' : model.get('type', true) || 'png';
  46196. var url = api.getConnectedDataURL({
  46197. type: type,
  46198. backgroundColor: model.get('backgroundColor', true) || ecModel.get('backgroundColor') || '#fff',
  46199. connectedBackgroundColor: model.get('connectedBackgroundColor'),
  46200. excludeComponents: model.get('excludeComponents'),
  46201. pixelRatio: model.get('pixelRatio')
  46202. }); // Chrome, Firefox, New Edge
  46203. if (typeof MouseEvent === 'function' && (env.browser.newEdge || !env.browser.ie && !env.browser.edge)) {
  46204. var $a = document.createElement('a');
  46205. $a.download = title + '.' + type;
  46206. $a.target = '_blank';
  46207. $a.href = url;
  46208. var evt = new MouseEvent('click', {
  46209. // some micro front-end framework, window maybe is a Proxy
  46210. view: document.defaultView,
  46211. bubbles: true,
  46212. cancelable: false
  46213. });
  46214. $a.dispatchEvent(evt);
  46215. } // IE or old Edge
  46216. else {
  46217. if (window.navigator.msSaveOrOpenBlob || isSvg) {
  46218. var parts = url.split(','); // data:[<mime type>][;charset=<charset>][;base64],<encoded data>
  46219. var base64Encoded = parts[0].indexOf('base64') > -1;
  46220. var bstr = isSvg // should decode the svg data uri first
  46221. ? decodeURIComponent(parts[1]) : parts[1]; // only `atob` when the data uri is encoded with base64
  46222. // otherwise, like `svg` data uri exported by zrender,
  46223. // there will be an error, for it's not encoded with base64.
  46224. // (just a url-encoded string through `encodeURIComponent`)
  46225. base64Encoded && (bstr = window.atob(bstr));
  46226. var filename = title + '.' + type;
  46227. if (window.navigator.msSaveOrOpenBlob) {
  46228. var n = bstr.length;
  46229. var u8arr = new Uint8Array(n);
  46230. while (n--) {
  46231. u8arr[n] = bstr.charCodeAt(n);
  46232. }
  46233. var blob = new Blob([u8arr]);
  46234. window.navigator.msSaveOrOpenBlob(blob, filename);
  46235. } else {
  46236. var frame = document.createElement('iframe');
  46237. document.body.appendChild(frame);
  46238. var cw = frame.contentWindow;
  46239. var doc = cw.document;
  46240. doc.open('image/svg+xml', 'replace');
  46241. doc.write(bstr);
  46242. doc.close();
  46243. cw.focus();
  46244. doc.execCommand('SaveAs', true, filename);
  46245. document.body.removeChild(frame);
  46246. }
  46247. } else {
  46248. var lang = model.get('lang');
  46249. var html = '' + '<body style="margin:0;">' + '<img src="' + url + '" style="max-width:100%;" title="' + (lang && lang[0] || '') + '" />' + '</body>';
  46250. var tab = window.open();
  46251. tab.document.write(html);
  46252. tab.document.title = title;
  46253. }
  46254. }
  46255. };
  46256. SaveAsImage.getDefaultOption = function (ecModel) {
  46257. var defaultOption = {
  46258. show: true,
  46259. icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0',
  46260. title: ecModel.getLocaleModel().get(['toolbox', 'saveAsImage', 'title']),
  46261. type: 'png',
  46262. // Default use option.backgroundColor
  46263. // backgroundColor: '#fff',
  46264. connectedBackgroundColor: '#fff',
  46265. name: '',
  46266. excludeComponents: ['toolbox'],
  46267. // use current pixel ratio of device by default
  46268. // pixelRatio: 1,
  46269. lang: ecModel.getLocaleModel().get(['toolbox', 'saveAsImage', 'lang'])
  46270. };
  46271. return defaultOption;
  46272. };
  46273. return SaveAsImage;
  46274. }(ToolboxFeature);
  46275. SaveAsImage.prototype.unusable = !env.canvasSupported;
  46276. var INNER_STACK_KEYWORD = '__ec_magicType_stack__';
  46277. var radioTypes = [['line', 'bar'], ['stack']];
  46278. var MagicType =
  46279. /** @class */
  46280. function (_super) {
  46281. __extends(MagicType, _super);
  46282. function MagicType() {
  46283. return _super !== null && _super.apply(this, arguments) || this;
  46284. }
  46285. MagicType.prototype.getIcons = function () {
  46286. var model = this.model;
  46287. var availableIcons = model.get('icon');
  46288. var icons = {};
  46289. each(model.get('type'), function (type) {
  46290. if (availableIcons[type]) {
  46291. icons[type] = availableIcons[type];
  46292. }
  46293. });
  46294. return icons;
  46295. };
  46296. MagicType.getDefaultOption = function (ecModel) {
  46297. var defaultOption = {
  46298. show: true,
  46299. type: [],
  46300. // Icon group
  46301. icon: {
  46302. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  46303. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  46304. // eslint-disable-next-line
  46305. stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line
  46306. },
  46307. // `line`, `bar`, `stack`, `tiled`
  46308. title: ecModel.getLocaleModel().get(['toolbox', 'magicType', 'title']),
  46309. option: {},
  46310. seriesIndex: {}
  46311. };
  46312. return defaultOption;
  46313. };
  46314. MagicType.prototype.onclick = function (ecModel, api, type) {
  46315. var model = this.model;
  46316. var seriesIndex = model.get(['seriesIndex', type]); // Not supported magicType
  46317. if (!seriesOptGenreator[type]) {
  46318. return;
  46319. }
  46320. var newOption = {
  46321. series: []
  46322. };
  46323. var generateNewSeriesTypes = function (seriesModel) {
  46324. var seriesType = seriesModel.subType;
  46325. var seriesId = seriesModel.id;
  46326. var newSeriesOpt = seriesOptGenreator[type](seriesType, seriesId, seriesModel, model);
  46327. if (newSeriesOpt) {
  46328. // PENDING If merge original option?
  46329. defaults(newSeriesOpt, seriesModel.option);
  46330. newOption.series.push(newSeriesOpt);
  46331. } // Modify boundaryGap
  46332. var coordSys = seriesModel.coordinateSystem;
  46333. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  46334. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  46335. if (categoryAxis) {
  46336. var axisDim = categoryAxis.dim;
  46337. var axisType = axisDim + 'Axis';
  46338. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  46339. var axisIndex = axisModel.componentIndex;
  46340. newOption[axisType] = newOption[axisType] || [];
  46341. for (var i = 0; i <= axisIndex; i++) {
  46342. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  46343. }
  46344. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  46345. }
  46346. }
  46347. };
  46348. each(radioTypes, function (radio) {
  46349. if (indexOf(radio, type) >= 0) {
  46350. each(radio, function (item) {
  46351. model.setIconStatus(item, 'normal');
  46352. });
  46353. }
  46354. });
  46355. model.setIconStatus(type, 'emphasis');
  46356. ecModel.eachComponent({
  46357. mainType: 'series',
  46358. query: seriesIndex == null ? null : {
  46359. seriesIndex: seriesIndex
  46360. }
  46361. }, generateNewSeriesTypes);
  46362. var newTitle;
  46363. var currentType = type; // Change title of stack
  46364. if (type === 'stack') {
  46365. // use titles in model instead of ecModel
  46366. // as stack and tiled appears in pair, just flip them
  46367. // no need of checking stack state
  46368. newTitle = merge({
  46369. stack: model.option.title.tiled,
  46370. tiled: model.option.title.stack
  46371. }, model.option.title);
  46372. if (model.get(['iconStatus', type]) !== 'emphasis') {
  46373. currentType = 'tiled';
  46374. }
  46375. }
  46376. api.dispatchAction({
  46377. type: 'changeMagicType',
  46378. currentType: currentType,
  46379. newOption: newOption,
  46380. newTitle: newTitle,
  46381. featureName: 'magicType'
  46382. });
  46383. };
  46384. return MagicType;
  46385. }(ToolboxFeature);
  46386. var seriesOptGenreator = {
  46387. 'line': function (seriesType, seriesId, seriesModel, model) {
  46388. if (seriesType === 'bar') {
  46389. return merge({
  46390. id: seriesId,
  46391. type: 'line',
  46392. // Preserve data related option
  46393. data: seriesModel.get('data'),
  46394. stack: seriesModel.get('stack'),
  46395. markPoint: seriesModel.get('markPoint'),
  46396. markLine: seriesModel.get('markLine')
  46397. }, model.get(['option', 'line']) || {}, true);
  46398. }
  46399. },
  46400. 'bar': function (seriesType, seriesId, seriesModel, model) {
  46401. if (seriesType === 'line') {
  46402. return merge({
  46403. id: seriesId,
  46404. type: 'bar',
  46405. // Preserve data related option
  46406. data: seriesModel.get('data'),
  46407. stack: seriesModel.get('stack'),
  46408. markPoint: seriesModel.get('markPoint'),
  46409. markLine: seriesModel.get('markLine')
  46410. }, model.get(['option', 'bar']) || {}, true);
  46411. }
  46412. },
  46413. 'stack': function (seriesType, seriesId, seriesModel, model) {
  46414. var isStack = seriesModel.get('stack') === INNER_STACK_KEYWORD;
  46415. if (seriesType === 'line' || seriesType === 'bar') {
  46416. model.setIconStatus('stack', isStack ? 'normal' : 'emphasis');
  46417. return merge({
  46418. id: seriesId,
  46419. stack: isStack ? '' : INNER_STACK_KEYWORD
  46420. }, model.get(['option', 'stack']) || {}, true);
  46421. }
  46422. }
  46423. }; // TODO: SELF REGISTERED.
  46424. registerAction({
  46425. type: 'changeMagicType',
  46426. event: 'magicTypeChanged',
  46427. update: 'prepareAndUpdate'
  46428. }, function (payload, ecModel) {
  46429. ecModel.mergeOption(payload.newOption);
  46430. });
  46431. /* global document */
  46432. var BLOCK_SPLITER = new Array(60).join('-');
  46433. var ITEM_SPLITER = '\t';
  46434. /**
  46435. * Group series into two types
  46436. * 1. on category axis, like line, bar
  46437. * 2. others, like scatter, pie
  46438. */
  46439. function groupSeries(ecModel) {
  46440. var seriesGroupByCategoryAxis = {};
  46441. var otherSeries = [];
  46442. var meta = [];
  46443. ecModel.eachRawSeries(function (seriesModel) {
  46444. var coordSys = seriesModel.coordinateSystem;
  46445. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  46446. // TODO: TYPE Consider polar? Include polar may increase unecessary bundle size.
  46447. var baseAxis = coordSys.getBaseAxis();
  46448. if (baseAxis.type === 'category') {
  46449. var key = baseAxis.dim + '_' + baseAxis.index;
  46450. if (!seriesGroupByCategoryAxis[key]) {
  46451. seriesGroupByCategoryAxis[key] = {
  46452. categoryAxis: baseAxis,
  46453. valueAxis: coordSys.getOtherAxis(baseAxis),
  46454. series: []
  46455. };
  46456. meta.push({
  46457. axisDim: baseAxis.dim,
  46458. axisIndex: baseAxis.index
  46459. });
  46460. }
  46461. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  46462. } else {
  46463. otherSeries.push(seriesModel);
  46464. }
  46465. } else {
  46466. otherSeries.push(seriesModel);
  46467. }
  46468. });
  46469. return {
  46470. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  46471. other: otherSeries,
  46472. meta: meta
  46473. };
  46474. }
  46475. /**
  46476. * Assemble content of series on cateogory axis
  46477. * @inner
  46478. */
  46479. function assembleSeriesWithCategoryAxis(groups) {
  46480. var tables = [];
  46481. each(groups, function (group, key) {
  46482. var categoryAxis = group.categoryAxis;
  46483. var valueAxis = group.valueAxis;
  46484. var valueAxisDim = valueAxis.dim;
  46485. var headers = [' '].concat(map(group.series, function (series) {
  46486. return series.name;
  46487. })); // @ts-ignore TODO Polar
  46488. var columns = [categoryAxis.model.getCategories()];
  46489. each(group.series, function (series) {
  46490. var rawData = series.getRawData();
  46491. columns.push(series.getRawData().mapArray(rawData.mapDimension(valueAxisDim), function (val) {
  46492. return val;
  46493. }));
  46494. }); // Assemble table content
  46495. var lines = [headers.join(ITEM_SPLITER)];
  46496. for (var i = 0; i < columns[0].length; i++) {
  46497. var items = [];
  46498. for (var j = 0; j < columns.length; j++) {
  46499. items.push(columns[j][i]);
  46500. }
  46501. lines.push(items.join(ITEM_SPLITER));
  46502. }
  46503. tables.push(lines.join('\n'));
  46504. });
  46505. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  46506. }
  46507. /**
  46508. * Assemble content of other series
  46509. */
  46510. function assembleOtherSeries(series) {
  46511. return map(series, function (series) {
  46512. var data = series.getRawData();
  46513. var lines = [series.name];
  46514. var vals = [];
  46515. data.each(data.dimensions, function () {
  46516. var argLen = arguments.length;
  46517. var dataIndex = arguments[argLen - 1];
  46518. var name = data.getName(dataIndex);
  46519. for (var i = 0; i < argLen - 1; i++) {
  46520. vals[i] = arguments[i];
  46521. }
  46522. lines.push((name ? name + ITEM_SPLITER : '') + vals.join(ITEM_SPLITER));
  46523. });
  46524. return lines.join('\n');
  46525. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  46526. }
  46527. function getContentFromModel(ecModel) {
  46528. var result = groupSeries(ecModel);
  46529. return {
  46530. value: filter([assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis), assembleOtherSeries(result.other)], function (str) {
  46531. return !!str.replace(/[\n\t\s]/g, '');
  46532. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  46533. meta: result.meta
  46534. };
  46535. }
  46536. function trim$1(str) {
  46537. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  46538. }
  46539. /**
  46540. * If a block is tsv format
  46541. */
  46542. function isTSVFormat(block) {
  46543. // Simple method to find out if a block is tsv format
  46544. var firstLine = block.slice(0, block.indexOf('\n'));
  46545. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  46546. return true;
  46547. }
  46548. }
  46549. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  46550. /**
  46551. * @param {string} tsv
  46552. * @return {Object}
  46553. */
  46554. function parseTSVContents(tsv) {
  46555. var tsvLines = tsv.split(/\n+/g);
  46556. var headers = trim$1(tsvLines.shift()).split(itemSplitRegex);
  46557. var categories = [];
  46558. var series = map(headers, function (header) {
  46559. return {
  46560. name: header,
  46561. data: []
  46562. };
  46563. });
  46564. for (var i = 0; i < tsvLines.length; i++) {
  46565. var items = trim$1(tsvLines[i]).split(itemSplitRegex);
  46566. categories.push(items.shift());
  46567. for (var j = 0; j < items.length; j++) {
  46568. series[j] && (series[j].data[i] = items[j]);
  46569. }
  46570. }
  46571. return {
  46572. series: series,
  46573. categories: categories
  46574. };
  46575. }
  46576. function parseListContents(str) {
  46577. var lines = str.split(/\n+/g);
  46578. var seriesName = trim$1(lines.shift());
  46579. var data = [];
  46580. for (var i = 0; i < lines.length; i++) {
  46581. // if line is empty, ignore it.
  46582. // there is a case that a user forgot to delete `\n`.
  46583. var line = trim$1(lines[i]);
  46584. if (!line) {
  46585. continue;
  46586. }
  46587. var items = line.split(itemSplitRegex);
  46588. var name_1 = '';
  46589. var value = void 0;
  46590. var hasName = false;
  46591. if (isNaN(items[0])) {
  46592. // First item is name
  46593. hasName = true;
  46594. name_1 = items[0];
  46595. items = items.slice(1);
  46596. data[i] = {
  46597. name: name_1,
  46598. value: []
  46599. };
  46600. value = data[i].value;
  46601. } else {
  46602. value = data[i] = [];
  46603. }
  46604. for (var j = 0; j < items.length; j++) {
  46605. value.push(+items[j]);
  46606. }
  46607. if (value.length === 1) {
  46608. hasName ? data[i].value = value[0] : data[i] = value[0];
  46609. }
  46610. }
  46611. return {
  46612. name: seriesName,
  46613. data: data
  46614. };
  46615. }
  46616. function parseContents(str, blockMetaList) {
  46617. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  46618. var newOption = {
  46619. series: []
  46620. };
  46621. each(blocks, function (block, idx) {
  46622. if (isTSVFormat(block)) {
  46623. var result = parseTSVContents(block);
  46624. var blockMeta = blockMetaList[idx];
  46625. var axisKey = blockMeta.axisDim + 'Axis';
  46626. if (blockMeta) {
  46627. newOption[axisKey] = newOption[axisKey] || [];
  46628. newOption[axisKey][blockMeta.axisIndex] = {
  46629. data: result.categories
  46630. };
  46631. newOption.series = newOption.series.concat(result.series);
  46632. }
  46633. } else {
  46634. var result = parseListContents(block);
  46635. newOption.series.push(result);
  46636. }
  46637. });
  46638. return newOption;
  46639. }
  46640. var DataView =
  46641. /** @class */
  46642. function (_super) {
  46643. __extends(DataView, _super);
  46644. function DataView() {
  46645. return _super !== null && _super.apply(this, arguments) || this;
  46646. }
  46647. DataView.prototype.onclick = function (ecModel, api) {
  46648. var container = api.getDom();
  46649. var model = this.model;
  46650. if (this._dom) {
  46651. container.removeChild(this._dom);
  46652. }
  46653. var root = document.createElement('div');
  46654. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  46655. root.style.backgroundColor = model.get('backgroundColor') || '#fff'; // Create elements
  46656. var header = document.createElement('h4');
  46657. var lang = model.get('lang') || [];
  46658. header.innerHTML = lang[0] || model.get('title');
  46659. header.style.cssText = 'margin: 10px 20px;';
  46660. header.style.color = model.get('textColor');
  46661. var viewMain = document.createElement('div');
  46662. var textarea = document.createElement('textarea');
  46663. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  46664. var optionToContent = model.get('optionToContent');
  46665. var contentToOption = model.get('contentToOption');
  46666. var result = getContentFromModel(ecModel);
  46667. if (typeof optionToContent === 'function') {
  46668. var htmlOrDom = optionToContent(api.getOption());
  46669. if (typeof htmlOrDom === 'string') {
  46670. viewMain.innerHTML = htmlOrDom;
  46671. } else if (isDom(htmlOrDom)) {
  46672. viewMain.appendChild(htmlOrDom);
  46673. }
  46674. } else {
  46675. // Use default textarea
  46676. viewMain.appendChild(textarea);
  46677. textarea.readOnly = model.get('readOnly');
  46678. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  46679. textarea.style.color = model.get('textColor');
  46680. textarea.style.borderColor = model.get('textareaBorderColor');
  46681. textarea.style.backgroundColor = model.get('textareaColor');
  46682. textarea.value = result.value;
  46683. }
  46684. var blockMetaList = result.meta;
  46685. var buttonContainer = document.createElement('div');
  46686. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  46687. var buttonStyle = 'float:right;margin-right:20px;border:none;' + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  46688. var closeButton = document.createElement('div');
  46689. var refreshButton = document.createElement('div');
  46690. buttonStyle += ';background-color:' + model.get('buttonColor');
  46691. buttonStyle += ';color:' + model.get('buttonTextColor');
  46692. var self = this;
  46693. function close() {
  46694. container.removeChild(root);
  46695. self._dom = null;
  46696. }
  46697. addEventListener(closeButton, 'click', close);
  46698. addEventListener(refreshButton, 'click', function () {
  46699. if (contentToOption == null && optionToContent != null || contentToOption != null && optionToContent == null) {
  46700. if ("development" !== 'production') {
  46701. // eslint-disable-next-line
  46702. console.warn('It seems you have just provided one of `contentToOption` and `optionToContent` functions but missed the other one. Data change is ignored.');
  46703. }
  46704. close();
  46705. return;
  46706. }
  46707. var newOption;
  46708. try {
  46709. if (typeof contentToOption === 'function') {
  46710. newOption = contentToOption(viewMain, api.getOption());
  46711. } else {
  46712. newOption = parseContents(textarea.value, blockMetaList);
  46713. }
  46714. } catch (e) {
  46715. close();
  46716. throw new Error('Data view format error ' + e);
  46717. }
  46718. if (newOption) {
  46719. api.dispatchAction({
  46720. type: 'changeDataView',
  46721. newOption: newOption
  46722. });
  46723. }
  46724. close();
  46725. });
  46726. closeButton.innerHTML = lang[1];
  46727. refreshButton.innerHTML = lang[2];
  46728. refreshButton.style.cssText = buttonStyle;
  46729. closeButton.style.cssText = buttonStyle;
  46730. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  46731. buttonContainer.appendChild(closeButton);
  46732. root.appendChild(header);
  46733. root.appendChild(viewMain);
  46734. root.appendChild(buttonContainer);
  46735. viewMain.style.height = container.clientHeight - 80 + 'px';
  46736. container.appendChild(root);
  46737. this._dom = root;
  46738. };
  46739. DataView.prototype.remove = function (ecModel, api) {
  46740. this._dom && api.getDom().removeChild(this._dom);
  46741. };
  46742. DataView.prototype.dispose = function (ecModel, api) {
  46743. this.remove(ecModel, api);
  46744. };
  46745. DataView.getDefaultOption = function (ecModel) {
  46746. var defaultOption = {
  46747. show: true,
  46748. readOnly: false,
  46749. optionToContent: null,
  46750. contentToOption: null,
  46751. // eslint-disable-next-line
  46752. icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
  46753. title: ecModel.getLocaleModel().get(['toolbox', 'dataView', 'title']),
  46754. lang: ecModel.getLocaleModel().get(['toolbox', 'dataView', 'lang']),
  46755. backgroundColor: '#fff',
  46756. textColor: '#000',
  46757. textareaColor: '#fff',
  46758. textareaBorderColor: '#333',
  46759. buttonColor: '#c23531',
  46760. buttonTextColor: '#fff'
  46761. };
  46762. return defaultOption;
  46763. };
  46764. return DataView;
  46765. }(ToolboxFeature);
  46766. /**
  46767. * @inner
  46768. */
  46769. function tryMergeDataOption(newData, originalData) {
  46770. return map(newData, function (newVal, idx) {
  46771. var original = originalData && originalData[idx];
  46772. if (isObject(original) && !isArray(original)) {
  46773. var newValIsObject = isObject(newVal) && !isArray(newVal);
  46774. if (!newValIsObject) {
  46775. newVal = {
  46776. value: newVal
  46777. };
  46778. } // original data has name but new data has no name
  46779. var shouldDeleteName = original.name != null && newVal.name == null; // Original data has option
  46780. newVal = defaults(newVal, original);
  46781. shouldDeleteName && delete newVal.name;
  46782. return newVal;
  46783. } else {
  46784. return newVal;
  46785. }
  46786. });
  46787. } // TODO: SELF REGISTERED.
  46788. registerAction({
  46789. type: 'changeDataView',
  46790. event: 'dataViewChanged',
  46791. update: 'prepareAndUpdate'
  46792. }, function (payload, ecModel) {
  46793. var newSeriesOptList = [];
  46794. each(payload.newOption.series, function (seriesOpt) {
  46795. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  46796. if (!seriesModel) {
  46797. // New created series
  46798. // Geuss the series type
  46799. newSeriesOptList.push(extend({
  46800. // Default is scatter
  46801. type: 'scatter'
  46802. }, seriesOpt));
  46803. } else {
  46804. var originalData = seriesModel.get('data');
  46805. newSeriesOptList.push({
  46806. name: seriesOpt.name,
  46807. data: tryMergeDataOption(seriesOpt.data, originalData)
  46808. });
  46809. }
  46810. });
  46811. ecModel.mergeOption(defaults({
  46812. series: newSeriesOptList
  46813. }, payload.newOption));
  46814. });
  46815. var each$5 = each;
  46816. var inner$b = makeInner();
  46817. /**
  46818. * @param ecModel
  46819. * @param newSnapshot key is dataZoomId
  46820. */
  46821. function push(ecModel, newSnapshot) {
  46822. var storedSnapshots = getStoreSnapshots(ecModel); // If previous dataZoom can not be found,
  46823. // complete an range with current range.
  46824. each$5(newSnapshot, function (batchItem, dataZoomId) {
  46825. var i = storedSnapshots.length - 1;
  46826. for (; i >= 0; i--) {
  46827. var snapshot = storedSnapshots[i];
  46828. if (snapshot[dataZoomId]) {
  46829. break;
  46830. }
  46831. }
  46832. if (i < 0) {
  46833. // No origin range set, create one by current range.
  46834. var dataZoomModel = ecModel.queryComponents({
  46835. mainType: 'dataZoom',
  46836. subType: 'select',
  46837. id: dataZoomId
  46838. })[0];
  46839. if (dataZoomModel) {
  46840. var percentRange = dataZoomModel.getPercentRange();
  46841. storedSnapshots[0][dataZoomId] = {
  46842. dataZoomId: dataZoomId,
  46843. start: percentRange[0],
  46844. end: percentRange[1]
  46845. };
  46846. }
  46847. }
  46848. });
  46849. storedSnapshots.push(newSnapshot);
  46850. }
  46851. function pop(ecModel) {
  46852. var storedSnapshots = getStoreSnapshots(ecModel);
  46853. var head = storedSnapshots[storedSnapshots.length - 1];
  46854. storedSnapshots.length > 1 && storedSnapshots.pop(); // Find top for all dataZoom.
  46855. var snapshot = {};
  46856. each$5(head, function (batchItem, dataZoomId) {
  46857. for (var i = storedSnapshots.length - 1; i >= 0; i--) {
  46858. batchItem = storedSnapshots[i][dataZoomId];
  46859. if (batchItem) {
  46860. snapshot[dataZoomId] = batchItem;
  46861. break;
  46862. }
  46863. }
  46864. });
  46865. return snapshot;
  46866. }
  46867. function clear$1(ecModel) {
  46868. inner$b(ecModel).snapshots = null;
  46869. }
  46870. function count(ecModel) {
  46871. return getStoreSnapshots(ecModel).length;
  46872. }
  46873. /**
  46874. * History length of each dataZoom may be different.
  46875. * this._history[0] is used to store origin range.
  46876. */
  46877. function getStoreSnapshots(ecModel) {
  46878. var store = inner$b(ecModel);
  46879. if (!store.snapshots) {
  46880. store.snapshots = [{}];
  46881. }
  46882. return store.snapshots;
  46883. }
  46884. var RestoreOption =
  46885. /** @class */
  46886. function (_super) {
  46887. __extends(RestoreOption, _super);
  46888. function RestoreOption() {
  46889. return _super !== null && _super.apply(this, arguments) || this;
  46890. }
  46891. RestoreOption.prototype.onclick = function (ecModel, api) {
  46892. clear$1(ecModel);
  46893. api.dispatchAction({
  46894. type: 'restore',
  46895. from: this.uid
  46896. });
  46897. };
  46898. RestoreOption.getDefaultOption = function (ecModel) {
  46899. var defaultOption = {
  46900. show: true,
  46901. // eslint-disable-next-line
  46902. icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5',
  46903. title: ecModel.getLocaleModel().get(['toolbox', 'restore', 'title'])
  46904. };
  46905. return defaultOption;
  46906. };
  46907. return RestoreOption;
  46908. }(ToolboxFeature); // TODO: SELF REGISTERED.
  46909. registerAction({
  46910. type: 'restore',
  46911. event: 'restore',
  46912. update: 'prepareAndUpdate'
  46913. }, function (payload, ecModel) {
  46914. ecModel.resetOption('recreate');
  46915. });
  46916. var ATTR = '\0_ec_interaction_mutex';
  46917. function take(zr, resourceKey, userKey) {
  46918. var store = getStore(zr);
  46919. store[resourceKey] = userKey;
  46920. }
  46921. function release(zr, resourceKey, userKey) {
  46922. var store = getStore(zr);
  46923. var uKey = store[resourceKey];
  46924. if (uKey === userKey) {
  46925. store[resourceKey] = null;
  46926. }
  46927. }
  46928. function isTaken(zr, resourceKey) {
  46929. return !!getStore(zr)[resourceKey];
  46930. }
  46931. function getStore(zr) {
  46932. return zr[ATTR] || (zr[ATTR] = {});
  46933. }
  46934. /**
  46935. * payload: {
  46936. * type: 'takeGlobalCursor',
  46937. * key: 'dataZoomSelect', or 'brush', or ...,
  46938. * If no userKey, release global cursor.
  46939. * }
  46940. */
  46941. // TODO: SELF REGISTERED.
  46942. registerAction({
  46943. type: 'takeGlobalCursor',
  46944. event: 'globalCursorTaken',
  46945. update: 'update'
  46946. }, function () {});
  46947. var BRUSH_PANEL_GLOBAL = true;
  46948. var mathMin$7 = Math.min;
  46949. var mathMax$7 = Math.max;
  46950. var mathPow$2 = Math.pow;
  46951. var COVER_Z = 10000;
  46952. var UNSELECT_THRESHOLD = 6;
  46953. var MIN_RESIZE_LINE_WIDTH = 6;
  46954. var MUTEX_RESOURCE_KEY = 'globalPan';
  46955. var DIRECTION_MAP = {
  46956. w: [0, 0],
  46957. e: [0, 1],
  46958. n: [1, 0],
  46959. s: [1, 1]
  46960. };
  46961. var CURSOR_MAP = {
  46962. w: 'ew',
  46963. e: 'ew',
  46964. n: 'ns',
  46965. s: 'ns',
  46966. ne: 'nesw',
  46967. sw: 'nesw',
  46968. nw: 'nwse',
  46969. se: 'nwse'
  46970. };
  46971. var DEFAULT_BRUSH_OPT = {
  46972. brushStyle: {
  46973. lineWidth: 2,
  46974. stroke: 'rgba(210,219,238,0.3)',
  46975. fill: '#D2DBEE'
  46976. },
  46977. transformable: true,
  46978. brushMode: 'single',
  46979. removeOnClick: false
  46980. };
  46981. var baseUID = 0;
  46982. /**
  46983. * params:
  46984. * areas: Array.<Array>, coord relates to container group,
  46985. * If no container specified, to global.
  46986. * opt {
  46987. * isEnd: boolean,
  46988. * removeOnClick: boolean
  46989. * }
  46990. */
  46991. var BrushController =
  46992. /** @class */
  46993. function (_super) {
  46994. __extends(BrushController, _super);
  46995. function BrushController(zr) {
  46996. var _this = _super.call(this) || this;
  46997. /**
  46998. * @internal
  46999. */
  47000. _this._track = [];
  47001. /**
  47002. * @internal
  47003. */
  47004. _this._covers = [];
  47005. _this._handlers = {};
  47006. if ("development" !== 'production') {
  47007. assert(zr);
  47008. }
  47009. _this._zr = zr;
  47010. _this.group = new Group();
  47011. _this._uid = 'brushController_' + baseUID++;
  47012. each(pointerHandlers, function (handler, eventName) {
  47013. this._handlers[eventName] = bind(handler, this);
  47014. }, _this);
  47015. return _this;
  47016. }
  47017. /**
  47018. * If set to `false`, select disabled.
  47019. */
  47020. BrushController.prototype.enableBrush = function (brushOption) {
  47021. if ("development" !== 'production') {
  47022. assert(this._mounted);
  47023. }
  47024. this._brushType && this._doDisableBrush();
  47025. brushOption.brushType && this._doEnableBrush(brushOption);
  47026. return this;
  47027. };
  47028. BrushController.prototype._doEnableBrush = function (brushOption) {
  47029. var zr = this._zr; // Consider roam, which takes globalPan too.
  47030. if (!this._enableGlobalPan) {
  47031. take(zr, MUTEX_RESOURCE_KEY, this._uid);
  47032. }
  47033. each(this._handlers, function (handler, eventName) {
  47034. zr.on(eventName, handler);
  47035. });
  47036. this._brushType = brushOption.brushType;
  47037. this._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  47038. };
  47039. BrushController.prototype._doDisableBrush = function () {
  47040. var zr = this._zr;
  47041. release(zr, MUTEX_RESOURCE_KEY, this._uid);
  47042. each(this._handlers, function (handler, eventName) {
  47043. zr.off(eventName, handler);
  47044. });
  47045. this._brushType = this._brushOption = null;
  47046. };
  47047. /**
  47048. * @param panelOpts If not pass, it is global brush.
  47049. */
  47050. BrushController.prototype.setPanels = function (panelOpts) {
  47051. if (panelOpts && panelOpts.length) {
  47052. var panels_1 = this._panels = {};
  47053. each(panelOpts, function (panelOpts) {
  47054. panels_1[panelOpts.panelId] = clone(panelOpts);
  47055. });
  47056. } else {
  47057. this._panels = null;
  47058. }
  47059. return this;
  47060. };
  47061. BrushController.prototype.mount = function (opt) {
  47062. opt = opt || {};
  47063. if ("development" !== 'production') {
  47064. this._mounted = true; // should be at first.
  47065. }
  47066. this._enableGlobalPan = opt.enableGlobalPan;
  47067. var thisGroup = this.group;
  47068. this._zr.add(thisGroup);
  47069. thisGroup.attr({
  47070. x: opt.x || 0,
  47071. y: opt.y || 0,
  47072. rotation: opt.rotation || 0,
  47073. scaleX: opt.scaleX || 1,
  47074. scaleY: opt.scaleY || 1
  47075. });
  47076. this._transform = thisGroup.getLocalTransform();
  47077. return this;
  47078. }; // eachCover(cb, context): void {
  47079. // each(this._covers, cb, context);
  47080. // }
  47081. /**
  47082. * Update covers.
  47083. * @param coverConfigList
  47084. * If coverConfigList is null/undefined, all covers removed.
  47085. */
  47086. BrushController.prototype.updateCovers = function (coverConfigList) {
  47087. if ("development" !== 'production') {
  47088. assert(this._mounted);
  47089. }
  47090. coverConfigList = map(coverConfigList, function (coverConfig) {
  47091. return merge(clone(DEFAULT_BRUSH_OPT), coverConfig, true);
  47092. });
  47093. var tmpIdPrefix = '\0-brush-index-';
  47094. var oldCovers = this._covers;
  47095. var newCovers = this._covers = [];
  47096. var controller = this;
  47097. var creatingCover = this._creatingCover;
  47098. new DataDiffer(oldCovers, coverConfigList, oldGetKey, getKey).add(addOrUpdate).update(addOrUpdate).remove(remove).execute();
  47099. return this;
  47100. function getKey(brushOption, index) {
  47101. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index) + '-' + brushOption.brushType;
  47102. }
  47103. function oldGetKey(cover, index) {
  47104. return getKey(cover.__brushOption, index);
  47105. }
  47106. function addOrUpdate(newIndex, oldIndex) {
  47107. var newBrushInternal = coverConfigList[newIndex]; // Consider setOption in event listener of brushSelect,
  47108. // where updating cover when creating should be forbiden.
  47109. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  47110. newCovers[newIndex] = oldCovers[oldIndex];
  47111. } else {
  47112. var cover = newCovers[newIndex] = oldIndex != null ? (oldCovers[oldIndex].__brushOption = newBrushInternal, oldCovers[oldIndex]) : endCreating(controller, createCover(controller, newBrushInternal));
  47113. updateCoverAfterCreation(controller, cover);
  47114. }
  47115. }
  47116. function remove(oldIndex) {
  47117. if (oldCovers[oldIndex] !== creatingCover) {
  47118. controller.group.remove(oldCovers[oldIndex]);
  47119. }
  47120. }
  47121. };
  47122. BrushController.prototype.unmount = function () {
  47123. if ("development" !== 'production') {
  47124. if (!this._mounted) {
  47125. return;
  47126. }
  47127. }
  47128. this.enableBrush(false); // container may 'removeAll' outside.
  47129. clearCovers(this);
  47130. this._zr.remove(this.group);
  47131. if ("development" !== 'production') {
  47132. this._mounted = false; // should be at last.
  47133. }
  47134. return this;
  47135. };
  47136. BrushController.prototype.dispose = function () {
  47137. this.unmount();
  47138. this.off();
  47139. };
  47140. return BrushController;
  47141. }(Eventful);
  47142. function createCover(controller, brushOption) {
  47143. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  47144. cover.__brushOption = brushOption;
  47145. updateZ(cover, brushOption);
  47146. controller.group.add(cover);
  47147. return cover;
  47148. }
  47149. function endCreating(controller, creatingCover) {
  47150. var coverRenderer = getCoverRenderer(creatingCover);
  47151. if (coverRenderer.endCreating) {
  47152. coverRenderer.endCreating(controller, creatingCover);
  47153. updateZ(creatingCover, creatingCover.__brushOption);
  47154. }
  47155. return creatingCover;
  47156. }
  47157. function updateCoverShape(controller, cover) {
  47158. var brushOption = cover.__brushOption;
  47159. getCoverRenderer(cover).updateCoverShape(controller, cover, brushOption.range, brushOption);
  47160. }
  47161. function updateZ(cover, brushOption) {
  47162. var z = brushOption.z;
  47163. z == null && (z = COVER_Z);
  47164. cover.traverse(function (el) {
  47165. el.z = z;
  47166. el.z2 = z; // Consider in given container.
  47167. });
  47168. }
  47169. function updateCoverAfterCreation(controller, cover) {
  47170. getCoverRenderer(cover).updateCommon(controller, cover);
  47171. updateCoverShape(controller, cover);
  47172. }
  47173. function getCoverRenderer(cover) {
  47174. return coverRenderers[cover.__brushOption.brushType];
  47175. } // return target panel or `true` (means global panel)
  47176. function getPanelByPoint(controller, e, localCursorPoint) {
  47177. var panels = controller._panels;
  47178. if (!panels) {
  47179. return BRUSH_PANEL_GLOBAL; // Global panel
  47180. }
  47181. var panel;
  47182. var transform = controller._transform;
  47183. each(panels, function (pn) {
  47184. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  47185. });
  47186. return panel;
  47187. } // Return a panel or true
  47188. function getPanelByCover(controller, cover) {
  47189. var panels = controller._panels;
  47190. if (!panels) {
  47191. return BRUSH_PANEL_GLOBAL; // Global panel
  47192. }
  47193. var panelId = cover.__brushOption.panelId; // User may give cover without coord sys info,
  47194. // which is then treated as global panel.
  47195. return panelId != null ? panels[panelId] : BRUSH_PANEL_GLOBAL;
  47196. }
  47197. function clearCovers(controller) {
  47198. var covers = controller._covers;
  47199. var originalLength = covers.length;
  47200. each(covers, function (cover) {
  47201. controller.group.remove(cover);
  47202. }, controller);
  47203. covers.length = 0;
  47204. return !!originalLength;
  47205. }
  47206. function trigger(controller, opt) {
  47207. var areas = map(controller._covers, function (cover) {
  47208. var brushOption = cover.__brushOption;
  47209. var range = clone(brushOption.range);
  47210. return {
  47211. brushType: brushOption.brushType,
  47212. panelId: brushOption.panelId,
  47213. range: range
  47214. };
  47215. });
  47216. controller.trigger('brush', {
  47217. areas: areas,
  47218. isEnd: !!opt.isEnd,
  47219. removeOnClick: !!opt.removeOnClick
  47220. });
  47221. }
  47222. function shouldShowCover(controller) {
  47223. var track = controller._track;
  47224. if (!track.length) {
  47225. return false;
  47226. }
  47227. var p2 = track[track.length - 1];
  47228. var p1 = track[0];
  47229. var dx = p2[0] - p1[0];
  47230. var dy = p2[1] - p1[1];
  47231. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  47232. return dist > UNSELECT_THRESHOLD;
  47233. }
  47234. function getTrackEnds(track) {
  47235. var tail = track.length - 1;
  47236. tail < 0 && (tail = 0);
  47237. return [track[0], track[tail]];
  47238. }
  47239. function createBaseRectCover(rectRangeConverter, controller, brushOption, edgeNameSequences) {
  47240. var cover = new Group();
  47241. cover.add(new Rect({
  47242. name: 'main',
  47243. style: makeStyle(brushOption),
  47244. silent: true,
  47245. draggable: true,
  47246. cursor: 'move',
  47247. drift: curry(driftRect, rectRangeConverter, controller, cover, ['n', 's', 'w', 'e']),
  47248. ondragend: curry(trigger, controller, {
  47249. isEnd: true
  47250. })
  47251. }));
  47252. each(edgeNameSequences, function (nameSequence) {
  47253. cover.add(new Rect({
  47254. name: nameSequence.join(''),
  47255. style: {
  47256. opacity: 0
  47257. },
  47258. draggable: true,
  47259. silent: true,
  47260. invisible: true,
  47261. drift: curry(driftRect, rectRangeConverter, controller, cover, nameSequence),
  47262. ondragend: curry(trigger, controller, {
  47263. isEnd: true
  47264. })
  47265. }));
  47266. });
  47267. return cover;
  47268. }
  47269. function updateBaseRect(controller, cover, localRange, brushOption) {
  47270. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  47271. var handleSize = mathMax$7(lineWidth, MIN_RESIZE_LINE_WIDTH);
  47272. var x = localRange[0][0];
  47273. var y = localRange[1][0];
  47274. var xa = x - lineWidth / 2;
  47275. var ya = y - lineWidth / 2;
  47276. var x2 = localRange[0][1];
  47277. var y2 = localRange[1][1];
  47278. var x2a = x2 - handleSize + lineWidth / 2;
  47279. var y2a = y2 - handleSize + lineWidth / 2;
  47280. var width = x2 - x;
  47281. var height = y2 - y;
  47282. var widtha = width + lineWidth;
  47283. var heighta = height + lineWidth;
  47284. updateRectShape(controller, cover, 'main', x, y, width, height);
  47285. if (brushOption.transformable) {
  47286. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  47287. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  47288. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  47289. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  47290. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  47291. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  47292. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  47293. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  47294. }
  47295. }
  47296. function updateCommon(controller, cover) {
  47297. var brushOption = cover.__brushOption;
  47298. var transformable = brushOption.transformable;
  47299. var mainEl = cover.childAt(0);
  47300. mainEl.useStyle(makeStyle(brushOption));
  47301. mainEl.attr({
  47302. silent: !transformable,
  47303. cursor: transformable ? 'move' : 'default'
  47304. });
  47305. each([['w'], ['e'], ['n'], ['s'], ['s', 'e'], ['s', 'w'], ['n', 'e'], ['n', 'w']], function (nameSequence) {
  47306. var el = cover.childOfName(nameSequence.join(''));
  47307. var globalDir = nameSequence.length === 1 ? getGlobalDirection1(controller, nameSequence[0]) : getGlobalDirection2(controller, nameSequence);
  47308. el && el.attr({
  47309. silent: !transformable,
  47310. invisible: !transformable,
  47311. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  47312. });
  47313. });
  47314. }
  47315. function updateRectShape(controller, cover, name, x, y, w, h) {
  47316. var el = cover.childOfName(name);
  47317. el && el.setShape(pointsToRect(clipByPanel(controller, cover, [[x, y], [x + w, y + h]])));
  47318. }
  47319. function makeStyle(brushOption) {
  47320. return defaults({
  47321. strokeNoScale: true
  47322. }, brushOption.brushStyle);
  47323. }
  47324. function formatRectRange(x, y, x2, y2) {
  47325. var min = [mathMin$7(x, x2), mathMin$7(y, y2)];
  47326. var max = [mathMax$7(x, x2), mathMax$7(y, y2)];
  47327. return [[min[0], max[0]], [min[1], max[1]] // y range
  47328. ];
  47329. }
  47330. function getTransform$1(controller) {
  47331. return getTransform(controller.group);
  47332. }
  47333. function getGlobalDirection1(controller, localDirName) {
  47334. var map = {
  47335. w: 'left',
  47336. e: 'right',
  47337. n: 'top',
  47338. s: 'bottom'
  47339. };
  47340. var inverseMap = {
  47341. left: 'w',
  47342. right: 'e',
  47343. top: 'n',
  47344. bottom: 's'
  47345. };
  47346. var dir = transformDirection(map[localDirName], getTransform$1(controller));
  47347. return inverseMap[dir];
  47348. }
  47349. function getGlobalDirection2(controller, localDirNameSeq) {
  47350. var globalDir = [getGlobalDirection1(controller, localDirNameSeq[0]), getGlobalDirection1(controller, localDirNameSeq[1])];
  47351. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  47352. return globalDir.join('');
  47353. }
  47354. function driftRect(rectRangeConverter, controller, cover, dirNameSequence, dx, dy) {
  47355. var brushOption = cover.__brushOption;
  47356. var rectRange = rectRangeConverter.toRectRange(brushOption.range);
  47357. var localDelta = toLocalDelta(controller, dx, dy);
  47358. each(dirNameSequence, function (dirName) {
  47359. var ind = DIRECTION_MAP[dirName];
  47360. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  47361. });
  47362. brushOption.range = rectRangeConverter.fromRectRange(formatRectRange(rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]));
  47363. updateCoverAfterCreation(controller, cover);
  47364. trigger(controller, {
  47365. isEnd: false
  47366. });
  47367. }
  47368. function driftPolygon(controller, cover, dx, dy) {
  47369. var range = cover.__brushOption.range;
  47370. var localDelta = toLocalDelta(controller, dx, dy);
  47371. each(range, function (point) {
  47372. point[0] += localDelta[0];
  47373. point[1] += localDelta[1];
  47374. });
  47375. updateCoverAfterCreation(controller, cover);
  47376. trigger(controller, {
  47377. isEnd: false
  47378. });
  47379. }
  47380. function toLocalDelta(controller, dx, dy) {
  47381. var thisGroup = controller.group;
  47382. var localD = thisGroup.transformCoordToLocal(dx, dy);
  47383. var localZero = thisGroup.transformCoordToLocal(0, 0);
  47384. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  47385. }
  47386. function clipByPanel(controller, cover, data) {
  47387. var panel = getPanelByCover(controller, cover);
  47388. return panel && panel !== BRUSH_PANEL_GLOBAL ? panel.clipPath(data, controller._transform) : clone(data);
  47389. }
  47390. function pointsToRect(points) {
  47391. var xmin = mathMin$7(points[0][0], points[1][0]);
  47392. var ymin = mathMin$7(points[0][1], points[1][1]);
  47393. var xmax = mathMax$7(points[0][0], points[1][0]);
  47394. var ymax = mathMax$7(points[0][1], points[1][1]);
  47395. return {
  47396. x: xmin,
  47397. y: ymin,
  47398. width: xmax - xmin,
  47399. height: ymax - ymin
  47400. };
  47401. }
  47402. function resetCursor(controller, e, localCursorPoint) {
  47403. if ( // Check active
  47404. !controller._brushType // resetCursor should be always called when mouse is in zr area,
  47405. // but not called when mouse is out of zr area to avoid bad influence
  47406. // if `mousemove`, `mouseup` are triggered from `document` event.
  47407. || isOutsideZrArea(controller, e.offsetX, e.offsetY)) {
  47408. return;
  47409. }
  47410. var zr = controller._zr;
  47411. var covers = controller._covers;
  47412. var currPanel = getPanelByPoint(controller, e, localCursorPoint); // Check whether in covers.
  47413. if (!controller._dragging) {
  47414. for (var i = 0; i < covers.length; i++) {
  47415. var brushOption = covers[i].__brushOption;
  47416. if (currPanel && (currPanel === BRUSH_PANEL_GLOBAL || brushOption.panelId === currPanel.panelId) && coverRenderers[brushOption.brushType].contain(covers[i], localCursorPoint[0], localCursorPoint[1])) {
  47417. // Use cursor style set on cover.
  47418. return;
  47419. }
  47420. }
  47421. }
  47422. currPanel && zr.setCursorStyle('crosshair');
  47423. }
  47424. function preventDefault(e) {
  47425. var rawE = e.event;
  47426. rawE.preventDefault && rawE.preventDefault();
  47427. }
  47428. function mainShapeContain(cover, x, y) {
  47429. return cover.childOfName('main').contain(x, y);
  47430. }
  47431. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  47432. var creatingCover = controller._creatingCover;
  47433. var panel = controller._creatingPanel;
  47434. var thisBrushOption = controller._brushOption;
  47435. var eventParams;
  47436. controller._track.push(localCursorPoint.slice());
  47437. if (shouldShowCover(controller) || creatingCover) {
  47438. if (panel && !creatingCover) {
  47439. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  47440. var brushOption = clone(thisBrushOption);
  47441. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  47442. brushOption.panelId = panel === BRUSH_PANEL_GLOBAL ? null : panel.panelId;
  47443. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  47444. controller._covers.push(creatingCover);
  47445. }
  47446. if (creatingCover) {
  47447. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  47448. var coverBrushOption = creatingCover.__brushOption;
  47449. coverBrushOption.range = coverRenderer.getCreatingRange(clipByPanel(controller, creatingCover, controller._track));
  47450. if (isEnd) {
  47451. endCreating(controller, creatingCover);
  47452. coverRenderer.updateCommon(controller, creatingCover);
  47453. }
  47454. updateCoverShape(controller, creatingCover);
  47455. eventParams = {
  47456. isEnd: isEnd
  47457. };
  47458. }
  47459. } else if (isEnd && thisBrushOption.brushMode === 'single' && thisBrushOption.removeOnClick) {
  47460. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  47461. // But a single click do not clear covers, because user may have casual
  47462. // clicks (for example, click on other component and do not expect covers
  47463. // disappear).
  47464. // Only some cover removed, trigger action, but not every click trigger action.
  47465. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  47466. eventParams = {
  47467. isEnd: isEnd,
  47468. removeOnClick: true
  47469. };
  47470. }
  47471. }
  47472. return eventParams;
  47473. }
  47474. function determineBrushType(brushType, panel) {
  47475. if (brushType === 'auto') {
  47476. if ("development" !== 'production') {
  47477. assert(panel && panel.defaultBrushType, 'MUST have defaultBrushType when brushType is "atuo"');
  47478. }
  47479. return panel.defaultBrushType;
  47480. }
  47481. return brushType;
  47482. }
  47483. var pointerHandlers = {
  47484. mousedown: function (e) {
  47485. if (this._dragging) {
  47486. // In case some browser do not support globalOut,
  47487. // and release mouse out side the browser.
  47488. handleDragEnd(this, e);
  47489. } else if (!e.target || !e.target.draggable) {
  47490. preventDefault(e);
  47491. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  47492. this._creatingCover = null;
  47493. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  47494. if (panel) {
  47495. this._dragging = true;
  47496. this._track = [localCursorPoint.slice()];
  47497. }
  47498. }
  47499. },
  47500. mousemove: function (e) {
  47501. var x = e.offsetX;
  47502. var y = e.offsetY;
  47503. var localCursorPoint = this.group.transformCoordToLocal(x, y);
  47504. resetCursor(this, e, localCursorPoint);
  47505. if (this._dragging) {
  47506. preventDefault(e);
  47507. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  47508. eventParams && trigger(this, eventParams);
  47509. }
  47510. },
  47511. mouseup: function (e) {
  47512. handleDragEnd(this, e);
  47513. }
  47514. };
  47515. function handleDragEnd(controller, e) {
  47516. if (controller._dragging) {
  47517. preventDefault(e);
  47518. var x = e.offsetX;
  47519. var y = e.offsetY;
  47520. var localCursorPoint = controller.group.transformCoordToLocal(x, y);
  47521. var eventParams = updateCoverByMouse(controller, e, localCursorPoint, true);
  47522. controller._dragging = false;
  47523. controller._track = [];
  47524. controller._creatingCover = null; // trigger event shoule be at final, after procedure will be nested.
  47525. eventParams && trigger(controller, eventParams);
  47526. }
  47527. }
  47528. function isOutsideZrArea(controller, x, y) {
  47529. var zr = controller._zr;
  47530. return x < 0 || x > zr.getWidth() || y < 0 || y > zr.getHeight();
  47531. }
  47532. /**
  47533. * key: brushType
  47534. */
  47535. var coverRenderers = {
  47536. lineX: getLineRenderer(0),
  47537. lineY: getLineRenderer(1),
  47538. rect: {
  47539. createCover: function (controller, brushOption) {
  47540. function returnInput(range) {
  47541. return range;
  47542. }
  47543. return createBaseRectCover({
  47544. toRectRange: returnInput,
  47545. fromRectRange: returnInput
  47546. }, controller, brushOption, [['w'], ['e'], ['n'], ['s'], ['s', 'e'], ['s', 'w'], ['n', 'e'], ['n', 'w']]);
  47547. },
  47548. getCreatingRange: function (localTrack) {
  47549. var ends = getTrackEnds(localTrack);
  47550. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  47551. },
  47552. updateCoverShape: function (controller, cover, localRange, brushOption) {
  47553. updateBaseRect(controller, cover, localRange, brushOption);
  47554. },
  47555. updateCommon: updateCommon,
  47556. contain: mainShapeContain
  47557. },
  47558. polygon: {
  47559. createCover: function (controller, brushOption) {
  47560. var cover = new Group(); // Do not use graphic.Polygon because graphic.Polyline do not close the
  47561. // border of the shape when drawing, which is a better experience for user.
  47562. cover.add(new Polyline({
  47563. name: 'main',
  47564. style: makeStyle(brushOption),
  47565. silent: true
  47566. }));
  47567. return cover;
  47568. },
  47569. getCreatingRange: function (localTrack) {
  47570. return localTrack;
  47571. },
  47572. endCreating: function (controller, cover) {
  47573. cover.remove(cover.childAt(0)); // Use graphic.Polygon close the shape.
  47574. cover.add(new Polygon({
  47575. name: 'main',
  47576. draggable: true,
  47577. drift: curry(driftPolygon, controller, cover),
  47578. ondragend: curry(trigger, controller, {
  47579. isEnd: true
  47580. })
  47581. }));
  47582. },
  47583. updateCoverShape: function (controller, cover, localRange, brushOption) {
  47584. cover.childAt(0).setShape({
  47585. points: clipByPanel(controller, cover, localRange)
  47586. });
  47587. },
  47588. updateCommon: updateCommon,
  47589. contain: mainShapeContain
  47590. }
  47591. };
  47592. function getLineRenderer(xyIndex) {
  47593. return {
  47594. createCover: function (controller, brushOption) {
  47595. return createBaseRectCover({
  47596. toRectRange: function (range) {
  47597. var rectRange = [range, [0, 100]];
  47598. xyIndex && rectRange.reverse();
  47599. return rectRange;
  47600. },
  47601. fromRectRange: function (rectRange) {
  47602. return rectRange[xyIndex];
  47603. }
  47604. }, controller, brushOption, [[['w'], ['e']], [['n'], ['s']]][xyIndex]);
  47605. },
  47606. getCreatingRange: function (localTrack) {
  47607. var ends = getTrackEnds(localTrack);
  47608. var min = mathMin$7(ends[0][xyIndex], ends[1][xyIndex]);
  47609. var max = mathMax$7(ends[0][xyIndex], ends[1][xyIndex]);
  47610. return [min, max];
  47611. },
  47612. updateCoverShape: function (controller, cover, localRange, brushOption) {
  47613. var otherExtent; // If brushWidth not specified, fit the panel.
  47614. var panel = getPanelByCover(controller, cover);
  47615. if (panel !== BRUSH_PANEL_GLOBAL && panel.getLinearBrushOtherExtent) {
  47616. otherExtent = panel.getLinearBrushOtherExtent(xyIndex);
  47617. } else {
  47618. var zr = controller._zr;
  47619. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  47620. }
  47621. var rectRange = [localRange, otherExtent];
  47622. xyIndex && rectRange.reverse();
  47623. updateBaseRect(controller, cover, rectRange, brushOption);
  47624. },
  47625. updateCommon: updateCommon,
  47626. contain: mainShapeContain
  47627. };
  47628. }
  47629. /*
  47630. * Licensed to the Apache Software Foundation (ASF) under one
  47631. * or more contributor license agreements. See the NOTICE file
  47632. * distributed with this work for additional information
  47633. * regarding copyright ownership. The ASF licenses this file
  47634. * to you under the Apache License, Version 2.0 (the
  47635. * "License"); you may not use this file except in compliance
  47636. * with the License. You may obtain a copy of the License at
  47637. *
  47638. * http://www.apache.org/licenses/LICENSE-2.0
  47639. *
  47640. * Unless required by applicable law or agreed to in writing,
  47641. * software distributed under the License is distributed on an
  47642. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47643. * KIND, either express or implied. See the License for the
  47644. * specific language governing permissions and limitations
  47645. * under the License.
  47646. */
  47647. /**
  47648. * AUTO-GENERATED FILE. DO NOT MODIFY.
  47649. */
  47650. /*
  47651. * Licensed to the Apache Software Foundation (ASF) under one
  47652. * or more contributor license agreements. See the NOTICE file
  47653. * distributed with this work for additional information
  47654. * regarding copyright ownership. The ASF licenses this file
  47655. * to you under the Apache License, Version 2.0 (the
  47656. * "License"); you may not use this file except in compliance
  47657. * with the License. You may obtain a copy of the License at
  47658. *
  47659. * http://www.apache.org/licenses/LICENSE-2.0
  47660. *
  47661. * Unless required by applicable law or agreed to in writing,
  47662. * software distributed under the License is distributed on an
  47663. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47664. * KIND, either express or implied. See the License for the
  47665. * specific language governing permissions and limitations
  47666. * under the License.
  47667. */
  47668. var IRRELEVANT_EXCLUDES = {
  47669. 'axisPointer': 1,
  47670. 'tooltip': 1,
  47671. 'brush': 1
  47672. };
  47673. /**
  47674. * Avoid that: mouse click on a elements that is over geo or graph,
  47675. * but roam is triggered.
  47676. */
  47677. function onIrrelevantElement(e, api, targetCoordSysModel) {
  47678. var model = api.getComponentByElement(e.topTarget); // If model is axisModel, it works only if it is injected with coordinateSystem.
  47679. var coordSys = model && model.coordinateSystem;
  47680. return model && model !== targetCoordSysModel && !IRRELEVANT_EXCLUDES.hasOwnProperty(model.mainType) && coordSys && coordSys.model !== targetCoordSysModel;
  47681. }
  47682. function makeRectPanelClipPath(rect) {
  47683. rect = normalizeRect(rect);
  47684. return function (localPoints) {
  47685. return clipPointsByRect(localPoints, rect);
  47686. };
  47687. }
  47688. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  47689. rect = normalizeRect(rect);
  47690. return function (xyIndex) {
  47691. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  47692. var brushWidth = idx ? rect.width : rect.height;
  47693. var base = idx ? rect.x : rect.y;
  47694. return [base, base + (brushWidth || 0)];
  47695. };
  47696. }
  47697. function makeRectIsTargetByCursor(rect, api, targetModel) {
  47698. var boundingRect = normalizeRect(rect);
  47699. return function (e, localCursorPoint) {
  47700. return boundingRect.contain(localCursorPoint[0], localCursorPoint[1]) && !onIrrelevantElement(e, api, targetModel);
  47701. };
  47702. } // Consider width/height is negative.
  47703. function normalizeRect(rect) {
  47704. return BoundingRect.create(rect);
  47705. }
  47706. // how to genarialize to more coordinate systems.
  47707. var INCLUDE_FINDER_MAIN_TYPES = ['grid', 'xAxis', 'yAxis', 'geo', 'graph', 'polar', 'radiusAxis', 'angleAxis', 'bmap'];
  47708. var BrushTargetManager =
  47709. /** @class */
  47710. function () {
  47711. /**
  47712. * @param finder contains Index/Id/Name of xAxis/yAxis/geo/grid
  47713. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  47714. * @param opt.include include coordinate system types.
  47715. */
  47716. function BrushTargetManager(finder, ecModel, opt) {
  47717. var _this = this;
  47718. this._targetInfoList = [];
  47719. var foundCpts = parseFinder$1(ecModel, finder);
  47720. each(targetInfoBuilders, function (builder, type) {
  47721. if (!opt || !opt.include || indexOf(opt.include, type) >= 0) {
  47722. builder(foundCpts, _this._targetInfoList);
  47723. }
  47724. });
  47725. }
  47726. BrushTargetManager.prototype.setOutputRanges = function (areas, ecModel) {
  47727. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  47728. (area.coordRanges || (area.coordRanges = [])).push(coordRange); // area.coordRange is the first of area.coordRanges
  47729. if (!area.coordRange) {
  47730. area.coordRange = coordRange; // In 'category' axis, coord to pixel is not reversible, so we can not
  47731. // rebuild range by coordRange accrately, which may bring trouble when
  47732. // brushing only one item. So we use __rangeOffset to rebuilding range
  47733. // by coordRange. And this it only used in brush component so it is no
  47734. // need to be adapted to coordRanges.
  47735. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  47736. area.__rangeOffset = {
  47737. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  47738. xyMinMax: result.xyMinMax
  47739. };
  47740. }
  47741. });
  47742. return areas;
  47743. };
  47744. BrushTargetManager.prototype.matchOutputRanges = function (areas, ecModel, cb) {
  47745. each(areas, function (area) {
  47746. var targetInfo = this.findTargetInfo(area, ecModel);
  47747. if (targetInfo && targetInfo !== true) {
  47748. each(targetInfo.coordSyses, function (coordSys) {
  47749. var result = coordConvert[area.brushType](1, coordSys, area.range, true);
  47750. cb(area, result.values, coordSys, ecModel);
  47751. });
  47752. }
  47753. }, this);
  47754. };
  47755. /**
  47756. * the `areas` is `BrushModel.areas`.
  47757. * Called in layout stage.
  47758. * convert `area.coordRange` to global range and set panelId to `area.range`.
  47759. */
  47760. BrushTargetManager.prototype.setInputRanges = function (areas, ecModel) {
  47761. each(areas, function (area) {
  47762. var targetInfo = this.findTargetInfo(area, ecModel);
  47763. if ("development" !== 'production') {
  47764. assert(!targetInfo || targetInfo === true || area.coordRange, 'coordRange must be specified when coord index specified.');
  47765. assert(!targetInfo || targetInfo !== true || area.range, 'range must be specified in global brush.');
  47766. }
  47767. area.range = area.range || []; // convert coordRange to global range and set panelId.
  47768. if (targetInfo && targetInfo !== true) {
  47769. area.panelId = targetInfo.panelId; // (1) area.range shoule always be calculate from coordRange but does
  47770. // not keep its original value, for the sake of the dataZoom scenario,
  47771. // where area.coordRange remains unchanged but area.range may be changed.
  47772. // (2) Only support converting one coordRange to pixel range in brush
  47773. // component. So do not consider `coordRanges`.
  47774. // (3) About __rangeOffset, see comment above.
  47775. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  47776. var rangeOffset = area.__rangeOffset;
  47777. area.range = rangeOffset ? diffProcessor[area.brushType](result.values, rangeOffset.offset, getScales(result.xyMinMax, rangeOffset.xyMinMax)) : result.values;
  47778. }
  47779. }, this);
  47780. };
  47781. BrushTargetManager.prototype.makePanelOpts = function (api, getDefaultBrushType) {
  47782. return map(this._targetInfoList, function (targetInfo) {
  47783. var rect = targetInfo.getPanelRect();
  47784. return {
  47785. panelId: targetInfo.panelId,
  47786. defaultBrushType: getDefaultBrushType ? getDefaultBrushType(targetInfo) : null,
  47787. clipPath: makeRectPanelClipPath(rect),
  47788. isTargetByCursor: makeRectIsTargetByCursor(rect, api, targetInfo.coordSysModel),
  47789. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  47790. };
  47791. });
  47792. };
  47793. BrushTargetManager.prototype.controlSeries = function (area, seriesModel, ecModel) {
  47794. // Check whether area is bound in coord, and series do not belong to that coord.
  47795. // If do not do this check, some brush (like lineX) will controll all axes.
  47796. var targetInfo = this.findTargetInfo(area, ecModel);
  47797. return targetInfo === true || targetInfo && indexOf(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0;
  47798. };
  47799. /**
  47800. * If return Object, a coord found.
  47801. * If reutrn true, global found.
  47802. * Otherwise nothing found.
  47803. */
  47804. BrushTargetManager.prototype.findTargetInfo = function (area, ecModel) {
  47805. var targetInfoList = this._targetInfoList;
  47806. var foundCpts = parseFinder$1(ecModel, area);
  47807. for (var i = 0; i < targetInfoList.length; i++) {
  47808. var targetInfo = targetInfoList[i];
  47809. var areaPanelId = area.panelId;
  47810. if (areaPanelId) {
  47811. if (targetInfo.panelId === areaPanelId) {
  47812. return targetInfo;
  47813. }
  47814. } else {
  47815. for (var j = 0; j < targetInfoMatchers.length; j++) {
  47816. if (targetInfoMatchers[j](foundCpts, targetInfo)) {
  47817. return targetInfo;
  47818. }
  47819. }
  47820. }
  47821. }
  47822. return true;
  47823. };
  47824. return BrushTargetManager;
  47825. }();
  47826. function formatMinMax(minMax) {
  47827. minMax[0] > minMax[1] && minMax.reverse();
  47828. return minMax;
  47829. }
  47830. function parseFinder$1(ecModel, finder) {
  47831. return parseFinder(ecModel, finder, {
  47832. includeMainTypes: INCLUDE_FINDER_MAIN_TYPES
  47833. });
  47834. }
  47835. var targetInfoBuilders = {
  47836. grid: function (foundCpts, targetInfoList) {
  47837. var xAxisModels = foundCpts.xAxisModels;
  47838. var yAxisModels = foundCpts.yAxisModels;
  47839. var gridModels = foundCpts.gridModels; // Remove duplicated.
  47840. var gridModelMap = createHashMap();
  47841. var xAxesHas = {};
  47842. var yAxesHas = {};
  47843. if (!xAxisModels && !yAxisModels && !gridModels) {
  47844. return;
  47845. }
  47846. each(xAxisModels, function (axisModel) {
  47847. var gridModel = axisModel.axis.grid.model;
  47848. gridModelMap.set(gridModel.id, gridModel);
  47849. xAxesHas[gridModel.id] = true;
  47850. });
  47851. each(yAxisModels, function (axisModel) {
  47852. var gridModel = axisModel.axis.grid.model;
  47853. gridModelMap.set(gridModel.id, gridModel);
  47854. yAxesHas[gridModel.id] = true;
  47855. });
  47856. each(gridModels, function (gridModel) {
  47857. gridModelMap.set(gridModel.id, gridModel);
  47858. xAxesHas[gridModel.id] = true;
  47859. yAxesHas[gridModel.id] = true;
  47860. });
  47861. gridModelMap.each(function (gridModel) {
  47862. var grid = gridModel.coordinateSystem;
  47863. var cartesians = [];
  47864. each(grid.getCartesians(), function (cartesian, index) {
  47865. if (indexOf(xAxisModels, cartesian.getAxis('x').model) >= 0 || indexOf(yAxisModels, cartesian.getAxis('y').model) >= 0) {
  47866. cartesians.push(cartesian);
  47867. }
  47868. });
  47869. targetInfoList.push({
  47870. panelId: 'grid--' + gridModel.id,
  47871. gridModel: gridModel,
  47872. coordSysModel: gridModel,
  47873. // Use the first one as the representitive coordSys.
  47874. coordSys: cartesians[0],
  47875. coordSyses: cartesians,
  47876. getPanelRect: panelRectBuilders.grid,
  47877. xAxisDeclared: xAxesHas[gridModel.id],
  47878. yAxisDeclared: yAxesHas[gridModel.id]
  47879. });
  47880. });
  47881. },
  47882. geo: function (foundCpts, targetInfoList) {
  47883. each(foundCpts.geoModels, function (geoModel) {
  47884. var coordSys = geoModel.coordinateSystem;
  47885. targetInfoList.push({
  47886. panelId: 'geo--' + geoModel.id,
  47887. geoModel: geoModel,
  47888. coordSysModel: geoModel,
  47889. coordSys: coordSys,
  47890. coordSyses: [coordSys],
  47891. getPanelRect: panelRectBuilders.geo
  47892. });
  47893. });
  47894. }
  47895. };
  47896. var targetInfoMatchers = [// grid
  47897. function (foundCpts, targetInfo) {
  47898. var xAxisModel = foundCpts.xAxisModel;
  47899. var yAxisModel = foundCpts.yAxisModel;
  47900. var gridModel = foundCpts.gridModel;
  47901. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  47902. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  47903. return gridModel && gridModel === targetInfo.gridModel;
  47904. }, // geo
  47905. function (foundCpts, targetInfo) {
  47906. var geoModel = foundCpts.geoModel;
  47907. return geoModel && geoModel === targetInfo.geoModel;
  47908. }];
  47909. var panelRectBuilders = {
  47910. grid: function () {
  47911. // grid is not Transformable.
  47912. return this.coordSys.master.getRect().clone();
  47913. },
  47914. geo: function () {
  47915. var coordSys = this.coordSys;
  47916. var rect = coordSys.getBoundingRect().clone(); // geo roam and zoom transform
  47917. rect.applyTransform(getTransform(coordSys));
  47918. return rect;
  47919. }
  47920. };
  47921. var coordConvert = {
  47922. lineX: curry(axisConvert, 0),
  47923. lineY: curry(axisConvert, 1),
  47924. rect: function (to, coordSys, rangeOrCoordRange, clamp) {
  47925. var xminymin = to ? coordSys.pointToData([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]], clamp) : coordSys.dataToPoint([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]], clamp);
  47926. var xmaxymax = to ? coordSys.pointToData([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]], clamp) : coordSys.dataToPoint([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]], clamp);
  47927. var values = [formatMinMax([xminymin[0], xmaxymax[0]]), formatMinMax([xminymin[1], xmaxymax[1]])];
  47928. return {
  47929. values: values,
  47930. xyMinMax: values
  47931. };
  47932. },
  47933. polygon: function (to, coordSys, rangeOrCoordRange, clamp) {
  47934. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  47935. var values = map(rangeOrCoordRange, function (item) {
  47936. var p = to ? coordSys.pointToData(item, clamp) : coordSys.dataToPoint(item, clamp);
  47937. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  47938. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  47939. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  47940. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  47941. return p;
  47942. });
  47943. return {
  47944. values: values,
  47945. xyMinMax: xyMinMax
  47946. };
  47947. }
  47948. };
  47949. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  47950. if ("development" !== 'production') {
  47951. assert(coordSys.type === 'cartesian2d', 'lineX/lineY brush is available only in cartesian2d.');
  47952. }
  47953. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  47954. var values = formatMinMax(map([0, 1], function (i) {
  47955. return to ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]), true) : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  47956. }));
  47957. var xyMinMax = [];
  47958. xyMinMax[axisNameIndex] = values;
  47959. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  47960. return {
  47961. values: values,
  47962. xyMinMax: xyMinMax
  47963. };
  47964. }
  47965. var diffProcessor = {
  47966. lineX: curry(axisDiffProcessor, 0),
  47967. lineY: curry(axisDiffProcessor, 1),
  47968. rect: function (values, refer, scales) {
  47969. return [[values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]], [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]];
  47970. },
  47971. polygon: function (values, refer, scales) {
  47972. return map(values, function (item, idx) {
  47973. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  47974. });
  47975. }
  47976. };
  47977. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  47978. return [values[0] - scales[axisNameIndex] * refer[0], values[1] - scales[axisNameIndex] * refer[1]];
  47979. } // We have to process scale caused by dataZoom manually,
  47980. // although it might be not accurate.
  47981. // Return [0~1, 0~1]
  47982. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  47983. var sizeCurr = getSize(xyMinMaxCurr);
  47984. var sizeOrigin = getSize(xyMinMaxOrigin);
  47985. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  47986. isNaN(scales[0]) && (scales[0] = 1);
  47987. isNaN(scales[1]) && (scales[1] = 1);
  47988. return scales;
  47989. }
  47990. function getSize(xyMinMax) {
  47991. return xyMinMax ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]] : [NaN, NaN];
  47992. }
  47993. var each$6 = each;
  47994. var DATA_ZOOM_ID_BASE = makeInternalComponentId('toolbox-dataZoom_');
  47995. var DataZoomFeature =
  47996. /** @class */
  47997. function (_super) {
  47998. __extends(DataZoomFeature, _super);
  47999. function DataZoomFeature() {
  48000. return _super !== null && _super.apply(this, arguments) || this;
  48001. }
  48002. DataZoomFeature.prototype.render = function (featureModel, ecModel, api, payload) {
  48003. if (!this._brushController) {
  48004. this._brushController = new BrushController(api.getZr());
  48005. this._brushController.on('brush', bind(this._onBrush, this)).mount();
  48006. }
  48007. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  48008. updateBackBtnStatus(featureModel, ecModel);
  48009. };
  48010. DataZoomFeature.prototype.onclick = function (ecModel, api, type) {
  48011. handlers[type].call(this);
  48012. };
  48013. DataZoomFeature.prototype.remove = function (ecModel, api) {
  48014. this._brushController && this._brushController.unmount();
  48015. };
  48016. DataZoomFeature.prototype.dispose = function (ecModel, api) {
  48017. this._brushController && this._brushController.dispose();
  48018. };
  48019. DataZoomFeature.prototype._onBrush = function (eventParam) {
  48020. var areas = eventParam.areas;
  48021. if (!eventParam.isEnd || !areas.length) {
  48022. return;
  48023. }
  48024. var snapshot = {};
  48025. var ecModel = this.ecModel;
  48026. this._brushController.updateCovers([]); // remove cover
  48027. var brushTargetManager = new BrushTargetManager(makeAxisFinder(this.model), ecModel, {
  48028. include: ['grid']
  48029. });
  48030. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  48031. if (coordSys.type !== 'cartesian2d') {
  48032. return;
  48033. }
  48034. var brushType = area.brushType;
  48035. if (brushType === 'rect') {
  48036. setBatch('x', coordSys, coordRange[0]);
  48037. setBatch('y', coordSys, coordRange[1]);
  48038. } else {
  48039. setBatch({
  48040. lineX: 'x',
  48041. lineY: 'y'
  48042. }[brushType], coordSys, coordRange);
  48043. }
  48044. });
  48045. push(ecModel, snapshot);
  48046. this._dispatchZoomAction(snapshot);
  48047. function setBatch(dimName, coordSys, minMax) {
  48048. var axis = coordSys.getAxis(dimName);
  48049. var axisModel = axis.model;
  48050. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel); // Restrict range.
  48051. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  48052. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  48053. minMax = sliderMove(0, minMax.slice(), axis.scale.getExtent(), 0, minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan);
  48054. }
  48055. dataZoomModel && (snapshot[dataZoomModel.id] = {
  48056. dataZoomId: dataZoomModel.id,
  48057. startValue: minMax[0],
  48058. endValue: minMax[1]
  48059. });
  48060. }
  48061. function findDataZoom(dimName, axisModel, ecModel) {
  48062. var found;
  48063. ecModel.eachComponent({
  48064. mainType: 'dataZoom',
  48065. subType: 'select'
  48066. }, function (dzModel) {
  48067. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  48068. has && (found = dzModel);
  48069. });
  48070. return found;
  48071. }
  48072. };
  48073. DataZoomFeature.prototype._dispatchZoomAction = function (snapshot) {
  48074. var batch = []; // Convert from hash map to array.
  48075. each$6(snapshot, function (batchItem, dataZoomId) {
  48076. batch.push(clone(batchItem));
  48077. });
  48078. batch.length && this.api.dispatchAction({
  48079. type: 'dataZoom',
  48080. from: this.uid,
  48081. batch: batch
  48082. });
  48083. };
  48084. DataZoomFeature.getDefaultOption = function (ecModel) {
  48085. var defaultOption = {
  48086. show: true,
  48087. filterMode: 'filter',
  48088. // Icon group
  48089. icon: {
  48090. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  48091. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  48092. },
  48093. // `zoom`, `back`
  48094. title: ecModel.getLocaleModel().get(['toolbox', 'dataZoom', 'title']),
  48095. brushStyle: {
  48096. borderWidth: 0,
  48097. color: 'rgba(210,219,238,0.2)'
  48098. }
  48099. };
  48100. return defaultOption;
  48101. };
  48102. return DataZoomFeature;
  48103. }(ToolboxFeature);
  48104. var handlers = {
  48105. zoom: function () {
  48106. var nextActive = !this._isZoomActive;
  48107. this.api.dispatchAction({
  48108. type: 'takeGlobalCursor',
  48109. key: 'dataZoomSelect',
  48110. dataZoomSelectActive: nextActive
  48111. });
  48112. },
  48113. back: function () {
  48114. this._dispatchZoomAction(pop(this.ecModel));
  48115. }
  48116. };
  48117. function makeAxisFinder(dzFeatureModel) {
  48118. var setting = {
  48119. xAxisIndex: dzFeatureModel.get('xAxisIndex', true),
  48120. yAxisIndex: dzFeatureModel.get('yAxisIndex', true),
  48121. xAxisId: dzFeatureModel.get('xAxisId', true),
  48122. yAxisId: dzFeatureModel.get('yAxisId', true)
  48123. }; // If both `xAxisIndex` `xAxisId` not set, it means 'all'.
  48124. // If both `yAxisIndex` `yAxisId` not set, it means 'all'.
  48125. // Some old cases set like this below to close yAxis control but leave xAxis control:
  48126. // `{ feature: { dataZoom: { yAxisIndex: false } }`.
  48127. if (setting.xAxisIndex == null && setting.xAxisId == null) {
  48128. setting.xAxisIndex = 'all';
  48129. }
  48130. if (setting.yAxisIndex == null && setting.yAxisId == null) {
  48131. setting.yAxisIndex = 'all';
  48132. }
  48133. return setting;
  48134. }
  48135. function updateBackBtnStatus(featureModel, ecModel) {
  48136. featureModel.setIconStatus('back', count(ecModel) > 1 ? 'emphasis' : 'normal');
  48137. }
  48138. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  48139. var zoomActive = view._isZoomActive;
  48140. if (payload && payload.type === 'takeGlobalCursor') {
  48141. zoomActive = payload.key === 'dataZoomSelect' ? payload.dataZoomSelectActive : false;
  48142. }
  48143. view._isZoomActive = zoomActive;
  48144. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  48145. var brushTargetManager = new BrushTargetManager(makeAxisFinder(featureModel), ecModel, {
  48146. include: ['grid']
  48147. });
  48148. var panels = brushTargetManager.makePanelOpts(api, function (targetInfo) {
  48149. return targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared ? 'lineX' : !targetInfo.xAxisDeclared && targetInfo.yAxisDeclared ? 'lineY' : 'rect';
  48150. });
  48151. view._brushController.setPanels(panels).enableBrush(zoomActive && panels.length ? {
  48152. brushType: 'auto',
  48153. brushStyle: featureModel.getModel('brushStyle').getItemStyle()
  48154. } : false);
  48155. }
  48156. registerInternalOptionCreator('dataZoom', function (ecModel) {
  48157. var toolboxModel = ecModel.getComponent('toolbox', 0);
  48158. var featureDataZoomPath = ['feature', 'dataZoom'];
  48159. if (!toolboxModel || toolboxModel.get(featureDataZoomPath) == null) {
  48160. return;
  48161. }
  48162. var dzFeatureModel = toolboxModel.getModel(featureDataZoomPath);
  48163. var dzOptions = [];
  48164. var finder = makeAxisFinder(dzFeatureModel);
  48165. var finderResult = parseFinder(ecModel, finder);
  48166. each$6(finderResult.xAxisModels, function (axisModel) {
  48167. return buildInternalOptions(axisModel, 'xAxis', 'xAxisIndex');
  48168. });
  48169. each$6(finderResult.yAxisModels, function (axisModel) {
  48170. return buildInternalOptions(axisModel, 'yAxis', 'yAxisIndex');
  48171. });
  48172. function buildInternalOptions(axisModel, axisMainType, axisIndexPropName) {
  48173. var axisIndex = axisModel.componentIndex;
  48174. var newOpt = {
  48175. type: 'select',
  48176. $fromToolbox: true,
  48177. // Default to be filter
  48178. filterMode: dzFeatureModel.get('filterMode', true) || 'filter',
  48179. // Id for merge mapping.
  48180. id: DATA_ZOOM_ID_BASE + axisMainType + axisIndex
  48181. };
  48182. newOpt[axisIndexPropName] = axisIndex;
  48183. dzOptions.push(newOpt);
  48184. }
  48185. return dzOptions;
  48186. });
  48187. function install$b(registers) {
  48188. registers.registerComponentModel(ToolboxModel);
  48189. registers.registerComponentView(ToolboxView);
  48190. registerFeature('saveAsImage', SaveAsImage);
  48191. registerFeature('magicType', MagicType);
  48192. registerFeature('dataView', DataView);
  48193. registerFeature('dataZoom', DataZoomFeature);
  48194. registerFeature('restore', RestoreOption);
  48195. use(install$a);
  48196. }
  48197. var TooltipModel =
  48198. /** @class */
  48199. function (_super) {
  48200. __extends(TooltipModel, _super);
  48201. function TooltipModel() {
  48202. var _this = _super !== null && _super.apply(this, arguments) || this;
  48203. _this.type = TooltipModel.type;
  48204. return _this;
  48205. }
  48206. TooltipModel.type = 'tooltip';
  48207. TooltipModel.dependencies = ['axisPointer'];
  48208. TooltipModel.defaultOption = {
  48209. zlevel: 0,
  48210. z: 60,
  48211. show: true,
  48212. // tooltip main content
  48213. showContent: true,
  48214. // 'trigger' only works on coordinate system.
  48215. // 'item' | 'axis' | 'none'
  48216. trigger: 'item',
  48217. // 'click' | 'mousemove' | 'none'
  48218. triggerOn: 'mousemove|click',
  48219. alwaysShowContent: false,
  48220. displayMode: 'single',
  48221. renderMode: 'auto',
  48222. // whether restraint content inside viewRect.
  48223. // If renderMode: 'richText', default true.
  48224. // If renderMode: 'html', defaut false (for backward compat).
  48225. confine: null,
  48226. showDelay: 0,
  48227. hideDelay: 100,
  48228. // Animation transition time, unit is second
  48229. transitionDuration: 0.4,
  48230. enterable: false,
  48231. backgroundColor: '#fff',
  48232. // box shadow
  48233. shadowBlur: 10,
  48234. shadowColor: 'rgba(0, 0, 0, .2)',
  48235. shadowOffsetX: 1,
  48236. shadowOffsetY: 2,
  48237. // tooltip border radius, unit is px, default is 4
  48238. borderRadius: 4,
  48239. // tooltip border width, unit is px, default is 0 (no border)
  48240. borderWidth: 1,
  48241. // Tooltip inside padding, default is 5 for all direction
  48242. // Array is allowed to set up, right, bottom, left, same with css
  48243. // The default value: See `tooltip/tooltipMarkup.ts#getPaddingFromTooltipModel`.
  48244. padding: null,
  48245. // Extra css text
  48246. extraCssText: '',
  48247. // axis indicator, trigger by axis
  48248. axisPointer: {
  48249. // default is line
  48250. // legal values: 'line' | 'shadow' | 'cross'
  48251. type: 'line',
  48252. // Valid when type is line, appoint tooltip line locate on which line. Optional
  48253. // legal values: 'x' | 'y' | 'angle' | 'radius' | 'auto'
  48254. // default is 'auto', chose the axis which type is category.
  48255. // for multiply y axis, cartesian coord chose x axis, polar chose angle axis
  48256. axis: 'auto',
  48257. animation: 'auto',
  48258. animationDurationUpdate: 200,
  48259. animationEasingUpdate: 'exponentialOut',
  48260. crossStyle: {
  48261. color: '#999',
  48262. width: 1,
  48263. type: 'dashed',
  48264. // TODO formatter
  48265. textStyle: {}
  48266. } // lineStyle and shadowStyle should not be specified here,
  48267. // otherwise it will always override those styles on option.axisPointer.
  48268. },
  48269. textStyle: {
  48270. color: '#666',
  48271. fontSize: 14
  48272. }
  48273. };
  48274. return TooltipModel;
  48275. }(ComponentModel);
  48276. /* global document */
  48277. function shouldTooltipConfine(tooltipModel) {
  48278. var confineOption = tooltipModel.get('confine');
  48279. return confineOption != null ? !!confineOption // In richText mode, the outside part can not be visible.
  48280. : tooltipModel.get('renderMode') === 'richText';
  48281. }
  48282. function testStyle(styleProps) {
  48283. if (!env.domSupported) {
  48284. return;
  48285. }
  48286. var style = document.documentElement.style;
  48287. for (var i = 0, len = styleProps.length; i < len; i++) {
  48288. if (styleProps[i] in style) {
  48289. return styleProps[i];
  48290. }
  48291. }
  48292. }
  48293. var TRANSFORM_VENDOR = testStyle(['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
  48294. var TRANSITION_VENDOR = testStyle(['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']);
  48295. function toCSSVendorPrefix(styleVendor, styleProp) {
  48296. if (!styleVendor) {
  48297. return styleProp;
  48298. }
  48299. styleProp = toCamelCase(styleProp, true);
  48300. var idx = styleVendor.indexOf(styleProp);
  48301. styleVendor = idx === -1 ? styleProp : "-" + styleVendor.slice(0, idx) + "-" + styleProp;
  48302. return styleVendor.toLowerCase();
  48303. }
  48304. function getComputedStyle(el, style) {
  48305. var stl = el.currentStyle || document.defaultView && document.defaultView.getComputedStyle(el);
  48306. return stl ? style ? stl[style] : stl : null;
  48307. }
  48308. /* global document, window */
  48309. var CSS_TRANSITION_VENDOR = toCSSVendorPrefix(TRANSITION_VENDOR, 'transition');
  48310. var CSS_TRANSFORM_VENDOR = toCSSVendorPrefix(TRANSFORM_VENDOR, 'transform'); // eslint-disable-next-line
  48311. var gCssText = "position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;" + (env.transform3dSupported ? 'will-change:transform;' : '');
  48312. function mirrorPos(pos) {
  48313. pos = pos === 'left' ? 'right' : pos === 'right' ? 'left' : pos === 'top' ? 'bottom' : 'top';
  48314. return pos;
  48315. }
  48316. function assembleArrow(tooltipModel, borderColor, arrowPosition) {
  48317. if (!isString(arrowPosition) || arrowPosition === 'inside') {
  48318. return '';
  48319. }
  48320. var backgroundColor = tooltipModel.get('backgroundColor');
  48321. var borderWidth = tooltipModel.get('borderWidth');
  48322. borderColor = convertToColorString(borderColor);
  48323. var arrowPos = mirrorPos(arrowPosition);
  48324. var arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
  48325. var positionStyle = '';
  48326. var transformStyle = CSS_TRANSFORM_VENDOR + ':';
  48327. var rotateDeg;
  48328. if (indexOf(['left', 'right'], arrowPos) > -1) {
  48329. positionStyle += 'top:50%';
  48330. transformStyle += "translateY(-50%) rotate(" + (rotateDeg = arrowPos === 'left' ? -225 : -45) + "deg)";
  48331. } else {
  48332. positionStyle += 'left:50%';
  48333. transformStyle += "translateX(-50%) rotate(" + (rotateDeg = arrowPos === 'top' ? 225 : 45) + "deg)";
  48334. }
  48335. var rotateRadian = rotateDeg * Math.PI / 180;
  48336. var arrowWH = arrowSize + borderWidth;
  48337. var rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * Math.abs(Math.sin(rotateRadian));
  48338. var arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2 + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
  48339. positionStyle += ";" + arrowPos + ":-" + arrowOffset + "px";
  48340. var borderStyle = borderColor + " solid " + borderWidth + "px;";
  48341. var styleCss = ["position:absolute;width:" + arrowSize + "px;height:" + arrowSize + "px;", positionStyle + ";" + transformStyle + ";", "border-bottom:" + borderStyle, "border-right:" + borderStyle, "background-color:" + backgroundColor + ";"];
  48342. return "<div style=\"" + styleCss.join('') + "\"></div>";
  48343. }
  48344. function assembleTransition(duration, onlyFade) {
  48345. var transitionCurve = 'cubic-bezier(0.23,1,0.32,1)';
  48346. var transitionOption = " " + duration / 2 + "s " + transitionCurve;
  48347. var transitionText = "opacity" + transitionOption + ",visibility" + transitionOption;
  48348. if (!onlyFade) {
  48349. transitionOption = " " + duration + "s " + transitionCurve;
  48350. transitionText += env.transformSupported ? "," + CSS_TRANSFORM_VENDOR + transitionOption : ",left" + transitionOption + ",top" + transitionOption;
  48351. }
  48352. return CSS_TRANSITION_VENDOR + ':' + transitionText;
  48353. }
  48354. function assembleTransform(x, y, toString) {
  48355. // If using float on style, the final width of the dom might
  48356. // keep changing slightly while mouse move. So `toFixed(0)` them.
  48357. var x0 = x.toFixed(0) + 'px';
  48358. var y0 = y.toFixed(0) + 'px'; // not support transform, use `left` and `top` instead.
  48359. if (!env.transformSupported) {
  48360. return toString ? "top:" + y0 + ";left:" + x0 + ";" : [['top', y0], ['left', x0]];
  48361. } // support transform
  48362. var is3d = env.transform3dSupported;
  48363. var translate = "translate" + (is3d ? '3d' : '') + "(" + x0 + "," + y0 + (is3d ? ',0' : '') + ")";
  48364. return toString ? 'top:0;left:0;' + CSS_TRANSFORM_VENDOR + ':' + translate + ';' : [['top', 0], ['left', 0], [TRANSFORM_VENDOR, translate]];
  48365. }
  48366. /**
  48367. * @param {Object} textStyle
  48368. * @return {string}
  48369. * @inner
  48370. */
  48371. function assembleFont(textStyleModel) {
  48372. var cssText = [];
  48373. var fontSize = textStyleModel.get('fontSize');
  48374. var color = textStyleModel.getTextColor();
  48375. color && cssText.push('color:' + color);
  48376. cssText.push('font:' + textStyleModel.getFont());
  48377. fontSize // @ts-ignore, leave it to the tooltip refactor.
  48378. && cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  48379. var shadowColor = textStyleModel.get('textShadowColor');
  48380. var shadowBlur = textStyleModel.get('textShadowBlur') || 0;
  48381. var shadowOffsetX = textStyleModel.get('textShadowOffsetX') || 0;
  48382. var shadowOffsetY = textStyleModel.get('textShadowOffsetY') || 0;
  48383. shadowColor && shadowBlur && cssText.push('text-shadow:' + shadowOffsetX + 'px ' + shadowOffsetY + 'px ' + shadowBlur + 'px ' + shadowColor);
  48384. each(['decoration', 'align'], function (name) {
  48385. var val = textStyleModel.get(name);
  48386. val && cssText.push('text-' + name + ':' + val);
  48387. });
  48388. return cssText.join(';');
  48389. }
  48390. function assembleCssText(tooltipModel, enableTransition, onlyFade) {
  48391. var cssText = [];
  48392. var transitionDuration = tooltipModel.get('transitionDuration');
  48393. var backgroundColor = tooltipModel.get('backgroundColor');
  48394. var shadowBlur = tooltipModel.get('shadowBlur');
  48395. var shadowColor = tooltipModel.get('shadowColor');
  48396. var shadowOffsetX = tooltipModel.get('shadowOffsetX');
  48397. var shadowOffsetY = tooltipModel.get('shadowOffsetY');
  48398. var textStyleModel = tooltipModel.getModel('textStyle');
  48399. var padding = getPaddingFromTooltipModel(tooltipModel, 'html');
  48400. var boxShadow = shadowOffsetX + "px " + shadowOffsetY + "px " + shadowBlur + "px " + shadowColor;
  48401. cssText.push('box-shadow:' + boxShadow); // Animation transition. Do not animate when transitionDuration is 0.
  48402. enableTransition && transitionDuration && cssText.push(assembleTransition(transitionDuration, onlyFade));
  48403. if (backgroundColor) {
  48404. if (env.canvasSupported) {
  48405. cssText.push('background-color:' + backgroundColor);
  48406. } else {
  48407. // for ie
  48408. cssText.push('background-color:#' + toHex(backgroundColor));
  48409. cssText.push('filter:alpha(opacity=70)');
  48410. }
  48411. } // Border style
  48412. each(['width', 'color', 'radius'], function (name) {
  48413. var borderName = 'border-' + name;
  48414. var camelCase = toCamelCase(borderName);
  48415. var val = tooltipModel.get(camelCase);
  48416. val != null && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  48417. }); // Text style
  48418. cssText.push(assembleFont(textStyleModel)); // Padding
  48419. if (padding != null) {
  48420. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  48421. }
  48422. return cssText.join(';') + ';';
  48423. } // If not able to make, do not modify the input `out`.
  48424. function makeStyleCoord(out, zr, appendToBody, zrX, zrY) {
  48425. var zrPainter = zr && zr.painter;
  48426. if (appendToBody) {
  48427. var zrViewportRoot = zrPainter && zrPainter.getViewportRoot();
  48428. if (zrViewportRoot) {
  48429. // Some APPs might use scale on body, so we support CSS transform here.
  48430. transformLocalCoord(out, zrViewportRoot, document.body, zrX, zrY);
  48431. }
  48432. } else {
  48433. out[0] = zrX;
  48434. out[1] = zrY; // xy should be based on canvas root. But tooltipContent is
  48435. // the sibling of canvas root. So padding of ec container
  48436. // should be considered here.
  48437. var viewportRootOffset = zrPainter && zrPainter.getViewportRootOffset();
  48438. if (viewportRootOffset) {
  48439. out[0] += viewportRootOffset.offsetLeft;
  48440. out[1] += viewportRootOffset.offsetTop;
  48441. }
  48442. }
  48443. out[2] = out[0] / zr.getWidth();
  48444. out[3] = out[1] / zr.getHeight();
  48445. }
  48446. var TooltipHTMLContent =
  48447. /** @class */
  48448. function () {
  48449. function TooltipHTMLContent(container, api, opt) {
  48450. this._show = false;
  48451. this._styleCoord = [0, 0, 0, 0];
  48452. this._enterable = true;
  48453. this._firstShow = true;
  48454. this._longHide = true;
  48455. if (env.wxa) {
  48456. return null;
  48457. }
  48458. var el = document.createElement('div'); // TODO: TYPE
  48459. el.domBelongToZr = true;
  48460. this.el = el;
  48461. var zr = this._zr = api.getZr();
  48462. var appendToBody = this._appendToBody = opt && opt.appendToBody;
  48463. makeStyleCoord(this._styleCoord, zr, appendToBody, api.getWidth() / 2, api.getHeight() / 2);
  48464. if (appendToBody) {
  48465. document.body.appendChild(el);
  48466. } else {
  48467. container.appendChild(el);
  48468. }
  48469. this._container = container; // FIXME
  48470. // Is it needed to trigger zr event manually if
  48471. // the browser do not support `pointer-events: none`.
  48472. var self = this;
  48473. el.onmouseenter = function () {
  48474. // clear the timeout in hideLater and keep showing tooltip
  48475. if (self._enterable) {
  48476. clearTimeout(self._hideTimeout);
  48477. self._show = true;
  48478. }
  48479. self._inContent = true;
  48480. };
  48481. el.onmousemove = function (e) {
  48482. e = e || window.event;
  48483. if (!self._enterable) {
  48484. // `pointer-events: none` is set to tooltip content div
  48485. // if `enterable` is set as `false`, and `el.onmousemove`
  48486. // can not be triggered. But in browser that do not
  48487. // support `pointer-events`, we need to do this:
  48488. // Try trigger zrender event to avoid mouse
  48489. // in and out shape too frequently
  48490. var handler = zr.handler;
  48491. var zrViewportRoot = zr.painter.getViewportRoot();
  48492. normalizeEvent(zrViewportRoot, e, true);
  48493. handler.dispatch('mousemove', e);
  48494. }
  48495. };
  48496. el.onmouseleave = function () {
  48497. // set `_inContent` to `false` before `hideLater`
  48498. self._inContent = false;
  48499. if (self._enterable) {
  48500. if (self._show) {
  48501. self.hideLater(self._hideDelay);
  48502. }
  48503. }
  48504. };
  48505. }
  48506. /**
  48507. * Update when tooltip is rendered
  48508. */
  48509. TooltipHTMLContent.prototype.update = function (tooltipModel) {
  48510. // FIXME
  48511. // Move this logic to ec main?
  48512. var container = this._container;
  48513. var position = getComputedStyle(container, 'position');
  48514. var domStyle = container.style;
  48515. if (domStyle.position !== 'absolute' && position !== 'absolute') {
  48516. domStyle.position = 'relative';
  48517. } // move tooltip if chart resized
  48518. var alwaysShowContent = tooltipModel.get('alwaysShowContent');
  48519. alwaysShowContent && this._moveIfResized(); // update className
  48520. this.el.className = tooltipModel.get('className') || ''; // Hide the tooltip
  48521. // PENDING
  48522. // this.hide();
  48523. };
  48524. TooltipHTMLContent.prototype.show = function (tooltipModel, nearPointColor) {
  48525. clearTimeout(this._hideTimeout);
  48526. clearTimeout(this._longHideTimeout);
  48527. var el = this.el;
  48528. var style = el.style;
  48529. var styleCoord = this._styleCoord;
  48530. if (!el.innerHTML) {
  48531. style.display = 'none';
  48532. } else {
  48533. style.cssText = gCssText + assembleCssText(tooltipModel, !this._firstShow, this._longHide) // initial transform
  48534. + assembleTransform(styleCoord[0], styleCoord[1], true) + ("border-color:" + convertToColorString(nearPointColor) + ";") + (tooltipModel.get('extraCssText') || '') // If mouse occasionally move over the tooltip, a mouseout event will be
  48535. // triggered by canvas, and cause some unexpectable result like dragging
  48536. // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
  48537. // it. Although it is not supported by IE8~IE10, fortunately it is a rare
  48538. // scenario.
  48539. + (";pointer-events:" + (this._enterable ? 'auto' : 'none'));
  48540. }
  48541. this._show = true;
  48542. this._firstShow = false;
  48543. this._longHide = false;
  48544. };
  48545. TooltipHTMLContent.prototype.setContent = function (content, markers, tooltipModel, borderColor, arrowPosition) {
  48546. var el = this.el;
  48547. if (content == null) {
  48548. el.innerHTML = '';
  48549. return;
  48550. }
  48551. var arrow = '';
  48552. if (isString(arrowPosition) && tooltipModel.get('trigger') === 'item' && !shouldTooltipConfine(tooltipModel)) {
  48553. arrow = assembleArrow(tooltipModel, borderColor, arrowPosition);
  48554. }
  48555. if (isString(content)) {
  48556. el.innerHTML = content + arrow;
  48557. } else if (content) {
  48558. // Clear previous
  48559. el.innerHTML = '';
  48560. if (!isArray(content)) {
  48561. content = [content];
  48562. }
  48563. for (var i = 0; i < content.length; i++) {
  48564. if (isDom(content[i]) && content[i].parentNode !== el) {
  48565. el.appendChild(content[i]);
  48566. }
  48567. } // no arrow if empty
  48568. if (arrow && el.childNodes.length) {
  48569. // no need to create a new parent element, but it's not supported by IE 10 and older.
  48570. // const arrowEl = document.createRange().createContextualFragment(arrow);
  48571. var arrowEl = document.createElement('div');
  48572. arrowEl.innerHTML = arrow;
  48573. el.appendChild(arrowEl);
  48574. }
  48575. }
  48576. };
  48577. TooltipHTMLContent.prototype.setEnterable = function (enterable) {
  48578. this._enterable = enterable;
  48579. };
  48580. TooltipHTMLContent.prototype.getSize = function () {
  48581. var el = this.el;
  48582. return [el.offsetWidth, el.offsetHeight];
  48583. };
  48584. TooltipHTMLContent.prototype.moveTo = function (zrX, zrY) {
  48585. var styleCoord = this._styleCoord;
  48586. makeStyleCoord(styleCoord, this._zr, this._appendToBody, zrX, zrY);
  48587. if (styleCoord[0] != null && styleCoord[1] != null) {
  48588. var style_1 = this.el.style;
  48589. var transforms = assembleTransform(styleCoord[0], styleCoord[1]);
  48590. each(transforms, function (transform) {
  48591. style_1[transform[0]] = transform[1];
  48592. });
  48593. }
  48594. };
  48595. /**
  48596. * when `alwaysShowContent` is true,
  48597. * move the tooltip after chart resized
  48598. */
  48599. TooltipHTMLContent.prototype._moveIfResized = function () {
  48600. // The ratio of left to width
  48601. var ratioX = this._styleCoord[2]; // The ratio of top to height
  48602. var ratioY = this._styleCoord[3];
  48603. this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
  48604. };
  48605. TooltipHTMLContent.prototype.hide = function () {
  48606. var _this = this;
  48607. var style = this.el.style;
  48608. style.visibility = 'hidden';
  48609. style.opacity = '0';
  48610. env.transform3dSupported && (style.willChange = '');
  48611. this._show = false;
  48612. this._longHideTimeout = setTimeout(function () {
  48613. return _this._longHide = true;
  48614. }, 500);
  48615. };
  48616. TooltipHTMLContent.prototype.hideLater = function (time) {
  48617. if (this._show && !(this._inContent && this._enterable)) {
  48618. if (time) {
  48619. this._hideDelay = time; // Set show false to avoid invoke hideLater multiple times
  48620. this._show = false;
  48621. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  48622. } else {
  48623. this.hide();
  48624. }
  48625. }
  48626. };
  48627. TooltipHTMLContent.prototype.isShow = function () {
  48628. return this._show;
  48629. };
  48630. TooltipHTMLContent.prototype.dispose = function () {
  48631. this.el.parentNode.removeChild(this.el);
  48632. };
  48633. return TooltipHTMLContent;
  48634. }();
  48635. var TooltipRichContent =
  48636. /** @class */
  48637. function () {
  48638. function TooltipRichContent(api) {
  48639. this._show = false;
  48640. this._styleCoord = [0, 0, 0, 0];
  48641. this._enterable = true;
  48642. this._zr = api.getZr();
  48643. makeStyleCoord$1(this._styleCoord, this._zr, api.getWidth() / 2, api.getHeight() / 2);
  48644. }
  48645. /**
  48646. * Update when tooltip is rendered
  48647. */
  48648. TooltipRichContent.prototype.update = function (tooltipModel) {
  48649. var alwaysShowContent = tooltipModel.get('alwaysShowContent');
  48650. alwaysShowContent && this._moveIfResized();
  48651. };
  48652. TooltipRichContent.prototype.show = function () {
  48653. if (this._hideTimeout) {
  48654. clearTimeout(this._hideTimeout);
  48655. }
  48656. this.el.show();
  48657. this._show = true;
  48658. };
  48659. /**
  48660. * Set tooltip content
  48661. */
  48662. TooltipRichContent.prototype.setContent = function (content, markupStyleCreator, tooltipModel, borderColor, arrowPosition) {
  48663. if (isObject(content)) {
  48664. throwError("development" !== 'production' ? 'Passing DOM nodes as content is not supported in richText tooltip!' : '');
  48665. }
  48666. if (this.el) {
  48667. this._zr.remove(this.el);
  48668. }
  48669. var textStyleModel = tooltipModel.getModel('textStyle');
  48670. this.el = new ZRText({
  48671. style: {
  48672. rich: markupStyleCreator.richTextStyles,
  48673. text: content,
  48674. lineHeight: 22,
  48675. backgroundColor: tooltipModel.get('backgroundColor'),
  48676. borderRadius: tooltipModel.get('borderRadius'),
  48677. borderWidth: 1,
  48678. borderColor: borderColor,
  48679. shadowColor: tooltipModel.get('shadowColor'),
  48680. shadowBlur: tooltipModel.get('shadowBlur'),
  48681. shadowOffsetX: tooltipModel.get('shadowOffsetX'),
  48682. shadowOffsetY: tooltipModel.get('shadowOffsetY'),
  48683. textShadowColor: textStyleModel.get('textShadowColor'),
  48684. textShadowBlur: textStyleModel.get('textShadowBlur') || 0,
  48685. textShadowOffsetX: textStyleModel.get('textShadowOffsetX') || 0,
  48686. textShadowOffsetY: textStyleModel.get('textShadowOffsetY') || 0,
  48687. fill: tooltipModel.get(['textStyle', 'color']),
  48688. padding: getPaddingFromTooltipModel(tooltipModel, 'richText'),
  48689. verticalAlign: 'top',
  48690. align: 'left'
  48691. },
  48692. z: tooltipModel.get('z')
  48693. });
  48694. this._zr.add(this.el);
  48695. var self = this;
  48696. this.el.on('mouseover', function () {
  48697. // clear the timeout in hideLater and keep showing tooltip
  48698. if (self._enterable) {
  48699. clearTimeout(self._hideTimeout);
  48700. self._show = true;
  48701. }
  48702. self._inContent = true;
  48703. });
  48704. this.el.on('mouseout', function () {
  48705. if (self._enterable) {
  48706. if (self._show) {
  48707. self.hideLater(self._hideDelay);
  48708. }
  48709. }
  48710. self._inContent = false;
  48711. });
  48712. };
  48713. TooltipRichContent.prototype.setEnterable = function (enterable) {
  48714. this._enterable = enterable;
  48715. };
  48716. TooltipRichContent.prototype.getSize = function () {
  48717. var el = this.el;
  48718. var bounding = this.el.getBoundingRect(); // bounding rect does not include shadow. For renderMode richText,
  48719. // if overflow, it will be cut. So calculate them accurately.
  48720. var shadowOuterSize = calcShadowOuterSize(el.style);
  48721. return [bounding.width + shadowOuterSize.left + shadowOuterSize.right, bounding.height + shadowOuterSize.top + shadowOuterSize.bottom];
  48722. };
  48723. TooltipRichContent.prototype.moveTo = function (x, y) {
  48724. var el = this.el;
  48725. if (el) {
  48726. var styleCoord = this._styleCoord;
  48727. makeStyleCoord$1(styleCoord, this._zr, x, y);
  48728. x = styleCoord[0];
  48729. y = styleCoord[1];
  48730. var style = el.style;
  48731. var borderWidth = mathMaxWith0(style.borderWidth || 0);
  48732. var shadowOuterSize = calcShadowOuterSize(style); // rich text x, y do not include border.
  48733. el.x = x + borderWidth + shadowOuterSize.left;
  48734. el.y = y + borderWidth + shadowOuterSize.top;
  48735. el.markRedraw();
  48736. }
  48737. };
  48738. /**
  48739. * when `alwaysShowContent` is true,
  48740. * move the tooltip after chart resized
  48741. */
  48742. TooltipRichContent.prototype._moveIfResized = function () {
  48743. // The ratio of left to width
  48744. var ratioX = this._styleCoord[2]; // The ratio of top to height
  48745. var ratioY = this._styleCoord[3];
  48746. this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
  48747. };
  48748. TooltipRichContent.prototype.hide = function () {
  48749. if (this.el) {
  48750. this.el.hide();
  48751. }
  48752. this._show = false;
  48753. };
  48754. TooltipRichContent.prototype.hideLater = function (time) {
  48755. if (this._show && !(this._inContent && this._enterable)) {
  48756. if (time) {
  48757. this._hideDelay = time; // Set show false to avoid invoke hideLater multiple times
  48758. this._show = false;
  48759. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  48760. } else {
  48761. this.hide();
  48762. }
  48763. }
  48764. };
  48765. TooltipRichContent.prototype.isShow = function () {
  48766. return this._show;
  48767. };
  48768. TooltipRichContent.prototype.dispose = function () {
  48769. this._zr.remove(this.el);
  48770. };
  48771. return TooltipRichContent;
  48772. }();
  48773. function mathMaxWith0(val) {
  48774. return Math.max(0, val);
  48775. }
  48776. function calcShadowOuterSize(style) {
  48777. var shadowBlur = mathMaxWith0(style.shadowBlur || 0);
  48778. var shadowOffsetX = mathMaxWith0(style.shadowOffsetX || 0);
  48779. var shadowOffsetY = mathMaxWith0(style.shadowOffsetY || 0);
  48780. return {
  48781. left: mathMaxWith0(shadowBlur - shadowOffsetX),
  48782. right: mathMaxWith0(shadowBlur + shadowOffsetX),
  48783. top: mathMaxWith0(shadowBlur - shadowOffsetY),
  48784. bottom: mathMaxWith0(shadowBlur + shadowOffsetY)
  48785. };
  48786. }
  48787. function makeStyleCoord$1(out, zr, zrX, zrY) {
  48788. out[0] = zrX;
  48789. out[1] = zrY;
  48790. out[2] = out[0] / zr.getWidth();
  48791. out[3] = out[1] / zr.getHeight();
  48792. }
  48793. var bind$2 = bind;
  48794. var each$7 = each;
  48795. var parsePercent$2 = parsePercent$1;
  48796. var proxyRect = new Rect({
  48797. shape: {
  48798. x: -1,
  48799. y: -1,
  48800. width: 2,
  48801. height: 2
  48802. }
  48803. });
  48804. var TooltipView =
  48805. /** @class */
  48806. function (_super) {
  48807. __extends(TooltipView, _super);
  48808. function TooltipView() {
  48809. var _this = _super !== null && _super.apply(this, arguments) || this;
  48810. _this.type = TooltipView.type;
  48811. return _this;
  48812. }
  48813. TooltipView.prototype.init = function (ecModel, api) {
  48814. if (env.node) {
  48815. return;
  48816. }
  48817. var tooltipModel = ecModel.getComponent('tooltip');
  48818. var renderMode = tooltipModel.get('renderMode');
  48819. this._renderMode = getTooltipRenderMode(renderMode);
  48820. this._tooltipContent = this._renderMode === 'richText' ? new TooltipRichContent(api) : new TooltipHTMLContent(api.getDom(), api, {
  48821. appendToBody: tooltipModel.get('appendToBody', true)
  48822. });
  48823. };
  48824. TooltipView.prototype.render = function (tooltipModel, ecModel, api) {
  48825. if (env.node) {
  48826. return;
  48827. } // Reset
  48828. this.group.removeAll();
  48829. this._tooltipModel = tooltipModel;
  48830. this._ecModel = ecModel;
  48831. this._api = api;
  48832. /**
  48833. * @private
  48834. * @type {boolean}
  48835. */
  48836. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  48837. var tooltipContent = this._tooltipContent;
  48838. tooltipContent.update(tooltipModel);
  48839. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  48840. this._initGlobalListener();
  48841. this._keepShow(); // PENDING
  48842. // `mousemove` event will be triggered very frequently when the mouse moves fast,
  48843. // which causes that the updatePosition was also called very frequently.
  48844. // In Chrome with devtools open and Firefox, tooltip looks lagged and shaked around. See #14695.
  48845. // To avoid the frequent triggering,
  48846. // consider throttling it in 50ms. (the tested result may need to validate)
  48847. this._updatePosition = this._renderMode === 'html' ? throttle(bind$2(this._doUpdatePosition, this), 50) : this._doUpdatePosition;
  48848. };
  48849. TooltipView.prototype._initGlobalListener = function () {
  48850. var tooltipModel = this._tooltipModel;
  48851. var triggerOn = tooltipModel.get('triggerOn');
  48852. register('itemTooltip', this._api, bind$2(function (currTrigger, e, dispatchAction) {
  48853. // If 'none', it is not controlled by mouse totally.
  48854. if (triggerOn !== 'none') {
  48855. if (triggerOn.indexOf(currTrigger) >= 0) {
  48856. this._tryShow(e, dispatchAction);
  48857. } else if (currTrigger === 'leave') {
  48858. this._hide(dispatchAction);
  48859. }
  48860. }
  48861. }, this));
  48862. };
  48863. TooltipView.prototype._keepShow = function () {
  48864. var tooltipModel = this._tooltipModel;
  48865. var ecModel = this._ecModel;
  48866. var api = this._api; // Try to keep the tooltip show when refreshing
  48867. if (this._lastX != null && this._lastY != null // When user is willing to control tooltip totally using API,
  48868. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  48869. // which is not expected.
  48870. && tooltipModel.get('triggerOn') !== 'none') {
  48871. var self_1 = this;
  48872. clearTimeout(this._refreshUpdateTimeout);
  48873. this._refreshUpdateTimeout = setTimeout(function () {
  48874. // Show tip next tick after other charts are rendered
  48875. // In case highlight action has wrong result
  48876. // FIXME
  48877. !api.isDisposed() && self_1.manuallyShowTip(tooltipModel, ecModel, api, {
  48878. x: self_1._lastX,
  48879. y: self_1._lastY,
  48880. dataByCoordSys: self_1._lastDataByCoordSys
  48881. });
  48882. });
  48883. }
  48884. };
  48885. /**
  48886. * Show tip manually by
  48887. * dispatchAction({
  48888. * type: 'showTip',
  48889. * x: 10,
  48890. * y: 10
  48891. * });
  48892. * Or
  48893. * dispatchAction({
  48894. * type: 'showTip',
  48895. * seriesIndex: 0,
  48896. * dataIndex or dataIndexInside or name
  48897. * });
  48898. *
  48899. * TODO Batch
  48900. */
  48901. TooltipView.prototype.manuallyShowTip = function (tooltipModel, ecModel, api, payload) {
  48902. if (payload.from === this.uid || env.node) {
  48903. return;
  48904. }
  48905. var dispatchAction = makeDispatchAction$1(payload, api); // Reset ticket
  48906. this._ticket = ''; // When triggered from axisPointer.
  48907. var dataByCoordSys = payload.dataByCoordSys;
  48908. var cmptRef = findComponentReference(payload, ecModel, api);
  48909. if (cmptRef) {
  48910. var rect = cmptRef.el.getBoundingRect().clone();
  48911. rect.applyTransform(cmptRef.el.transform);
  48912. this._tryShow({
  48913. offsetX: rect.x + rect.width / 2,
  48914. offsetY: rect.y + rect.height / 2,
  48915. target: cmptRef.el,
  48916. position: payload.position,
  48917. // When manully trigger, the mouse is not on the el, so we'd better to
  48918. // position tooltip on the bottom of the el and display arrow is possible.
  48919. positionDefault: 'bottom'
  48920. }, dispatchAction);
  48921. } else if (payload.tooltip && payload.x != null && payload.y != null) {
  48922. var el = proxyRect;
  48923. el.x = payload.x;
  48924. el.y = payload.y;
  48925. el.update();
  48926. getECData(el).tooltipConfig = {
  48927. name: null,
  48928. option: payload.tooltip
  48929. }; // Manually show tooltip while view is not using zrender elements.
  48930. this._tryShow({
  48931. offsetX: payload.x,
  48932. offsetY: payload.y,
  48933. target: el
  48934. }, dispatchAction);
  48935. } else if (dataByCoordSys) {
  48936. this._tryShow({
  48937. offsetX: payload.x,
  48938. offsetY: payload.y,
  48939. position: payload.position,
  48940. dataByCoordSys: dataByCoordSys,
  48941. tooltipOption: payload.tooltipOption
  48942. }, dispatchAction);
  48943. } else if (payload.seriesIndex != null) {
  48944. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  48945. return;
  48946. }
  48947. var pointInfo = findPointFromSeries(payload, ecModel);
  48948. var cx = pointInfo.point[0];
  48949. var cy = pointInfo.point[1];
  48950. if (cx != null && cy != null) {
  48951. this._tryShow({
  48952. offsetX: cx,
  48953. offsetY: cy,
  48954. target: pointInfo.el,
  48955. position: payload.position,
  48956. // When manully trigger, the mouse is not on the el, so we'd better to
  48957. // position tooltip on the bottom of the el and display arrow is possible.
  48958. positionDefault: 'bottom'
  48959. }, dispatchAction);
  48960. }
  48961. } else if (payload.x != null && payload.y != null) {
  48962. // FIXME
  48963. // should wrap dispatchAction like `axisPointer/globalListener` ?
  48964. api.dispatchAction({
  48965. type: 'updateAxisPointer',
  48966. x: payload.x,
  48967. y: payload.y
  48968. });
  48969. this._tryShow({
  48970. offsetX: payload.x,
  48971. offsetY: payload.y,
  48972. position: payload.position,
  48973. target: api.getZr().findHover(payload.x, payload.y).target
  48974. }, dispatchAction);
  48975. }
  48976. };
  48977. TooltipView.prototype.manuallyHideTip = function (tooltipModel, ecModel, api, payload) {
  48978. var tooltipContent = this._tooltipContent;
  48979. if (!this._alwaysShowContent && this._tooltipModel) {
  48980. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  48981. }
  48982. this._lastX = this._lastY = this._lastDataByCoordSys = null;
  48983. if (payload.from !== this.uid) {
  48984. this._hide(makeDispatchAction$1(payload, api));
  48985. }
  48986. }; // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  48987. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  48988. // and tooltip.
  48989. TooltipView.prototype._manuallyAxisShowTip = function (tooltipModel, ecModel, api, payload) {
  48990. var seriesIndex = payload.seriesIndex;
  48991. var dataIndex = payload.dataIndex; // @ts-ignore
  48992. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  48993. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  48994. return;
  48995. }
  48996. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  48997. if (!seriesModel) {
  48998. return;
  48999. }
  49000. var data = seriesModel.getData();
  49001. var tooltipCascadedModel = buildTooltipModel([data.getItemModel(dataIndex), seriesModel, (seriesModel.coordinateSystem || {}).model], this._tooltipModel);
  49002. if (tooltipCascadedModel.get('trigger') !== 'axis') {
  49003. return;
  49004. }
  49005. api.dispatchAction({
  49006. type: 'updateAxisPointer',
  49007. seriesIndex: seriesIndex,
  49008. dataIndex: dataIndex,
  49009. position: payload.position
  49010. });
  49011. return true;
  49012. };
  49013. TooltipView.prototype._tryShow = function (e, dispatchAction) {
  49014. var el = e.target;
  49015. var tooltipModel = this._tooltipModel;
  49016. if (!tooltipModel) {
  49017. return;
  49018. } // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  49019. this._lastX = e.offsetX;
  49020. this._lastY = e.offsetY;
  49021. var dataByCoordSys = e.dataByCoordSys;
  49022. if (dataByCoordSys && dataByCoordSys.length) {
  49023. this._showAxisTooltip(dataByCoordSys, e);
  49024. } else if (el) {
  49025. this._lastDataByCoordSys = null;
  49026. var seriesDispatcher_1;
  49027. var cmptDispatcher_1;
  49028. findEventDispatcher(el, function (target) {
  49029. // Always show item tooltip if mouse is on the element with dataIndex
  49030. if (getECData(target).dataIndex != null) {
  49031. seriesDispatcher_1 = target;
  49032. return true;
  49033. } // Tooltip provided directly. Like legend.
  49034. if (getECData(target).tooltipConfig != null) {
  49035. cmptDispatcher_1 = target;
  49036. return true;
  49037. }
  49038. }, true);
  49039. if (seriesDispatcher_1) {
  49040. this._showSeriesItemTooltip(e, seriesDispatcher_1, dispatchAction);
  49041. } else if (cmptDispatcher_1) {
  49042. this._showComponentItemTooltip(e, cmptDispatcher_1, dispatchAction);
  49043. } else {
  49044. this._hide(dispatchAction);
  49045. }
  49046. } else {
  49047. this._lastDataByCoordSys = null;
  49048. this._hide(dispatchAction);
  49049. }
  49050. };
  49051. TooltipView.prototype._showOrMove = function (tooltipModel, cb) {
  49052. // showDelay is used in this case: tooltip.enterable is set
  49053. // as true. User intent to move mouse into tooltip and click
  49054. // something. `showDelay` makes it easier to enter the content
  49055. // but tooltip do not move immediately.
  49056. var delay = tooltipModel.get('showDelay');
  49057. cb = bind(cb, this);
  49058. clearTimeout(this._showTimout);
  49059. delay > 0 ? this._showTimout = setTimeout(cb, delay) : cb();
  49060. };
  49061. TooltipView.prototype._showAxisTooltip = function (dataByCoordSys, e) {
  49062. var ecModel = this._ecModel;
  49063. var globalTooltipModel = this._tooltipModel;
  49064. var point = [e.offsetX, e.offsetY];
  49065. var singleTooltipModel = buildTooltipModel([e.tooltipOption], globalTooltipModel);
  49066. var renderMode = this._renderMode;
  49067. var cbParamsList = [];
  49068. var articleMarkup = createTooltipMarkup('section', {
  49069. blocks: [],
  49070. noHeader: true
  49071. }); // Only for legacy: `Serise['formatTooltip']` returns a string.
  49072. var markupTextArrLegacy = [];
  49073. var markupStyleCreator = new TooltipMarkupStyleCreator();
  49074. each$7(dataByCoordSys, function (itemCoordSys) {
  49075. each$7(itemCoordSys.dataByAxis, function (axisItem) {
  49076. var axisModel = ecModel.getComponent(axisItem.axisDim + 'Axis', axisItem.axisIndex);
  49077. var axisValue = axisItem.value;
  49078. if (!axisModel || axisValue == null) {
  49079. return;
  49080. }
  49081. var axisValueLabel = getValueLabel(axisValue, axisModel.axis, ecModel, axisItem.seriesDataIndices, axisItem.valueLabelOpt);
  49082. var axisSectionMarkup = createTooltipMarkup('section', {
  49083. header: axisValueLabel,
  49084. noHeader: !trim(axisValueLabel),
  49085. sortBlocks: true,
  49086. blocks: []
  49087. });
  49088. articleMarkup.blocks.push(axisSectionMarkup);
  49089. each(axisItem.seriesDataIndices, function (idxItem) {
  49090. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  49091. var dataIndex = idxItem.dataIndexInside;
  49092. var cbParams = series.getDataParams(dataIndex); // Can't find data.
  49093. if (cbParams.dataIndex < 0) {
  49094. return;
  49095. }
  49096. cbParams.axisDim = axisItem.axisDim;
  49097. cbParams.axisIndex = axisItem.axisIndex;
  49098. cbParams.axisType = axisItem.axisType;
  49099. cbParams.axisId = axisItem.axisId;
  49100. cbParams.axisValue = getAxisRawValue(axisModel.axis, {
  49101. value: axisValue
  49102. });
  49103. cbParams.axisValueLabel = axisValueLabel; // Pre-create marker style for makers. Users can assemble richText
  49104. // text in `formatter` callback and use those markers style.
  49105. cbParams.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(cbParams.color), renderMode);
  49106. var seriesTooltipResult = normalizeTooltipFormatResult(series.formatTooltip(dataIndex, true, null));
  49107. if (seriesTooltipResult.markupFragment) {
  49108. axisSectionMarkup.blocks.push(seriesTooltipResult.markupFragment);
  49109. }
  49110. if (seriesTooltipResult.markupText) {
  49111. markupTextArrLegacy.push(seriesTooltipResult.markupText);
  49112. }
  49113. cbParamsList.push(cbParams);
  49114. });
  49115. });
  49116. }); // In most cases, the second axis is displays upper on the first one.
  49117. // So we reverse it to look better.
  49118. articleMarkup.blocks.reverse();
  49119. markupTextArrLegacy.reverse();
  49120. var positionExpr = e.position;
  49121. var orderMode = singleTooltipModel.get('order');
  49122. var builtMarkupText = buildTooltipMarkup(articleMarkup, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), singleTooltipModel.get('textStyle'));
  49123. builtMarkupText && markupTextArrLegacy.unshift(builtMarkupText);
  49124. var blockBreak = renderMode === 'richText' ? '\n\n' : '<br/>';
  49125. var allMarkupText = markupTextArrLegacy.join(blockBreak);
  49126. this._showOrMove(singleTooltipModel, function () {
  49127. if (this._updateContentNotChangedOnAxis(dataByCoordSys, cbParamsList)) {
  49128. this._updatePosition(singleTooltipModel, positionExpr, point[0], point[1], this._tooltipContent, cbParamsList);
  49129. } else {
  49130. this._showTooltipContent(singleTooltipModel, allMarkupText, cbParamsList, Math.random() + '', point[0], point[1], positionExpr, null, markupStyleCreator);
  49131. }
  49132. }); // Do not trigger events here, because this branch only be entered
  49133. // from dispatchAction.
  49134. };
  49135. TooltipView.prototype._showSeriesItemTooltip = function (e, dispatcher, dispatchAction) {
  49136. var ecModel = this._ecModel;
  49137. var ecData = getECData(dispatcher); // Use dataModel in element if possible
  49138. // Used when mouseover on a element like markPoint or edge
  49139. // In which case, the data is not main data in series.
  49140. var seriesIndex = ecData.seriesIndex;
  49141. var seriesModel = ecModel.getSeriesByIndex(seriesIndex); // For example, graph link.
  49142. var dataModel = ecData.dataModel || seriesModel;
  49143. var dataIndex = ecData.dataIndex;
  49144. var dataType = ecData.dataType;
  49145. var data = dataModel.getData(dataType);
  49146. var renderMode = this._renderMode;
  49147. var positionDefault = e.positionDefault;
  49148. var tooltipModel = buildTooltipModel([data.getItemModel(dataIndex), dataModel, seriesModel && (seriesModel.coordinateSystem || {}).model], this._tooltipModel, positionDefault ? {
  49149. position: positionDefault
  49150. } : null);
  49151. var tooltipTrigger = tooltipModel.get('trigger');
  49152. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  49153. return;
  49154. }
  49155. var params = dataModel.getDataParams(dataIndex, dataType);
  49156. var markupStyleCreator = new TooltipMarkupStyleCreator(); // Pre-create marker style for makers. Users can assemble richText
  49157. // text in `formatter` callback and use those markers style.
  49158. params.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(params.color), renderMode);
  49159. var seriesTooltipResult = normalizeTooltipFormatResult(dataModel.formatTooltip(dataIndex, false, dataType));
  49160. var orderMode = tooltipModel.get('order');
  49161. var markupText = seriesTooltipResult.markupFragment ? buildTooltipMarkup(seriesTooltipResult.markupFragment, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), tooltipModel.get('textStyle')) : seriesTooltipResult.markupText;
  49162. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  49163. this._showOrMove(tooltipModel, function () {
  49164. this._showTooltipContent(tooltipModel, markupText, params, asyncTicket, e.offsetX, e.offsetY, e.position, e.target, markupStyleCreator);
  49165. }); // FIXME
  49166. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  49167. dispatchAction({
  49168. type: 'showTip',
  49169. dataIndexInside: dataIndex,
  49170. dataIndex: data.getRawIndex(dataIndex),
  49171. seriesIndex: seriesIndex,
  49172. from: this.uid
  49173. });
  49174. };
  49175. TooltipView.prototype._showComponentItemTooltip = function (e, el, dispatchAction) {
  49176. var ecData = getECData(el);
  49177. var tooltipConfig = ecData.tooltipConfig;
  49178. var tooltipOpt = tooltipConfig.option || {};
  49179. if (isString(tooltipOpt)) {
  49180. var content = tooltipOpt;
  49181. tooltipOpt = {
  49182. content: content,
  49183. // Fixed formatter
  49184. formatter: content
  49185. };
  49186. }
  49187. var tooltipModelCascade = [tooltipOpt];
  49188. var cmpt = this._ecModel.getComponent(ecData.componentMainType, ecData.componentIndex);
  49189. if (cmpt) {
  49190. tooltipModelCascade.push(cmpt);
  49191. } // In most cases, component tooltip formatter has different params with series tooltip formatter,
  49192. // so that they can not share the same formatter. Since the global tooltip formatter is used for series
  49193. // by convension, we do not use it as the default formatter for component.
  49194. tooltipModelCascade.push({
  49195. formatter: tooltipOpt.content
  49196. });
  49197. var positionDefault = e.positionDefault;
  49198. var subTooltipModel = buildTooltipModel(tooltipModelCascade, this._tooltipModel, positionDefault ? {
  49199. position: positionDefault
  49200. } : null);
  49201. var defaultHtml = subTooltipModel.get('content');
  49202. var asyncTicket = Math.random() + ''; // PENDING: this case do not support richText style yet.
  49203. var markupStyleCreator = new TooltipMarkupStyleCreator(); // Do not check whether `trigger` is 'none' here, because `trigger`
  49204. // only works on coordinate system. In fact, we have not found case
  49205. // that requires setting `trigger` nothing on component yet.
  49206. this._showOrMove(subTooltipModel, function () {
  49207. // Use formatterParams from element defined in component
  49208. // Avoid users modify it.
  49209. var formatterParams = clone(subTooltipModel.get('formatterParams') || {});
  49210. this._showTooltipContent(subTooltipModel, defaultHtml, formatterParams, asyncTicket, e.offsetX, e.offsetY, e.position, el, markupStyleCreator);
  49211. }); // If not dispatch showTip, tip may be hide triggered by axis.
  49212. dispatchAction({
  49213. type: 'showTip',
  49214. from: this.uid
  49215. });
  49216. };
  49217. TooltipView.prototype._showTooltipContent = function ( // Use Model<TooltipOption> insteadof TooltipModel because this model may be from series or other options.
  49218. // Instead of top level tooltip.
  49219. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markupStyleCreator) {
  49220. // Reset ticket
  49221. this._ticket = '';
  49222. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  49223. return;
  49224. }
  49225. var tooltipContent = this._tooltipContent;
  49226. var formatter = tooltipModel.get('formatter');
  49227. positionExpr = positionExpr || tooltipModel.get('position');
  49228. var html = defaultHtml;
  49229. var nearPoint = this._getNearestPoint([x, y], params, tooltipModel.get('trigger'), tooltipModel.get('borderColor'));
  49230. var nearPointColor = nearPoint.color;
  49231. if (formatter) {
  49232. if (isString(formatter)) {
  49233. var useUTC = tooltipModel.ecModel.get('useUTC');
  49234. var params0 = isArray(params) ? params[0] : params;
  49235. var isTimeAxis = params0 && params0.axisType && params0.axisType.indexOf('time') >= 0;
  49236. html = formatter;
  49237. if (isTimeAxis) {
  49238. html = format(params0.axisValue, html, useUTC);
  49239. }
  49240. html = formatTpl(html, params, true);
  49241. } else if (isFunction(formatter)) {
  49242. var callback = bind$2(function (cbTicket, html) {
  49243. if (cbTicket === this._ticket) {
  49244. tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
  49245. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  49246. }
  49247. }, this);
  49248. this._ticket = asyncTicket;
  49249. html = formatter(params, asyncTicket, callback);
  49250. } else {
  49251. html = formatter;
  49252. }
  49253. }
  49254. tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
  49255. tooltipContent.show(tooltipModel, nearPointColor);
  49256. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  49257. };
  49258. TooltipView.prototype._getNearestPoint = function (point, tooltipDataParams, trigger, borderColor) {
  49259. if (trigger === 'axis' || isArray(tooltipDataParams)) {
  49260. return {
  49261. color: borderColor || (this._renderMode === 'html' ? '#fff' : 'none')
  49262. };
  49263. }
  49264. if (!isArray(tooltipDataParams)) {
  49265. return {
  49266. color: borderColor || tooltipDataParams.color || tooltipDataParams.borderColor
  49267. };
  49268. }
  49269. };
  49270. TooltipView.prototype._doUpdatePosition = function (tooltipModel, positionExpr, x, // Mouse x
  49271. y, // Mouse y
  49272. content, params, el) {
  49273. var viewWidth = this._api.getWidth();
  49274. var viewHeight = this._api.getHeight();
  49275. positionExpr = positionExpr || tooltipModel.get('position');
  49276. var contentSize = content.getSize();
  49277. var align = tooltipModel.get('align');
  49278. var vAlign = tooltipModel.get('verticalAlign');
  49279. var rect = el && el.getBoundingRect().clone();
  49280. el && rect.applyTransform(el.transform);
  49281. if (isFunction(positionExpr)) {
  49282. // Callback of position can be an array or a string specify the position
  49283. positionExpr = positionExpr([x, y], params, content.el, rect, {
  49284. viewSize: [viewWidth, viewHeight],
  49285. contentSize: contentSize.slice()
  49286. });
  49287. }
  49288. if (isArray(positionExpr)) {
  49289. x = parsePercent$2(positionExpr[0], viewWidth);
  49290. y = parsePercent$2(positionExpr[1], viewHeight);
  49291. } else if (isObject(positionExpr)) {
  49292. var boxLayoutPosition = positionExpr;
  49293. boxLayoutPosition.width = contentSize[0];
  49294. boxLayoutPosition.height = contentSize[1];
  49295. var layoutRect = getLayoutRect(boxLayoutPosition, {
  49296. width: viewWidth,
  49297. height: viewHeight
  49298. });
  49299. x = layoutRect.x;
  49300. y = layoutRect.y;
  49301. align = null; // When positionExpr is left/top/right/bottom,
  49302. // align and verticalAlign will not work.
  49303. vAlign = null;
  49304. } // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  49305. else if (isString(positionExpr) && el) {
  49306. var pos = calcTooltipPosition(positionExpr, rect, contentSize, tooltipModel.get('borderWidth'));
  49307. x = pos[0];
  49308. y = pos[1];
  49309. } else {
  49310. var pos = refixTooltipPosition(x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20);
  49311. x = pos[0];
  49312. y = pos[1];
  49313. }
  49314. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  49315. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  49316. if (shouldTooltipConfine(tooltipModel)) {
  49317. var pos = confineTooltipPosition(x, y, content, viewWidth, viewHeight);
  49318. x = pos[0];
  49319. y = pos[1];
  49320. }
  49321. content.moveTo(x, y);
  49322. }; // FIXME
  49323. // Should we remove this but leave this to user?
  49324. TooltipView.prototype._updateContentNotChangedOnAxis = function (dataByCoordSys, cbParamsList) {
  49325. var lastCoordSys = this._lastDataByCoordSys;
  49326. var lastCbParamsList = this._cbParamsList;
  49327. var contentNotChanged = !!lastCoordSys && lastCoordSys.length === dataByCoordSys.length;
  49328. contentNotChanged && each$7(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  49329. var lastDataByAxis = lastItemCoordSys.dataByAxis || [];
  49330. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  49331. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  49332. contentNotChanged = contentNotChanged && lastDataByAxis.length === thisDataByAxis.length;
  49333. contentNotChanged && each$7(lastDataByAxis, function (lastItem, indexAxis) {
  49334. var thisItem = thisDataByAxis[indexAxis] || {};
  49335. var lastIndices = lastItem.seriesDataIndices || [];
  49336. var newIndices = thisItem.seriesDataIndices || [];
  49337. contentNotChanged = contentNotChanged && lastItem.value === thisItem.value && lastItem.axisType === thisItem.axisType && lastItem.axisId === thisItem.axisId && lastIndices.length === newIndices.length;
  49338. contentNotChanged && each$7(lastIndices, function (lastIdxItem, j) {
  49339. var newIdxItem = newIndices[j];
  49340. contentNotChanged = contentNotChanged && lastIdxItem.seriesIndex === newIdxItem.seriesIndex && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  49341. }); // check is cbParams data value changed
  49342. lastCbParamsList && each(lastItem.seriesDataIndices, function (idxItem) {
  49343. var seriesIdx = idxItem.seriesIndex;
  49344. var cbParams = cbParamsList[seriesIdx];
  49345. var lastCbParams = lastCbParamsList[seriesIdx];
  49346. if (cbParams && lastCbParams && lastCbParams.data !== cbParams.data) {
  49347. contentNotChanged = false;
  49348. }
  49349. });
  49350. });
  49351. });
  49352. this._lastDataByCoordSys = dataByCoordSys;
  49353. this._cbParamsList = cbParamsList;
  49354. return !!contentNotChanged;
  49355. };
  49356. TooltipView.prototype._hide = function (dispatchAction) {
  49357. // Do not directly hideLater here, because this behavior may be prevented
  49358. // in dispatchAction when showTip is dispatched.
  49359. // FIXME
  49360. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  49361. this._lastDataByCoordSys = null;
  49362. dispatchAction({
  49363. type: 'hideTip',
  49364. from: this.uid
  49365. });
  49366. };
  49367. TooltipView.prototype.dispose = function (ecModel, api) {
  49368. if (env.node) {
  49369. return;
  49370. }
  49371. this._tooltipContent.dispose();
  49372. unregister('itemTooltip', api);
  49373. };
  49374. TooltipView.type = 'tooltip';
  49375. return TooltipView;
  49376. }(ComponentView);
  49377. /**
  49378. * From top to bottom. (the last one should be globalTooltipModel);
  49379. */
  49380. function buildTooltipModel(modelCascade, globalTooltipModel, defaultTooltipOption) {
  49381. // Last is always tooltip model.
  49382. var ecModel = globalTooltipModel.ecModel;
  49383. var resultModel;
  49384. if (defaultTooltipOption) {
  49385. resultModel = new Model(defaultTooltipOption, ecModel, ecModel);
  49386. resultModel = new Model(globalTooltipModel.option, resultModel, ecModel);
  49387. } else {
  49388. resultModel = globalTooltipModel;
  49389. }
  49390. for (var i = modelCascade.length - 1; i >= 0; i--) {
  49391. var tooltipOpt = modelCascade[i];
  49392. if (tooltipOpt) {
  49393. if (tooltipOpt instanceof Model) {
  49394. tooltipOpt = tooltipOpt.get('tooltip', true);
  49395. } // In each data item tooltip can be simply write:
  49396. // {
  49397. // value: 10,
  49398. // tooltip: 'Something you need to know'
  49399. // }
  49400. if (isString(tooltipOpt)) {
  49401. tooltipOpt = {
  49402. formatter: tooltipOpt
  49403. };
  49404. }
  49405. if (tooltipOpt) {
  49406. resultModel = new Model(tooltipOpt, resultModel, ecModel);
  49407. }
  49408. }
  49409. }
  49410. return resultModel;
  49411. }
  49412. function makeDispatchAction$1(payload, api) {
  49413. return payload.dispatchAction || bind(api.dispatchAction, api);
  49414. }
  49415. function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
  49416. var size = content.getSize();
  49417. var width = size[0];
  49418. var height = size[1];
  49419. if (gapH != null) {
  49420. // Add extra 2 pixels for this case:
  49421. // At present the "values" in defaut tooltip are using CSS `float: right`.
  49422. // When the right edge of the tooltip box is on the right side of the
  49423. // viewport, the `float` layout might push the "values" to the second line.
  49424. if (x + width + gapH + 2 > viewWidth) {
  49425. x -= width + gapH;
  49426. } else {
  49427. x += gapH;
  49428. }
  49429. }
  49430. if (gapV != null) {
  49431. if (y + height + gapV > viewHeight) {
  49432. y -= height + gapV;
  49433. } else {
  49434. y += gapV;
  49435. }
  49436. }
  49437. return [x, y];
  49438. }
  49439. function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
  49440. var size = content.getSize();
  49441. var width = size[0];
  49442. var height = size[1];
  49443. x = Math.min(x + width, viewWidth) - width;
  49444. y = Math.min(y + height, viewHeight) - height;
  49445. x = Math.max(x, 0);
  49446. y = Math.max(y, 0);
  49447. return [x, y];
  49448. }
  49449. function calcTooltipPosition(position, rect, contentSize, borderWidth) {
  49450. var domWidth = contentSize[0];
  49451. var domHeight = contentSize[1];
  49452. var offset = Math.ceil(Math.SQRT2 * borderWidth) + 8;
  49453. var x = 0;
  49454. var y = 0;
  49455. var rectWidth = rect.width;
  49456. var rectHeight = rect.height;
  49457. switch (position) {
  49458. case 'inside':
  49459. x = rect.x + rectWidth / 2 - domWidth / 2;
  49460. y = rect.y + rectHeight / 2 - domHeight / 2;
  49461. break;
  49462. case 'top':
  49463. x = rect.x + rectWidth / 2 - domWidth / 2;
  49464. y = rect.y - domHeight - offset;
  49465. break;
  49466. case 'bottom':
  49467. x = rect.x + rectWidth / 2 - domWidth / 2;
  49468. y = rect.y + rectHeight + offset;
  49469. break;
  49470. case 'left':
  49471. x = rect.x - domWidth - offset;
  49472. y = rect.y + rectHeight / 2 - domHeight / 2;
  49473. break;
  49474. case 'right':
  49475. x = rect.x + rectWidth + offset;
  49476. y = rect.y + rectHeight / 2 - domHeight / 2;
  49477. }
  49478. return [x, y];
  49479. }
  49480. function isCenterAlign(align) {
  49481. return align === 'center' || align === 'middle';
  49482. }
  49483. /**
  49484. * Find target component by payload like:
  49485. * ```js
  49486. * { legendId: 'some_id', name: 'xxx' }
  49487. * { toolboxIndex: 1, name: 'xxx' }
  49488. * { geoName: 'some_name', name: 'xxx' }
  49489. * ```
  49490. * PENDING: at present only
  49491. *
  49492. * If not found, return null/undefined.
  49493. */
  49494. function findComponentReference(payload, ecModel, api) {
  49495. var queryOptionMap = preParseFinder(payload).queryOptionMap;
  49496. var componentMainType = queryOptionMap.keys()[0];
  49497. if (!componentMainType || componentMainType === 'series') {
  49498. return;
  49499. }
  49500. var queryResult = queryReferringComponents(ecModel, componentMainType, queryOptionMap.get(componentMainType), {
  49501. useDefault: false,
  49502. enableAll: false,
  49503. enableNone: false
  49504. });
  49505. var model = queryResult.models[0];
  49506. if (!model) {
  49507. return;
  49508. }
  49509. var view = api.getViewOfComponentModel(model);
  49510. var el;
  49511. view.group.traverse(function (subEl) {
  49512. var tooltipConfig = getECData(subEl).tooltipConfig;
  49513. if (tooltipConfig && tooltipConfig.name === payload.name) {
  49514. el = subEl;
  49515. return true; // stop
  49516. }
  49517. });
  49518. if (el) {
  49519. return {
  49520. componentMainType: componentMainType,
  49521. componentIndex: model.componentIndex,
  49522. el: el
  49523. };
  49524. }
  49525. }
  49526. function install$c(registers) {
  49527. use(install$7);
  49528. registers.registerComponentModel(TooltipModel);
  49529. registers.registerComponentView(TooltipView);
  49530. /**
  49531. * @action
  49532. * @property {string} type
  49533. * @property {number} seriesIndex
  49534. * @property {number} dataIndex
  49535. * @property {number} [x]
  49536. * @property {number} [y]
  49537. */
  49538. registers.registerAction({
  49539. type: 'showTip',
  49540. event: 'showTip',
  49541. update: 'tooltip:manuallyShowTip'
  49542. }, // noop
  49543. function () {});
  49544. registers.registerAction({
  49545. type: 'hideTip',
  49546. event: 'hideTip',
  49547. update: 'tooltip:manuallyHideTip'
  49548. }, // noop
  49549. function () {});
  49550. }
  49551. var TitleModel =
  49552. /** @class */
  49553. function (_super) {
  49554. __extends(TitleModel, _super);
  49555. function TitleModel() {
  49556. var _this = _super !== null && _super.apply(this, arguments) || this;
  49557. _this.type = TitleModel.type;
  49558. _this.layoutMode = {
  49559. type: 'box',
  49560. ignoreSize: true
  49561. };
  49562. return _this;
  49563. }
  49564. TitleModel.type = 'title';
  49565. TitleModel.defaultOption = {
  49566. zlevel: 0,
  49567. z: 6,
  49568. show: true,
  49569. text: '',
  49570. target: 'blank',
  49571. subtext: '',
  49572. subtarget: 'blank',
  49573. left: 0,
  49574. top: 0,
  49575. backgroundColor: 'rgba(0,0,0,0)',
  49576. borderColor: '#ccc',
  49577. borderWidth: 0,
  49578. padding: 5,
  49579. itemGap: 10,
  49580. textStyle: {
  49581. fontSize: 18,
  49582. fontWeight: 'bold',
  49583. color: '#464646'
  49584. },
  49585. subtextStyle: {
  49586. fontSize: 12,
  49587. color: '#6E7079'
  49588. }
  49589. };
  49590. return TitleModel;
  49591. }(ComponentModel); // View
  49592. var TitleView =
  49593. /** @class */
  49594. function (_super) {
  49595. __extends(TitleView, _super);
  49596. function TitleView() {
  49597. var _this = _super !== null && _super.apply(this, arguments) || this;
  49598. _this.type = TitleView.type;
  49599. return _this;
  49600. }
  49601. TitleView.prototype.render = function (titleModel, ecModel, api) {
  49602. this.group.removeAll();
  49603. if (!titleModel.get('show')) {
  49604. return;
  49605. }
  49606. var group = this.group;
  49607. var textStyleModel = titleModel.getModel('textStyle');
  49608. var subtextStyleModel = titleModel.getModel('subtextStyle');
  49609. var textAlign = titleModel.get('textAlign');
  49610. var textVerticalAlign = retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
  49611. var textEl = new ZRText({
  49612. style: createTextStyle(textStyleModel, {
  49613. text: titleModel.get('text'),
  49614. fill: textStyleModel.getTextColor()
  49615. }, {
  49616. disableBox: true
  49617. }),
  49618. z2: 10
  49619. });
  49620. var textRect = textEl.getBoundingRect();
  49621. var subText = titleModel.get('subtext');
  49622. var subTextEl = new ZRText({
  49623. style: createTextStyle(subtextStyleModel, {
  49624. text: subText,
  49625. fill: subtextStyleModel.getTextColor(),
  49626. y: textRect.height + titleModel.get('itemGap'),
  49627. verticalAlign: 'top'
  49628. }, {
  49629. disableBox: true
  49630. }),
  49631. z2: 10
  49632. });
  49633. var link = titleModel.get('link');
  49634. var sublink = titleModel.get('sublink');
  49635. var triggerEvent = titleModel.get('triggerEvent', true);
  49636. textEl.silent = !link && !triggerEvent;
  49637. subTextEl.silent = !sublink && !triggerEvent;
  49638. if (link) {
  49639. textEl.on('click', function () {
  49640. windowOpen(link, '_' + titleModel.get('target'));
  49641. });
  49642. }
  49643. if (sublink) {
  49644. subTextEl.on('click', function () {
  49645. windowOpen(sublink, '_' + titleModel.get('subtarget'));
  49646. });
  49647. }
  49648. getECData(textEl).eventData = getECData(subTextEl).eventData = triggerEvent ? {
  49649. componentType: 'title',
  49650. componentIndex: titleModel.componentIndex
  49651. } : null;
  49652. group.add(textEl);
  49653. subText && group.add(subTextEl); // If no subText, but add subTextEl, there will be an empty line.
  49654. var groupRect = group.getBoundingRect();
  49655. var layoutOption = titleModel.getBoxLayoutParams();
  49656. layoutOption.width = groupRect.width;
  49657. layoutOption.height = groupRect.height;
  49658. var layoutRect = getLayoutRect(layoutOption, {
  49659. width: api.getWidth(),
  49660. height: api.getHeight()
  49661. }, titleModel.get('padding')); // Adjust text align based on position
  49662. if (!textAlign) {
  49663. // Align left if title is on the left. center and right is same
  49664. textAlign = titleModel.get('left') || titleModel.get('right'); // @ts-ignore
  49665. if (textAlign === 'middle') {
  49666. textAlign = 'center';
  49667. } // Adjust layout by text align
  49668. if (textAlign === 'right') {
  49669. layoutRect.x += layoutRect.width;
  49670. } else if (textAlign === 'center') {
  49671. layoutRect.x += layoutRect.width / 2;
  49672. }
  49673. }
  49674. if (!textVerticalAlign) {
  49675. textVerticalAlign = titleModel.get('top') || titleModel.get('bottom'); // @ts-ignore
  49676. if (textVerticalAlign === 'center') {
  49677. textVerticalAlign = 'middle';
  49678. }
  49679. if (textVerticalAlign === 'bottom') {
  49680. layoutRect.y += layoutRect.height;
  49681. } else if (textVerticalAlign === 'middle') {
  49682. layoutRect.y += layoutRect.height / 2;
  49683. }
  49684. textVerticalAlign = textVerticalAlign || 'top';
  49685. }
  49686. group.x = layoutRect.x;
  49687. group.y = layoutRect.y;
  49688. group.markRedraw();
  49689. var alignStyle = {
  49690. align: textAlign,
  49691. verticalAlign: textVerticalAlign
  49692. };
  49693. textEl.setStyle(alignStyle);
  49694. subTextEl.setStyle(alignStyle); // Render background
  49695. // Get groupRect again because textAlign has been changed
  49696. groupRect = group.getBoundingRect();
  49697. var padding = layoutRect.margin;
  49698. var style = titleModel.getItemStyle(['color', 'opacity']);
  49699. style.fill = titleModel.get('backgroundColor');
  49700. var rect = new Rect({
  49701. shape: {
  49702. x: groupRect.x - padding[3],
  49703. y: groupRect.y - padding[0],
  49704. width: groupRect.width + padding[1] + padding[3],
  49705. height: groupRect.height + padding[0] + padding[2],
  49706. r: titleModel.get('borderRadius')
  49707. },
  49708. style: style,
  49709. subPixelOptimize: true,
  49710. silent: true
  49711. });
  49712. group.add(rect);
  49713. };
  49714. TitleView.type = 'title';
  49715. return TitleView;
  49716. }(ComponentView);
  49717. function install$d(registers) {
  49718. registers.registerComponentModel(TitleModel);
  49719. registers.registerComponentView(TitleView);
  49720. }
  49721. function checkMarkerInSeries(seriesOpts, markerType) {
  49722. if (!seriesOpts) {
  49723. return false;
  49724. }
  49725. var seriesOptArr = isArray(seriesOpts) ? seriesOpts : [seriesOpts];
  49726. for (var idx = 0; idx < seriesOptArr.length; idx++) {
  49727. if (seriesOptArr[idx] && seriesOptArr[idx][markerType]) {
  49728. return true;
  49729. }
  49730. }
  49731. return false;
  49732. }
  49733. function fillLabel(opt) {
  49734. defaultEmphasis(opt, 'label', ['show']);
  49735. } // { [componentType]: MarkerModel }
  49736. var inner$c = makeInner();
  49737. var MarkerModel =
  49738. /** @class */
  49739. function (_super) {
  49740. __extends(MarkerModel, _super);
  49741. function MarkerModel() {
  49742. var _this = _super !== null && _super.apply(this, arguments) || this;
  49743. _this.type = MarkerModel.type;
  49744. /**
  49745. * If marker model is created by self from series
  49746. */
  49747. _this.createdBySelf = false;
  49748. return _this;
  49749. }
  49750. /**
  49751. * @overrite
  49752. */
  49753. MarkerModel.prototype.init = function (option, parentModel, ecModel) {
  49754. if ("development" !== 'production') {
  49755. if (this.type === 'marker') {
  49756. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  49757. }
  49758. }
  49759. this.mergeDefaultAndTheme(option, ecModel);
  49760. this._mergeOption(option, ecModel, false, true);
  49761. };
  49762. MarkerModel.prototype.isAnimationEnabled = function () {
  49763. if (env.node) {
  49764. return false;
  49765. }
  49766. var hostSeries = this.__hostSeries;
  49767. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  49768. };
  49769. /**
  49770. * @overrite
  49771. */
  49772. MarkerModel.prototype.mergeOption = function (newOpt, ecModel) {
  49773. this._mergeOption(newOpt, ecModel, false, false);
  49774. };
  49775. MarkerModel.prototype._mergeOption = function (newOpt, ecModel, createdBySelf, isInit) {
  49776. var componentType = this.mainType;
  49777. if (!createdBySelf) {
  49778. ecModel.eachSeries(function (seriesModel) {
  49779. // mainType can be markPoint, markLine, markArea
  49780. var markerOpt = seriesModel.get(this.mainType, true);
  49781. var markerModel = inner$c(seriesModel)[componentType];
  49782. if (!markerOpt || !markerOpt.data) {
  49783. inner$c(seriesModel)[componentType] = null;
  49784. return;
  49785. }
  49786. if (!markerModel) {
  49787. if (isInit) {
  49788. // Default label emphasis `position` and `show`
  49789. fillLabel(markerOpt);
  49790. }
  49791. each(markerOpt.data, function (item) {
  49792. // FIXME Overwrite fillLabel method ?
  49793. if (item instanceof Array) {
  49794. fillLabel(item[0]);
  49795. fillLabel(item[1]);
  49796. } else {
  49797. fillLabel(item);
  49798. }
  49799. });
  49800. markerModel = this.createMarkerModelFromSeries(markerOpt, this, ecModel); // markerModel = new ImplementedMarkerModel(
  49801. // markerOpt, this, ecModel
  49802. // );
  49803. extend(markerModel, {
  49804. mainType: this.mainType,
  49805. // Use the same series index and name
  49806. seriesIndex: seriesModel.seriesIndex,
  49807. name: seriesModel.name,
  49808. createdBySelf: true
  49809. });
  49810. markerModel.__hostSeries = seriesModel;
  49811. } else {
  49812. markerModel._mergeOption(markerOpt, ecModel, true);
  49813. }
  49814. inner$c(seriesModel)[componentType] = markerModel;
  49815. }, this);
  49816. }
  49817. };
  49818. MarkerModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  49819. var data = this.getData();
  49820. var value = this.getRawValue(dataIndex);
  49821. var itemName = data.getName(dataIndex);
  49822. return createTooltipMarkup('section', {
  49823. header: this.name,
  49824. blocks: [createTooltipMarkup('nameValue', {
  49825. name: itemName,
  49826. value: value,
  49827. noName: !itemName,
  49828. noValue: value == null
  49829. })]
  49830. });
  49831. };
  49832. MarkerModel.prototype.getData = function () {
  49833. return this._data;
  49834. };
  49835. MarkerModel.prototype.setData = function (data) {
  49836. this._data = data;
  49837. };
  49838. MarkerModel.getMarkerModelFromSeries = function (seriesModel, // Support three types of markers. Strict check.
  49839. componentType) {
  49840. return inner$c(seriesModel)[componentType];
  49841. };
  49842. MarkerModel.type = 'marker';
  49843. MarkerModel.dependencies = ['series', 'grid', 'polar', 'geo'];
  49844. return MarkerModel;
  49845. }(ComponentModel);
  49846. mixin(MarkerModel, DataFormatMixin.prototype);
  49847. var MarkPointModel =
  49848. /** @class */
  49849. function (_super) {
  49850. __extends(MarkPointModel, _super);
  49851. function MarkPointModel() {
  49852. var _this = _super !== null && _super.apply(this, arguments) || this;
  49853. _this.type = MarkPointModel.type;
  49854. return _this;
  49855. }
  49856. MarkPointModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  49857. return new MarkPointModel(markerOpt, masterMarkerModel, ecModel);
  49858. };
  49859. MarkPointModel.type = 'markPoint';
  49860. MarkPointModel.defaultOption = {
  49861. zlevel: 0,
  49862. z: 5,
  49863. symbol: 'pin',
  49864. symbolSize: 50,
  49865. //symbolRotate: 0,
  49866. //symbolOffset: [0, 0]
  49867. tooltip: {
  49868. trigger: 'item'
  49869. },
  49870. label: {
  49871. show: true,
  49872. position: 'inside'
  49873. },
  49874. itemStyle: {
  49875. borderWidth: 2
  49876. },
  49877. emphasis: {
  49878. label: {
  49879. show: true
  49880. }
  49881. }
  49882. };
  49883. return MarkPointModel;
  49884. }(MarkerModel);
  49885. function hasXOrY(item) {
  49886. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  49887. }
  49888. function hasXAndY(item) {
  49889. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  49890. }
  49891. function markerTypeCalculatorWithExtent(markerType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex) {
  49892. var coordArr = [];
  49893. var stacked = isDimensionStacked(data, targetDataDim
  49894. /*, otherDataDim*/
  49895. );
  49896. var calcDataDim = stacked ? data.getCalculationInfo('stackResultDimension') : targetDataDim;
  49897. var value = numCalculate(data, calcDataDim, markerType);
  49898. var dataIndex = data.indicesOfNearest(calcDataDim, value)[0];
  49899. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
  49900. coordArr[targetCoordIndex] = data.get(calcDataDim, dataIndex);
  49901. var coordArrValue = data.get(targetDataDim, dataIndex); // Make it simple, do not visit all stacked value to count precision.
  49902. var precision = getPrecision(data.get(targetDataDim, dataIndex));
  49903. precision = Math.min(precision, 20);
  49904. if (precision >= 0) {
  49905. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  49906. }
  49907. return [coordArr, coordArrValue];
  49908. } // TODO Specified percent
  49909. var markerTypeCalculator = {
  49910. min: curry(markerTypeCalculatorWithExtent, 'min'),
  49911. max: curry(markerTypeCalculatorWithExtent, 'max'),
  49912. average: curry(markerTypeCalculatorWithExtent, 'average'),
  49913. median: curry(markerTypeCalculatorWithExtent, 'median')
  49914. };
  49915. /**
  49916. * Transform markPoint data item to format used in List by do the following
  49917. * 1. Calculate statistic like `max`, `min`, `average`
  49918. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  49919. */
  49920. function dataTransform(seriesModel, item) {
  49921. var data = seriesModel.getData();
  49922. var coordSys = seriesModel.coordinateSystem; // 1. If not specify the position with pixel directly
  49923. // 2. If `coord` is not a data array. Which uses `xAxis`,
  49924. // `yAxis` to specify the coord on each dimension
  49925. // parseFloat first because item.x and item.y can be percent string like '20%'
  49926. if (item && !hasXAndY(item) && !isArray(item.coord) && coordSys) {
  49927. var dims = coordSys.dimensions;
  49928. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel); // Clone the option
  49929. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  49930. item = clone(item);
  49931. if (item.type && markerTypeCalculator[item.type] && axisInfo.baseAxis && axisInfo.valueAxis) {
  49932. var otherCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
  49933. var targetCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
  49934. var coordInfo = markerTypeCalculator[item.type](data, axisInfo.baseDataDim, axisInfo.valueDataDim, otherCoordIndex, targetCoordIndex);
  49935. item.coord = coordInfo[0]; // Force to use the value of calculated value.
  49936. // let item use the value without stack.
  49937. item.value = coordInfo[1];
  49938. } else {
  49939. // FIXME Only has one of xAxis and yAxis.
  49940. var coord = [item.xAxis != null ? item.xAxis : item.radiusAxis, item.yAxis != null ? item.yAxis : item.angleAxis]; // Each coord support max, min, average
  49941. for (var i = 0; i < 2; i++) {
  49942. if (markerTypeCalculator[coord[i]]) {
  49943. coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
  49944. }
  49945. }
  49946. item.coord = coord;
  49947. }
  49948. }
  49949. return item;
  49950. }
  49951. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  49952. var ret = {};
  49953. if (item.valueIndex != null || item.valueDim != null) {
  49954. ret.valueDataDim = item.valueIndex != null ? data.getDimension(item.valueIndex) : item.valueDim;
  49955. ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
  49956. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  49957. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  49958. } else {
  49959. ret.baseAxis = seriesModel.getBaseAxis();
  49960. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  49961. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  49962. ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
  49963. }
  49964. return ret;
  49965. }
  49966. function dataDimToCoordDim(seriesModel, dataDim) {
  49967. var dimItem = seriesModel.getData().getDimensionInfo(dataDim);
  49968. return dimItem && dimItem.coordDim;
  49969. }
  49970. /**
  49971. * Filter data which is out of coordinateSystem range
  49972. * [dataFilter description]
  49973. */
  49974. function dataFilter$1( // Currently only polar and cartesian has containData.
  49975. coordSys, item) {
  49976. // Alwalys return true if there is no coordSys
  49977. return coordSys && coordSys.containData && item.coord && !hasXOrY(item) ? coordSys.containData(item.coord) : true;
  49978. }
  49979. function createMarkerDimValueGetter(inCoordSys, dims) {
  49980. return inCoordSys ? function (item, dimName, dataIndex, dimIndex) {
  49981. var rawVal = dimIndex < 2 // x, y, radius, angle
  49982. ? item.coord && item.coord[dimIndex] : item.value;
  49983. return parseDataValue(rawVal, dims[dimIndex]);
  49984. } : function (item, dimName, dataIndex, dimIndex) {
  49985. return parseDataValue(item.value, dims[dimIndex]);
  49986. };
  49987. }
  49988. function numCalculate(data, valueDataDim, type) {
  49989. if (type === 'average') {
  49990. var sum_1 = 0;
  49991. var count_1 = 0;
  49992. data.each(valueDataDim, function (val, idx) {
  49993. if (!isNaN(val)) {
  49994. sum_1 += val;
  49995. count_1++;
  49996. }
  49997. });
  49998. return sum_1 / count_1;
  49999. } else if (type === 'median') {
  50000. return data.getMedian(valueDataDim);
  50001. } else {
  50002. // max & min
  50003. return data.getDataExtent(valueDataDim)[type === 'max' ? 1 : 0];
  50004. }
  50005. }
  50006. var inner$d = makeInner();
  50007. var MarkerView =
  50008. /** @class */
  50009. function (_super) {
  50010. __extends(MarkerView, _super);
  50011. function MarkerView() {
  50012. var _this = _super !== null && _super.apply(this, arguments) || this;
  50013. _this.type = MarkerView.type;
  50014. return _this;
  50015. }
  50016. MarkerView.prototype.init = function () {
  50017. this.markerGroupMap = createHashMap();
  50018. };
  50019. MarkerView.prototype.render = function (markerModel, ecModel, api) {
  50020. var _this = this;
  50021. var markerGroupMap = this.markerGroupMap;
  50022. markerGroupMap.each(function (item) {
  50023. inner$d(item).keep = false;
  50024. });
  50025. ecModel.eachSeries(function (seriesModel) {
  50026. var markerModel = MarkerModel.getMarkerModelFromSeries(seriesModel, _this.type);
  50027. markerModel && _this.renderSeries(seriesModel, markerModel, ecModel, api);
  50028. });
  50029. markerGroupMap.each(function (item) {
  50030. !inner$d(item).keep && _this.group.remove(item.group);
  50031. });
  50032. };
  50033. MarkerView.prototype.markKeep = function (drawGroup) {
  50034. inner$d(drawGroup).keep = true;
  50035. };
  50036. MarkerView.prototype.blurSeries = function (seriesModelList) {
  50037. var _this = this;
  50038. each(seriesModelList, function (seriesModel) {
  50039. var markerModel = MarkerModel.getMarkerModelFromSeries(seriesModel, _this.type);
  50040. if (markerModel) {
  50041. var data = markerModel.getData();
  50042. data.eachItemGraphicEl(function (el) {
  50043. if (el) {
  50044. enterBlur(el);
  50045. }
  50046. });
  50047. }
  50048. });
  50049. };
  50050. MarkerView.type = 'marker';
  50051. return MarkerView;
  50052. }(ComponentView);
  50053. function updateMarkerLayout(mpData, seriesModel, api) {
  50054. var coordSys = seriesModel.coordinateSystem;
  50055. mpData.each(function (idx) {
  50056. var itemModel = mpData.getItemModel(idx);
  50057. var point;
  50058. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  50059. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  50060. if (!isNaN(xPx) && !isNaN(yPx)) {
  50061. point = [xPx, yPx];
  50062. } // Chart like bar may have there own marker positioning logic
  50063. else if (seriesModel.getMarkerPosition) {
  50064. // Use the getMarkerPoisition
  50065. point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
  50066. } else if (coordSys) {
  50067. var x = mpData.get(coordSys.dimensions[0], idx);
  50068. var y = mpData.get(coordSys.dimensions[1], idx);
  50069. point = coordSys.dataToPoint([x, y]);
  50070. } // Use x, y if has any
  50071. if (!isNaN(xPx)) {
  50072. point[0] = xPx;
  50073. }
  50074. if (!isNaN(yPx)) {
  50075. point[1] = yPx;
  50076. }
  50077. mpData.setItemLayout(idx, point);
  50078. });
  50079. }
  50080. var MarkPointView =
  50081. /** @class */
  50082. function (_super) {
  50083. __extends(MarkPointView, _super);
  50084. function MarkPointView() {
  50085. var _this = _super !== null && _super.apply(this, arguments) || this;
  50086. _this.type = MarkPointView.type;
  50087. return _this;
  50088. }
  50089. MarkPointView.prototype.updateTransform = function (markPointModel, ecModel, api) {
  50090. ecModel.eachSeries(function (seriesModel) {
  50091. var mpModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markPoint');
  50092. if (mpModel) {
  50093. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  50094. this.markerGroupMap.get(seriesModel.id).updateLayout();
  50095. }
  50096. }, this);
  50097. };
  50098. MarkPointView.prototype.renderSeries = function (seriesModel, mpModel, ecModel, api) {
  50099. var coordSys = seriesModel.coordinateSystem;
  50100. var seriesId = seriesModel.id;
  50101. var seriesData = seriesModel.getData();
  50102. var symbolDrawMap = this.markerGroupMap;
  50103. var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
  50104. var mpData = createData(coordSys, seriesModel, mpModel); // FIXME
  50105. mpModel.setData(mpData);
  50106. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  50107. mpData.each(function (idx) {
  50108. var itemModel = mpData.getItemModel(idx);
  50109. var symbol = itemModel.getShallow('symbol');
  50110. var symbolSize = itemModel.getShallow('symbolSize');
  50111. var symbolRotate = itemModel.getShallow('symbolRotate');
  50112. var symbolOffset = itemModel.getShallow('symbolOffset');
  50113. var symbolKeepAspect = itemModel.getShallow('symbolKeepAspect'); // TODO: refactor needed: single data item should not support callback function
  50114. if (isFunction(symbol) || isFunction(symbolSize) || isFunction(symbolRotate) || isFunction(symbolOffset)) {
  50115. var rawIdx = mpModel.getRawValue(idx);
  50116. var dataParams = mpModel.getDataParams(idx);
  50117. if (isFunction(symbol)) {
  50118. symbol = symbol(rawIdx, dataParams);
  50119. }
  50120. if (isFunction(symbolSize)) {
  50121. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  50122. symbolSize = symbolSize(rawIdx, dataParams);
  50123. }
  50124. if (isFunction(symbolRotate)) {
  50125. symbolRotate = symbolRotate(rawIdx, dataParams);
  50126. }
  50127. if (isFunction(symbolOffset)) {
  50128. symbolOffset = symbolOffset(rawIdx, dataParams);
  50129. }
  50130. }
  50131. var style = itemModel.getModel('itemStyle').getItemStyle();
  50132. var color = getVisualFromData(seriesData, 'color');
  50133. if (!style.fill) {
  50134. style.fill = color;
  50135. }
  50136. mpData.setItemVisual(idx, {
  50137. symbol: symbol,
  50138. symbolSize: symbolSize,
  50139. symbolRotate: symbolRotate,
  50140. symbolOffset: symbolOffset,
  50141. symbolKeepAspect: symbolKeepAspect,
  50142. style: style
  50143. });
  50144. }); // TODO Text are wrong
  50145. symbolDraw.updateData(mpData);
  50146. this.group.add(symbolDraw.group); // Set host model for tooltip
  50147. // FIXME
  50148. mpData.eachItemGraphicEl(function (el) {
  50149. el.traverse(function (child) {
  50150. getECData(child).dataModel = mpModel;
  50151. });
  50152. });
  50153. this.markKeep(symbolDraw);
  50154. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  50155. };
  50156. MarkPointView.type = 'markPoint';
  50157. return MarkPointView;
  50158. }(MarkerView);
  50159. function createData(coordSys, seriesModel, mpModel) {
  50160. var coordDimsInfos;
  50161. if (coordSys) {
  50162. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  50163. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  50164. return extend(extend({}, info), {
  50165. name: coordDim,
  50166. // DON'T use ordinalMeta to parse and collect ordinal.
  50167. ordinalMeta: null
  50168. });
  50169. });
  50170. } else {
  50171. coordDimsInfos = [{
  50172. name: 'value',
  50173. type: 'float'
  50174. }];
  50175. }
  50176. var mpData = new SeriesData(coordDimsInfos, mpModel);
  50177. var dataOpt = map(mpModel.get('data'), curry(dataTransform, seriesModel));
  50178. if (coordSys) {
  50179. dataOpt = filter(dataOpt, curry(dataFilter$1, coordSys));
  50180. }
  50181. var dimValueGetter = createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  50182. mpData.initData(dataOpt, null, dimValueGetter);
  50183. return mpData;
  50184. }
  50185. function install$e(registers) {
  50186. registers.registerComponentModel(MarkPointModel);
  50187. registers.registerComponentView(MarkPointView);
  50188. registers.registerPreprocessor(function (opt) {
  50189. if (checkMarkerInSeries(opt.series, 'markPoint')) {
  50190. // Make sure markPoint component is enabled
  50191. opt.markPoint = opt.markPoint || {};
  50192. }
  50193. });
  50194. }
  50195. var MarkLineModel =
  50196. /** @class */
  50197. function (_super) {
  50198. __extends(MarkLineModel, _super);
  50199. function MarkLineModel() {
  50200. var _this = _super !== null && _super.apply(this, arguments) || this;
  50201. _this.type = MarkLineModel.type;
  50202. return _this;
  50203. }
  50204. MarkLineModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  50205. return new MarkLineModel(markerOpt, masterMarkerModel, ecModel);
  50206. };
  50207. MarkLineModel.type = 'markLine';
  50208. MarkLineModel.defaultOption = {
  50209. zlevel: 0,
  50210. z: 5,
  50211. symbol: ['circle', 'arrow'],
  50212. symbolSize: [8, 16],
  50213. //symbolRotate: 0,
  50214. symbolOffset: 0,
  50215. precision: 2,
  50216. tooltip: {
  50217. trigger: 'item'
  50218. },
  50219. label: {
  50220. show: true,
  50221. position: 'end',
  50222. distance: 5
  50223. },
  50224. lineStyle: {
  50225. type: 'dashed'
  50226. },
  50227. emphasis: {
  50228. label: {
  50229. show: true
  50230. },
  50231. lineStyle: {
  50232. width: 3
  50233. }
  50234. },
  50235. animationEasing: 'linear'
  50236. };
  50237. return MarkLineModel;
  50238. }(MarkerModel);
  50239. var straightLineProto = Line.prototype;
  50240. var bezierCurveProto = BezierCurve.prototype;
  50241. var StraightLineShape =
  50242. /** @class */
  50243. function () {
  50244. function StraightLineShape() {
  50245. // Start point
  50246. this.x1 = 0;
  50247. this.y1 = 0; // End point
  50248. this.x2 = 0;
  50249. this.y2 = 0;
  50250. this.percent = 1;
  50251. }
  50252. return StraightLineShape;
  50253. }();
  50254. var CurveShape =
  50255. /** @class */
  50256. function (_super) {
  50257. __extends(CurveShape, _super);
  50258. function CurveShape() {
  50259. return _super !== null && _super.apply(this, arguments) || this;
  50260. }
  50261. return CurveShape;
  50262. }(StraightLineShape);
  50263. function isStraightLine(shape) {
  50264. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  50265. }
  50266. var ECLinePath =
  50267. /** @class */
  50268. function (_super) {
  50269. __extends(ECLinePath, _super);
  50270. function ECLinePath(opts) {
  50271. var _this = _super.call(this, opts) || this;
  50272. _this.type = 'ec-line';
  50273. return _this;
  50274. }
  50275. ECLinePath.prototype.getDefaultStyle = function () {
  50276. return {
  50277. stroke: '#000',
  50278. fill: null
  50279. };
  50280. };
  50281. ECLinePath.prototype.getDefaultShape = function () {
  50282. return new StraightLineShape();
  50283. };
  50284. ECLinePath.prototype.buildPath = function (ctx, shape) {
  50285. if (isStraightLine(shape)) {
  50286. straightLineProto.buildPath.call(this, ctx, shape);
  50287. } else {
  50288. bezierCurveProto.buildPath.call(this, ctx, shape);
  50289. }
  50290. };
  50291. ECLinePath.prototype.pointAt = function (t) {
  50292. if (isStraightLine(this.shape)) {
  50293. return straightLineProto.pointAt.call(this, t);
  50294. } else {
  50295. return bezierCurveProto.pointAt.call(this, t);
  50296. }
  50297. };
  50298. ECLinePath.prototype.tangentAt = function (t) {
  50299. var shape = this.shape;
  50300. var p = isStraightLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : bezierCurveProto.tangentAt.call(this, t);
  50301. return normalize(p, p);
  50302. };
  50303. return ECLinePath;
  50304. }(Path);
  50305. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  50306. function makeSymbolTypeKey(symbolCategory) {
  50307. return '_' + symbolCategory + 'Type';
  50308. }
  50309. /**
  50310. * @inner
  50311. */
  50312. function createSymbol$1(name, lineData, idx) {
  50313. var symbolType = lineData.getItemVisual(idx, name);
  50314. if (!symbolType || symbolType === 'none') {
  50315. return;
  50316. }
  50317. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  50318. var symbolRotate = lineData.getItemVisual(idx, name + 'Rotate');
  50319. var symbolOffset = lineData.getItemVisual(idx, name + 'Offset');
  50320. var symbolKeepAspect = lineData.getItemVisual(idx, name + 'KeepAspect');
  50321. var symbolSizeArr = normalizeSymbolSize(symbolSize);
  50322. var symbolOffsetArr = normalizeSymbolOffset(symbolOffset || 0, symbolSizeArr);
  50323. var symbolPath = createSymbol(symbolType, -symbolSizeArr[0] / 2 + symbolOffsetArr[0], -symbolSizeArr[1] / 2 + symbolOffsetArr[1], symbolSizeArr[0], symbolSizeArr[1], null, symbolKeepAspect);
  50324. symbolPath.__specifiedRotation = symbolRotate == null || isNaN(symbolRotate) ? void 0 : +symbolRotate * Math.PI / 180 || 0;
  50325. symbolPath.name = name;
  50326. return symbolPath;
  50327. }
  50328. function createLine(points) {
  50329. var line = new ECLinePath({
  50330. name: 'line',
  50331. subPixelOptimize: true
  50332. });
  50333. setLinePoints(line.shape, points);
  50334. return line;
  50335. }
  50336. function setLinePoints(targetShape, points) {
  50337. targetShape.x1 = points[0][0];
  50338. targetShape.y1 = points[0][1];
  50339. targetShape.x2 = points[1][0];
  50340. targetShape.y2 = points[1][1];
  50341. targetShape.percent = 1;
  50342. var cp1 = points[2];
  50343. if (cp1) {
  50344. targetShape.cpx1 = cp1[0];
  50345. targetShape.cpy1 = cp1[1];
  50346. } else {
  50347. targetShape.cpx1 = NaN;
  50348. targetShape.cpy1 = NaN;
  50349. }
  50350. }
  50351. var Line$1 =
  50352. /** @class */
  50353. function (_super) {
  50354. __extends(Line, _super);
  50355. function Line(lineData, idx, seriesScope) {
  50356. var _this = _super.call(this) || this;
  50357. _this._createLine(lineData, idx, seriesScope);
  50358. return _this;
  50359. }
  50360. Line.prototype._createLine = function (lineData, idx, seriesScope) {
  50361. var seriesModel = lineData.hostModel;
  50362. var linePoints = lineData.getItemLayout(idx);
  50363. var line = createLine(linePoints);
  50364. line.shape.percent = 0;
  50365. initProps(line, {
  50366. shape: {
  50367. percent: 1
  50368. }
  50369. }, seriesModel, idx);
  50370. this.add(line);
  50371. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  50372. var symbol = createSymbol$1(symbolCategory, lineData, idx); // symbols must added after line to make sure
  50373. // it will be updated after line#update.
  50374. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  50375. this.add(symbol);
  50376. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  50377. }, this);
  50378. this._updateCommonStl(lineData, idx, seriesScope);
  50379. }; // TODO More strict on the List type in parameters?
  50380. Line.prototype.updateData = function (lineData, idx, seriesScope) {
  50381. var seriesModel = lineData.hostModel;
  50382. var line = this.childOfName('line');
  50383. var linePoints = lineData.getItemLayout(idx);
  50384. var target = {
  50385. shape: {}
  50386. };
  50387. setLinePoints(target.shape, linePoints);
  50388. updateProps(line, target, seriesModel, idx);
  50389. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  50390. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  50391. var key = makeSymbolTypeKey(symbolCategory); // Symbol changed
  50392. if (this[key] !== symbolType) {
  50393. this.remove(this.childOfName(symbolCategory));
  50394. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  50395. this.add(symbol);
  50396. }
  50397. this[key] = symbolType;
  50398. }, this);
  50399. this._updateCommonStl(lineData, idx, seriesScope);
  50400. };
  50401. Line.prototype.getLinePath = function () {
  50402. return this.childAt(0);
  50403. };
  50404. Line.prototype._updateCommonStl = function (lineData, idx, seriesScope) {
  50405. var seriesModel = lineData.hostModel;
  50406. var line = this.childOfName('line');
  50407. var emphasisLineStyle = seriesScope && seriesScope.emphasisLineStyle;
  50408. var blurLineStyle = seriesScope && seriesScope.blurLineStyle;
  50409. var selectLineStyle = seriesScope && seriesScope.selectLineStyle;
  50410. var labelStatesModels = seriesScope && seriesScope.labelStatesModels; // Optimization for large dataset
  50411. if (!seriesScope || lineData.hasItemOption) {
  50412. var itemModel = lineData.getItemModel(idx);
  50413. emphasisLineStyle = itemModel.getModel(['emphasis', 'lineStyle']).getLineStyle();
  50414. blurLineStyle = itemModel.getModel(['blur', 'lineStyle']).getLineStyle();
  50415. selectLineStyle = itemModel.getModel(['select', 'lineStyle']).getLineStyle();
  50416. labelStatesModels = getLabelStatesModels(itemModel);
  50417. }
  50418. var lineStyle = lineData.getItemVisual(idx, 'style');
  50419. var visualColor = lineStyle.stroke;
  50420. line.useStyle(lineStyle);
  50421. line.style.fill = null;
  50422. line.style.strokeNoScale = true;
  50423. line.ensureState('emphasis').style = emphasisLineStyle;
  50424. line.ensureState('blur').style = blurLineStyle;
  50425. line.ensureState('select').style = selectLineStyle; // Update symbol
  50426. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  50427. var symbol = this.childOfName(symbolCategory);
  50428. if (symbol) {
  50429. // Share opacity and color with line.
  50430. symbol.setColor(visualColor);
  50431. symbol.style.opacity = lineStyle.opacity;
  50432. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  50433. var stateName = SPECIAL_STATES[i];
  50434. var lineState = line.getState(stateName);
  50435. if (lineState) {
  50436. var lineStateStyle = lineState.style || {};
  50437. var state = symbol.ensureState(stateName);
  50438. var stateStyle = state.style || (state.style = {});
  50439. if (lineStateStyle.stroke != null) {
  50440. stateStyle[symbol.__isEmptyBrush ? 'stroke' : 'fill'] = lineStateStyle.stroke;
  50441. }
  50442. if (lineStateStyle.opacity != null) {
  50443. stateStyle.opacity = lineStateStyle.opacity;
  50444. }
  50445. }
  50446. }
  50447. symbol.markRedraw();
  50448. }
  50449. }, this);
  50450. var rawVal = seriesModel.getRawValue(idx);
  50451. setLabelStyle(this, labelStatesModels, {
  50452. labelDataIndex: idx,
  50453. labelFetcher: {
  50454. getFormattedLabel: function (dataIndex, stateName) {
  50455. return seriesModel.getFormattedLabel(dataIndex, stateName, lineData.dataType);
  50456. }
  50457. },
  50458. inheritColor: visualColor || '#000',
  50459. defaultOpacity: lineStyle.opacity,
  50460. defaultText: (rawVal == null ? lineData.getName(idx) : isFinite(rawVal) ? round(rawVal) : rawVal) + ''
  50461. });
  50462. var label = this.getTextContent(); // Always set `textStyle` even if `normalStyle.text` is null, because default
  50463. // values have to be set on `normalStyle`.
  50464. if (label) {
  50465. var labelNormalModel = labelStatesModels.normal;
  50466. label.__align = label.style.align;
  50467. label.__verticalAlign = label.style.verticalAlign; // 'start', 'middle', 'end'
  50468. label.__position = labelNormalModel.get('position') || 'middle';
  50469. var distance = labelNormalModel.get('distance');
  50470. if (!isArray(distance)) {
  50471. distance = [distance, distance];
  50472. }
  50473. label.__labelDistance = distance;
  50474. }
  50475. this.setTextConfig({
  50476. position: null,
  50477. local: true,
  50478. inside: false // Can't be inside for stroke element.
  50479. });
  50480. enableHoverEmphasis(this);
  50481. };
  50482. Line.prototype.highlight = function () {
  50483. enterEmphasis(this);
  50484. };
  50485. Line.prototype.downplay = function () {
  50486. leaveEmphasis(this);
  50487. };
  50488. Line.prototype.updateLayout = function (lineData, idx) {
  50489. this.setLinePoints(lineData.getItemLayout(idx));
  50490. };
  50491. Line.prototype.setLinePoints = function (points) {
  50492. var linePath = this.childOfName('line');
  50493. setLinePoints(linePath.shape, points);
  50494. linePath.dirty();
  50495. };
  50496. Line.prototype.beforeUpdate = function () {
  50497. var lineGroup = this;
  50498. var symbolFrom = lineGroup.childOfName('fromSymbol');
  50499. var symbolTo = lineGroup.childOfName('toSymbol');
  50500. var label = lineGroup.getTextContent(); // Quick reject
  50501. if (!symbolFrom && !symbolTo && (!label || label.ignore)) {
  50502. return;
  50503. }
  50504. var invScale = 1;
  50505. var parentNode = this.parent;
  50506. while (parentNode) {
  50507. if (parentNode.scaleX) {
  50508. invScale /= parentNode.scaleX;
  50509. }
  50510. parentNode = parentNode.parent;
  50511. }
  50512. var line = lineGroup.childOfName('line'); // If line not changed
  50513. // FIXME Parent scale changed
  50514. if (!this.__dirty && !line.__dirty) {
  50515. return;
  50516. }
  50517. var percent = line.shape.percent;
  50518. var fromPos = line.pointAt(0);
  50519. var toPos = line.pointAt(percent);
  50520. var d = sub([], toPos, fromPos);
  50521. normalize(d, d);
  50522. function setSymbolRotation(symbol, percent) {
  50523. // Fix #12388
  50524. // when symbol is set to be 'arrow' in markLine,
  50525. // symbolRotate value will be ignored, and compulsively use tangent angle.
  50526. // rotate by default if symbol rotation is not specified
  50527. var specifiedRotation = symbol.__specifiedRotation;
  50528. if (specifiedRotation == null) {
  50529. var tangent = line.tangentAt(percent);
  50530. symbol.attr('rotation', (percent === 1 ? -1 : 1) * Math.PI / 2 - Math.atan2(tangent[1], tangent[0]));
  50531. } else {
  50532. symbol.attr('rotation', specifiedRotation);
  50533. }
  50534. }
  50535. if (symbolFrom) {
  50536. symbolFrom.setPosition(fromPos);
  50537. setSymbolRotation(symbolFrom, 0);
  50538. symbolFrom.scaleX = symbolFrom.scaleY = invScale * percent;
  50539. symbolFrom.markRedraw();
  50540. }
  50541. if (symbolTo) {
  50542. symbolTo.setPosition(toPos);
  50543. setSymbolRotation(symbolTo, 1);
  50544. symbolTo.scaleX = symbolTo.scaleY = invScale * percent;
  50545. symbolTo.markRedraw();
  50546. }
  50547. if (label && !label.ignore) {
  50548. label.x = label.y = 0;
  50549. label.originX = label.originY = 0;
  50550. var textAlign = void 0;
  50551. var textVerticalAlign = void 0;
  50552. var distance = label.__labelDistance;
  50553. var distanceX = distance[0] * invScale;
  50554. var distanceY = distance[1] * invScale;
  50555. var halfPercent = percent / 2;
  50556. var tangent = line.tangentAt(halfPercent);
  50557. var n = [tangent[1], -tangent[0]];
  50558. var cp = line.pointAt(halfPercent);
  50559. if (n[1] > 0) {
  50560. n[0] = -n[0];
  50561. n[1] = -n[1];
  50562. }
  50563. var dir = tangent[0] < 0 ? -1 : 1;
  50564. if (label.__position !== 'start' && label.__position !== 'end') {
  50565. var rotation = -Math.atan2(tangent[1], tangent[0]);
  50566. if (toPos[0] < fromPos[0]) {
  50567. rotation = Math.PI + rotation;
  50568. }
  50569. label.rotation = rotation;
  50570. }
  50571. var dy = void 0;
  50572. switch (label.__position) {
  50573. case 'insideStartTop':
  50574. case 'insideMiddleTop':
  50575. case 'insideEndTop':
  50576. case 'middle':
  50577. dy = -distanceY;
  50578. textVerticalAlign = 'bottom';
  50579. break;
  50580. case 'insideStartBottom':
  50581. case 'insideMiddleBottom':
  50582. case 'insideEndBottom':
  50583. dy = distanceY;
  50584. textVerticalAlign = 'top';
  50585. break;
  50586. default:
  50587. dy = 0;
  50588. textVerticalAlign = 'middle';
  50589. }
  50590. switch (label.__position) {
  50591. case 'end':
  50592. label.x = d[0] * distanceX + toPos[0];
  50593. label.y = d[1] * distanceY + toPos[1];
  50594. textAlign = d[0] > 0.8 ? 'left' : d[0] < -0.8 ? 'right' : 'center';
  50595. textVerticalAlign = d[1] > 0.8 ? 'top' : d[1] < -0.8 ? 'bottom' : 'middle';
  50596. break;
  50597. case 'start':
  50598. label.x = -d[0] * distanceX + fromPos[0];
  50599. label.y = -d[1] * distanceY + fromPos[1];
  50600. textAlign = d[0] > 0.8 ? 'right' : d[0] < -0.8 ? 'left' : 'center';
  50601. textVerticalAlign = d[1] > 0.8 ? 'bottom' : d[1] < -0.8 ? 'top' : 'middle';
  50602. break;
  50603. case 'insideStartTop':
  50604. case 'insideStart':
  50605. case 'insideStartBottom':
  50606. label.x = distanceX * dir + fromPos[0];
  50607. label.y = fromPos[1] + dy;
  50608. textAlign = tangent[0] < 0 ? 'right' : 'left';
  50609. label.originX = -distanceX * dir;
  50610. label.originY = -dy;
  50611. break;
  50612. case 'insideMiddleTop':
  50613. case 'insideMiddle':
  50614. case 'insideMiddleBottom':
  50615. case 'middle':
  50616. label.x = cp[0];
  50617. label.y = cp[1] + dy;
  50618. textAlign = 'center';
  50619. label.originY = -dy;
  50620. break;
  50621. case 'insideEndTop':
  50622. case 'insideEnd':
  50623. case 'insideEndBottom':
  50624. label.x = -distanceX * dir + toPos[0];
  50625. label.y = toPos[1] + dy;
  50626. textAlign = tangent[0] >= 0 ? 'right' : 'left';
  50627. label.originX = distanceX * dir;
  50628. label.originY = -dy;
  50629. break;
  50630. }
  50631. label.scaleX = label.scaleY = invScale;
  50632. label.setStyle({
  50633. // Use the user specified text align and baseline first
  50634. verticalAlign: label.__verticalAlign || textVerticalAlign,
  50635. align: label.__align || textAlign
  50636. });
  50637. }
  50638. };
  50639. return Line;
  50640. }(Group);
  50641. var LineDraw =
  50642. /** @class */
  50643. function () {
  50644. function LineDraw(LineCtor) {
  50645. this.group = new Group();
  50646. this._LineCtor = LineCtor || Line$1;
  50647. }
  50648. LineDraw.prototype.isPersistent = function () {
  50649. return true;
  50650. };
  50651. LineDraw.prototype.updateData = function (lineData) {
  50652. var _this = this;
  50653. var lineDraw = this;
  50654. var group = lineDraw.group;
  50655. var oldLineData = lineDraw._lineData;
  50656. lineDraw._lineData = lineData; // There is no oldLineData only when first rendering or switching from
  50657. // stream mode to normal mode, where previous elements should be removed.
  50658. if (!oldLineData) {
  50659. group.removeAll();
  50660. }
  50661. var seriesScope = makeSeriesScope$1(lineData);
  50662. lineData.diff(oldLineData).add(function (idx) {
  50663. _this._doAdd(lineData, idx, seriesScope);
  50664. }).update(function (newIdx, oldIdx) {
  50665. _this._doUpdate(oldLineData, lineData, oldIdx, newIdx, seriesScope);
  50666. }).remove(function (idx) {
  50667. group.remove(oldLineData.getItemGraphicEl(idx));
  50668. }).execute();
  50669. };
  50670. LineDraw.prototype.updateLayout = function () {
  50671. var lineData = this._lineData; // Do not support update layout in incremental mode.
  50672. if (!lineData) {
  50673. return;
  50674. }
  50675. lineData.eachItemGraphicEl(function (el, idx) {
  50676. el.updateLayout(lineData, idx);
  50677. }, this);
  50678. };
  50679. LineDraw.prototype.incrementalPrepareUpdate = function (lineData) {
  50680. this._seriesScope = makeSeriesScope$1(lineData);
  50681. this._lineData = null;
  50682. this.group.removeAll();
  50683. };
  50684. LineDraw.prototype.incrementalUpdate = function (taskParams, lineData) {
  50685. function updateIncrementalAndHover(el) {
  50686. if (!el.isGroup && !isEffectObject(el)) {
  50687. el.incremental = true;
  50688. el.ensureState('emphasis').hoverLayer = true;
  50689. }
  50690. }
  50691. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  50692. var itemLayout = lineData.getItemLayout(idx);
  50693. if (lineNeedsDraw(itemLayout)) {
  50694. var el = new this._LineCtor(lineData, idx, this._seriesScope);
  50695. el.traverse(updateIncrementalAndHover);
  50696. this.group.add(el);
  50697. lineData.setItemGraphicEl(idx, el);
  50698. }
  50699. }
  50700. };
  50701. LineDraw.prototype.remove = function () {
  50702. this.group.removeAll();
  50703. };
  50704. LineDraw.prototype._doAdd = function (lineData, idx, seriesScope) {
  50705. var itemLayout = lineData.getItemLayout(idx);
  50706. if (!lineNeedsDraw(itemLayout)) {
  50707. return;
  50708. }
  50709. var el = new this._LineCtor(lineData, idx, seriesScope);
  50710. lineData.setItemGraphicEl(idx, el);
  50711. this.group.add(el);
  50712. };
  50713. LineDraw.prototype._doUpdate = function (oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  50714. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  50715. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  50716. this.group.remove(itemEl);
  50717. return;
  50718. }
  50719. if (!itemEl) {
  50720. itemEl = new this._LineCtor(newLineData, newIdx, seriesScope);
  50721. } else {
  50722. itemEl.updateData(newLineData, newIdx, seriesScope);
  50723. }
  50724. newLineData.setItemGraphicEl(newIdx, itemEl);
  50725. this.group.add(itemEl);
  50726. };
  50727. return LineDraw;
  50728. }();
  50729. function isEffectObject(el) {
  50730. return el.animators && el.animators.length > 0;
  50731. }
  50732. function makeSeriesScope$1(lineData) {
  50733. var hostModel = lineData.hostModel;
  50734. return {
  50735. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  50736. emphasisLineStyle: hostModel.getModel(['emphasis', 'lineStyle']).getLineStyle(),
  50737. blurLineStyle: hostModel.getModel(['blur', 'lineStyle']).getLineStyle(),
  50738. selectLineStyle: hostModel.getModel(['select', 'lineStyle']).getLineStyle(),
  50739. labelStatesModels: getLabelStatesModels(hostModel)
  50740. };
  50741. }
  50742. function isPointNaN(pt) {
  50743. return isNaN(pt[0]) || isNaN(pt[1]);
  50744. }
  50745. function lineNeedsDraw(pts) {
  50746. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  50747. }
  50748. var inner$e = makeInner();
  50749. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  50750. var data = seriesModel.getData();
  50751. var itemArray;
  50752. if (!isArray(item)) {
  50753. // Special type markLine like 'min', 'max', 'average', 'median'
  50754. var mlType = item.type;
  50755. if (mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median' // In case
  50756. // data: [{
  50757. // yAxis: 10
  50758. // }]
  50759. || item.xAxis != null || item.yAxis != null) {
  50760. var valueAxis = void 0;
  50761. var value = void 0;
  50762. if (item.yAxis != null || item.xAxis != null) {
  50763. valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x');
  50764. value = retrieve(item.yAxis, item.xAxis);
  50765. } else {
  50766. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  50767. valueAxis = axisInfo.valueAxis;
  50768. var valueDataDim = getStackedDimension(data, axisInfo.valueDataDim);
  50769. value = numCalculate(data, valueDataDim, mlType);
  50770. }
  50771. var valueIndex = valueAxis.dim === 'x' ? 0 : 1;
  50772. var baseIndex = 1 - valueIndex; // Normized to 2d data with start and end point
  50773. var mlFrom = clone(item);
  50774. var mlTo = {
  50775. coord: []
  50776. };
  50777. mlFrom.type = null;
  50778. mlFrom.coord = [];
  50779. mlFrom.coord[baseIndex] = -Infinity;
  50780. mlTo.coord[baseIndex] = Infinity;
  50781. var precision = mlModel.get('precision');
  50782. if (precision >= 0 && typeof value === 'number') {
  50783. value = +value.toFixed(Math.min(precision, 20));
  50784. }
  50785. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  50786. itemArray = [mlFrom, mlTo, {
  50787. type: mlType,
  50788. valueIndex: item.valueIndex,
  50789. // Force to use the value of calculated value.
  50790. value: value
  50791. }];
  50792. } else {
  50793. // Invalid data
  50794. if ("development" !== 'production') {
  50795. logError('Invalid markLine data.');
  50796. }
  50797. itemArray = [];
  50798. }
  50799. } else {
  50800. itemArray = item;
  50801. }
  50802. var normalizedItem = [dataTransform(seriesModel, itemArray[0]), dataTransform(seriesModel, itemArray[1]), extend({}, itemArray[2])]; // Avoid line data type is extended by from(to) data type
  50803. normalizedItem[2].type = normalizedItem[2].type || null; // Merge from option and to option into line option
  50804. merge(normalizedItem[2], normalizedItem[0]);
  50805. merge(normalizedItem[2], normalizedItem[1]);
  50806. return normalizedItem;
  50807. };
  50808. function isInifinity(val) {
  50809. return !isNaN(val) && !isFinite(val);
  50810. } // If a markLine has one dim
  50811. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  50812. var otherDimIndex = 1 - dimIndex;
  50813. var dimName = coordSys.dimensions[dimIndex];
  50814. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex]) && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  50815. }
  50816. function markLineFilter(coordSys, item) {
  50817. if (coordSys.type === 'cartesian2d') {
  50818. var fromCoord = item[0].coord;
  50819. var toCoord = item[1].coord; // In case
  50820. // {
  50821. // markLine: {
  50822. // data: [{ yAxis: 2 }]
  50823. // }
  50824. // }
  50825. if (fromCoord && toCoord && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys) || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))) {
  50826. return true;
  50827. }
  50828. }
  50829. return dataFilter$1(coordSys, item[0]) && dataFilter$1(coordSys, item[1]);
  50830. }
  50831. function updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api) {
  50832. var coordSys = seriesModel.coordinateSystem;
  50833. var itemModel = data.getItemModel(idx);
  50834. var point;
  50835. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  50836. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  50837. if (!isNaN(xPx) && !isNaN(yPx)) {
  50838. point = [xPx, yPx];
  50839. } else {
  50840. // Chart like bar may have there own marker positioning logic
  50841. if (seriesModel.getMarkerPosition) {
  50842. // Use the getMarkerPoisition
  50843. point = seriesModel.getMarkerPosition(data.getValues(data.dimensions, idx));
  50844. } else {
  50845. var dims = coordSys.dimensions;
  50846. var x = data.get(dims[0], idx);
  50847. var y = data.get(dims[1], idx);
  50848. point = coordSys.dataToPoint([x, y]);
  50849. } // Expand line to the edge of grid if value on one axis is Inifnity
  50850. // In case
  50851. // markLine: {
  50852. // data: [{
  50853. // yAxis: 2
  50854. // // or
  50855. // type: 'average'
  50856. // }]
  50857. // }
  50858. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  50859. // TODO: TYPE ts@4.1 may still infer it as Axis instead of Axis2D. Not sure if it's a bug
  50860. var xAxis = coordSys.getAxis('x');
  50861. var yAxis = coordSys.getAxis('y');
  50862. var dims = coordSys.dimensions;
  50863. if (isInifinity(data.get(dims[0], idx))) {
  50864. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  50865. } else if (isInifinity(data.get(dims[1], idx))) {
  50866. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  50867. }
  50868. } // Use x, y if has any
  50869. if (!isNaN(xPx)) {
  50870. point[0] = xPx;
  50871. }
  50872. if (!isNaN(yPx)) {
  50873. point[1] = yPx;
  50874. }
  50875. }
  50876. data.setItemLayout(idx, point);
  50877. }
  50878. var MarkLineView =
  50879. /** @class */
  50880. function (_super) {
  50881. __extends(MarkLineView, _super);
  50882. function MarkLineView() {
  50883. var _this = _super !== null && _super.apply(this, arguments) || this;
  50884. _this.type = MarkLineView.type;
  50885. return _this;
  50886. }
  50887. MarkLineView.prototype.updateTransform = function (markLineModel, ecModel, api) {
  50888. ecModel.eachSeries(function (seriesModel) {
  50889. var mlModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markLine');
  50890. if (mlModel) {
  50891. var mlData_1 = mlModel.getData();
  50892. var fromData_1 = inner$e(mlModel).from;
  50893. var toData_1 = inner$e(mlModel).to; // Update visual and layout of from symbol and to symbol
  50894. fromData_1.each(function (idx) {
  50895. updateSingleMarkerEndLayout(fromData_1, idx, true, seriesModel, api);
  50896. updateSingleMarkerEndLayout(toData_1, idx, false, seriesModel, api);
  50897. }); // Update layout of line
  50898. mlData_1.each(function (idx) {
  50899. mlData_1.setItemLayout(idx, [fromData_1.getItemLayout(idx), toData_1.getItemLayout(idx)]);
  50900. });
  50901. this.markerGroupMap.get(seriesModel.id).updateLayout();
  50902. }
  50903. }, this);
  50904. };
  50905. MarkLineView.prototype.renderSeries = function (seriesModel, mlModel, ecModel, api) {
  50906. var coordSys = seriesModel.coordinateSystem;
  50907. var seriesId = seriesModel.id;
  50908. var seriesData = seriesModel.getData();
  50909. var lineDrawMap = this.markerGroupMap;
  50910. var lineDraw = lineDrawMap.get(seriesId) || lineDrawMap.set(seriesId, new LineDraw());
  50911. this.group.add(lineDraw.group);
  50912. var mlData = createList$1(coordSys, seriesModel, mlModel);
  50913. var fromData = mlData.from;
  50914. var toData = mlData.to;
  50915. var lineData = mlData.line;
  50916. inner$e(mlModel).from = fromData;
  50917. inner$e(mlModel).to = toData; // Line data for tooltip and formatter
  50918. mlModel.setData(lineData); // TODO
  50919. // Functionally, `symbolSize` & `symbolOffset` can also be 2D array now.
  50920. // But the related logic and type definition are not finished yet.
  50921. // Finish it if required
  50922. var symbolType = mlModel.get('symbol');
  50923. var symbolSize = mlModel.get('symbolSize');
  50924. var symbolRotate = mlModel.get('symbolRotate');
  50925. var symbolOffset = mlModel.get('symbolOffset'); // TODO: support callback function like markPoint
  50926. if (!isArray(symbolType)) {
  50927. symbolType = [symbolType, symbolType];
  50928. }
  50929. if (!isArray(symbolSize)) {
  50930. symbolSize = [symbolSize, symbolSize];
  50931. }
  50932. if (!isArray(symbolRotate)) {
  50933. symbolRotate = [symbolRotate, symbolRotate];
  50934. }
  50935. if (!isArray(symbolOffset)) {
  50936. symbolOffset = [symbolOffset, symbolOffset];
  50937. } // Update visual and layout of from symbol and to symbol
  50938. mlData.from.each(function (idx) {
  50939. updateDataVisualAndLayout(fromData, idx, true);
  50940. updateDataVisualAndLayout(toData, idx, false);
  50941. }); // Update visual and layout of line
  50942. lineData.each(function (idx) {
  50943. var lineStyle = lineData.getItemModel(idx).getModel('lineStyle').getLineStyle(); // lineData.setItemVisual(idx, {
  50944. // color: lineColor || fromData.getItemVisual(idx, 'color')
  50945. // });
  50946. lineData.setItemLayout(idx, [fromData.getItemLayout(idx), toData.getItemLayout(idx)]);
  50947. if (lineStyle.stroke == null) {
  50948. lineStyle.stroke = fromData.getItemVisual(idx, 'style').fill;
  50949. }
  50950. lineData.setItemVisual(idx, {
  50951. fromSymbolKeepAspect: fromData.getItemVisual(idx, 'symbolKeepAspect'),
  50952. fromSymbolOffset: fromData.getItemVisual(idx, 'symbolOffset'),
  50953. fromSymbolRotate: fromData.getItemVisual(idx, 'symbolRotate'),
  50954. fromSymbolSize: fromData.getItemVisual(idx, 'symbolSize'),
  50955. fromSymbol: fromData.getItemVisual(idx, 'symbol'),
  50956. toSymbolKeepAspect: toData.getItemVisual(idx, 'symbolKeepAspect'),
  50957. toSymbolOffset: toData.getItemVisual(idx, 'symbolOffset'),
  50958. toSymbolRotate: toData.getItemVisual(idx, 'symbolRotate'),
  50959. toSymbolSize: toData.getItemVisual(idx, 'symbolSize'),
  50960. toSymbol: toData.getItemVisual(idx, 'symbol'),
  50961. style: lineStyle
  50962. });
  50963. });
  50964. lineDraw.updateData(lineData); // Set host model for tooltip
  50965. // FIXME
  50966. mlData.line.eachItemGraphicEl(function (el, idx) {
  50967. el.traverse(function (child) {
  50968. getECData(child).dataModel = mlModel;
  50969. });
  50970. });
  50971. function updateDataVisualAndLayout(data, idx, isFrom) {
  50972. var itemModel = data.getItemModel(idx);
  50973. updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api);
  50974. var style = itemModel.getModel('itemStyle').getItemStyle();
  50975. if (style.fill == null) {
  50976. style.fill = getVisualFromData(seriesData, 'color');
  50977. }
  50978. data.setItemVisual(idx, {
  50979. symbolKeepAspect: itemModel.get('symbolKeepAspect'),
  50980. // `0` should be considered as a valid value, so use `retrieve2` instead of `||`
  50981. symbolOffset: retrieve2(itemModel.get('symbolOffset', true), symbolOffset[isFrom ? 0 : 1]),
  50982. symbolRotate: retrieve2(itemModel.get('symbolRotate', true), symbolRotate[isFrom ? 0 : 1]),
  50983. // TODO: when 2d array is supported, it should ignore parent
  50984. symbolSize: retrieve2(itemModel.get('symbolSize'), symbolSize[isFrom ? 0 : 1]),
  50985. symbol: retrieve2(itemModel.get('symbol', true), symbolType[isFrom ? 0 : 1]),
  50986. style: style
  50987. });
  50988. }
  50989. this.markKeep(lineDraw);
  50990. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  50991. };
  50992. MarkLineView.type = 'markLine';
  50993. return MarkLineView;
  50994. }(MarkerView);
  50995. function createList$1(coordSys, seriesModel, mlModel) {
  50996. var coordDimsInfos;
  50997. if (coordSys) {
  50998. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  50999. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  51000. return extend(extend({}, info), {
  51001. name: coordDim,
  51002. // DON'T use ordinalMeta to parse and collect ordinal.
  51003. ordinalMeta: null
  51004. });
  51005. });
  51006. } else {
  51007. coordDimsInfos = [{
  51008. name: 'value',
  51009. type: 'float'
  51010. }];
  51011. }
  51012. var fromData = new SeriesData(coordDimsInfos, mlModel);
  51013. var toData = new SeriesData(coordDimsInfos, mlModel); // No dimensions
  51014. var lineData = new SeriesData([], mlModel);
  51015. var optData = map(mlModel.get('data'), curry(markLineTransform, seriesModel, coordSys, mlModel));
  51016. if (coordSys) {
  51017. optData = filter(optData, curry(markLineFilter, coordSys));
  51018. }
  51019. var dimValueGetter = createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  51020. fromData.initData(map(optData, function (item) {
  51021. return item[0];
  51022. }), null, dimValueGetter);
  51023. toData.initData(map(optData, function (item) {
  51024. return item[1];
  51025. }), null, dimValueGetter);
  51026. lineData.initData(map(optData, function (item) {
  51027. return item[2];
  51028. }));
  51029. lineData.hasItemOption = true;
  51030. return {
  51031. from: fromData,
  51032. to: toData,
  51033. line: lineData
  51034. };
  51035. }
  51036. function install$f(registers) {
  51037. registers.registerComponentModel(MarkLineModel);
  51038. registers.registerComponentView(MarkLineView);
  51039. registers.registerPreprocessor(function (opt) {
  51040. if (checkMarkerInSeries(opt.series, 'markLine')) {
  51041. // Make sure markLine component is enabled
  51042. opt.markLine = opt.markLine || {};
  51043. }
  51044. });
  51045. }
  51046. var MarkAreaModel =
  51047. /** @class */
  51048. function (_super) {
  51049. __extends(MarkAreaModel, _super);
  51050. function MarkAreaModel() {
  51051. var _this = _super !== null && _super.apply(this, arguments) || this;
  51052. _this.type = MarkAreaModel.type;
  51053. return _this;
  51054. }
  51055. MarkAreaModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  51056. return new MarkAreaModel(markerOpt, masterMarkerModel, ecModel);
  51057. };
  51058. MarkAreaModel.type = 'markArea';
  51059. MarkAreaModel.defaultOption = {
  51060. zlevel: 0,
  51061. // PENDING
  51062. z: 1,
  51063. tooltip: {
  51064. trigger: 'item'
  51065. },
  51066. // markArea should fixed on the coordinate system
  51067. animation: false,
  51068. label: {
  51069. show: true,
  51070. position: 'top'
  51071. },
  51072. itemStyle: {
  51073. // color and borderColor default to use color from series
  51074. // color: 'auto'
  51075. // borderColor: 'auto'
  51076. borderWidth: 0
  51077. },
  51078. emphasis: {
  51079. label: {
  51080. show: true,
  51081. position: 'top'
  51082. }
  51083. }
  51084. };
  51085. return MarkAreaModel;
  51086. }(MarkerModel);
  51087. var inner$f = makeInner();
  51088. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  51089. var lt = dataTransform(seriesModel, item[0]);
  51090. var rb = dataTransform(seriesModel, item[1]); // FIXME make sure lt is less than rb
  51091. var ltCoord = lt.coord;
  51092. var rbCoord = rb.coord;
  51093. ltCoord[0] = retrieve(ltCoord[0], -Infinity);
  51094. ltCoord[1] = retrieve(ltCoord[1], -Infinity);
  51095. rbCoord[0] = retrieve(rbCoord[0], Infinity);
  51096. rbCoord[1] = retrieve(rbCoord[1], Infinity); // Merge option into one
  51097. var result = mergeAll([{}, lt, rb]);
  51098. result.coord = [lt.coord, rb.coord];
  51099. result.x0 = lt.x;
  51100. result.y0 = lt.y;
  51101. result.x1 = rb.x;
  51102. result.y1 = rb.y;
  51103. return result;
  51104. };
  51105. function isInifinity$1(val) {
  51106. return !isNaN(val) && !isFinite(val);
  51107. } // If a markArea has one dim
  51108. function ifMarkAreaHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  51109. var otherDimIndex = 1 - dimIndex;
  51110. return isInifinity$1(fromCoord[otherDimIndex]) && isInifinity$1(toCoord[otherDimIndex]);
  51111. }
  51112. function markAreaFilter(coordSys, item) {
  51113. var fromCoord = item.coord[0];
  51114. var toCoord = item.coord[1];
  51115. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  51116. // In case
  51117. // {
  51118. // markArea: {
  51119. // data: [{ yAxis: 2 }]
  51120. // }
  51121. // }
  51122. if (fromCoord && toCoord && (ifMarkAreaHasOnlyDim(1, fromCoord, toCoord) || ifMarkAreaHasOnlyDim(0, fromCoord, toCoord))) {
  51123. return true;
  51124. }
  51125. }
  51126. return dataFilter$1(coordSys, {
  51127. coord: fromCoord,
  51128. x: item.x0,
  51129. y: item.y0
  51130. }) || dataFilter$1(coordSys, {
  51131. coord: toCoord,
  51132. x: item.x1,
  51133. y: item.y1
  51134. });
  51135. } // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  51136. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  51137. var coordSys = seriesModel.coordinateSystem;
  51138. var itemModel = data.getItemModel(idx);
  51139. var point;
  51140. var xPx = parsePercent$1(itemModel.get(dims[0]), api.getWidth());
  51141. var yPx = parsePercent$1(itemModel.get(dims[1]), api.getHeight());
  51142. if (!isNaN(xPx) && !isNaN(yPx)) {
  51143. point = [xPx, yPx];
  51144. } else {
  51145. // Chart like bar may have there own marker positioning logic
  51146. if (seriesModel.getMarkerPosition) {
  51147. // Use the getMarkerPoisition
  51148. point = seriesModel.getMarkerPosition(data.getValues(dims, idx));
  51149. } else {
  51150. var x = data.get(dims[0], idx);
  51151. var y = data.get(dims[1], idx);
  51152. var pt = [x, y];
  51153. coordSys.clampData && coordSys.clampData(pt, pt);
  51154. point = coordSys.dataToPoint(pt, true);
  51155. }
  51156. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  51157. // TODO: TYPE ts@4.1 may still infer it as Axis instead of Axis2D. Not sure if it's a bug
  51158. var xAxis = coordSys.getAxis('x');
  51159. var yAxis = coordSys.getAxis('y');
  51160. var x = data.get(dims[0], idx);
  51161. var y = data.get(dims[1], idx);
  51162. if (isInifinity$1(x)) {
  51163. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  51164. } else if (isInifinity$1(y)) {
  51165. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  51166. }
  51167. } // Use x, y if has any
  51168. if (!isNaN(xPx)) {
  51169. point[0] = xPx;
  51170. }
  51171. if (!isNaN(yPx)) {
  51172. point[1] = yPx;
  51173. }
  51174. }
  51175. return point;
  51176. }
  51177. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  51178. var MarkAreaView =
  51179. /** @class */
  51180. function (_super) {
  51181. __extends(MarkAreaView, _super);
  51182. function MarkAreaView() {
  51183. var _this = _super !== null && _super.apply(this, arguments) || this;
  51184. _this.type = MarkAreaView.type;
  51185. return _this;
  51186. }
  51187. MarkAreaView.prototype.updateTransform = function (markAreaModel, ecModel, api) {
  51188. ecModel.eachSeries(function (seriesModel) {
  51189. var maModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markArea');
  51190. if (maModel) {
  51191. var areaData_1 = maModel.getData();
  51192. areaData_1.each(function (idx) {
  51193. var points = map(dimPermutations, function (dim) {
  51194. return getSingleMarkerEndPoint(areaData_1, idx, dim, seriesModel, api);
  51195. }); // Layout
  51196. areaData_1.setItemLayout(idx, points);
  51197. var el = areaData_1.getItemGraphicEl(idx);
  51198. el.setShape('points', points);
  51199. });
  51200. }
  51201. }, this);
  51202. };
  51203. MarkAreaView.prototype.renderSeries = function (seriesModel, maModel, ecModel, api) {
  51204. var coordSys = seriesModel.coordinateSystem;
  51205. var seriesId = seriesModel.id;
  51206. var seriesData = seriesModel.getData();
  51207. var areaGroupMap = this.markerGroupMap;
  51208. var polygonGroup = areaGroupMap.get(seriesId) || areaGroupMap.set(seriesId, {
  51209. group: new Group()
  51210. });
  51211. this.group.add(polygonGroup.group);
  51212. this.markKeep(polygonGroup);
  51213. var areaData = createList$2(coordSys, seriesModel, maModel); // Line data for tooltip and formatter
  51214. maModel.setData(areaData); // Update visual and layout of line
  51215. areaData.each(function (idx) {
  51216. // Layout
  51217. var points = map(dimPermutations, function (dim) {
  51218. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  51219. });
  51220. var xAxisScale = coordSys.getAxis('x').scale;
  51221. var yAxisScale = coordSys.getAxis('y').scale;
  51222. var xAxisExtent = xAxisScale.getExtent();
  51223. var yAxisExtent = yAxisScale.getExtent();
  51224. var xPointExtent = [xAxisScale.parse(areaData.get('x0', idx)), xAxisScale.parse(areaData.get('x1', idx))];
  51225. var yPointExtent = [yAxisScale.parse(areaData.get('y0', idx)), yAxisScale.parse(areaData.get('y1', idx))];
  51226. asc(xPointExtent);
  51227. asc(yPointExtent);
  51228. var overlapped = !(xAxisExtent[0] > xPointExtent[1] || xAxisExtent[1] < xPointExtent[0] || yAxisExtent[0] > yPointExtent[1] || yAxisExtent[1] < yPointExtent[0]); // If none of the area is inside coordSys, allClipped is set to be true
  51229. // in layout so that label will not be displayed. See #12591
  51230. var allClipped = !overlapped;
  51231. areaData.setItemLayout(idx, {
  51232. points: points,
  51233. allClipped: allClipped
  51234. });
  51235. var style = areaData.getItemModel(idx).getModel('itemStyle').getItemStyle();
  51236. var color$1 = getVisualFromData(seriesData, 'color');
  51237. if (!style.fill) {
  51238. style.fill = color$1;
  51239. if (typeof style.fill === 'string') {
  51240. style.fill = modifyAlpha(style.fill, 0.4);
  51241. }
  51242. }
  51243. if (!style.stroke) {
  51244. style.stroke = color$1;
  51245. } // Visual
  51246. areaData.setItemVisual(idx, 'style', style);
  51247. });
  51248. areaData.diff(inner$f(polygonGroup).data).add(function (idx) {
  51249. var layout = areaData.getItemLayout(idx);
  51250. if (!layout.allClipped) {
  51251. var polygon = new Polygon({
  51252. shape: {
  51253. points: layout.points
  51254. }
  51255. });
  51256. areaData.setItemGraphicEl(idx, polygon);
  51257. polygonGroup.group.add(polygon);
  51258. }
  51259. }).update(function (newIdx, oldIdx) {
  51260. var polygon = inner$f(polygonGroup).data.getItemGraphicEl(oldIdx);
  51261. var layout = areaData.getItemLayout(newIdx);
  51262. if (!layout.allClipped) {
  51263. if (polygon) {
  51264. updateProps(polygon, {
  51265. shape: {
  51266. points: layout.points
  51267. }
  51268. }, maModel, newIdx);
  51269. } else {
  51270. polygon = new Polygon({
  51271. shape: {
  51272. points: layout.points
  51273. }
  51274. });
  51275. }
  51276. areaData.setItemGraphicEl(newIdx, polygon);
  51277. polygonGroup.group.add(polygon);
  51278. } else if (polygon) {
  51279. polygonGroup.group.remove(polygon);
  51280. }
  51281. }).remove(function (idx) {
  51282. var polygon = inner$f(polygonGroup).data.getItemGraphicEl(idx);
  51283. polygonGroup.group.remove(polygon);
  51284. }).execute();
  51285. areaData.eachItemGraphicEl(function (polygon, idx) {
  51286. var itemModel = areaData.getItemModel(idx);
  51287. var style = areaData.getItemVisual(idx, 'style');
  51288. polygon.useStyle(areaData.getItemVisual(idx, 'style'));
  51289. setLabelStyle(polygon, getLabelStatesModels(itemModel), {
  51290. labelFetcher: maModel,
  51291. labelDataIndex: idx,
  51292. defaultText: areaData.getName(idx) || '',
  51293. inheritColor: typeof style.fill === 'string' ? modifyAlpha(style.fill, 1) : '#000'
  51294. });
  51295. setStatesStylesFromModel(polygon, itemModel);
  51296. enableHoverEmphasis(polygon);
  51297. getECData(polygon).dataModel = maModel;
  51298. });
  51299. inner$f(polygonGroup).data = areaData;
  51300. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  51301. };
  51302. MarkAreaView.type = 'markArea';
  51303. return MarkAreaView;
  51304. }(MarkerView);
  51305. function createList$2(coordSys, seriesModel, maModel) {
  51306. var areaData;
  51307. var dataDims;
  51308. var dims = ['x0', 'y0', 'x1', 'y1'];
  51309. if (coordSys) {
  51310. var coordDimsInfos_1 = map(coordSys && coordSys.dimensions, function (coordDim) {
  51311. var data = seriesModel.getData();
  51312. var info = data.getDimensionInfo(data.mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  51313. return extend(extend({}, info), {
  51314. name: coordDim,
  51315. // DON'T use ordinalMeta to parse and collect ordinal.
  51316. ordinalMeta: null
  51317. });
  51318. });
  51319. dataDims = map(dims, function (dim, idx) {
  51320. return {
  51321. name: dim,
  51322. type: coordDimsInfos_1[idx % 2].type
  51323. };
  51324. });
  51325. areaData = new SeriesData(dataDims, maModel);
  51326. } else {
  51327. dataDims = [{
  51328. name: 'value',
  51329. type: 'float'
  51330. }];
  51331. areaData = new SeriesData(dataDims, maModel);
  51332. }
  51333. var optData = map(maModel.get('data'), curry(markAreaTransform, seriesModel, coordSys, maModel));
  51334. if (coordSys) {
  51335. optData = filter(optData, curry(markAreaFilter, coordSys));
  51336. }
  51337. var dimValueGetter = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  51338. // TODO should convert to ParsedValue?
  51339. var rawVal = item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  51340. return parseDataValue(rawVal, dataDims[dimIndex]);
  51341. } : function (item, dimName, dataIndex, dimIndex) {
  51342. return parseDataValue(item.value, dataDims[dimIndex]);
  51343. };
  51344. areaData.initData(optData, null, dimValueGetter);
  51345. areaData.hasItemOption = true;
  51346. return areaData;
  51347. }
  51348. function install$g(registers) {
  51349. registers.registerComponentModel(MarkAreaModel);
  51350. registers.registerComponentView(MarkAreaView);
  51351. registers.registerPreprocessor(function (opt) {
  51352. if (checkMarkerInSeries(opt.series, 'markArea')) {
  51353. // Make sure markArea component is enabled
  51354. opt.markArea = opt.markArea || {};
  51355. }
  51356. });
  51357. }
  51358. var getDefaultSelectorOptions = function (ecModel, type) {
  51359. if (type === 'all') {
  51360. return {
  51361. type: 'all',
  51362. title: ecModel.getLocaleModel().get(['legend', 'selector', 'all'])
  51363. };
  51364. } else if (type === 'inverse') {
  51365. return {
  51366. type: 'inverse',
  51367. title: ecModel.getLocaleModel().get(['legend', 'selector', 'inverse'])
  51368. };
  51369. }
  51370. };
  51371. var LegendModel =
  51372. /** @class */
  51373. function (_super) {
  51374. __extends(LegendModel, _super);
  51375. function LegendModel() {
  51376. var _this = _super !== null && _super.apply(this, arguments) || this;
  51377. _this.type = LegendModel.type;
  51378. _this.layoutMode = {
  51379. type: 'box',
  51380. // legend.width/height are maxWidth/maxHeight actually,
  51381. // whereas realy width/height is calculated by its content.
  51382. // (Setting {left: 10, right: 10} does not make sense).
  51383. // So consider the case:
  51384. // `setOption({legend: {left: 10});`
  51385. // then `setOption({legend: {right: 10});`
  51386. // The previous `left` should be cleared by setting `ignoreSize`.
  51387. ignoreSize: true
  51388. };
  51389. return _this;
  51390. }
  51391. LegendModel.prototype.init = function (option, parentModel, ecModel) {
  51392. this.mergeDefaultAndTheme(option, ecModel);
  51393. option.selected = option.selected || {};
  51394. this._updateSelector(option);
  51395. };
  51396. LegendModel.prototype.mergeOption = function (option, ecModel) {
  51397. _super.prototype.mergeOption.call(this, option, ecModel);
  51398. this._updateSelector(option);
  51399. };
  51400. LegendModel.prototype._updateSelector = function (option) {
  51401. var selector = option.selector;
  51402. var ecModel = this.ecModel;
  51403. if (selector === true) {
  51404. selector = option.selector = ['all', 'inverse'];
  51405. }
  51406. if (isArray(selector)) {
  51407. each(selector, function (item, index) {
  51408. isString(item) && (item = {
  51409. type: item
  51410. });
  51411. selector[index] = merge(item, getDefaultSelectorOptions(ecModel, item.type));
  51412. });
  51413. }
  51414. };
  51415. LegendModel.prototype.optionUpdated = function () {
  51416. this._updateData(this.ecModel);
  51417. var legendData = this._data; // If selectedMode is single, try to select one
  51418. if (legendData[0] && this.get('selectedMode') === 'single') {
  51419. var hasSelected = false; // If has any selected in option.selected
  51420. for (var i = 0; i < legendData.length; i++) {
  51421. var name_1 = legendData[i].get('name');
  51422. if (this.isSelected(name_1)) {
  51423. // Force to unselect others
  51424. this.select(name_1);
  51425. hasSelected = true;
  51426. break;
  51427. }
  51428. } // Try select the first if selectedMode is single
  51429. !hasSelected && this.select(legendData[0].get('name'));
  51430. }
  51431. };
  51432. LegendModel.prototype._updateData = function (ecModel) {
  51433. var potentialData = [];
  51434. var availableNames = [];
  51435. ecModel.eachRawSeries(function (seriesModel) {
  51436. var seriesName = seriesModel.name;
  51437. availableNames.push(seriesName);
  51438. var isPotential;
  51439. if (seriesModel.legendVisualProvider) {
  51440. var provider = seriesModel.legendVisualProvider;
  51441. var names = provider.getAllNames();
  51442. if (!ecModel.isSeriesFiltered(seriesModel)) {
  51443. availableNames = availableNames.concat(names);
  51444. }
  51445. if (names.length) {
  51446. potentialData = potentialData.concat(names);
  51447. } else {
  51448. isPotential = true;
  51449. }
  51450. } else {
  51451. isPotential = true;
  51452. }
  51453. if (isPotential && isNameSpecified(seriesModel)) {
  51454. potentialData.push(seriesModel.name);
  51455. }
  51456. });
  51457. /**
  51458. * @type {Array.<string>}
  51459. * @private
  51460. */
  51461. this._availableNames = availableNames; // If legend.data not specified in option, use availableNames as data,
  51462. // which is convinient for user preparing option.
  51463. var rawData = this.get('data') || potentialData;
  51464. var legendData = map(rawData, function (dataItem) {
  51465. // Can be string or number
  51466. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  51467. dataItem = {
  51468. name: dataItem
  51469. };
  51470. }
  51471. return new Model(dataItem, this, this.ecModel);
  51472. }, this);
  51473. /**
  51474. * @type {Array.<module:echarts/model/Model>}
  51475. * @private
  51476. */
  51477. this._data = legendData;
  51478. };
  51479. LegendModel.prototype.getData = function () {
  51480. return this._data;
  51481. };
  51482. LegendModel.prototype.select = function (name) {
  51483. var selected = this.option.selected;
  51484. var selectedMode = this.get('selectedMode');
  51485. if (selectedMode === 'single') {
  51486. var data = this._data;
  51487. each(data, function (dataItem) {
  51488. selected[dataItem.get('name')] = false;
  51489. });
  51490. }
  51491. selected[name] = true;
  51492. };
  51493. LegendModel.prototype.unSelect = function (name) {
  51494. if (this.get('selectedMode') !== 'single') {
  51495. this.option.selected[name] = false;
  51496. }
  51497. };
  51498. LegendModel.prototype.toggleSelected = function (name) {
  51499. var selected = this.option.selected; // Default is true
  51500. if (!selected.hasOwnProperty(name)) {
  51501. selected[name] = true;
  51502. }
  51503. this[selected[name] ? 'unSelect' : 'select'](name);
  51504. };
  51505. LegendModel.prototype.allSelect = function () {
  51506. var data = this._data;
  51507. var selected = this.option.selected;
  51508. each(data, function (dataItem) {
  51509. selected[dataItem.get('name', true)] = true;
  51510. });
  51511. };
  51512. LegendModel.prototype.inverseSelect = function () {
  51513. var data = this._data;
  51514. var selected = this.option.selected;
  51515. each(data, function (dataItem) {
  51516. var name = dataItem.get('name', true); // Initially, default value is true
  51517. if (!selected.hasOwnProperty(name)) {
  51518. selected[name] = true;
  51519. }
  51520. selected[name] = !selected[name];
  51521. });
  51522. };
  51523. LegendModel.prototype.isSelected = function (name) {
  51524. var selected = this.option.selected;
  51525. return !(selected.hasOwnProperty(name) && !selected[name]) && indexOf(this._availableNames, name) >= 0;
  51526. };
  51527. LegendModel.prototype.getOrient = function () {
  51528. return this.get('orient') === 'vertical' ? {
  51529. index: 1,
  51530. name: 'vertical'
  51531. } : {
  51532. index: 0,
  51533. name: 'horizontal'
  51534. };
  51535. };
  51536. LegendModel.type = 'legend.plain';
  51537. LegendModel.dependencies = ['series'];
  51538. LegendModel.defaultOption = {
  51539. zlevel: 0,
  51540. z: 4,
  51541. show: true,
  51542. orient: 'horizontal',
  51543. left: 'center',
  51544. // right: 'center',
  51545. top: 0,
  51546. // bottom: null,
  51547. align: 'auto',
  51548. backgroundColor: 'rgba(0,0,0,0)',
  51549. borderColor: '#ccc',
  51550. borderRadius: 0,
  51551. borderWidth: 0,
  51552. padding: 5,
  51553. itemGap: 10,
  51554. itemWidth: 25,
  51555. itemHeight: 14,
  51556. symbolRotate: 'inherit',
  51557. symbolKeepAspect: true,
  51558. inactiveColor: '#ccc',
  51559. inactiveBorderColor: '#ccc',
  51560. inactiveBorderWidth: 'auto',
  51561. itemStyle: {
  51562. color: 'inherit',
  51563. opacity: 'inherit',
  51564. borderColor: 'inherit',
  51565. borderWidth: 'auto',
  51566. borderCap: 'inherit',
  51567. borderJoin: 'inherit',
  51568. borderDashOffset: 'inherit',
  51569. borderMiterLimit: 'inherit'
  51570. },
  51571. lineStyle: {
  51572. width: 'auto',
  51573. color: 'inherit',
  51574. inactiveColor: '#ccc',
  51575. inactiveWidth: 2,
  51576. opacity: 'inherit',
  51577. type: 'inherit',
  51578. cap: 'inherit',
  51579. join: 'inherit',
  51580. dashOffset: 'inherit',
  51581. miterLimit: 'inherit'
  51582. },
  51583. textStyle: {
  51584. color: '#333'
  51585. },
  51586. selectedMode: true,
  51587. selector: false,
  51588. selectorLabel: {
  51589. show: true,
  51590. borderRadius: 10,
  51591. padding: [3, 5, 3, 5],
  51592. fontSize: 12,
  51593. fontFamily: 'sans-serif',
  51594. color: '#666',
  51595. borderWidth: 1,
  51596. borderColor: '#666'
  51597. },
  51598. emphasis: {
  51599. selectorLabel: {
  51600. show: true,
  51601. color: '#eee',
  51602. backgroundColor: '#666'
  51603. }
  51604. },
  51605. selectorPosition: 'auto',
  51606. selectorItemGap: 7,
  51607. selectorButtonGap: 10,
  51608. tooltip: {
  51609. show: false
  51610. }
  51611. };
  51612. return LegendModel;
  51613. }(ComponentModel);
  51614. var curry$1 = curry;
  51615. var each$8 = each;
  51616. var Group$1 = Group;
  51617. var LegendView =
  51618. /** @class */
  51619. function (_super) {
  51620. __extends(LegendView, _super);
  51621. function LegendView() {
  51622. var _this = _super !== null && _super.apply(this, arguments) || this;
  51623. _this.type = LegendView.type;
  51624. _this.newlineDisabled = false;
  51625. return _this;
  51626. }
  51627. LegendView.prototype.init = function () {
  51628. this.group.add(this._contentGroup = new Group$1());
  51629. this.group.add(this._selectorGroup = new Group$1());
  51630. this._isFirstRender = true;
  51631. };
  51632. /**
  51633. * @protected
  51634. */
  51635. LegendView.prototype.getContentGroup = function () {
  51636. return this._contentGroup;
  51637. };
  51638. /**
  51639. * @protected
  51640. */
  51641. LegendView.prototype.getSelectorGroup = function () {
  51642. return this._selectorGroup;
  51643. };
  51644. /**
  51645. * @override
  51646. */
  51647. LegendView.prototype.render = function (legendModel, ecModel, api) {
  51648. var isFirstRender = this._isFirstRender;
  51649. this._isFirstRender = false;
  51650. this.resetInner();
  51651. if (!legendModel.get('show', true)) {
  51652. return;
  51653. }
  51654. var itemAlign = legendModel.get('align');
  51655. var orient = legendModel.get('orient');
  51656. if (!itemAlign || itemAlign === 'auto') {
  51657. itemAlign = legendModel.get('left') === 'right' && orient === 'vertical' ? 'right' : 'left';
  51658. } // selector has been normalized to an array in model
  51659. var selector = legendModel.get('selector', true);
  51660. var selectorPosition = legendModel.get('selectorPosition', true);
  51661. if (selector && (!selectorPosition || selectorPosition === 'auto')) {
  51662. selectorPosition = orient === 'horizontal' ? 'end' : 'start';
  51663. }
  51664. this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition); // Perform layout.
  51665. var positionInfo = legendModel.getBoxLayoutParams();
  51666. var viewportSize = {
  51667. width: api.getWidth(),
  51668. height: api.getHeight()
  51669. };
  51670. var padding = legendModel.get('padding');
  51671. var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
  51672. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition); // Place mainGroup, based on the calculated `mainRect`.
  51673. var layoutRect = getLayoutRect(defaults({
  51674. width: mainRect.width,
  51675. height: mainRect.height
  51676. }, positionInfo), viewportSize, padding);
  51677. this.group.x = layoutRect.x - mainRect.x;
  51678. this.group.y = layoutRect.y - mainRect.y;
  51679. this.group.markRedraw(); // Render background after group is layout.
  51680. this.group.add(this._backgroundEl = makeBackground(mainRect, legendModel));
  51681. };
  51682. LegendView.prototype.resetInner = function () {
  51683. this.getContentGroup().removeAll();
  51684. this._backgroundEl && this.group.remove(this._backgroundEl);
  51685. this.getSelectorGroup().removeAll();
  51686. };
  51687. LegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  51688. var contentGroup = this.getContentGroup();
  51689. var legendDrawnMap = createHashMap();
  51690. var selectMode = legendModel.get('selectedMode');
  51691. var excludeSeriesId = [];
  51692. ecModel.eachRawSeries(function (seriesModel) {
  51693. !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
  51694. });
  51695. each$8(legendModel.getData(), function (legendItemModel, dataIndex) {
  51696. var name = legendItemModel.get('name'); // Use empty string or \n as a newline string
  51697. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  51698. var g = new Group$1(); // @ts-ignore
  51699. g.newline = true;
  51700. contentGroup.add(g);
  51701. return;
  51702. } // Representitive series.
  51703. var seriesModel = ecModel.getSeriesByName(name)[0];
  51704. if (legendDrawnMap.get(name)) {
  51705. // Have been drawed
  51706. return;
  51707. } // Legend to control series.
  51708. if (seriesModel) {
  51709. var data = seriesModel.getData();
  51710. var lineVisualStyle = data.getVisual('legendLineStyle') || {};
  51711. var legendIcon = data.getVisual('legendIcon');
  51712. /**
  51713. * `data.getVisual('style')` may be the color from the register
  51714. * in series. For example, for line series,
  51715. */
  51716. var style = data.getVisual('style');
  51717. var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, style, legendIcon, selectMode);
  51718. itemGroup.on('click', curry$1(dispatchSelectAction, name, null, api, excludeSeriesId)).on('mouseover', curry$1(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId)).on('mouseout', curry$1(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
  51719. legendDrawnMap.set(name, true);
  51720. } else {
  51721. // Legend to control data. In pie and funnel.
  51722. ecModel.eachRawSeries(function (seriesModel) {
  51723. // In case multiple series has same data name
  51724. if (legendDrawnMap.get(name)) {
  51725. return;
  51726. }
  51727. if (seriesModel.legendVisualProvider) {
  51728. var provider = seriesModel.legendVisualProvider;
  51729. if (!provider.containName(name)) {
  51730. return;
  51731. }
  51732. var idx = provider.indexOfName(name);
  51733. var style = provider.getItemVisual(idx, 'style');
  51734. var legendIcon = provider.getItemVisual(idx, 'legendIcon');
  51735. var colorArr = parse(style.fill); // Color may be set to transparent in visualMap when data is out of range.
  51736. // Do not show nothing.
  51737. if (colorArr && colorArr[3] === 0) {
  51738. colorArr[3] = 0.2; // TODO color is set to 0, 0, 0, 0. Should show correct RGBA
  51739. style.fill = stringify(colorArr, 'rgba');
  51740. }
  51741. var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, {}, style, legendIcon, selectMode); // FIXME: consider different series has items with the same name.
  51742. itemGroup.on('click', curry$1(dispatchSelectAction, null, name, api, excludeSeriesId)) // Should not specify the series name, consider legend controls
  51743. // more than one pie series.
  51744. .on('mouseover', curry$1(dispatchHighlightAction, null, name, api, excludeSeriesId)).on('mouseout', curry$1(dispatchDownplayAction, null, name, api, excludeSeriesId));
  51745. legendDrawnMap.set(name, true);
  51746. }
  51747. }, this);
  51748. }
  51749. if ("development" !== 'production') {
  51750. if (!legendDrawnMap.get(name)) {
  51751. console.warn(name + ' series not exists. Legend data should be same with series name or data name.');
  51752. }
  51753. }
  51754. }, this);
  51755. if (selector) {
  51756. this._createSelector(selector, legendModel, api, orient, selectorPosition);
  51757. }
  51758. };
  51759. LegendView.prototype._createSelector = function (selector, legendModel, api, orient, selectorPosition) {
  51760. var selectorGroup = this.getSelectorGroup();
  51761. each$8(selector, function createSelectorButton(selectorItem) {
  51762. var type = selectorItem.type;
  51763. var labelText = new ZRText({
  51764. style: {
  51765. x: 0,
  51766. y: 0,
  51767. align: 'center',
  51768. verticalAlign: 'middle'
  51769. },
  51770. onclick: function () {
  51771. api.dispatchAction({
  51772. type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect'
  51773. });
  51774. }
  51775. });
  51776. selectorGroup.add(labelText);
  51777. var labelModel = legendModel.getModel('selectorLabel');
  51778. var emphasisLabelModel = legendModel.getModel(['emphasis', 'selectorLabel']);
  51779. setLabelStyle(labelText, {
  51780. normal: labelModel,
  51781. emphasis: emphasisLabelModel
  51782. }, {
  51783. defaultText: selectorItem.title
  51784. });
  51785. enableHoverEmphasis(labelText);
  51786. });
  51787. };
  51788. LegendView.prototype._createItem = function (seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, itemVisualStyle, legendIcon, selectMode) {
  51789. var drawType = seriesModel.visualDrawType;
  51790. var itemWidth = legendModel.get('itemWidth');
  51791. var itemHeight = legendModel.get('itemHeight');
  51792. var isSelected = legendModel.isSelected(name);
  51793. var iconRotate = legendItemModel.get('symbolRotate');
  51794. var symbolKeepAspect = legendItemModel.get('symbolKeepAspect');
  51795. var legendIconType = legendItemModel.get('icon');
  51796. legendIcon = legendIconType || legendIcon || 'roundRect';
  51797. var style = getLegendStyle(legendIcon, legendItemModel, lineVisualStyle, itemVisualStyle, drawType, isSelected);
  51798. var itemGroup = new Group$1();
  51799. var textStyleModel = legendItemModel.getModel('textStyle');
  51800. if (typeof seriesModel.getLegendIcon === 'function' && (!legendIconType || legendIconType === 'inherit')) {
  51801. // Series has specific way to define legend icon
  51802. itemGroup.add(seriesModel.getLegendIcon({
  51803. itemWidth: itemWidth,
  51804. itemHeight: itemHeight,
  51805. icon: legendIcon,
  51806. iconRotate: iconRotate,
  51807. itemStyle: style.itemStyle,
  51808. lineStyle: style.lineStyle,
  51809. symbolKeepAspect: symbolKeepAspect
  51810. }));
  51811. } else {
  51812. // Use default legend icon policy for most series
  51813. var rotate = legendIconType === 'inherit' && seriesModel.getData().getVisual('symbol') ? iconRotate === 'inherit' ? seriesModel.getData().getVisual('symbolRotate') : iconRotate : 0; // No rotation for no icon
  51814. itemGroup.add(getDefaultLegendIcon({
  51815. itemWidth: itemWidth,
  51816. itemHeight: itemHeight,
  51817. icon: legendIcon,
  51818. iconRotate: rotate,
  51819. itemStyle: style.itemStyle,
  51820. lineStyle: style.lineStyle,
  51821. symbolKeepAspect: symbolKeepAspect
  51822. }));
  51823. }
  51824. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  51825. var textAlign = itemAlign;
  51826. var formatter = legendModel.get('formatter');
  51827. var content = name;
  51828. if (typeof formatter === 'string' && formatter) {
  51829. content = formatter.replace('{name}', name != null ? name : '');
  51830. } else if (typeof formatter === 'function') {
  51831. content = formatter(name);
  51832. }
  51833. var inactiveColor = legendItemModel.get('inactiveColor');
  51834. itemGroup.add(new ZRText({
  51835. style: createTextStyle(textStyleModel, {
  51836. text: content,
  51837. x: textX,
  51838. y: itemHeight / 2,
  51839. fill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  51840. align: textAlign,
  51841. verticalAlign: 'middle'
  51842. })
  51843. })); // Add a invisible rect to increase the area of mouse hover
  51844. var hitRect = new Rect({
  51845. shape: itemGroup.getBoundingRect(),
  51846. invisible: true
  51847. });
  51848. var tooltipModel = legendItemModel.getModel('tooltip');
  51849. if (tooltipModel.get('show')) {
  51850. setTooltipConfig({
  51851. el: hitRect,
  51852. componentModel: legendModel,
  51853. itemName: name,
  51854. itemTooltipOption: tooltipModel.option
  51855. });
  51856. }
  51857. itemGroup.add(hitRect);
  51858. itemGroup.eachChild(function (child) {
  51859. child.silent = true;
  51860. });
  51861. hitRect.silent = !selectMode;
  51862. this.getContentGroup().add(itemGroup);
  51863. enableHoverEmphasis(itemGroup); // @ts-ignore
  51864. itemGroup.__legendDataIndex = dataIndex;
  51865. return itemGroup;
  51866. };
  51867. LegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  51868. var contentGroup = this.getContentGroup();
  51869. var selectorGroup = this.getSelectorGroup(); // Place items in contentGroup.
  51870. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), maxSize.width, maxSize.height);
  51871. var contentRect = contentGroup.getBoundingRect();
  51872. var contentPos = [-contentRect.x, -contentRect.y];
  51873. selectorGroup.markRedraw();
  51874. contentGroup.markRedraw();
  51875. if (selector) {
  51876. // Place buttons in selectorGroup
  51877. box( // Buttons in selectorGroup always layout horizontally
  51878. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  51879. var selectorRect = selectorGroup.getBoundingRect();
  51880. var selectorPos = [-selectorRect.x, -selectorRect.y];
  51881. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  51882. var orientIdx = legendModel.getOrient().index;
  51883. var wh = orientIdx === 0 ? 'width' : 'height';
  51884. var hw = orientIdx === 0 ? 'height' : 'width';
  51885. var yx = orientIdx === 0 ? 'y' : 'x';
  51886. if (selectorPosition === 'end') {
  51887. selectorPos[orientIdx] += contentRect[wh] + selectorButtonGap;
  51888. } else {
  51889. contentPos[orientIdx] += selectorRect[wh] + selectorButtonGap;
  51890. } //Always align selector to content as 'middle'
  51891. selectorPos[1 - orientIdx] += contentRect[hw] / 2 - selectorRect[hw] / 2;
  51892. selectorGroup.x = selectorPos[0];
  51893. selectorGroup.y = selectorPos[1];
  51894. contentGroup.x = contentPos[0];
  51895. contentGroup.y = contentPos[1];
  51896. var mainRect = {
  51897. x: 0,
  51898. y: 0
  51899. };
  51900. mainRect[wh] = contentRect[wh] + selectorButtonGap + selectorRect[wh];
  51901. mainRect[hw] = Math.max(contentRect[hw], selectorRect[hw]);
  51902. mainRect[yx] = Math.min(0, selectorRect[yx] + selectorPos[1 - orientIdx]);
  51903. return mainRect;
  51904. } else {
  51905. contentGroup.x = contentPos[0];
  51906. contentGroup.y = contentPos[1];
  51907. return this.group.getBoundingRect();
  51908. }
  51909. };
  51910. /**
  51911. * @protected
  51912. */
  51913. LegendView.prototype.remove = function () {
  51914. this.getContentGroup().removeAll();
  51915. this._isFirstRender = true;
  51916. };
  51917. LegendView.type = 'legend.plain';
  51918. return LegendView;
  51919. }(ComponentView);
  51920. function getLegendStyle(iconType, legendModel, lineVisualStyle, itemVisualStyle, drawType, isSelected) {
  51921. /**
  51922. * Use series style if is inherit;
  51923. * elsewise, use legend style
  51924. */
  51925. function handleCommonProps(style, visualStyle) {
  51926. // If lineStyle.width is 'auto', it is set to be 2 if series has border
  51927. if (style.lineWidth === 'auto') {
  51928. style.lineWidth = visualStyle.lineWidth > 0 ? 2 : 0;
  51929. }
  51930. each$8(style, function (propVal, propName) {
  51931. style[propName] === 'inherit' && (style[propName] = visualStyle[propName]);
  51932. });
  51933. } // itemStyle
  51934. var legendItemModel = legendModel.getModel('itemStyle');
  51935. var itemStyle = legendItemModel.getItemStyle();
  51936. var iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke';
  51937. itemStyle.decal = itemVisualStyle.decal;
  51938. if (itemStyle.fill === 'inherit') {
  51939. /**
  51940. * Series with visualDrawType as 'stroke' should have
  51941. * series stroke as legend fill
  51942. */
  51943. itemStyle.fill = itemVisualStyle[drawType];
  51944. }
  51945. if (itemStyle.stroke === 'inherit') {
  51946. /**
  51947. * icon type with "emptyXXX" should use fill color
  51948. * in visual style
  51949. */
  51950. itemStyle.stroke = itemVisualStyle[iconBrushType];
  51951. }
  51952. if (itemStyle.opacity === 'inherit') {
  51953. /**
  51954. * Use lineStyle.opacity if drawType is stroke
  51955. */
  51956. itemStyle.opacity = (drawType === 'fill' ? itemVisualStyle : lineVisualStyle).opacity;
  51957. }
  51958. handleCommonProps(itemStyle, itemVisualStyle); // lineStyle
  51959. var legendLineModel = legendModel.getModel('lineStyle');
  51960. var lineStyle = legendLineModel.getLineStyle();
  51961. handleCommonProps(lineStyle, lineVisualStyle); // Fix auto color to real color
  51962. itemStyle.fill === 'auto' && (itemStyle.fill = itemVisualStyle.fill);
  51963. itemStyle.stroke === 'auto' && (itemStyle.stroke = itemVisualStyle.fill);
  51964. lineStyle.stroke === 'auto' && (lineStyle.stroke = itemVisualStyle.fill);
  51965. if (!isSelected) {
  51966. var borderWidth = legendModel.get('inactiveBorderWidth');
  51967. /**
  51968. * Since stroke is set to be inactiveBorderColor, it may occur that
  51969. * there is no border in series but border in legend, so we need to
  51970. * use border only when series has border if is set to be auto
  51971. */
  51972. var visualHasBorder = itemStyle[iconBrushType];
  51973. itemStyle.lineWidth = borderWidth === 'auto' ? itemVisualStyle.lineWidth > 0 && visualHasBorder ? 2 : 0 : itemStyle.lineWidth;
  51974. itemStyle.fill = legendModel.get('inactiveColor');
  51975. itemStyle.stroke = legendModel.get('inactiveBorderColor');
  51976. lineStyle.stroke = legendLineModel.get('inactiveColor');
  51977. lineStyle.lineWidth = legendLineModel.get('inactiveWidth');
  51978. }
  51979. return {
  51980. itemStyle: itemStyle,
  51981. lineStyle: lineStyle
  51982. };
  51983. }
  51984. function getDefaultLegendIcon(opt) {
  51985. var symboType = opt.icon || 'roundRect';
  51986. var icon = createSymbol(symboType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill, opt.symbolKeepAspect);
  51987. icon.setStyle(opt.itemStyle);
  51988. icon.rotation = (opt.iconRotate || 0) * Math.PI / 180;
  51989. icon.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
  51990. if (symboType.indexOf('empty') > -1) {
  51991. icon.style.stroke = icon.style.fill;
  51992. icon.style.fill = '#fff';
  51993. icon.style.lineWidth = 2;
  51994. }
  51995. return icon;
  51996. }
  51997. function dispatchSelectAction(seriesName, dataName, api, excludeSeriesId) {
  51998. // downplay before unselect
  51999. dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId);
  52000. api.dispatchAction({
  52001. type: 'legendToggleSelect',
  52002. name: seriesName != null ? seriesName : dataName
  52003. }); // highlight after select
  52004. // TODO higlight immediately may cause animation loss.
  52005. dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId);
  52006. }
  52007. function isUseHoverLayer(api) {
  52008. var list = api.getZr().storage.getDisplayList();
  52009. var emphasisState;
  52010. var i = 0;
  52011. var len = list.length;
  52012. while (i < len && !(emphasisState = list[i].states.emphasis)) {
  52013. i++;
  52014. }
  52015. return emphasisState && emphasisState.hoverLayer;
  52016. }
  52017. function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
  52018. // If element hover will move to a hoverLayer.
  52019. if (!isUseHoverLayer(api)) {
  52020. api.dispatchAction({
  52021. type: 'highlight',
  52022. seriesName: seriesName,
  52023. name: dataName,
  52024. excludeSeriesId: excludeSeriesId
  52025. });
  52026. }
  52027. }
  52028. function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
  52029. // If element hover will move to a hoverLayer.
  52030. if (!isUseHoverLayer(api)) {
  52031. api.dispatchAction({
  52032. type: 'downplay',
  52033. seriesName: seriesName,
  52034. name: dataName,
  52035. excludeSeriesId: excludeSeriesId
  52036. });
  52037. }
  52038. }
  52039. /*
  52040. * Licensed to the Apache Software Foundation (ASF) under one
  52041. * or more contributor license agreements. See the NOTICE file
  52042. * distributed with this work for additional information
  52043. * regarding copyright ownership. The ASF licenses this file
  52044. * to you under the Apache License, Version 2.0 (the
  52045. * "License"); you may not use this file except in compliance
  52046. * with the License. You may obtain a copy of the License at
  52047. *
  52048. * http://www.apache.org/licenses/LICENSE-2.0
  52049. *
  52050. * Unless required by applicable law or agreed to in writing,
  52051. * software distributed under the License is distributed on an
  52052. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52053. * KIND, either express or implied. See the License for the
  52054. * specific language governing permissions and limitations
  52055. * under the License.
  52056. */
  52057. /**
  52058. * AUTO-GENERATED FILE. DO NOT MODIFY.
  52059. */
  52060. /*
  52061. * Licensed to the Apache Software Foundation (ASF) under one
  52062. * or more contributor license agreements. See the NOTICE file
  52063. * distributed with this work for additional information
  52064. * regarding copyright ownership. The ASF licenses this file
  52065. * to you under the Apache License, Version 2.0 (the
  52066. * "License"); you may not use this file except in compliance
  52067. * with the License. You may obtain a copy of the License at
  52068. *
  52069. * http://www.apache.org/licenses/LICENSE-2.0
  52070. *
  52071. * Unless required by applicable law or agreed to in writing,
  52072. * software distributed under the License is distributed on an
  52073. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52074. * KIND, either express or implied. See the License for the
  52075. * specific language governing permissions and limitations
  52076. * under the License.
  52077. */
  52078. function legendFilter(ecModel) {
  52079. var legendModels = ecModel.findComponents({
  52080. mainType: 'legend'
  52081. });
  52082. if (legendModels && legendModels.length) {
  52083. ecModel.filterSeries(function (series) {
  52084. // If in any legend component the status is not selected.
  52085. // Because in legend series is assumed selected when it is not in the legend data.
  52086. for (var i = 0; i < legendModels.length; i++) {
  52087. if (!legendModels[i].isSelected(series.name)) {
  52088. return false;
  52089. }
  52090. }
  52091. return true;
  52092. });
  52093. }
  52094. }
  52095. function legendSelectActionHandler(methodName, payload, ecModel) {
  52096. var selectedMap = {};
  52097. var isToggleSelect = methodName === 'toggleSelected';
  52098. var isSelected; // Update all legend components
  52099. ecModel.eachComponent('legend', function (legendModel) {
  52100. if (isToggleSelect && isSelected != null) {
  52101. // Force other legend has same selected status
  52102. // Or the first is toggled to true and other are toggled to false
  52103. // In the case one legend has some item unSelected in option. And if other legend
  52104. // doesn't has the item, they will assume it is selected.
  52105. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  52106. } else if (methodName === 'allSelect' || methodName === 'inverseSelect') {
  52107. legendModel[methodName]();
  52108. } else {
  52109. legendModel[methodName](payload.name);
  52110. isSelected = legendModel.isSelected(payload.name);
  52111. }
  52112. var legendData = legendModel.getData();
  52113. each(legendData, function (model) {
  52114. var name = model.get('name'); // Wrap element
  52115. if (name === '\n' || name === '') {
  52116. return;
  52117. }
  52118. var isItemSelected = legendModel.isSelected(name);
  52119. if (selectedMap.hasOwnProperty(name)) {
  52120. // Unselected if any legend is unselected
  52121. selectedMap[name] = selectedMap[name] && isItemSelected;
  52122. } else {
  52123. selectedMap[name] = isItemSelected;
  52124. }
  52125. });
  52126. }); // Return the event explicitly
  52127. return methodName === 'allSelect' || methodName === 'inverseSelect' ? {
  52128. selected: selectedMap
  52129. } : {
  52130. name: payload.name,
  52131. selected: selectedMap
  52132. };
  52133. }
  52134. function installLegendAction(registers) {
  52135. /**
  52136. * @event legendToggleSelect
  52137. * @type {Object}
  52138. * @property {string} type 'legendToggleSelect'
  52139. * @property {string} [from]
  52140. * @property {string} name Series name or data item name
  52141. */
  52142. registers.registerAction('legendToggleSelect', 'legendselectchanged', curry(legendSelectActionHandler, 'toggleSelected'));
  52143. registers.registerAction('legendAllSelect', 'legendselectall', curry(legendSelectActionHandler, 'allSelect'));
  52144. registers.registerAction('legendInverseSelect', 'legendinverseselect', curry(legendSelectActionHandler, 'inverseSelect'));
  52145. /**
  52146. * @event legendSelect
  52147. * @type {Object}
  52148. * @property {string} type 'legendSelect'
  52149. * @property {string} name Series name or data item name
  52150. */
  52151. registers.registerAction('legendSelect', 'legendselected', curry(legendSelectActionHandler, 'select'));
  52152. /**
  52153. * @event legendUnSelect
  52154. * @type {Object}
  52155. * @property {string} type 'legendUnSelect'
  52156. * @property {string} name Series name or data item name
  52157. */
  52158. registers.registerAction('legendUnSelect', 'legendunselected', curry(legendSelectActionHandler, 'unSelect'));
  52159. }
  52160. function install$h(registers) {
  52161. registers.registerComponentModel(LegendModel);
  52162. registers.registerComponentView(LegendView);
  52163. registers.registerProcessor(registers.PRIORITY.PROCESSOR.SERIES_FILTER, legendFilter);
  52164. registers.registerSubTypeDefaulter('legend', function () {
  52165. return 'plain';
  52166. });
  52167. installLegendAction(registers);
  52168. }
  52169. var ScrollableLegendModel =
  52170. /** @class */
  52171. function (_super) {
  52172. __extends(ScrollableLegendModel, _super);
  52173. function ScrollableLegendModel() {
  52174. var _this = _super !== null && _super.apply(this, arguments) || this;
  52175. _this.type = ScrollableLegendModel.type;
  52176. return _this;
  52177. }
  52178. /**
  52179. * @param {number} scrollDataIndex
  52180. */
  52181. ScrollableLegendModel.prototype.setScrollDataIndex = function (scrollDataIndex) {
  52182. this.option.scrollDataIndex = scrollDataIndex;
  52183. };
  52184. ScrollableLegendModel.prototype.init = function (option, parentModel, ecModel) {
  52185. var inputPositionParams = getLayoutParams(option);
  52186. _super.prototype.init.call(this, option, parentModel, ecModel);
  52187. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  52188. };
  52189. /**
  52190. * @override
  52191. */
  52192. ScrollableLegendModel.prototype.mergeOption = function (option, ecModel) {
  52193. _super.prototype.mergeOption.call(this, option, ecModel);
  52194. mergeAndNormalizeLayoutParams(this, this.option, option);
  52195. };
  52196. ScrollableLegendModel.type = 'legend.scroll';
  52197. ScrollableLegendModel.defaultOption = inheritDefaultOption(LegendModel.defaultOption, {
  52198. scrollDataIndex: 0,
  52199. pageButtonItemGap: 5,
  52200. pageButtonGap: null,
  52201. pageButtonPosition: 'end',
  52202. pageFormatter: '{current}/{total}',
  52203. pageIcons: {
  52204. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  52205. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  52206. },
  52207. pageIconColor: '#2f4554',
  52208. pageIconInactiveColor: '#aaa',
  52209. pageIconSize: 15,
  52210. pageTextStyle: {
  52211. color: '#333'
  52212. },
  52213. animationDurationUpdate: 800
  52214. });
  52215. return ScrollableLegendModel;
  52216. }(LegendModel);
  52217. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  52218. var orient = legendModel.getOrient();
  52219. var ignoreSize = [1, 1];
  52220. ignoreSize[orient.index] = 0;
  52221. mergeLayoutParam(target, raw, {
  52222. type: 'box',
  52223. ignoreSize: !!ignoreSize
  52224. });
  52225. }
  52226. var Group$2 = Group;
  52227. var WH = ['width', 'height'];
  52228. var XY = ['x', 'y'];
  52229. var ScrollableLegendView =
  52230. /** @class */
  52231. function (_super) {
  52232. __extends(ScrollableLegendView, _super);
  52233. function ScrollableLegendView() {
  52234. var _this = _super !== null && _super.apply(this, arguments) || this;
  52235. _this.type = ScrollableLegendView.type;
  52236. _this.newlineDisabled = true;
  52237. _this._currentIndex = 0;
  52238. return _this;
  52239. }
  52240. ScrollableLegendView.prototype.init = function () {
  52241. _super.prototype.init.call(this);
  52242. this.group.add(this._containerGroup = new Group$2());
  52243. this._containerGroup.add(this.getContentGroup());
  52244. this.group.add(this._controllerGroup = new Group$2());
  52245. };
  52246. /**
  52247. * @override
  52248. */
  52249. ScrollableLegendView.prototype.resetInner = function () {
  52250. _super.prototype.resetInner.call(this);
  52251. this._controllerGroup.removeAll();
  52252. this._containerGroup.removeClipPath();
  52253. this._containerGroup.__rectSize = null;
  52254. };
  52255. /**
  52256. * @override
  52257. */
  52258. ScrollableLegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  52259. var self = this; // Render content items.
  52260. _super.prototype.renderInner.call(this, itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
  52261. var controllerGroup = this._controllerGroup; // FIXME: support be 'auto' adapt to size number text length,
  52262. // e.g., '3/12345' should not overlap with the control arrow button.
  52263. var pageIconSize = legendModel.get('pageIconSize', true);
  52264. var pageIconSizeArr = isArray(pageIconSize) ? pageIconSize : [pageIconSize, pageIconSize];
  52265. createPageButton('pagePrev', 0);
  52266. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  52267. controllerGroup.add(new ZRText({
  52268. name: 'pageText',
  52269. style: {
  52270. // Placeholder to calculate a proper layout.
  52271. text: 'xx/xx',
  52272. fill: pageTextStyleModel.getTextColor(),
  52273. font: pageTextStyleModel.getFont(),
  52274. verticalAlign: 'middle',
  52275. align: 'center'
  52276. },
  52277. silent: true
  52278. }));
  52279. createPageButton('pageNext', 1);
  52280. function createPageButton(name, iconIdx) {
  52281. var pageDataIndexName = name + 'DataIndex';
  52282. var icon = createIcon(legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx], {
  52283. // Buttons will be created in each render, so we do not need
  52284. // to worry about avoiding using legendModel kept in scope.
  52285. onclick: bind(self._pageGo, self, pageDataIndexName, legendModel, api)
  52286. }, {
  52287. x: -pageIconSizeArr[0] / 2,
  52288. y: -pageIconSizeArr[1] / 2,
  52289. width: pageIconSizeArr[0],
  52290. height: pageIconSizeArr[1]
  52291. });
  52292. icon.name = name;
  52293. controllerGroup.add(icon);
  52294. }
  52295. };
  52296. /**
  52297. * @override
  52298. */
  52299. ScrollableLegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  52300. var selectorGroup = this.getSelectorGroup();
  52301. var orientIdx = legendModel.getOrient().index;
  52302. var wh = WH[orientIdx];
  52303. var xy = XY[orientIdx];
  52304. var hw = WH[1 - orientIdx];
  52305. var yx = XY[1 - orientIdx];
  52306. selector && box( // Buttons in selectorGroup always layout horizontally
  52307. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  52308. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  52309. var selectorRect = selectorGroup.getBoundingRect();
  52310. var selectorPos = [-selectorRect.x, -selectorRect.y];
  52311. var processMaxSize = clone(maxSize);
  52312. selector && (processMaxSize[wh] = maxSize[wh] - selectorRect[wh] - selectorButtonGap);
  52313. var mainRect = this._layoutContentAndController(legendModel, isFirstRender, processMaxSize, orientIdx, wh, hw, yx, xy);
  52314. if (selector) {
  52315. if (selectorPosition === 'end') {
  52316. selectorPos[orientIdx] += mainRect[wh] + selectorButtonGap;
  52317. } else {
  52318. var offset = selectorRect[wh] + selectorButtonGap;
  52319. selectorPos[orientIdx] -= offset;
  52320. mainRect[xy] -= offset;
  52321. }
  52322. mainRect[wh] += selectorRect[wh] + selectorButtonGap;
  52323. selectorPos[1 - orientIdx] += mainRect[yx] + mainRect[hw] / 2 - selectorRect[hw] / 2;
  52324. mainRect[hw] = Math.max(mainRect[hw], selectorRect[hw]);
  52325. mainRect[yx] = Math.min(mainRect[yx], selectorRect[yx] + selectorPos[1 - orientIdx]);
  52326. selectorGroup.x = selectorPos[0];
  52327. selectorGroup.y = selectorPos[1];
  52328. selectorGroup.markRedraw();
  52329. }
  52330. return mainRect;
  52331. };
  52332. ScrollableLegendView.prototype._layoutContentAndController = function (legendModel, isFirstRender, maxSize, orientIdx, wh, hw, yx, xy) {
  52333. var contentGroup = this.getContentGroup();
  52334. var containerGroup = this._containerGroup;
  52335. var controllerGroup = this._controllerGroup; // Place items in contentGroup.
  52336. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), !orientIdx ? null : maxSize.width, orientIdx ? null : maxSize.height);
  52337. box( // Buttons in controller are layout always horizontally.
  52338. 'horizontal', controllerGroup, legendModel.get('pageButtonItemGap', true));
  52339. var contentRect = contentGroup.getBoundingRect();
  52340. var controllerRect = controllerGroup.getBoundingRect();
  52341. var showController = this._showController = contentRect[wh] > maxSize[wh]; // In case that the inner elements of contentGroup layout do not based on [0, 0]
  52342. var contentPos = [-contentRect.x, -contentRect.y]; // Remain contentPos when scroll animation perfroming.
  52343. // If first rendering, `contentGroup.position` is [0, 0], which
  52344. // does not make sense and may cause unexepcted animation if adopted.
  52345. if (!isFirstRender) {
  52346. contentPos[orientIdx] = contentGroup[xy];
  52347. } // Layout container group based on 0.
  52348. var containerPos = [0, 0];
  52349. var controllerPos = [-controllerRect.x, -controllerRect.y];
  52350. var pageButtonGap = retrieve2(legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)); // Place containerGroup and controllerGroup and contentGroup.
  52351. if (showController) {
  52352. var pageButtonPosition = legendModel.get('pageButtonPosition', true); // controller is on the right / bottom.
  52353. if (pageButtonPosition === 'end') {
  52354. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  52355. } // controller is on the left / top.
  52356. else {
  52357. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  52358. }
  52359. } // Always align controller to content as 'middle'.
  52360. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  52361. contentGroup.setPosition(contentPos);
  52362. containerGroup.setPosition(containerPos);
  52363. controllerGroup.setPosition(controllerPos); // Calculate `mainRect` and set `clipPath`.
  52364. // mainRect should not be calculated by `this.group.getBoundingRect()`
  52365. // for sake of the overflow.
  52366. var mainRect = {
  52367. x: 0,
  52368. y: 0
  52369. }; // Consider content may be overflow (should be clipped).
  52370. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  52371. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]); // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  52372. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  52373. containerGroup.__rectSize = maxSize[wh];
  52374. if (showController) {
  52375. var clipShape = {
  52376. x: 0,
  52377. y: 0
  52378. };
  52379. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  52380. clipShape[hw] = mainRect[hw];
  52381. containerGroup.setClipPath(new Rect({
  52382. shape: clipShape
  52383. })); // Consider content may be larger than container, container rect
  52384. // can not be obtained from `containerGroup.getBoundingRect()`.
  52385. containerGroup.__rectSize = clipShape[wh];
  52386. } else {
  52387. // Do not remove or ignore controller. Keep them set as placeholders.
  52388. controllerGroup.eachChild(function (child) {
  52389. child.attr({
  52390. invisible: true,
  52391. silent: true
  52392. });
  52393. });
  52394. } // Content translate animation.
  52395. var pageInfo = this._getPageInfo(legendModel);
  52396. pageInfo.pageIndex != null && updateProps(contentGroup, {
  52397. x: pageInfo.contentPosition[0],
  52398. y: pageInfo.contentPosition[1]
  52399. }, // When switch from "show controller" to "not show controller", view should be
  52400. // updated immediately without animation, otherwise causes weird effect.
  52401. showController ? legendModel : null);
  52402. this._updatePageInfoView(legendModel, pageInfo);
  52403. return mainRect;
  52404. };
  52405. ScrollableLegendView.prototype._pageGo = function (to, legendModel, api) {
  52406. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  52407. scrollDataIndex != null && api.dispatchAction({
  52408. type: 'legendScroll',
  52409. scrollDataIndex: scrollDataIndex,
  52410. legendId: legendModel.id
  52411. });
  52412. };
  52413. ScrollableLegendView.prototype._updatePageInfoView = function (legendModel, pageInfo) {
  52414. var controllerGroup = this._controllerGroup;
  52415. each(['pagePrev', 'pageNext'], function (name) {
  52416. var key = name + 'DataIndex';
  52417. var canJump = pageInfo[key] != null;
  52418. var icon = controllerGroup.childOfName(name);
  52419. if (icon) {
  52420. icon.setStyle('fill', canJump ? legendModel.get('pageIconColor', true) : legendModel.get('pageIconInactiveColor', true));
  52421. icon.cursor = canJump ? 'pointer' : 'default';
  52422. }
  52423. });
  52424. var pageText = controllerGroup.childOfName('pageText');
  52425. var pageFormatter = legendModel.get('pageFormatter');
  52426. var pageIndex = pageInfo.pageIndex;
  52427. var current = pageIndex != null ? pageIndex + 1 : 0;
  52428. var total = pageInfo.pageCount;
  52429. pageText && pageFormatter && pageText.setStyle('text', isString(pageFormatter) ? pageFormatter.replace('{current}', current == null ? '' : current + '').replace('{total}', total == null ? '' : total + '') : pageFormatter({
  52430. current: current,
  52431. total: total
  52432. }));
  52433. };
  52434. /**
  52435. * contentPosition: Array.<number>, null when data item not found.
  52436. * pageIndex: number, null when data item not found.
  52437. * pageCount: number, always be a number, can be 0.
  52438. * pagePrevDataIndex: number, null when no previous page.
  52439. * pageNextDataIndex: number, null when no next page.
  52440. * }
  52441. */
  52442. ScrollableLegendView.prototype._getPageInfo = function (legendModel) {
  52443. var scrollDataIndex = legendModel.get('scrollDataIndex', true);
  52444. var contentGroup = this.getContentGroup();
  52445. var containerRectSize = this._containerGroup.__rectSize;
  52446. var orientIdx = legendModel.getOrient().index;
  52447. var wh = WH[orientIdx];
  52448. var xy = XY[orientIdx];
  52449. var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
  52450. var children = contentGroup.children();
  52451. var targetItem = children[targetItemIndex];
  52452. var itemCount = children.length;
  52453. var pCount = !itemCount ? 0 : 1;
  52454. var result = {
  52455. contentPosition: [contentGroup.x, contentGroup.y],
  52456. pageCount: pCount,
  52457. pageIndex: pCount - 1,
  52458. pagePrevDataIndex: null,
  52459. pageNextDataIndex: null
  52460. };
  52461. if (!targetItem) {
  52462. return result;
  52463. }
  52464. var targetItemInfo = getItemInfo(targetItem);
  52465. result.contentPosition[orientIdx] = -targetItemInfo.s; // Strategy:
  52466. // (1) Always align based on the left/top most item.
  52467. // (2) It is user-friendly that the last item shown in the
  52468. // current window is shown at the begining of next window.
  52469. // Otherwise if half of the last item is cut by the window,
  52470. // it will have no chance to display entirely.
  52471. // (3) Consider that item size probably be different, we
  52472. // have calculate pageIndex by size rather than item index,
  52473. // and we can not get page index directly by division.
  52474. // (4) The window is to narrow to contain more than
  52475. // one item, we should make sure that the page can be fliped.
  52476. for (var i = targetItemIndex + 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i <= itemCount; ++i) {
  52477. currItemInfo = getItemInfo(children[i]);
  52478. if ( // Half of the last item is out of the window.
  52479. !currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize || // If the current item does not intersect with the window, the new page
  52480. // can be started at the current item or the last item.
  52481. currItemInfo && !intersect(currItemInfo, winStartItemInfo.s)) {
  52482. if (winEndItemInfo.i > winStartItemInfo.i) {
  52483. winStartItemInfo = winEndItemInfo;
  52484. } else {
  52485. // e.g., when page size is smaller than item size.
  52486. winStartItemInfo = currItemInfo;
  52487. }
  52488. if (winStartItemInfo) {
  52489. if (result.pageNextDataIndex == null) {
  52490. result.pageNextDataIndex = winStartItemInfo.i;
  52491. }
  52492. ++result.pageCount;
  52493. }
  52494. }
  52495. winEndItemInfo = currItemInfo;
  52496. }
  52497. for (var i = targetItemIndex - 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i >= -1; --i) {
  52498. currItemInfo = getItemInfo(children[i]);
  52499. if ( // If the the end item does not intersect with the window started
  52500. // from the current item, a page can be settled.
  52501. (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s)) && // e.g., when page size is smaller than item size.
  52502. winStartItemInfo.i < winEndItemInfo.i) {
  52503. winEndItemInfo = winStartItemInfo;
  52504. if (result.pagePrevDataIndex == null) {
  52505. result.pagePrevDataIndex = winStartItemInfo.i;
  52506. }
  52507. ++result.pageCount;
  52508. ++result.pageIndex;
  52509. }
  52510. winStartItemInfo = currItemInfo;
  52511. }
  52512. return result;
  52513. function getItemInfo(el) {
  52514. if (el) {
  52515. var itemRect = el.getBoundingRect();
  52516. var start = itemRect[xy] + el[xy];
  52517. return {
  52518. s: start,
  52519. e: start + itemRect[wh],
  52520. i: el.__legendDataIndex
  52521. };
  52522. }
  52523. }
  52524. function intersect(itemInfo, winStart) {
  52525. return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
  52526. }
  52527. };
  52528. ScrollableLegendView.prototype._findTargetItemIndex = function (targetDataIndex) {
  52529. if (!this._showController) {
  52530. return 0;
  52531. }
  52532. var index;
  52533. var contentGroup = this.getContentGroup();
  52534. var defaultIndex;
  52535. contentGroup.eachChild(function (child, idx) {
  52536. var legendDataIdx = child.__legendDataIndex; // FIXME
  52537. // If the given targetDataIndex (from model) is illegal,
  52538. // we use defaultIndex. But the index on the legend model and
  52539. // action payload is still illegal. That case will not be
  52540. // changed until some scenario requires.
  52541. if (defaultIndex == null && legendDataIdx != null) {
  52542. defaultIndex = idx;
  52543. }
  52544. if (legendDataIdx === targetDataIndex) {
  52545. index = idx;
  52546. }
  52547. });
  52548. return index != null ? index : defaultIndex;
  52549. };
  52550. ScrollableLegendView.type = 'legend.scroll';
  52551. return ScrollableLegendView;
  52552. }(LegendView);
  52553. /*
  52554. * Licensed to the Apache Software Foundation (ASF) under one
  52555. * or more contributor license agreements. See the NOTICE file
  52556. * distributed with this work for additional information
  52557. * regarding copyright ownership. The ASF licenses this file
  52558. * to you under the Apache License, Version 2.0 (the
  52559. * "License"); you may not use this file except in compliance
  52560. * with the License. You may obtain a copy of the License at
  52561. *
  52562. * http://www.apache.org/licenses/LICENSE-2.0
  52563. *
  52564. * Unless required by applicable law or agreed to in writing,
  52565. * software distributed under the License is distributed on an
  52566. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52567. * KIND, either express or implied. See the License for the
  52568. * specific language governing permissions and limitations
  52569. * under the License.
  52570. */
  52571. /**
  52572. * AUTO-GENERATED FILE. DO NOT MODIFY.
  52573. */
  52574. /*
  52575. * Licensed to the Apache Software Foundation (ASF) under one
  52576. * or more contributor license agreements. See the NOTICE file
  52577. * distributed with this work for additional information
  52578. * regarding copyright ownership. The ASF licenses this file
  52579. * to you under the Apache License, Version 2.0 (the
  52580. * "License"); you may not use this file except in compliance
  52581. * with the License. You may obtain a copy of the License at
  52582. *
  52583. * http://www.apache.org/licenses/LICENSE-2.0
  52584. *
  52585. * Unless required by applicable law or agreed to in writing,
  52586. * software distributed under the License is distributed on an
  52587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52588. * KIND, either express or implied. See the License for the
  52589. * specific language governing permissions and limitations
  52590. * under the License.
  52591. */
  52592. function installScrollableLegendAction(registers) {
  52593. /**
  52594. * @event legendScroll
  52595. * @type {Object}
  52596. * @property {string} type 'legendScroll'
  52597. * @property {string} scrollDataIndex
  52598. */
  52599. registers.registerAction('legendScroll', 'legendscroll', function (payload, ecModel) {
  52600. var scrollDataIndex = payload.scrollDataIndex;
  52601. scrollDataIndex != null && ecModel.eachComponent({
  52602. mainType: 'legend',
  52603. subType: 'scroll',
  52604. query: payload
  52605. }, function (legendModel) {
  52606. legendModel.setScrollDataIndex(scrollDataIndex);
  52607. });
  52608. });
  52609. }
  52610. function install$i(registers) {
  52611. use(install$h);
  52612. registers.registerComponentModel(ScrollableLegendModel);
  52613. registers.registerComponentView(ScrollableLegendView);
  52614. installScrollableLegendAction(registers);
  52615. }
  52616. function install$j(registers) {
  52617. use(install$h);
  52618. use(install$i);
  52619. }
  52620. var InsideZoomModel =
  52621. /** @class */
  52622. function (_super) {
  52623. __extends(InsideZoomModel, _super);
  52624. function InsideZoomModel() {
  52625. var _this = _super !== null && _super.apply(this, arguments) || this;
  52626. _this.type = InsideZoomModel.type;
  52627. return _this;
  52628. }
  52629. InsideZoomModel.type = 'dataZoom.inside';
  52630. InsideZoomModel.defaultOption = inheritDefaultOption(DataZoomModel.defaultOption, {
  52631. disabled: false,
  52632. zoomLock: false,
  52633. zoomOnMouseWheel: true,
  52634. moveOnMouseMove: true,
  52635. moveOnMouseWheel: false,
  52636. preventDefaultMouseMove: true
  52637. });
  52638. return InsideZoomModel;
  52639. }(DataZoomModel);
  52640. var RoamController =
  52641. /** @class */
  52642. function (_super) {
  52643. __extends(RoamController, _super);
  52644. function RoamController(zr) {
  52645. var _this = _super.call(this) || this;
  52646. _this._zr = zr; // Avoid two roamController bind the same handler
  52647. var mousedownHandler = bind(_this._mousedownHandler, _this);
  52648. var mousemoveHandler = bind(_this._mousemoveHandler, _this);
  52649. var mouseupHandler = bind(_this._mouseupHandler, _this);
  52650. var mousewheelHandler = bind(_this._mousewheelHandler, _this);
  52651. var pinchHandler = bind(_this._pinchHandler, _this);
  52652. /**
  52653. * Notice: only enable needed types. For example, if 'zoom'
  52654. * is not needed, 'zoom' should not be enabled, otherwise
  52655. * default mousewheel behaviour (scroll page) will be disabled.
  52656. */
  52657. _this.enable = function (controlType, opt) {
  52658. // Disable previous first
  52659. this.disable();
  52660. this._opt = defaults(clone(opt) || {}, {
  52661. zoomOnMouseWheel: true,
  52662. moveOnMouseMove: true,
  52663. // By default, wheel do not trigger move.
  52664. moveOnMouseWheel: false,
  52665. preventDefaultMouseMove: true
  52666. });
  52667. if (controlType == null) {
  52668. controlType = true;
  52669. }
  52670. if (controlType === true || controlType === 'move' || controlType === 'pan') {
  52671. zr.on('mousedown', mousedownHandler);
  52672. zr.on('mousemove', mousemoveHandler);
  52673. zr.on('mouseup', mouseupHandler);
  52674. }
  52675. if (controlType === true || controlType === 'scale' || controlType === 'zoom') {
  52676. zr.on('mousewheel', mousewheelHandler);
  52677. zr.on('pinch', pinchHandler);
  52678. }
  52679. };
  52680. _this.disable = function () {
  52681. zr.off('mousedown', mousedownHandler);
  52682. zr.off('mousemove', mousemoveHandler);
  52683. zr.off('mouseup', mouseupHandler);
  52684. zr.off('mousewheel', mousewheelHandler);
  52685. zr.off('pinch', pinchHandler);
  52686. };
  52687. return _this;
  52688. }
  52689. RoamController.prototype.isDragging = function () {
  52690. return this._dragging;
  52691. };
  52692. RoamController.prototype.isPinching = function () {
  52693. return this._pinching;
  52694. };
  52695. RoamController.prototype.setPointerChecker = function (pointerChecker) {
  52696. this.pointerChecker = pointerChecker;
  52697. };
  52698. RoamController.prototype.dispose = function () {
  52699. this.disable();
  52700. };
  52701. RoamController.prototype._mousedownHandler = function (e) {
  52702. if (isMiddleOrRightButtonOnMouseUpDown(e) || e.target && e.target.draggable) {
  52703. return;
  52704. }
  52705. var x = e.offsetX;
  52706. var y = e.offsetY; // Only check on mosedown, but not mousemove.
  52707. // Mouse can be out of target when mouse moving.
  52708. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  52709. this._x = x;
  52710. this._y = y;
  52711. this._dragging = true;
  52712. }
  52713. };
  52714. RoamController.prototype._mousemoveHandler = function (e) {
  52715. if (!this._dragging || !isAvailableBehavior('moveOnMouseMove', e, this._opt) || e.gestureEvent === 'pinch' || isTaken(this._zr, 'globalPan')) {
  52716. return;
  52717. }
  52718. var x = e.offsetX;
  52719. var y = e.offsetY;
  52720. var oldX = this._x;
  52721. var oldY = this._y;
  52722. var dx = x - oldX;
  52723. var dy = y - oldY;
  52724. this._x = x;
  52725. this._y = y;
  52726. this._opt.preventDefaultMouseMove && stop(e.event);
  52727. trigger$1(this, 'pan', 'moveOnMouseMove', e, {
  52728. dx: dx,
  52729. dy: dy,
  52730. oldX: oldX,
  52731. oldY: oldY,
  52732. newX: x,
  52733. newY: y,
  52734. isAvailableBehavior: null
  52735. });
  52736. };
  52737. RoamController.prototype._mouseupHandler = function (e) {
  52738. if (!isMiddleOrRightButtonOnMouseUpDown(e)) {
  52739. this._dragging = false;
  52740. }
  52741. };
  52742. RoamController.prototype._mousewheelHandler = function (e) {
  52743. var shouldZoom = isAvailableBehavior('zoomOnMouseWheel', e, this._opt);
  52744. var shouldMove = isAvailableBehavior('moveOnMouseWheel', e, this._opt);
  52745. var wheelDelta = e.wheelDelta;
  52746. var absWheelDeltaDelta = Math.abs(wheelDelta);
  52747. var originX = e.offsetX;
  52748. var originY = e.offsetY; // wheelDelta maybe -0 in chrome mac.
  52749. if (wheelDelta === 0 || !shouldZoom && !shouldMove) {
  52750. return;
  52751. } // If both `shouldZoom` and `shouldMove` is true, trigger
  52752. // their event both, and the final behavior is determined
  52753. // by event listener themselves.
  52754. if (shouldZoom) {
  52755. // Convenience:
  52756. // Mac and VM Windows on Mac: scroll up: zoom out.
  52757. // Windows: scroll up: zoom in.
  52758. // FIXME: Should do more test in different environment.
  52759. // wheelDelta is too complicated in difference nvironment
  52760. // (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel),
  52761. // although it has been normallized by zrender.
  52762. // wheelDelta of mouse wheel is bigger than touch pad.
  52763. var factor = absWheelDeltaDelta > 3 ? 1.4 : absWheelDeltaDelta > 1 ? 1.2 : 1.1;
  52764. var scale = wheelDelta > 0 ? factor : 1 / factor;
  52765. checkPointerAndTrigger(this, 'zoom', 'zoomOnMouseWheel', e, {
  52766. scale: scale,
  52767. originX: originX,
  52768. originY: originY,
  52769. isAvailableBehavior: null
  52770. });
  52771. }
  52772. if (shouldMove) {
  52773. // FIXME: Should do more test in different environment.
  52774. var absDelta = Math.abs(wheelDelta); // wheelDelta of mouse wheel is bigger than touch pad.
  52775. var scrollDelta = (wheelDelta > 0 ? 1 : -1) * (absDelta > 3 ? 0.4 : absDelta > 1 ? 0.15 : 0.05);
  52776. checkPointerAndTrigger(this, 'scrollMove', 'moveOnMouseWheel', e, {
  52777. scrollDelta: scrollDelta,
  52778. originX: originX,
  52779. originY: originY,
  52780. isAvailableBehavior: null
  52781. });
  52782. }
  52783. };
  52784. RoamController.prototype._pinchHandler = function (e) {
  52785. if (isTaken(this._zr, 'globalPan')) {
  52786. return;
  52787. }
  52788. var scale = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  52789. checkPointerAndTrigger(this, 'zoom', null, e, {
  52790. scale: scale,
  52791. originX: e.pinchX,
  52792. originY: e.pinchY,
  52793. isAvailableBehavior: null
  52794. });
  52795. };
  52796. return RoamController;
  52797. }(Eventful);
  52798. function checkPointerAndTrigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  52799. if (controller.pointerChecker && controller.pointerChecker(e, contollerEvent.originX, contollerEvent.originY)) {
  52800. // When mouse is out of roamController rect,
  52801. // default befavoius should not be be disabled, otherwise
  52802. // page sliding is disabled, contrary to expectation.
  52803. stop(e.event);
  52804. trigger$1(controller, eventName, behaviorToCheck, e, contollerEvent);
  52805. }
  52806. }
  52807. function trigger$1(controller, eventName, behaviorToCheck, e, contollerEvent) {
  52808. // Also provide behavior checker for event listener, for some case that
  52809. // multiple components share one listener.
  52810. contollerEvent.isAvailableBehavior = bind(isAvailableBehavior, null, behaviorToCheck, e); // TODO should not have type issue.
  52811. controller.trigger(eventName, contollerEvent);
  52812. } // settings: {
  52813. // zoomOnMouseWheel
  52814. // moveOnMouseMove
  52815. // moveOnMouseWheel
  52816. // }
  52817. // The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  52818. function isAvailableBehavior(behaviorToCheck, e, settings) {
  52819. var setting = settings[behaviorToCheck];
  52820. return !behaviorToCheck || setting && (!isString(setting) || e.event[setting + 'Key']);
  52821. }
  52822. var inner$g = makeInner();
  52823. function setViewInfoToCoordSysRecord(api, dataZoomModel, getRange) {
  52824. inner$g(api).coordSysRecordMap.each(function (coordSysRecord) {
  52825. var dzInfo = coordSysRecord.dataZoomInfoMap.get(dataZoomModel.uid);
  52826. if (dzInfo) {
  52827. dzInfo.getRange = getRange;
  52828. }
  52829. });
  52830. }
  52831. function disposeCoordSysRecordIfNeeded(api, dataZoomModel) {
  52832. var coordSysRecordMap = inner$g(api).coordSysRecordMap;
  52833. var coordSysKeyArr = coordSysRecordMap.keys();
  52834. for (var i = 0; i < coordSysKeyArr.length; i++) {
  52835. var coordSysKey = coordSysKeyArr[i];
  52836. var coordSysRecord = coordSysRecordMap.get(coordSysKey);
  52837. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap;
  52838. if (dataZoomInfoMap) {
  52839. var dzUid = dataZoomModel.uid;
  52840. var dzInfo = dataZoomInfoMap.get(dzUid);
  52841. if (dzInfo) {
  52842. dataZoomInfoMap.removeKey(dzUid);
  52843. if (!dataZoomInfoMap.keys().length) {
  52844. disposeCoordSysRecord(coordSysRecordMap, coordSysRecord);
  52845. }
  52846. }
  52847. }
  52848. }
  52849. }
  52850. function disposeCoordSysRecord(coordSysRecordMap, coordSysRecord) {
  52851. if (coordSysRecord) {
  52852. coordSysRecordMap.removeKey(coordSysRecord.model.uid);
  52853. var controller = coordSysRecord.controller;
  52854. controller && controller.dispose();
  52855. }
  52856. }
  52857. function createCoordSysRecord(api, coordSysModel) {
  52858. // These init props will never change after record created.
  52859. var coordSysRecord = {
  52860. model: coordSysModel,
  52861. containsPoint: curry(containsPoint, coordSysModel),
  52862. dispatchAction: curry(dispatchAction, api),
  52863. dataZoomInfoMap: null,
  52864. controller: null
  52865. }; // Must not do anything depends on coordSysRecord outside the event handler here,
  52866. // because coordSysRecord not completed yet.
  52867. var controller = coordSysRecord.controller = new RoamController(api.getZr());
  52868. each(['pan', 'zoom', 'scrollMove'], function (eventName) {
  52869. controller.on(eventName, function (event) {
  52870. var batch = [];
  52871. coordSysRecord.dataZoomInfoMap.each(function (dzInfo) {
  52872. // Check whether the behaviors (zoomOnMouseWheel, moveOnMouseMove,
  52873. // moveOnMouseWheel, ...) enabled.
  52874. if (!event.isAvailableBehavior(dzInfo.model.option)) {
  52875. return;
  52876. }
  52877. var method = (dzInfo.getRange || {})[eventName];
  52878. var range = method && method(dzInfo.dzReferCoordSysInfo, coordSysRecord.model.mainType, coordSysRecord.controller, event);
  52879. !dzInfo.model.get('disabled', true) && range && batch.push({
  52880. dataZoomId: dzInfo.model.id,
  52881. start: range[0],
  52882. end: range[1]
  52883. });
  52884. });
  52885. batch.length && coordSysRecord.dispatchAction(batch);
  52886. });
  52887. });
  52888. return coordSysRecord;
  52889. }
  52890. /**
  52891. * This action will be throttled.
  52892. */
  52893. function dispatchAction(api, batch) {
  52894. api.dispatchAction({
  52895. type: 'dataZoom',
  52896. animation: {
  52897. easing: 'cubicOut',
  52898. duration: 100
  52899. },
  52900. batch: batch
  52901. });
  52902. }
  52903. function containsPoint(coordSysModel, e, x, y) {
  52904. return coordSysModel.coordinateSystem.containPoint([x, y]);
  52905. }
  52906. /**
  52907. * Merge roamController settings when multiple dataZooms share one roamController.
  52908. */
  52909. function mergeControllerParams(dataZoomInfoMap) {
  52910. var controlType; // DO NOT use reserved word (true, false, undefined) as key literally. Even if encapsulated
  52911. // as string, it is probably revert to reserved word by compress tool. See #7411.
  52912. var prefix = 'type_';
  52913. var typePriority = {
  52914. 'type_true': 2,
  52915. 'type_move': 1,
  52916. 'type_false': 0,
  52917. 'type_undefined': -1
  52918. };
  52919. var preventDefaultMouseMove = true;
  52920. dataZoomInfoMap.each(function (dataZoomInfo) {
  52921. var dataZoomModel = dataZoomInfo.model;
  52922. var oneType = dataZoomModel.get('disabled', true) ? false : dataZoomModel.get('zoomLock', true) ? 'move' : true;
  52923. if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
  52924. controlType = oneType;
  52925. } // Prevent default move event by default. If one false, do not prevent. Otherwise
  52926. // users may be confused why it does not work when multiple insideZooms exist.
  52927. preventDefaultMouseMove = preventDefaultMouseMove && dataZoomModel.get('preventDefaultMouseMove', true);
  52928. });
  52929. return {
  52930. controlType: controlType,
  52931. opt: {
  52932. // RoamController will enable all of these functionalities,
  52933. // and the final behavior is determined by its event listener
  52934. // provided by each inside zoom.
  52935. zoomOnMouseWheel: true,
  52936. moveOnMouseMove: true,
  52937. moveOnMouseWheel: true,
  52938. preventDefaultMouseMove: !!preventDefaultMouseMove
  52939. }
  52940. };
  52941. }
  52942. function installDataZoomRoamProcessor(registers) {
  52943. registers.registerProcessor(registers.PRIORITY.PROCESSOR.FILTER, function (ecModel, api) {
  52944. var apiInner = inner$g(api);
  52945. var coordSysRecordMap = apiInner.coordSysRecordMap || (apiInner.coordSysRecordMap = createHashMap());
  52946. coordSysRecordMap.each(function (coordSysRecord) {
  52947. // `coordSysRecordMap` always exists (becuase it hold the `roam controller`, which should
  52948. // better not re-create each time), but clear `dataZoomInfoMap` each round of the workflow.
  52949. coordSysRecord.dataZoomInfoMap = null;
  52950. });
  52951. ecModel.eachComponent({
  52952. mainType: 'dataZoom',
  52953. subType: 'inside'
  52954. }, function (dataZoomModel) {
  52955. var dzReferCoordSysWrap = collectReferCoordSysModelInfo(dataZoomModel);
  52956. each(dzReferCoordSysWrap.infoList, function (dzCoordSysInfo) {
  52957. var coordSysUid = dzCoordSysInfo.model.uid;
  52958. var coordSysRecord = coordSysRecordMap.get(coordSysUid) || coordSysRecordMap.set(coordSysUid, createCoordSysRecord(api, dzCoordSysInfo.model));
  52959. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap || (coordSysRecord.dataZoomInfoMap = createHashMap()); // Notice these props might be changed each time for a single dataZoomModel.
  52960. dataZoomInfoMap.set(dataZoomModel.uid, {
  52961. dzReferCoordSysInfo: dzCoordSysInfo,
  52962. model: dataZoomModel,
  52963. getRange: null
  52964. });
  52965. });
  52966. }); // (1) Merge dataZoom settings for each coord sys and set to the roam controller.
  52967. // (2) Clear coord sys if not refered by any dataZoom.
  52968. coordSysRecordMap.each(function (coordSysRecord) {
  52969. var controller = coordSysRecord.controller;
  52970. var firstDzInfo;
  52971. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap;
  52972. if (dataZoomInfoMap) {
  52973. var firstDzKey = dataZoomInfoMap.keys()[0];
  52974. if (firstDzKey != null) {
  52975. firstDzInfo = dataZoomInfoMap.get(firstDzKey);
  52976. }
  52977. }
  52978. if (!firstDzInfo) {
  52979. disposeCoordSysRecord(coordSysRecordMap, coordSysRecord);
  52980. return;
  52981. }
  52982. var controllerParams = mergeControllerParams(dataZoomInfoMap);
  52983. controller.enable(controllerParams.controlType, controllerParams.opt);
  52984. controller.setPointerChecker(coordSysRecord.containsPoint);
  52985. createOrUpdate(coordSysRecord, 'dispatchAction', firstDzInfo.model.get('throttle', true), 'fixRate');
  52986. });
  52987. });
  52988. }
  52989. var InsideZoomView =
  52990. /** @class */
  52991. function (_super) {
  52992. __extends(InsideZoomView, _super);
  52993. function InsideZoomView() {
  52994. var _this = _super !== null && _super.apply(this, arguments) || this;
  52995. _this.type = 'dataZoom.inside';
  52996. return _this;
  52997. }
  52998. InsideZoomView.prototype.render = function (dataZoomModel, ecModel, api) {
  52999. _super.prototype.render.apply(this, arguments);
  53000. if (dataZoomModel.noTarget()) {
  53001. this._clear();
  53002. return;
  53003. } // Hence the `throttle` util ensures to preserve command order,
  53004. // here simply updating range all the time will not cause missing
  53005. // any of the the roam change.
  53006. this.range = dataZoomModel.getPercentRange(); // Reset controllers.
  53007. setViewInfoToCoordSysRecord(api, dataZoomModel, {
  53008. pan: bind(getRangeHandlers.pan, this),
  53009. zoom: bind(getRangeHandlers.zoom, this),
  53010. scrollMove: bind(getRangeHandlers.scrollMove, this)
  53011. });
  53012. };
  53013. InsideZoomView.prototype.dispose = function () {
  53014. this._clear();
  53015. _super.prototype.dispose.apply(this, arguments);
  53016. };
  53017. InsideZoomView.prototype._clear = function () {
  53018. disposeCoordSysRecordIfNeeded(this.api, this.dataZoomModel);
  53019. this.range = null;
  53020. };
  53021. InsideZoomView.type = 'dataZoom.inside';
  53022. return InsideZoomView;
  53023. }(DataZoomView);
  53024. var getRangeHandlers = {
  53025. zoom: function (coordSysInfo, coordSysMainType, controller, e) {
  53026. var lastRange = this.range;
  53027. var range = lastRange.slice(); // Calculate transform by the first axis.
  53028. var axisModel = coordSysInfo.axisModels[0];
  53029. if (!axisModel) {
  53030. return;
  53031. }
  53032. var directionInfo = getDirectionInfo[coordSysMainType](null, [e.originX, e.originY], axisModel, controller, coordSysInfo);
  53033. var percentPoint = (directionInfo.signal > 0 ? directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel : directionInfo.pixel - directionInfo.pixelStart) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  53034. var scale = Math.max(1 / e.scale, 0);
  53035. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  53036. range[1] = (range[1] - percentPoint) * scale + percentPoint; // Restrict range.
  53037. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  53038. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  53039. this.range = range;
  53040. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  53041. return range;
  53042. }
  53043. },
  53044. pan: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  53045. var directionInfo = getDirectionInfo[coordSysMainType]([e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordSysInfo);
  53046. return directionInfo.signal * (range[1] - range[0]) * directionInfo.pixel / directionInfo.pixelLength;
  53047. }),
  53048. scrollMove: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  53049. var directionInfo = getDirectionInfo[coordSysMainType]([0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordSysInfo);
  53050. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  53051. })
  53052. };
  53053. function makeMover(getPercentDelta) {
  53054. return function (coordSysInfo, coordSysMainType, controller, e) {
  53055. var lastRange = this.range;
  53056. var range = lastRange.slice(); // Calculate transform by the first axis.
  53057. var axisModel = coordSysInfo.axisModels[0];
  53058. if (!axisModel) {
  53059. return;
  53060. }
  53061. var percentDelta = getPercentDelta(range, axisModel, coordSysInfo, coordSysMainType, controller, e);
  53062. sliderMove(percentDelta, range, [0, 100], 'all');
  53063. this.range = range;
  53064. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  53065. return range;
  53066. }
  53067. };
  53068. }
  53069. var getDirectionInfo = {
  53070. grid: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  53071. var axis = axisModel.axis;
  53072. var ret = {};
  53073. var rect = coordSysInfo.model.coordinateSystem.getRect();
  53074. oldPoint = oldPoint || [0, 0];
  53075. if (axis.dim === 'x') {
  53076. ret.pixel = newPoint[0] - oldPoint[0];
  53077. ret.pixelLength = rect.width;
  53078. ret.pixelStart = rect.x;
  53079. ret.signal = axis.inverse ? 1 : -1;
  53080. } else {
  53081. // axis.dim === 'y'
  53082. ret.pixel = newPoint[1] - oldPoint[1];
  53083. ret.pixelLength = rect.height;
  53084. ret.pixelStart = rect.y;
  53085. ret.signal = axis.inverse ? -1 : 1;
  53086. }
  53087. return ret;
  53088. },
  53089. polar: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  53090. var axis = axisModel.axis;
  53091. var ret = {};
  53092. var polar = coordSysInfo.model.coordinateSystem;
  53093. var radiusExtent = polar.getRadiusAxis().getExtent();
  53094. var angleExtent = polar.getAngleAxis().getExtent();
  53095. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  53096. newPoint = polar.pointToCoord(newPoint);
  53097. if (axisModel.mainType === 'radiusAxis') {
  53098. ret.pixel = newPoint[0] - oldPoint[0]; // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  53099. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  53100. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  53101. ret.pixelStart = radiusExtent[0];
  53102. ret.signal = axis.inverse ? 1 : -1;
  53103. } else {
  53104. // 'angleAxis'
  53105. ret.pixel = newPoint[1] - oldPoint[1]; // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  53106. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  53107. ret.pixelLength = angleExtent[1] - angleExtent[0];
  53108. ret.pixelStart = angleExtent[0];
  53109. ret.signal = axis.inverse ? -1 : 1;
  53110. }
  53111. return ret;
  53112. },
  53113. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  53114. var axis = axisModel.axis;
  53115. var rect = coordSysInfo.model.coordinateSystem.getRect();
  53116. var ret = {};
  53117. oldPoint = oldPoint || [0, 0];
  53118. if (axis.orient === 'horizontal') {
  53119. ret.pixel = newPoint[0] - oldPoint[0];
  53120. ret.pixelLength = rect.width;
  53121. ret.pixelStart = rect.x;
  53122. ret.signal = axis.inverse ? 1 : -1;
  53123. } else {
  53124. // 'vertical'
  53125. ret.pixel = newPoint[1] - oldPoint[1];
  53126. ret.pixelLength = rect.height;
  53127. ret.pixelStart = rect.y;
  53128. ret.signal = axis.inverse ? -1 : 1;
  53129. }
  53130. return ret;
  53131. }
  53132. };
  53133. function install$k(registers) {
  53134. installCommon(registers);
  53135. registers.registerComponentModel(InsideZoomModel);
  53136. registers.registerComponentView(InsideZoomView);
  53137. installDataZoomRoamProcessor(registers);
  53138. }
  53139. var SliderZoomModel =
  53140. /** @class */
  53141. function (_super) {
  53142. __extends(SliderZoomModel, _super);
  53143. function SliderZoomModel() {
  53144. var _this = _super !== null && _super.apply(this, arguments) || this;
  53145. _this.type = SliderZoomModel.type;
  53146. return _this;
  53147. }
  53148. SliderZoomModel.type = 'dataZoom.slider';
  53149. SliderZoomModel.layoutMode = 'box';
  53150. SliderZoomModel.defaultOption = inheritDefaultOption(DataZoomModel.defaultOption, {
  53151. show: true,
  53152. // deault value can only be drived in view stage.
  53153. right: 'ph',
  53154. top: 'ph',
  53155. width: 'ph',
  53156. height: 'ph',
  53157. left: null,
  53158. bottom: null,
  53159. borderColor: '#d2dbee',
  53160. borderRadius: 3,
  53161. backgroundColor: 'rgba(47,69,84,0)',
  53162. // dataBackgroundColor: '#ddd',
  53163. dataBackground: {
  53164. lineStyle: {
  53165. color: '#d2dbee',
  53166. width: 0.5
  53167. },
  53168. areaStyle: {
  53169. color: '#d2dbee',
  53170. opacity: 0.2
  53171. }
  53172. },
  53173. selectedDataBackground: {
  53174. lineStyle: {
  53175. color: '#8fb0f7',
  53176. width: 0.5
  53177. },
  53178. areaStyle: {
  53179. color: '#8fb0f7',
  53180. opacity: 0.2
  53181. }
  53182. },
  53183. // Color of selected window.
  53184. fillerColor: 'rgba(135,175,274,0.2)',
  53185. handleIcon: 'path://M-9.35,34.56V42m0-40V9.5m-2,0h4a2,2,0,0,1,2,2v21a2,2,0,0,1-2,2h-4a2,2,0,0,1-2-2v-21A2,2,0,0,1-11.35,9.5Z',
  53186. // Percent of the slider height
  53187. handleSize: '100%',
  53188. handleStyle: {
  53189. color: '#fff',
  53190. borderColor: '#ACB8D1'
  53191. },
  53192. moveHandleSize: 7,
  53193. moveHandleIcon: 'path://M-320.9-50L-320.9-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-348-41-339-50-320.9-50z M-212.3-50L-212.3-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-239.4-41-230.4-50-212.3-50z M-103.7-50L-103.7-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-130.9-41-121.8-50-103.7-50z',
  53194. moveHandleStyle: {
  53195. color: '#D2DBEE',
  53196. opacity: 0.7
  53197. },
  53198. showDetail: true,
  53199. showDataShadow: 'auto',
  53200. realtime: true,
  53201. zoomLock: false,
  53202. textStyle: {
  53203. color: '#6E7079'
  53204. },
  53205. brushSelect: true,
  53206. brushStyle: {
  53207. color: 'rgba(135,175,274,0.15)'
  53208. },
  53209. emphasis: {
  53210. handleStyle: {
  53211. borderColor: '#8FB0F7'
  53212. },
  53213. moveHandleStyle: {
  53214. color: '#8FB0F7'
  53215. }
  53216. }
  53217. });
  53218. return SliderZoomModel;
  53219. }(DataZoomModel);
  53220. var Rect$1 = Rect; // Constants
  53221. var DEFAULT_LOCATION_EDGE_GAP = 7;
  53222. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  53223. var DEFAULT_FILLER_SIZE = 30;
  53224. var DEFAULT_MOVE_HANDLE_SIZE = 7;
  53225. var HORIZONTAL = 'horizontal';
  53226. var VERTICAL = 'vertical';
  53227. var LABEL_GAP = 5;
  53228. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  53229. var REALTIME_ANIMATION_CONFIG = {
  53230. easing: 'cubicOut',
  53231. duration: 100,
  53232. delay: 0
  53233. };
  53234. var SliderZoomView =
  53235. /** @class */
  53236. function (_super) {
  53237. __extends(SliderZoomView, _super);
  53238. function SliderZoomView() {
  53239. var _this = _super !== null && _super.apply(this, arguments) || this;
  53240. _this.type = SliderZoomView.type;
  53241. _this._displayables = {};
  53242. return _this;
  53243. }
  53244. SliderZoomView.prototype.init = function (ecModel, api) {
  53245. this.api = api; // A unique handler for each dataZoom component
  53246. this._onBrush = bind(this._onBrush, this);
  53247. this._onBrushEnd = bind(this._onBrushEnd, this);
  53248. };
  53249. SliderZoomView.prototype.render = function (dataZoomModel, ecModel, api, payload) {
  53250. _super.prototype.render.apply(this, arguments);
  53251. createOrUpdate(this, '_dispatchZoomAction', dataZoomModel.get('throttle'), 'fixRate');
  53252. this._orient = dataZoomModel.getOrient();
  53253. if (dataZoomModel.get('show') === false) {
  53254. this.group.removeAll();
  53255. return;
  53256. }
  53257. if (dataZoomModel.noTarget()) {
  53258. this._clear();
  53259. this.group.removeAll();
  53260. return;
  53261. } // Notice: this._resetInterval() should not be executed when payload.type
  53262. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  53263. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  53264. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  53265. this._buildView();
  53266. }
  53267. this._updateView();
  53268. };
  53269. SliderZoomView.prototype.dispose = function () {
  53270. this._clear();
  53271. _super.prototype.dispose.apply(this, arguments);
  53272. };
  53273. SliderZoomView.prototype._clear = function () {
  53274. clear(this, '_dispatchZoomAction');
  53275. var zr = this.api.getZr();
  53276. zr.off('mousemove', this._onBrush);
  53277. zr.off('mouseup', this._onBrushEnd);
  53278. };
  53279. SliderZoomView.prototype._buildView = function () {
  53280. var thisGroup = this.group;
  53281. thisGroup.removeAll();
  53282. this._brushing = false;
  53283. this._displayables.brushRect = null;
  53284. this._resetLocation();
  53285. this._resetInterval();
  53286. var barGroup = this._displayables.sliderGroup = new Group();
  53287. this._renderBackground();
  53288. this._renderHandle();
  53289. this._renderDataShadow();
  53290. thisGroup.add(barGroup);
  53291. this._positionGroup();
  53292. };
  53293. SliderZoomView.prototype._resetLocation = function () {
  53294. var dataZoomModel = this.dataZoomModel;
  53295. var api = this.api;
  53296. var showMoveHandle = dataZoomModel.get('brushSelect');
  53297. var moveHandleSize = showMoveHandle ? DEFAULT_MOVE_HANDLE_SIZE : 0; // If some of x/y/width/height are not specified,
  53298. // auto-adapt according to target grid.
  53299. var coordRect = this._findCoordRect();
  53300. var ecSize = {
  53301. width: api.getWidth(),
  53302. height: api.getHeight()
  53303. }; // Default align by coordinate system rect.
  53304. var positionInfo = this._orient === HORIZONTAL ? {
  53305. // Why using 'right', because right should be used in vertical,
  53306. // and it is better to be consistent for dealing with position param merge.
  53307. right: ecSize.width - coordRect.x - coordRect.width,
  53308. top: ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP - moveHandleSize,
  53309. width: coordRect.width,
  53310. height: DEFAULT_FILLER_SIZE
  53311. } : {
  53312. right: DEFAULT_LOCATION_EDGE_GAP,
  53313. top: coordRect.y,
  53314. width: DEFAULT_FILLER_SIZE,
  53315. height: coordRect.height
  53316. }; // Do not write back to option and replace value 'ph', because
  53317. // the 'ph' value should be recalculated when resize.
  53318. var layoutParams = getLayoutParams(dataZoomModel.option); // Replace the placeholder value.
  53319. each(['right', 'top', 'width', 'height'], function (name) {
  53320. if (layoutParams[name] === 'ph') {
  53321. layoutParams[name] = positionInfo[name];
  53322. }
  53323. });
  53324. var layoutRect = getLayoutRect(layoutParams, ecSize);
  53325. this._location = {
  53326. x: layoutRect.x,
  53327. y: layoutRect.y
  53328. };
  53329. this._size = [layoutRect.width, layoutRect.height];
  53330. this._orient === VERTICAL && this._size.reverse();
  53331. };
  53332. SliderZoomView.prototype._positionGroup = function () {
  53333. var thisGroup = this.group;
  53334. var location = this._location;
  53335. var orient = this._orient; // Just use the first axis to determine mapping.
  53336. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  53337. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  53338. var sliderGroup = this._displayables.sliderGroup;
  53339. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse; // Transform barGroup.
  53340. sliderGroup.attr(orient === HORIZONTAL && !inverse ? {
  53341. scaleY: otherAxisInverse ? 1 : -1,
  53342. scaleX: 1
  53343. } : orient === HORIZONTAL && inverse ? {
  53344. scaleY: otherAxisInverse ? 1 : -1,
  53345. scaleX: -1
  53346. } : orient === VERTICAL && !inverse ? {
  53347. scaleY: otherAxisInverse ? -1 : 1,
  53348. scaleX: 1,
  53349. rotation: Math.PI / 2
  53350. } // Dont use Math.PI, considering shadow direction.
  53351. : {
  53352. scaleY: otherAxisInverse ? -1 : 1,
  53353. scaleX: -1,
  53354. rotation: Math.PI / 2
  53355. }); // Position barGroup
  53356. var rect = thisGroup.getBoundingRect([sliderGroup]);
  53357. thisGroup.x = location.x - rect.x;
  53358. thisGroup.y = location.y - rect.y;
  53359. thisGroup.markRedraw();
  53360. };
  53361. SliderZoomView.prototype._getViewExtent = function () {
  53362. return [0, this._size[0]];
  53363. };
  53364. SliderZoomView.prototype._renderBackground = function () {
  53365. var dataZoomModel = this.dataZoomModel;
  53366. var size = this._size;
  53367. var barGroup = this._displayables.sliderGroup;
  53368. var brushSelect = dataZoomModel.get('brushSelect');
  53369. barGroup.add(new Rect$1({
  53370. silent: true,
  53371. shape: {
  53372. x: 0,
  53373. y: 0,
  53374. width: size[0],
  53375. height: size[1]
  53376. },
  53377. style: {
  53378. fill: dataZoomModel.get('backgroundColor')
  53379. },
  53380. z2: -40
  53381. })); // Click panel, over shadow, below handles.
  53382. var clickPanel = new Rect$1({
  53383. shape: {
  53384. x: 0,
  53385. y: 0,
  53386. width: size[0],
  53387. height: size[1]
  53388. },
  53389. style: {
  53390. fill: 'transparent'
  53391. },
  53392. z2: 0,
  53393. onclick: bind(this._onClickPanel, this)
  53394. });
  53395. var zr = this.api.getZr();
  53396. if (brushSelect) {
  53397. clickPanel.on('mousedown', this._onBrushStart, this);
  53398. clickPanel.cursor = 'crosshair';
  53399. zr.on('mousemove', this._onBrush);
  53400. zr.on('mouseup', this._onBrushEnd);
  53401. } else {
  53402. zr.off('mousemove', this._onBrush);
  53403. zr.off('mouseup', this._onBrushEnd);
  53404. }
  53405. barGroup.add(clickPanel);
  53406. };
  53407. SliderZoomView.prototype._renderDataShadow = function () {
  53408. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  53409. this._displayables.dataShadowSegs = [];
  53410. if (!info) {
  53411. return;
  53412. }
  53413. var size = this._size;
  53414. var seriesModel = info.series;
  53415. var data = seriesModel.getRawData();
  53416. var otherDim = seriesModel.getShadowDim ? seriesModel.getShadowDim() // @see candlestick
  53417. : info.otherDim;
  53418. if (otherDim == null) {
  53419. return;
  53420. }
  53421. var otherDataExtent = data.getDataExtent(otherDim); // Nice extent.
  53422. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  53423. otherDataExtent = [otherDataExtent[0] - otherOffset, otherDataExtent[1] + otherOffset];
  53424. var otherShadowExtent = [0, size[1]];
  53425. var thisShadowExtent = [0, size[0]];
  53426. var areaPoints = [[size[0], 0], [0, 0]];
  53427. var linePoints = [];
  53428. var step = thisShadowExtent[1] / (data.count() - 1);
  53429. var thisCoord = 0; // Optimize for large data shadow
  53430. var stride = Math.round(data.count() / size[0]);
  53431. var lastIsEmpty;
  53432. data.each([otherDim], function (value, index) {
  53433. if (stride > 0 && index % stride) {
  53434. thisCoord += step;
  53435. return;
  53436. } // FIXME
  53437. // Should consider axis.min/axis.max when drawing dataShadow.
  53438. // FIXME
  53439. // 应该使用统一的空判断?还是在list里进行空判断?
  53440. var isEmpty = value == null || isNaN(value) || value === ''; // See #4235.
  53441. var otherCoord = isEmpty ? 0 : linearMap(value, otherDataExtent, otherShadowExtent, true); // Attempt to draw data shadow precisely when there are empty value.
  53442. if (isEmpty && !lastIsEmpty && index) {
  53443. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  53444. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  53445. } else if (!isEmpty && lastIsEmpty) {
  53446. areaPoints.push([thisCoord, 0]);
  53447. linePoints.push([thisCoord, 0]);
  53448. }
  53449. areaPoints.push([thisCoord, otherCoord]);
  53450. linePoints.push([thisCoord, otherCoord]);
  53451. thisCoord += step;
  53452. lastIsEmpty = isEmpty;
  53453. });
  53454. var dataZoomModel = this.dataZoomModel;
  53455. function createDataShadowGroup(isSelectedArea) {
  53456. var model = dataZoomModel.getModel(isSelectedArea ? 'selectedDataBackground' : 'dataBackground');
  53457. var group = new Group();
  53458. var polygon = new Polygon({
  53459. shape: {
  53460. points: areaPoints
  53461. },
  53462. segmentIgnoreThreshold: 1,
  53463. style: model.getModel('areaStyle').getAreaStyle(),
  53464. silent: true,
  53465. z2: -20
  53466. });
  53467. var polyline = new Polyline({
  53468. shape: {
  53469. points: linePoints
  53470. },
  53471. segmentIgnoreThreshold: 1,
  53472. style: model.getModel('lineStyle').getLineStyle(),
  53473. silent: true,
  53474. z2: -19
  53475. });
  53476. group.add(polygon);
  53477. group.add(polyline);
  53478. return group;
  53479. } // let dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  53480. for (var i = 0; i < 3; i++) {
  53481. var group = createDataShadowGroup(i === 1);
  53482. this._displayables.sliderGroup.add(group);
  53483. this._displayables.dataShadowSegs.push(group);
  53484. }
  53485. };
  53486. SliderZoomView.prototype._prepareDataShadowInfo = function () {
  53487. var dataZoomModel = this.dataZoomModel;
  53488. var showDataShadow = dataZoomModel.get('showDataShadow');
  53489. if (showDataShadow === false) {
  53490. return;
  53491. } // Find a representative series.
  53492. var result;
  53493. var ecModel = this.ecModel;
  53494. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  53495. var seriesModels = dataZoomModel.getAxisProxy(axisDim, axisIndex).getTargetSeriesModels();
  53496. each(seriesModels, function (seriesModel) {
  53497. if (result) {
  53498. return;
  53499. }
  53500. if (showDataShadow !== true && indexOf(SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')) < 0) {
  53501. return;
  53502. }
  53503. var thisAxis = ecModel.getComponent(getAxisMainType(axisDim), axisIndex).axis;
  53504. var otherDim = getOtherDim(axisDim);
  53505. var otherAxisInverse;
  53506. var coordSys = seriesModel.coordinateSystem;
  53507. if (otherDim != null && coordSys.getOtherAxis) {
  53508. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  53509. }
  53510. otherDim = seriesModel.getData().mapDimension(otherDim);
  53511. result = {
  53512. thisAxis: thisAxis,
  53513. series: seriesModel,
  53514. thisDim: axisDim,
  53515. otherDim: otherDim,
  53516. otherAxisInverse: otherAxisInverse
  53517. };
  53518. }, this);
  53519. }, this);
  53520. return result;
  53521. };
  53522. SliderZoomView.prototype._renderHandle = function () {
  53523. var thisGroup = this.group;
  53524. var displayables = this._displayables;
  53525. var handles = displayables.handles = [null, null];
  53526. var handleLabels = displayables.handleLabels = [null, null];
  53527. var sliderGroup = this._displayables.sliderGroup;
  53528. var size = this._size;
  53529. var dataZoomModel = this.dataZoomModel;
  53530. var api = this.api;
  53531. var borderRadius = dataZoomModel.get('borderRadius') || 0;
  53532. var brushSelect = dataZoomModel.get('brushSelect');
  53533. var filler = displayables.filler = new Rect$1({
  53534. silent: brushSelect,
  53535. style: {
  53536. fill: dataZoomModel.get('fillerColor')
  53537. },
  53538. textConfig: {
  53539. position: 'inside'
  53540. }
  53541. });
  53542. sliderGroup.add(filler); // Frame border.
  53543. sliderGroup.add(new Rect$1({
  53544. silent: true,
  53545. subPixelOptimize: true,
  53546. shape: {
  53547. x: 0,
  53548. y: 0,
  53549. width: size[0],
  53550. height: size[1],
  53551. r: borderRadius
  53552. },
  53553. style: {
  53554. stroke: dataZoomModel.get('dataBackgroundColor') // deprecated option
  53555. || dataZoomModel.get('borderColor'),
  53556. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  53557. fill: 'rgba(0,0,0,0)'
  53558. }
  53559. })); // Left and right handle to resize
  53560. each([0, 1], function (handleIndex) {
  53561. var iconStr = dataZoomModel.get('handleIcon');
  53562. if (!symbolBuildProxies[iconStr] && iconStr.indexOf('path://') < 0 && iconStr.indexOf('image://') < 0) {
  53563. // Compatitable with the old icon parsers. Which can use a path string without path://
  53564. iconStr = 'path://' + iconStr;
  53565. if ("development" !== 'production') {
  53566. deprecateLog('handleIcon now needs \'path://\' prefix when using a path string');
  53567. }
  53568. }
  53569. var path = createSymbol(iconStr, -1, 0, 2, 2, null, true);
  53570. path.attr({
  53571. cursor: getCursor(this._orient),
  53572. draggable: true,
  53573. drift: bind(this._onDragMove, this, handleIndex),
  53574. ondragend: bind(this._onDragEnd, this),
  53575. onmouseover: bind(this._showDataInfo, this, true),
  53576. onmouseout: bind(this._showDataInfo, this, false),
  53577. z2: 5
  53578. });
  53579. var bRect = path.getBoundingRect();
  53580. var handleSize = dataZoomModel.get('handleSize');
  53581. this._handleHeight = parsePercent$1(handleSize, this._size[1]);
  53582. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  53583. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  53584. path.style.strokeNoScale = true;
  53585. path.rectHover = true;
  53586. path.ensureState('emphasis').style = dataZoomModel.getModel(['emphasis', 'handleStyle']).getItemStyle();
  53587. enableHoverEmphasis(path);
  53588. var handleColor = dataZoomModel.get('handleColor'); // deprecated option
  53589. // Compatitable with previous version
  53590. if (handleColor != null) {
  53591. path.style.fill = handleColor;
  53592. }
  53593. sliderGroup.add(handles[handleIndex] = path);
  53594. var textStyleModel = dataZoomModel.getModel('textStyle');
  53595. thisGroup.add(handleLabels[handleIndex] = new ZRText({
  53596. silent: true,
  53597. invisible: true,
  53598. style: createTextStyle(textStyleModel, {
  53599. x: 0,
  53600. y: 0,
  53601. text: '',
  53602. verticalAlign: 'middle',
  53603. align: 'center',
  53604. fill: textStyleModel.getTextColor(),
  53605. font: textStyleModel.getFont()
  53606. }),
  53607. z2: 10
  53608. }));
  53609. }, this); // Handle to move. Only visible when brushSelect is set true.
  53610. var actualMoveZone = filler;
  53611. if (brushSelect) {
  53612. var moveHandleHeight = parsePercent$1(dataZoomModel.get('moveHandleSize'), size[1]);
  53613. var moveHandle_1 = displayables.moveHandle = new Rect({
  53614. style: dataZoomModel.getModel('moveHandleStyle').getItemStyle(),
  53615. silent: true,
  53616. shape: {
  53617. r: [0, 0, 2, 2],
  53618. y: size[1] - 0.5,
  53619. height: moveHandleHeight
  53620. }
  53621. });
  53622. var iconSize = moveHandleHeight * 0.8;
  53623. var moveHandleIcon = displayables.moveHandleIcon = createSymbol(dataZoomModel.get('moveHandleIcon'), -iconSize / 2, -iconSize / 2, iconSize, iconSize, '#fff', true);
  53624. moveHandleIcon.silent = true;
  53625. moveHandleIcon.y = size[1] + moveHandleHeight / 2 - 0.5;
  53626. moveHandle_1.ensureState('emphasis').style = dataZoomModel.getModel(['emphasis', 'moveHandleStyle']).getItemStyle();
  53627. var moveZoneExpandSize = Math.min(size[1] / 2, Math.max(moveHandleHeight, 10));
  53628. actualMoveZone = displayables.moveZone = new Rect({
  53629. invisible: true,
  53630. shape: {
  53631. y: size[1] - moveZoneExpandSize,
  53632. height: moveHandleHeight + moveZoneExpandSize
  53633. }
  53634. });
  53635. actualMoveZone.on('mouseover', function () {
  53636. api.enterEmphasis(moveHandle_1);
  53637. }).on('mouseout', function () {
  53638. api.leaveEmphasis(moveHandle_1);
  53639. });
  53640. sliderGroup.add(moveHandle_1);
  53641. sliderGroup.add(moveHandleIcon);
  53642. sliderGroup.add(actualMoveZone);
  53643. }
  53644. actualMoveZone.attr({
  53645. draggable: true,
  53646. cursor: getCursor(this._orient),
  53647. drift: bind(this._onDragMove, this, 'all'),
  53648. ondragstart: bind(this._showDataInfo, this, true),
  53649. ondragend: bind(this._onDragEnd, this),
  53650. onmouseover: bind(this._showDataInfo, this, true),
  53651. onmouseout: bind(this._showDataInfo, this, false)
  53652. });
  53653. };
  53654. SliderZoomView.prototype._resetInterval = function () {
  53655. var range = this._range = this.dataZoomModel.getPercentRange();
  53656. var viewExtent = this._getViewExtent();
  53657. this._handleEnds = [linearMap(range[0], [0, 100], viewExtent, true), linearMap(range[1], [0, 100], viewExtent, true)];
  53658. };
  53659. SliderZoomView.prototype._updateInterval = function (handleIndex, delta) {
  53660. var dataZoomModel = this.dataZoomModel;
  53661. var handleEnds = this._handleEnds;
  53662. var viewExtend = this._getViewExtent();
  53663. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  53664. var percentExtent = [0, 100];
  53665. sliderMove(delta, handleEnds, viewExtend, dataZoomModel.get('zoomLock') ? 'all' : handleIndex, minMaxSpan.minSpan != null ? linearMap(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null, minMaxSpan.maxSpan != null ? linearMap(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null);
  53666. var lastRange = this._range;
  53667. var range = this._range = asc([linearMap(handleEnds[0], viewExtend, percentExtent, true), linearMap(handleEnds[1], viewExtend, percentExtent, true)]);
  53668. return !lastRange || lastRange[0] !== range[0] || lastRange[1] !== range[1];
  53669. };
  53670. SliderZoomView.prototype._updateView = function (nonRealtime) {
  53671. var displaybles = this._displayables;
  53672. var handleEnds = this._handleEnds;
  53673. var handleInterval = asc(handleEnds.slice());
  53674. var size = this._size;
  53675. each([0, 1], function (handleIndex) {
  53676. // Handles
  53677. var handle = displaybles.handles[handleIndex];
  53678. var handleHeight = this._handleHeight;
  53679. handle.attr({
  53680. scaleX: handleHeight / 2,
  53681. scaleY: handleHeight / 2,
  53682. // This is a trick, by adding an extra tiny offset to let the default handle's end point align to the drag window.
  53683. // NOTE: It may affect some custom shapes a bit. But we prefer to have better result by default.
  53684. x: handleEnds[handleIndex] + (handleIndex ? -1 : 1),
  53685. y: size[1] / 2 - handleHeight / 2
  53686. });
  53687. }, this); // Filler
  53688. displaybles.filler.setShape({
  53689. x: handleInterval[0],
  53690. y: 0,
  53691. width: handleInterval[1] - handleInterval[0],
  53692. height: size[1]
  53693. });
  53694. var viewExtent = {
  53695. x: handleInterval[0],
  53696. width: handleInterval[1] - handleInterval[0]
  53697. }; // Move handle
  53698. if (displaybles.moveHandle) {
  53699. displaybles.moveHandle.setShape(viewExtent);
  53700. displaybles.moveZone.setShape(viewExtent); // Force update path on the invisible object
  53701. displaybles.moveZone.getBoundingRect();
  53702. displaybles.moveHandleIcon && displaybles.moveHandleIcon.attr('x', viewExtent.x + viewExtent.width / 2);
  53703. } // update clip path of shadow.
  53704. var dataShadowSegs = displaybles.dataShadowSegs;
  53705. var segIntervals = [0, handleInterval[0], handleInterval[1], size[0]];
  53706. for (var i = 0; i < dataShadowSegs.length; i++) {
  53707. var segGroup = dataShadowSegs[i];
  53708. var clipPath = segGroup.getClipPath();
  53709. if (!clipPath) {
  53710. clipPath = new Rect();
  53711. segGroup.setClipPath(clipPath);
  53712. }
  53713. clipPath.setShape({
  53714. x: segIntervals[i],
  53715. y: 0,
  53716. width: segIntervals[i + 1] - segIntervals[i],
  53717. height: size[1]
  53718. });
  53719. }
  53720. this._updateDataInfo(nonRealtime);
  53721. };
  53722. SliderZoomView.prototype._updateDataInfo = function (nonRealtime) {
  53723. var dataZoomModel = this.dataZoomModel;
  53724. var displaybles = this._displayables;
  53725. var handleLabels = displaybles.handleLabels;
  53726. var orient = this._orient;
  53727. var labelTexts = ['', '']; // FIXME
  53728. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  53729. if (dataZoomModel.get('showDetail')) {
  53730. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  53731. if (axisProxy) {
  53732. var axis = axisProxy.getAxisModel().axis;
  53733. var range = this._range;
  53734. var dataInterval = nonRealtime // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  53735. ? axisProxy.calculateDataWindow({
  53736. start: range[0],
  53737. end: range[1]
  53738. }).valueWindow : axisProxy.getDataValueWindow();
  53739. labelTexts = [this._formatLabel(dataInterval[0], axis), this._formatLabel(dataInterval[1], axis)];
  53740. }
  53741. }
  53742. var orderedHandleEnds = asc(this._handleEnds.slice());
  53743. setLabel.call(this, 0);
  53744. setLabel.call(this, 1);
  53745. function setLabel(handleIndex) {
  53746. // Label
  53747. // Text should not transform by barGroup.
  53748. // Ignore handlers transform
  53749. var barTransform = getTransform(displaybles.handles[handleIndex].parent, this.group);
  53750. var direction = transformDirection(handleIndex === 0 ? 'right' : 'left', barTransform);
  53751. var offset = this._handleWidth / 2 + LABEL_GAP;
  53752. var textPoint = applyTransform$1([orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset), this._size[1] / 2], barTransform);
  53753. handleLabels[handleIndex].setStyle({
  53754. x: textPoint[0],
  53755. y: textPoint[1],
  53756. verticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  53757. align: orient === HORIZONTAL ? direction : 'center',
  53758. text: labelTexts[handleIndex]
  53759. });
  53760. }
  53761. };
  53762. SliderZoomView.prototype._formatLabel = function (value, axis) {
  53763. var dataZoomModel = this.dataZoomModel;
  53764. var labelFormatter = dataZoomModel.get('labelFormatter');
  53765. var labelPrecision = dataZoomModel.get('labelPrecision');
  53766. if (labelPrecision == null || labelPrecision === 'auto') {
  53767. labelPrecision = axis.getPixelPrecision();
  53768. }
  53769. var valueStr = value == null || isNaN(value) ? '' // FIXME Glue code
  53770. : axis.type === 'category' || axis.type === 'time' ? axis.scale.getLabel({
  53771. value: Math.round(value)
  53772. }) // param of toFixed should less then 20.
  53773. : value.toFixed(Math.min(labelPrecision, 20));
  53774. return isFunction(labelFormatter) ? labelFormatter(value, valueStr) : isString(labelFormatter) ? labelFormatter.replace('{value}', valueStr) : valueStr;
  53775. };
  53776. /**
  53777. * @param showOrHide true: show, false: hide
  53778. */
  53779. SliderZoomView.prototype._showDataInfo = function (showOrHide) {
  53780. // Always show when drgging.
  53781. showOrHide = this._dragging || showOrHide;
  53782. var displayables = this._displayables;
  53783. var handleLabels = displayables.handleLabels;
  53784. handleLabels[0].attr('invisible', !showOrHide);
  53785. handleLabels[1].attr('invisible', !showOrHide); // Highlight move handle
  53786. displayables.moveHandle && this.api[showOrHide ? 'enterEmphasis' : 'leaveEmphasis'](displayables.moveHandle, 1);
  53787. };
  53788. SliderZoomView.prototype._onDragMove = function (handleIndex, dx, dy, event) {
  53789. this._dragging = true; // For mobile device, prevent screen slider on the button.
  53790. stop(event.event); // Transform dx, dy to bar coordination.
  53791. var barTransform = this._displayables.sliderGroup.getLocalTransform();
  53792. var vertex = applyTransform$1([dx, dy], barTransform, true);
  53793. var changed = this._updateInterval(handleIndex, vertex[0]);
  53794. var realtime = this.dataZoomModel.get('realtime');
  53795. this._updateView(!realtime); // Avoid dispatch dataZoom repeatly but range not changed,
  53796. // which cause bad visual effect when progressive enabled.
  53797. changed && realtime && this._dispatchZoomAction(true);
  53798. };
  53799. SliderZoomView.prototype._onDragEnd = function () {
  53800. this._dragging = false;
  53801. this._showDataInfo(false); // While in realtime mode and stream mode, dispatch action when
  53802. // drag end will cause the whole view rerender, which is unnecessary.
  53803. var realtime = this.dataZoomModel.get('realtime');
  53804. !realtime && this._dispatchZoomAction(false);
  53805. };
  53806. SliderZoomView.prototype._onClickPanel = function (e) {
  53807. var size = this._size;
  53808. var localPoint = this._displayables.sliderGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  53809. if (localPoint[0] < 0 || localPoint[0] > size[0] || localPoint[1] < 0 || localPoint[1] > size[1]) {
  53810. return;
  53811. }
  53812. var handleEnds = this._handleEnds;
  53813. var center = (handleEnds[0] + handleEnds[1]) / 2;
  53814. var changed = this._updateInterval('all', localPoint[0] - center);
  53815. this._updateView();
  53816. changed && this._dispatchZoomAction(false);
  53817. };
  53818. SliderZoomView.prototype._onBrushStart = function (e) {
  53819. var x = e.offsetX;
  53820. var y = e.offsetY;
  53821. this._brushStart = new Point(x, y);
  53822. this._brushing = true;
  53823. this._brushStartTime = +new Date(); // this._updateBrushRect(x, y);
  53824. };
  53825. SliderZoomView.prototype._onBrushEnd = function (e) {
  53826. if (!this._brushing) {
  53827. return;
  53828. }
  53829. var brushRect = this._displayables.brushRect;
  53830. this._brushing = false;
  53831. if (!brushRect) {
  53832. return;
  53833. }
  53834. brushRect.attr('ignore', true);
  53835. var brushShape = brushRect.shape;
  53836. var brushEndTime = +new Date(); // console.log(brushEndTime - this._brushStartTime);
  53837. if (brushEndTime - this._brushStartTime < 200 && Math.abs(brushShape.width) < 5) {
  53838. // Will treat it as a click
  53839. return;
  53840. }
  53841. var viewExtend = this._getViewExtent();
  53842. var percentExtent = [0, 100];
  53843. this._range = asc([linearMap(brushShape.x, viewExtend, percentExtent, true), linearMap(brushShape.x + brushShape.width, viewExtend, percentExtent, true)]);
  53844. this._handleEnds = [brushShape.x, brushShape.x + brushShape.width];
  53845. this._updateView();
  53846. this._dispatchZoomAction(false);
  53847. };
  53848. SliderZoomView.prototype._onBrush = function (e) {
  53849. if (this._brushing) {
  53850. // For mobile device, prevent screen slider on the button.
  53851. stop(e.event);
  53852. this._updateBrushRect(e.offsetX, e.offsetY);
  53853. }
  53854. };
  53855. SliderZoomView.prototype._updateBrushRect = function (mouseX, mouseY) {
  53856. var displayables = this._displayables;
  53857. var dataZoomModel = this.dataZoomModel;
  53858. var brushRect = displayables.brushRect;
  53859. if (!brushRect) {
  53860. brushRect = displayables.brushRect = new Rect$1({
  53861. silent: true,
  53862. style: dataZoomModel.getModel('brushStyle').getItemStyle()
  53863. });
  53864. displayables.sliderGroup.add(brushRect);
  53865. }
  53866. brushRect.attr('ignore', false);
  53867. var brushStart = this._brushStart;
  53868. var sliderGroup = this._displayables.sliderGroup;
  53869. var endPoint = sliderGroup.transformCoordToLocal(mouseX, mouseY);
  53870. var startPoint = sliderGroup.transformCoordToLocal(brushStart.x, brushStart.y);
  53871. var size = this._size;
  53872. endPoint[0] = Math.max(Math.min(size[0], endPoint[0]), 0);
  53873. brushRect.setShape({
  53874. x: startPoint[0],
  53875. y: 0,
  53876. width: endPoint[0] - startPoint[0],
  53877. height: size[1]
  53878. });
  53879. };
  53880. /**
  53881. * This action will be throttled.
  53882. */
  53883. SliderZoomView.prototype._dispatchZoomAction = function (realtime) {
  53884. var range = this._range;
  53885. this.api.dispatchAction({
  53886. type: 'dataZoom',
  53887. from: this.uid,
  53888. dataZoomId: this.dataZoomModel.id,
  53889. animation: realtime ? REALTIME_ANIMATION_CONFIG : null,
  53890. start: range[0],
  53891. end: range[1]
  53892. });
  53893. };
  53894. SliderZoomView.prototype._findCoordRect = function () {
  53895. // Find the grid coresponding to the first axis referred by dataZoom.
  53896. var rect;
  53897. var coordSysInfoList = collectReferCoordSysModelInfo(this.dataZoomModel).infoList;
  53898. if (!rect && coordSysInfoList.length) {
  53899. var coordSys = coordSysInfoList[0].model.coordinateSystem;
  53900. rect = coordSys.getRect && coordSys.getRect();
  53901. }
  53902. if (!rect) {
  53903. var width = this.api.getWidth();
  53904. var height = this.api.getHeight();
  53905. rect = {
  53906. x: width * 0.2,
  53907. y: height * 0.2,
  53908. width: width * 0.6,
  53909. height: height * 0.6
  53910. };
  53911. }
  53912. return rect;
  53913. };
  53914. SliderZoomView.type = 'dataZoom.slider';
  53915. return SliderZoomView;
  53916. }(DataZoomView);
  53917. function getOtherDim(thisDim) {
  53918. // FIXME
  53919. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  53920. var map = {
  53921. x: 'y',
  53922. y: 'x',
  53923. radius: 'angle',
  53924. angle: 'radius'
  53925. };
  53926. return map[thisDim];
  53927. }
  53928. function getCursor(orient) {
  53929. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  53930. }
  53931. function install$l(registers) {
  53932. registers.registerComponentModel(SliderZoomModel);
  53933. registers.registerComponentView(SliderZoomView);
  53934. installCommon(registers);
  53935. }
  53936. function install$m(registers) {
  53937. use(install$k);
  53938. use(install$l); // Do not install './dataZoomSelect',
  53939. // since it only work for toolbox dataZoom.
  53940. }
  53941. var DEFAULT_OPTION = {
  53942. label: {
  53943. enabled: true
  53944. },
  53945. decal: {
  53946. show: false
  53947. }
  53948. };
  53949. var inner$h = makeInner();
  53950. var decalPaletteScope = {};
  53951. function ariaVisual(ecModel, api) {
  53952. var ariaModel = ecModel.getModel('aria'); // See "area enabled" detection code in `GlobalModel.ts`.
  53953. if (!ariaModel.get('enabled')) {
  53954. return;
  53955. }
  53956. var defaultOption = clone(DEFAULT_OPTION);
  53957. merge(defaultOption.label, ecModel.getLocaleModel().get('aria'), false);
  53958. merge(ariaModel.option, defaultOption, false);
  53959. setDecal();
  53960. setLabel();
  53961. function setDecal() {
  53962. var decalModel = ariaModel.getModel('decal');
  53963. var useDecal = decalModel.get('show');
  53964. if (useDecal) {
  53965. // Each type of series use one scope.
  53966. // Pie and funnel are using diferrent scopes
  53967. var paletteScopeGroupByType_1 = createHashMap();
  53968. ecModel.eachSeries(function (seriesModel) {
  53969. if (seriesModel.isColorBySeries()) {
  53970. return;
  53971. }
  53972. var decalScope = paletteScopeGroupByType_1.get(seriesModel.type);
  53973. if (!decalScope) {
  53974. decalScope = {};
  53975. paletteScopeGroupByType_1.set(seriesModel.type, decalScope);
  53976. }
  53977. inner$h(seriesModel).scope = decalScope;
  53978. });
  53979. ecModel.eachRawSeries(function (seriesModel) {
  53980. if (ecModel.isSeriesFiltered(seriesModel)) {
  53981. return;
  53982. }
  53983. if (typeof seriesModel.enableAriaDecal === 'function') {
  53984. // Let series define how to use decal palette on data
  53985. seriesModel.enableAriaDecal();
  53986. return;
  53987. }
  53988. var data = seriesModel.getData();
  53989. if (!seriesModel.isColorBySeries()) {
  53990. var dataAll_1 = seriesModel.getRawData();
  53991. var idxMap_1 = {};
  53992. var decalScope_1 = inner$h(seriesModel).scope;
  53993. data.each(function (idx) {
  53994. var rawIdx = data.getRawIndex(idx);
  53995. idxMap_1[rawIdx] = idx;
  53996. });
  53997. var dataCount_1 = dataAll_1.count();
  53998. dataAll_1.each(function (rawIdx) {
  53999. var idx = idxMap_1[rawIdx];
  54000. var name = dataAll_1.getName(rawIdx) || rawIdx + '';
  54001. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, name, decalScope_1, dataCount_1);
  54002. var specifiedDecal = data.getItemVisual(idx, 'decal');
  54003. data.setItemVisual(idx, 'decal', mergeDecal(specifiedDecal, paletteDecal));
  54004. });
  54005. } else {
  54006. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, seriesModel.name, decalPaletteScope, ecModel.getSeriesCount());
  54007. var specifiedDecal = data.getVisual('decal');
  54008. data.setVisual('decal', mergeDecal(specifiedDecal, paletteDecal));
  54009. }
  54010. function mergeDecal(specifiedDecal, paletteDecal) {
  54011. // Merge decal from palette to decal from itemStyle.
  54012. // User do not need to specify all of the decal props.
  54013. var resultDecal = specifiedDecal ? extend(extend({}, paletteDecal), specifiedDecal) : paletteDecal;
  54014. resultDecal.dirty = true;
  54015. return resultDecal;
  54016. }
  54017. });
  54018. }
  54019. }
  54020. function setLabel() {
  54021. var labelLocale = ecModel.getLocaleModel().get('aria');
  54022. var labelModel = ariaModel.getModel('label');
  54023. labelModel.option = defaults(labelModel.option, labelLocale);
  54024. if (!labelModel.get('enabled')) {
  54025. return;
  54026. }
  54027. var dom = api.getZr().dom;
  54028. if (labelModel.get('description')) {
  54029. dom.setAttribute('aria-label', labelModel.get('description'));
  54030. return;
  54031. }
  54032. var seriesCnt = ecModel.getSeriesCount();
  54033. var maxDataCnt = labelModel.get(['data', 'maxCount']) || 10;
  54034. var maxSeriesCnt = labelModel.get(['series', 'maxCount']) || 10;
  54035. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  54036. var ariaLabel;
  54037. if (seriesCnt < 1) {
  54038. // No series, no aria label
  54039. return;
  54040. } else {
  54041. var title = getTitle();
  54042. if (title) {
  54043. var withTitle = labelModel.get(['general', 'withTitle']);
  54044. ariaLabel = replace(withTitle, {
  54045. title: title
  54046. });
  54047. } else {
  54048. ariaLabel = labelModel.get(['general', 'withoutTitle']);
  54049. }
  54050. var seriesLabels_1 = [];
  54051. var prefix = seriesCnt > 1 ? labelModel.get(['series', 'multiple', 'prefix']) : labelModel.get(['series', 'single', 'prefix']);
  54052. ariaLabel += replace(prefix, {
  54053. seriesCount: seriesCnt
  54054. });
  54055. ecModel.eachSeries(function (seriesModel, idx) {
  54056. if (idx < displaySeriesCnt) {
  54057. var seriesLabel = void 0;
  54058. var seriesName = seriesModel.get('name');
  54059. var withName = seriesName ? 'withName' : 'withoutName';
  54060. seriesLabel = seriesCnt > 1 ? labelModel.get(['series', 'multiple', withName]) : labelModel.get(['series', 'single', withName]);
  54061. seriesLabel = replace(seriesLabel, {
  54062. seriesId: seriesModel.seriesIndex,
  54063. seriesName: seriesModel.get('name'),
  54064. seriesType: getSeriesTypeName(seriesModel.subType)
  54065. });
  54066. var data = seriesModel.getData();
  54067. if (data.count() > maxDataCnt) {
  54068. // Show part of data
  54069. var partialLabel = labelModel.get(['data', 'partialData']);
  54070. seriesLabel += replace(partialLabel, {
  54071. displayCnt: maxDataCnt
  54072. });
  54073. } else {
  54074. seriesLabel += labelModel.get(['data', 'allData']);
  54075. }
  54076. var middleSeparator_1 = labelModel.get(['data', 'separator', 'middle']);
  54077. var endSeparator_1 = labelModel.get(['data', 'separator', 'end']);
  54078. var dataLabels = [];
  54079. for (var i = 0; i < data.count(); i++) {
  54080. if (i < maxDataCnt) {
  54081. var name_1 = data.getName(i);
  54082. var value = data.getValues(i);
  54083. var dataLabel = labelModel.get(['data', name_1 ? 'withName' : 'withoutName']);
  54084. dataLabels.push(replace(dataLabel, {
  54085. name: name_1,
  54086. value: value.join(middleSeparator_1)
  54087. }));
  54088. }
  54089. }
  54090. seriesLabel += dataLabels.join(middleSeparator_1) + endSeparator_1;
  54091. seriesLabels_1.push(seriesLabel);
  54092. }
  54093. });
  54094. var separatorModel = labelModel.getModel(['series', 'multiple', 'separator']);
  54095. var middleSeparator = separatorModel.get('middle');
  54096. var endSeparator = separatorModel.get('end');
  54097. ariaLabel += seriesLabels_1.join(middleSeparator) + endSeparator;
  54098. dom.setAttribute('aria-label', ariaLabel);
  54099. }
  54100. }
  54101. function replace(str, keyValues) {
  54102. if (typeof str !== 'string') {
  54103. return str;
  54104. }
  54105. var result = str;
  54106. each(keyValues, function (value, key) {
  54107. result = result.replace(new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'), value);
  54108. });
  54109. return result;
  54110. }
  54111. function getTitle() {
  54112. var title = ecModel.get('title');
  54113. if (title && title.length) {
  54114. title = title[0];
  54115. }
  54116. return title && title.text;
  54117. }
  54118. function getSeriesTypeName(type) {
  54119. return ecModel.getLocaleModel().get(['series', 'typeNames'])[type] || '自定义图';
  54120. }
  54121. }
  54122. function ariaPreprocessor(option) {
  54123. if (!option || !option.aria) {
  54124. return;
  54125. }
  54126. var aria = option.aria; // aria.show is deprecated and should use aria.enabled instead
  54127. if (aria.show != null) {
  54128. aria.enabled = aria.show;
  54129. }
  54130. aria.label = aria.label || {}; // move description, general, series, data to be under aria.label
  54131. each(['description', 'general', 'series', 'data'], function (name) {
  54132. if (aria[name] != null) {
  54133. aria.label[name] = aria[name];
  54134. }
  54135. });
  54136. }
  54137. function install$n(registers) {
  54138. registers.registerPreprocessor(ariaPreprocessor);
  54139. registers.registerVisual(registers.PRIORITY.VISUAL.ARIA, ariaVisual);
  54140. }
  54141. var DatasetModel =
  54142. /** @class */
  54143. function (_super) {
  54144. __extends(DatasetModel, _super);
  54145. function DatasetModel() {
  54146. var _this = _super !== null && _super.apply(this, arguments) || this;
  54147. _this.type = 'dataset';
  54148. return _this;
  54149. }
  54150. DatasetModel.prototype.init = function (option, parentModel, ecModel) {
  54151. _super.prototype.init.call(this, option, parentModel, ecModel);
  54152. this._sourceManager = new SourceManager(this);
  54153. disableTransformOptionMerge(this);
  54154. };
  54155. DatasetModel.prototype.mergeOption = function (newOption, ecModel) {
  54156. _super.prototype.mergeOption.call(this, newOption, ecModel);
  54157. disableTransformOptionMerge(this);
  54158. };
  54159. DatasetModel.prototype.optionUpdated = function () {
  54160. this._sourceManager.dirty();
  54161. };
  54162. DatasetModel.prototype.getSourceManager = function () {
  54163. return this._sourceManager;
  54164. };
  54165. DatasetModel.type = 'dataset';
  54166. DatasetModel.defaultOption = {
  54167. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN
  54168. };
  54169. return DatasetModel;
  54170. }(ComponentModel);
  54171. var DatasetView =
  54172. /** @class */
  54173. function (_super) {
  54174. __extends(DatasetView, _super);
  54175. function DatasetView() {
  54176. var _this = _super !== null && _super.apply(this, arguments) || this;
  54177. _this.type = 'dataset';
  54178. return _this;
  54179. }
  54180. DatasetView.type = 'dataset';
  54181. return DatasetView;
  54182. }(ComponentView);
  54183. function install$o(registers) {
  54184. registers.registerComponentModel(DatasetModel);
  54185. registers.registerComponentView(DatasetView);
  54186. }
  54187. use([install$1]);
  54188. use([install]);
  54189. use([install$2, install$3, install$4, install$6]);
  54190. use([install$9, install$c, install$7, install$j, install$8, install$d, install$e, install$f, install$g, install$m, install$b, install$n, install$o]);
  54191. exports.Axis = Axis;
  54192. exports.ChartView = ChartView;
  54193. exports.ComponentModel = ComponentModel;
  54194. exports.ComponentView = ComponentView;
  54195. exports.List = SeriesData;
  54196. exports.Model = Model;
  54197. exports.PRIORITY = PRIORITY;
  54198. exports.SeriesModel = SeriesModel;
  54199. exports.color = color;
  54200. exports.connect = connect;
  54201. exports.dataTool = dataTool;
  54202. exports.dependencies = dependencies;
  54203. exports.disConnect = disConnect;
  54204. exports.disconnect = disconnect;
  54205. exports.dispose = dispose$1;
  54206. exports.env = env;
  54207. exports.extendChartView = extendChartView;
  54208. exports.extendComponentModel = extendComponentModel;
  54209. exports.extendComponentView = extendComponentView;
  54210. exports.extendSeriesModel = extendSeriesModel;
  54211. exports.format = format$1;
  54212. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  54213. exports.getInstanceByDom = getInstanceByDom;
  54214. exports.getInstanceById = getInstanceById;
  54215. exports.getMap = getMap;
  54216. exports.graphic = graphic$1;
  54217. exports.helper = helper;
  54218. exports.init = init$1;
  54219. exports.innerDrawElementOnCanvas = brushSingle;
  54220. exports.matrix = matrix;
  54221. exports.number = number;
  54222. exports.parseGeoJSON = parseGeoJSON;
  54223. exports.parseGeoJson = parseGeoJSON;
  54224. exports.registerAction = registerAction;
  54225. exports.registerCoordinateSystem = registerCoordinateSystem;
  54226. exports.registerLayout = registerLayout;
  54227. exports.registerLoading = registerLoading;
  54228. exports.registerLocale = registerLocale;
  54229. exports.registerMap = registerMap;
  54230. exports.registerPostInit = registerPostInit;
  54231. exports.registerPostUpdate = registerPostUpdate;
  54232. exports.registerPreprocessor = registerPreprocessor;
  54233. exports.registerProcessor = registerProcessor;
  54234. exports.registerTheme = registerTheme;
  54235. exports.registerTransform = registerTransform;
  54236. exports.registerUpdateLifecycle = registerUpdateLifecycle;
  54237. exports.registerVisual = registerVisual;
  54238. exports.setCanvasCreator = setCanvasCreator;
  54239. exports.throttle = throttle;
  54240. exports.time = time;
  54241. exports.use = use;
  54242. exports.util = util$1;
  54243. exports.vector = vector;
  54244. exports.version = version$1;
  54245. exports.zrUtil = util;
  54246. exports.zrender = zrender;
  54247. Object.defineProperty(exports, '__esModule', { value: true });
  54248. })));
  54249. //# sourceMappingURL=echarts.common.js.map