echarts-en.common.js 1.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.echarts = {})));
  5. }(this, (function (exports) { 'use strict';
  6. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  7. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  8. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  9. // declaration is behind of the using position (for example in `Model.extent`,
  10. // And tools like rollup can not analysis the dependency if not import).
  11. var dev;
  12. // In browser
  13. if (typeof window !== 'undefined') {
  14. dev = window.__DEV__;
  15. }
  16. // In node
  17. else if (typeof global !== 'undefined') {
  18. dev = global.__DEV__;
  19. }
  20. if (typeof dev === 'undefined') {
  21. dev = true;
  22. }
  23. var __DEV__ = dev;
  24. /**
  25. * zrender: 生成唯一id
  26. *
  27. * @author errorrik (errorrik@gmail.com)
  28. */
  29. var idStart = 0x0907;
  30. var guid = function () {
  31. return idStart++;
  32. };
  33. /**
  34. * echarts设备环境识别
  35. *
  36. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  37. * @author firede[firede@firede.us]
  38. * @desc thanks zepto.
  39. */
  40. var env = {};
  41. if (typeof navigator === 'undefined') {
  42. // In node
  43. env = {
  44. browser: {},
  45. os: {},
  46. node: true,
  47. // Assume canvas is supported
  48. canvasSupported: true,
  49. svgSupported: true
  50. };
  51. }
  52. else {
  53. env = detect(navigator.userAgent);
  54. }
  55. var env$1 = env;
  56. // Zepto.js
  57. // (c) 2010-2013 Thomas Fuchs
  58. // Zepto.js may be freely distributed under the MIT license.
  59. function detect(ua) {
  60. var os = {};
  61. var browser = {};
  62. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  63. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  64. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  65. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  66. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  67. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  68. // var touchpad = webos && ua.match(/TouchPad/);
  69. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  70. // var silk = ua.match(/Silk\/([\d._]+)/);
  71. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  72. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  73. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  74. // var playbook = ua.match(/PlayBook/);
  75. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  76. var firefox = ua.match(/Firefox\/([\d.]+)/);
  77. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  78. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  79. var ie = ua.match(/MSIE\s([\d.]+)/)
  80. // IE 11 Trident/7.0; rv:11.0
  81. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  82. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  83. var weChat = (/micromessenger/i).test(ua);
  84. // Todo: clean this up with a better OS/browser seperation:
  85. // - discern (more) between multiple browsers on android
  86. // - decide if kindle fire in silk mode is android or not
  87. // - Firefox on Android doesn't specify the Android version
  88. // - possibly devide in os, device and browser hashes
  89. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  90. // if (android) os.android = true, os.version = android[2];
  91. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  92. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  93. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  94. // if (webos) os.webos = true, os.version = webos[2];
  95. // if (touchpad) os.touchpad = true;
  96. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  97. // if (bb10) os.bb10 = true, os.version = bb10[2];
  98. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  99. // if (playbook) browser.playbook = true;
  100. // if (kindle) os.kindle = true, os.version = kindle[1];
  101. // if (silk) browser.silk = true, browser.version = silk[1];
  102. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  103. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  104. if (firefox) {
  105. browser.firefox = true;
  106. browser.version = firefox[1];
  107. }
  108. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  109. // if (webview) browser.webview = true;
  110. if (ie) {
  111. browser.ie = true;
  112. browser.version = ie[1];
  113. }
  114. if (edge) {
  115. browser.edge = true;
  116. browser.version = edge[1];
  117. }
  118. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  119. // not be set on win phone. So we do not consider Win Phone.
  120. if (weChat) {
  121. browser.weChat = true;
  122. }
  123. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  124. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  125. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  126. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  127. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  128. return {
  129. browser: browser,
  130. os: os,
  131. node: false,
  132. // 原生canvas支持,改极端点了
  133. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  134. canvasSupported: !!document.createElement('canvas').getContext,
  135. svgSupported: typeof SVGRect !== 'undefined',
  136. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  137. // works on most browsers
  138. // IE10/11 does not support touch event, and MS Edge supports them but not by
  139. // default, so we dont check navigator.maxTouchPoints for them here.
  140. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  141. // <http://caniuse.com/#search=pointer%20event>.
  142. pointerEventsSupported: 'onpointerdown' in window
  143. // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  144. // events currently. So we dont use that on other browsers unless tested sufficiently.
  145. // Although IE 10 supports pointer event, it use old style and is different from the
  146. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  147. && (browser.edge || (browser.ie && browser.version >= 11))
  148. };
  149. }
  150. /**
  151. * @module zrender/core/util
  152. */
  153. // 用于处理merge时无法遍历Date等对象的问题
  154. var BUILTIN_OBJECT = {
  155. '[object Function]': 1,
  156. '[object RegExp]': 1,
  157. '[object Date]': 1,
  158. '[object Error]': 1,
  159. '[object CanvasGradient]': 1,
  160. '[object CanvasPattern]': 1,
  161. // For node-canvas
  162. '[object Image]': 1,
  163. '[object Canvas]': 1
  164. };
  165. var TYPED_ARRAY = {
  166. '[object Int8Array]': 1,
  167. '[object Uint8Array]': 1,
  168. '[object Uint8ClampedArray]': 1,
  169. '[object Int16Array]': 1,
  170. '[object Uint16Array]': 1,
  171. '[object Int32Array]': 1,
  172. '[object Uint32Array]': 1,
  173. '[object Float32Array]': 1,
  174. '[object Float64Array]': 1
  175. };
  176. var objToString = Object.prototype.toString;
  177. var arrayProto = Array.prototype;
  178. var nativeForEach = arrayProto.forEach;
  179. var nativeFilter = arrayProto.filter;
  180. var nativeSlice = arrayProto.slice;
  181. var nativeMap = arrayProto.map;
  182. var nativeReduce = arrayProto.reduce;
  183. // Avoid assign to an exported variable, for transforming to cjs.
  184. var methods = {};
  185. function $override(name, fn) {
  186. methods[name] = fn;
  187. }
  188. /**
  189. * Those data types can be cloned:
  190. * Plain object, Array, TypedArray, number, string, null, undefined.
  191. * Those data types will be assgined using the orginal data:
  192. * BUILTIN_OBJECT
  193. * Instance of user defined class will be cloned to a plain object, without
  194. * properties in prototype.
  195. * Other data types is not supported (not sure what will happen).
  196. *
  197. * Caution: do not support clone Date, for performance consideration.
  198. * (There might be a large number of date in `series.data`).
  199. * So date should not be modified in and out of echarts.
  200. *
  201. * @param {*} source
  202. * @return {*} new
  203. */
  204. function clone(source) {
  205. if (source == null || typeof source != 'object') {
  206. return source;
  207. }
  208. var result = source;
  209. var typeStr = objToString.call(source);
  210. if (typeStr === '[object Array]') {
  211. result = [];
  212. for (var i = 0, len = source.length; i < len; i++) {
  213. result[i] = clone(source[i]);
  214. }
  215. }
  216. else if (TYPED_ARRAY[typeStr]) {
  217. var Ctor = source.constructor;
  218. if (source.constructor.from) {
  219. result = Ctor.from(source);
  220. }
  221. else {
  222. result = new Ctor(source.length);
  223. for (var i = 0, len = source.length; i < len; i++) {
  224. result[i] = clone(source[i]);
  225. }
  226. }
  227. }
  228. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  229. result = {};
  230. for (var key in source) {
  231. if (source.hasOwnProperty(key)) {
  232. result[key] = clone(source[key]);
  233. }
  234. }
  235. }
  236. return result;
  237. }
  238. /**
  239. * @memberOf module:zrender/core/util
  240. * @param {*} target
  241. * @param {*} source
  242. * @param {boolean} [overwrite=false]
  243. */
  244. function merge(target, source, overwrite) {
  245. // We should escapse that source is string
  246. // and enter for ... in ...
  247. if (!isObject(source) || !isObject(target)) {
  248. return overwrite ? clone(source) : target;
  249. }
  250. for (var key in source) {
  251. if (source.hasOwnProperty(key)) {
  252. var targetProp = target[key];
  253. var sourceProp = source[key];
  254. if (isObject(sourceProp)
  255. && isObject(targetProp)
  256. && !isArray(sourceProp)
  257. && !isArray(targetProp)
  258. && !isDom(sourceProp)
  259. && !isDom(targetProp)
  260. && !isBuiltInObject(sourceProp)
  261. && !isBuiltInObject(targetProp)
  262. && !isPrimitive(sourceProp)
  263. && !isPrimitive(targetProp)
  264. ) {
  265. // 如果需要递归覆盖,就递归调用merge
  266. merge(targetProp, sourceProp, overwrite);
  267. }
  268. else if (overwrite || !(key in target)) {
  269. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  270. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  271. target[key] = clone(source[key], true);
  272. }
  273. }
  274. }
  275. return target;
  276. }
  277. /**
  278. * @param {Array} targetAndSources The first item is target, and the rests are source.
  279. * @param {boolean} [overwrite=false]
  280. * @return {*} target
  281. */
  282. function mergeAll(targetAndSources, overwrite) {
  283. var result = targetAndSources[0];
  284. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  285. result = merge(result, targetAndSources[i], overwrite);
  286. }
  287. return result;
  288. }
  289. /**
  290. * @param {*} target
  291. * @param {*} source
  292. * @memberOf module:zrender/core/util
  293. */
  294. function extend(target, source) {
  295. for (var key in source) {
  296. if (source.hasOwnProperty(key)) {
  297. target[key] = source[key];
  298. }
  299. }
  300. return target;
  301. }
  302. /**
  303. * @param {*} target
  304. * @param {*} source
  305. * @param {boolean} [overlay=false]
  306. * @memberOf module:zrender/core/util
  307. */
  308. function defaults(target, source, overlay) {
  309. for (var key in source) {
  310. if (source.hasOwnProperty(key)
  311. && (overlay ? source[key] != null : target[key] == null)
  312. ) {
  313. target[key] = source[key];
  314. }
  315. }
  316. return target;
  317. }
  318. var createCanvas = function () {
  319. return methods.createCanvas();
  320. };
  321. methods.createCanvas = function () {
  322. return document.createElement('canvas');
  323. };
  324. // FIXME
  325. var _ctx;
  326. function getContext() {
  327. if (!_ctx) {
  328. // Use util.createCanvas instead of createCanvas
  329. // because createCanvas may be overwritten in different environment
  330. _ctx = createCanvas().getContext('2d');
  331. }
  332. return _ctx;
  333. }
  334. /**
  335. * 查询数组中元素的index
  336. * @memberOf module:zrender/core/util
  337. */
  338. function indexOf(array, value) {
  339. if (array) {
  340. if (array.indexOf) {
  341. return array.indexOf(value);
  342. }
  343. for (var i = 0, len = array.length; i < len; i++) {
  344. if (array[i] === value) {
  345. return i;
  346. }
  347. }
  348. }
  349. return -1;
  350. }
  351. /**
  352. * 构造类继承关系
  353. *
  354. * @memberOf module:zrender/core/util
  355. * @param {Function} clazz 源类
  356. * @param {Function} baseClazz 基类
  357. */
  358. function inherits(clazz, baseClazz) {
  359. var clazzPrototype = clazz.prototype;
  360. function F() {}
  361. F.prototype = baseClazz.prototype;
  362. clazz.prototype = new F();
  363. for (var prop in clazzPrototype) {
  364. clazz.prototype[prop] = clazzPrototype[prop];
  365. }
  366. clazz.prototype.constructor = clazz;
  367. clazz.superClass = baseClazz;
  368. }
  369. /**
  370. * @memberOf module:zrender/core/util
  371. * @param {Object|Function} target
  372. * @param {Object|Function} sorce
  373. * @param {boolean} overlay
  374. */
  375. function mixin(target, source, overlay) {
  376. target = 'prototype' in target ? target.prototype : target;
  377. source = 'prototype' in source ? source.prototype : source;
  378. defaults(target, source, overlay);
  379. }
  380. /**
  381. * Consider typed array.
  382. * @param {Array|TypedArray} data
  383. */
  384. function isArrayLike(data) {
  385. if (! data) {
  386. return;
  387. }
  388. if (typeof data == 'string') {
  389. return false;
  390. }
  391. return typeof data.length == 'number';
  392. }
  393. /**
  394. * 数组或对象遍历
  395. * @memberOf module:zrender/core/util
  396. * @param {Object|Array} obj
  397. * @param {Function} cb
  398. * @param {*} [context]
  399. */
  400. function each$1(obj, cb, context) {
  401. if (!(obj && cb)) {
  402. return;
  403. }
  404. if (obj.forEach && obj.forEach === nativeForEach) {
  405. obj.forEach(cb, context);
  406. }
  407. else if (obj.length === +obj.length) {
  408. for (var i = 0, len = obj.length; i < len; i++) {
  409. cb.call(context, obj[i], i, obj);
  410. }
  411. }
  412. else {
  413. for (var key in obj) {
  414. if (obj.hasOwnProperty(key)) {
  415. cb.call(context, obj[key], key, obj);
  416. }
  417. }
  418. }
  419. }
  420. /**
  421. * 数组映射
  422. * @memberOf module:zrender/core/util
  423. * @param {Array} obj
  424. * @param {Function} cb
  425. * @param {*} [context]
  426. * @return {Array}
  427. */
  428. function map(obj, cb, context) {
  429. if (!(obj && cb)) {
  430. return;
  431. }
  432. if (obj.map && obj.map === nativeMap) {
  433. return obj.map(cb, context);
  434. }
  435. else {
  436. var result = [];
  437. for (var i = 0, len = obj.length; i < len; i++) {
  438. result.push(cb.call(context, obj[i], i, obj));
  439. }
  440. return result;
  441. }
  442. }
  443. /**
  444. * @memberOf module:zrender/core/util
  445. * @param {Array} obj
  446. * @param {Function} cb
  447. * @param {Object} [memo]
  448. * @param {*} [context]
  449. * @return {Array}
  450. */
  451. function reduce(obj, cb, memo, context) {
  452. if (!(obj && cb)) {
  453. return;
  454. }
  455. if (obj.reduce && obj.reduce === nativeReduce) {
  456. return obj.reduce(cb, memo, context);
  457. }
  458. else {
  459. for (var i = 0, len = obj.length; i < len; i++) {
  460. memo = cb.call(context, memo, obj[i], i, obj);
  461. }
  462. return memo;
  463. }
  464. }
  465. /**
  466. * 数组过滤
  467. * @memberOf module:zrender/core/util
  468. * @param {Array} obj
  469. * @param {Function} cb
  470. * @param {*} [context]
  471. * @return {Array}
  472. */
  473. function filter(obj, cb, context) {
  474. if (!(obj && cb)) {
  475. return;
  476. }
  477. if (obj.filter && obj.filter === nativeFilter) {
  478. return obj.filter(cb, context);
  479. }
  480. else {
  481. var result = [];
  482. for (var i = 0, len = obj.length; i < len; i++) {
  483. if (cb.call(context, obj[i], i, obj)) {
  484. result.push(obj[i]);
  485. }
  486. }
  487. return result;
  488. }
  489. }
  490. /**
  491. * 数组项查找
  492. * @memberOf module:zrender/core/util
  493. * @param {Array} obj
  494. * @param {Function} cb
  495. * @param {*} [context]
  496. * @return {*}
  497. */
  498. function find(obj, cb, context) {
  499. if (!(obj && cb)) {
  500. return;
  501. }
  502. for (var i = 0, len = obj.length; i < len; i++) {
  503. if (cb.call(context, obj[i], i, obj)) {
  504. return obj[i];
  505. }
  506. }
  507. }
  508. /**
  509. * @memberOf module:zrender/core/util
  510. * @param {Function} func
  511. * @param {*} context
  512. * @return {Function}
  513. */
  514. function bind(func, context) {
  515. var args = nativeSlice.call(arguments, 2);
  516. return function () {
  517. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  518. };
  519. }
  520. /**
  521. * @memberOf module:zrender/core/util
  522. * @param {Function} func
  523. * @return {Function}
  524. */
  525. function curry(func) {
  526. var args = nativeSlice.call(arguments, 1);
  527. return function () {
  528. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  529. };
  530. }
  531. /**
  532. * @memberOf module:zrender/core/util
  533. * @param {*} value
  534. * @return {boolean}
  535. */
  536. function isArray(value) {
  537. return objToString.call(value) === '[object Array]';
  538. }
  539. /**
  540. * @memberOf module:zrender/core/util
  541. * @param {*} value
  542. * @return {boolean}
  543. */
  544. function isFunction(value) {
  545. return typeof value === 'function';
  546. }
  547. /**
  548. * @memberOf module:zrender/core/util
  549. * @param {*} value
  550. * @return {boolean}
  551. */
  552. function isString(value) {
  553. return objToString.call(value) === '[object String]';
  554. }
  555. /**
  556. * @memberOf module:zrender/core/util
  557. * @param {*} value
  558. * @return {boolean}
  559. */
  560. function isObject(value) {
  561. // Avoid a V8 JIT bug in Chrome 19-20.
  562. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  563. var type = typeof value;
  564. return type === 'function' || (!!value && type == 'object');
  565. }
  566. /**
  567. * @memberOf module:zrender/core/util
  568. * @param {*} value
  569. * @return {boolean}
  570. */
  571. function isBuiltInObject(value) {
  572. return !!BUILTIN_OBJECT[objToString.call(value)];
  573. }
  574. /**
  575. * @memberOf module:zrender/core/util
  576. * @param {*} value
  577. * @return {boolean}
  578. */
  579. function isDom(value) {
  580. return typeof value === 'object'
  581. && typeof value.nodeType === 'number'
  582. && typeof value.ownerDocument === 'object';
  583. }
  584. /**
  585. * Whether is exactly NaN. Notice isNaN('a') returns true.
  586. * @param {*} value
  587. * @return {boolean}
  588. */
  589. function eqNaN(value) {
  590. return value !== value;
  591. }
  592. /**
  593. * If value1 is not null, then return value1, otherwise judget rest of values.
  594. * Low performance.
  595. * @memberOf module:zrender/core/util
  596. * @return {*} Final value
  597. */
  598. function retrieve(values) {
  599. for (var i = 0, len = arguments.length; i < len; i++) {
  600. if (arguments[i] != null) {
  601. return arguments[i];
  602. }
  603. }
  604. }
  605. function retrieve2(value0, value1) {
  606. return value0 != null
  607. ? value0
  608. : value1;
  609. }
  610. function retrieve3(value0, value1, value2) {
  611. return value0 != null
  612. ? value0
  613. : value1 != null
  614. ? value1
  615. : value2;
  616. }
  617. /**
  618. * @memberOf module:zrender/core/util
  619. * @param {Array} arr
  620. * @param {number} startIndex
  621. * @param {number} endIndex
  622. * @return {Array}
  623. */
  624. function slice() {
  625. return Function.call.apply(nativeSlice, arguments);
  626. }
  627. /**
  628. * Normalize css liked array configuration
  629. * e.g.
  630. * 3 => [3, 3, 3, 3]
  631. * [4, 2] => [4, 2, 4, 2]
  632. * [4, 3, 2] => [4, 3, 2, 3]
  633. * @param {number|Array.<number>} val
  634. * @return {Array.<number>}
  635. */
  636. function normalizeCssArray(val) {
  637. if (typeof (val) === 'number') {
  638. return [val, val, val, val];
  639. }
  640. var len = val.length;
  641. if (len === 2) {
  642. // vertical | horizontal
  643. return [val[0], val[1], val[0], val[1]];
  644. }
  645. else if (len === 3) {
  646. // top | horizontal | bottom
  647. return [val[0], val[1], val[2], val[1]];
  648. }
  649. return val;
  650. }
  651. /**
  652. * @memberOf module:zrender/core/util
  653. * @param {boolean} condition
  654. * @param {string} message
  655. */
  656. function assert(condition, message) {
  657. if (!condition) {
  658. throw new Error(message);
  659. }
  660. }
  661. var primitiveKey = '__ec_primitive__';
  662. /**
  663. * Set an object as primitive to be ignored traversing children in clone or merge
  664. */
  665. function setAsPrimitive(obj) {
  666. obj[primitiveKey] = true;
  667. }
  668. function isPrimitive(obj) {
  669. return obj[primitiveKey];
  670. }
  671. /**
  672. * @constructor
  673. * @param {Object} obj Only apply `ownProperty`.
  674. */
  675. function HashMap(obj) {
  676. obj && each$1(obj, function (value, key) {
  677. this.set(key, value);
  678. }, this);
  679. }
  680. // Add prefix to avoid conflict with Object.prototype.
  681. var HASH_MAP_PREFIX = '_ec_';
  682. var HASH_MAP_PREFIX_LENGTH = 4;
  683. HashMap.prototype = {
  684. constructor: HashMap,
  685. // Do not provide `has` method to avoid defining what is `has`.
  686. // (We usually treat `null` and `undefined` as the same, different
  687. // from ES6 Map).
  688. get: function (key) {
  689. return this[HASH_MAP_PREFIX + key];
  690. },
  691. set: function (key, value) {
  692. this[HASH_MAP_PREFIX + key] = value;
  693. // Comparing with invocation chaining, `return value` is more commonly
  694. // used in this case: `var someVal = map.set('a', genVal());`
  695. return value;
  696. },
  697. // Although util.each can be performed on this hashMap directly, user
  698. // should not use the exposed keys, who are prefixed.
  699. each: function (cb, context) {
  700. context !== void 0 && (cb = bind(cb, context));
  701. for (var prefixedKey in this) {
  702. this.hasOwnProperty(prefixedKey)
  703. && cb(this[prefixedKey], prefixedKey.slice(HASH_MAP_PREFIX_LENGTH));
  704. }
  705. },
  706. // Do not use this method if performance sensitive.
  707. removeKey: function (key) {
  708. delete this[HASH_MAP_PREFIX + key];
  709. }
  710. };
  711. function createHashMap(obj) {
  712. return new HashMap(obj);
  713. }
  714. function noop() {}
  715. var zrUtil = (Object.freeze || Object)({
  716. $override: $override,
  717. clone: clone,
  718. merge: merge,
  719. mergeAll: mergeAll,
  720. extend: extend,
  721. defaults: defaults,
  722. createCanvas: createCanvas,
  723. getContext: getContext,
  724. indexOf: indexOf,
  725. inherits: inherits,
  726. mixin: mixin,
  727. isArrayLike: isArrayLike,
  728. each: each$1,
  729. map: map,
  730. reduce: reduce,
  731. filter: filter,
  732. find: find,
  733. bind: bind,
  734. curry: curry,
  735. isArray: isArray,
  736. isFunction: isFunction,
  737. isString: isString,
  738. isObject: isObject,
  739. isBuiltInObject: isBuiltInObject,
  740. isDom: isDom,
  741. eqNaN: eqNaN,
  742. retrieve: retrieve,
  743. retrieve2: retrieve2,
  744. retrieve3: retrieve3,
  745. slice: slice,
  746. normalizeCssArray: normalizeCssArray,
  747. assert: assert,
  748. setAsPrimitive: setAsPrimitive,
  749. isPrimitive: isPrimitive,
  750. createHashMap: createHashMap,
  751. noop: noop
  752. });
  753. var ArrayCtor = typeof Float32Array === 'undefined'
  754. ? Array
  755. : Float32Array;
  756. /**
  757. * 创建一个向量
  758. * @param {number} [x=0]
  759. * @param {number} [y=0]
  760. * @return {Vector2}
  761. */
  762. function create(x, y) {
  763. var out = new ArrayCtor(2);
  764. if (x == null) {
  765. x = 0;
  766. }
  767. if (y == null) {
  768. y = 0;
  769. }
  770. out[0] = x;
  771. out[1] = y;
  772. return out;
  773. }
  774. /**
  775. * 复制向量数据
  776. * @param {Vector2} out
  777. * @param {Vector2} v
  778. * @return {Vector2}
  779. */
  780. function copy(out, v) {
  781. out[0] = v[0];
  782. out[1] = v[1];
  783. return out;
  784. }
  785. /**
  786. * 克隆一个向量
  787. * @param {Vector2} v
  788. * @return {Vector2}
  789. */
  790. function clone$1(v) {
  791. var out = new ArrayCtor(2);
  792. out[0] = v[0];
  793. out[1] = v[1];
  794. return out;
  795. }
  796. /**
  797. * 设置向量的两个项
  798. * @param {Vector2} out
  799. * @param {number} a
  800. * @param {number} b
  801. * @return {Vector2} 结果
  802. */
  803. function set(out, a, b) {
  804. out[0] = a;
  805. out[1] = b;
  806. return out;
  807. }
  808. /**
  809. * 向量相加
  810. * @param {Vector2} out
  811. * @param {Vector2} v1
  812. * @param {Vector2} v2
  813. */
  814. function add(out, v1, v2) {
  815. out[0] = v1[0] + v2[0];
  816. out[1] = v1[1] + v2[1];
  817. return out;
  818. }
  819. /**
  820. * 向量缩放后相加
  821. * @param {Vector2} out
  822. * @param {Vector2} v1
  823. * @param {Vector2} v2
  824. * @param {number} a
  825. */
  826. function scaleAndAdd(out, v1, v2, a) {
  827. out[0] = v1[0] + v2[0] * a;
  828. out[1] = v1[1] + v2[1] * a;
  829. return out;
  830. }
  831. /**
  832. * 向量相减
  833. * @param {Vector2} out
  834. * @param {Vector2} v1
  835. * @param {Vector2} v2
  836. */
  837. function sub(out, v1, v2) {
  838. out[0] = v1[0] - v2[0];
  839. out[1] = v1[1] - v2[1];
  840. return out;
  841. }
  842. /**
  843. * 向量长度
  844. * @param {Vector2} v
  845. * @return {number}
  846. */
  847. function len(v) {
  848. return Math.sqrt(lenSquare(v));
  849. }
  850. var length = len; // jshint ignore:line
  851. /**
  852. * 向量长度平方
  853. * @param {Vector2} v
  854. * @return {number}
  855. */
  856. function lenSquare(v) {
  857. return v[0] * v[0] + v[1] * v[1];
  858. }
  859. var lengthSquare = lenSquare;
  860. /**
  861. * 向量乘法
  862. * @param {Vector2} out
  863. * @param {Vector2} v1
  864. * @param {Vector2} v2
  865. */
  866. function mul(out, v1, v2) {
  867. out[0] = v1[0] * v2[0];
  868. out[1] = v1[1] * v2[1];
  869. return out;
  870. }
  871. /**
  872. * 向量除法
  873. * @param {Vector2} out
  874. * @param {Vector2} v1
  875. * @param {Vector2} v2
  876. */
  877. function div(out, v1, v2) {
  878. out[0] = v1[0] / v2[0];
  879. out[1] = v1[1] / v2[1];
  880. return out;
  881. }
  882. /**
  883. * 向量点乘
  884. * @param {Vector2} v1
  885. * @param {Vector2} v2
  886. * @return {number}
  887. */
  888. function dot(v1, v2) {
  889. return v1[0] * v2[0] + v1[1] * v2[1];
  890. }
  891. /**
  892. * 向量缩放
  893. * @param {Vector2} out
  894. * @param {Vector2} v
  895. * @param {number} s
  896. */
  897. function scale(out, v, s) {
  898. out[0] = v[0] * s;
  899. out[1] = v[1] * s;
  900. return out;
  901. }
  902. /**
  903. * 向量归一化
  904. * @param {Vector2} out
  905. * @param {Vector2} v
  906. */
  907. function normalize(out, v) {
  908. var d = len(v);
  909. if (d === 0) {
  910. out[0] = 0;
  911. out[1] = 0;
  912. }
  913. else {
  914. out[0] = v[0] / d;
  915. out[1] = v[1] / d;
  916. }
  917. return out;
  918. }
  919. /**
  920. * 计算向量间距离
  921. * @param {Vector2} v1
  922. * @param {Vector2} v2
  923. * @return {number}
  924. */
  925. function distance(v1, v2) {
  926. return Math.sqrt(
  927. (v1[0] - v2[0]) * (v1[0] - v2[0])
  928. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  929. );
  930. }
  931. var dist = distance;
  932. /**
  933. * 向量距离平方
  934. * @param {Vector2} v1
  935. * @param {Vector2} v2
  936. * @return {number}
  937. */
  938. function distanceSquare(v1, v2) {
  939. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  940. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  941. }
  942. var distSquare = distanceSquare;
  943. /**
  944. * 求负向量
  945. * @param {Vector2} out
  946. * @param {Vector2} v
  947. */
  948. function negate(out, v) {
  949. out[0] = -v[0];
  950. out[1] = -v[1];
  951. return out;
  952. }
  953. /**
  954. * 插值两个点
  955. * @param {Vector2} out
  956. * @param {Vector2} v1
  957. * @param {Vector2} v2
  958. * @param {number} t
  959. */
  960. function lerp(out, v1, v2, t) {
  961. out[0] = v1[0] + t * (v2[0] - v1[0]);
  962. out[1] = v1[1] + t * (v2[1] - v1[1]);
  963. return out;
  964. }
  965. /**
  966. * 矩阵左乘向量
  967. * @param {Vector2} out
  968. * @param {Vector2} v
  969. * @param {Vector2} m
  970. */
  971. function applyTransform(out, v, m) {
  972. var x = v[0];
  973. var y = v[1];
  974. out[0] = m[0] * x + m[2] * y + m[4];
  975. out[1] = m[1] * x + m[3] * y + m[5];
  976. return out;
  977. }
  978. /**
  979. * 求两个向量最小值
  980. * @param {Vector2} out
  981. * @param {Vector2} v1
  982. * @param {Vector2} v2
  983. */
  984. function min(out, v1, v2) {
  985. out[0] = Math.min(v1[0], v2[0]);
  986. out[1] = Math.min(v1[1], v2[1]);
  987. return out;
  988. }
  989. /**
  990. * 求两个向量最大值
  991. * @param {Vector2} out
  992. * @param {Vector2} v1
  993. * @param {Vector2} v2
  994. */
  995. function max(out, v1, v2) {
  996. out[0] = Math.max(v1[0], v2[0]);
  997. out[1] = Math.max(v1[1], v2[1]);
  998. return out;
  999. }
  1000. var vector = (Object.freeze || Object)({
  1001. create: create,
  1002. copy: copy,
  1003. clone: clone$1,
  1004. set: set,
  1005. add: add,
  1006. scaleAndAdd: scaleAndAdd,
  1007. sub: sub,
  1008. len: len,
  1009. length: length,
  1010. lenSquare: lenSquare,
  1011. lengthSquare: lengthSquare,
  1012. mul: mul,
  1013. div: div,
  1014. dot: dot,
  1015. scale: scale,
  1016. normalize: normalize,
  1017. distance: distance,
  1018. dist: dist,
  1019. distanceSquare: distanceSquare,
  1020. distSquare: distSquare,
  1021. negate: negate,
  1022. lerp: lerp,
  1023. applyTransform: applyTransform,
  1024. min: min,
  1025. max: max
  1026. });
  1027. // TODO Draggable for group
  1028. // FIXME Draggable on element which has parent rotation or scale
  1029. function Draggable() {
  1030. this.on('mousedown', this._dragStart, this);
  1031. this.on('mousemove', this._drag, this);
  1032. this.on('mouseup', this._dragEnd, this);
  1033. this.on('globalout', this._dragEnd, this);
  1034. // this._dropTarget = null;
  1035. // this._draggingTarget = null;
  1036. // this._x = 0;
  1037. // this._y = 0;
  1038. }
  1039. Draggable.prototype = {
  1040. constructor: Draggable,
  1041. _dragStart: function (e) {
  1042. var draggingTarget = e.target;
  1043. if (draggingTarget && draggingTarget.draggable) {
  1044. this._draggingTarget = draggingTarget;
  1045. draggingTarget.dragging = true;
  1046. this._x = e.offsetX;
  1047. this._y = e.offsetY;
  1048. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  1049. }
  1050. },
  1051. _drag: function (e) {
  1052. var draggingTarget = this._draggingTarget;
  1053. if (draggingTarget) {
  1054. var x = e.offsetX;
  1055. var y = e.offsetY;
  1056. var dx = x - this._x;
  1057. var dy = y - this._y;
  1058. this._x = x;
  1059. this._y = y;
  1060. draggingTarget.drift(dx, dy, e);
  1061. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  1062. var dropTarget = this.findHover(x, y, draggingTarget).target;
  1063. var lastDropTarget = this._dropTarget;
  1064. this._dropTarget = dropTarget;
  1065. if (draggingTarget !== dropTarget) {
  1066. if (lastDropTarget && dropTarget !== lastDropTarget) {
  1067. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  1068. }
  1069. if (dropTarget && dropTarget !== lastDropTarget) {
  1070. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  1071. }
  1072. }
  1073. }
  1074. },
  1075. _dragEnd: function (e) {
  1076. var draggingTarget = this._draggingTarget;
  1077. if (draggingTarget) {
  1078. draggingTarget.dragging = false;
  1079. }
  1080. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  1081. if (this._dropTarget) {
  1082. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  1083. }
  1084. this._draggingTarget = null;
  1085. this._dropTarget = null;
  1086. }
  1087. };
  1088. function param(target, e) {
  1089. return {target: target, topTarget: e && e.topTarget};
  1090. }
  1091. /**
  1092. * 事件扩展
  1093. * @module zrender/mixin/Eventful
  1094. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1095. * pissang (https://www.github.com/pissang)
  1096. */
  1097. var arrySlice = Array.prototype.slice;
  1098. /**
  1099. * 事件分发器
  1100. * @alias module:zrender/mixin/Eventful
  1101. * @constructor
  1102. */
  1103. var Eventful = function () {
  1104. this._$handlers = {};
  1105. };
  1106. Eventful.prototype = {
  1107. constructor: Eventful,
  1108. /**
  1109. * 单次触发绑定,trigger后销毁
  1110. *
  1111. * @param {string} event 事件名
  1112. * @param {Function} handler 响应函数
  1113. * @param {Object} context
  1114. */
  1115. one: function (event, handler, context) {
  1116. var _h = this._$handlers;
  1117. if (!handler || !event) {
  1118. return this;
  1119. }
  1120. if (!_h[event]) {
  1121. _h[event] = [];
  1122. }
  1123. for (var i = 0; i < _h[event].length; i++) {
  1124. if (_h[event][i].h === handler) {
  1125. return this;
  1126. }
  1127. }
  1128. _h[event].push({
  1129. h: handler,
  1130. one: true,
  1131. ctx: context || this
  1132. });
  1133. return this;
  1134. },
  1135. /**
  1136. * 绑定事件
  1137. * @param {string} event 事件名
  1138. * @param {Function} handler 事件处理函数
  1139. * @param {Object} [context]
  1140. */
  1141. on: function (event, handler, context) {
  1142. var _h = this._$handlers;
  1143. if (!handler || !event) {
  1144. return this;
  1145. }
  1146. if (!_h[event]) {
  1147. _h[event] = [];
  1148. }
  1149. for (var i = 0; i < _h[event].length; i++) {
  1150. if (_h[event][i].h === handler) {
  1151. return this;
  1152. }
  1153. }
  1154. _h[event].push({
  1155. h: handler,
  1156. one: false,
  1157. ctx: context || this
  1158. });
  1159. return this;
  1160. },
  1161. /**
  1162. * 是否绑定了事件
  1163. * @param {string} event
  1164. * @return {boolean}
  1165. */
  1166. isSilent: function (event) {
  1167. var _h = this._$handlers;
  1168. return _h[event] && _h[event].length;
  1169. },
  1170. /**
  1171. * 解绑事件
  1172. * @param {string} event 事件名
  1173. * @param {Function} [handler] 事件处理函数
  1174. */
  1175. off: function (event, handler) {
  1176. var _h = this._$handlers;
  1177. if (!event) {
  1178. this._$handlers = {};
  1179. return this;
  1180. }
  1181. if (handler) {
  1182. if (_h[event]) {
  1183. var newList = [];
  1184. for (var i = 0, l = _h[event].length; i < l; i++) {
  1185. if (_h[event][i]['h'] != handler) {
  1186. newList.push(_h[event][i]);
  1187. }
  1188. }
  1189. _h[event] = newList;
  1190. }
  1191. if (_h[event] && _h[event].length === 0) {
  1192. delete _h[event];
  1193. }
  1194. }
  1195. else {
  1196. delete _h[event];
  1197. }
  1198. return this;
  1199. },
  1200. /**
  1201. * 事件分发
  1202. *
  1203. * @param {string} type 事件类型
  1204. */
  1205. trigger: function (type) {
  1206. if (this._$handlers[type]) {
  1207. var args = arguments;
  1208. var argLen = args.length;
  1209. if (argLen > 3) {
  1210. args = arrySlice.call(args, 1);
  1211. }
  1212. var _h = this._$handlers[type];
  1213. var len = _h.length;
  1214. for (var i = 0; i < len;) {
  1215. // Optimize advise from backbone
  1216. switch (argLen) {
  1217. case 1:
  1218. _h[i]['h'].call(_h[i]['ctx']);
  1219. break;
  1220. case 2:
  1221. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  1222. break;
  1223. case 3:
  1224. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  1225. break;
  1226. default:
  1227. // have more than 2 given arguments
  1228. _h[i]['h'].apply(_h[i]['ctx'], args);
  1229. break;
  1230. }
  1231. if (_h[i]['one']) {
  1232. _h.splice(i, 1);
  1233. len--;
  1234. }
  1235. else {
  1236. i++;
  1237. }
  1238. }
  1239. }
  1240. return this;
  1241. },
  1242. /**
  1243. * 带有context的事件分发, 最后一个参数是事件回调的context
  1244. * @param {string} type 事件类型
  1245. */
  1246. triggerWithContext: function (type) {
  1247. if (this._$handlers[type]) {
  1248. var args = arguments;
  1249. var argLen = args.length;
  1250. if (argLen > 4) {
  1251. args = arrySlice.call(args, 1, args.length - 1);
  1252. }
  1253. var ctx = args[args.length - 1];
  1254. var _h = this._$handlers[type];
  1255. var len = _h.length;
  1256. for (var i = 0; i < len;) {
  1257. // Optimize advise from backbone
  1258. switch (argLen) {
  1259. case 1:
  1260. _h[i]['h'].call(ctx);
  1261. break;
  1262. case 2:
  1263. _h[i]['h'].call(ctx, args[1]);
  1264. break;
  1265. case 3:
  1266. _h[i]['h'].call(ctx, args[1], args[2]);
  1267. break;
  1268. default:
  1269. // have more than 2 given arguments
  1270. _h[i]['h'].apply(ctx, args);
  1271. break;
  1272. }
  1273. if (_h[i]['one']) {
  1274. _h.splice(i, 1);
  1275. len--;
  1276. }
  1277. else {
  1278. i++;
  1279. }
  1280. }
  1281. }
  1282. return this;
  1283. }
  1284. };
  1285. /**
  1286. * Handler
  1287. * @module zrender/Handler
  1288. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1289. * errorrik (errorrik@gmail.com)
  1290. * pissang (shenyi.914@gmail.com)
  1291. */
  1292. var SILENT = 'silent';
  1293. function makeEventPacket(eveType, targetInfo, event) {
  1294. return {
  1295. type: eveType,
  1296. event: event,
  1297. // target can only be an element that is not silent.
  1298. target: targetInfo.target,
  1299. // topTarget can be a silent element.
  1300. topTarget: targetInfo.topTarget,
  1301. cancelBubble: false,
  1302. offsetX: event.zrX,
  1303. offsetY: event.zrY,
  1304. gestureEvent: event.gestureEvent,
  1305. pinchX: event.pinchX,
  1306. pinchY: event.pinchY,
  1307. pinchScale: event.pinchScale,
  1308. wheelDelta: event.zrDelta,
  1309. zrByTouch: event.zrByTouch,
  1310. which: event.which
  1311. };
  1312. }
  1313. function EmptyProxy () {}
  1314. EmptyProxy.prototype.dispose = function () {};
  1315. var handlerNames = [
  1316. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1317. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1318. ];
  1319. /**
  1320. * @alias module:zrender/Handler
  1321. * @constructor
  1322. * @extends module:zrender/mixin/Eventful
  1323. * @param {module:zrender/Storage} storage Storage instance.
  1324. * @param {module:zrender/Painter} painter Painter instance.
  1325. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1326. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1327. */
  1328. var Handler = function(storage, painter, proxy, painterRoot) {
  1329. Eventful.call(this);
  1330. this.storage = storage;
  1331. this.painter = painter;
  1332. this.painterRoot = painterRoot;
  1333. proxy = proxy || new EmptyProxy();
  1334. /**
  1335. * Proxy of event. can be Dom, WebGLSurface, etc.
  1336. */
  1337. this.proxy = proxy;
  1338. // Attach handler
  1339. proxy.handler = this;
  1340. /**
  1341. * {target, topTarget, x, y}
  1342. * @private
  1343. * @type {Object}
  1344. */
  1345. this._hovered = {};
  1346. /**
  1347. * @private
  1348. * @type {Date}
  1349. */
  1350. this._lastTouchMoment;
  1351. /**
  1352. * @private
  1353. * @type {number}
  1354. */
  1355. this._lastX;
  1356. /**
  1357. * @private
  1358. * @type {number}
  1359. */
  1360. this._lastY;
  1361. Draggable.call(this);
  1362. each$1(handlerNames, function (name) {
  1363. proxy.on && proxy.on(name, this[name], this);
  1364. }, this);
  1365. };
  1366. Handler.prototype = {
  1367. constructor: Handler,
  1368. mousemove: function (event) {
  1369. var x = event.zrX;
  1370. var y = event.zrY;
  1371. var lastHovered = this._hovered;
  1372. var lastHoveredTarget = lastHovered.target;
  1373. // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  1374. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  1375. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  1376. // See #6198.
  1377. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1378. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1379. lastHoveredTarget = lastHovered.target;
  1380. }
  1381. var hovered = this._hovered = this.findHover(x, y);
  1382. var hoveredTarget = hovered.target;
  1383. var proxy = this.proxy;
  1384. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  1385. // Mouse out on previous hovered element
  1386. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1387. this.dispatchToElement(lastHovered, 'mouseout', event);
  1388. }
  1389. // Mouse moving on one element
  1390. this.dispatchToElement(hovered, 'mousemove', event);
  1391. // Mouse over on a new element
  1392. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1393. this.dispatchToElement(hovered, 'mouseover', event);
  1394. }
  1395. },
  1396. mouseout: function (event) {
  1397. this.dispatchToElement(this._hovered, 'mouseout', event);
  1398. // There might be some doms created by upper layer application
  1399. // at the same level of painter.getViewportRoot() (e.g., tooltip
  1400. // dom created by echarts), where 'globalout' event should not
  1401. // be triggered when mouse enters these doms. (But 'mouseout'
  1402. // should be triggered at the original hovered element as usual).
  1403. var element = event.toElement || event.relatedTarget;
  1404. var innerDom;
  1405. do {
  1406. element = element && element.parentNode;
  1407. }
  1408. while (element && element.nodeType != 9 && !(
  1409. innerDom = element === this.painterRoot
  1410. ));
  1411. !innerDom && this.trigger('globalout', {event: event});
  1412. },
  1413. /**
  1414. * Resize
  1415. */
  1416. resize: function (event) {
  1417. this._hovered = {};
  1418. },
  1419. /**
  1420. * Dispatch event
  1421. * @param {string} eventName
  1422. * @param {event=} eventArgs
  1423. */
  1424. dispatch: function (eventName, eventArgs) {
  1425. var handler = this[eventName];
  1426. handler && handler.call(this, eventArgs);
  1427. },
  1428. /**
  1429. * Dispose
  1430. */
  1431. dispose: function () {
  1432. this.proxy.dispose();
  1433. this.storage =
  1434. this.proxy =
  1435. this.painter = null;
  1436. },
  1437. /**
  1438. * 设置默认的cursor style
  1439. * @param {string} [cursorStyle='default'] 例如 crosshair
  1440. */
  1441. setCursorStyle: function (cursorStyle) {
  1442. var proxy = this.proxy;
  1443. proxy.setCursor && proxy.setCursor(cursorStyle);
  1444. },
  1445. /**
  1446. * 事件分发代理
  1447. *
  1448. * @private
  1449. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  1450. * @param {string} eventName 事件名称
  1451. * @param {Object} event 事件对象
  1452. */
  1453. dispatchToElement: function (targetInfo, eventName, event) {
  1454. targetInfo = targetInfo || {};
  1455. var el = targetInfo.target;
  1456. if (el && el.silent) {
  1457. return;
  1458. }
  1459. var eventHandler = 'on' + eventName;
  1460. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  1461. while (el) {
  1462. el[eventHandler]
  1463. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  1464. el.trigger(eventName, eventPacket);
  1465. el = el.parent;
  1466. if (eventPacket.cancelBubble) {
  1467. break;
  1468. }
  1469. }
  1470. if (!eventPacket.cancelBubble) {
  1471. // 冒泡到顶级 zrender 对象
  1472. this.trigger(eventName, eventPacket);
  1473. // 分发事件到用户自定义层
  1474. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  1475. this.painter && this.painter.eachOtherLayer(function (layer) {
  1476. if (typeof(layer[eventHandler]) == 'function') {
  1477. layer[eventHandler].call(layer, eventPacket);
  1478. }
  1479. if (layer.trigger) {
  1480. layer.trigger(eventName, eventPacket);
  1481. }
  1482. });
  1483. }
  1484. },
  1485. /**
  1486. * @private
  1487. * @param {number} x
  1488. * @param {number} y
  1489. * @param {module:zrender/graphic/Displayable} exclude
  1490. * @return {model:zrender/Element}
  1491. * @method
  1492. */
  1493. findHover: function(x, y, exclude) {
  1494. var list = this.storage.getDisplayList();
  1495. var out = {x: x, y: y};
  1496. for (var i = list.length - 1; i >= 0 ; i--) {
  1497. var hoverCheckResult;
  1498. if (list[i] !== exclude
  1499. // getDisplayList may include ignored item in VML mode
  1500. && !list[i].ignore
  1501. && (hoverCheckResult = isHover(list[i], x, y))
  1502. ) {
  1503. !out.topTarget && (out.topTarget = list[i]);
  1504. if (hoverCheckResult !== SILENT) {
  1505. out.target = list[i];
  1506. break;
  1507. }
  1508. }
  1509. }
  1510. return out;
  1511. }
  1512. };
  1513. // Common handlers
  1514. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  1515. Handler.prototype[name] = function (event) {
  1516. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  1517. var hovered = this.findHover(event.zrX, event.zrY);
  1518. var hoveredTarget = hovered.target;
  1519. if (name === 'mousedown') {
  1520. this._downEl = hoveredTarget;
  1521. this._downPoint = [event.zrX, event.zrY];
  1522. // In case click triggered before mouseup
  1523. this._upEl = hoveredTarget;
  1524. }
  1525. else if (name === 'mosueup') {
  1526. this._upEl = hoveredTarget;
  1527. }
  1528. else if (name === 'click') {
  1529. if (this._downEl !== this._upEl
  1530. // Original click event is triggered on the whole canvas element,
  1531. // including the case that `mousedown` - `mousemove` - `mouseup`,
  1532. // which should be filtered, otherwise it will bring trouble to
  1533. // pan and zoom.
  1534. || !this._downPoint
  1535. // Arbitrary value
  1536. || dist(this._downPoint, [event.zrX, event.zrY]) > 4
  1537. ) {
  1538. return;
  1539. }
  1540. this._downPoint = null;
  1541. }
  1542. this.dispatchToElement(hovered, name, event);
  1543. };
  1544. });
  1545. function isHover(displayable, x, y) {
  1546. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  1547. var el = displayable;
  1548. var isSilent;
  1549. while (el) {
  1550. // If clipped by ancestor.
  1551. // FIXME: If clipPath has neither stroke nor fill,
  1552. // el.clipPath.contain(x, y) will always return false.
  1553. if (el.clipPath && !el.clipPath.contain(x, y)) {
  1554. return false;
  1555. }
  1556. if (el.silent) {
  1557. isSilent = true;
  1558. }
  1559. el = el.parent;
  1560. }
  1561. return isSilent ? SILENT : true;
  1562. }
  1563. return false;
  1564. }
  1565. mixin(Handler, Eventful);
  1566. mixin(Handler, Draggable);
  1567. /**
  1568. * 3x2矩阵操作类
  1569. * @exports zrender/tool/matrix
  1570. */
  1571. var ArrayCtor$1 = typeof Float32Array === 'undefined'
  1572. ? Array
  1573. : Float32Array;
  1574. /**
  1575. * 创建一个单位矩阵
  1576. * @return {Float32Array|Array.<number>}
  1577. */
  1578. function create$1() {
  1579. var out = new ArrayCtor$1(6);
  1580. identity(out);
  1581. return out;
  1582. }
  1583. /**
  1584. * 设置矩阵为单位矩阵
  1585. * @param {Float32Array|Array.<number>} out
  1586. */
  1587. function identity(out) {
  1588. out[0] = 1;
  1589. out[1] = 0;
  1590. out[2] = 0;
  1591. out[3] = 1;
  1592. out[4] = 0;
  1593. out[5] = 0;
  1594. return out;
  1595. }
  1596. /**
  1597. * 复制矩阵
  1598. * @param {Float32Array|Array.<number>} out
  1599. * @param {Float32Array|Array.<number>} m
  1600. */
  1601. function copy$1(out, m) {
  1602. out[0] = m[0];
  1603. out[1] = m[1];
  1604. out[2] = m[2];
  1605. out[3] = m[3];
  1606. out[4] = m[4];
  1607. out[5] = m[5];
  1608. return out;
  1609. }
  1610. /**
  1611. * 矩阵相乘
  1612. * @param {Float32Array|Array.<number>} out
  1613. * @param {Float32Array|Array.<number>} m1
  1614. * @param {Float32Array|Array.<number>} m2
  1615. */
  1616. function mul$1(out, m1, m2) {
  1617. // Consider matrix.mul(m, m2, m);
  1618. // where out is the same as m2.
  1619. // So use temp variable to escape error.
  1620. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1621. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1622. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1623. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1624. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1625. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1626. out[0] = out0;
  1627. out[1] = out1;
  1628. out[2] = out2;
  1629. out[3] = out3;
  1630. out[4] = out4;
  1631. out[5] = out5;
  1632. return out;
  1633. }
  1634. /**
  1635. * 平移变换
  1636. * @param {Float32Array|Array.<number>} out
  1637. * @param {Float32Array|Array.<number>} a
  1638. * @param {Float32Array|Array.<number>} v
  1639. */
  1640. function translate(out, a, v) {
  1641. out[0] = a[0];
  1642. out[1] = a[1];
  1643. out[2] = a[2];
  1644. out[3] = a[3];
  1645. out[4] = a[4] + v[0];
  1646. out[5] = a[5] + v[1];
  1647. return out;
  1648. }
  1649. /**
  1650. * 旋转变换
  1651. * @param {Float32Array|Array.<number>} out
  1652. * @param {Float32Array|Array.<number>} a
  1653. * @param {number} rad
  1654. */
  1655. function rotate(out, a, rad) {
  1656. var aa = a[0];
  1657. var ac = a[2];
  1658. var atx = a[4];
  1659. var ab = a[1];
  1660. var ad = a[3];
  1661. var aty = a[5];
  1662. var st = Math.sin(rad);
  1663. var ct = Math.cos(rad);
  1664. out[0] = aa * ct + ab * st;
  1665. out[1] = -aa * st + ab * ct;
  1666. out[2] = ac * ct + ad * st;
  1667. out[3] = -ac * st + ct * ad;
  1668. out[4] = ct * atx + st * aty;
  1669. out[5] = ct * aty - st * atx;
  1670. return out;
  1671. }
  1672. /**
  1673. * 缩放变换
  1674. * @param {Float32Array|Array.<number>} out
  1675. * @param {Float32Array|Array.<number>} a
  1676. * @param {Float32Array|Array.<number>} v
  1677. */
  1678. function scale$1(out, a, v) {
  1679. var vx = v[0];
  1680. var vy = v[1];
  1681. out[0] = a[0] * vx;
  1682. out[1] = a[1] * vy;
  1683. out[2] = a[2] * vx;
  1684. out[3] = a[3] * vy;
  1685. out[4] = a[4] * vx;
  1686. out[5] = a[5] * vy;
  1687. return out;
  1688. }
  1689. /**
  1690. * 求逆矩阵
  1691. * @param {Float32Array|Array.<number>} out
  1692. * @param {Float32Array|Array.<number>} a
  1693. */
  1694. function invert(out, a) {
  1695. var aa = a[0];
  1696. var ac = a[2];
  1697. var atx = a[4];
  1698. var ab = a[1];
  1699. var ad = a[3];
  1700. var aty = a[5];
  1701. var det = aa * ad - ab * ac;
  1702. if (!det) {
  1703. return null;
  1704. }
  1705. det = 1.0 / det;
  1706. out[0] = ad * det;
  1707. out[1] = -ab * det;
  1708. out[2] = -ac * det;
  1709. out[3] = aa * det;
  1710. out[4] = (ac * aty - ad * atx) * det;
  1711. out[5] = (ab * atx - aa * aty) * det;
  1712. return out;
  1713. }
  1714. var matrix = (Object.freeze || Object)({
  1715. create: create$1,
  1716. identity: identity,
  1717. copy: copy$1,
  1718. mul: mul$1,
  1719. translate: translate,
  1720. rotate: rotate,
  1721. scale: scale$1,
  1722. invert: invert
  1723. });
  1724. /**
  1725. * 提供变换扩展
  1726. * @module zrender/mixin/Transformable
  1727. * @author pissang (https://www.github.com/pissang)
  1728. */
  1729. var mIdentity = identity;
  1730. var EPSILON = 5e-5;
  1731. function isNotAroundZero(val) {
  1732. return val > EPSILON || val < -EPSILON;
  1733. }
  1734. /**
  1735. * @alias module:zrender/mixin/Transformable
  1736. * @constructor
  1737. */
  1738. var Transformable = function (opts) {
  1739. opts = opts || {};
  1740. // If there are no given position, rotation, scale
  1741. if (!opts.position) {
  1742. /**
  1743. * 平移
  1744. * @type {Array.<number>}
  1745. * @default [0, 0]
  1746. */
  1747. this.position = [0, 0];
  1748. }
  1749. if (opts.rotation == null) {
  1750. /**
  1751. * 旋转
  1752. * @type {Array.<number>}
  1753. * @default 0
  1754. */
  1755. this.rotation = 0;
  1756. }
  1757. if (!opts.scale) {
  1758. /**
  1759. * 缩放
  1760. * @type {Array.<number>}
  1761. * @default [1, 1]
  1762. */
  1763. this.scale = [1, 1];
  1764. }
  1765. /**
  1766. * 旋转和缩放的原点
  1767. * @type {Array.<number>}
  1768. * @default null
  1769. */
  1770. this.origin = this.origin || null;
  1771. };
  1772. var transformableProto = Transformable.prototype;
  1773. transformableProto.transform = null;
  1774. /**
  1775. * 判断是否需要有坐标变换
  1776. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  1777. */
  1778. transformableProto.needLocalTransform = function () {
  1779. return isNotAroundZero(this.rotation)
  1780. || isNotAroundZero(this.position[0])
  1781. || isNotAroundZero(this.position[1])
  1782. || isNotAroundZero(this.scale[0] - 1)
  1783. || isNotAroundZero(this.scale[1] - 1);
  1784. };
  1785. transformableProto.updateTransform = function () {
  1786. var parent = this.parent;
  1787. var parentHasTransform = parent && parent.transform;
  1788. var needLocalTransform = this.needLocalTransform();
  1789. var m = this.transform;
  1790. if (!(needLocalTransform || parentHasTransform)) {
  1791. m && mIdentity(m);
  1792. return;
  1793. }
  1794. m = m || create$1();
  1795. if (needLocalTransform) {
  1796. this.getLocalTransform(m);
  1797. }
  1798. else {
  1799. mIdentity(m);
  1800. }
  1801. // 应用父节点变换
  1802. if (parentHasTransform) {
  1803. if (needLocalTransform) {
  1804. mul$1(m, parent.transform, m);
  1805. }
  1806. else {
  1807. copy$1(m, parent.transform);
  1808. }
  1809. }
  1810. // 保存这个变换矩阵
  1811. this.transform = m;
  1812. this.invTransform = this.invTransform || create$1();
  1813. invert(this.invTransform, m);
  1814. };
  1815. transformableProto.getLocalTransform = function (m) {
  1816. return Transformable.getLocalTransform(this, m);
  1817. };
  1818. /**
  1819. * 将自己的transform应用到context上
  1820. * @param {CanvasRenderingContext2D} ctx
  1821. */
  1822. transformableProto.setTransform = function (ctx) {
  1823. var m = this.transform;
  1824. var dpr = ctx.dpr || 1;
  1825. if (m) {
  1826. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  1827. }
  1828. else {
  1829. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  1830. }
  1831. };
  1832. transformableProto.restoreTransform = function (ctx) {
  1833. var dpr = ctx.dpr || 1;
  1834. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  1835. };
  1836. var tmpTransform = [];
  1837. /**
  1838. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  1839. */
  1840. transformableProto.decomposeTransform = function () {
  1841. if (!this.transform) {
  1842. return;
  1843. }
  1844. var parent = this.parent;
  1845. var m = this.transform;
  1846. if (parent && parent.transform) {
  1847. // Get local transform and decompose them to position, scale, rotation
  1848. mul$1(tmpTransform, parent.invTransform, m);
  1849. m = tmpTransform;
  1850. }
  1851. var sx = m[0] * m[0] + m[1] * m[1];
  1852. var sy = m[2] * m[2] + m[3] * m[3];
  1853. var position = this.position;
  1854. var scale$$1 = this.scale;
  1855. if (isNotAroundZero(sx - 1)) {
  1856. sx = Math.sqrt(sx);
  1857. }
  1858. if (isNotAroundZero(sy - 1)) {
  1859. sy = Math.sqrt(sy);
  1860. }
  1861. if (m[0] < 0) {
  1862. sx = -sx;
  1863. }
  1864. if (m[3] < 0) {
  1865. sy = -sy;
  1866. }
  1867. position[0] = m[4];
  1868. position[1] = m[5];
  1869. scale$$1[0] = sx;
  1870. scale$$1[1] = sy;
  1871. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  1872. };
  1873. /**
  1874. * Get global scale
  1875. * @return {Array.<number>}
  1876. */
  1877. transformableProto.getGlobalScale = function () {
  1878. var m = this.transform;
  1879. if (!m) {
  1880. return [1, 1];
  1881. }
  1882. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  1883. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  1884. if (m[0] < 0) {
  1885. sx = -sx;
  1886. }
  1887. if (m[3] < 0) {
  1888. sy = -sy;
  1889. }
  1890. return [sx, sy];
  1891. };
  1892. /**
  1893. * 变换坐标位置到 shape 的局部坐标空间
  1894. * @method
  1895. * @param {number} x
  1896. * @param {number} y
  1897. * @return {Array.<number>}
  1898. */
  1899. transformableProto.transformCoordToLocal = function (x, y) {
  1900. var v2 = [x, y];
  1901. var invTransform = this.invTransform;
  1902. if (invTransform) {
  1903. applyTransform(v2, v2, invTransform);
  1904. }
  1905. return v2;
  1906. };
  1907. /**
  1908. * 变换局部坐标位置到全局坐标空间
  1909. * @method
  1910. * @param {number} x
  1911. * @param {number} y
  1912. * @return {Array.<number>}
  1913. */
  1914. transformableProto.transformCoordToGlobal = function (x, y) {
  1915. var v2 = [x, y];
  1916. var transform = this.transform;
  1917. if (transform) {
  1918. applyTransform(v2, v2, transform);
  1919. }
  1920. return v2;
  1921. };
  1922. /**
  1923. * @static
  1924. * @param {Object} target
  1925. * @param {Array.<number>} target.origin
  1926. * @param {number} target.rotation
  1927. * @param {Array.<number>} target.position
  1928. * @param {Array.<number>} [m]
  1929. */
  1930. Transformable.getLocalTransform = function (target, m) {
  1931. m = m || [];
  1932. mIdentity(m);
  1933. var origin = target.origin;
  1934. var scale$$1 = target.scale || [1, 1];
  1935. var rotation = target.rotation || 0;
  1936. var position = target.position || [0, 0];
  1937. if (origin) {
  1938. // Translate to origin
  1939. m[4] -= origin[0];
  1940. m[5] -= origin[1];
  1941. }
  1942. scale$1(m, m, scale$$1);
  1943. if (rotation) {
  1944. rotate(m, m, rotation);
  1945. }
  1946. if (origin) {
  1947. // Translate back from origin
  1948. m[4] += origin[0];
  1949. m[5] += origin[1];
  1950. }
  1951. m[4] += position[0];
  1952. m[5] += position[1];
  1953. return m;
  1954. };
  1955. /**
  1956. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  1957. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  1958. * @exports zrender/animation/easing
  1959. */
  1960. var easing = {
  1961. /**
  1962. * @param {number} k
  1963. * @return {number}
  1964. */
  1965. linear: function (k) {
  1966. return k;
  1967. },
  1968. /**
  1969. * @param {number} k
  1970. * @return {number}
  1971. */
  1972. quadraticIn: function (k) {
  1973. return k * k;
  1974. },
  1975. /**
  1976. * @param {number} k
  1977. * @return {number}
  1978. */
  1979. quadraticOut: function (k) {
  1980. return k * (2 - k);
  1981. },
  1982. /**
  1983. * @param {number} k
  1984. * @return {number}
  1985. */
  1986. quadraticInOut: function (k) {
  1987. if ((k *= 2) < 1) {
  1988. return 0.5 * k * k;
  1989. }
  1990. return -0.5 * (--k * (k - 2) - 1);
  1991. },
  1992. // 三次方的缓动(t^3)
  1993. /**
  1994. * @param {number} k
  1995. * @return {number}
  1996. */
  1997. cubicIn: function (k) {
  1998. return k * k * k;
  1999. },
  2000. /**
  2001. * @param {number} k
  2002. * @return {number}
  2003. */
  2004. cubicOut: function (k) {
  2005. return --k * k * k + 1;
  2006. },
  2007. /**
  2008. * @param {number} k
  2009. * @return {number}
  2010. */
  2011. cubicInOut: function (k) {
  2012. if ((k *= 2) < 1) {
  2013. return 0.5 * k * k * k;
  2014. }
  2015. return 0.5 * ((k -= 2) * k * k + 2);
  2016. },
  2017. // 四次方的缓动(t^4)
  2018. /**
  2019. * @param {number} k
  2020. * @return {number}
  2021. */
  2022. quarticIn: function (k) {
  2023. return k * k * k * k;
  2024. },
  2025. /**
  2026. * @param {number} k
  2027. * @return {number}
  2028. */
  2029. quarticOut: function (k) {
  2030. return 1 - (--k * k * k * k);
  2031. },
  2032. /**
  2033. * @param {number} k
  2034. * @return {number}
  2035. */
  2036. quarticInOut: function (k) {
  2037. if ((k *= 2) < 1) {
  2038. return 0.5 * k * k * k * k;
  2039. }
  2040. return -0.5 * ((k -= 2) * k * k * k - 2);
  2041. },
  2042. // 五次方的缓动(t^5)
  2043. /**
  2044. * @param {number} k
  2045. * @return {number}
  2046. */
  2047. quinticIn: function (k) {
  2048. return k * k * k * k * k;
  2049. },
  2050. /**
  2051. * @param {number} k
  2052. * @return {number}
  2053. */
  2054. quinticOut: function (k) {
  2055. return --k * k * k * k * k + 1;
  2056. },
  2057. /**
  2058. * @param {number} k
  2059. * @return {number}
  2060. */
  2061. quinticInOut: function (k) {
  2062. if ((k *= 2) < 1) {
  2063. return 0.5 * k * k * k * k * k;
  2064. }
  2065. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2066. },
  2067. // 正弦曲线的缓动(sin(t))
  2068. /**
  2069. * @param {number} k
  2070. * @return {number}
  2071. */
  2072. sinusoidalIn: function (k) {
  2073. return 1 - Math.cos(k * Math.PI / 2);
  2074. },
  2075. /**
  2076. * @param {number} k
  2077. * @return {number}
  2078. */
  2079. sinusoidalOut: function (k) {
  2080. return Math.sin(k * Math.PI / 2);
  2081. },
  2082. /**
  2083. * @param {number} k
  2084. * @return {number}
  2085. */
  2086. sinusoidalInOut: function (k) {
  2087. return 0.5 * (1 - Math.cos(Math.PI * k));
  2088. },
  2089. // 指数曲线的缓动(2^t)
  2090. /**
  2091. * @param {number} k
  2092. * @return {number}
  2093. */
  2094. exponentialIn: function (k) {
  2095. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2096. },
  2097. /**
  2098. * @param {number} k
  2099. * @return {number}
  2100. */
  2101. exponentialOut: function (k) {
  2102. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2103. },
  2104. /**
  2105. * @param {number} k
  2106. * @return {number}
  2107. */
  2108. exponentialInOut: function (k) {
  2109. if (k === 0) {
  2110. return 0;
  2111. }
  2112. if (k === 1) {
  2113. return 1;
  2114. }
  2115. if ((k *= 2) < 1) {
  2116. return 0.5 * Math.pow(1024, k - 1);
  2117. }
  2118. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2119. },
  2120. // 圆形曲线的缓动(sqrt(1-t^2))
  2121. /**
  2122. * @param {number} k
  2123. * @return {number}
  2124. */
  2125. circularIn: function (k) {
  2126. return 1 - Math.sqrt(1 - k * k);
  2127. },
  2128. /**
  2129. * @param {number} k
  2130. * @return {number}
  2131. */
  2132. circularOut: function (k) {
  2133. return Math.sqrt(1 - (--k * k));
  2134. },
  2135. /**
  2136. * @param {number} k
  2137. * @return {number}
  2138. */
  2139. circularInOut: function (k) {
  2140. if ((k *= 2) < 1) {
  2141. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2142. }
  2143. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2144. },
  2145. // 创建类似于弹簧在停止前来回振荡的动画
  2146. /**
  2147. * @param {number} k
  2148. * @return {number}
  2149. */
  2150. elasticIn: function (k) {
  2151. var s;
  2152. var a = 0.1;
  2153. var p = 0.4;
  2154. if (k === 0) {
  2155. return 0;
  2156. }
  2157. if (k === 1) {
  2158. return 1;
  2159. }
  2160. if (!a || a < 1) {
  2161. a = 1; s = p / 4;
  2162. }
  2163. else {
  2164. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2165. }
  2166. return -(a * Math.pow(2, 10 * (k -= 1)) *
  2167. Math.sin((k - s) * (2 * Math.PI) / p));
  2168. },
  2169. /**
  2170. * @param {number} k
  2171. * @return {number}
  2172. */
  2173. elasticOut: function (k) {
  2174. var s;
  2175. var a = 0.1;
  2176. var p = 0.4;
  2177. if (k === 0) {
  2178. return 0;
  2179. }
  2180. if (k === 1) {
  2181. return 1;
  2182. }
  2183. if (!a || a < 1) {
  2184. a = 1; s = p / 4;
  2185. }
  2186. else {
  2187. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2188. }
  2189. return (a * Math.pow(2, -10 * k) *
  2190. Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2191. },
  2192. /**
  2193. * @param {number} k
  2194. * @return {number}
  2195. */
  2196. elasticInOut: function (k) {
  2197. var s;
  2198. var a = 0.1;
  2199. var p = 0.4;
  2200. if (k === 0) {
  2201. return 0;
  2202. }
  2203. if (k === 1) {
  2204. return 1;
  2205. }
  2206. if (!a || a < 1) {
  2207. a = 1; s = p / 4;
  2208. }
  2209. else {
  2210. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2211. }
  2212. if ((k *= 2) < 1) {
  2213. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2214. * Math.sin((k - s) * (2 * Math.PI) / p));
  2215. }
  2216. return a * Math.pow(2, -10 * (k -= 1))
  2217. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2218. },
  2219. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2220. /**
  2221. * @param {number} k
  2222. * @return {number}
  2223. */
  2224. backIn: function (k) {
  2225. var s = 1.70158;
  2226. return k * k * ((s + 1) * k - s);
  2227. },
  2228. /**
  2229. * @param {number} k
  2230. * @return {number}
  2231. */
  2232. backOut: function (k) {
  2233. var s = 1.70158;
  2234. return --k * k * ((s + 1) * k + s) + 1;
  2235. },
  2236. /**
  2237. * @param {number} k
  2238. * @return {number}
  2239. */
  2240. backInOut: function (k) {
  2241. var s = 1.70158 * 1.525;
  2242. if ((k *= 2) < 1) {
  2243. return 0.5 * (k * k * ((s + 1) * k - s));
  2244. }
  2245. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2246. },
  2247. // 创建弹跳效果
  2248. /**
  2249. * @param {number} k
  2250. * @return {number}
  2251. */
  2252. bounceIn: function (k) {
  2253. return 1 - easing.bounceOut(1 - k);
  2254. },
  2255. /**
  2256. * @param {number} k
  2257. * @return {number}
  2258. */
  2259. bounceOut: function (k) {
  2260. if (k < (1 / 2.75)) {
  2261. return 7.5625 * k * k;
  2262. }
  2263. else if (k < (2 / 2.75)) {
  2264. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  2265. }
  2266. else if (k < (2.5 / 2.75)) {
  2267. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  2268. }
  2269. else {
  2270. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  2271. }
  2272. },
  2273. /**
  2274. * @param {number} k
  2275. * @return {number}
  2276. */
  2277. bounceInOut: function (k) {
  2278. if (k < 0.5) {
  2279. return easing.bounceIn(k * 2) * 0.5;
  2280. }
  2281. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2282. }
  2283. };
  2284. /**
  2285. * 动画主控制器
  2286. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  2287. * @config life(1000) 动画时长
  2288. * @config delay(0) 动画延迟时间
  2289. * @config loop(true)
  2290. * @config gap(0) 循环的间隔时间
  2291. * @config onframe
  2292. * @config easing(optional)
  2293. * @config ondestroy(optional)
  2294. * @config onrestart(optional)
  2295. *
  2296. * TODO pause
  2297. */
  2298. function Clip(options) {
  2299. this._target = options.target;
  2300. // 生命周期
  2301. this._life = options.life || 1000;
  2302. // 延时
  2303. this._delay = options.delay || 0;
  2304. // 开始时间
  2305. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  2306. this._initialized = false;
  2307. // 是否循环
  2308. this.loop = options.loop == null ? false : options.loop;
  2309. this.gap = options.gap || 0;
  2310. this.easing = options.easing || 'Linear';
  2311. this.onframe = options.onframe;
  2312. this.ondestroy = options.ondestroy;
  2313. this.onrestart = options.onrestart;
  2314. this._pausedTime = 0;
  2315. this._paused = false;
  2316. }
  2317. Clip.prototype = {
  2318. constructor: Clip,
  2319. step: function (globalTime, deltaTime) {
  2320. // Set startTime on first step, or _startTime may has milleseconds different between clips
  2321. // PENDING
  2322. if (!this._initialized) {
  2323. this._startTime = globalTime + this._delay;
  2324. this._initialized = true;
  2325. }
  2326. if (this._paused) {
  2327. this._pausedTime += deltaTime;
  2328. return;
  2329. }
  2330. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  2331. // 还没开始
  2332. if (percent < 0) {
  2333. return;
  2334. }
  2335. percent = Math.min(percent, 1);
  2336. var easing$$1 = this.easing;
  2337. var easingFunc = typeof easing$$1 == 'string' ? easing[easing$$1] : easing$$1;
  2338. var schedule = typeof easingFunc === 'function'
  2339. ? easingFunc(percent)
  2340. : percent;
  2341. this.fire('frame', schedule);
  2342. // 结束
  2343. if (percent == 1) {
  2344. if (this.loop) {
  2345. this.restart (globalTime);
  2346. // 重新开始周期
  2347. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  2348. return 'restart';
  2349. }
  2350. // 动画完成将这个控制器标识为待删除
  2351. // 在Animation.update中进行批量删除
  2352. this._needsRemove = true;
  2353. return 'destroy';
  2354. }
  2355. return null;
  2356. },
  2357. restart: function (globalTime) {
  2358. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  2359. this._startTime = globalTime - remainder + this.gap;
  2360. this._pausedTime = 0;
  2361. this._needsRemove = false;
  2362. },
  2363. fire: function (eventType, arg) {
  2364. eventType = 'on' + eventType;
  2365. if (this[eventType]) {
  2366. this[eventType](this._target, arg);
  2367. }
  2368. },
  2369. pause: function () {
  2370. this._paused = true;
  2371. },
  2372. resume: function () {
  2373. this._paused = false;
  2374. }
  2375. };
  2376. // Simple LRU cache use doubly linked list
  2377. // @module zrender/core/LRU
  2378. /**
  2379. * Simple double linked list. Compared with array, it has O(1) remove operation.
  2380. * @constructor
  2381. */
  2382. var LinkedList = function () {
  2383. /**
  2384. * @type {module:zrender/core/LRU~Entry}
  2385. */
  2386. this.head = null;
  2387. /**
  2388. * @type {module:zrender/core/LRU~Entry}
  2389. */
  2390. this.tail = null;
  2391. this._len = 0;
  2392. };
  2393. var linkedListProto = LinkedList.prototype;
  2394. /**
  2395. * Insert a new value at the tail
  2396. * @param {} val
  2397. * @return {module:zrender/core/LRU~Entry}
  2398. */
  2399. linkedListProto.insert = function (val) {
  2400. var entry = new Entry(val);
  2401. this.insertEntry(entry);
  2402. return entry;
  2403. };
  2404. /**
  2405. * Insert an entry at the tail
  2406. * @param {module:zrender/core/LRU~Entry} entry
  2407. */
  2408. linkedListProto.insertEntry = function (entry) {
  2409. if (!this.head) {
  2410. this.head = this.tail = entry;
  2411. }
  2412. else {
  2413. this.tail.next = entry;
  2414. entry.prev = this.tail;
  2415. entry.next = null;
  2416. this.tail = entry;
  2417. }
  2418. this._len++;
  2419. };
  2420. /**
  2421. * Remove entry.
  2422. * @param {module:zrender/core/LRU~Entry} entry
  2423. */
  2424. linkedListProto.remove = function (entry) {
  2425. var prev = entry.prev;
  2426. var next = entry.next;
  2427. if (prev) {
  2428. prev.next = next;
  2429. }
  2430. else {
  2431. // Is head
  2432. this.head = next;
  2433. }
  2434. if (next) {
  2435. next.prev = prev;
  2436. }
  2437. else {
  2438. // Is tail
  2439. this.tail = prev;
  2440. }
  2441. entry.next = entry.prev = null;
  2442. this._len--;
  2443. };
  2444. /**
  2445. * @return {number}
  2446. */
  2447. linkedListProto.len = function () {
  2448. return this._len;
  2449. };
  2450. /**
  2451. * Clear list
  2452. */
  2453. linkedListProto.clear = function () {
  2454. this.head = this.tail = null;
  2455. this._len = 0;
  2456. };
  2457. /**
  2458. * @constructor
  2459. * @param {} val
  2460. */
  2461. var Entry = function (val) {
  2462. /**
  2463. * @type {}
  2464. */
  2465. this.value = val;
  2466. /**
  2467. * @type {module:zrender/core/LRU~Entry}
  2468. */
  2469. this.next;
  2470. /**
  2471. * @type {module:zrender/core/LRU~Entry}
  2472. */
  2473. this.prev;
  2474. };
  2475. /**
  2476. * LRU Cache
  2477. * @constructor
  2478. * @alias module:zrender/core/LRU
  2479. */
  2480. var LRU = function (maxSize) {
  2481. this._list = new LinkedList();
  2482. this._map = {};
  2483. this._maxSize = maxSize || 10;
  2484. this._lastRemovedEntry = null;
  2485. };
  2486. var LRUProto = LRU.prototype;
  2487. /**
  2488. * @param {string} key
  2489. * @param {} value
  2490. * @return {} Removed value
  2491. */
  2492. LRUProto.put = function (key, value) {
  2493. var list = this._list;
  2494. var map = this._map;
  2495. var removed = null;
  2496. if (map[key] == null) {
  2497. var len = list.len();
  2498. // Reuse last removed entry
  2499. var entry = this._lastRemovedEntry;
  2500. if (len >= this._maxSize && len > 0) {
  2501. // Remove the least recently used
  2502. var leastUsedEntry = list.head;
  2503. list.remove(leastUsedEntry);
  2504. delete map[leastUsedEntry.key];
  2505. removed = leastUsedEntry.value;
  2506. this._lastRemovedEntry = leastUsedEntry;
  2507. }
  2508. if (entry) {
  2509. entry.value = value;
  2510. }
  2511. else {
  2512. entry = new Entry(value);
  2513. }
  2514. entry.key = key;
  2515. list.insertEntry(entry);
  2516. map[key] = entry;
  2517. }
  2518. return removed;
  2519. };
  2520. /**
  2521. * @param {string} key
  2522. * @return {}
  2523. */
  2524. LRUProto.get = function (key) {
  2525. var entry = this._map[key];
  2526. var list = this._list;
  2527. if (entry != null) {
  2528. // Put the latest used entry in the tail
  2529. if (entry !== list.tail) {
  2530. list.remove(entry);
  2531. list.insertEntry(entry);
  2532. }
  2533. return entry.value;
  2534. }
  2535. };
  2536. /**
  2537. * Clear the cache
  2538. */
  2539. LRUProto.clear = function () {
  2540. this._list.clear();
  2541. this._map = {};
  2542. };
  2543. var kCSSColorTable = {
  2544. 'transparent': [0,0,0,0], 'aliceblue': [240,248,255,1],
  2545. 'antiquewhite': [250,235,215,1], 'aqua': [0,255,255,1],
  2546. 'aquamarine': [127,255,212,1], 'azure': [240,255,255,1],
  2547. 'beige': [245,245,220,1], 'bisque': [255,228,196,1],
  2548. 'black': [0,0,0,1], 'blanchedalmond': [255,235,205,1],
  2549. 'blue': [0,0,255,1], 'blueviolet': [138,43,226,1],
  2550. 'brown': [165,42,42,1], 'burlywood': [222,184,135,1],
  2551. 'cadetblue': [95,158,160,1], 'chartreuse': [127,255,0,1],
  2552. 'chocolate': [210,105,30,1], 'coral': [255,127,80,1],
  2553. 'cornflowerblue': [100,149,237,1], 'cornsilk': [255,248,220,1],
  2554. 'crimson': [220,20,60,1], 'cyan': [0,255,255,1],
  2555. 'darkblue': [0,0,139,1], 'darkcyan': [0,139,139,1],
  2556. 'darkgoldenrod': [184,134,11,1], 'darkgray': [169,169,169,1],
  2557. 'darkgreen': [0,100,0,1], 'darkgrey': [169,169,169,1],
  2558. 'darkkhaki': [189,183,107,1], 'darkmagenta': [139,0,139,1],
  2559. 'darkolivegreen': [85,107,47,1], 'darkorange': [255,140,0,1],
  2560. 'darkorchid': [153,50,204,1], 'darkred': [139,0,0,1],
  2561. 'darksalmon': [233,150,122,1], 'darkseagreen': [143,188,143,1],
  2562. 'darkslateblue': [72,61,139,1], 'darkslategray': [47,79,79,1],
  2563. 'darkslategrey': [47,79,79,1], 'darkturquoise': [0,206,209,1],
  2564. 'darkviolet': [148,0,211,1], 'deeppink': [255,20,147,1],
  2565. 'deepskyblue': [0,191,255,1], 'dimgray': [105,105,105,1],
  2566. 'dimgrey': [105,105,105,1], 'dodgerblue': [30,144,255,1],
  2567. 'firebrick': [178,34,34,1], 'floralwhite': [255,250,240,1],
  2568. 'forestgreen': [34,139,34,1], 'fuchsia': [255,0,255,1],
  2569. 'gainsboro': [220,220,220,1], 'ghostwhite': [248,248,255,1],
  2570. 'gold': [255,215,0,1], 'goldenrod': [218,165,32,1],
  2571. 'gray': [128,128,128,1], 'green': [0,128,0,1],
  2572. 'greenyellow': [173,255,47,1], 'grey': [128,128,128,1],
  2573. 'honeydew': [240,255,240,1], 'hotpink': [255,105,180,1],
  2574. 'indianred': [205,92,92,1], 'indigo': [75,0,130,1],
  2575. 'ivory': [255,255,240,1], 'khaki': [240,230,140,1],
  2576. 'lavender': [230,230,250,1], 'lavenderblush': [255,240,245,1],
  2577. 'lawngreen': [124,252,0,1], 'lemonchiffon': [255,250,205,1],
  2578. 'lightblue': [173,216,230,1], 'lightcoral': [240,128,128,1],
  2579. 'lightcyan': [224,255,255,1], 'lightgoldenrodyellow': [250,250,210,1],
  2580. 'lightgray': [211,211,211,1], 'lightgreen': [144,238,144,1],
  2581. 'lightgrey': [211,211,211,1], 'lightpink': [255,182,193,1],
  2582. 'lightsalmon': [255,160,122,1], 'lightseagreen': [32,178,170,1],
  2583. 'lightskyblue': [135,206,250,1], 'lightslategray': [119,136,153,1],
  2584. 'lightslategrey': [119,136,153,1], 'lightsteelblue': [176,196,222,1],
  2585. 'lightyellow': [255,255,224,1], 'lime': [0,255,0,1],
  2586. 'limegreen': [50,205,50,1], 'linen': [250,240,230,1],
  2587. 'magenta': [255,0,255,1], 'maroon': [128,0,0,1],
  2588. 'mediumaquamarine': [102,205,170,1], 'mediumblue': [0,0,205,1],
  2589. 'mediumorchid': [186,85,211,1], 'mediumpurple': [147,112,219,1],
  2590. 'mediumseagreen': [60,179,113,1], 'mediumslateblue': [123,104,238,1],
  2591. 'mediumspringgreen': [0,250,154,1], 'mediumturquoise': [72,209,204,1],
  2592. 'mediumvioletred': [199,21,133,1], 'midnightblue': [25,25,112,1],
  2593. 'mintcream': [245,255,250,1], 'mistyrose': [255,228,225,1],
  2594. 'moccasin': [255,228,181,1], 'navajowhite': [255,222,173,1],
  2595. 'navy': [0,0,128,1], 'oldlace': [253,245,230,1],
  2596. 'olive': [128,128,0,1], 'olivedrab': [107,142,35,1],
  2597. 'orange': [255,165,0,1], 'orangered': [255,69,0,1],
  2598. 'orchid': [218,112,214,1], 'palegoldenrod': [238,232,170,1],
  2599. 'palegreen': [152,251,152,1], 'paleturquoise': [175,238,238,1],
  2600. 'palevioletred': [219,112,147,1], 'papayawhip': [255,239,213,1],
  2601. 'peachpuff': [255,218,185,1], 'peru': [205,133,63,1],
  2602. 'pink': [255,192,203,1], 'plum': [221,160,221,1],
  2603. 'powderblue': [176,224,230,1], 'purple': [128,0,128,1],
  2604. 'red': [255,0,0,1], 'rosybrown': [188,143,143,1],
  2605. 'royalblue': [65,105,225,1], 'saddlebrown': [139,69,19,1],
  2606. 'salmon': [250,128,114,1], 'sandybrown': [244,164,96,1],
  2607. 'seagreen': [46,139,87,1], 'seashell': [255,245,238,1],
  2608. 'sienna': [160,82,45,1], 'silver': [192,192,192,1],
  2609. 'skyblue': [135,206,235,1], 'slateblue': [106,90,205,1],
  2610. 'slategray': [112,128,144,1], 'slategrey': [112,128,144,1],
  2611. 'snow': [255,250,250,1], 'springgreen': [0,255,127,1],
  2612. 'steelblue': [70,130,180,1], 'tan': [210,180,140,1],
  2613. 'teal': [0,128,128,1], 'thistle': [216,191,216,1],
  2614. 'tomato': [255,99,71,1], 'turquoise': [64,224,208,1],
  2615. 'violet': [238,130,238,1], 'wheat': [245,222,179,1],
  2616. 'white': [255,255,255,1], 'whitesmoke': [245,245,245,1],
  2617. 'yellow': [255,255,0,1], 'yellowgreen': [154,205,50,1]
  2618. };
  2619. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  2620. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  2621. return i < 0 ? 0 : i > 255 ? 255 : i;
  2622. }
  2623. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  2624. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  2625. return i < 0 ? 0 : i > 360 ? 360 : i;
  2626. }
  2627. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  2628. return f < 0 ? 0 : f > 1 ? 1 : f;
  2629. }
  2630. function parseCssInt(str) { // int or percentage.
  2631. if (str.length && str.charAt(str.length - 1) === '%') {
  2632. return clampCssByte(parseFloat(str) / 100 * 255);
  2633. }
  2634. return clampCssByte(parseInt(str, 10));
  2635. }
  2636. function parseCssFloat(str) { // float or percentage.
  2637. if (str.length && str.charAt(str.length - 1) === '%') {
  2638. return clampCssFloat(parseFloat(str) / 100);
  2639. }
  2640. return clampCssFloat(parseFloat(str));
  2641. }
  2642. function cssHueToRgb(m1, m2, h) {
  2643. if (h < 0) {
  2644. h += 1;
  2645. }
  2646. else if (h > 1) {
  2647. h -= 1;
  2648. }
  2649. if (h * 6 < 1) {
  2650. return m1 + (m2 - m1) * h * 6;
  2651. }
  2652. if (h * 2 < 1) {
  2653. return m2;
  2654. }
  2655. if (h * 3 < 2) {
  2656. return m1 + (m2 - m1) * (2/3 - h) * 6;
  2657. }
  2658. return m1;
  2659. }
  2660. function lerpNumber(a, b, p) {
  2661. return a + (b - a) * p;
  2662. }
  2663. function setRgba(out, r, g, b, a) {
  2664. out[0] = r; out[1] = g; out[2] = b; out[3] = a;
  2665. return out;
  2666. }
  2667. function copyRgba(out, a) {
  2668. out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];
  2669. return out;
  2670. }
  2671. var colorCache = new LRU(20);
  2672. var lastRemovedArr = null;
  2673. function putToCache(colorStr, rgbaArr) {
  2674. // Reuse removed array
  2675. if (lastRemovedArr) {
  2676. copyRgba(lastRemovedArr, rgbaArr);
  2677. }
  2678. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  2679. }
  2680. /**
  2681. * @param {string} colorStr
  2682. * @param {Array.<number>} out
  2683. * @return {Array.<number>}
  2684. * @memberOf module:zrender/util/color
  2685. */
  2686. function parse(colorStr, rgbaArr) {
  2687. if (!colorStr) {
  2688. return;
  2689. }
  2690. rgbaArr = rgbaArr || [];
  2691. var cached = colorCache.get(colorStr);
  2692. if (cached) {
  2693. return copyRgba(rgbaArr, cached);
  2694. }
  2695. // colorStr may be not string
  2696. colorStr = colorStr + '';
  2697. // Remove all whitespace, not compliant, but should just be more accepting.
  2698. var str = colorStr.replace(/ /g, '').toLowerCase();
  2699. // Color keywords (and transparent) lookup.
  2700. if (str in kCSSColorTable) {
  2701. copyRgba(rgbaArr, kCSSColorTable[str]);
  2702. putToCache(colorStr, rgbaArr);
  2703. return rgbaArr;
  2704. }
  2705. // #abc and #abc123 syntax.
  2706. if (str.charAt(0) === '#') {
  2707. if (str.length === 4) {
  2708. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  2709. if (!(iv >= 0 && iv <= 0xfff)) {
  2710. setRgba(rgbaArr, 0, 0, 0, 1);
  2711. return; // Covers NaN.
  2712. }
  2713. setRgba(rgbaArr,
  2714. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  2715. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  2716. (iv & 0xf) | ((iv & 0xf) << 4),
  2717. 1
  2718. );
  2719. putToCache(colorStr, rgbaArr);
  2720. return rgbaArr;
  2721. }
  2722. else if (str.length === 7) {
  2723. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  2724. if (!(iv >= 0 && iv <= 0xffffff)) {
  2725. setRgba(rgbaArr, 0, 0, 0, 1);
  2726. return; // Covers NaN.
  2727. }
  2728. setRgba(rgbaArr,
  2729. (iv & 0xff0000) >> 16,
  2730. (iv & 0xff00) >> 8,
  2731. iv & 0xff,
  2732. 1
  2733. );
  2734. putToCache(colorStr, rgbaArr);
  2735. return rgbaArr;
  2736. }
  2737. return;
  2738. }
  2739. var op = str.indexOf('('), ep = str.indexOf(')');
  2740. if (op !== -1 && ep + 1 === str.length) {
  2741. var fname = str.substr(0, op);
  2742. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  2743. var alpha = 1; // To allow case fallthrough.
  2744. switch (fname) {
  2745. case 'rgba':
  2746. if (params.length !== 4) {
  2747. setRgba(rgbaArr, 0, 0, 0, 1);
  2748. return;
  2749. }
  2750. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  2751. // Fall through.
  2752. case 'rgb':
  2753. if (params.length !== 3) {
  2754. setRgba(rgbaArr, 0, 0, 0, 1);
  2755. return;
  2756. }
  2757. setRgba(rgbaArr,
  2758. parseCssInt(params[0]),
  2759. parseCssInt(params[1]),
  2760. parseCssInt(params[2]),
  2761. alpha
  2762. );
  2763. putToCache(colorStr, rgbaArr);
  2764. return rgbaArr;
  2765. case 'hsla':
  2766. if (params.length !== 4) {
  2767. setRgba(rgbaArr, 0, 0, 0, 1);
  2768. return;
  2769. }
  2770. params[3] = parseCssFloat(params[3]);
  2771. hsla2rgba(params, rgbaArr);
  2772. putToCache(colorStr, rgbaArr);
  2773. return rgbaArr;
  2774. case 'hsl':
  2775. if (params.length !== 3) {
  2776. setRgba(rgbaArr, 0, 0, 0, 1);
  2777. return;
  2778. }
  2779. hsla2rgba(params, rgbaArr);
  2780. putToCache(colorStr, rgbaArr);
  2781. return rgbaArr;
  2782. default:
  2783. return;
  2784. }
  2785. }
  2786. setRgba(rgbaArr, 0, 0, 0, 1);
  2787. return;
  2788. }
  2789. /**
  2790. * @param {Array.<number>} hsla
  2791. * @param {Array.<number>} rgba
  2792. * @return {Array.<number>} rgba
  2793. */
  2794. function hsla2rgba(hsla, rgba) {
  2795. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  2796. // NOTE(deanm): According to the CSS spec s/l should only be
  2797. // percentages, but we don't bother and let float or percentage.
  2798. var s = parseCssFloat(hsla[1]);
  2799. var l = parseCssFloat(hsla[2]);
  2800. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  2801. var m1 = l * 2 - m2;
  2802. rgba = rgba || [];
  2803. setRgba(rgba,
  2804. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  2805. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  2806. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  2807. 1
  2808. );
  2809. if (hsla.length === 4) {
  2810. rgba[3] = hsla[3];
  2811. }
  2812. return rgba;
  2813. }
  2814. /**
  2815. * @param {Array.<number>} rgba
  2816. * @return {Array.<number>} hsla
  2817. */
  2818. function rgba2hsla(rgba) {
  2819. if (!rgba) {
  2820. return;
  2821. }
  2822. // RGB from 0 to 255
  2823. var R = rgba[0] / 255;
  2824. var G = rgba[1] / 255;
  2825. var B = rgba[2] / 255;
  2826. var vMin = Math.min(R, G, B); // Min. value of RGB
  2827. var vMax = Math.max(R, G, B); // Max. value of RGB
  2828. var delta = vMax - vMin; // Delta RGB value
  2829. var L = (vMax + vMin) / 2;
  2830. var H;
  2831. var S;
  2832. // HSL results from 0 to 1
  2833. if (delta === 0) {
  2834. H = 0;
  2835. S = 0;
  2836. }
  2837. else {
  2838. if (L < 0.5) {
  2839. S = delta / (vMax + vMin);
  2840. }
  2841. else {
  2842. S = delta / (2 - vMax - vMin);
  2843. }
  2844. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  2845. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  2846. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  2847. if (R === vMax) {
  2848. H = deltaB - deltaG;
  2849. }
  2850. else if (G === vMax) {
  2851. H = (1 / 3) + deltaR - deltaB;
  2852. }
  2853. else if (B === vMax) {
  2854. H = (2 / 3) + deltaG - deltaR;
  2855. }
  2856. if (H < 0) {
  2857. H += 1;
  2858. }
  2859. if (H > 1) {
  2860. H -= 1;
  2861. }
  2862. }
  2863. var hsla = [H * 360, S, L];
  2864. if (rgba[3] != null) {
  2865. hsla.push(rgba[3]);
  2866. }
  2867. return hsla;
  2868. }
  2869. /**
  2870. * @param {string} color
  2871. * @param {number} level
  2872. * @return {string}
  2873. * @memberOf module:zrender/util/color
  2874. */
  2875. function lift(color, level) {
  2876. var colorArr = parse(color);
  2877. if (colorArr) {
  2878. for (var i = 0; i < 3; i++) {
  2879. if (level < 0) {
  2880. colorArr[i] = colorArr[i] * (1 - level) | 0;
  2881. }
  2882. else {
  2883. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  2884. }
  2885. }
  2886. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  2887. }
  2888. }
  2889. /**
  2890. * @param {string} color
  2891. * @return {string}
  2892. * @memberOf module:zrender/util/color
  2893. */
  2894. function toHex(color) {
  2895. var colorArr = parse(color);
  2896. if (colorArr) {
  2897. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  2898. }
  2899. }
  2900. /**
  2901. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  2902. * @param {number} normalizedValue A float between 0 and 1.
  2903. * @param {Array.<Array.<number>>} colors List of rgba color array
  2904. * @param {Array.<number>} [out] Mapped gba color array
  2905. * @return {Array.<number>} will be null/undefined if input illegal.
  2906. */
  2907. function fastLerp(normalizedValue, colors, out) {
  2908. if (!(colors && colors.length)
  2909. || !(normalizedValue >= 0 && normalizedValue <= 1)
  2910. ) {
  2911. return;
  2912. }
  2913. out = out || [];
  2914. var value = normalizedValue * (colors.length - 1);
  2915. var leftIndex = Math.floor(value);
  2916. var rightIndex = Math.ceil(value);
  2917. var leftColor = colors[leftIndex];
  2918. var rightColor = colors[rightIndex];
  2919. var dv = value - leftIndex;
  2920. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  2921. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  2922. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  2923. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  2924. return out;
  2925. }
  2926. /**
  2927. * @deprecated
  2928. */
  2929. var fastMapToColor = fastLerp;
  2930. /**
  2931. * @param {number} normalizedValue A float between 0 and 1.
  2932. * @param {Array.<string>} colors Color list.
  2933. * @param {boolean=} fullOutput Default false.
  2934. * @return {(string|Object)} Result color. If fullOutput,
  2935. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  2936. * @memberOf module:zrender/util/color
  2937. */
  2938. function lerp$1(normalizedValue, colors, fullOutput) {
  2939. if (!(colors && colors.length)
  2940. || !(normalizedValue >= 0 && normalizedValue <= 1)
  2941. ) {
  2942. return;
  2943. }
  2944. var value = normalizedValue * (colors.length - 1);
  2945. var leftIndex = Math.floor(value);
  2946. var rightIndex = Math.ceil(value);
  2947. var leftColor = parse(colors[leftIndex]);
  2948. var rightColor = parse(colors[rightIndex]);
  2949. var dv = value - leftIndex;
  2950. var color = stringify(
  2951. [
  2952. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  2953. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  2954. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  2955. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  2956. ],
  2957. 'rgba'
  2958. );
  2959. return fullOutput
  2960. ? {
  2961. color: color,
  2962. leftIndex: leftIndex,
  2963. rightIndex: rightIndex,
  2964. value: value
  2965. }
  2966. : color;
  2967. }
  2968. /**
  2969. * @deprecated
  2970. */
  2971. var mapToColor = lerp$1;
  2972. /**
  2973. * @param {string} color
  2974. * @param {number=} h 0 ~ 360, ignore when null.
  2975. * @param {number=} s 0 ~ 1, ignore when null.
  2976. * @param {number=} l 0 ~ 1, ignore when null.
  2977. * @return {string} Color string in rgba format.
  2978. * @memberOf module:zrender/util/color
  2979. */
  2980. function modifyHSL(color, h, s, l) {
  2981. color = parse(color);
  2982. if (color) {
  2983. color = rgba2hsla(color);
  2984. h != null && (color[0] = clampCssAngle(h));
  2985. s != null && (color[1] = parseCssFloat(s));
  2986. l != null && (color[2] = parseCssFloat(l));
  2987. return stringify(hsla2rgba(color), 'rgba');
  2988. }
  2989. }
  2990. /**
  2991. * @param {string} color
  2992. * @param {number=} alpha 0 ~ 1
  2993. * @return {string} Color string in rgba format.
  2994. * @memberOf module:zrender/util/color
  2995. */
  2996. function modifyAlpha(color, alpha) {
  2997. color = parse(color);
  2998. if (color && alpha != null) {
  2999. color[3] = clampCssFloat(alpha);
  3000. return stringify(color, 'rgba');
  3001. }
  3002. }
  3003. /**
  3004. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3005. * @param {string} type 'rgba', 'hsva', ...
  3006. * @return {string} Result color. (If input illegal, return undefined).
  3007. */
  3008. function stringify(arrColor, type) {
  3009. if (!arrColor || !arrColor.length) {
  3010. return;
  3011. }
  3012. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3013. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3014. colorStr += ',' + arrColor[3];
  3015. }
  3016. return type + '(' + colorStr + ')';
  3017. }
  3018. var color = (Object.freeze || Object)({
  3019. parse: parse,
  3020. lift: lift,
  3021. toHex: toHex,
  3022. fastLerp: fastLerp,
  3023. fastMapToColor: fastMapToColor,
  3024. lerp: lerp$1,
  3025. mapToColor: mapToColor,
  3026. modifyHSL: modifyHSL,
  3027. modifyAlpha: modifyAlpha,
  3028. stringify: stringify
  3029. });
  3030. /**
  3031. * @module echarts/animation/Animator
  3032. */
  3033. var arraySlice = Array.prototype.slice;
  3034. function defaultGetter(target, key) {
  3035. return target[key];
  3036. }
  3037. function defaultSetter(target, key, value) {
  3038. target[key] = value;
  3039. }
  3040. /**
  3041. * @param {number} p0
  3042. * @param {number} p1
  3043. * @param {number} percent
  3044. * @return {number}
  3045. */
  3046. function interpolateNumber(p0, p1, percent) {
  3047. return (p1 - p0) * percent + p0;
  3048. }
  3049. /**
  3050. * @param {string} p0
  3051. * @param {string} p1
  3052. * @param {number} percent
  3053. * @return {string}
  3054. */
  3055. function interpolateString(p0, p1, percent) {
  3056. return percent > 0.5 ? p1 : p0;
  3057. }
  3058. /**
  3059. * @param {Array} p0
  3060. * @param {Array} p1
  3061. * @param {number} percent
  3062. * @param {Array} out
  3063. * @param {number} arrDim
  3064. */
  3065. function interpolateArray(p0, p1, percent, out, arrDim) {
  3066. var len = p0.length;
  3067. if (arrDim == 1) {
  3068. for (var i = 0; i < len; i++) {
  3069. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3070. }
  3071. }
  3072. else {
  3073. var len2 = len && p0[0].length;
  3074. for (var i = 0; i < len; i++) {
  3075. for (var j = 0; j < len2; j++) {
  3076. out[i][j] = interpolateNumber(
  3077. p0[i][j], p1[i][j], percent
  3078. );
  3079. }
  3080. }
  3081. }
  3082. }
  3083. // arr0 is source array, arr1 is target array.
  3084. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3085. function fillArr(arr0, arr1, arrDim) {
  3086. var arr0Len = arr0.length;
  3087. var arr1Len = arr1.length;
  3088. if (arr0Len !== arr1Len) {
  3089. // FIXME Not work for TypedArray
  3090. var isPreviousLarger = arr0Len > arr1Len;
  3091. if (isPreviousLarger) {
  3092. // Cut the previous
  3093. arr0.length = arr1Len;
  3094. }
  3095. else {
  3096. // Fill the previous
  3097. for (var i = arr0Len; i < arr1Len; i++) {
  3098. arr0.push(
  3099. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  3100. );
  3101. }
  3102. }
  3103. }
  3104. // Handling NaN value
  3105. var len2 = arr0[0] && arr0[0].length;
  3106. for (var i = 0; i < arr0.length; i++) {
  3107. if (arrDim === 1) {
  3108. if (isNaN(arr0[i])) {
  3109. arr0[i] = arr1[i];
  3110. }
  3111. }
  3112. else {
  3113. for (var j = 0; j < len2; j++) {
  3114. if (isNaN(arr0[i][j])) {
  3115. arr0[i][j] = arr1[i][j];
  3116. }
  3117. }
  3118. }
  3119. }
  3120. }
  3121. /**
  3122. * @param {Array} arr0
  3123. * @param {Array} arr1
  3124. * @param {number} arrDim
  3125. * @return {boolean}
  3126. */
  3127. function isArraySame(arr0, arr1, arrDim) {
  3128. if (arr0 === arr1) {
  3129. return true;
  3130. }
  3131. var len = arr0.length;
  3132. if (len !== arr1.length) {
  3133. return false;
  3134. }
  3135. if (arrDim === 1) {
  3136. for (var i = 0; i < len; i++) {
  3137. if (arr0[i] !== arr1[i]) {
  3138. return false;
  3139. }
  3140. }
  3141. }
  3142. else {
  3143. var len2 = arr0[0].length;
  3144. for (var i = 0; i < len; i++) {
  3145. for (var j = 0; j < len2; j++) {
  3146. if (arr0[i][j] !== arr1[i][j]) {
  3147. return false;
  3148. }
  3149. }
  3150. }
  3151. }
  3152. return true;
  3153. }
  3154. /**
  3155. * Catmull Rom interpolate array
  3156. * @param {Array} p0
  3157. * @param {Array} p1
  3158. * @param {Array} p2
  3159. * @param {Array} p3
  3160. * @param {number} t
  3161. * @param {number} t2
  3162. * @param {number} t3
  3163. * @param {Array} out
  3164. * @param {number} arrDim
  3165. */
  3166. function catmullRomInterpolateArray(
  3167. p0, p1, p2, p3, t, t2, t3, out, arrDim
  3168. ) {
  3169. var len = p0.length;
  3170. if (arrDim == 1) {
  3171. for (var i = 0; i < len; i++) {
  3172. out[i] = catmullRomInterpolate(
  3173. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  3174. );
  3175. }
  3176. }
  3177. else {
  3178. var len2 = p0[0].length;
  3179. for (var i = 0; i < len; i++) {
  3180. for (var j = 0; j < len2; j++) {
  3181. out[i][j] = catmullRomInterpolate(
  3182. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  3183. t, t2, t3
  3184. );
  3185. }
  3186. }
  3187. }
  3188. }
  3189. /**
  3190. * Catmull Rom interpolate number
  3191. * @param {number} p0
  3192. * @param {number} p1
  3193. * @param {number} p2
  3194. * @param {number} p3
  3195. * @param {number} t
  3196. * @param {number} t2
  3197. * @param {number} t3
  3198. * @return {number}
  3199. */
  3200. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3201. var v0 = (p2 - p0) * 0.5;
  3202. var v1 = (p3 - p1) * 0.5;
  3203. return (2 * (p1 - p2) + v0 + v1) * t3
  3204. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  3205. + v0 * t + p1;
  3206. }
  3207. function cloneValue(value) {
  3208. if (isArrayLike(value)) {
  3209. var len = value.length;
  3210. if (isArrayLike(value[0])) {
  3211. var ret = [];
  3212. for (var i = 0; i < len; i++) {
  3213. ret.push(arraySlice.call(value[i]));
  3214. }
  3215. return ret;
  3216. }
  3217. return arraySlice.call(value);
  3218. }
  3219. return value;
  3220. }
  3221. function rgba2String(rgba) {
  3222. rgba[0] = Math.floor(rgba[0]);
  3223. rgba[1] = Math.floor(rgba[1]);
  3224. rgba[2] = Math.floor(rgba[2]);
  3225. return 'rgba(' + rgba.join(',') + ')';
  3226. }
  3227. function getArrayDim(keyframes) {
  3228. var lastValue = keyframes[keyframes.length - 1].value;
  3229. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3230. }
  3231. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3232. var getter = animator._getter;
  3233. var setter = animator._setter;
  3234. var useSpline = easing === 'spline';
  3235. var trackLen = keyframes.length;
  3236. if (!trackLen) {
  3237. return;
  3238. }
  3239. // Guess data type
  3240. var firstVal = keyframes[0].value;
  3241. var isValueArray = isArrayLike(firstVal);
  3242. var isValueColor = false;
  3243. var isValueString = false;
  3244. // For vertices morphing
  3245. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3246. var trackMaxTime;
  3247. // Sort keyframe as ascending
  3248. keyframes.sort(function(a, b) {
  3249. return a.time - b.time;
  3250. });
  3251. trackMaxTime = keyframes[trackLen - 1].time;
  3252. // Percents of each keyframe
  3253. var kfPercents = [];
  3254. // Value of each keyframe
  3255. var kfValues = [];
  3256. var prevValue = keyframes[0].value;
  3257. var isAllValueEqual = true;
  3258. for (var i = 0; i < trackLen; i++) {
  3259. kfPercents.push(keyframes[i].time / trackMaxTime);
  3260. // Assume value is a color when it is a string
  3261. var value = keyframes[i].value;
  3262. // Check if value is equal, deep check if value is array
  3263. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  3264. || (!isValueArray && value === prevValue))) {
  3265. isAllValueEqual = false;
  3266. }
  3267. prevValue = value;
  3268. // Try converting a string to a color array
  3269. if (typeof value == 'string') {
  3270. var colorArray = parse(value);
  3271. if (colorArray) {
  3272. value = colorArray;
  3273. isValueColor = true;
  3274. }
  3275. else {
  3276. isValueString = true;
  3277. }
  3278. }
  3279. kfValues.push(value);
  3280. }
  3281. if (!forceAnimate && isAllValueEqual) {
  3282. return;
  3283. }
  3284. var lastValue = kfValues[trackLen - 1];
  3285. // Polyfill array and NaN value
  3286. for (var i = 0; i < trackLen - 1; i++) {
  3287. if (isValueArray) {
  3288. fillArr(kfValues[i], lastValue, arrDim);
  3289. }
  3290. else {
  3291. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3292. kfValues[i] = lastValue;
  3293. }
  3294. }
  3295. }
  3296. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  3297. // Cache the key of last frame to speed up when
  3298. // animation playback is sequency
  3299. var lastFrame = 0;
  3300. var lastFramePercent = 0;
  3301. var start;
  3302. var w;
  3303. var p0;
  3304. var p1;
  3305. var p2;
  3306. var p3;
  3307. if (isValueColor) {
  3308. var rgba = [0, 0, 0, 0];
  3309. }
  3310. var onframe = function (target, percent) {
  3311. // Find the range keyframes
  3312. // kf1-----kf2---------current--------kf3
  3313. // find kf2 and kf3 and do interpolation
  3314. var frame;
  3315. // In the easing function like elasticOut, percent may less than 0
  3316. if (percent < 0) {
  3317. frame = 0;
  3318. }
  3319. else if (percent < lastFramePercent) {
  3320. // Start from next key
  3321. // PENDING start from lastFrame ?
  3322. start = Math.min(lastFrame + 1, trackLen - 1);
  3323. for (frame = start; frame >= 0; frame--) {
  3324. if (kfPercents[frame] <= percent) {
  3325. break;
  3326. }
  3327. }
  3328. // PENDING really need to do this ?
  3329. frame = Math.min(frame, trackLen - 2);
  3330. }
  3331. else {
  3332. for (frame = lastFrame; frame < trackLen; frame++) {
  3333. if (kfPercents[frame] > percent) {
  3334. break;
  3335. }
  3336. }
  3337. frame = Math.min(frame - 1, trackLen - 2);
  3338. }
  3339. lastFrame = frame;
  3340. lastFramePercent = percent;
  3341. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  3342. if (range === 0) {
  3343. return;
  3344. }
  3345. else {
  3346. w = (percent - kfPercents[frame]) / range;
  3347. }
  3348. if (useSpline) {
  3349. p1 = kfValues[frame];
  3350. p0 = kfValues[frame === 0 ? frame : frame - 1];
  3351. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  3352. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  3353. if (isValueArray) {
  3354. catmullRomInterpolateArray(
  3355. p0, p1, p2, p3, w, w * w, w * w * w,
  3356. getter(target, propName),
  3357. arrDim
  3358. );
  3359. }
  3360. else {
  3361. var value;
  3362. if (isValueColor) {
  3363. value = catmullRomInterpolateArray(
  3364. p0, p1, p2, p3, w, w * w, w * w * w,
  3365. rgba, 1
  3366. );
  3367. value = rgba2String(rgba);
  3368. }
  3369. else if (isValueString) {
  3370. // String is step(0.5)
  3371. return interpolateString(p1, p2, w);
  3372. }
  3373. else {
  3374. value = catmullRomInterpolate(
  3375. p0, p1, p2, p3, w, w * w, w * w * w
  3376. );
  3377. }
  3378. setter(
  3379. target,
  3380. propName,
  3381. value
  3382. );
  3383. }
  3384. }
  3385. else {
  3386. if (isValueArray) {
  3387. interpolateArray(
  3388. kfValues[frame], kfValues[frame + 1], w,
  3389. getter(target, propName),
  3390. arrDim
  3391. );
  3392. }
  3393. else {
  3394. var value;
  3395. if (isValueColor) {
  3396. interpolateArray(
  3397. kfValues[frame], kfValues[frame + 1], w,
  3398. rgba, 1
  3399. );
  3400. value = rgba2String(rgba);
  3401. }
  3402. else if (isValueString) {
  3403. // String is step(0.5)
  3404. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  3405. }
  3406. else {
  3407. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  3408. }
  3409. setter(
  3410. target,
  3411. propName,
  3412. value
  3413. );
  3414. }
  3415. }
  3416. };
  3417. var clip = new Clip({
  3418. target: animator._target,
  3419. life: trackMaxTime,
  3420. loop: animator._loop,
  3421. delay: animator._delay,
  3422. onframe: onframe,
  3423. ondestroy: oneTrackDone
  3424. });
  3425. if (easing && easing !== 'spline') {
  3426. clip.easing = easing;
  3427. }
  3428. return clip;
  3429. }
  3430. /**
  3431. * @alias module:zrender/animation/Animator
  3432. * @constructor
  3433. * @param {Object} target
  3434. * @param {boolean} loop
  3435. * @param {Function} getter
  3436. * @param {Function} setter
  3437. */
  3438. var Animator = function(target, loop, getter, setter) {
  3439. this._tracks = {};
  3440. this._target = target;
  3441. this._loop = loop || false;
  3442. this._getter = getter || defaultGetter;
  3443. this._setter = setter || defaultSetter;
  3444. this._clipCount = 0;
  3445. this._delay = 0;
  3446. this._doneList = [];
  3447. this._onframeList = [];
  3448. this._clipList = [];
  3449. };
  3450. Animator.prototype = {
  3451. /**
  3452. * 设置动画关键帧
  3453. * @param {number} time 关键帧时间,单位是ms
  3454. * @param {Object} props 关键帧的属性值,key-value表示
  3455. * @return {module:zrender/animation/Animator}
  3456. */
  3457. when: function(time /* ms */, props) {
  3458. var tracks = this._tracks;
  3459. for (var propName in props) {
  3460. if (!props.hasOwnProperty(propName)) {
  3461. continue;
  3462. }
  3463. if (!tracks[propName]) {
  3464. tracks[propName] = [];
  3465. // Invalid value
  3466. var value = this._getter(this._target, propName);
  3467. if (value == null) {
  3468. // zrLog('Invalid property ' + propName);
  3469. continue;
  3470. }
  3471. // If time is 0
  3472. // Then props is given initialize value
  3473. // Else
  3474. // Initialize value from current prop value
  3475. if (time !== 0) {
  3476. tracks[propName].push({
  3477. time: 0,
  3478. value: cloneValue(value)
  3479. });
  3480. }
  3481. }
  3482. tracks[propName].push({
  3483. time: time,
  3484. value: props[propName]
  3485. });
  3486. }
  3487. return this;
  3488. },
  3489. /**
  3490. * 添加动画每一帧的回调函数
  3491. * @param {Function} callback
  3492. * @return {module:zrender/animation/Animator}
  3493. */
  3494. during: function (callback) {
  3495. this._onframeList.push(callback);
  3496. return this;
  3497. },
  3498. pause: function () {
  3499. for (var i = 0; i < this._clipList.length; i++) {
  3500. this._clipList[i].pause();
  3501. }
  3502. this._paused = true;
  3503. },
  3504. resume: function () {
  3505. for (var i = 0; i < this._clipList.length; i++) {
  3506. this._clipList[i].resume();
  3507. }
  3508. this._paused = false;
  3509. },
  3510. isPaused: function () {
  3511. return !!this._paused;
  3512. },
  3513. _doneCallback: function () {
  3514. // Clear all tracks
  3515. this._tracks = {};
  3516. // Clear all clips
  3517. this._clipList.length = 0;
  3518. var doneList = this._doneList;
  3519. var len = doneList.length;
  3520. for (var i = 0; i < len; i++) {
  3521. doneList[i].call(this);
  3522. }
  3523. },
  3524. /**
  3525. * 开始执行动画
  3526. * @param {string|Function} [easing]
  3527. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  3528. * @param {boolean} forceAnimate
  3529. * @return {module:zrender/animation/Animator}
  3530. */
  3531. start: function (easing, forceAnimate) {
  3532. var self = this;
  3533. var clipCount = 0;
  3534. var oneTrackDone = function() {
  3535. clipCount--;
  3536. if (!clipCount) {
  3537. self._doneCallback();
  3538. }
  3539. };
  3540. var lastClip;
  3541. for (var propName in this._tracks) {
  3542. if (!this._tracks.hasOwnProperty(propName)) {
  3543. continue;
  3544. }
  3545. var clip = createTrackClip(
  3546. this, easing, oneTrackDone,
  3547. this._tracks[propName], propName, forceAnimate
  3548. );
  3549. if (clip) {
  3550. this._clipList.push(clip);
  3551. clipCount++;
  3552. // If start after added to animation
  3553. if (this.animation) {
  3554. this.animation.addClip(clip);
  3555. }
  3556. lastClip = clip;
  3557. }
  3558. }
  3559. // Add during callback on the last clip
  3560. if (lastClip) {
  3561. var oldOnFrame = lastClip.onframe;
  3562. lastClip.onframe = function (target, percent) {
  3563. oldOnFrame(target, percent);
  3564. for (var i = 0; i < self._onframeList.length; i++) {
  3565. self._onframeList[i](target, percent);
  3566. }
  3567. };
  3568. }
  3569. // This optimization will help the case that in the upper application
  3570. // the view may be refreshed frequently, where animation will be
  3571. // called repeatly but nothing changed.
  3572. if (!clipCount) {
  3573. this._doneCallback();
  3574. }
  3575. return this;
  3576. },
  3577. /**
  3578. * 停止动画
  3579. * @param {boolean} forwardToLast If move to last frame before stop
  3580. */
  3581. stop: function (forwardToLast) {
  3582. var clipList = this._clipList;
  3583. var animation = this.animation;
  3584. for (var i = 0; i < clipList.length; i++) {
  3585. var clip = clipList[i];
  3586. if (forwardToLast) {
  3587. // Move to last frame before stop
  3588. clip.onframe(this._target, 1);
  3589. }
  3590. animation && animation.removeClip(clip);
  3591. }
  3592. clipList.length = 0;
  3593. },
  3594. /**
  3595. * 设置动画延迟开始的时间
  3596. * @param {number} time 单位ms
  3597. * @return {module:zrender/animation/Animator}
  3598. */
  3599. delay: function (time) {
  3600. this._delay = time;
  3601. return this;
  3602. },
  3603. /**
  3604. * 添加动画结束的回调
  3605. * @param {Function} cb
  3606. * @return {module:zrender/animation/Animator}
  3607. */
  3608. done: function(cb) {
  3609. if (cb) {
  3610. this._doneList.push(cb);
  3611. }
  3612. return this;
  3613. },
  3614. /**
  3615. * @return {Array.<module:zrender/animation/Clip>}
  3616. */
  3617. getClips: function () {
  3618. return this._clipList;
  3619. }
  3620. };
  3621. var dpr = 1;
  3622. // If in browser environment
  3623. if (typeof window !== 'undefined') {
  3624. dpr = Math.max(window.devicePixelRatio || 1, 1);
  3625. }
  3626. /**
  3627. * config默认配置项
  3628. * @exports zrender/config
  3629. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  3630. */
  3631. /**
  3632. * debug日志选项:catchBrushException为true下有效
  3633. * 0 : 不生成debug数据,发布用
  3634. * 1 : 异常抛出,调试用
  3635. * 2 : 控制台输出,调试用
  3636. */
  3637. var debugMode = 0;
  3638. // retina 屏幕优化
  3639. var devicePixelRatio = dpr;
  3640. var log = function () {
  3641. };
  3642. if (debugMode === 1) {
  3643. log = function () {
  3644. for (var k in arguments) {
  3645. throw new Error(arguments[k]);
  3646. }
  3647. };
  3648. }
  3649. else if (debugMode > 1) {
  3650. log = function () {
  3651. for (var k in arguments) {
  3652. console.log(arguments[k]);
  3653. }
  3654. };
  3655. }
  3656. var zrLog = log;
  3657. /**
  3658. * @alias modue:zrender/mixin/Animatable
  3659. * @constructor
  3660. */
  3661. var Animatable = function () {
  3662. /**
  3663. * @type {Array.<module:zrender/animation/Animator>}
  3664. * @readOnly
  3665. */
  3666. this.animators = [];
  3667. };
  3668. Animatable.prototype = {
  3669. constructor: Animatable,
  3670. /**
  3671. * 动画
  3672. *
  3673. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  3674. * @param {boolean} [loop] Whether to loop animation.
  3675. * @return {module:zrender/animation/Animator}
  3676. * @example:
  3677. * el.animate('style', false)
  3678. * .when(1000, {x: 10} )
  3679. * .done(function(){ // Animation done })
  3680. * .start()
  3681. */
  3682. animate: function (path, loop) {
  3683. var target;
  3684. var animatingShape = false;
  3685. var el = this;
  3686. var zr = this.__zr;
  3687. if (path) {
  3688. var pathSplitted = path.split('.');
  3689. var prop = el;
  3690. // If animating shape
  3691. animatingShape = pathSplitted[0] === 'shape';
  3692. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  3693. if (!prop) {
  3694. continue;
  3695. }
  3696. prop = prop[pathSplitted[i]];
  3697. }
  3698. if (prop) {
  3699. target = prop;
  3700. }
  3701. }
  3702. else {
  3703. target = el;
  3704. }
  3705. if (!target) {
  3706. zrLog(
  3707. 'Property "'
  3708. + path
  3709. + '" is not existed in element '
  3710. + el.id
  3711. );
  3712. return;
  3713. }
  3714. var animators = el.animators;
  3715. var animator = new Animator(target, loop);
  3716. animator.during(function (target) {
  3717. el.dirty(animatingShape);
  3718. })
  3719. .done(function () {
  3720. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  3721. animators.splice(indexOf(animators, animator), 1);
  3722. });
  3723. animators.push(animator);
  3724. // If animate after added to the zrender
  3725. if (zr) {
  3726. zr.animation.addAnimator(animator);
  3727. }
  3728. return animator;
  3729. },
  3730. /**
  3731. * 停止动画
  3732. * @param {boolean} forwardToLast If move to last frame before stop
  3733. */
  3734. stopAnimation: function (forwardToLast) {
  3735. var animators = this.animators;
  3736. var len = animators.length;
  3737. for (var i = 0; i < len; i++) {
  3738. animators[i].stop(forwardToLast);
  3739. }
  3740. animators.length = 0;
  3741. return this;
  3742. },
  3743. /**
  3744. * Caution: this method will stop previous animation.
  3745. * So do not use this method to one element twice before
  3746. * animation starts, unless you know what you are doing.
  3747. * @param {Object} target
  3748. * @param {number} [time=500] Time in ms
  3749. * @param {string} [easing='linear']
  3750. * @param {number} [delay=0]
  3751. * @param {Function} [callback]
  3752. * @param {Function} [forceAnimate] Prevent stop animation and callback
  3753. * immediently when target values are the same as current values.
  3754. *
  3755. * @example
  3756. * // Animate position
  3757. * el.animateTo({
  3758. * position: [10, 10]
  3759. * }, function () { // done })
  3760. *
  3761. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  3762. * el.animateTo({
  3763. * shape: {
  3764. * width: 500
  3765. * },
  3766. * style: {
  3767. * fill: 'red'
  3768. * }
  3769. * position: [10, 10]
  3770. * }, 100, 100, 'cubicOut', function () { // done })
  3771. */
  3772. // TODO Return animation key
  3773. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  3774. // animateTo(target, time, easing, callback);
  3775. if (isString(delay)) {
  3776. callback = easing;
  3777. easing = delay;
  3778. delay = 0;
  3779. }
  3780. // animateTo(target, time, delay, callback);
  3781. else if (isFunction(easing)) {
  3782. callback = easing;
  3783. easing = 'linear';
  3784. delay = 0;
  3785. }
  3786. // animateTo(target, time, callback);
  3787. else if (isFunction(delay)) {
  3788. callback = delay;
  3789. delay = 0;
  3790. }
  3791. // animateTo(target, callback)
  3792. else if (isFunction(time)) {
  3793. callback = time;
  3794. time = 500;
  3795. }
  3796. // animateTo(target)
  3797. else if (!time) {
  3798. time = 500;
  3799. }
  3800. // Stop all previous animations
  3801. this.stopAnimation();
  3802. this._animateToShallow('', this, target, time, delay);
  3803. // Animators may be removed immediately after start
  3804. // if there is nothing to animate
  3805. var animators = this.animators.slice();
  3806. var count = animators.length;
  3807. function done() {
  3808. count--;
  3809. if (!count) {
  3810. callback && callback();
  3811. }
  3812. }
  3813. // No animators. This should be checked before animators[i].start(),
  3814. // because 'done' may be executed immediately if no need to animate.
  3815. if (!count) {
  3816. callback && callback();
  3817. }
  3818. // Start after all animators created
  3819. // Incase any animator is done immediately when all animation properties are not changed
  3820. for (var i = 0; i < animators.length; i++) {
  3821. animators[i]
  3822. .done(done)
  3823. .start(easing, forceAnimate);
  3824. }
  3825. },
  3826. /**
  3827. * @private
  3828. * @param {string} path=''
  3829. * @param {Object} source=this
  3830. * @param {Object} target
  3831. * @param {number} [time=500]
  3832. * @param {number} [delay=0]
  3833. *
  3834. * @example
  3835. * // Animate position
  3836. * el._animateToShallow({
  3837. * position: [10, 10]
  3838. * })
  3839. *
  3840. * // Animate shape, style and position in 100ms, delayed 100ms
  3841. * el._animateToShallow({
  3842. * shape: {
  3843. * width: 500
  3844. * },
  3845. * style: {
  3846. * fill: 'red'
  3847. * }
  3848. * position: [10, 10]
  3849. * }, 100, 100)
  3850. */
  3851. _animateToShallow: function (path, source, target, time, delay) {
  3852. var objShallow = {};
  3853. var propertyCount = 0;
  3854. for (var name in target) {
  3855. if (!target.hasOwnProperty(name)) {
  3856. continue;
  3857. }
  3858. if (source[name] != null) {
  3859. if (isObject(target[name]) && !isArrayLike(target[name])) {
  3860. this._animateToShallow(
  3861. path ? path + '.' + name : name,
  3862. source[name],
  3863. target[name],
  3864. time,
  3865. delay
  3866. );
  3867. }
  3868. else {
  3869. objShallow[name] = target[name];
  3870. propertyCount++;
  3871. }
  3872. }
  3873. else if (target[name] != null) {
  3874. // Attr directly if not has property
  3875. // FIXME, if some property not needed for element ?
  3876. if (!path) {
  3877. this.attr(name, target[name]);
  3878. }
  3879. else { // Shape or style
  3880. var props = {};
  3881. props[path] = {};
  3882. props[path][name] = target[name];
  3883. this.attr(props);
  3884. }
  3885. }
  3886. }
  3887. if (propertyCount > 0) {
  3888. this.animate(path, false)
  3889. .when(time == null ? 500 : time, objShallow)
  3890. .delay(delay || 0);
  3891. }
  3892. return this;
  3893. }
  3894. };
  3895. /**
  3896. * @alias module:zrender/Element
  3897. * @constructor
  3898. * @extends {module:zrender/mixin/Animatable}
  3899. * @extends {module:zrender/mixin/Transformable}
  3900. * @extends {module:zrender/mixin/Eventful}
  3901. */
  3902. var Element = function (opts) { // jshint ignore:line
  3903. Transformable.call(this, opts);
  3904. Eventful.call(this, opts);
  3905. Animatable.call(this, opts);
  3906. /**
  3907. * 画布元素ID
  3908. * @type {string}
  3909. */
  3910. this.id = opts.id || guid();
  3911. };
  3912. Element.prototype = {
  3913. /**
  3914. * 元素类型
  3915. * Element type
  3916. * @type {string}
  3917. */
  3918. type: 'element',
  3919. /**
  3920. * 元素名字
  3921. * Element name
  3922. * @type {string}
  3923. */
  3924. name: '',
  3925. /**
  3926. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  3927. * ZRender instance will be assigned when element is associated with zrender
  3928. * @name module:/zrender/Element#__zr
  3929. * @type {module:zrender/ZRender}
  3930. */
  3931. __zr: null,
  3932. /**
  3933. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  3934. * If ignore drawing and events of the element object
  3935. * @name module:/zrender/Element#ignore
  3936. * @type {boolean}
  3937. * @default false
  3938. */
  3939. ignore: false,
  3940. /**
  3941. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  3942. * 该路径会继承被裁减对象的变换
  3943. * @type {module:zrender/graphic/Path}
  3944. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  3945. * @readOnly
  3946. */
  3947. clipPath: null,
  3948. /**
  3949. * Drift element
  3950. * @param {number} dx dx on the global space
  3951. * @param {number} dy dy on the global space
  3952. */
  3953. drift: function (dx, dy) {
  3954. switch (this.draggable) {
  3955. case 'horizontal':
  3956. dy = 0;
  3957. break;
  3958. case 'vertical':
  3959. dx = 0;
  3960. break;
  3961. }
  3962. var m = this.transform;
  3963. if (!m) {
  3964. m = this.transform = [1, 0, 0, 1, 0, 0];
  3965. }
  3966. m[4] += dx;
  3967. m[5] += dy;
  3968. this.decomposeTransform();
  3969. this.dirty(false);
  3970. },
  3971. /**
  3972. * Hook before update
  3973. */
  3974. beforeUpdate: function () {},
  3975. /**
  3976. * Hook after update
  3977. */
  3978. afterUpdate: function () {},
  3979. /**
  3980. * Update each frame
  3981. */
  3982. update: function () {
  3983. this.updateTransform();
  3984. },
  3985. /**
  3986. * @param {Function} cb
  3987. * @param {} context
  3988. */
  3989. traverse: function (cb, context) {},
  3990. /**
  3991. * @protected
  3992. */
  3993. attrKV: function (key, value) {
  3994. if (key === 'position' || key === 'scale' || key === 'origin') {
  3995. // Copy the array
  3996. if (value) {
  3997. var target = this[key];
  3998. if (!target) {
  3999. target = this[key] = [];
  4000. }
  4001. target[0] = value[0];
  4002. target[1] = value[1];
  4003. }
  4004. }
  4005. else {
  4006. this[key] = value;
  4007. }
  4008. },
  4009. /**
  4010. * Hide the element
  4011. */
  4012. hide: function () {
  4013. this.ignore = true;
  4014. this.__zr && this.__zr.refresh();
  4015. },
  4016. /**
  4017. * Show the element
  4018. */
  4019. show: function () {
  4020. this.ignore = false;
  4021. this.__zr && this.__zr.refresh();
  4022. },
  4023. /**
  4024. * @param {string|Object} key
  4025. * @param {*} value
  4026. */
  4027. attr: function (key, value) {
  4028. if (typeof key === 'string') {
  4029. this.attrKV(key, value);
  4030. }
  4031. else if (isObject(key)) {
  4032. for (var name in key) {
  4033. if (key.hasOwnProperty(name)) {
  4034. this.attrKV(name, key[name]);
  4035. }
  4036. }
  4037. }
  4038. this.dirty(false);
  4039. return this;
  4040. },
  4041. /**
  4042. * @param {module:zrender/graphic/Path} clipPath
  4043. */
  4044. setClipPath: function (clipPath) {
  4045. var zr = this.__zr;
  4046. if (zr) {
  4047. clipPath.addSelfToZr(zr);
  4048. }
  4049. // Remove previous clip path
  4050. if (this.clipPath && this.clipPath !== clipPath) {
  4051. this.removeClipPath();
  4052. }
  4053. this.clipPath = clipPath;
  4054. clipPath.__zr = zr;
  4055. clipPath.__clipTarget = this;
  4056. this.dirty(false);
  4057. },
  4058. /**
  4059. */
  4060. removeClipPath: function () {
  4061. var clipPath = this.clipPath;
  4062. if (clipPath) {
  4063. if (clipPath.__zr) {
  4064. clipPath.removeSelfFromZr(clipPath.__zr);
  4065. }
  4066. clipPath.__zr = null;
  4067. clipPath.__clipTarget = null;
  4068. this.clipPath = null;
  4069. this.dirty(false);
  4070. }
  4071. },
  4072. /**
  4073. * Add self from zrender instance.
  4074. * Not recursively because it will be invoked when element added to storage.
  4075. * @param {module:zrender/ZRender} zr
  4076. */
  4077. addSelfToZr: function (zr) {
  4078. this.__zr = zr;
  4079. // 添加动画
  4080. var animators = this.animators;
  4081. if (animators) {
  4082. for (var i = 0; i < animators.length; i++) {
  4083. zr.animation.addAnimator(animators[i]);
  4084. }
  4085. }
  4086. if (this.clipPath) {
  4087. this.clipPath.addSelfToZr(zr);
  4088. }
  4089. },
  4090. /**
  4091. * Remove self from zrender instance.
  4092. * Not recursively because it will be invoked when element added to storage.
  4093. * @param {module:zrender/ZRender} zr
  4094. */
  4095. removeSelfFromZr: function (zr) {
  4096. this.__zr = null;
  4097. // 移除动画
  4098. var animators = this.animators;
  4099. if (animators) {
  4100. for (var i = 0; i < animators.length; i++) {
  4101. zr.animation.removeAnimator(animators[i]);
  4102. }
  4103. }
  4104. if (this.clipPath) {
  4105. this.clipPath.removeSelfFromZr(zr);
  4106. }
  4107. }
  4108. };
  4109. mixin(Element, Animatable);
  4110. mixin(Element, Transformable);
  4111. mixin(Element, Eventful);
  4112. /**
  4113. * @module echarts/core/BoundingRect
  4114. */
  4115. var v2ApplyTransform = applyTransform;
  4116. var mathMin = Math.min;
  4117. var mathMax = Math.max;
  4118. /**
  4119. * @alias module:echarts/core/BoundingRect
  4120. */
  4121. function BoundingRect(x, y, width, height) {
  4122. if (width < 0) {
  4123. x = x + width;
  4124. width = -width;
  4125. }
  4126. if (height < 0) {
  4127. y = y + height;
  4128. height = -height;
  4129. }
  4130. /**
  4131. * @type {number}
  4132. */
  4133. this.x = x;
  4134. /**
  4135. * @type {number}
  4136. */
  4137. this.y = y;
  4138. /**
  4139. * @type {number}
  4140. */
  4141. this.width = width;
  4142. /**
  4143. * @type {number}
  4144. */
  4145. this.height = height;
  4146. }
  4147. BoundingRect.prototype = {
  4148. constructor: BoundingRect,
  4149. /**
  4150. * @param {module:echarts/core/BoundingRect} other
  4151. */
  4152. union: function (other) {
  4153. var x = mathMin(other.x, this.x);
  4154. var y = mathMin(other.y, this.y);
  4155. this.width = mathMax(
  4156. other.x + other.width,
  4157. this.x + this.width
  4158. ) - x;
  4159. this.height = mathMax(
  4160. other.y + other.height,
  4161. this.y + this.height
  4162. ) - y;
  4163. this.x = x;
  4164. this.y = y;
  4165. },
  4166. /**
  4167. * @param {Array.<number>} m
  4168. * @methods
  4169. */
  4170. applyTransform: (function () {
  4171. var lt = [];
  4172. var rb = [];
  4173. var lb = [];
  4174. var rt = [];
  4175. return function (m) {
  4176. // In case usage like this
  4177. // el.getBoundingRect().applyTransform(el.transform)
  4178. // And element has no transform
  4179. if (!m) {
  4180. return;
  4181. }
  4182. lt[0] = lb[0] = this.x;
  4183. lt[1] = rt[1] = this.y;
  4184. rb[0] = rt[0] = this.x + this.width;
  4185. rb[1] = lb[1] = this.y + this.height;
  4186. v2ApplyTransform(lt, lt, m);
  4187. v2ApplyTransform(rb, rb, m);
  4188. v2ApplyTransform(lb, lb, m);
  4189. v2ApplyTransform(rt, rt, m);
  4190. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4191. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4192. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4193. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4194. this.width = maxX - this.x;
  4195. this.height = maxY - this.y;
  4196. };
  4197. })(),
  4198. /**
  4199. * Calculate matrix of transforming from self to target rect
  4200. * @param {module:zrender/core/BoundingRect} b
  4201. * @return {Array.<number>}
  4202. */
  4203. calculateTransform: function (b) {
  4204. var a = this;
  4205. var sx = b.width / a.width;
  4206. var sy = b.height / a.height;
  4207. var m = create$1();
  4208. // 矩阵右乘
  4209. translate(m, m, [-a.x, -a.y]);
  4210. scale$1(m, m, [sx, sy]);
  4211. translate(m, m, [b.x, b.y]);
  4212. return m;
  4213. },
  4214. /**
  4215. * @param {(module:echarts/core/BoundingRect|Object)} b
  4216. * @return {boolean}
  4217. */
  4218. intersect: function (b) {
  4219. if (!b) {
  4220. return false;
  4221. }
  4222. if (!(b instanceof BoundingRect)) {
  4223. // Normalize negative width/height.
  4224. b = BoundingRect.create(b);
  4225. }
  4226. var a = this;
  4227. var ax0 = a.x;
  4228. var ax1 = a.x + a.width;
  4229. var ay0 = a.y;
  4230. var ay1 = a.y + a.height;
  4231. var bx0 = b.x;
  4232. var bx1 = b.x + b.width;
  4233. var by0 = b.y;
  4234. var by1 = b.y + b.height;
  4235. return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4236. },
  4237. contain: function (x, y) {
  4238. var rect = this;
  4239. return x >= rect.x
  4240. && x <= (rect.x + rect.width)
  4241. && y >= rect.y
  4242. && y <= (rect.y + rect.height);
  4243. },
  4244. /**
  4245. * @return {module:echarts/core/BoundingRect}
  4246. */
  4247. clone: function () {
  4248. return new BoundingRect(this.x, this.y, this.width, this.height);
  4249. },
  4250. /**
  4251. * Copy from another rect
  4252. */
  4253. copy: function (other) {
  4254. this.x = other.x;
  4255. this.y = other.y;
  4256. this.width = other.width;
  4257. this.height = other.height;
  4258. },
  4259. plain: function () {
  4260. return {
  4261. x: this.x,
  4262. y: this.y,
  4263. width: this.width,
  4264. height: this.height
  4265. };
  4266. }
  4267. };
  4268. /**
  4269. * @param {Object|module:zrender/core/BoundingRect} rect
  4270. * @param {number} rect.x
  4271. * @param {number} rect.y
  4272. * @param {number} rect.width
  4273. * @param {number} rect.height
  4274. * @return {module:zrender/core/BoundingRect}
  4275. */
  4276. BoundingRect.create = function (rect) {
  4277. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4278. };
  4279. /**
  4280. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  4281. * @module zrender/graphic/Group
  4282. * @example
  4283. * var Group = require('zrender/container/Group');
  4284. * var Circle = require('zrender/graphic/shape/Circle');
  4285. * var g = new Group();
  4286. * g.position[0] = 100;
  4287. * g.position[1] = 100;
  4288. * g.add(new Circle({
  4289. * style: {
  4290. * x: 100,
  4291. * y: 100,
  4292. * r: 20,
  4293. * }
  4294. * }));
  4295. * zr.add(g);
  4296. */
  4297. /**
  4298. * @alias module:zrender/graphic/Group
  4299. * @constructor
  4300. * @extends module:zrender/mixin/Transformable
  4301. * @extends module:zrender/mixin/Eventful
  4302. */
  4303. var Group = function (opts) {
  4304. opts = opts || {};
  4305. Element.call(this, opts);
  4306. for (var key in opts) {
  4307. if (opts.hasOwnProperty(key)) {
  4308. this[key] = opts[key];
  4309. }
  4310. }
  4311. this._children = [];
  4312. this.__storage = null;
  4313. this.__dirty = true;
  4314. };
  4315. Group.prototype = {
  4316. constructor: Group,
  4317. isGroup: true,
  4318. /**
  4319. * @type {string}
  4320. */
  4321. type: 'group',
  4322. /**
  4323. * 所有子孙元素是否响应鼠标事件
  4324. * @name module:/zrender/container/Group#silent
  4325. * @type {boolean}
  4326. * @default false
  4327. */
  4328. silent: false,
  4329. /**
  4330. * @return {Array.<module:zrender/Element>}
  4331. */
  4332. children: function () {
  4333. return this._children.slice();
  4334. },
  4335. /**
  4336. * 获取指定 index 的儿子节点
  4337. * @param {number} idx
  4338. * @return {module:zrender/Element}
  4339. */
  4340. childAt: function (idx) {
  4341. return this._children[idx];
  4342. },
  4343. /**
  4344. * 获取指定名字的儿子节点
  4345. * @param {string} name
  4346. * @return {module:zrender/Element}
  4347. */
  4348. childOfName: function (name) {
  4349. var children = this._children;
  4350. for (var i = 0; i < children.length; i++) {
  4351. if (children[i].name === name) {
  4352. return children[i];
  4353. }
  4354. }
  4355. },
  4356. /**
  4357. * @return {number}
  4358. */
  4359. childCount: function () {
  4360. return this._children.length;
  4361. },
  4362. /**
  4363. * 添加子节点到最后
  4364. * @param {module:zrender/Element} child
  4365. */
  4366. add: function (child) {
  4367. if (child && child !== this && child.parent !== this) {
  4368. this._children.push(child);
  4369. this._doAdd(child);
  4370. }
  4371. return this;
  4372. },
  4373. /**
  4374. * 添加子节点在 nextSibling 之前
  4375. * @param {module:zrender/Element} child
  4376. * @param {module:zrender/Element} nextSibling
  4377. */
  4378. addBefore: function (child, nextSibling) {
  4379. if (child && child !== this && child.parent !== this
  4380. && nextSibling && nextSibling.parent === this) {
  4381. var children = this._children;
  4382. var idx = children.indexOf(nextSibling);
  4383. if (idx >= 0) {
  4384. children.splice(idx, 0, child);
  4385. this._doAdd(child);
  4386. }
  4387. }
  4388. return this;
  4389. },
  4390. _doAdd: function (child) {
  4391. if (child.parent) {
  4392. child.parent.remove(child);
  4393. }
  4394. child.parent = this;
  4395. var storage = this.__storage;
  4396. var zr = this.__zr;
  4397. if (storage && storage !== child.__storage) {
  4398. storage.addToStorage(child);
  4399. if (child instanceof Group) {
  4400. child.addChildrenToStorage(storage);
  4401. }
  4402. }
  4403. zr && zr.refresh();
  4404. },
  4405. /**
  4406. * 移除子节点
  4407. * @param {module:zrender/Element} child
  4408. */
  4409. remove: function (child) {
  4410. var zr = this.__zr;
  4411. var storage = this.__storage;
  4412. var children = this._children;
  4413. var idx = indexOf(children, child);
  4414. if (idx < 0) {
  4415. return this;
  4416. }
  4417. children.splice(idx, 1);
  4418. child.parent = null;
  4419. if (storage) {
  4420. storage.delFromStorage(child);
  4421. if (child instanceof Group) {
  4422. child.delChildrenFromStorage(storage);
  4423. }
  4424. }
  4425. zr && zr.refresh();
  4426. return this;
  4427. },
  4428. /**
  4429. * 移除所有子节点
  4430. */
  4431. removeAll: function () {
  4432. var children = this._children;
  4433. var storage = this.__storage;
  4434. var child;
  4435. var i;
  4436. for (i = 0; i < children.length; i++) {
  4437. child = children[i];
  4438. if (storage) {
  4439. storage.delFromStorage(child);
  4440. if (child instanceof Group) {
  4441. child.delChildrenFromStorage(storage);
  4442. }
  4443. }
  4444. child.parent = null;
  4445. }
  4446. children.length = 0;
  4447. return this;
  4448. },
  4449. /**
  4450. * 遍历所有子节点
  4451. * @param {Function} cb
  4452. * @param {} context
  4453. */
  4454. eachChild: function (cb, context) {
  4455. var children = this._children;
  4456. for (var i = 0; i < children.length; i++) {
  4457. var child = children[i];
  4458. cb.call(context, child, i);
  4459. }
  4460. return this;
  4461. },
  4462. /**
  4463. * 深度优先遍历所有子孙节点
  4464. * @param {Function} cb
  4465. * @param {} context
  4466. */
  4467. traverse: function (cb, context) {
  4468. for (var i = 0; i < this._children.length; i++) {
  4469. var child = this._children[i];
  4470. cb.call(context, child);
  4471. if (child.type === 'group') {
  4472. child.traverse(cb, context);
  4473. }
  4474. }
  4475. return this;
  4476. },
  4477. addChildrenToStorage: function (storage) {
  4478. for (var i = 0; i < this._children.length; i++) {
  4479. var child = this._children[i];
  4480. storage.addToStorage(child);
  4481. if (child instanceof Group) {
  4482. child.addChildrenToStorage(storage);
  4483. }
  4484. }
  4485. },
  4486. delChildrenFromStorage: function (storage) {
  4487. for (var i = 0; i < this._children.length; i++) {
  4488. var child = this._children[i];
  4489. storage.delFromStorage(child);
  4490. if (child instanceof Group) {
  4491. child.delChildrenFromStorage(storage);
  4492. }
  4493. }
  4494. },
  4495. dirty: function () {
  4496. this.__dirty = true;
  4497. this.__zr && this.__zr.refresh();
  4498. return this;
  4499. },
  4500. /**
  4501. * @return {module:zrender/core/BoundingRect}
  4502. */
  4503. getBoundingRect: function (includeChildren) {
  4504. // TODO Caching
  4505. var rect = null;
  4506. var tmpRect = new BoundingRect(0, 0, 0, 0);
  4507. var children = includeChildren || this._children;
  4508. var tmpMat = [];
  4509. for (var i = 0; i < children.length; i++) {
  4510. var child = children[i];
  4511. if (child.ignore || child.invisible) {
  4512. continue;
  4513. }
  4514. var childRect = child.getBoundingRect();
  4515. var transform = child.getLocalTransform(tmpMat);
  4516. // TODO
  4517. // The boundingRect cacluated by transforming original
  4518. // rect may be bigger than the actual bundingRect when rotation
  4519. // is used. (Consider a circle rotated aginst its center, where
  4520. // the actual boundingRect should be the same as that not be
  4521. // rotated.) But we can not find better approach to calculate
  4522. // actual boundingRect yet, considering performance.
  4523. if (transform) {
  4524. tmpRect.copy(childRect);
  4525. tmpRect.applyTransform(transform);
  4526. rect = rect || tmpRect.clone();
  4527. rect.union(tmpRect);
  4528. }
  4529. else {
  4530. rect = rect || childRect.clone();
  4531. rect.union(childRect);
  4532. }
  4533. }
  4534. return rect || tmpRect;
  4535. }
  4536. };
  4537. inherits(Group, Element);
  4538. // https://github.com/mziccard/node-timsort
  4539. var DEFAULT_MIN_MERGE = 32;
  4540. var DEFAULT_MIN_GALLOPING = 7;
  4541. function minRunLength(n) {
  4542. var r = 0;
  4543. while (n >= DEFAULT_MIN_MERGE) {
  4544. r |= n & 1;
  4545. n >>= 1;
  4546. }
  4547. return n + r;
  4548. }
  4549. function makeAscendingRun(array, lo, hi, compare) {
  4550. var runHi = lo + 1;
  4551. if (runHi === hi) {
  4552. return 1;
  4553. }
  4554. if (compare(array[runHi++], array[lo]) < 0) {
  4555. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  4556. runHi++;
  4557. }
  4558. reverseRun(array, lo, runHi);
  4559. }
  4560. else {
  4561. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  4562. runHi++;
  4563. }
  4564. }
  4565. return runHi - lo;
  4566. }
  4567. function reverseRun(array, lo, hi) {
  4568. hi--;
  4569. while (lo < hi) {
  4570. var t = array[lo];
  4571. array[lo++] = array[hi];
  4572. array[hi--] = t;
  4573. }
  4574. }
  4575. function binaryInsertionSort(array, lo, hi, start, compare) {
  4576. if (start === lo) {
  4577. start++;
  4578. }
  4579. for (; start < hi; start++) {
  4580. var pivot = array[start];
  4581. var left = lo;
  4582. var right = start;
  4583. var mid;
  4584. while (left < right) {
  4585. mid = left + right >>> 1;
  4586. if (compare(pivot, array[mid]) < 0) {
  4587. right = mid;
  4588. }
  4589. else {
  4590. left = mid + 1;
  4591. }
  4592. }
  4593. var n = start - left;
  4594. switch (n) {
  4595. case 3:
  4596. array[left + 3] = array[left + 2];
  4597. case 2:
  4598. array[left + 2] = array[left + 1];
  4599. case 1:
  4600. array[left + 1] = array[left];
  4601. break;
  4602. default:
  4603. while (n > 0) {
  4604. array[left + n] = array[left + n - 1];
  4605. n--;
  4606. }
  4607. }
  4608. array[left] = pivot;
  4609. }
  4610. }
  4611. function gallopLeft(value, array, start, length, hint, compare) {
  4612. var lastOffset = 0;
  4613. var maxOffset = 0;
  4614. var offset = 1;
  4615. if (compare(value, array[start + hint]) > 0) {
  4616. maxOffset = length - hint;
  4617. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  4618. lastOffset = offset;
  4619. offset = (offset << 1) + 1;
  4620. if (offset <= 0) {
  4621. offset = maxOffset;
  4622. }
  4623. }
  4624. if (offset > maxOffset) {
  4625. offset = maxOffset;
  4626. }
  4627. lastOffset += hint;
  4628. offset += hint;
  4629. }
  4630. else {
  4631. maxOffset = hint + 1;
  4632. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  4633. lastOffset = offset;
  4634. offset = (offset << 1) + 1;
  4635. if (offset <= 0) {
  4636. offset = maxOffset;
  4637. }
  4638. }
  4639. if (offset > maxOffset) {
  4640. offset = maxOffset;
  4641. }
  4642. var tmp = lastOffset;
  4643. lastOffset = hint - offset;
  4644. offset = hint - tmp;
  4645. }
  4646. lastOffset++;
  4647. while (lastOffset < offset) {
  4648. var m = lastOffset + (offset - lastOffset >>> 1);
  4649. if (compare(value, array[start + m]) > 0) {
  4650. lastOffset = m + 1;
  4651. }
  4652. else {
  4653. offset = m;
  4654. }
  4655. }
  4656. return offset;
  4657. }
  4658. function gallopRight(value, array, start, length, hint, compare) {
  4659. var lastOffset = 0;
  4660. var maxOffset = 0;
  4661. var offset = 1;
  4662. if (compare(value, array[start + hint]) < 0) {
  4663. maxOffset = hint + 1;
  4664. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  4665. lastOffset = offset;
  4666. offset = (offset << 1) + 1;
  4667. if (offset <= 0) {
  4668. offset = maxOffset;
  4669. }
  4670. }
  4671. if (offset > maxOffset) {
  4672. offset = maxOffset;
  4673. }
  4674. var tmp = lastOffset;
  4675. lastOffset = hint - offset;
  4676. offset = hint - tmp;
  4677. }
  4678. else {
  4679. maxOffset = length - hint;
  4680. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  4681. lastOffset = offset;
  4682. offset = (offset << 1) + 1;
  4683. if (offset <= 0) {
  4684. offset = maxOffset;
  4685. }
  4686. }
  4687. if (offset > maxOffset) {
  4688. offset = maxOffset;
  4689. }
  4690. lastOffset += hint;
  4691. offset += hint;
  4692. }
  4693. lastOffset++;
  4694. while (lastOffset < offset) {
  4695. var m = lastOffset + (offset - lastOffset >>> 1);
  4696. if (compare(value, array[start + m]) < 0) {
  4697. offset = m;
  4698. }
  4699. else {
  4700. lastOffset = m + 1;
  4701. }
  4702. }
  4703. return offset;
  4704. }
  4705. function TimSort(array, compare) {
  4706. var minGallop = DEFAULT_MIN_GALLOPING;
  4707. var runStart;
  4708. var runLength;
  4709. var stackSize = 0;
  4710. var tmp = [];
  4711. runStart = [];
  4712. runLength = [];
  4713. function pushRun(_runStart, _runLength) {
  4714. runStart[stackSize] = _runStart;
  4715. runLength[stackSize] = _runLength;
  4716. stackSize += 1;
  4717. }
  4718. function mergeRuns() {
  4719. while (stackSize > 1) {
  4720. var n = stackSize - 2;
  4721. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  4722. if (runLength[n - 1] < runLength[n + 1]) {
  4723. n--;
  4724. }
  4725. }
  4726. else if (runLength[n] > runLength[n + 1]) {
  4727. break;
  4728. }
  4729. mergeAt(n);
  4730. }
  4731. }
  4732. function forceMergeRuns() {
  4733. while (stackSize > 1) {
  4734. var n = stackSize - 2;
  4735. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  4736. n--;
  4737. }
  4738. mergeAt(n);
  4739. }
  4740. }
  4741. function mergeAt(i) {
  4742. var start1 = runStart[i];
  4743. var length1 = runLength[i];
  4744. var start2 = runStart[i + 1];
  4745. var length2 = runLength[i + 1];
  4746. runLength[i] = length1 + length2;
  4747. if (i === stackSize - 3) {
  4748. runStart[i + 1] = runStart[i + 2];
  4749. runLength[i + 1] = runLength[i + 2];
  4750. }
  4751. stackSize--;
  4752. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  4753. start1 += k;
  4754. length1 -= k;
  4755. if (length1 === 0) {
  4756. return;
  4757. }
  4758. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  4759. if (length2 === 0) {
  4760. return;
  4761. }
  4762. if (length1 <= length2) {
  4763. mergeLow(start1, length1, start2, length2);
  4764. }
  4765. else {
  4766. mergeHigh(start1, length1, start2, length2);
  4767. }
  4768. }
  4769. function mergeLow(start1, length1, start2, length2) {
  4770. var i = 0;
  4771. for (i = 0; i < length1; i++) {
  4772. tmp[i] = array[start1 + i];
  4773. }
  4774. var cursor1 = 0;
  4775. var cursor2 = start2;
  4776. var dest = start1;
  4777. array[dest++] = array[cursor2++];
  4778. if (--length2 === 0) {
  4779. for (i = 0; i < length1; i++) {
  4780. array[dest + i] = tmp[cursor1 + i];
  4781. }
  4782. return;
  4783. }
  4784. if (length1 === 1) {
  4785. for (i = 0; i < length2; i++) {
  4786. array[dest + i] = array[cursor2 + i];
  4787. }
  4788. array[dest + length2] = tmp[cursor1];
  4789. return;
  4790. }
  4791. var _minGallop = minGallop;
  4792. var count1, count2, exit;
  4793. while (1) {
  4794. count1 = 0;
  4795. count2 = 0;
  4796. exit = false;
  4797. do {
  4798. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  4799. array[dest++] = array[cursor2++];
  4800. count2++;
  4801. count1 = 0;
  4802. if (--length2 === 0) {
  4803. exit = true;
  4804. break;
  4805. }
  4806. }
  4807. else {
  4808. array[dest++] = tmp[cursor1++];
  4809. count1++;
  4810. count2 = 0;
  4811. if (--length1 === 1) {
  4812. exit = true;
  4813. break;
  4814. }
  4815. }
  4816. } while ((count1 | count2) < _minGallop);
  4817. if (exit) {
  4818. break;
  4819. }
  4820. do {
  4821. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  4822. if (count1 !== 0) {
  4823. for (i = 0; i < count1; i++) {
  4824. array[dest + i] = tmp[cursor1 + i];
  4825. }
  4826. dest += count1;
  4827. cursor1 += count1;
  4828. length1 -= count1;
  4829. if (length1 <= 1) {
  4830. exit = true;
  4831. break;
  4832. }
  4833. }
  4834. array[dest++] = array[cursor2++];
  4835. if (--length2 === 0) {
  4836. exit = true;
  4837. break;
  4838. }
  4839. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  4840. if (count2 !== 0) {
  4841. for (i = 0; i < count2; i++) {
  4842. array[dest + i] = array[cursor2 + i];
  4843. }
  4844. dest += count2;
  4845. cursor2 += count2;
  4846. length2 -= count2;
  4847. if (length2 === 0) {
  4848. exit = true;
  4849. break;
  4850. }
  4851. }
  4852. array[dest++] = tmp[cursor1++];
  4853. if (--length1 === 1) {
  4854. exit = true;
  4855. break;
  4856. }
  4857. _minGallop--;
  4858. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  4859. if (exit) {
  4860. break;
  4861. }
  4862. if (_minGallop < 0) {
  4863. _minGallop = 0;
  4864. }
  4865. _minGallop += 2;
  4866. }
  4867. minGallop = _minGallop;
  4868. minGallop < 1 && (minGallop = 1);
  4869. if (length1 === 1) {
  4870. for (i = 0; i < length2; i++) {
  4871. array[dest + i] = array[cursor2 + i];
  4872. }
  4873. array[dest + length2] = tmp[cursor1];
  4874. }
  4875. else if (length1 === 0) {
  4876. throw new Error();
  4877. // throw new Error('mergeLow preconditions were not respected');
  4878. }
  4879. else {
  4880. for (i = 0; i < length1; i++) {
  4881. array[dest + i] = tmp[cursor1 + i];
  4882. }
  4883. }
  4884. }
  4885. function mergeHigh (start1, length1, start2, length2) {
  4886. var i = 0;
  4887. for (i = 0; i < length2; i++) {
  4888. tmp[i] = array[start2 + i];
  4889. }
  4890. var cursor1 = start1 + length1 - 1;
  4891. var cursor2 = length2 - 1;
  4892. var dest = start2 + length2 - 1;
  4893. var customCursor = 0;
  4894. var customDest = 0;
  4895. array[dest--] = array[cursor1--];
  4896. if (--length1 === 0) {
  4897. customCursor = dest - (length2 - 1);
  4898. for (i = 0; i < length2; i++) {
  4899. array[customCursor + i] = tmp[i];
  4900. }
  4901. return;
  4902. }
  4903. if (length2 === 1) {
  4904. dest -= length1;
  4905. cursor1 -= length1;
  4906. customDest = dest + 1;
  4907. customCursor = cursor1 + 1;
  4908. for (i = length1 - 1; i >= 0; i--) {
  4909. array[customDest + i] = array[customCursor + i];
  4910. }
  4911. array[dest] = tmp[cursor2];
  4912. return;
  4913. }
  4914. var _minGallop = minGallop;
  4915. while (true) {
  4916. var count1 = 0;
  4917. var count2 = 0;
  4918. var exit = false;
  4919. do {
  4920. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  4921. array[dest--] = array[cursor1--];
  4922. count1++;
  4923. count2 = 0;
  4924. if (--length1 === 0) {
  4925. exit = true;
  4926. break;
  4927. }
  4928. }
  4929. else {
  4930. array[dest--] = tmp[cursor2--];
  4931. count2++;
  4932. count1 = 0;
  4933. if (--length2 === 1) {
  4934. exit = true;
  4935. break;
  4936. }
  4937. }
  4938. } while ((count1 | count2) < _minGallop);
  4939. if (exit) {
  4940. break;
  4941. }
  4942. do {
  4943. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  4944. if (count1 !== 0) {
  4945. dest -= count1;
  4946. cursor1 -= count1;
  4947. length1 -= count1;
  4948. customDest = dest + 1;
  4949. customCursor = cursor1 + 1;
  4950. for (i = count1 - 1; i >= 0; i--) {
  4951. array[customDest + i] = array[customCursor + i];
  4952. }
  4953. if (length1 === 0) {
  4954. exit = true;
  4955. break;
  4956. }
  4957. }
  4958. array[dest--] = tmp[cursor2--];
  4959. if (--length2 === 1) {
  4960. exit = true;
  4961. break;
  4962. }
  4963. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  4964. if (count2 !== 0) {
  4965. dest -= count2;
  4966. cursor2 -= count2;
  4967. length2 -= count2;
  4968. customDest = dest + 1;
  4969. customCursor = cursor2 + 1;
  4970. for (i = 0; i < count2; i++) {
  4971. array[customDest + i] = tmp[customCursor + i];
  4972. }
  4973. if (length2 <= 1) {
  4974. exit = true;
  4975. break;
  4976. }
  4977. }
  4978. array[dest--] = array[cursor1--];
  4979. if (--length1 === 0) {
  4980. exit = true;
  4981. break;
  4982. }
  4983. _minGallop--;
  4984. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  4985. if (exit) {
  4986. break;
  4987. }
  4988. if (_minGallop < 0) {
  4989. _minGallop = 0;
  4990. }
  4991. _minGallop += 2;
  4992. }
  4993. minGallop = _minGallop;
  4994. if (minGallop < 1) {
  4995. minGallop = 1;
  4996. }
  4997. if (length2 === 1) {
  4998. dest -= length1;
  4999. cursor1 -= length1;
  5000. customDest = dest + 1;
  5001. customCursor = cursor1 + 1;
  5002. for (i = length1 - 1; i >= 0; i--) {
  5003. array[customDest + i] = array[customCursor + i];
  5004. }
  5005. array[dest] = tmp[cursor2];
  5006. }
  5007. else if (length2 === 0) {
  5008. throw new Error();
  5009. // throw new Error('mergeHigh preconditions were not respected');
  5010. }
  5011. else {
  5012. customCursor = dest - (length2 - 1);
  5013. for (i = 0; i < length2; i++) {
  5014. array[customCursor + i] = tmp[i];
  5015. }
  5016. }
  5017. }
  5018. this.mergeRuns = mergeRuns;
  5019. this.forceMergeRuns = forceMergeRuns;
  5020. this.pushRun = pushRun;
  5021. }
  5022. function sort(array, compare, lo, hi) {
  5023. if (!lo) {
  5024. lo = 0;
  5025. }
  5026. if (!hi) {
  5027. hi = array.length;
  5028. }
  5029. var remaining = hi - lo;
  5030. if (remaining < 2) {
  5031. return;
  5032. }
  5033. var runLength = 0;
  5034. if (remaining < DEFAULT_MIN_MERGE) {
  5035. runLength = makeAscendingRun(array, lo, hi, compare);
  5036. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5037. return;
  5038. }
  5039. var ts = new TimSort(array, compare);
  5040. var minRun = minRunLength(remaining);
  5041. do {
  5042. runLength = makeAscendingRun(array, lo, hi, compare);
  5043. if (runLength < minRun) {
  5044. var force = remaining;
  5045. if (force > minRun) {
  5046. force = minRun;
  5047. }
  5048. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5049. runLength = force;
  5050. }
  5051. ts.pushRun(lo, runLength);
  5052. ts.mergeRuns();
  5053. remaining -= runLength;
  5054. lo += runLength;
  5055. } while (remaining !== 0);
  5056. ts.forceMergeRuns();
  5057. }
  5058. /**
  5059. * Storage内容仓库模块
  5060. * @module zrender/Storage
  5061. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  5062. * @author errorrik (errorrik@gmail.com)
  5063. * @author pissang (https://github.com/pissang/)
  5064. */
  5065. // Use timsort because in most case elements are partially sorted
  5066. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5067. function shapeCompareFunc(a, b) {
  5068. if (a.zlevel === b.zlevel) {
  5069. if (a.z === b.z) {
  5070. // if (a.z2 === b.z2) {
  5071. // // FIXME Slow has renderidx compare
  5072. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5073. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5074. // return a.__renderidx - b.__renderidx;
  5075. // }
  5076. return a.z2 - b.z2;
  5077. }
  5078. return a.z - b.z;
  5079. }
  5080. return a.zlevel - b.zlevel;
  5081. }
  5082. /**
  5083. * 内容仓库 (M)
  5084. * @alias module:zrender/Storage
  5085. * @constructor
  5086. */
  5087. var Storage = function () { // jshint ignore:line
  5088. this._roots = [];
  5089. this._displayList = [];
  5090. this._displayListLen = 0;
  5091. };
  5092. Storage.prototype = {
  5093. constructor: Storage,
  5094. /**
  5095. * @param {Function} cb
  5096. *
  5097. */
  5098. traverse: function (cb, context) {
  5099. for (var i = 0; i < this._roots.length; i++) {
  5100. this._roots[i].traverse(cb, context);
  5101. }
  5102. },
  5103. /**
  5104. * 返回所有图形的绘制队列
  5105. * @param {boolean} [update=false] 是否在返回前更新该数组
  5106. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5107. *
  5108. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5109. * @return {Array.<module:zrender/graphic/Displayable>}
  5110. */
  5111. getDisplayList: function (update, includeIgnore) {
  5112. includeIgnore = includeIgnore || false;
  5113. if (update) {
  5114. this.updateDisplayList(includeIgnore);
  5115. }
  5116. return this._displayList;
  5117. },
  5118. /**
  5119. * 更新图形的绘制队列。
  5120. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5121. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5122. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5123. */
  5124. updateDisplayList: function (includeIgnore) {
  5125. this._displayListLen = 0;
  5126. var roots = this._roots;
  5127. var displayList = this._displayList;
  5128. for (var i = 0, len = roots.length; i < len; i++) {
  5129. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5130. }
  5131. displayList.length = this._displayListLen;
  5132. // for (var i = 0, len = displayList.length; i < len; i++) {
  5133. // displayList[i].__renderidx = i;
  5134. // }
  5135. // displayList.sort(shapeCompareFunc);
  5136. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5137. },
  5138. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5139. if (el.ignore && !includeIgnore) {
  5140. return;
  5141. }
  5142. el.beforeUpdate();
  5143. if (el.__dirty) {
  5144. el.update();
  5145. }
  5146. el.afterUpdate();
  5147. var userSetClipPath = el.clipPath;
  5148. if (userSetClipPath) {
  5149. // FIXME 效率影响
  5150. if (clipPaths) {
  5151. clipPaths = clipPaths.slice();
  5152. }
  5153. else {
  5154. clipPaths = [];
  5155. }
  5156. var currentClipPath = userSetClipPath;
  5157. var parentClipPath = el;
  5158. // Recursively add clip path
  5159. while (currentClipPath) {
  5160. // clipPath 的变换是基于使用这个 clipPath 的元素
  5161. currentClipPath.parent = parentClipPath;
  5162. currentClipPath.updateTransform();
  5163. clipPaths.push(currentClipPath);
  5164. parentClipPath = currentClipPath;
  5165. currentClipPath = currentClipPath.clipPath;
  5166. }
  5167. }
  5168. if (el.isGroup) {
  5169. var children = el._children;
  5170. for (var i = 0; i < children.length; i++) {
  5171. var child = children[i];
  5172. // Force to mark as dirty if group is dirty
  5173. // FIXME __dirtyPath ?
  5174. if (el.__dirty) {
  5175. child.__dirty = true;
  5176. }
  5177. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5178. }
  5179. // Mark group clean here
  5180. el.__dirty = false;
  5181. }
  5182. else {
  5183. el.__clipPaths = clipPaths;
  5184. this._displayList[this._displayListLen++] = el;
  5185. }
  5186. },
  5187. /**
  5188. * 添加图形(Shape)或者组(Group)到根节点
  5189. * @param {module:zrender/Element} el
  5190. */
  5191. addRoot: function (el) {
  5192. if (el.__storage === this) {
  5193. return;
  5194. }
  5195. if (el instanceof Group) {
  5196. el.addChildrenToStorage(this);
  5197. }
  5198. this.addToStorage(el);
  5199. this._roots.push(el);
  5200. },
  5201. /**
  5202. * 删除指定的图形(Shape)或者组(Group)
  5203. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5204. */
  5205. delRoot: function (el) {
  5206. if (el == null) {
  5207. // 不指定el清空
  5208. for (var i = 0; i < this._roots.length; i++) {
  5209. var root = this._roots[i];
  5210. if (root instanceof Group) {
  5211. root.delChildrenFromStorage(this);
  5212. }
  5213. }
  5214. this._roots = [];
  5215. this._displayList = [];
  5216. this._displayListLen = 0;
  5217. return;
  5218. }
  5219. if (el instanceof Array) {
  5220. for (var i = 0, l = el.length; i < l; i++) {
  5221. this.delRoot(el[i]);
  5222. }
  5223. return;
  5224. }
  5225. var idx = indexOf(this._roots, el);
  5226. if (idx >= 0) {
  5227. this.delFromStorage(el);
  5228. this._roots.splice(idx, 1);
  5229. if (el instanceof Group) {
  5230. el.delChildrenFromStorage(this);
  5231. }
  5232. }
  5233. },
  5234. addToStorage: function (el) {
  5235. el.__storage = this;
  5236. el.dirty(false);
  5237. return this;
  5238. },
  5239. delFromStorage: function (el) {
  5240. if (el) {
  5241. el.__storage = null;
  5242. }
  5243. return this;
  5244. },
  5245. /**
  5246. * 清空并且释放Storage
  5247. */
  5248. dispose: function () {
  5249. this._renderList =
  5250. this._roots = null;
  5251. },
  5252. displayableSortFunc: shapeCompareFunc
  5253. };
  5254. var STYLE_COMMON_PROPS = [
  5255. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  5256. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  5257. ];
  5258. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  5259. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5260. var Style = function (opts, host) {
  5261. this.extendFrom(opts, false);
  5262. this.host = host;
  5263. };
  5264. function createLinearGradient(ctx, obj, rect) {
  5265. var x = obj.x == null ? 0 : obj.x;
  5266. var x2 = obj.x2 == null ? 1 : obj.x2;
  5267. var y = obj.y == null ? 0 : obj.y;
  5268. var y2 = obj.y2 == null ? 0 : obj.y2;
  5269. if (!obj.global) {
  5270. x = x * rect.width + rect.x;
  5271. x2 = x2 * rect.width + rect.x;
  5272. y = y * rect.height + rect.y;
  5273. y2 = y2 * rect.height + rect.y;
  5274. }
  5275. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  5276. return canvasGradient;
  5277. }
  5278. function createRadialGradient(ctx, obj, rect) {
  5279. var width = rect.width;
  5280. var height = rect.height;
  5281. var min = Math.min(width, height);
  5282. var x = obj.x == null ? 0.5 : obj.x;
  5283. var y = obj.y == null ? 0.5 : obj.y;
  5284. var r = obj.r == null ? 0.5 : obj.r;
  5285. if (!obj.global) {
  5286. x = x * width + rect.x;
  5287. y = y * height + rect.y;
  5288. r = r * min;
  5289. }
  5290. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  5291. return canvasGradient;
  5292. }
  5293. Style.prototype = {
  5294. constructor: Style,
  5295. /**
  5296. * @type {module:zrender/graphic/Displayable}
  5297. */
  5298. host: null,
  5299. /**
  5300. * @type {string}
  5301. */
  5302. fill: '#000',
  5303. /**
  5304. * @type {string}
  5305. */
  5306. stroke: null,
  5307. /**
  5308. * @type {number}
  5309. */
  5310. opacity: 1,
  5311. /**
  5312. * @type {Array.<number>}
  5313. */
  5314. lineDash: null,
  5315. /**
  5316. * @type {number}
  5317. */
  5318. lineDashOffset: 0,
  5319. /**
  5320. * @type {number}
  5321. */
  5322. shadowBlur: 0,
  5323. /**
  5324. * @type {number}
  5325. */
  5326. shadowOffsetX: 0,
  5327. /**
  5328. * @type {number}
  5329. */
  5330. shadowOffsetY: 0,
  5331. /**
  5332. * @type {number}
  5333. */
  5334. lineWidth: 1,
  5335. /**
  5336. * If stroke ignore scale
  5337. * @type {Boolean}
  5338. */
  5339. strokeNoScale: false,
  5340. // Bounding rect text configuration
  5341. // Not affected by element transform
  5342. /**
  5343. * @type {string}
  5344. */
  5345. text: null,
  5346. /**
  5347. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  5348. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  5349. * So do not visit it directly in upper application (like echarts),
  5350. * but use `contain/text#makeFont` instead.
  5351. * @type {string}
  5352. */
  5353. font: null,
  5354. /**
  5355. * The same as font. Use font please.
  5356. * @deprecated
  5357. * @type {string}
  5358. */
  5359. textFont: null,
  5360. /**
  5361. * It helps merging respectively, rather than parsing an entire font string.
  5362. * @type {string}
  5363. */
  5364. fontStyle: null,
  5365. /**
  5366. * It helps merging respectively, rather than parsing an entire font string.
  5367. * @type {string}
  5368. */
  5369. fontWeight: null,
  5370. /**
  5371. * It helps merging respectively, rather than parsing an entire font string.
  5372. * Should be 12 but not '12px'.
  5373. * @type {number}
  5374. */
  5375. fontSize: null,
  5376. /**
  5377. * It helps merging respectively, rather than parsing an entire font string.
  5378. * @type {string}
  5379. */
  5380. fontFamily: null,
  5381. /**
  5382. * Reserved for special functinality, like 'hr'.
  5383. * @type {string}
  5384. */
  5385. textTag: null,
  5386. /**
  5387. * @type {string}
  5388. */
  5389. textFill: '#000',
  5390. /**
  5391. * @type {string}
  5392. */
  5393. textStroke: null,
  5394. /**
  5395. * @type {number}
  5396. */
  5397. textWidth: null,
  5398. /**
  5399. * Only for textBackground.
  5400. * @type {number}
  5401. */
  5402. textHeight: null,
  5403. /**
  5404. * textStroke may be set as some color as a default
  5405. * value in upper applicaion, where the default value
  5406. * of textStrokeWidth should be 0 to make sure that
  5407. * user can choose to do not use text stroke.
  5408. * @type {number}
  5409. */
  5410. textStrokeWidth: 0,
  5411. /**
  5412. * @type {number}
  5413. */
  5414. textLineHeight: null,
  5415. /**
  5416. * 'inside', 'left', 'right', 'top', 'bottom'
  5417. * [x, y]
  5418. * Based on x, y of rect.
  5419. * @type {string|Array.<number>}
  5420. * @default 'inside'
  5421. */
  5422. textPosition: 'inside',
  5423. /**
  5424. * If not specified, use the boundingRect of a `displayable`.
  5425. * @type {Object}
  5426. */
  5427. textRect: null,
  5428. /**
  5429. * [x, y]
  5430. * @type {Array.<number>}
  5431. */
  5432. textOffset: null,
  5433. /**
  5434. * @type {string}
  5435. */
  5436. textAlign: null,
  5437. /**
  5438. * @type {string}
  5439. */
  5440. textVerticalAlign: null,
  5441. /**
  5442. * @type {number}
  5443. */
  5444. textDistance: 5,
  5445. /**
  5446. * @type {string}
  5447. */
  5448. textShadowColor: 'transparent',
  5449. /**
  5450. * @type {number}
  5451. */
  5452. textShadowBlur: 0,
  5453. /**
  5454. * @type {number}
  5455. */
  5456. textShadowOffsetX: 0,
  5457. /**
  5458. * @type {number}
  5459. */
  5460. textShadowOffsetY: 0,
  5461. /**
  5462. * @type {string}
  5463. */
  5464. textBoxShadowColor: 'transparent',
  5465. /**
  5466. * @type {number}
  5467. */
  5468. textBoxShadowBlur: 0,
  5469. /**
  5470. * @type {number}
  5471. */
  5472. textBoxShadowOffsetX: 0,
  5473. /**
  5474. * @type {number}
  5475. */
  5476. textBoxShadowOffsetY: 0,
  5477. /**
  5478. * Whether transform text.
  5479. * Only useful in Path and Image element
  5480. * @type {boolean}
  5481. */
  5482. transformText: false,
  5483. /**
  5484. * Text rotate around position of Path or Image
  5485. * Only useful in Path and Image element and transformText is false.
  5486. */
  5487. textRotation: 0,
  5488. /**
  5489. * Text origin of text rotation, like [10, 40].
  5490. * Based on x, y of rect.
  5491. * Useful in label rotation of circular symbol.
  5492. * By default, this origin is textPosition.
  5493. * Can be 'center'.
  5494. * @type {string|Array.<number>}
  5495. */
  5496. textOrigin: null,
  5497. /**
  5498. * @type {string}
  5499. */
  5500. textBackgroundColor: null,
  5501. /**
  5502. * @type {string}
  5503. */
  5504. textBorderColor: null,
  5505. /**
  5506. * @type {number}
  5507. */
  5508. textBorderWidth: 0,
  5509. /**
  5510. * @type {number}
  5511. */
  5512. textBorderRadius: 0,
  5513. /**
  5514. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  5515. * @type {number|Array.<number>}
  5516. */
  5517. textPadding: null,
  5518. /**
  5519. * Text styles for rich text.
  5520. * @type {Object}
  5521. */
  5522. rich: null,
  5523. /**
  5524. * {outerWidth, outerHeight, ellipsis, placeholder}
  5525. * @type {Object}
  5526. */
  5527. truncate: null,
  5528. /**
  5529. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  5530. * @type {string}
  5531. */
  5532. blend: null,
  5533. /**
  5534. * @param {CanvasRenderingContext2D} ctx
  5535. */
  5536. bind: function (ctx, el, prevEl) {
  5537. var style = this;
  5538. var prevStyle = prevEl && prevEl.style;
  5539. var firstDraw = !prevStyle;
  5540. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  5541. var prop = STYLE_COMMON_PROPS[i];
  5542. var styleName = prop[0];
  5543. if (firstDraw || style[styleName] !== prevStyle[styleName]) {
  5544. // FIXME Invalid property value will cause style leak from previous element.
  5545. ctx[styleName] = style[styleName] || prop[1];
  5546. }
  5547. }
  5548. if ((firstDraw || style.fill !== prevStyle.fill)) {
  5549. ctx.fillStyle = style.fill;
  5550. }
  5551. if ((firstDraw || style.stroke !== prevStyle.stroke)) {
  5552. ctx.strokeStyle = style.stroke;
  5553. }
  5554. if ((firstDraw || style.opacity !== prevStyle.opacity)) {
  5555. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  5556. }
  5557. if ((firstDraw || style.blend !== prevStyle.blend)) {
  5558. ctx.globalCompositeOperation = style.blend || 'source-over';
  5559. }
  5560. if (this.hasStroke()) {
  5561. var lineWidth = style.lineWidth;
  5562. ctx.lineWidth = lineWidth / (
  5563. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  5564. );
  5565. }
  5566. },
  5567. hasFill: function () {
  5568. var fill = this.fill;
  5569. return fill != null && fill !== 'none';
  5570. },
  5571. hasStroke: function () {
  5572. var stroke = this.stroke;
  5573. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  5574. },
  5575. /**
  5576. * Extend from other style
  5577. * @param {zrender/graphic/Style} otherStyle
  5578. * @param {boolean} overwrite true: overwrirte any way.
  5579. * false: overwrite only when !target.hasOwnProperty
  5580. * others: overwrite when property is not null/undefined.
  5581. */
  5582. extendFrom: function (otherStyle, overwrite) {
  5583. if (otherStyle) {
  5584. for (var name in otherStyle) {
  5585. if (otherStyle.hasOwnProperty(name)
  5586. && (overwrite === true
  5587. || (
  5588. overwrite === false
  5589. ? !this.hasOwnProperty(name)
  5590. : otherStyle[name] != null
  5591. )
  5592. )
  5593. ) {
  5594. this[name] = otherStyle[name];
  5595. }
  5596. }
  5597. }
  5598. },
  5599. /**
  5600. * Batch setting style with a given object
  5601. * @param {Object|string} obj
  5602. * @param {*} [obj]
  5603. */
  5604. set: function (obj, value) {
  5605. if (typeof obj === 'string') {
  5606. this[obj] = value;
  5607. }
  5608. else {
  5609. this.extendFrom(obj, true);
  5610. }
  5611. },
  5612. /**
  5613. * Clone
  5614. * @return {zrender/graphic/Style} [description]
  5615. */
  5616. clone: function () {
  5617. var newStyle = new this.constructor();
  5618. newStyle.extendFrom(this, true);
  5619. return newStyle;
  5620. },
  5621. getGradient: function (ctx, obj, rect) {
  5622. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  5623. var canvasGradient = method(ctx, obj, rect);
  5624. var colorStops = obj.colorStops;
  5625. for (var i = 0; i < colorStops.length; i++) {
  5626. canvasGradient.addColorStop(
  5627. colorStops[i].offset, colorStops[i].color
  5628. );
  5629. }
  5630. return canvasGradient;
  5631. }
  5632. };
  5633. var styleProto = Style.prototype;
  5634. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  5635. var prop = STYLE_COMMON_PROPS[i];
  5636. if (!(prop[0] in styleProto)) {
  5637. styleProto[prop[0]] = prop[1];
  5638. }
  5639. }
  5640. // Provide for others
  5641. Style.getGradient = styleProto.getGradient;
  5642. var Pattern = function (image, repeat) {
  5643. // Should do nothing more in this constructor. Because gradient can be
  5644. // declard by `color: {image: ...}`, where this constructor will not be called.
  5645. this.image = image;
  5646. this.repeat = repeat;
  5647. // Can be cloned
  5648. this.type = 'pattern';
  5649. };
  5650. Pattern.prototype.getCanvasPattern = function (ctx) {
  5651. return ctx.createPattern(this.image, this.repeat || 'repeat');
  5652. };
  5653. /**
  5654. * @module zrender/Layer
  5655. * @author pissang(https://www.github.com/pissang)
  5656. */
  5657. function returnFalse() {
  5658. return false;
  5659. }
  5660. /**
  5661. * 创建dom
  5662. *
  5663. * @inner
  5664. * @param {string} id dom id 待用
  5665. * @param {Painter} painter painter instance
  5666. * @param {number} number
  5667. */
  5668. function createDom(id, painter, dpr) {
  5669. var newDom = createCanvas();
  5670. var width = painter.getWidth();
  5671. var height = painter.getHeight();
  5672. var newDomStyle = newDom.style;
  5673. // 没append呢,请原谅我这样写,清晰~
  5674. newDomStyle.position = 'absolute';
  5675. newDomStyle.left = 0;
  5676. newDomStyle.top = 0;
  5677. newDomStyle.width = width + 'px';
  5678. newDomStyle.height = height + 'px';
  5679. newDom.width = width * dpr;
  5680. newDom.height = height * dpr;
  5681. // id不作为索引用,避免可能造成的重名,定义为私有属性
  5682. newDom.setAttribute('data-zr-dom-id', id);
  5683. return newDom;
  5684. }
  5685. /**
  5686. * @alias module:zrender/Layer
  5687. * @constructor
  5688. * @extends module:zrender/mixin/Transformable
  5689. * @param {string} id
  5690. * @param {module:zrender/Painter} painter
  5691. * @param {number} [dpr]
  5692. */
  5693. var Layer = function(id, painter, dpr) {
  5694. var dom;
  5695. dpr = dpr || devicePixelRatio;
  5696. if (typeof id === 'string') {
  5697. dom = createDom(id, painter, dpr);
  5698. }
  5699. // Not using isDom because in node it will return false
  5700. else if (isObject(id)) {
  5701. dom = id;
  5702. id = dom.id;
  5703. }
  5704. this.id = id;
  5705. this.dom = dom;
  5706. var domStyle = dom.style;
  5707. if (domStyle) { // Not in node
  5708. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  5709. domStyle['-webkit-user-select'] = 'none';
  5710. domStyle['user-select'] = 'none';
  5711. domStyle['-webkit-touch-callout'] = 'none';
  5712. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  5713. domStyle['padding'] = 0;
  5714. domStyle['margin'] = 0;
  5715. domStyle['border-width'] = 0;
  5716. }
  5717. this.domBack = null;
  5718. this.ctxBack = null;
  5719. this.painter = painter;
  5720. this.config = null;
  5721. // Configs
  5722. /**
  5723. * 每次清空画布的颜色
  5724. * @type {string}
  5725. * @default 0
  5726. */
  5727. this.clearColor = 0;
  5728. /**
  5729. * 是否开启动态模糊
  5730. * @type {boolean}
  5731. * @default false
  5732. */
  5733. this.motionBlur = false;
  5734. /**
  5735. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  5736. * @type {number}
  5737. * @default 0.7
  5738. */
  5739. this.lastFrameAlpha = 0.7;
  5740. /**
  5741. * Layer dpr
  5742. * @type {number}
  5743. */
  5744. this.dpr = dpr;
  5745. };
  5746. Layer.prototype = {
  5747. constructor: Layer,
  5748. elCount: 0,
  5749. __dirty: true,
  5750. initContext: function () {
  5751. this.ctx = this.dom.getContext('2d');
  5752. this.ctx.__currentValues = {};
  5753. this.ctx.dpr = this.dpr;
  5754. },
  5755. createBackBuffer: function () {
  5756. var dpr = this.dpr;
  5757. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  5758. this.ctxBack = this.domBack.getContext('2d');
  5759. this.ctxBack.__currentValues = {};
  5760. if (dpr != 1) {
  5761. this.ctxBack.scale(dpr, dpr);
  5762. }
  5763. },
  5764. /**
  5765. * @param {number} width
  5766. * @param {number} height
  5767. */
  5768. resize: function (width, height) {
  5769. var dpr = this.dpr;
  5770. var dom = this.dom;
  5771. var domStyle = dom.style;
  5772. var domBack = this.domBack;
  5773. domStyle.width = width + 'px';
  5774. domStyle.height = height + 'px';
  5775. dom.width = width * dpr;
  5776. dom.height = height * dpr;
  5777. if (domBack) {
  5778. domBack.width = width * dpr;
  5779. domBack.height = height * dpr;
  5780. if (dpr != 1) {
  5781. this.ctxBack.scale(dpr, dpr);
  5782. }
  5783. }
  5784. },
  5785. /**
  5786. * 清空该层画布
  5787. * @param {boolean} clearAll Clear all with out motion blur
  5788. */
  5789. clear: function (clearAll) {
  5790. var dom = this.dom;
  5791. var ctx = this.ctx;
  5792. var width = dom.width;
  5793. var height = dom.height;
  5794. var clearColor = this.clearColor;
  5795. var haveMotionBLur = this.motionBlur && !clearAll;
  5796. var lastFrameAlpha = this.lastFrameAlpha;
  5797. var dpr = this.dpr;
  5798. if (haveMotionBLur) {
  5799. if (!this.domBack) {
  5800. this.createBackBuffer();
  5801. }
  5802. this.ctxBack.globalCompositeOperation = 'copy';
  5803. this.ctxBack.drawImage(
  5804. dom, 0, 0,
  5805. width / dpr,
  5806. height / dpr
  5807. );
  5808. }
  5809. ctx.clearRect(0, 0, width, height);
  5810. if (clearColor) {
  5811. var clearColorGradientOrPattern;
  5812. // Gradient
  5813. if (clearColor.colorStops) {
  5814. // Cache canvas gradient
  5815. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  5816. x: 0,
  5817. y: 0,
  5818. width: width,
  5819. height: height
  5820. });
  5821. clearColor.__canvasGradient = clearColorGradientOrPattern;
  5822. }
  5823. // Pattern
  5824. else if (clearColor.image) {
  5825. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  5826. }
  5827. ctx.save();
  5828. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  5829. ctx.fillRect(0, 0, width, height);
  5830. ctx.restore();
  5831. }
  5832. if (haveMotionBLur) {
  5833. var domBack = this.domBack;
  5834. ctx.save();
  5835. ctx.globalAlpha = lastFrameAlpha;
  5836. ctx.drawImage(domBack, 0, 0, width, height);
  5837. ctx.restore();
  5838. }
  5839. }
  5840. };
  5841. var requestAnimationFrame = (
  5842. typeof window !== 'undefined'
  5843. && (
  5844. (window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  5845. // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  5846. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  5847. || window.mozRequestAnimationFrame
  5848. || window.webkitRequestAnimationFrame
  5849. )
  5850. ) || function (func) {
  5851. setTimeout(func, 16);
  5852. };
  5853. var globalImageCache = new LRU(50);
  5854. /**
  5855. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  5856. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  5857. */
  5858. function findExistImage(newImageOrSrc) {
  5859. if (typeof newImageOrSrc === 'string') {
  5860. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  5861. return cachedImgObj && cachedImgObj.image;
  5862. }
  5863. else {
  5864. return newImageOrSrc;
  5865. }
  5866. }
  5867. /**
  5868. * Caution: User should cache loaded images, but not just count on LRU.
  5869. * Consider if required images more than LRU size, will dead loop occur?
  5870. *
  5871. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  5872. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  5873. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  5874. * @param {Function} [cb] params: (image, cbPayload)
  5875. * @param {Object} [cbPayload] Payload on cb calling.
  5876. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  5877. */
  5878. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  5879. if (!newImageOrSrc) {
  5880. return image;
  5881. }
  5882. else if (typeof newImageOrSrc === 'string') {
  5883. // Image should not be loaded repeatly.
  5884. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  5885. return image;
  5886. }
  5887. // Only when there is no existent image or existent image src
  5888. // is different, this method is responsible for load.
  5889. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  5890. var pendingWrap = {hostEl: hostEl, cb: cb, cbPayload: cbPayload};
  5891. if (cachedImgObj) {
  5892. image = cachedImgObj.image;
  5893. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  5894. }
  5895. else {
  5896. !image && (image = new Image());
  5897. image.onload = imageOnLoad;
  5898. globalImageCache.put(
  5899. newImageOrSrc,
  5900. image.__cachedImgObj = {
  5901. image: image,
  5902. pending: [pendingWrap]
  5903. }
  5904. );
  5905. image.src = image.__zrImageSrc = newImageOrSrc;
  5906. }
  5907. return image;
  5908. }
  5909. // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  5910. else {
  5911. return newImageOrSrc;
  5912. }
  5913. }
  5914. function imageOnLoad() {
  5915. var cachedImgObj = this.__cachedImgObj;
  5916. this.onload = this.__cachedImgObj = null;
  5917. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  5918. var pendingWrap = cachedImgObj.pending[i];
  5919. var cb = pendingWrap.cb;
  5920. cb && cb(this, pendingWrap.cbPayload);
  5921. pendingWrap.hostEl.dirty();
  5922. }
  5923. cachedImgObj.pending.length = 0;
  5924. }
  5925. function isImageReady(image) {
  5926. return image && image.width && image.height;
  5927. }
  5928. var textWidthCache = {};
  5929. var textWidthCacheCounter = 0;
  5930. var TEXT_CACHE_MAX = 5000;
  5931. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  5932. var DEFAULT_FONT = '12px sans-serif';
  5933. // Avoid assign to an exported variable, for transforming to cjs.
  5934. var methods$1 = {};
  5935. function $override$1(name, fn) {
  5936. methods$1[name] = fn;
  5937. }
  5938. /**
  5939. * @public
  5940. * @param {string} text
  5941. * @param {string} font
  5942. * @return {number} width
  5943. */
  5944. function getWidth(text, font) {
  5945. font = font || DEFAULT_FONT;
  5946. var key = text + ':' + font;
  5947. if (textWidthCache[key]) {
  5948. return textWidthCache[key];
  5949. }
  5950. var textLines = (text + '').split('\n');
  5951. var width = 0;
  5952. for (var i = 0, l = textLines.length; i < l; i++) {
  5953. // textContain.measureText may be overrided in SVG or VML
  5954. width = Math.max(measureText(textLines[i], font).width, width);
  5955. }
  5956. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  5957. textWidthCacheCounter = 0;
  5958. textWidthCache = {};
  5959. }
  5960. textWidthCacheCounter++;
  5961. textWidthCache[key] = width;
  5962. return width;
  5963. }
  5964. /**
  5965. * @public
  5966. * @param {string} text
  5967. * @param {string} font
  5968. * @param {string} [textAlign='left']
  5969. * @param {string} [textVerticalAlign='top']
  5970. * @param {Array.<number>} [textPadding]
  5971. * @param {Object} [rich]
  5972. * @param {Object} [truncate]
  5973. * @return {Object} {x, y, width, height, lineHeight}
  5974. */
  5975. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  5976. return rich
  5977. ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate)
  5978. : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate);
  5979. }
  5980. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, truncate) {
  5981. var contentBlock = parsePlainText(text, font, textPadding, truncate);
  5982. var outerWidth = getWidth(text, font);
  5983. if (textPadding) {
  5984. outerWidth += textPadding[1] + textPadding[3];
  5985. }
  5986. var outerHeight = contentBlock.outerHeight;
  5987. var x = adjustTextX(0, outerWidth, textAlign);
  5988. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  5989. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  5990. rect.lineHeight = contentBlock.lineHeight;
  5991. return rect;
  5992. }
  5993. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate) {
  5994. var contentBlock = parseRichText(text, {
  5995. rich: rich,
  5996. truncate: truncate,
  5997. font: font,
  5998. textAlign: textAlign,
  5999. textPadding: textPadding
  6000. });
  6001. var outerWidth = contentBlock.outerWidth;
  6002. var outerHeight = contentBlock.outerHeight;
  6003. var x = adjustTextX(0, outerWidth, textAlign);
  6004. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6005. return new BoundingRect(x, y, outerWidth, outerHeight);
  6006. }
  6007. /**
  6008. * @public
  6009. * @param {number} x
  6010. * @param {number} width
  6011. * @param {string} [textAlign='left']
  6012. * @return {number} Adjusted x.
  6013. */
  6014. function adjustTextX(x, width, textAlign) {
  6015. // FIXME Right to left language
  6016. if (textAlign === 'right') {
  6017. x -= width;
  6018. }
  6019. else if (textAlign === 'center') {
  6020. x -= width / 2;
  6021. }
  6022. return x;
  6023. }
  6024. /**
  6025. * @public
  6026. * @param {number} y
  6027. * @param {number} height
  6028. * @param {string} [textVerticalAlign='top']
  6029. * @return {number} Adjusted y.
  6030. */
  6031. function adjustTextY(y, height, textVerticalAlign) {
  6032. if (textVerticalAlign === 'middle') {
  6033. y -= height / 2;
  6034. }
  6035. else if (textVerticalAlign === 'bottom') {
  6036. y -= height;
  6037. }
  6038. return y;
  6039. }
  6040. /**
  6041. * @public
  6042. * @param {stirng} textPosition
  6043. * @param {Object} rect {x, y, width, height}
  6044. * @param {number} distance
  6045. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6046. */
  6047. function adjustTextPositionOnRect(textPosition, rect, distance) {
  6048. var x = rect.x;
  6049. var y = rect.y;
  6050. var height = rect.height;
  6051. var width = rect.width;
  6052. var halfHeight = height / 2;
  6053. var textAlign = 'left';
  6054. var textVerticalAlign = 'top';
  6055. switch (textPosition) {
  6056. case 'left':
  6057. x -= distance;
  6058. y += halfHeight;
  6059. textAlign = 'right';
  6060. textVerticalAlign = 'middle';
  6061. break;
  6062. case 'right':
  6063. x += distance + width;
  6064. y += halfHeight;
  6065. textVerticalAlign = 'middle';
  6066. break;
  6067. case 'top':
  6068. x += width / 2;
  6069. y -= distance;
  6070. textAlign = 'center';
  6071. textVerticalAlign = 'bottom';
  6072. break;
  6073. case 'bottom':
  6074. x += width / 2;
  6075. y += height + distance;
  6076. textAlign = 'center';
  6077. break;
  6078. case 'inside':
  6079. x += width / 2;
  6080. y += halfHeight;
  6081. textAlign = 'center';
  6082. textVerticalAlign = 'middle';
  6083. break;
  6084. case 'insideLeft':
  6085. x += distance;
  6086. y += halfHeight;
  6087. textVerticalAlign = 'middle';
  6088. break;
  6089. case 'insideRight':
  6090. x += width - distance;
  6091. y += halfHeight;
  6092. textAlign = 'right';
  6093. textVerticalAlign = 'middle';
  6094. break;
  6095. case 'insideTop':
  6096. x += width / 2;
  6097. y += distance;
  6098. textAlign = 'center';
  6099. break;
  6100. case 'insideBottom':
  6101. x += width / 2;
  6102. y += height - distance;
  6103. textAlign = 'center';
  6104. textVerticalAlign = 'bottom';
  6105. break;
  6106. case 'insideTopLeft':
  6107. x += distance;
  6108. y += distance;
  6109. break;
  6110. case 'insideTopRight':
  6111. x += width - distance;
  6112. y += distance;
  6113. textAlign = 'right';
  6114. break;
  6115. case 'insideBottomLeft':
  6116. x += distance;
  6117. y += height - distance;
  6118. textVerticalAlign = 'bottom';
  6119. break;
  6120. case 'insideBottomRight':
  6121. x += width - distance;
  6122. y += height - distance;
  6123. textAlign = 'right';
  6124. textVerticalAlign = 'bottom';
  6125. break;
  6126. }
  6127. return {
  6128. x: x,
  6129. y: y,
  6130. textAlign: textAlign,
  6131. textVerticalAlign: textVerticalAlign
  6132. };
  6133. }
  6134. /**
  6135. * Show ellipsis if overflow.
  6136. *
  6137. * @public
  6138. * @param {string} text
  6139. * @param {string} containerWidth
  6140. * @param {string} font
  6141. * @param {number} [ellipsis='...']
  6142. * @param {Object} [options]
  6143. * @param {number} [options.maxIterations=3]
  6144. * @param {number} [options.minChar=0] If truncate result are less
  6145. * then minChar, ellipsis will not show, which is
  6146. * better for user hint in some cases.
  6147. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6148. * @return {string}
  6149. */
  6150. function truncateText(text, containerWidth, font, ellipsis, options) {
  6151. if (!containerWidth) {
  6152. return '';
  6153. }
  6154. var textLines = (text + '').split('\n');
  6155. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  6156. // FIXME
  6157. // It is not appropriate that every line has '...' when truncate multiple lines.
  6158. for (var i = 0, len = textLines.length; i < len; i++) {
  6159. textLines[i] = truncateSingleLine(textLines[i], options);
  6160. }
  6161. return textLines.join('\n');
  6162. }
  6163. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6164. options = extend({}, options);
  6165. options.font = font;
  6166. var ellipsis = retrieve2(ellipsis, '...');
  6167. options.maxIterations = retrieve2(options.maxIterations, 2);
  6168. var minChar = options.minChar = retrieve2(options.minChar, 0);
  6169. // FIXME
  6170. // Other languages?
  6171. options.cnCharWidth = getWidth('国', font);
  6172. // FIXME
  6173. // Consider proportional font?
  6174. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6175. options.placeholder = retrieve2(options.placeholder, '');
  6176. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6177. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6178. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6179. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6180. contentWidth -= ascCharWidth;
  6181. }
  6182. var ellipsisWidth = getWidth(ellipsis);
  6183. if (ellipsisWidth > contentWidth) {
  6184. ellipsis = '';
  6185. ellipsisWidth = 0;
  6186. }
  6187. contentWidth = containerWidth - ellipsisWidth;
  6188. options.ellipsis = ellipsis;
  6189. options.ellipsisWidth = ellipsisWidth;
  6190. options.contentWidth = contentWidth;
  6191. options.containerWidth = containerWidth;
  6192. return options;
  6193. }
  6194. function truncateSingleLine(textLine, options) {
  6195. var containerWidth = options.containerWidth;
  6196. var font = options.font;
  6197. var contentWidth = options.contentWidth;
  6198. if (!containerWidth) {
  6199. return '';
  6200. }
  6201. var lineWidth = getWidth(textLine, font);
  6202. if (lineWidth <= containerWidth) {
  6203. return textLine;
  6204. }
  6205. for (var j = 0;; j++) {
  6206. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6207. textLine += options.ellipsis;
  6208. break;
  6209. }
  6210. var subLength = j === 0
  6211. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  6212. : lineWidth > 0
  6213. ? Math.floor(textLine.length * contentWidth / lineWidth)
  6214. : 0;
  6215. textLine = textLine.substr(0, subLength);
  6216. lineWidth = getWidth(textLine, font);
  6217. }
  6218. if (textLine === '') {
  6219. textLine = options.placeholder;
  6220. }
  6221. return textLine;
  6222. }
  6223. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6224. var width = 0;
  6225. var i = 0;
  6226. for (var len = text.length; i < len && width < contentWidth; i++) {
  6227. var charCode = text.charCodeAt(i);
  6228. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  6229. }
  6230. return i;
  6231. }
  6232. /**
  6233. * @public
  6234. * @param {string} font
  6235. * @return {number} line height
  6236. */
  6237. function getLineHeight(font) {
  6238. // FIXME A rough approach.
  6239. return getWidth('国', font);
  6240. }
  6241. /**
  6242. * @public
  6243. * @param {string} text
  6244. * @param {string} font
  6245. * @return {Object} width
  6246. */
  6247. function measureText(text, font) {
  6248. return methods$1.measureText(text, font);
  6249. }
  6250. // Avoid assign to an exported variable, for transforming to cjs.
  6251. methods$1.measureText = function (text, font) {
  6252. var ctx = getContext();
  6253. ctx.font = font || DEFAULT_FONT;
  6254. return ctx.measureText(text);
  6255. };
  6256. /**
  6257. * @public
  6258. * @param {string} text
  6259. * @param {string} font
  6260. * @param {Object} [truncate]
  6261. * @return {Object} block: {lineHeight, lines, height, outerHeight}
  6262. * Notice: for performance, do not calculate outerWidth util needed.
  6263. */
  6264. function parsePlainText(text, font, padding, truncate) {
  6265. text != null && (text += '');
  6266. var lineHeight = getLineHeight(font);
  6267. var lines = text ? text.split('\n') : [];
  6268. var height = lines.length * lineHeight;
  6269. var outerHeight = height;
  6270. if (padding) {
  6271. outerHeight += padding[0] + padding[2];
  6272. }
  6273. if (text && truncate) {
  6274. var truncOuterHeight = truncate.outerHeight;
  6275. var truncOuterWidth = truncate.outerWidth;
  6276. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  6277. text = '';
  6278. lines = [];
  6279. }
  6280. else if (truncOuterWidth != null) {
  6281. var options = prepareTruncateOptions(
  6282. truncOuterWidth - (padding ? padding[1] + padding[3] : 0),
  6283. font,
  6284. truncate.ellipsis,
  6285. {minChar: truncate.minChar, placeholder: truncate.placeholder}
  6286. );
  6287. // FIXME
  6288. // It is not appropriate that every line has '...' when truncate multiple lines.
  6289. for (var i = 0, len = lines.length; i < len; i++) {
  6290. lines[i] = truncateSingleLine(lines[i], options);
  6291. }
  6292. }
  6293. }
  6294. return {
  6295. lines: lines,
  6296. height: height,
  6297. outerHeight: outerHeight,
  6298. lineHeight: lineHeight
  6299. };
  6300. }
  6301. /**
  6302. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  6303. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  6304. *
  6305. * @public
  6306. * @param {string} text
  6307. * @param {Object} style
  6308. * @return {Object} block
  6309. * {
  6310. * width,
  6311. * height,
  6312. * lines: [{
  6313. * lineHeight,
  6314. * width,
  6315. * tokens: [[{
  6316. * styleName,
  6317. * text,
  6318. * width, // include textPadding
  6319. * height, // include textPadding
  6320. * textWidth, // pure text width
  6321. * textHeight, // pure text height
  6322. * lineHeihgt,
  6323. * font,
  6324. * textAlign,
  6325. * textVerticalAlign
  6326. * }], [...], ...]
  6327. * }, ...]
  6328. * }
  6329. * If styleName is undefined, it is plain text.
  6330. */
  6331. function parseRichText(text, style) {
  6332. var contentBlock = {lines: [], width: 0, height: 0};
  6333. text != null && (text += '');
  6334. if (!text) {
  6335. return contentBlock;
  6336. }
  6337. var lastIndex = STYLE_REG.lastIndex = 0;
  6338. var result;
  6339. while ((result = STYLE_REG.exec(text)) != null) {
  6340. var matchedIndex = result.index;
  6341. if (matchedIndex > lastIndex) {
  6342. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  6343. }
  6344. pushTokens(contentBlock, result[2], result[1]);
  6345. lastIndex = STYLE_REG.lastIndex;
  6346. }
  6347. if (lastIndex < text.length) {
  6348. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  6349. }
  6350. var lines = contentBlock.lines;
  6351. var contentHeight = 0;
  6352. var contentWidth = 0;
  6353. // For `textWidth: 100%`
  6354. var pendingList = [];
  6355. var stlPadding = style.textPadding;
  6356. var truncate = style.truncate;
  6357. var truncateWidth = truncate && truncate.outerWidth;
  6358. var truncateHeight = truncate && truncate.outerHeight;
  6359. if (stlPadding) {
  6360. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  6361. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  6362. }
  6363. // Calculate layout info of tokens.
  6364. for (var i = 0; i < lines.length; i++) {
  6365. var line = lines[i];
  6366. var lineHeight = 0;
  6367. var lineWidth = 0;
  6368. for (var j = 0; j < line.tokens.length; j++) {
  6369. var token = line.tokens[j];
  6370. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  6371. // textPadding should not inherit from style.
  6372. var textPadding = token.textPadding = tokenStyle.textPadding;
  6373. // textFont has been asigned to font by `normalizeStyle`.
  6374. var font = token.font = tokenStyle.font || style.font;
  6375. // textHeight can be used when textVerticalAlign is specified in token.
  6376. var tokenHeight = token.textHeight = retrieve2(
  6377. // textHeight should not be inherited, consider it can be specified
  6378. // as box height of the block.
  6379. tokenStyle.textHeight, getLineHeight(font)
  6380. );
  6381. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  6382. token.height = tokenHeight;
  6383. token.lineHeight = retrieve3(
  6384. tokenStyle.textLineHeight, style.textLineHeight, tokenHeight
  6385. );
  6386. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  6387. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  6388. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  6389. return {lines: [], width: 0, height: 0};
  6390. }
  6391. token.textWidth = getWidth(token.text, font);
  6392. var tokenWidth = tokenStyle.textWidth;
  6393. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto';
  6394. // Percent width, can be `100%`, can be used in drawing separate
  6395. // line when box width is needed to be auto.
  6396. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  6397. token.percentWidth = tokenWidth;
  6398. pendingList.push(token);
  6399. tokenWidth = 0;
  6400. // Do not truncate in this case, because there is no user case
  6401. // and it is too complicated.
  6402. }
  6403. else {
  6404. if (tokenWidthNotSpecified) {
  6405. tokenWidth = token.textWidth;
  6406. // FIXME: If image is not loaded and textWidth is not specified, calling
  6407. // `getBoundingRect()` will not get correct result.
  6408. var textBackgroundColor = tokenStyle.textBackgroundColor;
  6409. var bgImg = textBackgroundColor && textBackgroundColor.image;
  6410. // Use cases:
  6411. // (1) If image is not loaded, it will be loaded at render phase and call
  6412. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  6413. // image, and then the right size will be calculated here at the next tick.
  6414. // See `graphic/helper/text.js`.
  6415. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  6416. // use `imageHelper.findExistImage` to find cached image.
  6417. // `imageHelper.findExistImage` will always be called here before
  6418. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  6419. // which ensures that image will not be rendered before correct size calcualted.
  6420. if (bgImg) {
  6421. bgImg = findExistImage(bgImg);
  6422. if (isImageReady(bgImg)) {
  6423. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  6424. }
  6425. }
  6426. }
  6427. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  6428. tokenWidth += paddingW;
  6429. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  6430. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  6431. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  6432. token.text = '';
  6433. token.textWidth = tokenWidth = 0;
  6434. }
  6435. else {
  6436. token.text = truncateText(
  6437. token.text, remianTruncWidth - paddingW, font, truncate.ellipsis,
  6438. {minChar: truncate.minChar}
  6439. );
  6440. token.textWidth = getWidth(token.text, font);
  6441. tokenWidth = token.textWidth + paddingW;
  6442. }
  6443. }
  6444. }
  6445. lineWidth += (token.width = tokenWidth);
  6446. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  6447. }
  6448. line.width = lineWidth;
  6449. line.lineHeight = lineHeight;
  6450. contentHeight += lineHeight;
  6451. contentWidth = Math.max(contentWidth, lineWidth);
  6452. }
  6453. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  6454. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  6455. if (stlPadding) {
  6456. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  6457. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  6458. }
  6459. for (var i = 0; i < pendingList.length; i++) {
  6460. var token = pendingList[i];
  6461. var percentWidth = token.percentWidth;
  6462. // Should not base on outerWidth, because token can not be placed out of padding.
  6463. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  6464. }
  6465. return contentBlock;
  6466. }
  6467. function pushTokens(block, str, styleName) {
  6468. var isEmptyStr = str === '';
  6469. var strs = str.split('\n');
  6470. var lines = block.lines;
  6471. for (var i = 0; i < strs.length; i++) {
  6472. var text = strs[i];
  6473. var token = {
  6474. styleName: styleName,
  6475. text: text,
  6476. isLineHolder: !text && !isEmptyStr
  6477. };
  6478. // The first token should be appended to the last line.
  6479. if (!i) {
  6480. var tokens = (lines[lines.length - 1] || (lines[0] = {tokens: []})).tokens;
  6481. // Consider cases:
  6482. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  6483. // (which is a placeholder) should be replaced by new token.
  6484. // (2) A image backage, where token likes {a|}.
  6485. // (3) A redundant '' will affect textAlign in line.
  6486. // (4) tokens with the same tplName should not be merged, because
  6487. // they should be displayed in different box (with border and padding).
  6488. var tokensLen = tokens.length;
  6489. (tokensLen === 1 && tokens[0].isLineHolder)
  6490. ? (tokens[0] = token)
  6491. // Consider text is '', only insert when it is the "lineHolder" or
  6492. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  6493. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  6494. }
  6495. // Other tokens always start a new line.
  6496. else {
  6497. // If there is '', insert it as a placeholder.
  6498. lines.push({tokens: [token]});
  6499. }
  6500. }
  6501. }
  6502. function makeFont(style) {
  6503. // FIXME in node-canvas fontWeight is before fontStyle
  6504. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  6505. return (style.fontSize || style.fontFamily) && [
  6506. style.fontStyle,
  6507. style.fontWeight,
  6508. (style.fontSize || 12) + 'px',
  6509. // If font properties are defined, `fontFamily` should not be ignored.
  6510. style.fontFamily || 'sans-serif'
  6511. ].join(' ') || style.textFont || style.font;
  6512. }
  6513. function buildPath(ctx, shape) {
  6514. var x = shape.x;
  6515. var y = shape.y;
  6516. var width = shape.width;
  6517. var height = shape.height;
  6518. var r = shape.r;
  6519. var r1;
  6520. var r2;
  6521. var r3;
  6522. var r4;
  6523. // Convert width and height to positive for better borderRadius
  6524. if (width < 0) {
  6525. x = x + width;
  6526. width = -width;
  6527. }
  6528. if (height < 0) {
  6529. y = y + height;
  6530. height = -height;
  6531. }
  6532. if (typeof r === 'number') {
  6533. r1 = r2 = r3 = r4 = r;
  6534. }
  6535. else if (r instanceof Array) {
  6536. if (r.length === 1) {
  6537. r1 = r2 = r3 = r4 = r[0];
  6538. }
  6539. else if (r.length === 2) {
  6540. r1 = r3 = r[0];
  6541. r2 = r4 = r[1];
  6542. }
  6543. else if (r.length === 3) {
  6544. r1 = r[0];
  6545. r2 = r4 = r[1];
  6546. r3 = r[2];
  6547. }
  6548. else {
  6549. r1 = r[0];
  6550. r2 = r[1];
  6551. r3 = r[2];
  6552. r4 = r[3];
  6553. }
  6554. }
  6555. else {
  6556. r1 = r2 = r3 = r4 = 0;
  6557. }
  6558. var total;
  6559. if (r1 + r2 > width) {
  6560. total = r1 + r2;
  6561. r1 *= width / total;
  6562. r2 *= width / total;
  6563. }
  6564. if (r3 + r4 > width) {
  6565. total = r3 + r4;
  6566. r3 *= width / total;
  6567. r4 *= width / total;
  6568. }
  6569. if (r2 + r3 > height) {
  6570. total = r2 + r3;
  6571. r2 *= height / total;
  6572. r3 *= height / total;
  6573. }
  6574. if (r1 + r4 > height) {
  6575. total = r1 + r4;
  6576. r1 *= height / total;
  6577. r4 *= height / total;
  6578. }
  6579. ctx.moveTo(x + r1, y);
  6580. ctx.lineTo(x + width - r2, y);
  6581. r2 !== 0 && ctx.quadraticCurveTo(
  6582. x + width, y, x + width, y + r2
  6583. );
  6584. ctx.lineTo(x + width, y + height - r3);
  6585. r3 !== 0 && ctx.quadraticCurveTo(
  6586. x + width, y + height, x + width - r3, y + height
  6587. );
  6588. ctx.lineTo(x + r4, y + height);
  6589. r4 !== 0 && ctx.quadraticCurveTo(
  6590. x, y + height, x, y + height - r4
  6591. );
  6592. ctx.lineTo(x, y + r1);
  6593. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  6594. }
  6595. // TODO: Have not support 'start', 'end' yet.
  6596. var VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};
  6597. var VALID_TEXT_VERTICAL_ALIGN = {top: 1, bottom: 1, middle: 1};
  6598. /**
  6599. * @param {module:zrender/graphic/Style} style
  6600. * @return {module:zrender/graphic/Style} The input style.
  6601. */
  6602. function normalizeTextStyle(style) {
  6603. normalizeStyle(style);
  6604. each$1(style.rich, normalizeStyle);
  6605. return style;
  6606. }
  6607. function normalizeStyle(style) {
  6608. if (style) {
  6609. style.font = makeFont(style);
  6610. var textAlign = style.textAlign;
  6611. textAlign === 'middle' && (textAlign = 'center');
  6612. style.textAlign = (
  6613. textAlign == null || VALID_TEXT_ALIGN[textAlign]
  6614. ) ? textAlign : 'left';
  6615. // Compatible with textBaseline.
  6616. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  6617. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  6618. style.textVerticalAlign = (
  6619. textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]
  6620. ) ? textVerticalAlign : 'top';
  6621. var textPadding = style.textPadding;
  6622. if (textPadding) {
  6623. style.textPadding = normalizeCssArray(style.textPadding);
  6624. }
  6625. }
  6626. }
  6627. /**
  6628. * @param {CanvasRenderingContext2D} ctx
  6629. * @param {string} text
  6630. * @param {module:zrender/graphic/Style} style
  6631. * @param {Object|boolean} [rect] {x, y, width, height}
  6632. * If set false, rect text is not used.
  6633. */
  6634. function renderText(hostEl, ctx, text, style, rect) {
  6635. style.rich
  6636. ? renderRichText(hostEl, ctx, text, style, rect)
  6637. : renderPlainText(hostEl, ctx, text, style, rect);
  6638. }
  6639. function renderPlainText(hostEl, ctx, text, style, rect) {
  6640. var font = setCtx(ctx, 'font', style.font || DEFAULT_FONT);
  6641. var textPadding = style.textPadding;
  6642. var contentBlock = hostEl.__textCotentBlock;
  6643. if (!contentBlock || hostEl.__dirty) {
  6644. contentBlock = hostEl.__textCotentBlock = parsePlainText(
  6645. text, font, textPadding, style.truncate
  6646. );
  6647. }
  6648. var outerHeight = contentBlock.outerHeight;
  6649. var textLines = contentBlock.lines;
  6650. var lineHeight = contentBlock.lineHeight;
  6651. var boxPos = getBoxPosition(outerHeight, style, rect);
  6652. var baseX = boxPos.baseX;
  6653. var baseY = boxPos.baseY;
  6654. var textAlign = boxPos.textAlign;
  6655. var textVerticalAlign = boxPos.textVerticalAlign;
  6656. // Origin of textRotation should be the base point of text drawing.
  6657. applyTextRotation(ctx, style, rect, baseX, baseY);
  6658. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  6659. var textX = baseX;
  6660. var textY = boxY;
  6661. var needDrawBg = needDrawBackground(style);
  6662. if (needDrawBg || textPadding) {
  6663. // Consider performance, do not call getTextWidth util necessary.
  6664. var textWidth = getWidth(text, font);
  6665. var outerWidth = textWidth;
  6666. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  6667. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  6668. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  6669. if (textPadding) {
  6670. textX = getTextXForPadding(baseX, textAlign, textPadding);
  6671. textY += textPadding[0];
  6672. }
  6673. }
  6674. setCtx(ctx, 'textAlign', textAlign || 'left');
  6675. // Force baseline to be "middle". Otherwise, if using "top", the
  6676. // text will offset downward a little bit in font "Microsoft YaHei".
  6677. setCtx(ctx, 'textBaseline', 'middle');
  6678. // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  6679. setCtx(ctx, 'shadowBlur', style.textShadowBlur || 0);
  6680. setCtx(ctx, 'shadowColor', style.textShadowColor || 'transparent');
  6681. setCtx(ctx, 'shadowOffsetX', style.textShadowOffsetX || 0);
  6682. setCtx(ctx, 'shadowOffsetY', style.textShadowOffsetY || 0);
  6683. // `textBaseline` is set as 'middle'.
  6684. textY += lineHeight / 2;
  6685. var textStrokeWidth = style.textStrokeWidth;
  6686. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  6687. var textFill = getFill(style.textFill);
  6688. if (textStroke) {
  6689. setCtx(ctx, 'lineWidth', textStrokeWidth);
  6690. setCtx(ctx, 'strokeStyle', textStroke);
  6691. }
  6692. if (textFill) {
  6693. setCtx(ctx, 'fillStyle', textFill);
  6694. }
  6695. for (var i = 0; i < textLines.length; i++) {
  6696. // Fill after stroke so the outline will not cover the main part.
  6697. textStroke && ctx.strokeText(textLines[i], textX, textY);
  6698. textFill && ctx.fillText(textLines[i], textX, textY);
  6699. textY += lineHeight;
  6700. }
  6701. }
  6702. function renderRichText(hostEl, ctx, text, style, rect) {
  6703. var contentBlock = hostEl.__textCotentBlock;
  6704. if (!contentBlock || hostEl.__dirty) {
  6705. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  6706. }
  6707. drawRichText(hostEl, ctx, contentBlock, style, rect);
  6708. }
  6709. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  6710. var contentWidth = contentBlock.width;
  6711. var outerWidth = contentBlock.outerWidth;
  6712. var outerHeight = contentBlock.outerHeight;
  6713. var textPadding = style.textPadding;
  6714. var boxPos = getBoxPosition(outerHeight, style, rect);
  6715. var baseX = boxPos.baseX;
  6716. var baseY = boxPos.baseY;
  6717. var textAlign = boxPos.textAlign;
  6718. var textVerticalAlign = boxPos.textVerticalAlign;
  6719. // Origin of textRotation should be the base point of text drawing.
  6720. applyTextRotation(ctx, style, rect, baseX, baseY);
  6721. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  6722. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  6723. var xLeft = boxX;
  6724. var lineTop = boxY;
  6725. if (textPadding) {
  6726. xLeft += textPadding[3];
  6727. lineTop += textPadding[0];
  6728. }
  6729. var xRight = xLeft + contentWidth;
  6730. needDrawBackground(style) && drawBackground(
  6731. hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight
  6732. );
  6733. for (var i = 0; i < contentBlock.lines.length; i++) {
  6734. var line = contentBlock.lines[i];
  6735. var tokens = line.tokens;
  6736. var tokenCount = tokens.length;
  6737. var lineHeight = line.lineHeight;
  6738. var usedWidth = line.width;
  6739. var leftIndex = 0;
  6740. var lineXLeft = xLeft;
  6741. var lineXRight = xRight;
  6742. var rightIndex = tokenCount - 1;
  6743. var token;
  6744. while (
  6745. leftIndex < tokenCount
  6746. && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')
  6747. ) {
  6748. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  6749. usedWidth -= token.width;
  6750. lineXLeft += token.width;
  6751. leftIndex++;
  6752. }
  6753. while (
  6754. rightIndex >= 0
  6755. && (token = tokens[rightIndex], token.textAlign === 'right')
  6756. ) {
  6757. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  6758. usedWidth -= token.width;
  6759. lineXRight -= token.width;
  6760. rightIndex--;
  6761. }
  6762. // The other tokens are placed as textAlign 'center' if there is enough space.
  6763. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  6764. while (leftIndex <= rightIndex) {
  6765. token = tokens[leftIndex];
  6766. // Consider width specified by user, use 'center' rather than 'left'.
  6767. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  6768. lineXLeft += token.width;
  6769. leftIndex++;
  6770. }
  6771. lineTop += lineHeight;
  6772. }
  6773. }
  6774. function applyTextRotation(ctx, style, rect, x, y) {
  6775. // textRotation only apply in RectText.
  6776. if (rect && style.textRotation) {
  6777. var origin = style.textOrigin;
  6778. if (origin === 'center') {
  6779. x = rect.width / 2 + rect.x;
  6780. y = rect.height / 2 + rect.y;
  6781. }
  6782. else if (origin) {
  6783. x = origin[0] + rect.x;
  6784. y = origin[1] + rect.y;
  6785. }
  6786. ctx.translate(x, y);
  6787. // Positive: anticlockwise
  6788. ctx.rotate(-style.textRotation);
  6789. ctx.translate(-x, -y);
  6790. }
  6791. }
  6792. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  6793. var tokenStyle = style.rich[token.styleName] || {};
  6794. // 'ctx.textBaseline' is always set as 'middle', for sake of
  6795. // the bias of "Microsoft YaHei".
  6796. var textVerticalAlign = token.textVerticalAlign;
  6797. var y = lineTop + lineHeight / 2;
  6798. if (textVerticalAlign === 'top') {
  6799. y = lineTop + token.height / 2;
  6800. }
  6801. else if (textVerticalAlign === 'bottom') {
  6802. y = lineTop + lineHeight - token.height / 2;
  6803. }
  6804. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(
  6805. hostEl,
  6806. ctx,
  6807. tokenStyle,
  6808. textAlign === 'right'
  6809. ? x - token.width
  6810. : textAlign === 'center'
  6811. ? x - token.width / 2
  6812. : x,
  6813. y - token.height / 2,
  6814. token.width,
  6815. token.height
  6816. );
  6817. var textPadding = token.textPadding;
  6818. if (textPadding) {
  6819. x = getTextXForPadding(x, textAlign, textPadding);
  6820. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  6821. }
  6822. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  6823. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  6824. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  6825. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  6826. setCtx(ctx, 'textAlign', textAlign);
  6827. // Force baseline to be "middle". Otherwise, if using "top", the
  6828. // text will offset downward a little bit in font "Microsoft YaHei".
  6829. setCtx(ctx, 'textBaseline', 'middle');
  6830. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  6831. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  6832. var textFill = getFill(tokenStyle.textFill || style.textFill);
  6833. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
  6834. // Fill after stroke so the outline will not cover the main part.
  6835. if (textStroke) {
  6836. setCtx(ctx, 'lineWidth', textStrokeWidth);
  6837. setCtx(ctx, 'strokeStyle', textStroke);
  6838. ctx.strokeText(token.text, x, y);
  6839. }
  6840. if (textFill) {
  6841. setCtx(ctx, 'fillStyle', textFill);
  6842. ctx.fillText(token.text, x, y);
  6843. }
  6844. }
  6845. function needDrawBackground(style) {
  6846. return style.textBackgroundColor
  6847. || (style.textBorderWidth && style.textBorderColor);
  6848. }
  6849. // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius}
  6850. // shape: {x, y, width, height}
  6851. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  6852. var textBackgroundColor = style.textBackgroundColor;
  6853. var textBorderWidth = style.textBorderWidth;
  6854. var textBorderColor = style.textBorderColor;
  6855. var isPlainBg = isString(textBackgroundColor);
  6856. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  6857. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  6858. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  6859. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  6860. if (isPlainBg || (textBorderWidth && textBorderColor)) {
  6861. ctx.beginPath();
  6862. var textBorderRadius = style.textBorderRadius;
  6863. if (!textBorderRadius) {
  6864. ctx.rect(x, y, width, height);
  6865. }
  6866. else {
  6867. buildPath(ctx, {
  6868. x: x, y: y, width: width, height: height, r: textBorderRadius
  6869. });
  6870. }
  6871. ctx.closePath();
  6872. }
  6873. if (isPlainBg) {
  6874. setCtx(ctx, 'fillStyle', textBackgroundColor);
  6875. ctx.fill();
  6876. }
  6877. else if (isObject(textBackgroundColor)) {
  6878. var image = textBackgroundColor.image;
  6879. image = createOrUpdateImage(
  6880. image, null, hostEl, onBgImageLoaded, textBackgroundColor
  6881. );
  6882. if (image && isImageReady(image)) {
  6883. ctx.drawImage(image, x, y, width, height);
  6884. }
  6885. }
  6886. if (textBorderWidth && textBorderColor) {
  6887. setCtx(ctx, 'lineWidth', textBorderWidth);
  6888. setCtx(ctx, 'strokeStyle', textBorderColor);
  6889. ctx.stroke();
  6890. }
  6891. }
  6892. function onBgImageLoaded(image, textBackgroundColor) {
  6893. // Replace image, so that `contain/text.js#parseRichText`
  6894. // will get correct result in next tick.
  6895. textBackgroundColor.image = image;
  6896. }
  6897. function getBoxPosition(blockHeiht, style, rect) {
  6898. var baseX = style.x || 0;
  6899. var baseY = style.y || 0;
  6900. var textAlign = style.textAlign;
  6901. var textVerticalAlign = style.textVerticalAlign;
  6902. // Text position represented by coord
  6903. if (rect) {
  6904. var textPosition = style.textPosition;
  6905. if (textPosition instanceof Array) {
  6906. // Percent
  6907. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  6908. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  6909. }
  6910. else {
  6911. var res = adjustTextPositionOnRect(
  6912. textPosition, rect, style.textDistance
  6913. );
  6914. baseX = res.x;
  6915. baseY = res.y;
  6916. // Default align and baseline when has textPosition
  6917. textAlign = textAlign || res.textAlign;
  6918. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  6919. }
  6920. // textOffset is only support in RectText, otherwise
  6921. // we have to adjust boundingRect for textOffset.
  6922. var textOffset = style.textOffset;
  6923. if (textOffset) {
  6924. baseX += textOffset[0];
  6925. baseY += textOffset[1];
  6926. }
  6927. }
  6928. return {
  6929. baseX: baseX,
  6930. baseY: baseY,
  6931. textAlign: textAlign,
  6932. textVerticalAlign: textVerticalAlign
  6933. };
  6934. }
  6935. function setCtx(ctx, prop, value) {
  6936. // FIXME ??? performance try
  6937. // if (ctx.__currentValues[prop] !== value) {
  6938. // ctx[prop] = ctx.__currentValues[prop] = value;
  6939. ctx[prop] = value;
  6940. // }
  6941. return ctx[prop];
  6942. }
  6943. /**
  6944. * @param {string} [stroke] If specified, do not check style.textStroke.
  6945. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  6946. * @param {number} style
  6947. */
  6948. function getStroke(stroke, lineWidth) {
  6949. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  6950. ? null
  6951. // TODO pattern and gradient?
  6952. : (stroke.image || stroke.colorStops)
  6953. ? '#000'
  6954. : stroke;
  6955. }
  6956. function getFill(fill) {
  6957. return (fill == null || fill === 'none')
  6958. ? null
  6959. // TODO pattern and gradient?
  6960. : (fill.image || fill.colorStops)
  6961. ? '#000'
  6962. : fill;
  6963. }
  6964. function parsePercent(value, maxValue) {
  6965. if (typeof value === 'string') {
  6966. if (value.lastIndexOf('%') >= 0) {
  6967. return parseFloat(value) / 100 * maxValue;
  6968. }
  6969. return parseFloat(value);
  6970. }
  6971. return value;
  6972. }
  6973. function getTextXForPadding(x, textAlign, textPadding) {
  6974. return textAlign === 'right'
  6975. ? (x - textPadding[1])
  6976. : textAlign === 'center'
  6977. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  6978. : (x + textPadding[3]);
  6979. }
  6980. /**
  6981. * @param {string} text
  6982. * @param {module:zrender/Style} style
  6983. * @return {boolean}
  6984. */
  6985. function needDrawText(text, style) {
  6986. return text != null
  6987. && (text
  6988. || style.textBackgroundColor
  6989. || (style.textBorderWidth && style.textBorderColor)
  6990. || style.textPadding
  6991. );
  6992. }
  6993. /**
  6994. * Mixin for drawing text in a element bounding rect
  6995. * @module zrender/mixin/RectText
  6996. */
  6997. var tmpRect$1 = new BoundingRect();
  6998. var RectText = function () {};
  6999. RectText.prototype = {
  7000. constructor: RectText,
  7001. /**
  7002. * Draw text in a rect with specified position.
  7003. * @param {CanvasRenderingContext2D} ctx
  7004. * @param {Object} rect Displayable rect
  7005. */
  7006. drawRectText: function (ctx, rect) {
  7007. var style = this.style;
  7008. rect = style.textRect || rect;
  7009. // Optimize, avoid normalize every time.
  7010. this.__dirty && normalizeTextStyle(style, true);
  7011. var text = style.text;
  7012. // Convert to string
  7013. text != null && (text += '');
  7014. if (!needDrawText(text, style)) {
  7015. return;
  7016. }
  7017. // FIXME
  7018. ctx.save();
  7019. // Transform rect to view space
  7020. var transform = this.transform;
  7021. if (!style.transformText) {
  7022. if (transform) {
  7023. tmpRect$1.copy(rect);
  7024. tmpRect$1.applyTransform(transform);
  7025. rect = tmpRect$1;
  7026. }
  7027. }
  7028. else {
  7029. this.setTransform(ctx);
  7030. }
  7031. // transformText and textRotation can not be used at the same time.
  7032. renderText(this, ctx, text, style, rect);
  7033. ctx.restore();
  7034. }
  7035. };
  7036. /**
  7037. * 可绘制的图形基类
  7038. * Base class of all displayable graphic objects
  7039. * @module zrender/graphic/Displayable
  7040. */
  7041. /**
  7042. * @alias module:zrender/graphic/Displayable
  7043. * @extends module:zrender/Element
  7044. * @extends module:zrender/graphic/mixin/RectText
  7045. */
  7046. function Displayable(opts) {
  7047. opts = opts || {};
  7048. Element.call(this, opts);
  7049. // Extend properties
  7050. for (var name in opts) {
  7051. if (
  7052. opts.hasOwnProperty(name) &&
  7053. name !== 'style'
  7054. ) {
  7055. this[name] = opts[name];
  7056. }
  7057. }
  7058. /**
  7059. * @type {module:zrender/graphic/Style}
  7060. */
  7061. this.style = new Style(opts.style, this);
  7062. this._rect = null;
  7063. // Shapes for cascade clipping.
  7064. this.__clipPaths = [];
  7065. // FIXME Stateful must be mixined after style is setted
  7066. // Stateful.call(this, opts);
  7067. }
  7068. Displayable.prototype = {
  7069. constructor: Displayable,
  7070. type: 'displayable',
  7071. /**
  7072. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  7073. * Dirty flag. From which painter will determine if this displayable object needs brush
  7074. * @name module:zrender/graphic/Displayable#__dirty
  7075. * @type {boolean}
  7076. */
  7077. __dirty: true,
  7078. /**
  7079. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  7080. * If ignore drawing of the displayable object. Mouse event will still be triggered
  7081. * @name module:/zrender/graphic/Displayable#invisible
  7082. * @type {boolean}
  7083. * @default false
  7084. */
  7085. invisible: false,
  7086. /**
  7087. * @name module:/zrender/graphic/Displayable#z
  7088. * @type {number}
  7089. * @default 0
  7090. */
  7091. z: 0,
  7092. /**
  7093. * @name module:/zrender/graphic/Displayable#z
  7094. * @type {number}
  7095. * @default 0
  7096. */
  7097. z2: 0,
  7098. /**
  7099. * z层level,决定绘画在哪层canvas中
  7100. * @name module:/zrender/graphic/Displayable#zlevel
  7101. * @type {number}
  7102. * @default 0
  7103. */
  7104. zlevel: 0,
  7105. /**
  7106. * 是否可拖拽
  7107. * @name module:/zrender/graphic/Displayable#draggable
  7108. * @type {boolean}
  7109. * @default false
  7110. */
  7111. draggable: false,
  7112. /**
  7113. * 是否正在拖拽
  7114. * @name module:/zrender/graphic/Displayable#draggable
  7115. * @type {boolean}
  7116. * @default false
  7117. */
  7118. dragging: false,
  7119. /**
  7120. * 是否相应鼠标事件
  7121. * @name module:/zrender/graphic/Displayable#silent
  7122. * @type {boolean}
  7123. * @default false
  7124. */
  7125. silent: false,
  7126. /**
  7127. * If enable culling
  7128. * @type {boolean}
  7129. * @default false
  7130. */
  7131. culling: false,
  7132. /**
  7133. * Mouse cursor when hovered
  7134. * @name module:/zrender/graphic/Displayable#cursor
  7135. * @type {string}
  7136. */
  7137. cursor: 'pointer',
  7138. /**
  7139. * If hover area is bounding rect
  7140. * @name module:/zrender/graphic/Displayable#rectHover
  7141. * @type {string}
  7142. */
  7143. rectHover: false,
  7144. /**
  7145. * Render the element progressively when the value >= 0,
  7146. * usefull for large data.
  7147. * @type {number}
  7148. */
  7149. progressive: -1,
  7150. beforeBrush: function (ctx) {},
  7151. afterBrush: function (ctx) {},
  7152. /**
  7153. * 图形绘制方法
  7154. * @param {CanvasRenderingContext2D} ctx
  7155. */
  7156. // Interface
  7157. brush: function (ctx, prevEl) {},
  7158. /**
  7159. * 获取最小包围盒
  7160. * @return {module:zrender/core/BoundingRect}
  7161. */
  7162. // Interface
  7163. getBoundingRect: function () {},
  7164. /**
  7165. * 判断坐标 x, y 是否在图形上
  7166. * If displayable element contain coord x, y
  7167. * @param {number} x
  7168. * @param {number} y
  7169. * @return {boolean}
  7170. */
  7171. contain: function (x, y) {
  7172. return this.rectContain(x, y);
  7173. },
  7174. /**
  7175. * @param {Function} cb
  7176. * @param {} context
  7177. */
  7178. traverse: function (cb, context) {
  7179. cb.call(context, this);
  7180. },
  7181. /**
  7182. * 判断坐标 x, y 是否在图形的包围盒上
  7183. * If bounding rect of element contain coord x, y
  7184. * @param {number} x
  7185. * @param {number} y
  7186. * @return {boolean}
  7187. */
  7188. rectContain: function (x, y) {
  7189. var coord = this.transformCoordToLocal(x, y);
  7190. var rect = this.getBoundingRect();
  7191. return rect.contain(coord[0], coord[1]);
  7192. },
  7193. /**
  7194. * 标记图形元素为脏,并且在下一帧重绘
  7195. * Mark displayable element dirty and refresh next frame
  7196. */
  7197. dirty: function () {
  7198. this.__dirty = true;
  7199. this._rect = null;
  7200. this.__zr && this.__zr.refresh();
  7201. },
  7202. /**
  7203. * 图形是否会触发事件
  7204. * If displayable object binded any event
  7205. * @return {boolean}
  7206. */
  7207. // TODO, 通过 bind 绑定的事件
  7208. // isSilent: function () {
  7209. // return !(
  7210. // this.hoverable || this.draggable
  7211. // || this.onmousemove || this.onmouseover || this.onmouseout
  7212. // || this.onmousedown || this.onmouseup || this.onclick
  7213. // || this.ondragenter || this.ondragover || this.ondragleave
  7214. // || this.ondrop
  7215. // );
  7216. // },
  7217. /**
  7218. * Alias for animate('style')
  7219. * @param {boolean} loop
  7220. */
  7221. animateStyle: function (loop) {
  7222. return this.animate('style', loop);
  7223. },
  7224. attrKV: function (key, value) {
  7225. if (key !== 'style') {
  7226. Element.prototype.attrKV.call(this, key, value);
  7227. }
  7228. else {
  7229. this.style.set(value);
  7230. }
  7231. },
  7232. /**
  7233. * @param {Object|string} key
  7234. * @param {*} value
  7235. */
  7236. setStyle: function (key, value) {
  7237. this.style.set(key, value);
  7238. this.dirty(false);
  7239. return this;
  7240. },
  7241. /**
  7242. * Use given style object
  7243. * @param {Object} obj
  7244. */
  7245. useStyle: function (obj) {
  7246. this.style = new Style(obj, this);
  7247. this.dirty(false);
  7248. return this;
  7249. }
  7250. };
  7251. inherits(Displayable, Element);
  7252. mixin(Displayable, RectText);
  7253. /**
  7254. * @alias zrender/graphic/Image
  7255. * @extends module:zrender/graphic/Displayable
  7256. * @constructor
  7257. * @param {Object} opts
  7258. */
  7259. function ZImage(opts) {
  7260. Displayable.call(this, opts);
  7261. }
  7262. ZImage.prototype = {
  7263. constructor: ZImage,
  7264. type: 'image',
  7265. brush: function (ctx, prevEl) {
  7266. var style = this.style;
  7267. var src = style.image;
  7268. // Must bind each time
  7269. style.bind(ctx, this, prevEl);
  7270. var image = this._image = createOrUpdateImage(
  7271. src,
  7272. this._image,
  7273. this,
  7274. this.onload
  7275. );
  7276. if (!image || !isImageReady(image)) {
  7277. return;
  7278. }
  7279. // 图片已经加载完成
  7280. // if (image.nodeName.toUpperCase() == 'IMG') {
  7281. // if (!image.complete) {
  7282. // return;
  7283. // }
  7284. // }
  7285. // Else is canvas
  7286. var x = style.x || 0;
  7287. var y = style.y || 0;
  7288. var width = style.width;
  7289. var height = style.height;
  7290. var aspect = image.width / image.height;
  7291. if (width == null && height != null) {
  7292. // Keep image/height ratio
  7293. width = height * aspect;
  7294. }
  7295. else if (height == null && width != null) {
  7296. height = width / aspect;
  7297. }
  7298. else if (width == null && height == null) {
  7299. width = image.width;
  7300. height = image.height;
  7301. }
  7302. // 设置transform
  7303. this.setTransform(ctx);
  7304. if (style.sWidth && style.sHeight) {
  7305. var sx = style.sx || 0;
  7306. var sy = style.sy || 0;
  7307. ctx.drawImage(
  7308. image,
  7309. sx, sy, style.sWidth, style.sHeight,
  7310. x, y, width, height
  7311. );
  7312. }
  7313. else if (style.sx && style.sy) {
  7314. var sx = style.sx;
  7315. var sy = style.sy;
  7316. var sWidth = width - sx;
  7317. var sHeight = height - sy;
  7318. ctx.drawImage(
  7319. image,
  7320. sx, sy, sWidth, sHeight,
  7321. x, y, width, height
  7322. );
  7323. }
  7324. else {
  7325. ctx.drawImage(image, x, y, width, height);
  7326. }
  7327. this.restoreTransform(ctx);
  7328. // Draw rect text
  7329. if (style.text != null) {
  7330. this.drawRectText(ctx, this.getBoundingRect());
  7331. }
  7332. },
  7333. getBoundingRect: function () {
  7334. var style = this.style;
  7335. if (! this._rect) {
  7336. this._rect = new BoundingRect(
  7337. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  7338. );
  7339. }
  7340. return this._rect;
  7341. }
  7342. };
  7343. inherits(ZImage, Displayable);
  7344. /**
  7345. * Default canvas painter
  7346. * @module zrender/Painter
  7347. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  7348. * errorrik (errorrik@gmail.com)
  7349. * pissang (https://www.github.com/pissang)
  7350. */
  7351. // PENDIGN
  7352. // Layer exceeds MAX_PROGRESSIVE_LAYER_NUMBER may have some problem when flush directly second time.
  7353. //
  7354. // Maximum progressive layer. When exceeding this number. All elements will be drawed in the last layer.
  7355. var MAX_PROGRESSIVE_LAYER_NUMBER = 5;
  7356. function parseInt10(val) {
  7357. return parseInt(val, 10);
  7358. }
  7359. function isLayerValid(layer) {
  7360. if (!layer) {
  7361. return false;
  7362. }
  7363. if (layer.__builtin__) {
  7364. return true;
  7365. }
  7366. if (typeof(layer.resize) !== 'function'
  7367. || typeof(layer.refresh) !== 'function'
  7368. ) {
  7369. return false;
  7370. }
  7371. return true;
  7372. }
  7373. function preProcessLayer(layer) {
  7374. layer.__unusedCount++;
  7375. }
  7376. function postProcessLayer(layer) {
  7377. if (layer.__unusedCount == 1) {
  7378. layer.clear();
  7379. }
  7380. }
  7381. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7382. var viewRect = new BoundingRect(0, 0, 0, 0);
  7383. function isDisplayableCulled(el, width, height) {
  7384. tmpRect.copy(el.getBoundingRect());
  7385. if (el.transform) {
  7386. tmpRect.applyTransform(el.transform);
  7387. }
  7388. viewRect.width = width;
  7389. viewRect.height = height;
  7390. return !tmpRect.intersect(viewRect);
  7391. }
  7392. function isClipPathChanged(clipPaths, prevClipPaths) {
  7393. if (clipPaths == prevClipPaths) { // Can both be null or undefined
  7394. return false;
  7395. }
  7396. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  7397. return true;
  7398. }
  7399. for (var i = 0; i < clipPaths.length; i++) {
  7400. if (clipPaths[i] !== prevClipPaths[i]) {
  7401. return true;
  7402. }
  7403. }
  7404. }
  7405. function doClip(clipPaths, ctx) {
  7406. for (var i = 0; i < clipPaths.length; i++) {
  7407. var clipPath = clipPaths[i];
  7408. clipPath.setTransform(ctx);
  7409. ctx.beginPath();
  7410. clipPath.buildPath(ctx, clipPath.shape);
  7411. ctx.clip();
  7412. // Transform back
  7413. clipPath.restoreTransform(ctx);
  7414. }
  7415. }
  7416. function createRoot(width, height) {
  7417. var domRoot = document.createElement('div');
  7418. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  7419. domRoot.style.cssText = [
  7420. 'position:relative',
  7421. 'overflow:hidden',
  7422. 'width:' + width + 'px',
  7423. 'height:' + height + 'px',
  7424. 'padding:0',
  7425. 'margin:0',
  7426. 'border-width:0'
  7427. ].join(';') + ';';
  7428. return domRoot;
  7429. }
  7430. /**
  7431. * @alias module:zrender/Painter
  7432. * @constructor
  7433. * @param {HTMLElement} root 绘图容器
  7434. * @param {module:zrender/Storage} storage
  7435. * @param {Object} opts
  7436. */
  7437. var Painter = function (root, storage, opts) {
  7438. this.type = 'canvas';
  7439. // In node environment using node-canvas
  7440. var singleCanvas = !root.nodeName // In node ?
  7441. || root.nodeName.toUpperCase() === 'CANVAS';
  7442. this._opts = opts = extend({}, opts || {});
  7443. /**
  7444. * @type {number}
  7445. */
  7446. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  7447. /**
  7448. * @type {boolean}
  7449. * @private
  7450. */
  7451. this._singleCanvas = singleCanvas;
  7452. /**
  7453. * 绘图容器
  7454. * @type {HTMLElement}
  7455. */
  7456. this.root = root;
  7457. var rootStyle = root.style;
  7458. if (rootStyle) {
  7459. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  7460. rootStyle['-webkit-user-select'] =
  7461. rootStyle['user-select'] =
  7462. rootStyle['-webkit-touch-callout'] = 'none';
  7463. root.innerHTML = '';
  7464. }
  7465. /**
  7466. * @type {module:zrender/Storage}
  7467. */
  7468. this.storage = storage;
  7469. /**
  7470. * @type {Array.<number>}
  7471. * @private
  7472. */
  7473. var zlevelList = this._zlevelList = [];
  7474. /**
  7475. * @type {Object.<string, module:zrender/Layer>}
  7476. * @private
  7477. */
  7478. var layers = this._layers = {};
  7479. /**
  7480. * @type {Object.<string, Object>}
  7481. * @type {private}
  7482. */
  7483. this._layerConfig = {};
  7484. if (!singleCanvas) {
  7485. this._width = this._getSize(0);
  7486. this._height = this._getSize(1);
  7487. var domRoot = this._domRoot = createRoot(
  7488. this._width, this._height
  7489. );
  7490. root.appendChild(domRoot);
  7491. }
  7492. else {
  7493. if (opts.width != null) {
  7494. root.width = opts.width;
  7495. }
  7496. if (opts.height != null) {
  7497. root.height = opts.height;
  7498. }
  7499. // Use canvas width and height directly
  7500. var width = root.width;
  7501. var height = root.height;
  7502. this._width = width;
  7503. this._height = height;
  7504. // Create layer if only one given canvas
  7505. // Device pixel ratio is fixed to 1 because given canvas has its specified width and height
  7506. var mainLayer = new Layer(root, this, 1);
  7507. mainLayer.initContext();
  7508. // FIXME Use canvas width and height
  7509. // mainLayer.resize(width, height);
  7510. layers[0] = mainLayer;
  7511. zlevelList.push(0);
  7512. this._domRoot = root;
  7513. }
  7514. // Layers for progressive rendering
  7515. this._progressiveLayers = [];
  7516. /**
  7517. * @type {module:zrender/Layer}
  7518. * @private
  7519. */
  7520. this._hoverlayer;
  7521. this._hoverElements = [];
  7522. };
  7523. Painter.prototype = {
  7524. constructor: Painter,
  7525. getType: function () {
  7526. return 'canvas';
  7527. },
  7528. /**
  7529. * If painter use a single canvas
  7530. * @return {boolean}
  7531. */
  7532. isSingleCanvas: function () {
  7533. return this._singleCanvas;
  7534. },
  7535. /**
  7536. * @return {HTMLDivElement}
  7537. */
  7538. getViewportRoot: function () {
  7539. return this._domRoot;
  7540. },
  7541. getViewportRootOffset: function () {
  7542. var viewportRoot = this.getViewportRoot();
  7543. if (viewportRoot) {
  7544. return {
  7545. offsetLeft: viewportRoot.offsetLeft || 0,
  7546. offsetTop: viewportRoot.offsetTop || 0
  7547. };
  7548. }
  7549. },
  7550. /**
  7551. * 刷新
  7552. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  7553. */
  7554. refresh: function (paintAll) {
  7555. var list = this.storage.getDisplayList(true);
  7556. var zlevelList = this._zlevelList;
  7557. this._paintList(list, paintAll);
  7558. // Paint custum layers
  7559. for (var i = 0; i < zlevelList.length; i++) {
  7560. var z = zlevelList[i];
  7561. var layer = this._layers[z];
  7562. if (!layer.__builtin__ && layer.refresh) {
  7563. layer.refresh();
  7564. }
  7565. }
  7566. this.refreshHover();
  7567. if (this._progressiveLayers.length) {
  7568. this._startProgessive();
  7569. }
  7570. return this;
  7571. },
  7572. addHover: function (el, hoverStyle) {
  7573. if (el.__hoverMir) {
  7574. return;
  7575. }
  7576. var elMirror = new el.constructor({
  7577. style: el.style,
  7578. shape: el.shape
  7579. });
  7580. elMirror.__from = el;
  7581. el.__hoverMir = elMirror;
  7582. elMirror.setStyle(hoverStyle);
  7583. this._hoverElements.push(elMirror);
  7584. },
  7585. removeHover: function (el) {
  7586. var elMirror = el.__hoverMir;
  7587. var hoverElements = this._hoverElements;
  7588. var idx = indexOf(hoverElements, elMirror);
  7589. if (idx >= 0) {
  7590. hoverElements.splice(idx, 1);
  7591. }
  7592. el.__hoverMir = null;
  7593. },
  7594. clearHover: function (el) {
  7595. var hoverElements = this._hoverElements;
  7596. for (var i = 0; i < hoverElements.length; i++) {
  7597. var from = hoverElements[i].__from;
  7598. if (from) {
  7599. from.__hoverMir = null;
  7600. }
  7601. }
  7602. hoverElements.length = 0;
  7603. },
  7604. refreshHover: function () {
  7605. var hoverElements = this._hoverElements;
  7606. var len = hoverElements.length;
  7607. var hoverLayer = this._hoverlayer;
  7608. hoverLayer && hoverLayer.clear();
  7609. if (!len) {
  7610. return;
  7611. }
  7612. sort(hoverElements, this.storage.displayableSortFunc);
  7613. // Use a extream large zlevel
  7614. // FIXME?
  7615. if (!hoverLayer) {
  7616. hoverLayer = this._hoverlayer = this.getLayer(1e5);
  7617. }
  7618. var scope = {};
  7619. hoverLayer.ctx.save();
  7620. for (var i = 0; i < len;) {
  7621. var el = hoverElements[i];
  7622. var originalEl = el.__from;
  7623. // Original el is removed
  7624. // PENDING
  7625. if (!(originalEl && originalEl.__zr)) {
  7626. hoverElements.splice(i, 1);
  7627. originalEl.__hoverMir = null;
  7628. len--;
  7629. continue;
  7630. }
  7631. i++;
  7632. // Use transform
  7633. // FIXME style and shape ?
  7634. if (!originalEl.invisible) {
  7635. el.transform = originalEl.transform;
  7636. el.invTransform = originalEl.invTransform;
  7637. el.__clipPaths = originalEl.__clipPaths;
  7638. // el.
  7639. this._doPaintEl(el, hoverLayer, true, scope);
  7640. }
  7641. }
  7642. hoverLayer.ctx.restore();
  7643. },
  7644. _startProgessive: function () {
  7645. var self = this;
  7646. if (!self._furtherProgressive) {
  7647. return;
  7648. }
  7649. // Use a token to stop progress steps triggered by
  7650. // previous zr.refresh calling.
  7651. var token = self._progressiveToken = +new Date();
  7652. self._progress++;
  7653. requestAnimationFrame(step);
  7654. function step() {
  7655. // In case refreshed or disposed
  7656. if (token === self._progressiveToken && self.storage) {
  7657. self._doPaintList(self.storage.getDisplayList());
  7658. if (self._furtherProgressive) {
  7659. self._progress++;
  7660. requestAnimationFrame(step);
  7661. }
  7662. else {
  7663. self._progressiveToken = -1;
  7664. }
  7665. }
  7666. }
  7667. },
  7668. _clearProgressive: function () {
  7669. this._progressiveToken = -1;
  7670. this._progress = 0;
  7671. each$1(this._progressiveLayers, function (layer) {
  7672. layer.__dirty && layer.clear();
  7673. });
  7674. },
  7675. _paintList: function (list, paintAll) {
  7676. if (paintAll == null) {
  7677. paintAll = false;
  7678. }
  7679. this._updateLayerStatus(list);
  7680. this._clearProgressive();
  7681. this.eachBuiltinLayer(preProcessLayer);
  7682. this._doPaintList(list, paintAll);
  7683. this.eachBuiltinLayer(postProcessLayer);
  7684. },
  7685. _doPaintList: function (list, paintAll) {
  7686. var currentLayer;
  7687. var currentZLevel;
  7688. var ctx;
  7689. // var invTransform = [];
  7690. var scope;
  7691. var progressiveLayerIdx = 0;
  7692. var currentProgressiveLayer;
  7693. var width = this._width;
  7694. var height = this._height;
  7695. var layerProgress;
  7696. var frame = this._progress;
  7697. function flushProgressiveLayer(layer) {
  7698. var dpr = ctx.dpr || 1;
  7699. ctx.save();
  7700. ctx.globalAlpha = 1;
  7701. ctx.shadowBlur = 0;
  7702. // Avoid layer don't clear in next progressive frame
  7703. currentLayer.__dirty = true;
  7704. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7705. ctx.drawImage(layer.dom, 0, 0, width * dpr, height * dpr);
  7706. ctx.restore();
  7707. }
  7708. for (var i = 0, l = list.length; i < l; i++) {
  7709. var el = list[i];
  7710. var elZLevel = this._singleCanvas ? 0 : el.zlevel;
  7711. var elFrame = el.__frame;
  7712. // Flush at current context
  7713. // PENDING
  7714. if (elFrame < 0 && currentProgressiveLayer) {
  7715. flushProgressiveLayer(currentProgressiveLayer);
  7716. currentProgressiveLayer = null;
  7717. }
  7718. // Change draw layer
  7719. if (currentZLevel !== elZLevel) {
  7720. if (ctx) {
  7721. ctx.restore();
  7722. }
  7723. // Reset scope
  7724. scope = {};
  7725. // Only 0 zlevel if only has one canvas
  7726. currentZLevel = elZLevel;
  7727. currentLayer = this.getLayer(currentZLevel);
  7728. if (!currentLayer.__builtin__) {
  7729. zrLog(
  7730. 'ZLevel ' + currentZLevel
  7731. + ' has been used by unkown layer ' + currentLayer.id
  7732. );
  7733. }
  7734. ctx = currentLayer.ctx;
  7735. ctx.save();
  7736. // Reset the count
  7737. currentLayer.__unusedCount = 0;
  7738. if (currentLayer.__dirty || paintAll) {
  7739. currentLayer.clear();
  7740. }
  7741. }
  7742. if (!(currentLayer.__dirty || paintAll)) {
  7743. continue;
  7744. }
  7745. if (elFrame >= 0) {
  7746. // Progressive layer changed
  7747. if (!currentProgressiveLayer) {
  7748. currentProgressiveLayer = this._progressiveLayers[
  7749. Math.min(progressiveLayerIdx++, MAX_PROGRESSIVE_LAYER_NUMBER - 1)
  7750. ];
  7751. currentProgressiveLayer.ctx.save();
  7752. currentProgressiveLayer.renderScope = {};
  7753. if (currentProgressiveLayer
  7754. && (currentProgressiveLayer.__progress > currentProgressiveLayer.__maxProgress)
  7755. ) {
  7756. // flushProgressiveLayer(currentProgressiveLayer);
  7757. // Quick jump all progressive elements
  7758. // All progressive element are not dirty, jump over and flush directly
  7759. i = currentProgressiveLayer.__nextIdxNotProg - 1;
  7760. // currentProgressiveLayer = null;
  7761. continue;
  7762. }
  7763. layerProgress = currentProgressiveLayer.__progress;
  7764. if (!currentProgressiveLayer.__dirty) {
  7765. // Keep rendering
  7766. frame = layerProgress;
  7767. }
  7768. currentProgressiveLayer.__progress = frame + 1;
  7769. }
  7770. if (elFrame === frame) {
  7771. this._doPaintEl(el, currentProgressiveLayer, true, currentProgressiveLayer.renderScope);
  7772. }
  7773. }
  7774. else {
  7775. this._doPaintEl(el, currentLayer, paintAll, scope);
  7776. }
  7777. el.__dirty = false;
  7778. }
  7779. if (currentProgressiveLayer) {
  7780. flushProgressiveLayer(currentProgressiveLayer);
  7781. }
  7782. // Restore the lastLayer ctx
  7783. ctx && ctx.restore();
  7784. // If still has clipping state
  7785. // if (scope.prevElClipPaths) {
  7786. // ctx.restore();
  7787. // }
  7788. this._furtherProgressive = false;
  7789. each$1(this._progressiveLayers, function (layer) {
  7790. if (layer.__maxProgress >= layer.__progress) {
  7791. this._furtherProgressive = true;
  7792. }
  7793. }, this);
  7794. },
  7795. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  7796. var ctx = currentLayer.ctx;
  7797. var m = el.transform;
  7798. if (
  7799. (currentLayer.__dirty || forcePaint)
  7800. // Ignore invisible element
  7801. && !el.invisible
  7802. // Ignore transparent element
  7803. && el.style.opacity !== 0
  7804. // Ignore scale 0 element, in some environment like node-canvas
  7805. // Draw a scale 0 element can cause all following draw wrong
  7806. // And setTransform with scale 0 will cause set back transform failed.
  7807. && !(m && !m[0] && !m[3])
  7808. // Ignore culled element
  7809. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  7810. ) {
  7811. var clipPaths = el.__clipPaths;
  7812. // Optimize when clipping on group with several elements
  7813. if (scope.prevClipLayer !== currentLayer
  7814. || isClipPathChanged(clipPaths, scope.prevElClipPaths)
  7815. ) {
  7816. // If has previous clipping state, restore from it
  7817. if (scope.prevElClipPaths) {
  7818. scope.prevClipLayer.ctx.restore();
  7819. scope.prevClipLayer = scope.prevElClipPaths = null;
  7820. // Reset prevEl since context has been restored
  7821. scope.prevEl = null;
  7822. }
  7823. // New clipping state
  7824. if (clipPaths) {
  7825. ctx.save();
  7826. doClip(clipPaths, ctx);
  7827. scope.prevClipLayer = currentLayer;
  7828. scope.prevElClipPaths = clipPaths;
  7829. }
  7830. }
  7831. el.beforeBrush && el.beforeBrush(ctx);
  7832. el.brush(ctx, scope.prevEl || null);
  7833. scope.prevEl = el;
  7834. el.afterBrush && el.afterBrush(ctx);
  7835. }
  7836. },
  7837. /**
  7838. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  7839. * @param {number} zlevel
  7840. * @return {module:zrender/Layer}
  7841. */
  7842. getLayer: function (zlevel) {
  7843. if (this._singleCanvas) {
  7844. return this._layers[0];
  7845. }
  7846. var layer = this._layers[zlevel];
  7847. if (!layer) {
  7848. // Create a new layer
  7849. layer = new Layer('zr_' + zlevel, this, this.dpr);
  7850. layer.__builtin__ = true;
  7851. if (this._layerConfig[zlevel]) {
  7852. merge(layer, this._layerConfig[zlevel], true);
  7853. }
  7854. this.insertLayer(zlevel, layer);
  7855. // Context is created after dom inserted to document
  7856. // Or excanvas will get 0px clientWidth and clientHeight
  7857. layer.initContext();
  7858. }
  7859. return layer;
  7860. },
  7861. insertLayer: function (zlevel, layer) {
  7862. var layersMap = this._layers;
  7863. var zlevelList = this._zlevelList;
  7864. var len = zlevelList.length;
  7865. var prevLayer = null;
  7866. var i = -1;
  7867. var domRoot = this._domRoot;
  7868. if (layersMap[zlevel]) {
  7869. zrLog('ZLevel ' + zlevel + ' has been used already');
  7870. return;
  7871. }
  7872. // Check if is a valid layer
  7873. if (!isLayerValid(layer)) {
  7874. zrLog('Layer of zlevel ' + zlevel + ' is not valid');
  7875. return;
  7876. }
  7877. if (len > 0 && zlevel > zlevelList[0]) {
  7878. for (i = 0; i < len - 1; i++) {
  7879. if (
  7880. zlevelList[i] < zlevel
  7881. && zlevelList[i + 1] > zlevel
  7882. ) {
  7883. break;
  7884. }
  7885. }
  7886. prevLayer = layersMap[zlevelList[i]];
  7887. }
  7888. zlevelList.splice(i + 1, 0, zlevel);
  7889. layersMap[zlevel] = layer;
  7890. // Vitual layer will not directly show on the screen.
  7891. // (It can be a WebGL layer and assigned to a ZImage element)
  7892. // But it still under management of zrender.
  7893. if (!layer.virtual) {
  7894. if (prevLayer) {
  7895. var prevDom = prevLayer.dom;
  7896. if (prevDom.nextSibling) {
  7897. domRoot.insertBefore(
  7898. layer.dom,
  7899. prevDom.nextSibling
  7900. );
  7901. }
  7902. else {
  7903. domRoot.appendChild(layer.dom);
  7904. }
  7905. }
  7906. else {
  7907. if (domRoot.firstChild) {
  7908. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  7909. }
  7910. else {
  7911. domRoot.appendChild(layer.dom);
  7912. }
  7913. }
  7914. }
  7915. },
  7916. // Iterate each layer
  7917. eachLayer: function (cb, context) {
  7918. var zlevelList = this._zlevelList;
  7919. var z;
  7920. var i;
  7921. for (i = 0; i < zlevelList.length; i++) {
  7922. z = zlevelList[i];
  7923. cb.call(context, this._layers[z], z);
  7924. }
  7925. },
  7926. // Iterate each buildin layer
  7927. eachBuiltinLayer: function (cb, context) {
  7928. var zlevelList = this._zlevelList;
  7929. var layer;
  7930. var z;
  7931. var i;
  7932. for (i = 0; i < zlevelList.length; i++) {
  7933. z = zlevelList[i];
  7934. layer = this._layers[z];
  7935. if (layer.__builtin__) {
  7936. cb.call(context, layer, z);
  7937. }
  7938. }
  7939. },
  7940. // Iterate each other layer except buildin layer
  7941. eachOtherLayer: function (cb, context) {
  7942. var zlevelList = this._zlevelList;
  7943. var layer;
  7944. var z;
  7945. var i;
  7946. for (i = 0; i < zlevelList.length; i++) {
  7947. z = zlevelList[i];
  7948. layer = this._layers[z];
  7949. if (!layer.__builtin__) {
  7950. cb.call(context, layer, z);
  7951. }
  7952. }
  7953. },
  7954. /**
  7955. * 获取所有已创建的层
  7956. * @param {Array.<module:zrender/Layer>} [prevLayer]
  7957. */
  7958. getLayers: function () {
  7959. return this._layers;
  7960. },
  7961. _updateLayerStatus: function (list) {
  7962. var layers = this._layers;
  7963. var progressiveLayers = this._progressiveLayers;
  7964. var elCountsLastFrame = {};
  7965. var progressiveElCountsLastFrame = {};
  7966. this.eachBuiltinLayer(function (layer, z) {
  7967. elCountsLastFrame[z] = layer.elCount;
  7968. layer.elCount = 0;
  7969. layer.__dirty = false;
  7970. });
  7971. each$1(progressiveLayers, function (layer, idx) {
  7972. progressiveElCountsLastFrame[idx] = layer.elCount;
  7973. layer.elCount = 0;
  7974. layer.__dirty = false;
  7975. });
  7976. var progressiveLayerCount = 0;
  7977. var currentProgressiveLayer;
  7978. var lastProgressiveKey;
  7979. var frameCount = 0;
  7980. for (var i = 0, l = list.length; i < l; i++) {
  7981. var el = list[i];
  7982. var zlevel = this._singleCanvas ? 0 : el.zlevel;
  7983. var layer = layers[zlevel];
  7984. var elProgress = el.progressive;
  7985. if (layer) {
  7986. layer.elCount++;
  7987. layer.__dirty = layer.__dirty || el.__dirty;
  7988. }
  7989. /////// Update progressive
  7990. if (elProgress >= 0) {
  7991. // Fix wrong progressive sequence problem.
  7992. if (lastProgressiveKey !== elProgress) {
  7993. lastProgressiveKey = elProgress;
  7994. frameCount++;
  7995. }
  7996. var elFrame = el.__frame = frameCount - 1;
  7997. if (!currentProgressiveLayer) {
  7998. var idx = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER - 1);
  7999. currentProgressiveLayer = progressiveLayers[idx];
  8000. if (!currentProgressiveLayer) {
  8001. currentProgressiveLayer = progressiveLayers[idx] = new Layer(
  8002. 'progressive', this, this.dpr
  8003. );
  8004. currentProgressiveLayer.initContext();
  8005. }
  8006. currentProgressiveLayer.__maxProgress = 0;
  8007. }
  8008. currentProgressiveLayer.__dirty = currentProgressiveLayer.__dirty || el.__dirty;
  8009. currentProgressiveLayer.elCount++;
  8010. currentProgressiveLayer.__maxProgress = Math.max(
  8011. currentProgressiveLayer.__maxProgress, elFrame
  8012. );
  8013. if (currentProgressiveLayer.__maxProgress >= currentProgressiveLayer.__progress) {
  8014. // Should keep rendering this layer because progressive rendering is not finished yet
  8015. layer.__dirty = true;
  8016. }
  8017. }
  8018. else {
  8019. el.__frame = -1;
  8020. if (currentProgressiveLayer) {
  8021. currentProgressiveLayer.__nextIdxNotProg = i;
  8022. progressiveLayerCount++;
  8023. currentProgressiveLayer = null;
  8024. }
  8025. }
  8026. }
  8027. if (currentProgressiveLayer) {
  8028. progressiveLayerCount++;
  8029. currentProgressiveLayer.__nextIdxNotProg = i;
  8030. }
  8031. // 层中的元素数量有发生变化
  8032. this.eachBuiltinLayer(function (layer, z) {
  8033. if (elCountsLastFrame[z] !== layer.elCount) {
  8034. layer.__dirty = true;
  8035. }
  8036. });
  8037. progressiveLayers.length = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER);
  8038. each$1(progressiveLayers, function (layer, idx) {
  8039. if (progressiveElCountsLastFrame[idx] !== layer.elCount) {
  8040. el.__dirty = true;
  8041. }
  8042. if (layer.__dirty) {
  8043. layer.__progress = 0;
  8044. }
  8045. });
  8046. },
  8047. /**
  8048. * 清除hover层外所有内容
  8049. */
  8050. clear: function () {
  8051. this.eachBuiltinLayer(this._clearLayer);
  8052. return this;
  8053. },
  8054. _clearLayer: function (layer) {
  8055. layer.clear();
  8056. },
  8057. /**
  8058. * 修改指定zlevel的绘制参数
  8059. *
  8060. * @param {string} zlevel
  8061. * @param {Object} config 配置对象
  8062. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8063. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8064. * @param {number} [config.lastFrameAlpha=0.7]
  8065. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8066. */
  8067. configLayer: function (zlevel, config) {
  8068. if (config) {
  8069. var layerConfig = this._layerConfig;
  8070. if (!layerConfig[zlevel]) {
  8071. layerConfig[zlevel] = config;
  8072. }
  8073. else {
  8074. merge(layerConfig[zlevel], config, true);
  8075. }
  8076. var layer = this._layers[zlevel];
  8077. if (layer) {
  8078. merge(layer, layerConfig[zlevel], true);
  8079. }
  8080. }
  8081. },
  8082. /**
  8083. * 删除指定层
  8084. * @param {number} zlevel 层所在的zlevel
  8085. */
  8086. delLayer: function (zlevel) {
  8087. var layers = this._layers;
  8088. var zlevelList = this._zlevelList;
  8089. var layer = layers[zlevel];
  8090. if (!layer) {
  8091. return;
  8092. }
  8093. layer.dom.parentNode.removeChild(layer.dom);
  8094. delete layers[zlevel];
  8095. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8096. },
  8097. /**
  8098. * 区域大小变化后重绘
  8099. */
  8100. resize: function (width, height) {
  8101. var domRoot = this._domRoot;
  8102. // FIXME Why ?
  8103. domRoot.style.display = 'none';
  8104. // Save input w/h
  8105. var opts = this._opts;
  8106. width != null && (opts.width = width);
  8107. height != null && (opts.height = height);
  8108. width = this._getSize(0);
  8109. height = this._getSize(1);
  8110. domRoot.style.display = '';
  8111. // 优化没有实际改变的resize
  8112. if (this._width != width || height != this._height) {
  8113. domRoot.style.width = width + 'px';
  8114. domRoot.style.height = height + 'px';
  8115. for (var id in this._layers) {
  8116. if (this._layers.hasOwnProperty(id)) {
  8117. this._layers[id].resize(width, height);
  8118. }
  8119. }
  8120. each$1(this._progressiveLayers, function (layer) {
  8121. layer.resize(width, height);
  8122. });
  8123. this.refresh(true);
  8124. }
  8125. this._width = width;
  8126. this._height = height;
  8127. return this;
  8128. },
  8129. /**
  8130. * 清除单独的一个层
  8131. * @param {number} zlevel
  8132. */
  8133. clearLayer: function (zlevel) {
  8134. var layer = this._layers[zlevel];
  8135. if (layer) {
  8136. layer.clear();
  8137. }
  8138. },
  8139. /**
  8140. * 释放
  8141. */
  8142. dispose: function () {
  8143. this.root.innerHTML = '';
  8144. this.root =
  8145. this.storage =
  8146. this._domRoot =
  8147. this._layers = null;
  8148. },
  8149. /**
  8150. * Get canvas which has all thing rendered
  8151. * @param {Object} opts
  8152. * @param {string} [opts.backgroundColor]
  8153. * @param {number} [opts.pixelRatio]
  8154. */
  8155. getRenderedCanvas: function (opts) {
  8156. opts = opts || {};
  8157. if (this._singleCanvas) {
  8158. return this._layers[0].dom;
  8159. }
  8160. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  8161. imageLayer.initContext();
  8162. imageLayer.clearColor = opts.backgroundColor;
  8163. imageLayer.clear();
  8164. var displayList = this.storage.getDisplayList(true);
  8165. var scope = {};
  8166. var zlevel;
  8167. var self = this;
  8168. function findAndDrawOtherLayer(smaller, larger) {
  8169. var zlevelList = self._zlevelList;
  8170. if (smaller == null) {
  8171. smaller = -Infinity;
  8172. }
  8173. var intermediateLayer;
  8174. for (var i = 0; i < zlevelList.length; i++) {
  8175. var z = zlevelList[i];
  8176. var layer = self._layers[z];
  8177. if (!layer.__builtin__ && z > smaller && z < larger) {
  8178. intermediateLayer = layer;
  8179. break;
  8180. }
  8181. }
  8182. if (intermediateLayer && intermediateLayer.renderToCanvas) {
  8183. imageLayer.ctx.save();
  8184. intermediateLayer.renderToCanvas(imageLayer.ctx);
  8185. imageLayer.ctx.restore();
  8186. }
  8187. }
  8188. for (var i = 0; i < displayList.length; i++) {
  8189. var el = displayList[i];
  8190. if (el.zlevel !== zlevel) {
  8191. findAndDrawOtherLayer(zlevel, el.zlevel);
  8192. zlevel = el.zlevel;
  8193. }
  8194. this._doPaintEl(el, imageLayer, true, scope);
  8195. }
  8196. findAndDrawOtherLayer(zlevel, Infinity);
  8197. return imageLayer.dom;
  8198. },
  8199. /**
  8200. * 获取绘图区域宽度
  8201. */
  8202. getWidth: function () {
  8203. return this._width;
  8204. },
  8205. /**
  8206. * 获取绘图区域高度
  8207. */
  8208. getHeight: function () {
  8209. return this._height;
  8210. },
  8211. _getSize: function (whIdx) {
  8212. var opts = this._opts;
  8213. var wh = ['width', 'height'][whIdx];
  8214. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  8215. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  8216. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  8217. if (opts[wh] != null && opts[wh] !== 'auto') {
  8218. return parseFloat(opts[wh]);
  8219. }
  8220. var root = this.root;
  8221. // IE8 does not support getComputedStyle, but it use VML.
  8222. var stl = document.defaultView.getComputedStyle(root);
  8223. return (
  8224. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  8225. - (parseInt10(stl[plt]) || 0)
  8226. - (parseInt10(stl[prb]) || 0)
  8227. ) | 0;
  8228. },
  8229. pathToImage: function (path, dpr) {
  8230. dpr = dpr || this.dpr;
  8231. var canvas = document.createElement('canvas');
  8232. var ctx = canvas.getContext('2d');
  8233. var rect = path.getBoundingRect();
  8234. var style = path.style;
  8235. var shadowBlurSize = style.shadowBlur;
  8236. var shadowOffsetX = style.shadowOffsetX;
  8237. var shadowOffsetY = style.shadowOffsetY;
  8238. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  8239. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  8240. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  8241. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  8242. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  8243. var width = rect.width + leftMargin + rightMargin;
  8244. var height = rect.height + topMargin + bottomMargin;
  8245. canvas.width = width * dpr;
  8246. canvas.height = height * dpr;
  8247. ctx.scale(dpr, dpr);
  8248. ctx.clearRect(0, 0, width, height);
  8249. ctx.dpr = dpr;
  8250. var pathTransform = {
  8251. position: path.position,
  8252. rotation: path.rotation,
  8253. scale: path.scale
  8254. };
  8255. path.position = [leftMargin - rect.x, topMargin - rect.y];
  8256. path.rotation = 0;
  8257. path.scale = [1, 1];
  8258. path.updateTransform();
  8259. if (path) {
  8260. path.brush(ctx);
  8261. }
  8262. var ImageShape = ZImage;
  8263. var imgShape = new ImageShape({
  8264. style: {
  8265. x: 0,
  8266. y: 0,
  8267. image: canvas
  8268. }
  8269. });
  8270. if (pathTransform.position != null) {
  8271. imgShape.position = path.position = pathTransform.position;
  8272. }
  8273. if (pathTransform.rotation != null) {
  8274. imgShape.rotation = path.rotation = pathTransform.rotation;
  8275. }
  8276. if (pathTransform.scale != null) {
  8277. imgShape.scale = path.scale = pathTransform.scale;
  8278. }
  8279. return imgShape;
  8280. }
  8281. };
  8282. /**
  8283. * 事件辅助类
  8284. * @module zrender/core/event
  8285. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  8286. */
  8287. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  8288. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  8289. function getBoundingClientRect(el) {
  8290. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  8291. return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
  8292. }
  8293. // `calculate` is optional, default false
  8294. function clientToLocal(el, e, out, calculate) {
  8295. out = out || {};
  8296. // According to the W3C Working Draft, offsetX and offsetY should be relative
  8297. // to the padding edge of the target element. The only browser using this convention
  8298. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  8299. // not support the properties.
  8300. // (see http://www.jacklmoore.com/notes/mouse-position/)
  8301. // In zr painter.dom, padding edge equals to border edge.
  8302. // FIXME
  8303. // When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
  8304. // offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
  8305. // is too complex. So css-transfrom dont support in this case temporarily.
  8306. if (calculate || !env$1.canvasSupported) {
  8307. defaultGetZrXY(el, e, out);
  8308. }
  8309. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  8310. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  8311. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  8312. // zoom-factor, overflow / opacity layers, transforms ...)
  8313. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  8314. // <https://bugs.jquery.com/ticket/8523#comment:14>
  8315. // BTW3, In ff, offsetX/offsetY is always 0.
  8316. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  8317. out.zrX = e.layerX;
  8318. out.zrY = e.layerY;
  8319. }
  8320. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  8321. else if (e.offsetX != null) {
  8322. out.zrX = e.offsetX;
  8323. out.zrY = e.offsetY;
  8324. }
  8325. // For some other device, e.g., IOS safari.
  8326. else {
  8327. defaultGetZrXY(el, e, out);
  8328. }
  8329. return out;
  8330. }
  8331. function defaultGetZrXY(el, e, out) {
  8332. // This well-known method below does not support css transform.
  8333. var box = getBoundingClientRect(el);
  8334. out.zrX = e.clientX - box.left;
  8335. out.zrY = e.clientY - box.top;
  8336. }
  8337. /**
  8338. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
  8339. * `calculate` is optional, default false.
  8340. */
  8341. function normalizeEvent(el, e, calculate) {
  8342. e = e || window.event;
  8343. if (e.zrX != null) {
  8344. return e;
  8345. }
  8346. var eventType = e.type;
  8347. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  8348. if (!isTouch) {
  8349. clientToLocal(el, e, e, calculate);
  8350. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  8351. }
  8352. else {
  8353. var touch = eventType != 'touchend'
  8354. ? e.targetTouches[0]
  8355. : e.changedTouches[0];
  8356. touch && clientToLocal(el, touch, e, calculate);
  8357. }
  8358. // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  8359. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  8360. // If e.which has been defined, if may be readonly,
  8361. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  8362. var button = e.button;
  8363. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  8364. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  8365. }
  8366. return e;
  8367. }
  8368. function addEventListener(el, name, handler) {
  8369. if (isDomLevel2) {
  8370. el.addEventListener(name, handler);
  8371. }
  8372. else {
  8373. el.attachEvent('on' + name, handler);
  8374. }
  8375. }
  8376. function removeEventListener(el, name, handler) {
  8377. if (isDomLevel2) {
  8378. el.removeEventListener(name, handler);
  8379. }
  8380. else {
  8381. el.detachEvent('on' + name, handler);
  8382. }
  8383. }
  8384. /**
  8385. * preventDefault and stopPropagation.
  8386. * Notice: do not do that in zrender. Upper application
  8387. * do that if necessary.
  8388. *
  8389. * @memberOf module:zrender/core/event
  8390. * @method
  8391. * @param {Event} e : event对象
  8392. */
  8393. var stop = isDomLevel2
  8394. ? function (e) {
  8395. e.preventDefault();
  8396. e.stopPropagation();
  8397. e.cancelBubble = true;
  8398. }
  8399. : function (e) {
  8400. e.returnValue = false;
  8401. e.cancelBubble = true;
  8402. };
  8403. function notLeftMouse(e) {
  8404. // If e.which is undefined, considered as left mouse event.
  8405. return e.which > 1;
  8406. }
  8407. /**
  8408. * 动画主类, 调度和管理所有动画控制器
  8409. *
  8410. * @module zrender/animation/Animation
  8411. * @author pissang(https://github.com/pissang)
  8412. */
  8413. // TODO Additive animation
  8414. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  8415. // https://developer.apple.com/videos/wwdc2014/#236
  8416. /**
  8417. * @typedef {Object} IZRenderStage
  8418. * @property {Function} update
  8419. */
  8420. /**
  8421. * @alias module:zrender/animation/Animation
  8422. * @constructor
  8423. * @param {Object} [options]
  8424. * @param {Function} [options.onframe]
  8425. * @param {IZRenderStage} [options.stage]
  8426. * @example
  8427. * var animation = new Animation();
  8428. * var obj = {
  8429. * x: 100,
  8430. * y: 100
  8431. * };
  8432. * animation.animate(node.position)
  8433. * .when(1000, {
  8434. * x: 500,
  8435. * y: 500
  8436. * })
  8437. * .when(2000, {
  8438. * x: 100,
  8439. * y: 100
  8440. * })
  8441. * .start('spline');
  8442. */
  8443. var Animation = function (options) {
  8444. options = options || {};
  8445. this.stage = options.stage || {};
  8446. this.onframe = options.onframe || function() {};
  8447. // private properties
  8448. this._clips = [];
  8449. this._running = false;
  8450. this._time;
  8451. this._pausedTime;
  8452. this._pauseStart;
  8453. this._paused = false;
  8454. Eventful.call(this);
  8455. };
  8456. Animation.prototype = {
  8457. constructor: Animation,
  8458. /**
  8459. * 添加 clip
  8460. * @param {module:zrender/animation/Clip} clip
  8461. */
  8462. addClip: function (clip) {
  8463. this._clips.push(clip);
  8464. },
  8465. /**
  8466. * 添加 animator
  8467. * @param {module:zrender/animation/Animator} animator
  8468. */
  8469. addAnimator: function (animator) {
  8470. animator.animation = this;
  8471. var clips = animator.getClips();
  8472. for (var i = 0; i < clips.length; i++) {
  8473. this.addClip(clips[i]);
  8474. }
  8475. },
  8476. /**
  8477. * 删除动画片段
  8478. * @param {module:zrender/animation/Clip} clip
  8479. */
  8480. removeClip: function(clip) {
  8481. var idx = indexOf(this._clips, clip);
  8482. if (idx >= 0) {
  8483. this._clips.splice(idx, 1);
  8484. }
  8485. },
  8486. /**
  8487. * 删除动画片段
  8488. * @param {module:zrender/animation/Animator} animator
  8489. */
  8490. removeAnimator: function (animator) {
  8491. var clips = animator.getClips();
  8492. for (var i = 0; i < clips.length; i++) {
  8493. this.removeClip(clips[i]);
  8494. }
  8495. animator.animation = null;
  8496. },
  8497. _update: function() {
  8498. var time = new Date().getTime() - this._pausedTime;
  8499. var delta = time - this._time;
  8500. var clips = this._clips;
  8501. var len = clips.length;
  8502. var deferredEvents = [];
  8503. var deferredClips = [];
  8504. for (var i = 0; i < len; i++) {
  8505. var clip = clips[i];
  8506. var e = clip.step(time, delta);
  8507. // Throw out the events need to be called after
  8508. // stage.update, like destroy
  8509. if (e) {
  8510. deferredEvents.push(e);
  8511. deferredClips.push(clip);
  8512. }
  8513. }
  8514. // Remove the finished clip
  8515. for (var i = 0; i < len;) {
  8516. if (clips[i]._needsRemove) {
  8517. clips[i] = clips[len - 1];
  8518. clips.pop();
  8519. len--;
  8520. }
  8521. else {
  8522. i++;
  8523. }
  8524. }
  8525. len = deferredEvents.length;
  8526. for (var i = 0; i < len; i++) {
  8527. deferredClips[i].fire(deferredEvents[i]);
  8528. }
  8529. this._time = time;
  8530. this.onframe(delta);
  8531. this.trigger('frame', delta);
  8532. if (this.stage.update) {
  8533. this.stage.update();
  8534. }
  8535. },
  8536. _startLoop: function () {
  8537. var self = this;
  8538. this._running = true;
  8539. function step() {
  8540. if (self._running) {
  8541. requestAnimationFrame(step);
  8542. !self._paused && self._update();
  8543. }
  8544. }
  8545. requestAnimationFrame(step);
  8546. },
  8547. /**
  8548. * 开始运行动画
  8549. */
  8550. start: function () {
  8551. this._time = new Date().getTime();
  8552. this._pausedTime = 0;
  8553. this._startLoop();
  8554. },
  8555. /**
  8556. * 停止运行动画
  8557. */
  8558. stop: function () {
  8559. this._running = false;
  8560. },
  8561. /**
  8562. * Pause
  8563. */
  8564. pause: function () {
  8565. if (!this._paused) {
  8566. this._pauseStart = new Date().getTime();
  8567. this._paused = true;
  8568. }
  8569. },
  8570. /**
  8571. * Resume
  8572. */
  8573. resume: function () {
  8574. if (this._paused) {
  8575. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  8576. this._paused = false;
  8577. }
  8578. },
  8579. /**
  8580. * 清除所有动画片段
  8581. */
  8582. clear: function () {
  8583. this._clips = [];
  8584. },
  8585. /**
  8586. * 对一个目标创建一个animator对象,可以指定目标中的属性使用动画
  8587. * @param {Object} target
  8588. * @param {Object} options
  8589. * @param {boolean} [options.loop=false] 是否循环播放动画
  8590. * @param {Function} [options.getter=null]
  8591. * 如果指定getter函数,会通过getter函数取属性值
  8592. * @param {Function} [options.setter=null]
  8593. * 如果指定setter函数,会通过setter函数设置属性值
  8594. * @return {module:zrender/animation/Animation~Animator}
  8595. */
  8596. // TODO Gap
  8597. animate: function (target, options) {
  8598. options = options || {};
  8599. var animator = new Animator(
  8600. target,
  8601. options.loop,
  8602. options.getter,
  8603. options.setter
  8604. );
  8605. this.addAnimator(animator);
  8606. return animator;
  8607. }
  8608. };
  8609. mixin(Animation, Eventful);
  8610. /**
  8611. * Only implements needed gestures for mobile.
  8612. */
  8613. var GestureMgr = function () {
  8614. /**
  8615. * @private
  8616. * @type {Array.<Object>}
  8617. */
  8618. this._track = [];
  8619. };
  8620. GestureMgr.prototype = {
  8621. constructor: GestureMgr,
  8622. recognize: function (event, target, root) {
  8623. this._doTrack(event, target, root);
  8624. return this._recognize(event);
  8625. },
  8626. clear: function () {
  8627. this._track.length = 0;
  8628. return this;
  8629. },
  8630. _doTrack: function (event, target, root) {
  8631. var touches = event.touches;
  8632. if (!touches) {
  8633. return;
  8634. }
  8635. var trackItem = {
  8636. points: [],
  8637. touches: [],
  8638. target: target,
  8639. event: event
  8640. };
  8641. for (var i = 0, len = touches.length; i < len; i++) {
  8642. var touch = touches[i];
  8643. var pos = clientToLocal(root, touch, {});
  8644. trackItem.points.push([pos.zrX, pos.zrY]);
  8645. trackItem.touches.push(touch);
  8646. }
  8647. this._track.push(trackItem);
  8648. },
  8649. _recognize: function (event) {
  8650. for (var eventName in recognizers) {
  8651. if (recognizers.hasOwnProperty(eventName)) {
  8652. var gestureInfo = recognizers[eventName](this._track, event);
  8653. if (gestureInfo) {
  8654. return gestureInfo;
  8655. }
  8656. }
  8657. }
  8658. }
  8659. };
  8660. function dist$1(pointPair) {
  8661. var dx = pointPair[1][0] - pointPair[0][0];
  8662. var dy = pointPair[1][1] - pointPair[0][1];
  8663. return Math.sqrt(dx * dx + dy * dy);
  8664. }
  8665. function center(pointPair) {
  8666. return [
  8667. (pointPair[0][0] + pointPair[1][0]) / 2,
  8668. (pointPair[0][1] + pointPair[1][1]) / 2
  8669. ];
  8670. }
  8671. var recognizers = {
  8672. pinch: function (track, event) {
  8673. var trackLen = track.length;
  8674. if (!trackLen) {
  8675. return;
  8676. }
  8677. var pinchEnd = (track[trackLen - 1] || {}).points;
  8678. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  8679. if (pinchPre
  8680. && pinchPre.length > 1
  8681. && pinchEnd
  8682. && pinchEnd.length > 1
  8683. ) {
  8684. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  8685. !isFinite(pinchScale) && (pinchScale = 1);
  8686. event.pinchScale = pinchScale;
  8687. var pinchCenter = center(pinchEnd);
  8688. event.pinchX = pinchCenter[0];
  8689. event.pinchY = pinchCenter[1];
  8690. return {
  8691. type: 'pinch',
  8692. target: track[0].target,
  8693. event: event
  8694. };
  8695. }
  8696. }
  8697. // Only pinch currently.
  8698. };
  8699. var TOUCH_CLICK_DELAY = 300;
  8700. var mouseHandlerNames = [
  8701. 'click', 'dblclick', 'mousewheel', 'mouseout',
  8702. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  8703. ];
  8704. var touchHandlerNames = [
  8705. 'touchstart', 'touchend', 'touchmove'
  8706. ];
  8707. var pointerEventNames = {
  8708. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  8709. };
  8710. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  8711. var nm = name.replace('mouse', 'pointer');
  8712. return pointerEventNames[nm] ? nm : name;
  8713. });
  8714. function eventNameFix(name) {
  8715. return (name === 'mousewheel' && env$1.browser.firefox) ? 'DOMMouseScroll' : name;
  8716. }
  8717. function processGesture(proxy, event, stage) {
  8718. var gestureMgr = proxy._gestureMgr;
  8719. stage === 'start' && gestureMgr.clear();
  8720. var gestureInfo = gestureMgr.recognize(
  8721. event,
  8722. proxy.handler.findHover(event.zrX, event.zrY, null).target,
  8723. proxy.dom
  8724. );
  8725. stage === 'end' && gestureMgr.clear();
  8726. // Do not do any preventDefault here. Upper application do that if necessary.
  8727. if (gestureInfo) {
  8728. var type = gestureInfo.type;
  8729. event.gestureEvent = type;
  8730. proxy.handler.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);
  8731. }
  8732. }
  8733. // function onMSGestureChange(proxy, event) {
  8734. // if (event.translationX || event.translationY) {
  8735. // // mousemove is carried by MSGesture to reduce the sensitivity.
  8736. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  8737. // }
  8738. // if (event.scale !== 1) {
  8739. // event.pinchX = event.offsetX;
  8740. // event.pinchY = event.offsetY;
  8741. // event.pinchScale = event.scale;
  8742. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  8743. // }
  8744. // }
  8745. /**
  8746. * Prevent mouse event from being dispatched after Touch Events action
  8747. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  8748. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  8749. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  8750. * Result: Blocking Mouse Events for 700ms.
  8751. */
  8752. function setTouchTimer(instance) {
  8753. instance._touching = true;
  8754. clearTimeout(instance._touchTimer);
  8755. instance._touchTimer = setTimeout(function () {
  8756. instance._touching = false;
  8757. }, 700);
  8758. }
  8759. var domHandlers = {
  8760. /**
  8761. * Mouse move handler
  8762. * @inner
  8763. * @param {Event} event
  8764. */
  8765. mousemove: function (event) {
  8766. event = normalizeEvent(this.dom, event);
  8767. this.trigger('mousemove', event);
  8768. },
  8769. /**
  8770. * Mouse out handler
  8771. * @inner
  8772. * @param {Event} event
  8773. */
  8774. mouseout: function (event) {
  8775. event = normalizeEvent(this.dom, event);
  8776. var element = event.toElement || event.relatedTarget;
  8777. if (element != this.dom) {
  8778. while (element && element.nodeType != 9) {
  8779. // 忽略包含在root中的dom引起的mouseOut
  8780. if (element === this.dom) {
  8781. return;
  8782. }
  8783. element = element.parentNode;
  8784. }
  8785. }
  8786. this.trigger('mouseout', event);
  8787. },
  8788. /**
  8789. * Touch开始响应函数
  8790. * @inner
  8791. * @param {Event} event
  8792. */
  8793. touchstart: function (event) {
  8794. // Default mouse behaviour should not be disabled here.
  8795. // For example, page may needs to be slided.
  8796. event = normalizeEvent(this.dom, event);
  8797. // Mark touch, which is useful in distinguish touch and
  8798. // mouse event in upper applicatoin.
  8799. event.zrByTouch = true;
  8800. this._lastTouchMoment = new Date();
  8801. processGesture(this, event, 'start');
  8802. // In touch device, trigger `mousemove`(`mouseover`) should
  8803. // be triggered, and must before `mousedown` triggered.
  8804. domHandlers.mousemove.call(this, event);
  8805. domHandlers.mousedown.call(this, event);
  8806. setTouchTimer(this);
  8807. },
  8808. /**
  8809. * Touch移动响应函数
  8810. * @inner
  8811. * @param {Event} event
  8812. */
  8813. touchmove: function (event) {
  8814. event = normalizeEvent(this.dom, event);
  8815. // Mark touch, which is useful in distinguish touch and
  8816. // mouse event in upper applicatoin.
  8817. event.zrByTouch = true;
  8818. processGesture(this, event, 'change');
  8819. // Mouse move should always be triggered no matter whether
  8820. // there is gestrue event, because mouse move and pinch may
  8821. // be used at the same time.
  8822. domHandlers.mousemove.call(this, event);
  8823. setTouchTimer(this);
  8824. },
  8825. /**
  8826. * Touch结束响应函数
  8827. * @inner
  8828. * @param {Event} event
  8829. */
  8830. touchend: function (event) {
  8831. event = normalizeEvent(this.dom, event);
  8832. // Mark touch, which is useful in distinguish touch and
  8833. // mouse event in upper applicatoin.
  8834. event.zrByTouch = true;
  8835. processGesture(this, event, 'end');
  8836. domHandlers.mouseup.call(this, event);
  8837. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  8838. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  8839. // we can conveniently implement "hover style" in both PC and touch device just
  8840. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  8841. // to remove "hover style" on an element, without any additional code for
  8842. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  8843. // style" will remain for user view)
  8844. // click event should always be triggered no matter whether
  8845. // there is gestrue event. System click can not be prevented.
  8846. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  8847. domHandlers.click.call(this, event);
  8848. }
  8849. setTouchTimer(this);
  8850. },
  8851. pointerdown: function (event) {
  8852. domHandlers.mousedown.call(this, event);
  8853. // if (useMSGuesture(this, event)) {
  8854. // this._msGesture.addPointer(event.pointerId);
  8855. // }
  8856. },
  8857. pointermove: function (event) {
  8858. // FIXME
  8859. // pointermove is so sensitive that it always triggered when
  8860. // tap(click) on touch screen, which affect some judgement in
  8861. // upper application. So, we dont support mousemove on MS touch
  8862. // device yet.
  8863. if (!isPointerFromTouch(event)) {
  8864. domHandlers.mousemove.call(this, event);
  8865. }
  8866. },
  8867. pointerup: function (event) {
  8868. domHandlers.mouseup.call(this, event);
  8869. },
  8870. pointerout: function (event) {
  8871. // pointerout will be triggered when tap on touch screen
  8872. // (IE11+/Edge on MS Surface) after click event triggered,
  8873. // which is inconsistent with the mousout behavior we defined
  8874. // in touchend. So we unify them.
  8875. // (check domHandlers.touchend for detailed explanation)
  8876. if (!isPointerFromTouch(event)) {
  8877. domHandlers.mouseout.call(this, event);
  8878. }
  8879. }
  8880. };
  8881. function isPointerFromTouch(event) {
  8882. var pointerType = event.pointerType;
  8883. return pointerType === 'pen' || pointerType === 'touch';
  8884. }
  8885. // function useMSGuesture(handlerProxy, event) {
  8886. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  8887. // }
  8888. // Common handlers
  8889. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  8890. domHandlers[name] = function (event) {
  8891. event = normalizeEvent(this.dom, event);
  8892. this.trigger(name, event);
  8893. };
  8894. });
  8895. /**
  8896. * 为控制类实例初始化dom 事件处理函数
  8897. *
  8898. * @inner
  8899. * @param {module:zrender/Handler} instance 控制类实例
  8900. */
  8901. function initDomHandler(instance) {
  8902. each$1(touchHandlerNames, function (name) {
  8903. instance._handlers[name] = bind(domHandlers[name], instance);
  8904. });
  8905. each$1(pointerHandlerNames, function (name) {
  8906. instance._handlers[name] = bind(domHandlers[name], instance);
  8907. });
  8908. each$1(mouseHandlerNames, function (name) {
  8909. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  8910. });
  8911. function makeMouseHandler(fn, instance) {
  8912. return function () {
  8913. if (instance._touching) {
  8914. return;
  8915. }
  8916. return fn.apply(instance, arguments);
  8917. };
  8918. }
  8919. }
  8920. function HandlerDomProxy(dom) {
  8921. Eventful.call(this);
  8922. this.dom = dom;
  8923. /**
  8924. * @private
  8925. * @type {boolean}
  8926. */
  8927. this._touching = false;
  8928. /**
  8929. * @private
  8930. * @type {number}
  8931. */
  8932. this._touchTimer;
  8933. /**
  8934. * @private
  8935. * @type {module:zrender/core/GestureMgr}
  8936. */
  8937. this._gestureMgr = new GestureMgr();
  8938. this._handlers = {};
  8939. initDomHandler(this);
  8940. if (env$1.pointerEventsSupported) { // Only IE11+/Edge
  8941. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  8942. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  8943. // at the same time.
  8944. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  8945. // screen, which do not occurs in pointer event.
  8946. // So we use pointer event to both detect touch gesture and mouse behavior.
  8947. mountHandlers(pointerHandlerNames, this);
  8948. // FIXME
  8949. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  8950. // which does not prevent defuault behavior occasionally (which may cause view port
  8951. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  8952. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  8953. // touch screen. And we only support click behavior on MS touch screen now.
  8954. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  8955. // We dont support touch on IE on win7.
  8956. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  8957. // if (typeof MSGesture === 'function') {
  8958. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  8959. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  8960. // }
  8961. }
  8962. else {
  8963. if (env$1.touchEventsSupported) {
  8964. mountHandlers(touchHandlerNames, this);
  8965. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  8966. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  8967. }
  8968. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  8969. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  8970. // mouse event can not be handle in those devices.
  8971. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  8972. // mouseevent after touch event triggered, see `setTouchTimer`.
  8973. mountHandlers(mouseHandlerNames, this);
  8974. }
  8975. function mountHandlers(handlerNames, instance) {
  8976. each$1(handlerNames, function (name) {
  8977. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  8978. }, instance);
  8979. }
  8980. }
  8981. var handlerDomProxyProto = HandlerDomProxy.prototype;
  8982. handlerDomProxyProto.dispose = function () {
  8983. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  8984. for (var i = 0; i < handlerNames.length; i++) {
  8985. var name = handlerNames[i];
  8986. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  8987. }
  8988. };
  8989. handlerDomProxyProto.setCursor = function (cursorStyle) {
  8990. this.dom.style.cursor = cursorStyle || 'default';
  8991. };
  8992. mixin(HandlerDomProxy, Eventful);
  8993. /*!
  8994. * ZRender, a high performance 2d drawing library.
  8995. *
  8996. * Copyright (c) 2013, Baidu Inc.
  8997. * All rights reserved.
  8998. *
  8999. * LICENSE
  9000. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9001. */
  9002. var useVML = !env$1.canvasSupported;
  9003. var painterCtors = {
  9004. canvas: Painter
  9005. };
  9006. var instances$1 = {}; // ZRender实例map索引
  9007. /**
  9008. * @type {string}
  9009. */
  9010. var version$1 = '3.7.4';
  9011. /**
  9012. * Initializing a zrender instance
  9013. * @param {HTMLElement} dom
  9014. * @param {Object} opts
  9015. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9016. * @param {number} [opts.devicePixelRatio]
  9017. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9018. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9019. * @return {module:zrender/ZRender}
  9020. */
  9021. function init$1(dom, opts) {
  9022. var zr = new ZRender(guid(), dom, opts);
  9023. instances$1[zr.id] = zr;
  9024. return zr;
  9025. }
  9026. /**
  9027. * Dispose zrender instance
  9028. * @param {module:zrender/ZRender} zr
  9029. */
  9030. function dispose$1(zr) {
  9031. if (zr) {
  9032. zr.dispose();
  9033. }
  9034. else {
  9035. for (var key in instances$1) {
  9036. if (instances$1.hasOwnProperty(key)) {
  9037. instances$1[key].dispose();
  9038. }
  9039. }
  9040. instances$1 = {};
  9041. }
  9042. return this;
  9043. }
  9044. /**
  9045. * Get zrender instance by id
  9046. * @param {string} id zrender instance id
  9047. * @return {module:zrender/ZRender}
  9048. */
  9049. function getInstance(id) {
  9050. return instances$1[id];
  9051. }
  9052. function registerPainter(name, Ctor) {
  9053. painterCtors[name] = Ctor;
  9054. }
  9055. function delInstance(id) {
  9056. delete instances$1[id];
  9057. }
  9058. /**
  9059. * @module zrender/ZRender
  9060. */
  9061. /**
  9062. * @constructor
  9063. * @alias module:zrender/ZRender
  9064. * @param {string} id
  9065. * @param {HTMLElement} dom
  9066. * @param {Object} opts
  9067. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9068. * @param {number} [opts.devicePixelRatio]
  9069. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9070. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9071. */
  9072. var ZRender = function (id, dom, opts) {
  9073. opts = opts || {};
  9074. /**
  9075. * @type {HTMLDomElement}
  9076. */
  9077. this.dom = dom;
  9078. /**
  9079. * @type {string}
  9080. */
  9081. this.id = id;
  9082. var self = this;
  9083. var storage = new Storage();
  9084. var rendererType = opts.renderer;
  9085. // TODO WebGL
  9086. if (useVML) {
  9087. if (!painterCtors.vml) {
  9088. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9089. }
  9090. rendererType = 'vml';
  9091. }
  9092. else if (!rendererType || !painterCtors[rendererType]) {
  9093. rendererType = 'canvas';
  9094. }
  9095. var painter = new painterCtors[rendererType](dom, storage, opts);
  9096. this.storage = storage;
  9097. this.painter = painter;
  9098. var handerProxy = !env$1.node ? new HandlerDomProxy(painter.getViewportRoot()) : null;
  9099. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9100. /**
  9101. * @type {module:zrender/animation/Animation}
  9102. */
  9103. this.animation = new Animation({
  9104. stage: {
  9105. update: bind(this.flush, this)
  9106. }
  9107. });
  9108. this.animation.start();
  9109. /**
  9110. * @type {boolean}
  9111. * @private
  9112. */
  9113. this._needsRefresh;
  9114. // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9115. // FIXME 有点ugly
  9116. var oldDelFromStorage = storage.delFromStorage;
  9117. var oldAddToStorage = storage.addToStorage;
  9118. storage.delFromStorage = function (el) {
  9119. oldDelFromStorage.call(storage, el);
  9120. el && el.removeSelfFromZr(self);
  9121. };
  9122. storage.addToStorage = function (el) {
  9123. oldAddToStorage.call(storage, el);
  9124. el.addSelfToZr(self);
  9125. };
  9126. };
  9127. ZRender.prototype = {
  9128. constructor: ZRender,
  9129. /**
  9130. * 获取实例唯一标识
  9131. * @return {string}
  9132. */
  9133. getId: function () {
  9134. return this.id;
  9135. },
  9136. /**
  9137. * 添加元素
  9138. * @param {module:zrender/Element} el
  9139. */
  9140. add: function (el) {
  9141. this.storage.addRoot(el);
  9142. this._needsRefresh = true;
  9143. },
  9144. /**
  9145. * 删除元素
  9146. * @param {module:zrender/Element} el
  9147. */
  9148. remove: function (el) {
  9149. this.storage.delRoot(el);
  9150. this._needsRefresh = true;
  9151. },
  9152. /**
  9153. * Change configuration of layer
  9154. * @param {string} zLevel
  9155. * @param {Object} config
  9156. * @param {string} [config.clearColor=0] Clear color
  9157. * @param {string} [config.motionBlur=false] If enable motion blur
  9158. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9159. */
  9160. configLayer: function (zLevel, config) {
  9161. this.painter.configLayer(zLevel, config);
  9162. this._needsRefresh = true;
  9163. },
  9164. /**
  9165. * Repaint the canvas immediately
  9166. */
  9167. refreshImmediately: function () {
  9168. // var start = new Date();
  9169. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9170. // Or it will cause zrender refreshes again and again.
  9171. this._needsRefresh = false;
  9172. this.painter.refresh();
  9173. /**
  9174. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  9175. */
  9176. this._needsRefresh = false;
  9177. // var end = new Date();
  9178. // var log = document.getElementById('log');
  9179. // if (log) {
  9180. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9181. // }
  9182. },
  9183. /**
  9184. * Mark and repaint the canvas in the next frame of browser
  9185. */
  9186. refresh: function() {
  9187. this._needsRefresh = true;
  9188. },
  9189. /**
  9190. * Perform all refresh
  9191. */
  9192. flush: function () {
  9193. if (this._needsRefresh) {
  9194. this.refreshImmediately();
  9195. }
  9196. if (this._needsRefreshHover) {
  9197. this.refreshHoverImmediately();
  9198. }
  9199. },
  9200. /**
  9201. * Add element to hover layer
  9202. * @param {module:zrender/Element} el
  9203. * @param {Object} style
  9204. */
  9205. addHover: function (el, style) {
  9206. if (this.painter.addHover) {
  9207. this.painter.addHover(el, style);
  9208. this.refreshHover();
  9209. }
  9210. },
  9211. /**
  9212. * Add element from hover layer
  9213. * @param {module:zrender/Element} el
  9214. */
  9215. removeHover: function (el) {
  9216. if (this.painter.removeHover) {
  9217. this.painter.removeHover(el);
  9218. this.refreshHover();
  9219. }
  9220. },
  9221. /**
  9222. * Clear all hover elements in hover layer
  9223. * @param {module:zrender/Element} el
  9224. */
  9225. clearHover: function () {
  9226. if (this.painter.clearHover) {
  9227. this.painter.clearHover();
  9228. this.refreshHover();
  9229. }
  9230. },
  9231. /**
  9232. * Refresh hover in next frame
  9233. */
  9234. refreshHover: function () {
  9235. this._needsRefreshHover = true;
  9236. },
  9237. /**
  9238. * Refresh hover immediately
  9239. */
  9240. refreshHoverImmediately: function () {
  9241. this._needsRefreshHover = false;
  9242. this.painter.refreshHover && this.painter.refreshHover();
  9243. },
  9244. /**
  9245. * Resize the canvas.
  9246. * Should be invoked when container size is changed
  9247. * @param {Object} [opts]
  9248. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9249. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9250. */
  9251. resize: function(opts) {
  9252. opts = opts || {};
  9253. this.painter.resize(opts.width, opts.height);
  9254. this.handler.resize();
  9255. },
  9256. /**
  9257. * Stop and clear all animation immediately
  9258. */
  9259. clearAnimation: function () {
  9260. this.animation.clear();
  9261. },
  9262. /**
  9263. * Get container width
  9264. */
  9265. getWidth: function() {
  9266. return this.painter.getWidth();
  9267. },
  9268. /**
  9269. * Get container height
  9270. */
  9271. getHeight: function() {
  9272. return this.painter.getHeight();
  9273. },
  9274. /**
  9275. * Export the canvas as Base64 URL
  9276. * @param {string} type
  9277. * @param {string} [backgroundColor='#fff']
  9278. * @return {string} Base64 URL
  9279. */
  9280. // toDataURL: function(type, backgroundColor) {
  9281. // return this.painter.getRenderedCanvas({
  9282. // backgroundColor: backgroundColor
  9283. // }).toDataURL(type);
  9284. // },
  9285. /**
  9286. * Converting a path to image.
  9287. * It has much better performance of drawing image rather than drawing a vector path.
  9288. * @param {module:zrender/graphic/Path} e
  9289. * @param {number} width
  9290. * @param {number} height
  9291. */
  9292. pathToImage: function(e, dpr) {
  9293. return this.painter.pathToImage(e, dpr);
  9294. },
  9295. /**
  9296. * Set default cursor
  9297. * @param {string} [cursorStyle='default'] 例如 crosshair
  9298. */
  9299. setCursorStyle: function (cursorStyle) {
  9300. this.handler.setCursorStyle(cursorStyle);
  9301. },
  9302. /**
  9303. * Find hovered element
  9304. * @param {number} x
  9305. * @param {number} y
  9306. * @return {Object} {target, topTarget}
  9307. */
  9308. findHover: function (x, y) {
  9309. return this.handler.findHover(x, y);
  9310. },
  9311. /**
  9312. * Bind event
  9313. *
  9314. * @param {string} eventName Event name
  9315. * @param {Function} eventHandler Handler function
  9316. * @param {Object} [context] Context object
  9317. */
  9318. on: function(eventName, eventHandler, context) {
  9319. this.handler.on(eventName, eventHandler, context);
  9320. },
  9321. /**
  9322. * Unbind event
  9323. * @param {string} eventName Event name
  9324. * @param {Function} [eventHandler] Handler function
  9325. */
  9326. off: function(eventName, eventHandler) {
  9327. this.handler.off(eventName, eventHandler);
  9328. },
  9329. /**
  9330. * Trigger event manually
  9331. *
  9332. * @param {string} eventName Event name
  9333. * @param {event=} event Event object
  9334. */
  9335. trigger: function (eventName, event) {
  9336. this.handler.trigger(eventName, event);
  9337. },
  9338. /**
  9339. * Clear all objects and the canvas.
  9340. */
  9341. clear: function () {
  9342. this.storage.delRoot();
  9343. this.painter.clear();
  9344. },
  9345. /**
  9346. * Dispose self.
  9347. */
  9348. dispose: function () {
  9349. this.animation.stop();
  9350. this.clear();
  9351. this.storage.dispose();
  9352. this.painter.dispose();
  9353. this.handler.dispose();
  9354. this.animation =
  9355. this.storage =
  9356. this.painter =
  9357. this.handler = null;
  9358. delInstance(this.id);
  9359. }
  9360. };
  9361. var zrender = (Object.freeze || Object)({
  9362. version: version$1,
  9363. init: init$1,
  9364. dispose: dispose$1,
  9365. getInstance: getInstance,
  9366. registerPainter: registerPainter
  9367. });
  9368. var RADIAN_EPSILON = 1e-4;
  9369. function _trim(str) {
  9370. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  9371. }
  9372. /**
  9373. * Linear mapping a value from domain to range
  9374. * @memberOf module:echarts/util/number
  9375. * @param {(number|Array.<number>)} val
  9376. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  9377. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  9378. * @param {boolean} clamp
  9379. * @return {(number|Array.<number>}
  9380. */
  9381. function linearMap(val, domain, range, clamp) {
  9382. var subDomain = domain[1] - domain[0];
  9383. var subRange = range[1] - range[0];
  9384. if (subDomain === 0) {
  9385. return subRange === 0
  9386. ? range[0]
  9387. : (range[0] + range[1]) / 2;
  9388. }
  9389. // Avoid accuracy problem in edge, such as
  9390. // 146.39 - 62.83 === 83.55999999999999.
  9391. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  9392. // It is a little verbose for efficiency considering this method
  9393. // is a hotspot.
  9394. if (clamp) {
  9395. if (subDomain > 0) {
  9396. if (val <= domain[0]) {
  9397. return range[0];
  9398. }
  9399. else if (val >= domain[1]) {
  9400. return range[1];
  9401. }
  9402. }
  9403. else {
  9404. if (val >= domain[0]) {
  9405. return range[0];
  9406. }
  9407. else if (val <= domain[1]) {
  9408. return range[1];
  9409. }
  9410. }
  9411. }
  9412. else {
  9413. if (val === domain[0]) {
  9414. return range[0];
  9415. }
  9416. if (val === domain[1]) {
  9417. return range[1];
  9418. }
  9419. }
  9420. return (val - domain[0]) / subDomain * subRange + range[0];
  9421. }
  9422. /**
  9423. * Convert a percent string to absolute number.
  9424. * Returns NaN if percent is not a valid string or number
  9425. * @memberOf module:echarts/util/number
  9426. * @param {string|number} percent
  9427. * @param {number} all
  9428. * @return {number}
  9429. */
  9430. function parsePercent$1(percent, all) {
  9431. switch (percent) {
  9432. case 'center':
  9433. case 'middle':
  9434. percent = '50%';
  9435. break;
  9436. case 'left':
  9437. case 'top':
  9438. percent = '0%';
  9439. break;
  9440. case 'right':
  9441. case 'bottom':
  9442. percent = '100%';
  9443. break;
  9444. }
  9445. if (typeof percent === 'string') {
  9446. if (_trim(percent).match(/%$/)) {
  9447. return parseFloat(percent) / 100 * all;
  9448. }
  9449. return parseFloat(percent);
  9450. }
  9451. return percent == null ? NaN : +percent;
  9452. }
  9453. /**
  9454. * (1) Fix rounding error of float numbers.
  9455. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  9456. *
  9457. * @param {number} x
  9458. * @param {number} [precision]
  9459. * @param {boolean} [returnStr]
  9460. * @return {number|string}
  9461. */
  9462. function round(x, precision, returnStr) {
  9463. if (precision == null) {
  9464. precision = 10;
  9465. }
  9466. // Avoid range error
  9467. precision = Math.min(Math.max(0, precision), 20);
  9468. x = (+x).toFixed(precision);
  9469. return returnStr ? x : +x;
  9470. }
  9471. function asc(arr) {
  9472. arr.sort(function (a, b) {
  9473. return a - b;
  9474. });
  9475. return arr;
  9476. }
  9477. /**
  9478. * Get precision
  9479. * @param {number} val
  9480. */
  9481. function getPrecision(val) {
  9482. val = +val;
  9483. if (isNaN(val)) {
  9484. return 0;
  9485. }
  9486. // It is much faster than methods converting number to string as follows
  9487. // var tmp = val.toString();
  9488. // return tmp.length - 1 - tmp.indexOf('.');
  9489. // especially when precision is low
  9490. var e = 1;
  9491. var count = 0;
  9492. while (Math.round(val * e) / e !== val) {
  9493. e *= 10;
  9494. count++;
  9495. }
  9496. return count;
  9497. }
  9498. /**
  9499. * @param {string|number} val
  9500. * @return {number}
  9501. */
  9502. function getPrecisionSafe(val) {
  9503. var str = val.toString();
  9504. // Consider scientific notation: '3.4e-12' '3.4e+12'
  9505. var eIndex = str.indexOf('e');
  9506. if (eIndex > 0) {
  9507. var precision = +str.slice(eIndex + 1);
  9508. return precision < 0 ? -precision : 0;
  9509. }
  9510. else {
  9511. var dotIndex = str.indexOf('.');
  9512. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  9513. }
  9514. }
  9515. /**
  9516. * Minimal dicernible data precisioin according to a single pixel.
  9517. *
  9518. * @param {Array.<number>} dataExtent
  9519. * @param {Array.<number>} pixelExtent
  9520. * @return {number} precision
  9521. */
  9522. function getPixelPrecision(dataExtent, pixelExtent) {
  9523. var log = Math.log;
  9524. var LN10 = Math.LN10;
  9525. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  9526. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  9527. // toFixed() digits argument must be between 0 and 20.
  9528. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  9529. return !isFinite(precision) ? 20 : precision;
  9530. }
  9531. /**
  9532. * Get a data of given precision, assuring the sum of percentages
  9533. * in valueList is 1.
  9534. * The largest remainer method is used.
  9535. * https://en.wikipedia.org/wiki/Largest_remainder_method
  9536. *
  9537. * @param {Array.<number>} valueList a list of all data
  9538. * @param {number} idx index of the data to be processed in valueList
  9539. * @param {number} precision integer number showing digits of precision
  9540. * @return {number} percent ranging from 0 to 100
  9541. */
  9542. function getPercentWithPrecision(valueList, idx, precision) {
  9543. if (!valueList[idx]) {
  9544. return 0;
  9545. }
  9546. var sum = reduce(valueList, function (acc, val) {
  9547. return acc + (isNaN(val) ? 0 : val);
  9548. }, 0);
  9549. if (sum === 0) {
  9550. return 0;
  9551. }
  9552. var digits = Math.pow(10, precision);
  9553. var votesPerQuota = map(valueList, function (val) {
  9554. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  9555. });
  9556. var targetSeats = digits * 100;
  9557. var seats = map(votesPerQuota, function (votes) {
  9558. // Assign automatic seats.
  9559. return Math.floor(votes);
  9560. });
  9561. var currentSum = reduce(seats, function (acc, val) {
  9562. return acc + val;
  9563. }, 0);
  9564. var remainder = map(votesPerQuota, function (votes, idx) {
  9565. return votes - seats[idx];
  9566. });
  9567. // Has remainding votes.
  9568. while (currentSum < targetSeats) {
  9569. // Find next largest remainder.
  9570. var max = Number.NEGATIVE_INFINITY;
  9571. var maxId = null;
  9572. for (var i = 0, len = remainder.length; i < len; ++i) {
  9573. if (remainder[i] > max) {
  9574. max = remainder[i];
  9575. maxId = i;
  9576. }
  9577. }
  9578. // Add a vote to max remainder.
  9579. ++seats[maxId];
  9580. remainder[maxId] = 0;
  9581. ++currentSum;
  9582. }
  9583. return seats[idx] / digits;
  9584. }
  9585. // Number.MAX_SAFE_INTEGER, ie do not support.
  9586. var MAX_SAFE_INTEGER = 9007199254740991;
  9587. /**
  9588. * To 0 - 2 * PI, considering negative radian.
  9589. * @param {number} radian
  9590. * @return {number}
  9591. */
  9592. function remRadian(radian) {
  9593. var pi2 = Math.PI * 2;
  9594. return (radian % pi2 + pi2) % pi2;
  9595. }
  9596. /**
  9597. * @param {type} radian
  9598. * @return {boolean}
  9599. */
  9600. function isRadianAroundZero(val) {
  9601. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  9602. }
  9603. var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d\d)(?::(\d\d)(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
  9604. /**
  9605. * @param {string|Date|number} value These values can be accepted:
  9606. * + An instance of Date, represent a time in its own time zone.
  9607. * + Or string in a subset of ISO 8601, only including:
  9608. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  9609. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  9610. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  9611. * all of which will be treated as local time if time zone is not specified
  9612. * (see <https://momentjs.com/>).
  9613. * + Or other string format, including (all of which will be treated as loacal time):
  9614. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  9615. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  9616. * + a timestamp, which represent a time in UTC.
  9617. * @return {Date} date
  9618. */
  9619. function parseDate(value) {
  9620. if (value instanceof Date) {
  9621. return value;
  9622. }
  9623. else if (typeof value === 'string') {
  9624. // Different browsers parse date in different way, so we parse it manually.
  9625. // Some other issues:
  9626. // new Date('1970-01-01') is UTC,
  9627. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  9628. // See issue #3623
  9629. var match = TIME_REG.exec(value);
  9630. if (!match) {
  9631. // return Invalid Date.
  9632. return new Date(NaN);
  9633. }
  9634. // Use local time when no timezone offset specifed.
  9635. if (!match[8]) {
  9636. // match[n] can only be string or undefined.
  9637. // But take care of '12' + 1 => '121'.
  9638. return new Date(
  9639. +match[1],
  9640. +(match[2] || 1) - 1,
  9641. +match[3] || 1,
  9642. +match[4] || 0,
  9643. +(match[5] || 0),
  9644. +match[6] || 0,
  9645. +match[7] || 0
  9646. );
  9647. }
  9648. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  9649. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  9650. // For example, system timezone is set as "Time Zone: America/Toronto",
  9651. // then these code will get different result:
  9652. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  9653. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  9654. // So we should not use `new Date`, but use `Date.UTC`.
  9655. else {
  9656. var hour = +match[4] || 0;
  9657. if (match[8].toUpperCase() !== 'Z') {
  9658. hour -= match[8].slice(0, 3);
  9659. }
  9660. return new Date(Date.UTC(
  9661. +match[1],
  9662. +(match[2] || 1) - 1,
  9663. +match[3] || 1,
  9664. hour,
  9665. +(match[5] || 0),
  9666. +match[6] || 0,
  9667. +match[7] || 0
  9668. ));
  9669. }
  9670. }
  9671. else if (value == null) {
  9672. return new Date(NaN);
  9673. }
  9674. return new Date(Math.round(value));
  9675. }
  9676. /**
  9677. * Quantity of a number. e.g. 0.1, 1, 10, 100
  9678. *
  9679. * @param {number} val
  9680. * @return {number}
  9681. */
  9682. function quantity(val) {
  9683. return Math.pow(10, quantityExponent(val));
  9684. }
  9685. function quantityExponent(val) {
  9686. return Math.floor(Math.log(val) / Math.LN10);
  9687. }
  9688. /**
  9689. * find a “nice” number approximately equal to x. Round the number if round = true,
  9690. * take ceiling if round = false. The primary observation is that the “nicest”
  9691. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  9692. *
  9693. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  9694. *
  9695. * @param {number} val Non-negative value.
  9696. * @param {boolean} round
  9697. * @return {number}
  9698. */
  9699. function nice(val, round) {
  9700. var exponent = quantityExponent(val);
  9701. var exp10 = Math.pow(10, exponent);
  9702. var f = val / exp10; // 1 <= f < 10
  9703. var nf;
  9704. if (round) {
  9705. if (f < 1.5) { nf = 1; }
  9706. else if (f < 2.5) { nf = 2; }
  9707. else if (f < 4) { nf = 3; }
  9708. else if (f < 7) { nf = 5; }
  9709. else { nf = 10; }
  9710. }
  9711. else {
  9712. if (f < 1) { nf = 1; }
  9713. else if (f < 2) { nf = 2; }
  9714. else if (f < 3) { nf = 3; }
  9715. else if (f < 5) { nf = 5; }
  9716. else { nf = 10; }
  9717. }
  9718. val = nf * exp10;
  9719. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  9720. // 20 is the uppper bound of toFixed.
  9721. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  9722. }
  9723. /**
  9724. * Order intervals asc, and split them when overlap.
  9725. * expect(numberUtil.reformIntervals([
  9726. * {interval: [18, 62], close: [1, 1]},
  9727. * {interval: [-Infinity, -70], close: [0, 0]},
  9728. * {interval: [-70, -26], close: [1, 1]},
  9729. * {interval: [-26, 18], close: [1, 1]},
  9730. * {interval: [62, 150], close: [1, 1]},
  9731. * {interval: [106, 150], close: [1, 1]},
  9732. * {interval: [150, Infinity], close: [0, 0]}
  9733. * ])).toEqual([
  9734. * {interval: [-Infinity, -70], close: [0, 0]},
  9735. * {interval: [-70, -26], close: [1, 1]},
  9736. * {interval: [-26, 18], close: [0, 1]},
  9737. * {interval: [18, 62], close: [0, 1]},
  9738. * {interval: [62, 150], close: [0, 1]},
  9739. * {interval: [150, Infinity], close: [0, 0]}
  9740. * ]);
  9741. * @param {Array.<Object>} list, where `close` mean open or close
  9742. * of the interval, and Infinity can be used.
  9743. * @return {Array.<Object>} The origin list, which has been reformed.
  9744. */
  9745. function reformIntervals(list) {
  9746. list.sort(function (a, b) {
  9747. return littleThan(a, b, 0) ? -1 : 1;
  9748. });
  9749. var curr = -Infinity;
  9750. var currClose = 1;
  9751. for (var i = 0; i < list.length;) {
  9752. var interval = list[i].interval;
  9753. var close = list[i].close;
  9754. for (var lg = 0; lg < 2; lg++) {
  9755. if (interval[lg] <= curr) {
  9756. interval[lg] = curr;
  9757. close[lg] = !lg ? 1 - currClose : 1;
  9758. }
  9759. curr = interval[lg];
  9760. currClose = close[lg];
  9761. }
  9762. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  9763. list.splice(i, 1);
  9764. }
  9765. else {
  9766. i++;
  9767. }
  9768. }
  9769. return list;
  9770. function littleThan(a, b, lg) {
  9771. return a.interval[lg] < b.interval[lg]
  9772. || (
  9773. a.interval[lg] === b.interval[lg]
  9774. && (
  9775. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  9776. || (!lg && littleThan(a, b, 1))
  9777. )
  9778. );
  9779. }
  9780. }
  9781. /**
  9782. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  9783. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  9784. * subtraction forces infinities to NaN
  9785. *
  9786. * @param {*} v
  9787. * @return {boolean}
  9788. */
  9789. function isNumeric(v) {
  9790. return v - parseFloat(v) >= 0;
  9791. }
  9792. var number = (Object.freeze || Object)({
  9793. linearMap: linearMap,
  9794. parsePercent: parsePercent$1,
  9795. round: round,
  9796. asc: asc,
  9797. getPrecision: getPrecision,
  9798. getPrecisionSafe: getPrecisionSafe,
  9799. getPixelPrecision: getPixelPrecision,
  9800. getPercentWithPrecision: getPercentWithPrecision,
  9801. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  9802. remRadian: remRadian,
  9803. isRadianAroundZero: isRadianAroundZero,
  9804. parseDate: parseDate,
  9805. quantity: quantity,
  9806. nice: nice,
  9807. reformIntervals: reformIntervals,
  9808. isNumeric: isNumeric
  9809. });
  9810. /**
  9811. * 每三位默认加,格式化
  9812. * @param {string|number} x
  9813. * @return {string}
  9814. */
  9815. function addCommas(x) {
  9816. if (isNaN(x)) {
  9817. return '-';
  9818. }
  9819. x = (x + '').split('.');
  9820. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,')
  9821. + (x.length > 1 ? ('.' + x[1]) : '');
  9822. }
  9823. /**
  9824. * @param {string} str
  9825. * @param {boolean} [upperCaseFirst=false]
  9826. * @return {string} str
  9827. */
  9828. function toCamelCase(str, upperCaseFirst) {
  9829. str = (str || '').toLowerCase().replace(/-(.)/g, function(match, group1) {
  9830. return group1.toUpperCase();
  9831. });
  9832. if (upperCaseFirst && str) {
  9833. str = str.charAt(0).toUpperCase() + str.slice(1);
  9834. }
  9835. return str;
  9836. }
  9837. var normalizeCssArray$1 = normalizeCssArray;
  9838. function encodeHTML(source) {
  9839. return String(source)
  9840. .replace(/&/g, '&amp;')
  9841. .replace(/</g, '&lt;')
  9842. .replace(/>/g, '&gt;')
  9843. .replace(/"/g, '&quot;')
  9844. .replace(/'/g, '&#39;');
  9845. }
  9846. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  9847. var wrapVar = function (varName, seriesIdx) {
  9848. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  9849. };
  9850. /**
  9851. * Template formatter
  9852. * @param {string} tpl
  9853. * @param {Array.<Object>|Object} paramsList
  9854. * @param {boolean} [encode=false]
  9855. * @return {string}
  9856. */
  9857. function formatTpl(tpl, paramsList, encode) {
  9858. if (!isArray(paramsList)) {
  9859. paramsList = [paramsList];
  9860. }
  9861. var seriesLen = paramsList.length;
  9862. if (!seriesLen) {
  9863. return '';
  9864. }
  9865. var $vars = paramsList[0].$vars || [];
  9866. for (var i = 0; i < $vars.length; i++) {
  9867. var alias = TPL_VAR_ALIAS[i];
  9868. var val = wrapVar(alias, 0);
  9869. tpl = tpl.replace(wrapVar(alias), encode ? encodeHTML(val) : val);
  9870. }
  9871. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  9872. for (var k = 0; k < $vars.length; k++) {
  9873. var val = paramsList[seriesIdx][$vars[k]];
  9874. tpl = tpl.replace(
  9875. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  9876. encode ? encodeHTML(val) : val
  9877. );
  9878. }
  9879. }
  9880. return tpl;
  9881. }
  9882. /**
  9883. * simple Template formatter
  9884. *
  9885. * @param {string} tpl
  9886. * @param {Object} param
  9887. * @param {boolean} [encode=false]
  9888. * @return {string}
  9889. */
  9890. function formatTplSimple(tpl, param, encode) {
  9891. each$1(param, function (value, key) {
  9892. tpl = tpl.replace(
  9893. '{' + key + '}',
  9894. encode ? encodeHTML(value) : value
  9895. );
  9896. });
  9897. return tpl;
  9898. }
  9899. /**
  9900. * @param {string} color
  9901. * @param {string} [extraCssText]
  9902. * @return {string}
  9903. */
  9904. function getTooltipMarker(color, extraCssText) {
  9905. return color
  9906. ? '<span style="display:inline-block;margin-right:5px;'
  9907. + 'border-radius:10px;width:9px;height:9px;background-color:'
  9908. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
  9909. : '';
  9910. }
  9911. /**
  9912. * @param {string} str
  9913. * @return {string}
  9914. * @inner
  9915. */
  9916. var s2d = function (str) {
  9917. return str < 10 ? ('0' + str) : str;
  9918. };
  9919. /**
  9920. * ISO Date format
  9921. * @param {string} tpl
  9922. * @param {number} value
  9923. * @param {boolean} [isUTC=false] Default in local time.
  9924. * see `module:echarts/scale/Time`
  9925. * and `module:echarts/util/number#parseDate`.
  9926. * @inner
  9927. */
  9928. function formatTime(tpl, value, isUTC) {
  9929. if (tpl === 'week'
  9930. || tpl === 'month'
  9931. || tpl === 'quarter'
  9932. || tpl === 'half-year'
  9933. || tpl === 'year'
  9934. ) {
  9935. tpl = 'MM-dd\nyyyy';
  9936. }
  9937. var date = parseDate(value);
  9938. var utc = isUTC ? 'UTC' : '';
  9939. var y = date['get' + utc + 'FullYear']();
  9940. var M = date['get' + utc + 'Month']() + 1;
  9941. var d = date['get' + utc + 'Date']();
  9942. var h = date['get' + utc + 'Hours']();
  9943. var m = date['get' + utc + 'Minutes']();
  9944. var s = date['get' + utc + 'Seconds']();
  9945. tpl = tpl.replace('MM', s2d(M))
  9946. .replace('M', M)
  9947. .replace('yyyy', y)
  9948. .replace('yy', y % 100)
  9949. .replace('dd', s2d(d))
  9950. .replace('d', d)
  9951. .replace('hh', s2d(h))
  9952. .replace('h', h)
  9953. .replace('mm', s2d(m))
  9954. .replace('m', m)
  9955. .replace('ss', s2d(s))
  9956. .replace('s', s);
  9957. return tpl;
  9958. }
  9959. /**
  9960. * Capital first
  9961. * @param {string} str
  9962. * @return {string}
  9963. */
  9964. function capitalFirst(str) {
  9965. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  9966. }
  9967. var truncateText$1 = truncateText;
  9968. var getTextRect = getBoundingRect;
  9969. var format = (Object.freeze || Object)({
  9970. addCommas: addCommas,
  9971. toCamelCase: toCamelCase,
  9972. normalizeCssArray: normalizeCssArray$1,
  9973. encodeHTML: encodeHTML,
  9974. formatTpl: formatTpl,
  9975. formatTplSimple: formatTplSimple,
  9976. getTooltipMarker: getTooltipMarker,
  9977. formatTime: formatTime,
  9978. capitalFirst: capitalFirst,
  9979. truncateText: truncateText$1,
  9980. getTextRect: getTextRect
  9981. });
  9982. var TYPE_DELIMITER = '.';
  9983. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  9984. var MEMBER_PRIFIX = '\0ec_\0';
  9985. /**
  9986. * Hide private class member.
  9987. * The same behavior as `host[name] = value;` (can be right-value)
  9988. * @public
  9989. */
  9990. function set$1(host, name, value) {
  9991. return (host[MEMBER_PRIFIX + name] = value);
  9992. }
  9993. /**
  9994. * Hide private class member.
  9995. * The same behavior as `host[name];`
  9996. * @public
  9997. */
  9998. function get(host, name) {
  9999. return host[MEMBER_PRIFIX + name];
  10000. }
  10001. /**
  10002. * For hidden private class member.
  10003. * The same behavior as `host.hasOwnProperty(name);`
  10004. * @public
  10005. */
  10006. function hasOwn(host, name) {
  10007. return host.hasOwnProperty(MEMBER_PRIFIX + name);
  10008. }
  10009. /**
  10010. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10011. * @public
  10012. */
  10013. function parseClassType$1(componentType) {
  10014. var ret = {main: '', sub: ''};
  10015. if (componentType) {
  10016. componentType = componentType.split(TYPE_DELIMITER);
  10017. ret.main = componentType[0] || '';
  10018. ret.sub = componentType[1] || '';
  10019. }
  10020. return ret;
  10021. }
  10022. /**
  10023. * @public
  10024. */
  10025. function checkClassType(componentType) {
  10026. assert(
  10027. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  10028. 'componentType "' + componentType + '" illegal'
  10029. );
  10030. }
  10031. /**
  10032. * @public
  10033. */
  10034. function enableClassExtend(RootClass, mandatoryMethods) {
  10035. RootClass.$constructor = RootClass;
  10036. RootClass.extend = function (proto) {
  10037. if (__DEV__) {
  10038. each$1(mandatoryMethods, function (method) {
  10039. if (!proto[method]) {
  10040. console.warn(
  10041. 'Method `' + method + '` should be implemented'
  10042. + (proto.type ? ' in ' + proto.type : '') + '.'
  10043. );
  10044. }
  10045. });
  10046. }
  10047. var superClass = this;
  10048. var ExtendedClass = function () {
  10049. if (!proto.$constructor) {
  10050. superClass.apply(this, arguments);
  10051. }
  10052. else {
  10053. proto.$constructor.apply(this, arguments);
  10054. }
  10055. };
  10056. extend(ExtendedClass.prototype, proto);
  10057. ExtendedClass.extend = this.extend;
  10058. ExtendedClass.superCall = superCall;
  10059. ExtendedClass.superApply = superApply;
  10060. inherits(ExtendedClass, this);
  10061. ExtendedClass.superClass = superClass;
  10062. return ExtendedClass;
  10063. };
  10064. }
  10065. // superCall should have class info, which can not be fetch from 'this'.
  10066. // Consider this case:
  10067. // class A has method f,
  10068. // class B inherits class A, overrides method f, f call superApply('f'),
  10069. // class C inherits class B, do not overrides method f,
  10070. // then when method of class C is called, dead loop occured.
  10071. function superCall(context, methodName) {
  10072. var args = slice(arguments, 2);
  10073. return this.superClass.prototype[methodName].apply(context, args);
  10074. }
  10075. function superApply(context, methodName, args) {
  10076. return this.superClass.prototype[methodName].apply(context, args);
  10077. }
  10078. /**
  10079. * @param {Object} entity
  10080. * @param {Object} options
  10081. * @param {boolean} [options.registerWhenExtend]
  10082. * @public
  10083. */
  10084. function enableClassManagement(entity, options) {
  10085. options = options || {};
  10086. /**
  10087. * Component model classes
  10088. * key: componentType,
  10089. * value:
  10090. * componentClass, when componentType is 'xxx'
  10091. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10092. * @type {Object}
  10093. */
  10094. var storage = {};
  10095. entity.registerClass = function (Clazz, componentType) {
  10096. if (componentType) {
  10097. checkClassType(componentType);
  10098. componentType = parseClassType$1(componentType);
  10099. if (!componentType.sub) {
  10100. if (__DEV__) {
  10101. if (storage[componentType.main]) {
  10102. console.warn(componentType.main + ' exists.');
  10103. }
  10104. }
  10105. storage[componentType.main] = Clazz;
  10106. }
  10107. else if (componentType.sub !== IS_CONTAINER) {
  10108. var container = makeContainer(componentType);
  10109. container[componentType.sub] = Clazz;
  10110. }
  10111. }
  10112. return Clazz;
  10113. };
  10114. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10115. var Clazz = storage[componentMainType];
  10116. if (Clazz && Clazz[IS_CONTAINER]) {
  10117. Clazz = subType ? Clazz[subType] : null;
  10118. }
  10119. if (throwWhenNotFound && !Clazz) {
  10120. throw new Error(
  10121. !subType
  10122. ? componentMainType + '.' + 'type should be specified.'
  10123. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  10124. );
  10125. }
  10126. return Clazz;
  10127. };
  10128. entity.getClassesByMainType = function (componentType) {
  10129. componentType = parseClassType$1(componentType);
  10130. var result = [];
  10131. var obj = storage[componentType.main];
  10132. if (obj && obj[IS_CONTAINER]) {
  10133. each$1(obj, function (o, type) {
  10134. type !== IS_CONTAINER && result.push(o);
  10135. });
  10136. }
  10137. else {
  10138. result.push(obj);
  10139. }
  10140. return result;
  10141. };
  10142. entity.hasClass = function (componentType) {
  10143. // Just consider componentType.main.
  10144. componentType = parseClassType$1(componentType);
  10145. return !!storage[componentType.main];
  10146. };
  10147. /**
  10148. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10149. */
  10150. entity.getAllClassMainTypes = function () {
  10151. var types = [];
  10152. each$1(storage, function (obj, type) {
  10153. types.push(type);
  10154. });
  10155. return types;
  10156. };
  10157. /**
  10158. * If a main type is container and has sub types
  10159. * @param {string} mainType
  10160. * @return {boolean}
  10161. */
  10162. entity.hasSubTypes = function (componentType) {
  10163. componentType = parseClassType$1(componentType);
  10164. var obj = storage[componentType.main];
  10165. return obj && obj[IS_CONTAINER];
  10166. };
  10167. entity.parseClassType = parseClassType$1;
  10168. function makeContainer(componentType) {
  10169. var container = storage[componentType.main];
  10170. if (!container || !container[IS_CONTAINER]) {
  10171. container = storage[componentType.main] = {};
  10172. container[IS_CONTAINER] = true;
  10173. }
  10174. return container;
  10175. }
  10176. if (options.registerWhenExtend) {
  10177. var originalExtend = entity.extend;
  10178. if (originalExtend) {
  10179. entity.extend = function (proto) {
  10180. var ExtendedClass = originalExtend.call(this, proto);
  10181. return entity.registerClass(ExtendedClass, proto.type);
  10182. };
  10183. }
  10184. }
  10185. return entity;
  10186. }
  10187. /**
  10188. * @param {string|Array.<string>} properties
  10189. */
  10190. // TODO Parse shadow style
  10191. // TODO Only shallow path support
  10192. var makeStyleMapper = function (properties) {
  10193. // Normalize
  10194. for (var i = 0; i < properties.length; i++) {
  10195. if (!properties[i][1]) {
  10196. properties[i][1] = properties[i][0];
  10197. }
  10198. }
  10199. return function (model, excludes, includes) {
  10200. var style = {};
  10201. for (var i = 0; i < properties.length; i++) {
  10202. var propName = properties[i][1];
  10203. if ((excludes && indexOf(excludes, propName) >= 0)
  10204. || (includes && indexOf(includes, propName) < 0)
  10205. ) {
  10206. continue;
  10207. }
  10208. var val = model.getShallow(propName);
  10209. if (val != null) {
  10210. style[properties[i][0]] = val;
  10211. }
  10212. }
  10213. return style;
  10214. };
  10215. };
  10216. var getLineStyle = makeStyleMapper(
  10217. [
  10218. ['lineWidth', 'width'],
  10219. ['stroke', 'color'],
  10220. ['opacity'],
  10221. ['shadowBlur'],
  10222. ['shadowOffsetX'],
  10223. ['shadowOffsetY'],
  10224. ['shadowColor']
  10225. ]
  10226. );
  10227. var lineStyleMixin = {
  10228. getLineStyle: function (excludes) {
  10229. var style = getLineStyle(this, excludes);
  10230. var lineDash = this.getLineDash(style.lineWidth);
  10231. lineDash && (style.lineDash = lineDash);
  10232. return style;
  10233. },
  10234. getLineDash: function (lineWidth) {
  10235. if (lineWidth == null) {
  10236. lineWidth = 1;
  10237. }
  10238. var lineType = this.get('type');
  10239. var dotSize = Math.max(lineWidth, 2);
  10240. var dashSize = lineWidth * 4;
  10241. return (lineType === 'solid' || lineType == null) ? null
  10242. : (lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize]);
  10243. }
  10244. };
  10245. var getAreaStyle = makeStyleMapper(
  10246. [
  10247. ['fill', 'color'],
  10248. ['shadowBlur'],
  10249. ['shadowOffsetX'],
  10250. ['shadowOffsetY'],
  10251. ['opacity'],
  10252. ['shadowColor']
  10253. ]
  10254. );
  10255. var areaStyleMixin = {
  10256. getAreaStyle: function (excludes, includes) {
  10257. return getAreaStyle(this, excludes, includes);
  10258. }
  10259. };
  10260. /**
  10261. * 曲线辅助模块
  10262. * @module zrender/core/curve
  10263. * @author pissang(https://www.github.com/pissang)
  10264. */
  10265. var mathPow = Math.pow;
  10266. var mathSqrt$2 = Math.sqrt;
  10267. var EPSILON$1 = 1e-8;
  10268. var EPSILON_NUMERIC = 1e-4;
  10269. var THREE_SQRT = mathSqrt$2(3);
  10270. var ONE_THIRD = 1 / 3;
  10271. // 临时变量
  10272. var _v0 = create();
  10273. var _v1 = create();
  10274. var _v2 = create();
  10275. function isAroundZero(val) {
  10276. return val > -EPSILON$1 && val < EPSILON$1;
  10277. }
  10278. function isNotAroundZero$1(val) {
  10279. return val > EPSILON$1 || val < -EPSILON$1;
  10280. }
  10281. /**
  10282. * 计算三次贝塞尔值
  10283. * @memberOf module:zrender/core/curve
  10284. * @param {number} p0
  10285. * @param {number} p1
  10286. * @param {number} p2
  10287. * @param {number} p3
  10288. * @param {number} t
  10289. * @return {number}
  10290. */
  10291. function cubicAt(p0, p1, p2, p3, t) {
  10292. var onet = 1 - t;
  10293. return onet * onet * (onet * p0 + 3 * t * p1)
  10294. + t * t * (t * p3 + 3 * onet * p2);
  10295. }
  10296. /**
  10297. * 计算三次贝塞尔导数值
  10298. * @memberOf module:zrender/core/curve
  10299. * @param {number} p0
  10300. * @param {number} p1
  10301. * @param {number} p2
  10302. * @param {number} p3
  10303. * @param {number} t
  10304. * @return {number}
  10305. */
  10306. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10307. var onet = 1 - t;
  10308. return 3 * (
  10309. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10310. + (p3 - p2) * t * t
  10311. );
  10312. }
  10313. /**
  10314. * 计算三次贝塞尔方程根,使用盛金公式
  10315. * @memberOf module:zrender/core/curve
  10316. * @param {number} p0
  10317. * @param {number} p1
  10318. * @param {number} p2
  10319. * @param {number} p3
  10320. * @param {number} val
  10321. * @param {Array.<number>} roots
  10322. * @return {number} 有效根数目
  10323. */
  10324. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10325. // Evaluate roots of cubic functions
  10326. var a = p3 + 3 * (p1 - p2) - p0;
  10327. var b = 3 * (p2 - p1 * 2 + p0);
  10328. var c = 3 * (p1 - p0);
  10329. var d = p0 - val;
  10330. var A = b * b - 3 * a * c;
  10331. var B = b * c - 9 * a * d;
  10332. var C = c * c - 3 * b * d;
  10333. var n = 0;
  10334. if (isAroundZero(A) && isAroundZero(B)) {
  10335. if (isAroundZero(b)) {
  10336. roots[0] = 0;
  10337. }
  10338. else {
  10339. var t1 = -c / b; //t1, t2, t3, b is not zero
  10340. if (t1 >= 0 && t1 <= 1) {
  10341. roots[n++] = t1;
  10342. }
  10343. }
  10344. }
  10345. else {
  10346. var disc = B * B - 4 * A * C;
  10347. if (isAroundZero(disc)) {
  10348. var K = B / A;
  10349. var t1 = -b / a + K; // t1, a is not zero
  10350. var t2 = -K / 2; // t2, t3
  10351. if (t1 >= 0 && t1 <= 1) {
  10352. roots[n++] = t1;
  10353. }
  10354. if (t2 >= 0 && t2 <= 1) {
  10355. roots[n++] = t2;
  10356. }
  10357. }
  10358. else if (disc > 0) {
  10359. var discSqrt = mathSqrt$2(disc);
  10360. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10361. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10362. if (Y1 < 0) {
  10363. Y1 = -mathPow(-Y1, ONE_THIRD);
  10364. }
  10365. else {
  10366. Y1 = mathPow(Y1, ONE_THIRD);
  10367. }
  10368. if (Y2 < 0) {
  10369. Y2 = -mathPow(-Y2, ONE_THIRD);
  10370. }
  10371. else {
  10372. Y2 = mathPow(Y2, ONE_THIRD);
  10373. }
  10374. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10375. if (t1 >= 0 && t1 <= 1) {
  10376. roots[n++] = t1;
  10377. }
  10378. }
  10379. else {
  10380. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  10381. var theta = Math.acos(T) / 3;
  10382. var ASqrt = mathSqrt$2(A);
  10383. var tmp = Math.cos(theta);
  10384. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10385. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10386. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10387. if (t1 >= 0 && t1 <= 1) {
  10388. roots[n++] = t1;
  10389. }
  10390. if (t2 >= 0 && t2 <= 1) {
  10391. roots[n++] = t2;
  10392. }
  10393. if (t3 >= 0 && t3 <= 1) {
  10394. roots[n++] = t3;
  10395. }
  10396. }
  10397. }
  10398. return n;
  10399. }
  10400. /**
  10401. * 计算三次贝塞尔方程极限值的位置
  10402. * @memberOf module:zrender/core/curve
  10403. * @param {number} p0
  10404. * @param {number} p1
  10405. * @param {number} p2
  10406. * @param {number} p3
  10407. * @param {Array.<number>} extrema
  10408. * @return {number} 有效数目
  10409. */
  10410. function cubicExtrema(p0, p1, p2, p3, extrema) {
  10411. var b = 6 * p2 - 12 * p1 + 6 * p0;
  10412. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  10413. var c = 3 * p1 - 3 * p0;
  10414. var n = 0;
  10415. if (isAroundZero(a)) {
  10416. if (isNotAroundZero$1(b)) {
  10417. var t1 = -c / b;
  10418. if (t1 >= 0 && t1 <=1) {
  10419. extrema[n++] = t1;
  10420. }
  10421. }
  10422. }
  10423. else {
  10424. var disc = b * b - 4 * a * c;
  10425. if (isAroundZero(disc)) {
  10426. extrema[0] = -b / (2 * a);
  10427. }
  10428. else if (disc > 0) {
  10429. var discSqrt = mathSqrt$2(disc);
  10430. var t1 = (-b + discSqrt) / (2 * a);
  10431. var t2 = (-b - discSqrt) / (2 * a);
  10432. if (t1 >= 0 && t1 <= 1) {
  10433. extrema[n++] = t1;
  10434. }
  10435. if (t2 >= 0 && t2 <= 1) {
  10436. extrema[n++] = t2;
  10437. }
  10438. }
  10439. }
  10440. return n;
  10441. }
  10442. /**
  10443. * 细分三次贝塞尔曲线
  10444. * @memberOf module:zrender/core/curve
  10445. * @param {number} p0
  10446. * @param {number} p1
  10447. * @param {number} p2
  10448. * @param {number} p3
  10449. * @param {number} t
  10450. * @param {Array.<number>} out
  10451. */
  10452. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  10453. var p01 = (p1 - p0) * t + p0;
  10454. var p12 = (p2 - p1) * t + p1;
  10455. var p23 = (p3 - p2) * t + p2;
  10456. var p012 = (p12 - p01) * t + p01;
  10457. var p123 = (p23 - p12) * t + p12;
  10458. var p0123 = (p123 - p012) * t + p012;
  10459. // Seg0
  10460. out[0] = p0;
  10461. out[1] = p01;
  10462. out[2] = p012;
  10463. out[3] = p0123;
  10464. // Seg1
  10465. out[4] = p0123;
  10466. out[5] = p123;
  10467. out[6] = p23;
  10468. out[7] = p3;
  10469. }
  10470. /**
  10471. * 投射点到三次贝塞尔曲线上,返回投射距离。
  10472. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10473. * @param {number} x0
  10474. * @param {number} y0
  10475. * @param {number} x1
  10476. * @param {number} y1
  10477. * @param {number} x2
  10478. * @param {number} y2
  10479. * @param {number} x3
  10480. * @param {number} y3
  10481. * @param {number} x
  10482. * @param {number} y
  10483. * @param {Array.<number>} [out] 投射点
  10484. * @return {number}
  10485. */
  10486. function cubicProjectPoint(
  10487. x0, y0, x1, y1, x2, y2, x3, y3,
  10488. x, y, out
  10489. ) {
  10490. // http://pomax.github.io/bezierinfo/#projections
  10491. var t;
  10492. var interval = 0.005;
  10493. var d = Infinity;
  10494. var prev;
  10495. var next;
  10496. var d1;
  10497. var d2;
  10498. _v0[0] = x;
  10499. _v0[1] = y;
  10500. // 先粗略估计一下可能的最小距离的 t 值
  10501. // PENDING
  10502. for (var _t = 0; _t < 1; _t += 0.05) {
  10503. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  10504. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  10505. d1 = distSquare(_v0, _v1);
  10506. if (d1 < d) {
  10507. t = _t;
  10508. d = d1;
  10509. }
  10510. }
  10511. d = Infinity;
  10512. // At most 32 iteration
  10513. for (var i = 0; i < 32; i++) {
  10514. if (interval < EPSILON_NUMERIC) {
  10515. break;
  10516. }
  10517. prev = t - interval;
  10518. next = t + interval;
  10519. // t - interval
  10520. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  10521. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  10522. d1 = distSquare(_v1, _v0);
  10523. if (prev >= 0 && d1 < d) {
  10524. t = prev;
  10525. d = d1;
  10526. }
  10527. else {
  10528. // t + interval
  10529. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  10530. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  10531. d2 = distSquare(_v2, _v0);
  10532. if (next <= 1 && d2 < d) {
  10533. t = next;
  10534. d = d2;
  10535. }
  10536. else {
  10537. interval *= 0.5;
  10538. }
  10539. }
  10540. }
  10541. // t
  10542. if (out) {
  10543. out[0] = cubicAt(x0, x1, x2, x3, t);
  10544. out[1] = cubicAt(y0, y1, y2, y3, t);
  10545. }
  10546. // console.log(interval, i);
  10547. return mathSqrt$2(d);
  10548. }
  10549. /**
  10550. * 计算二次方贝塞尔值
  10551. * @param {number} p0
  10552. * @param {number} p1
  10553. * @param {number} p2
  10554. * @param {number} t
  10555. * @return {number}
  10556. */
  10557. function quadraticAt(p0, p1, p2, t) {
  10558. var onet = 1 - t;
  10559. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  10560. }
  10561. /**
  10562. * 计算二次方贝塞尔导数值
  10563. * @param {number} p0
  10564. * @param {number} p1
  10565. * @param {number} p2
  10566. * @param {number} t
  10567. * @return {number}
  10568. */
  10569. function quadraticDerivativeAt(p0, p1, p2, t) {
  10570. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  10571. }
  10572. /**
  10573. * 计算二次方贝塞尔方程根
  10574. * @param {number} p0
  10575. * @param {number} p1
  10576. * @param {number} p2
  10577. * @param {number} t
  10578. * @param {Array.<number>} roots
  10579. * @return {number} 有效根数目
  10580. */
  10581. function quadraticRootAt(p0, p1, p2, val, roots) {
  10582. var a = p0 - 2 * p1 + p2;
  10583. var b = 2 * (p1 - p0);
  10584. var c = p0 - val;
  10585. var n = 0;
  10586. if (isAroundZero(a)) {
  10587. if (isNotAroundZero$1(b)) {
  10588. var t1 = -c / b;
  10589. if (t1 >= 0 && t1 <= 1) {
  10590. roots[n++] = t1;
  10591. }
  10592. }
  10593. }
  10594. else {
  10595. var disc = b * b - 4 * a * c;
  10596. if (isAroundZero(disc)) {
  10597. var t1 = -b / (2 * a);
  10598. if (t1 >= 0 && t1 <= 1) {
  10599. roots[n++] = t1;
  10600. }
  10601. }
  10602. else if (disc > 0) {
  10603. var discSqrt = mathSqrt$2(disc);
  10604. var t1 = (-b + discSqrt) / (2 * a);
  10605. var t2 = (-b - discSqrt) / (2 * a);
  10606. if (t1 >= 0 && t1 <= 1) {
  10607. roots[n++] = t1;
  10608. }
  10609. if (t2 >= 0 && t2 <= 1) {
  10610. roots[n++] = t2;
  10611. }
  10612. }
  10613. }
  10614. return n;
  10615. }
  10616. /**
  10617. * 计算二次贝塞尔方程极限值
  10618. * @memberOf module:zrender/core/curve
  10619. * @param {number} p0
  10620. * @param {number} p1
  10621. * @param {number} p2
  10622. * @return {number}
  10623. */
  10624. function quadraticExtremum(p0, p1, p2) {
  10625. var divider = p0 + p2 - 2 * p1;
  10626. if (divider === 0) {
  10627. // p1 is center of p0 and p2
  10628. return 0.5;
  10629. }
  10630. else {
  10631. return (p0 - p1) / divider;
  10632. }
  10633. }
  10634. /**
  10635. * 细分二次贝塞尔曲线
  10636. * @memberOf module:zrender/core/curve
  10637. * @param {number} p0
  10638. * @param {number} p1
  10639. * @param {number} p2
  10640. * @param {number} t
  10641. * @param {Array.<number>} out
  10642. */
  10643. function quadraticSubdivide(p0, p1, p2, t, out) {
  10644. var p01 = (p1 - p0) * t + p0;
  10645. var p12 = (p2 - p1) * t + p1;
  10646. var p012 = (p12 - p01) * t + p01;
  10647. // Seg0
  10648. out[0] = p0;
  10649. out[1] = p01;
  10650. out[2] = p012;
  10651. // Seg1
  10652. out[3] = p012;
  10653. out[4] = p12;
  10654. out[5] = p2;
  10655. }
  10656. /**
  10657. * 投射点到二次贝塞尔曲线上,返回投射距离。
  10658. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10659. * @param {number} x0
  10660. * @param {number} y0
  10661. * @param {number} x1
  10662. * @param {number} y1
  10663. * @param {number} x2
  10664. * @param {number} y2
  10665. * @param {number} x
  10666. * @param {number} y
  10667. * @param {Array.<number>} out 投射点
  10668. * @return {number}
  10669. */
  10670. function quadraticProjectPoint(
  10671. x0, y0, x1, y1, x2, y2,
  10672. x, y, out
  10673. ) {
  10674. // http://pomax.github.io/bezierinfo/#projections
  10675. var t;
  10676. var interval = 0.005;
  10677. var d = Infinity;
  10678. _v0[0] = x;
  10679. _v0[1] = y;
  10680. // 先粗略估计一下可能的最小距离的 t 值
  10681. // PENDING
  10682. for (var _t = 0; _t < 1; _t += 0.05) {
  10683. _v1[0] = quadraticAt(x0, x1, x2, _t);
  10684. _v1[1] = quadraticAt(y0, y1, y2, _t);
  10685. var d1 = distSquare(_v0, _v1);
  10686. if (d1 < d) {
  10687. t = _t;
  10688. d = d1;
  10689. }
  10690. }
  10691. d = Infinity;
  10692. // At most 32 iteration
  10693. for (var i = 0; i < 32; i++) {
  10694. if (interval < EPSILON_NUMERIC) {
  10695. break;
  10696. }
  10697. var prev = t - interval;
  10698. var next = t + interval;
  10699. // t - interval
  10700. _v1[0] = quadraticAt(x0, x1, x2, prev);
  10701. _v1[1] = quadraticAt(y0, y1, y2, prev);
  10702. var d1 = distSquare(_v1, _v0);
  10703. if (prev >= 0 && d1 < d) {
  10704. t = prev;
  10705. d = d1;
  10706. }
  10707. else {
  10708. // t + interval
  10709. _v2[0] = quadraticAt(x0, x1, x2, next);
  10710. _v2[1] = quadraticAt(y0, y1, y2, next);
  10711. var d2 = distSquare(_v2, _v0);
  10712. if (next <= 1 && d2 < d) {
  10713. t = next;
  10714. d = d2;
  10715. }
  10716. else {
  10717. interval *= 0.5;
  10718. }
  10719. }
  10720. }
  10721. // t
  10722. if (out) {
  10723. out[0] = quadraticAt(x0, x1, x2, t);
  10724. out[1] = quadraticAt(y0, y1, y2, t);
  10725. }
  10726. // console.log(interval, i);
  10727. return mathSqrt$2(d);
  10728. }
  10729. /**
  10730. * @author Yi Shen(https://github.com/pissang)
  10731. */
  10732. var mathMin$3 = Math.min;
  10733. var mathMax$3 = Math.max;
  10734. var mathSin$2 = Math.sin;
  10735. var mathCos$2 = Math.cos;
  10736. var PI2 = Math.PI * 2;
  10737. var start = create();
  10738. var end = create();
  10739. var extremity = create();
  10740. /**
  10741. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  10742. * @module zrender/core/bbox
  10743. * @param {Array<Object>} points 顶点数组
  10744. * @param {number} min
  10745. * @param {number} max
  10746. */
  10747. function fromPoints(points, min$$1, max$$1) {
  10748. if (points.length === 0) {
  10749. return;
  10750. }
  10751. var p = points[0];
  10752. var left = p[0];
  10753. var right = p[0];
  10754. var top = p[1];
  10755. var bottom = p[1];
  10756. var i;
  10757. for (i = 1; i < points.length; i++) {
  10758. p = points[i];
  10759. left = mathMin$3(left, p[0]);
  10760. right = mathMax$3(right, p[0]);
  10761. top = mathMin$3(top, p[1]);
  10762. bottom = mathMax$3(bottom, p[1]);
  10763. }
  10764. min$$1[0] = left;
  10765. min$$1[1] = top;
  10766. max$$1[0] = right;
  10767. max$$1[1] = bottom;
  10768. }
  10769. /**
  10770. * @memberOf module:zrender/core/bbox
  10771. * @param {number} x0
  10772. * @param {number} y0
  10773. * @param {number} x1
  10774. * @param {number} y1
  10775. * @param {Array.<number>} min
  10776. * @param {Array.<number>} max
  10777. */
  10778. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  10779. min$$1[0] = mathMin$3(x0, x1);
  10780. min$$1[1] = mathMin$3(y0, y1);
  10781. max$$1[0] = mathMax$3(x0, x1);
  10782. max$$1[1] = mathMax$3(y0, y1);
  10783. }
  10784. var xDim = [];
  10785. var yDim = [];
  10786. /**
  10787. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  10788. * @memberOf module:zrender/core/bbox
  10789. * @param {number} x0
  10790. * @param {number} y0
  10791. * @param {number} x1
  10792. * @param {number} y1
  10793. * @param {number} x2
  10794. * @param {number} y2
  10795. * @param {number} x3
  10796. * @param {number} y3
  10797. * @param {Array.<number>} min
  10798. * @param {Array.<number>} max
  10799. */
  10800. function fromCubic(
  10801. x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1
  10802. ) {
  10803. var cubicExtrema$$1 = cubicExtrema;
  10804. var cubicAt$$1 = cubicAt;
  10805. var i;
  10806. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  10807. min$$1[0] = Infinity;
  10808. min$$1[1] = Infinity;
  10809. max$$1[0] = -Infinity;
  10810. max$$1[1] = -Infinity;
  10811. for (i = 0; i < n; i++) {
  10812. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  10813. min$$1[0] = mathMin$3(x, min$$1[0]);
  10814. max$$1[0] = mathMax$3(x, max$$1[0]);
  10815. }
  10816. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  10817. for (i = 0; i < n; i++) {
  10818. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  10819. min$$1[1] = mathMin$3(y, min$$1[1]);
  10820. max$$1[1] = mathMax$3(y, max$$1[1]);
  10821. }
  10822. min$$1[0] = mathMin$3(x0, min$$1[0]);
  10823. max$$1[0] = mathMax$3(x0, max$$1[0]);
  10824. min$$1[0] = mathMin$3(x3, min$$1[0]);
  10825. max$$1[0] = mathMax$3(x3, max$$1[0]);
  10826. min$$1[1] = mathMin$3(y0, min$$1[1]);
  10827. max$$1[1] = mathMax$3(y0, max$$1[1]);
  10828. min$$1[1] = mathMin$3(y3, min$$1[1]);
  10829. max$$1[1] = mathMax$3(y3, max$$1[1]);
  10830. }
  10831. /**
  10832. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  10833. * @memberOf module:zrender/core/bbox
  10834. * @param {number} x0
  10835. * @param {number} y0
  10836. * @param {number} x1
  10837. * @param {number} y1
  10838. * @param {number} x2
  10839. * @param {number} y2
  10840. * @param {Array.<number>} min
  10841. * @param {Array.<number>} max
  10842. */
  10843. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  10844. var quadraticExtremum$$1 = quadraticExtremum;
  10845. var quadraticAt$$1 = quadraticAt;
  10846. // Find extremities, where derivative in x dim or y dim is zero
  10847. var tx =
  10848. mathMax$3(
  10849. mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0
  10850. );
  10851. var ty =
  10852. mathMax$3(
  10853. mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0
  10854. );
  10855. var x = quadraticAt$$1(x0, x1, x2, tx);
  10856. var y = quadraticAt$$1(y0, y1, y2, ty);
  10857. min$$1[0] = mathMin$3(x0, x2, x);
  10858. min$$1[1] = mathMin$3(y0, y2, y);
  10859. max$$1[0] = mathMax$3(x0, x2, x);
  10860. max$$1[1] = mathMax$3(y0, y2, y);
  10861. }
  10862. /**
  10863. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  10864. * @method
  10865. * @memberOf module:zrender/core/bbox
  10866. * @param {number} x
  10867. * @param {number} y
  10868. * @param {number} rx
  10869. * @param {number} ry
  10870. * @param {number} startAngle
  10871. * @param {number} endAngle
  10872. * @param {number} anticlockwise
  10873. * @param {Array.<number>} min
  10874. * @param {Array.<number>} max
  10875. */
  10876. function fromArc(
  10877. x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1
  10878. ) {
  10879. var vec2Min = min;
  10880. var vec2Max = max;
  10881. var diff = Math.abs(startAngle - endAngle);
  10882. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  10883. // Is a circle
  10884. min$$1[0] = x - rx;
  10885. min$$1[1] = y - ry;
  10886. max$$1[0] = x + rx;
  10887. max$$1[1] = y + ry;
  10888. return;
  10889. }
  10890. start[0] = mathCos$2(startAngle) * rx + x;
  10891. start[1] = mathSin$2(startAngle) * ry + y;
  10892. end[0] = mathCos$2(endAngle) * rx + x;
  10893. end[1] = mathSin$2(endAngle) * ry + y;
  10894. vec2Min(min$$1, start, end);
  10895. vec2Max(max$$1, start, end);
  10896. // Thresh to [0, Math.PI * 2]
  10897. startAngle = startAngle % (PI2);
  10898. if (startAngle < 0) {
  10899. startAngle = startAngle + PI2;
  10900. }
  10901. endAngle = endAngle % (PI2);
  10902. if (endAngle < 0) {
  10903. endAngle = endAngle + PI2;
  10904. }
  10905. if (startAngle > endAngle && !anticlockwise) {
  10906. endAngle += PI2;
  10907. }
  10908. else if (startAngle < endAngle && anticlockwise) {
  10909. startAngle += PI2;
  10910. }
  10911. if (anticlockwise) {
  10912. var tmp = endAngle;
  10913. endAngle = startAngle;
  10914. startAngle = tmp;
  10915. }
  10916. // var number = 0;
  10917. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  10918. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  10919. if (angle > startAngle) {
  10920. extremity[0] = mathCos$2(angle) * rx + x;
  10921. extremity[1] = mathSin$2(angle) * ry + y;
  10922. vec2Min(min$$1, extremity, min$$1);
  10923. vec2Max(max$$1, extremity, max$$1);
  10924. }
  10925. }
  10926. }
  10927. /**
  10928. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  10929. * 可以用于 isInsidePath 判断以及获取boundingRect
  10930. *
  10931. * @module zrender/core/PathProxy
  10932. * @author Yi Shen (http://www.github.com/pissang)
  10933. */
  10934. // TODO getTotalLength, getPointAtLength
  10935. var CMD = {
  10936. M: 1,
  10937. L: 2,
  10938. C: 3,
  10939. Q: 4,
  10940. A: 5,
  10941. Z: 6,
  10942. // Rect
  10943. R: 7
  10944. };
  10945. // var CMD_MEM_SIZE = {
  10946. // M: 3,
  10947. // L: 3,
  10948. // C: 7,
  10949. // Q: 5,
  10950. // A: 9,
  10951. // R: 5,
  10952. // Z: 1
  10953. // };
  10954. var min$1 = [];
  10955. var max$1 = [];
  10956. var min2 = [];
  10957. var max2 = [];
  10958. var mathMin$2 = Math.min;
  10959. var mathMax$2 = Math.max;
  10960. var mathCos$1 = Math.cos;
  10961. var mathSin$1 = Math.sin;
  10962. var mathSqrt$1 = Math.sqrt;
  10963. var mathAbs = Math.abs;
  10964. var hasTypedArray = typeof Float32Array != 'undefined';
  10965. /**
  10966. * @alias module:zrender/core/PathProxy
  10967. * @constructor
  10968. */
  10969. var PathProxy = function (notSaveData) {
  10970. this._saveData = !(notSaveData || false);
  10971. if (this._saveData) {
  10972. /**
  10973. * Path data. Stored as flat array
  10974. * @type {Array.<Object>}
  10975. */
  10976. this.data = [];
  10977. }
  10978. this._ctx = null;
  10979. };
  10980. /**
  10981. * 快速计算Path包围盒(并不是最小包围盒)
  10982. * @return {Object}
  10983. */
  10984. PathProxy.prototype = {
  10985. constructor: PathProxy,
  10986. _xi: 0,
  10987. _yi: 0,
  10988. _x0: 0,
  10989. _y0: 0,
  10990. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  10991. _ux: 0,
  10992. _uy: 0,
  10993. _len: 0,
  10994. _lineDash: null,
  10995. _dashOffset: 0,
  10996. _dashIdx: 0,
  10997. _dashSum: 0,
  10998. /**
  10999. * @readOnly
  11000. */
  11001. setScale: function (sx, sy) {
  11002. this._ux = mathAbs(1 / devicePixelRatio / sx) || 0;
  11003. this._uy = mathAbs(1 / devicePixelRatio / sy) || 0;
  11004. },
  11005. getContext: function () {
  11006. return this._ctx;
  11007. },
  11008. /**
  11009. * @param {CanvasRenderingContext2D} ctx
  11010. * @return {module:zrender/core/PathProxy}
  11011. */
  11012. beginPath: function (ctx) {
  11013. this._ctx = ctx;
  11014. ctx && ctx.beginPath();
  11015. ctx && (this.dpr = ctx.dpr);
  11016. // Reset
  11017. if (this._saveData) {
  11018. this._len = 0;
  11019. }
  11020. if (this._lineDash) {
  11021. this._lineDash = null;
  11022. this._dashOffset = 0;
  11023. }
  11024. return this;
  11025. },
  11026. /**
  11027. * @param {number} x
  11028. * @param {number} y
  11029. * @return {module:zrender/core/PathProxy}
  11030. */
  11031. moveTo: function (x, y) {
  11032. this.addData(CMD.M, x, y);
  11033. this._ctx && this._ctx.moveTo(x, y);
  11034. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11035. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11036. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11037. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11038. this._x0 = x;
  11039. this._y0 = y;
  11040. this._xi = x;
  11041. this._yi = y;
  11042. return this;
  11043. },
  11044. /**
  11045. * @param {number} x
  11046. * @param {number} y
  11047. * @return {module:zrender/core/PathProxy}
  11048. */
  11049. lineTo: function (x, y) {
  11050. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11051. || mathAbs(y - this._yi) > this._uy
  11052. // Force draw the first segment
  11053. || this._len < 5;
  11054. this.addData(CMD.L, x, y);
  11055. if (this._ctx && exceedUnit) {
  11056. this._needsDash() ? this._dashedLineTo(x, y)
  11057. : this._ctx.lineTo(x, y);
  11058. }
  11059. if (exceedUnit) {
  11060. this._xi = x;
  11061. this._yi = y;
  11062. }
  11063. return this;
  11064. },
  11065. /**
  11066. * @param {number} x1
  11067. * @param {number} y1
  11068. * @param {number} x2
  11069. * @param {number} y2
  11070. * @param {number} x3
  11071. * @param {number} y3
  11072. * @return {module:zrender/core/PathProxy}
  11073. */
  11074. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11075. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11076. if (this._ctx) {
  11077. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11078. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11079. }
  11080. this._xi = x3;
  11081. this._yi = y3;
  11082. return this;
  11083. },
  11084. /**
  11085. * @param {number} x1
  11086. * @param {number} y1
  11087. * @param {number} x2
  11088. * @param {number} y2
  11089. * @return {module:zrender/core/PathProxy}
  11090. */
  11091. quadraticCurveTo: function (x1, y1, x2, y2) {
  11092. this.addData(CMD.Q, x1, y1, x2, y2);
  11093. if (this._ctx) {
  11094. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11095. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11096. }
  11097. this._xi = x2;
  11098. this._yi = y2;
  11099. return this;
  11100. },
  11101. /**
  11102. * @param {number} cx
  11103. * @param {number} cy
  11104. * @param {number} r
  11105. * @param {number} startAngle
  11106. * @param {number} endAngle
  11107. * @param {boolean} anticlockwise
  11108. * @return {module:zrender/core/PathProxy}
  11109. */
  11110. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11111. this.addData(
  11112. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11113. );
  11114. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11115. this._xi = mathCos$1(endAngle) * r + cx;
  11116. this._yi = mathSin$1(endAngle) * r + cx;
  11117. return this;
  11118. },
  11119. // TODO
  11120. arcTo: function (x1, y1, x2, y2, radius) {
  11121. if (this._ctx) {
  11122. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11123. }
  11124. return this;
  11125. },
  11126. // TODO
  11127. rect: function (x, y, w, h) {
  11128. this._ctx && this._ctx.rect(x, y, w, h);
  11129. this.addData(CMD.R, x, y, w, h);
  11130. return this;
  11131. },
  11132. /**
  11133. * @return {module:zrender/core/PathProxy}
  11134. */
  11135. closePath: function () {
  11136. this.addData(CMD.Z);
  11137. var ctx = this._ctx;
  11138. var x0 = this._x0;
  11139. var y0 = this._y0;
  11140. if (ctx) {
  11141. this._needsDash() && this._dashedLineTo(x0, y0);
  11142. ctx.closePath();
  11143. }
  11144. this._xi = x0;
  11145. this._yi = y0;
  11146. return this;
  11147. },
  11148. /**
  11149. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11150. * stroke 同样
  11151. * @param {CanvasRenderingContext2D} ctx
  11152. * @return {module:zrender/core/PathProxy}
  11153. */
  11154. fill: function (ctx) {
  11155. ctx && ctx.fill();
  11156. this.toStatic();
  11157. },
  11158. /**
  11159. * @param {CanvasRenderingContext2D} ctx
  11160. * @return {module:zrender/core/PathProxy}
  11161. */
  11162. stroke: function (ctx) {
  11163. ctx && ctx.stroke();
  11164. this.toStatic();
  11165. },
  11166. /**
  11167. * 必须在其它绘制命令前调用
  11168. * Must be invoked before all other path drawing methods
  11169. * @return {module:zrender/core/PathProxy}
  11170. */
  11171. setLineDash: function (lineDash) {
  11172. if (lineDash instanceof Array) {
  11173. this._lineDash = lineDash;
  11174. this._dashIdx = 0;
  11175. var lineDashSum = 0;
  11176. for (var i = 0; i < lineDash.length; i++) {
  11177. lineDashSum += lineDash[i];
  11178. }
  11179. this._dashSum = lineDashSum;
  11180. }
  11181. return this;
  11182. },
  11183. /**
  11184. * 必须在其它绘制命令前调用
  11185. * Must be invoked before all other path drawing methods
  11186. * @return {module:zrender/core/PathProxy}
  11187. */
  11188. setLineDashOffset: function (offset) {
  11189. this._dashOffset = offset;
  11190. return this;
  11191. },
  11192. /**
  11193. *
  11194. * @return {boolean}
  11195. */
  11196. len: function () {
  11197. return this._len;
  11198. },
  11199. /**
  11200. * 直接设置 Path 数据
  11201. */
  11202. setData: function (data) {
  11203. var len$$1 = data.length;
  11204. if (! (this.data && this.data.length == len$$1) && hasTypedArray) {
  11205. this.data = new Float32Array(len$$1);
  11206. }
  11207. for (var i = 0; i < len$$1; i++) {
  11208. this.data[i] = data[i];
  11209. }
  11210. this._len = len$$1;
  11211. },
  11212. /**
  11213. * 添加子路径
  11214. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11215. */
  11216. appendPath: function (path) {
  11217. if (!(path instanceof Array)) {
  11218. path = [path];
  11219. }
  11220. var len$$1 = path.length;
  11221. var appendSize = 0;
  11222. var offset = this._len;
  11223. for (var i = 0; i < len$$1; i++) {
  11224. appendSize += path[i].len();
  11225. }
  11226. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11227. this.data = new Float32Array(offset + appendSize);
  11228. }
  11229. for (var i = 0; i < len$$1; i++) {
  11230. var appendPathData = path[i].data;
  11231. for (var k = 0; k < appendPathData.length; k++) {
  11232. this.data[offset++] = appendPathData[k];
  11233. }
  11234. }
  11235. this._len = offset;
  11236. },
  11237. /**
  11238. * 填充 Path 数据。
  11239. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11240. */
  11241. addData: function (cmd) {
  11242. if (!this._saveData) {
  11243. return;
  11244. }
  11245. var data = this.data;
  11246. if (this._len + arguments.length > data.length) {
  11247. // 因为之前的数组已经转换成静态的 Float32Array
  11248. // 所以不够用时需要扩展一个新的动态数组
  11249. this._expandData();
  11250. data = this.data;
  11251. }
  11252. for (var i = 0; i < arguments.length; i++) {
  11253. data[this._len++] = arguments[i];
  11254. }
  11255. this._prevCmd = cmd;
  11256. },
  11257. _expandData: function () {
  11258. // Only if data is Float32Array
  11259. if (!(this.data instanceof Array)) {
  11260. var newData = [];
  11261. for (var i = 0; i < this._len; i++) {
  11262. newData[i] = this.data[i];
  11263. }
  11264. this.data = newData;
  11265. }
  11266. },
  11267. /**
  11268. * If needs js implemented dashed line
  11269. * @return {boolean}
  11270. * @private
  11271. */
  11272. _needsDash: function () {
  11273. return this._lineDash;
  11274. },
  11275. _dashedLineTo: function (x1, y1) {
  11276. var dashSum = this._dashSum;
  11277. var offset = this._dashOffset;
  11278. var lineDash = this._lineDash;
  11279. var ctx = this._ctx;
  11280. var x0 = this._xi;
  11281. var y0 = this._yi;
  11282. var dx = x1 - x0;
  11283. var dy = y1 - y0;
  11284. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11285. var x = x0;
  11286. var y = y0;
  11287. var dash;
  11288. var nDash = lineDash.length;
  11289. var idx;
  11290. dx /= dist$$1;
  11291. dy /= dist$$1;
  11292. if (offset < 0) {
  11293. // Convert to positive offset
  11294. offset = dashSum + offset;
  11295. }
  11296. offset %= dashSum;
  11297. x -= offset * dx;
  11298. y -= offset * dy;
  11299. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11300. || (dx == 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11301. idx = this._dashIdx;
  11302. dash = lineDash[idx];
  11303. x += dx * dash;
  11304. y += dy * dash;
  11305. this._dashIdx = (idx + 1) % nDash;
  11306. // Skip positive offset
  11307. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11308. continue;
  11309. }
  11310. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11311. dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1),
  11312. dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1)
  11313. );
  11314. }
  11315. // Offset for next lineTo
  11316. dx = x - x1;
  11317. dy = y - y1;
  11318. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11319. },
  11320. // Not accurate dashed line to
  11321. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11322. var dashSum = this._dashSum;
  11323. var offset = this._dashOffset;
  11324. var lineDash = this._lineDash;
  11325. var ctx = this._ctx;
  11326. var x0 = this._xi;
  11327. var y0 = this._yi;
  11328. var t;
  11329. var dx;
  11330. var dy;
  11331. var cubicAt$$1 = cubicAt;
  11332. var bezierLen = 0;
  11333. var idx = this._dashIdx;
  11334. var nDash = lineDash.length;
  11335. var x;
  11336. var y;
  11337. var tmpLen = 0;
  11338. if (offset < 0) {
  11339. // Convert to positive offset
  11340. offset = dashSum + offset;
  11341. }
  11342. offset %= dashSum;
  11343. // Bezier approx length
  11344. for (t = 0; t < 1; t += 0.1) {
  11345. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1)
  11346. - cubicAt$$1(x0, x1, x2, x3, t);
  11347. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1)
  11348. - cubicAt$$1(y0, y1, y2, y3, t);
  11349. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11350. }
  11351. // Find idx after add offset
  11352. for (; idx < nDash; idx++) {
  11353. tmpLen += lineDash[idx];
  11354. if (tmpLen > offset) {
  11355. break;
  11356. }
  11357. }
  11358. t = (tmpLen - offset) / bezierLen;
  11359. while (t <= 1) {
  11360. x = cubicAt$$1(x0, x1, x2, x3, t);
  11361. y = cubicAt$$1(y0, y1, y2, y3, t);
  11362. // Use line to approximate dashed bezier
  11363. // Bad result if dash is long
  11364. idx % 2 ? ctx.moveTo(x, y)
  11365. : ctx.lineTo(x, y);
  11366. t += lineDash[idx] / bezierLen;
  11367. idx = (idx + 1) % nDash;
  11368. }
  11369. // Finish the last segment and calculate the new offset
  11370. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  11371. dx = x3 - x;
  11372. dy = y3 - y;
  11373. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11374. },
  11375. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11376. // Convert quadratic to cubic using degree elevation
  11377. var x3 = x2;
  11378. var y3 = y2;
  11379. x2 = (x2 + 2 * x1) / 3;
  11380. y2 = (y2 + 2 * y1) / 3;
  11381. x1 = (this._xi + 2 * x1) / 3;
  11382. y1 = (this._yi + 2 * y1) / 3;
  11383. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11384. },
  11385. /**
  11386. * 转成静态的 Float32Array 减少堆内存占用
  11387. * Convert dynamic array to static Float32Array
  11388. */
  11389. toStatic: function () {
  11390. var data = this.data;
  11391. if (data instanceof Array) {
  11392. data.length = this._len;
  11393. if (hasTypedArray) {
  11394. this.data = new Float32Array(data);
  11395. }
  11396. }
  11397. },
  11398. /**
  11399. * @return {module:zrender/core/BoundingRect}
  11400. */
  11401. getBoundingRect: function () {
  11402. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11403. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11404. var data = this.data;
  11405. var xi = 0;
  11406. var yi = 0;
  11407. var x0 = 0;
  11408. var y0 = 0;
  11409. for (var i = 0; i < data.length;) {
  11410. var cmd = data[i++];
  11411. if (i == 1) {
  11412. // 如果第一个命令是 L, C, Q
  11413. // 则 previous point 同绘制命令的第一个 point
  11414. //
  11415. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11416. xi = data[i];
  11417. yi = data[i + 1];
  11418. x0 = xi;
  11419. y0 = yi;
  11420. }
  11421. switch (cmd) {
  11422. case CMD.M:
  11423. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11424. // 在 closePath 的时候使用
  11425. x0 = data[i++];
  11426. y0 = data[i++];
  11427. xi = x0;
  11428. yi = y0;
  11429. min2[0] = x0;
  11430. min2[1] = y0;
  11431. max2[0] = x0;
  11432. max2[1] = y0;
  11433. break;
  11434. case CMD.L:
  11435. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11436. xi = data[i++];
  11437. yi = data[i++];
  11438. break;
  11439. case CMD.C:
  11440. fromCubic(
  11441. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11442. min2, max2
  11443. );
  11444. xi = data[i++];
  11445. yi = data[i++];
  11446. break;
  11447. case CMD.Q:
  11448. fromQuadratic(
  11449. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  11450. min2, max2
  11451. );
  11452. xi = data[i++];
  11453. yi = data[i++];
  11454. break;
  11455. case CMD.A:
  11456. // TODO Arc 判断的开销比较大
  11457. var cx = data[i++];
  11458. var cy = data[i++];
  11459. var rx = data[i++];
  11460. var ry = data[i++];
  11461. var startAngle = data[i++];
  11462. var endAngle = data[i++] + startAngle;
  11463. // TODO Arc 旋转
  11464. var psi = data[i++];
  11465. var anticlockwise = 1 - data[i++];
  11466. if (i == 1) {
  11467. // 直接使用 arc 命令
  11468. // 第一个命令起点还未定义
  11469. x0 = mathCos$1(startAngle) * rx + cx;
  11470. y0 = mathSin$1(startAngle) * ry + cy;
  11471. }
  11472. fromArc(
  11473. cx, cy, rx, ry, startAngle, endAngle,
  11474. anticlockwise, min2, max2
  11475. );
  11476. xi = mathCos$1(endAngle) * rx + cx;
  11477. yi = mathSin$1(endAngle) * ry + cy;
  11478. break;
  11479. case CMD.R:
  11480. x0 = xi = data[i++];
  11481. y0 = yi = data[i++];
  11482. var width = data[i++];
  11483. var height = data[i++];
  11484. // Use fromLine
  11485. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  11486. break;
  11487. case CMD.Z:
  11488. xi = x0;
  11489. yi = y0;
  11490. break;
  11491. }
  11492. // Union
  11493. min(min$1, min$1, min2);
  11494. max(max$1, max$1, max2);
  11495. }
  11496. // No data
  11497. if (i === 0) {
  11498. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  11499. }
  11500. return new BoundingRect(
  11501. min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]
  11502. );
  11503. },
  11504. /**
  11505. * Rebuild path from current data
  11506. * Rebuild path will not consider javascript implemented line dash.
  11507. * @param {CanvasRenderingContext2D} ctx
  11508. */
  11509. rebuildPath: function (ctx) {
  11510. var d = this.data;
  11511. var x0, y0;
  11512. var xi, yi;
  11513. var x, y;
  11514. var ux = this._ux;
  11515. var uy = this._uy;
  11516. var len$$1 = this._len;
  11517. for (var i = 0; i < len$$1;) {
  11518. var cmd = d[i++];
  11519. if (i == 1) {
  11520. // 如果第一个命令是 L, C, Q
  11521. // 则 previous point 同绘制命令的第一个 point
  11522. //
  11523. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11524. xi = d[i];
  11525. yi = d[i + 1];
  11526. x0 = xi;
  11527. y0 = yi;
  11528. }
  11529. switch (cmd) {
  11530. case CMD.M:
  11531. x0 = xi = d[i++];
  11532. y0 = yi = d[i++];
  11533. ctx.moveTo(xi, yi);
  11534. break;
  11535. case CMD.L:
  11536. x = d[i++];
  11537. y = d[i++];
  11538. // Not draw too small seg between
  11539. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  11540. ctx.lineTo(x, y);
  11541. xi = x;
  11542. yi = y;
  11543. }
  11544. break;
  11545. case CMD.C:
  11546. ctx.bezierCurveTo(
  11547. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  11548. );
  11549. xi = d[i - 2];
  11550. yi = d[i - 1];
  11551. break;
  11552. case CMD.Q:
  11553. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  11554. xi = d[i - 2];
  11555. yi = d[i - 1];
  11556. break;
  11557. case CMD.A:
  11558. var cx = d[i++];
  11559. var cy = d[i++];
  11560. var rx = d[i++];
  11561. var ry = d[i++];
  11562. var theta = d[i++];
  11563. var dTheta = d[i++];
  11564. var psi = d[i++];
  11565. var fs = d[i++];
  11566. var r = (rx > ry) ? rx : ry;
  11567. var scaleX = (rx > ry) ? 1 : rx / ry;
  11568. var scaleY = (rx > ry) ? ry / rx : 1;
  11569. var isEllipse = Math.abs(rx - ry) > 1e-3;
  11570. var endAngle = theta + dTheta;
  11571. if (isEllipse) {
  11572. ctx.translate(cx, cy);
  11573. ctx.rotate(psi);
  11574. ctx.scale(scaleX, scaleY);
  11575. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  11576. ctx.scale(1 / scaleX, 1 / scaleY);
  11577. ctx.rotate(-psi);
  11578. ctx.translate(-cx, -cy);
  11579. }
  11580. else {
  11581. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  11582. }
  11583. if (i == 1) {
  11584. // 直接使用 arc 命令
  11585. // 第一个命令起点还未定义
  11586. x0 = mathCos$1(theta) * rx + cx;
  11587. y0 = mathSin$1(theta) * ry + cy;
  11588. }
  11589. xi = mathCos$1(endAngle) * rx + cx;
  11590. yi = mathSin$1(endAngle) * ry + cy;
  11591. break;
  11592. case CMD.R:
  11593. x0 = xi = d[i];
  11594. y0 = yi = d[i + 1];
  11595. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  11596. break;
  11597. case CMD.Z:
  11598. ctx.closePath();
  11599. xi = x0;
  11600. yi = y0;
  11601. }
  11602. }
  11603. }
  11604. };
  11605. PathProxy.CMD = CMD;
  11606. /**
  11607. * 线段包含判断
  11608. * @param {number} x0
  11609. * @param {number} y0
  11610. * @param {number} x1
  11611. * @param {number} y1
  11612. * @param {number} lineWidth
  11613. * @param {number} x
  11614. * @param {number} y
  11615. * @return {boolean}
  11616. */
  11617. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  11618. if (lineWidth === 0) {
  11619. return false;
  11620. }
  11621. var _l = lineWidth;
  11622. var _a = 0;
  11623. var _b = x0;
  11624. // Quick reject
  11625. if (
  11626. (y > y0 + _l && y > y1 + _l)
  11627. || (y < y0 - _l && y < y1 - _l)
  11628. || (x > x0 + _l && x > x1 + _l)
  11629. || (x < x0 - _l && x < x1 - _l)
  11630. ) {
  11631. return false;
  11632. }
  11633. if (x0 !== x1) {
  11634. _a = (y0 - y1) / (x0 - x1);
  11635. _b = (x0 * y1 - x1 * y0) / (x0 - x1) ;
  11636. }
  11637. else {
  11638. return Math.abs(x - x0) <= _l / 2;
  11639. }
  11640. var tmp = _a * x - y + _b;
  11641. var _s = tmp * tmp / (_a * _a + 1);
  11642. return _s <= _l / 2 * _l / 2;
  11643. }
  11644. /**
  11645. * 三次贝塞尔曲线描边包含判断
  11646. * @param {number} x0
  11647. * @param {number} y0
  11648. * @param {number} x1
  11649. * @param {number} y1
  11650. * @param {number} x2
  11651. * @param {number} y2
  11652. * @param {number} x3
  11653. * @param {number} y3
  11654. * @param {number} lineWidth
  11655. * @param {number} x
  11656. * @param {number} y
  11657. * @return {boolean}
  11658. */
  11659. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11660. if (lineWidth === 0) {
  11661. return false;
  11662. }
  11663. var _l = lineWidth;
  11664. // Quick reject
  11665. if (
  11666. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  11667. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  11668. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  11669. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  11670. ) {
  11671. return false;
  11672. }
  11673. var d = cubicProjectPoint(
  11674. x0, y0, x1, y1, x2, y2, x3, y3,
  11675. x, y, null
  11676. );
  11677. return d <= _l / 2;
  11678. }
  11679. /**
  11680. * 二次贝塞尔曲线描边包含判断
  11681. * @param {number} x0
  11682. * @param {number} y0
  11683. * @param {number} x1
  11684. * @param {number} y1
  11685. * @param {number} x2
  11686. * @param {number} y2
  11687. * @param {number} lineWidth
  11688. * @param {number} x
  11689. * @param {number} y
  11690. * @return {boolean}
  11691. */
  11692. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  11693. if (lineWidth === 0) {
  11694. return false;
  11695. }
  11696. var _l = lineWidth;
  11697. // Quick reject
  11698. if (
  11699. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  11700. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  11701. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  11702. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  11703. ) {
  11704. return false;
  11705. }
  11706. var d = quadraticProjectPoint(
  11707. x0, y0, x1, y1, x2, y2,
  11708. x, y, null
  11709. );
  11710. return d <= _l / 2;
  11711. }
  11712. var PI2$3 = Math.PI * 2;
  11713. function normalizeRadian(angle) {
  11714. angle %= PI2$3;
  11715. if (angle < 0) {
  11716. angle += PI2$3;
  11717. }
  11718. return angle;
  11719. }
  11720. var PI2$2 = Math.PI * 2;
  11721. /**
  11722. * 圆弧描边包含判断
  11723. * @param {number} cx
  11724. * @param {number} cy
  11725. * @param {number} r
  11726. * @param {number} startAngle
  11727. * @param {number} endAngle
  11728. * @param {boolean} anticlockwise
  11729. * @param {number} lineWidth
  11730. * @param {number} x
  11731. * @param {number} y
  11732. * @return {Boolean}
  11733. */
  11734. function containStroke$4(
  11735. cx, cy, r, startAngle, endAngle, anticlockwise,
  11736. lineWidth, x, y
  11737. ) {
  11738. if (lineWidth === 0) {
  11739. return false;
  11740. }
  11741. var _l = lineWidth;
  11742. x -= cx;
  11743. y -= cy;
  11744. var d = Math.sqrt(x * x + y * y);
  11745. if ((d - _l > r) || (d + _l < r)) {
  11746. return false;
  11747. }
  11748. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  11749. // Is a circle
  11750. return true;
  11751. }
  11752. if (anticlockwise) {
  11753. var tmp = startAngle;
  11754. startAngle = normalizeRadian(endAngle);
  11755. endAngle = normalizeRadian(tmp);
  11756. } else {
  11757. startAngle = normalizeRadian(startAngle);
  11758. endAngle = normalizeRadian(endAngle);
  11759. }
  11760. if (startAngle > endAngle) {
  11761. endAngle += PI2$2;
  11762. }
  11763. var angle = Math.atan2(y, x);
  11764. if (angle < 0) {
  11765. angle += PI2$2;
  11766. }
  11767. return (angle >= startAngle && angle <= endAngle)
  11768. || (angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle);
  11769. }
  11770. function windingLine(x0, y0, x1, y1, x, y) {
  11771. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  11772. return 0;
  11773. }
  11774. // Ignore horizontal line
  11775. if (y1 === y0) {
  11776. return 0;
  11777. }
  11778. var dir = y1 < y0 ? 1 : -1;
  11779. var t = (y - y0) / (y1 - y0);
  11780. // Avoid winding error when intersection point is the connect point of two line of polygon
  11781. if (t === 1 || t === 0) {
  11782. dir = y1 < y0 ? 0.5 : -0.5;
  11783. }
  11784. var x_ = t * (x1 - x0) + x0;
  11785. return x_ > x ? dir : 0;
  11786. }
  11787. var CMD$1 = PathProxy.CMD;
  11788. var PI2$1 = Math.PI * 2;
  11789. var EPSILON$2 = 1e-4;
  11790. function isAroundEqual(a, b) {
  11791. return Math.abs(a - b) < EPSILON$2;
  11792. }
  11793. // 临时数组
  11794. var roots = [-1, -1, -1];
  11795. var extrema = [-1, -1];
  11796. function swapExtrema() {
  11797. var tmp = extrema[0];
  11798. extrema[0] = extrema[1];
  11799. extrema[1] = tmp;
  11800. }
  11801. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11802. // Quick reject
  11803. if (
  11804. (y > y0 && y > y1 && y > y2 && y > y3)
  11805. || (y < y0 && y < y1 && y < y2 && y < y3)
  11806. ) {
  11807. return 0;
  11808. }
  11809. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  11810. if (nRoots === 0) {
  11811. return 0;
  11812. }
  11813. else {
  11814. var w = 0;
  11815. var nExtrema = -1;
  11816. var y0_, y1_;
  11817. for (var i = 0; i < nRoots; i++) {
  11818. var t = roots[i];
  11819. // Avoid winding error when intersection point is the connect point of two line of polygon
  11820. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  11821. var x_ = cubicAt(x0, x1, x2, x3, t);
  11822. if (x_ < x) { // Quick reject
  11823. continue;
  11824. }
  11825. if (nExtrema < 0) {
  11826. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  11827. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11828. swapExtrema();
  11829. }
  11830. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  11831. if (nExtrema > 1) {
  11832. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  11833. }
  11834. }
  11835. if (nExtrema == 2) {
  11836. // 分成三段单调函数
  11837. if (t < extrema[0]) {
  11838. w += y0_ < y0 ? unit : -unit;
  11839. }
  11840. else if (t < extrema[1]) {
  11841. w += y1_ < y0_ ? unit : -unit;
  11842. }
  11843. else {
  11844. w += y3 < y1_ ? unit : -unit;
  11845. }
  11846. }
  11847. else {
  11848. // 分成两段单调函数
  11849. if (t < extrema[0]) {
  11850. w += y0_ < y0 ? unit : -unit;
  11851. }
  11852. else {
  11853. w += y3 < y0_ ? unit : -unit;
  11854. }
  11855. }
  11856. }
  11857. return w;
  11858. }
  11859. }
  11860. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11861. // Quick reject
  11862. if (
  11863. (y > y0 && y > y1 && y > y2)
  11864. || (y < y0 && y < y1 && y < y2)
  11865. ) {
  11866. return 0;
  11867. }
  11868. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  11869. if (nRoots === 0) {
  11870. return 0;
  11871. }
  11872. else {
  11873. var t = quadraticExtremum(y0, y1, y2);
  11874. if (t >= 0 && t <= 1) {
  11875. var w = 0;
  11876. var y_ = quadraticAt(y0, y1, y2, t);
  11877. for (var i = 0; i < nRoots; i++) {
  11878. // Remove one endpoint.
  11879. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  11880. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  11881. if (x_ < x) { // Quick reject
  11882. continue;
  11883. }
  11884. if (roots[i] < t) {
  11885. w += y_ < y0 ? unit : -unit;
  11886. }
  11887. else {
  11888. w += y2 < y_ ? unit : -unit;
  11889. }
  11890. }
  11891. return w;
  11892. }
  11893. else {
  11894. // Remove one endpoint.
  11895. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  11896. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  11897. if (x_ < x) { // Quick reject
  11898. return 0;
  11899. }
  11900. return y2 < y0 ? unit : -unit;
  11901. }
  11902. }
  11903. }
  11904. // TODO
  11905. // Arc 旋转
  11906. function windingArc(
  11907. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  11908. ) {
  11909. y -= cy;
  11910. if (y > r || y < -r) {
  11911. return 0;
  11912. }
  11913. var tmp = Math.sqrt(r * r - y * y);
  11914. roots[0] = -tmp;
  11915. roots[1] = tmp;
  11916. var diff = Math.abs(startAngle - endAngle);
  11917. if (diff < 1e-4) {
  11918. return 0;
  11919. }
  11920. if (diff % PI2$1 < 1e-4) {
  11921. // Is a circle
  11922. startAngle = 0;
  11923. endAngle = PI2$1;
  11924. var dir = anticlockwise ? 1 : -1;
  11925. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  11926. return dir;
  11927. } else {
  11928. return 0;
  11929. }
  11930. }
  11931. if (anticlockwise) {
  11932. var tmp = startAngle;
  11933. startAngle = normalizeRadian(endAngle);
  11934. endAngle = normalizeRadian(tmp);
  11935. }
  11936. else {
  11937. startAngle = normalizeRadian(startAngle);
  11938. endAngle = normalizeRadian(endAngle);
  11939. }
  11940. if (startAngle > endAngle) {
  11941. endAngle += PI2$1;
  11942. }
  11943. var w = 0;
  11944. for (var i = 0; i < 2; i++) {
  11945. var x_ = roots[i];
  11946. if (x_ + cx > x) {
  11947. var angle = Math.atan2(y, x_);
  11948. var dir = anticlockwise ? 1 : -1;
  11949. if (angle < 0) {
  11950. angle = PI2$1 + angle;
  11951. }
  11952. if (
  11953. (angle >= startAngle && angle <= endAngle)
  11954. || (angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle)
  11955. ) {
  11956. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  11957. dir = -dir;
  11958. }
  11959. w += dir;
  11960. }
  11961. }
  11962. }
  11963. return w;
  11964. }
  11965. function containPath(data, lineWidth, isStroke, x, y) {
  11966. var w = 0;
  11967. var xi = 0;
  11968. var yi = 0;
  11969. var x0 = 0;
  11970. var y0 = 0;
  11971. for (var i = 0; i < data.length;) {
  11972. var cmd = data[i++];
  11973. // Begin a new subpath
  11974. if (cmd === CMD$1.M && i > 1) {
  11975. // Close previous subpath
  11976. if (!isStroke) {
  11977. w += windingLine(xi, yi, x0, y0, x, y);
  11978. }
  11979. // 如果被任何一个 subpath 包含
  11980. // if (w !== 0) {
  11981. // return true;
  11982. // }
  11983. }
  11984. if (i == 1) {
  11985. // 如果第一个命令是 L, C, Q
  11986. // 则 previous point 同绘制命令的第一个 point
  11987. //
  11988. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11989. xi = data[i];
  11990. yi = data[i + 1];
  11991. x0 = xi;
  11992. y0 = yi;
  11993. }
  11994. switch (cmd) {
  11995. case CMD$1.M:
  11996. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11997. // 在 closePath 的时候使用
  11998. x0 = data[i++];
  11999. y0 = data[i++];
  12000. xi = x0;
  12001. yi = y0;
  12002. break;
  12003. case CMD$1.L:
  12004. if (isStroke) {
  12005. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12006. return true;
  12007. }
  12008. }
  12009. else {
  12010. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12011. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12012. }
  12013. xi = data[i++];
  12014. yi = data[i++];
  12015. break;
  12016. case CMD$1.C:
  12017. if (isStroke) {
  12018. if (containStroke$2(xi, yi,
  12019. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12020. lineWidth, x, y
  12021. )) {
  12022. return true;
  12023. }
  12024. }
  12025. else {
  12026. w += windingCubic(
  12027. xi, yi,
  12028. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12029. x, y
  12030. ) || 0;
  12031. }
  12032. xi = data[i++];
  12033. yi = data[i++];
  12034. break;
  12035. case CMD$1.Q:
  12036. if (isStroke) {
  12037. if (containStroke$3(xi, yi,
  12038. data[i++], data[i++], data[i], data[i + 1],
  12039. lineWidth, x, y
  12040. )) {
  12041. return true;
  12042. }
  12043. }
  12044. else {
  12045. w += windingQuadratic(
  12046. xi, yi,
  12047. data[i++], data[i++], data[i], data[i + 1],
  12048. x, y
  12049. ) || 0;
  12050. }
  12051. xi = data[i++];
  12052. yi = data[i++];
  12053. break;
  12054. case CMD$1.A:
  12055. // TODO Arc 判断的开销比较大
  12056. var cx = data[i++];
  12057. var cy = data[i++];
  12058. var rx = data[i++];
  12059. var ry = data[i++];
  12060. var theta = data[i++];
  12061. var dTheta = data[i++];
  12062. // TODO Arc 旋转
  12063. var psi = data[i++];
  12064. var anticlockwise = 1 - data[i++];
  12065. var x1 = Math.cos(theta) * rx + cx;
  12066. var y1 = Math.sin(theta) * ry + cy;
  12067. // 不是直接使用 arc 命令
  12068. if (i > 1) {
  12069. w += windingLine(xi, yi, x1, y1, x, y);
  12070. }
  12071. else {
  12072. // 第一个命令起点还未定义
  12073. x0 = x1;
  12074. y0 = y1;
  12075. }
  12076. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12077. var _x = (x - cx) * ry / rx + cx;
  12078. if (isStroke) {
  12079. if (containStroke$4(
  12080. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12081. lineWidth, _x, y
  12082. )) {
  12083. return true;
  12084. }
  12085. }
  12086. else {
  12087. w += windingArc(
  12088. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12089. _x, y
  12090. );
  12091. }
  12092. xi = Math.cos(theta + dTheta) * rx + cx;
  12093. yi = Math.sin(theta + dTheta) * ry + cy;
  12094. break;
  12095. case CMD$1.R:
  12096. x0 = xi = data[i++];
  12097. y0 = yi = data[i++];
  12098. var width = data[i++];
  12099. var height = data[i++];
  12100. var x1 = x0 + width;
  12101. var y1 = y0 + height;
  12102. if (isStroke) {
  12103. if (containStroke$1(x0, y0, x1, y0, lineWidth, x, y)
  12104. || containStroke$1(x1, y0, x1, y1, lineWidth, x, y)
  12105. || containStroke$1(x1, y1, x0, y1, lineWidth, x, y)
  12106. || containStroke$1(x0, y1, x0, y0, lineWidth, x, y)
  12107. ) {
  12108. return true;
  12109. }
  12110. }
  12111. else {
  12112. // FIXME Clockwise ?
  12113. w += windingLine(x1, y0, x1, y1, x, y);
  12114. w += windingLine(x0, y1, x0, y0, x, y);
  12115. }
  12116. break;
  12117. case CMD$1.Z:
  12118. if (isStroke) {
  12119. if (containStroke$1(
  12120. xi, yi, x0, y0, lineWidth, x, y
  12121. )) {
  12122. return true;
  12123. }
  12124. }
  12125. else {
  12126. // Close a subpath
  12127. w += windingLine(xi, yi, x0, y0, x, y);
  12128. // 如果被任何一个 subpath 包含
  12129. // FIXME subpaths may overlap
  12130. // if (w !== 0) {
  12131. // return true;
  12132. // }
  12133. }
  12134. xi = x0;
  12135. yi = y0;
  12136. break;
  12137. }
  12138. }
  12139. if (!isStroke && !isAroundEqual(yi, y0)) {
  12140. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12141. }
  12142. return w !== 0;
  12143. }
  12144. function contain(pathData, x, y) {
  12145. return containPath(pathData, 0, false, x, y);
  12146. }
  12147. function containStroke(pathData, lineWidth, x, y) {
  12148. return containPath(pathData, lineWidth, true, x, y);
  12149. }
  12150. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12151. var abs = Math.abs;
  12152. var pathProxyForDraw = new PathProxy(true);
  12153. /**
  12154. * @alias module:zrender/graphic/Path
  12155. * @extends module:zrender/graphic/Displayable
  12156. * @constructor
  12157. * @param {Object} opts
  12158. */
  12159. function Path(opts) {
  12160. Displayable.call(this, opts);
  12161. /**
  12162. * @type {module:zrender/core/PathProxy}
  12163. * @readOnly
  12164. */
  12165. this.path = null;
  12166. }
  12167. Path.prototype = {
  12168. constructor: Path,
  12169. type: 'path',
  12170. __dirtyPath: true,
  12171. strokeContainThreshold: 5,
  12172. brush: function (ctx, prevEl) {
  12173. var style = this.style;
  12174. var path = this.path || pathProxyForDraw;
  12175. var hasStroke = style.hasStroke();
  12176. var hasFill = style.hasFill();
  12177. var fill = style.fill;
  12178. var stroke = style.stroke;
  12179. var hasFillGradient = hasFill && !!(fill.colorStops);
  12180. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  12181. var hasFillPattern = hasFill && !!(fill.image);
  12182. var hasStrokePattern = hasStroke && !!(stroke.image);
  12183. style.bind(ctx, this, prevEl);
  12184. this.setTransform(ctx);
  12185. if (this.__dirty) {
  12186. var rect;
  12187. // Update gradient because bounding rect may changed
  12188. if (hasFillGradient) {
  12189. rect = rect || this.getBoundingRect();
  12190. this._fillGradient = style.getGradient(ctx, fill, rect);
  12191. }
  12192. if (hasStrokeGradient) {
  12193. rect = rect || this.getBoundingRect();
  12194. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12195. }
  12196. }
  12197. // Use the gradient or pattern
  12198. if (hasFillGradient) {
  12199. // PENDING If may have affect the state
  12200. ctx.fillStyle = this._fillGradient;
  12201. }
  12202. else if (hasFillPattern) {
  12203. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12204. }
  12205. if (hasStrokeGradient) {
  12206. ctx.strokeStyle = this._strokeGradient;
  12207. }
  12208. else if (hasStrokePattern) {
  12209. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12210. }
  12211. var lineDash = style.lineDash;
  12212. var lineDashOffset = style.lineDashOffset;
  12213. var ctxLineDash = !!ctx.setLineDash;
  12214. // Update path sx, sy
  12215. var scale = this.getGlobalScale();
  12216. path.setScale(scale[0], scale[1]);
  12217. // Proxy context
  12218. // Rebuild path in following 2 cases
  12219. // 1. Path is dirty
  12220. // 2. Path needs javascript implemented lineDash stroking.
  12221. // In this case, lineDash information will not be saved in PathProxy
  12222. if (this.__dirtyPath
  12223. || (lineDash && !ctxLineDash && hasStroke)
  12224. ) {
  12225. path.beginPath(ctx);
  12226. // Setting line dash before build path
  12227. if (lineDash && !ctxLineDash) {
  12228. path.setLineDash(lineDash);
  12229. path.setLineDashOffset(lineDashOffset);
  12230. }
  12231. this.buildPath(path, this.shape, false);
  12232. // Clear path dirty flag
  12233. if (this.path) {
  12234. this.__dirtyPath = false;
  12235. }
  12236. }
  12237. else {
  12238. // Replay path building
  12239. ctx.beginPath();
  12240. this.path.rebuildPath(ctx);
  12241. }
  12242. hasFill && path.fill(ctx);
  12243. if (lineDash && ctxLineDash) {
  12244. ctx.setLineDash(lineDash);
  12245. ctx.lineDashOffset = lineDashOffset;
  12246. }
  12247. hasStroke && path.stroke(ctx);
  12248. if (lineDash && ctxLineDash) {
  12249. // PENDING
  12250. // Remove lineDash
  12251. ctx.setLineDash([]);
  12252. }
  12253. this.restoreTransform(ctx);
  12254. // Draw rect text
  12255. if (style.text != null) {
  12256. this.drawRectText(ctx, this.getBoundingRect());
  12257. }
  12258. },
  12259. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12260. // Like in circle
  12261. buildPath: function (ctx, shapeCfg, inBundle) {},
  12262. createPathProxy: function () {
  12263. this.path = new PathProxy();
  12264. },
  12265. getBoundingRect: function () {
  12266. var rect = this._rect;
  12267. var style = this.style;
  12268. var needsUpdateRect = !rect;
  12269. if (needsUpdateRect) {
  12270. var path = this.path;
  12271. if (!path) {
  12272. // Create path on demand.
  12273. path = this.path = new PathProxy();
  12274. }
  12275. if (this.__dirtyPath) {
  12276. path.beginPath();
  12277. this.buildPath(path, this.shape, false);
  12278. }
  12279. rect = path.getBoundingRect();
  12280. }
  12281. this._rect = rect;
  12282. if (style.hasStroke()) {
  12283. // Needs update rect with stroke lineWidth when
  12284. // 1. Element changes scale or lineWidth
  12285. // 2. Shape is changed
  12286. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12287. if (this.__dirty || needsUpdateRect) {
  12288. rectWithStroke.copy(rect);
  12289. // FIXME Must after updateTransform
  12290. var w = style.lineWidth;
  12291. // PENDING, Min line width is needed when line is horizontal or vertical
  12292. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12293. // Only add extra hover lineWidth when there are no fill
  12294. if (!style.hasFill()) {
  12295. w = Math.max(w, this.strokeContainThreshold || 4);
  12296. }
  12297. // Consider line width
  12298. // Line scale can't be 0;
  12299. if (lineScale > 1e-10) {
  12300. rectWithStroke.width += w / lineScale;
  12301. rectWithStroke.height += w / lineScale;
  12302. rectWithStroke.x -= w / lineScale / 2;
  12303. rectWithStroke.y -= w / lineScale / 2;
  12304. }
  12305. }
  12306. // Return rect with stroke
  12307. return rectWithStroke;
  12308. }
  12309. return rect;
  12310. },
  12311. contain: function (x, y) {
  12312. var localPos = this.transformCoordToLocal(x, y);
  12313. var rect = this.getBoundingRect();
  12314. var style = this.style;
  12315. x = localPos[0];
  12316. y = localPos[1];
  12317. if (rect.contain(x, y)) {
  12318. var pathData = this.path.data;
  12319. if (style.hasStroke()) {
  12320. var lineWidth = style.lineWidth;
  12321. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12322. // Line scale can't be 0;
  12323. if (lineScale > 1e-10) {
  12324. // Only add extra hover lineWidth when there are no fill
  12325. if (!style.hasFill()) {
  12326. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  12327. }
  12328. if (containStroke(
  12329. pathData, lineWidth / lineScale, x, y
  12330. )) {
  12331. return true;
  12332. }
  12333. }
  12334. }
  12335. if (style.hasFill()) {
  12336. return contain(pathData, x, y);
  12337. }
  12338. }
  12339. return false;
  12340. },
  12341. /**
  12342. * @param {boolean} dirtyPath
  12343. */
  12344. dirty: function (dirtyPath) {
  12345. if (dirtyPath == null) {
  12346. dirtyPath = true;
  12347. }
  12348. // Only mark dirty, not mark clean
  12349. if (dirtyPath) {
  12350. this.__dirtyPath = dirtyPath;
  12351. this._rect = null;
  12352. }
  12353. this.__dirty = true;
  12354. this.__zr && this.__zr.refresh();
  12355. // Used as a clipping path
  12356. if (this.__clipTarget) {
  12357. this.__clipTarget.dirty();
  12358. }
  12359. },
  12360. /**
  12361. * Alias for animate('shape')
  12362. * @param {boolean} loop
  12363. */
  12364. animateShape: function (loop) {
  12365. return this.animate('shape', loop);
  12366. },
  12367. // Overwrite attrKV
  12368. attrKV: function (key, value) {
  12369. // FIXME
  12370. if (key === 'shape') {
  12371. this.setShape(value);
  12372. this.__dirtyPath = true;
  12373. this._rect = null;
  12374. }
  12375. else {
  12376. Displayable.prototype.attrKV.call(this, key, value);
  12377. }
  12378. },
  12379. /**
  12380. * @param {Object|string} key
  12381. * @param {*} value
  12382. */
  12383. setShape: function (key, value) {
  12384. var shape = this.shape;
  12385. // Path from string may not have shape
  12386. if (shape) {
  12387. if (isObject(key)) {
  12388. for (var name in key) {
  12389. if (key.hasOwnProperty(name)) {
  12390. shape[name] = key[name];
  12391. }
  12392. }
  12393. }
  12394. else {
  12395. shape[key] = value;
  12396. }
  12397. this.dirty(true);
  12398. }
  12399. return this;
  12400. },
  12401. getLineScale: function () {
  12402. var m = this.transform;
  12403. // Get the line scale.
  12404. // Determinant of `m` means how much the area is enlarged by the
  12405. // transformation. So its square root can be used as a scale factor
  12406. // for width.
  12407. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  12408. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  12409. : 1;
  12410. }
  12411. };
  12412. /**
  12413. * 扩展一个 Path element, 比如星形,圆等。
  12414. * Extend a path element
  12415. * @param {Object} props
  12416. * @param {string} props.type Path type
  12417. * @param {Function} props.init Initialize
  12418. * @param {Function} props.buildPath Overwrite buildPath method
  12419. * @param {Object} [props.style] Extended default style config
  12420. * @param {Object} [props.shape] Extended default shape config
  12421. */
  12422. Path.extend = function (defaults$$1) {
  12423. var Sub = function (opts) {
  12424. Path.call(this, opts);
  12425. if (defaults$$1.style) {
  12426. // Extend default style
  12427. this.style.extendFrom(defaults$$1.style, false);
  12428. }
  12429. // Extend default shape
  12430. var defaultShape = defaults$$1.shape;
  12431. if (defaultShape) {
  12432. this.shape = this.shape || {};
  12433. var thisShape = this.shape;
  12434. for (var name in defaultShape) {
  12435. if (
  12436. ! thisShape.hasOwnProperty(name)
  12437. && defaultShape.hasOwnProperty(name)
  12438. ) {
  12439. thisShape[name] = defaultShape[name];
  12440. }
  12441. }
  12442. }
  12443. defaults$$1.init && defaults$$1.init.call(this, opts);
  12444. };
  12445. inherits(Sub, Path);
  12446. // FIXME 不能 extend position, rotation 等引用对象
  12447. for (var name in defaults$$1) {
  12448. // Extending prototype values and methods
  12449. if (name !== 'style' && name !== 'shape') {
  12450. Sub.prototype[name] = defaults$$1[name];
  12451. }
  12452. }
  12453. return Sub;
  12454. };
  12455. inherits(Path, Displayable);
  12456. var CMD$2 = PathProxy.CMD;
  12457. var points = [[], [], []];
  12458. var mathSqrt$3 = Math.sqrt;
  12459. var mathAtan2 = Math.atan2;
  12460. var transformPath = function (path, m) {
  12461. var data = path.data;
  12462. var cmd;
  12463. var nPoint;
  12464. var i;
  12465. var j;
  12466. var k;
  12467. var p;
  12468. var M = CMD$2.M;
  12469. var C = CMD$2.C;
  12470. var L = CMD$2.L;
  12471. var R = CMD$2.R;
  12472. var A = CMD$2.A;
  12473. var Q = CMD$2.Q;
  12474. for (i = 0, j = 0; i < data.length;) {
  12475. cmd = data[i++];
  12476. j = i;
  12477. nPoint = 0;
  12478. switch (cmd) {
  12479. case M:
  12480. nPoint = 1;
  12481. break;
  12482. case L:
  12483. nPoint = 1;
  12484. break;
  12485. case C:
  12486. nPoint = 3;
  12487. break;
  12488. case Q:
  12489. nPoint = 2;
  12490. break;
  12491. case A:
  12492. var x = m[4];
  12493. var y = m[5];
  12494. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  12495. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  12496. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  12497. // cx
  12498. data[i] *= sx;
  12499. data[i++] += x;
  12500. // cy
  12501. data[i] *= sy;
  12502. data[i++] += y;
  12503. // Scale rx and ry
  12504. // FIXME Assume psi is 0 here
  12505. data[i++] *= sx;
  12506. data[i++] *= sy;
  12507. // Start angle
  12508. data[i++] += angle;
  12509. // end angle
  12510. data[i++] += angle;
  12511. // FIXME psi
  12512. i += 2;
  12513. j = i;
  12514. break;
  12515. case R:
  12516. // x0, y0
  12517. p[0] = data[i++];
  12518. p[1] = data[i++];
  12519. applyTransform(p, p, m);
  12520. data[j++] = p[0];
  12521. data[j++] = p[1];
  12522. // x1, y1
  12523. p[0] += data[i++];
  12524. p[1] += data[i++];
  12525. applyTransform(p, p, m);
  12526. data[j++] = p[0];
  12527. data[j++] = p[1];
  12528. }
  12529. for (k = 0; k < nPoint; k++) {
  12530. var p = points[k];
  12531. p[0] = data[i++];
  12532. p[1] = data[i++];
  12533. applyTransform(p, p, m);
  12534. // Write back
  12535. data[j++] = p[0];
  12536. data[j++] = p[1];
  12537. }
  12538. }
  12539. };
  12540. // command chars
  12541. var cc = [
  12542. 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  12543. 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  12544. ];
  12545. var mathSqrt = Math.sqrt;
  12546. var mathSin = Math.sin;
  12547. var mathCos = Math.cos;
  12548. var PI = Math.PI;
  12549. var vMag = function(v) {
  12550. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12551. };
  12552. var vRatio = function(u, v) {
  12553. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12554. };
  12555. var vAngle = function(u, v) {
  12556. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  12557. * Math.acos(vRatio(u, v));
  12558. };
  12559. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12560. var psi = psiDeg * (PI / 180.0);
  12561. var xp = mathCos(psi) * (x1 - x2) / 2.0
  12562. + mathSin(psi) * (y1 - y2) / 2.0;
  12563. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  12564. + mathCos(psi) * (y1 - y2) / 2.0;
  12565. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  12566. if (lambda > 1) {
  12567. rx *= mathSqrt(lambda);
  12568. ry *= mathSqrt(lambda);
  12569. }
  12570. var f = (fa === fs ? -1 : 1)
  12571. * mathSqrt((((rx * rx) * (ry * ry))
  12572. - ((rx * rx) * (yp * yp))
  12573. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  12574. + (ry * ry) * (xp * xp))
  12575. ) || 0;
  12576. var cxp = f * rx * yp / ry;
  12577. var cyp = f * -ry * xp / rx;
  12578. var cx = (x1 + x2) / 2.0
  12579. + mathCos(psi) * cxp
  12580. - mathSin(psi) * cyp;
  12581. var cy = (y1 + y2) / 2.0
  12582. + mathSin(psi) * cxp
  12583. + mathCos(psi) * cyp;
  12584. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  12585. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  12586. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  12587. var dTheta = vAngle(u, v);
  12588. if (vRatio(u, v) <= -1) {
  12589. dTheta = PI;
  12590. }
  12591. if (vRatio(u, v) >= 1) {
  12592. dTheta = 0;
  12593. }
  12594. if (fs === 0 && dTheta > 0) {
  12595. dTheta = dTheta - 2 * PI;
  12596. }
  12597. if (fs === 1 && dTheta < 0) {
  12598. dTheta = dTheta + 2 * PI;
  12599. }
  12600. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  12601. }
  12602. function createPathProxyFromString(data) {
  12603. if (!data) {
  12604. return [];
  12605. }
  12606. // command string
  12607. var cs = data.replace(/-/g, ' -')
  12608. .replace(/ /g, ' ')
  12609. .replace(/ /g, ',')
  12610. .replace(/,,/g, ',');
  12611. var n;
  12612. // create pipes so that we can split the data
  12613. for (n = 0; n < cc.length; n++) {
  12614. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  12615. }
  12616. // create array
  12617. var arr = cs.split('|');
  12618. // init context point
  12619. var cpx = 0;
  12620. var cpy = 0;
  12621. var path = new PathProxy();
  12622. var CMD = PathProxy.CMD;
  12623. var prevCmd;
  12624. for (n = 1; n < arr.length; n++) {
  12625. var str = arr[n];
  12626. var c = str.charAt(0);
  12627. var off = 0;
  12628. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  12629. var cmd;
  12630. if (p.length > 0 && p[0] === '') {
  12631. p.shift();
  12632. }
  12633. for (var i = 0; i < p.length; i++) {
  12634. p[i] = parseFloat(p[i]);
  12635. }
  12636. while (off < p.length && !isNaN(p[off])) {
  12637. if (isNaN(p[0])) {
  12638. break;
  12639. }
  12640. var ctlPtx;
  12641. var ctlPty;
  12642. var rx;
  12643. var ry;
  12644. var psi;
  12645. var fa;
  12646. var fs;
  12647. var x1 = cpx;
  12648. var y1 = cpy;
  12649. // convert l, H, h, V, and v to L
  12650. switch (c) {
  12651. case 'l':
  12652. cpx += p[off++];
  12653. cpy += p[off++];
  12654. cmd = CMD.L;
  12655. path.addData(cmd, cpx, cpy);
  12656. break;
  12657. case 'L':
  12658. cpx = p[off++];
  12659. cpy = p[off++];
  12660. cmd = CMD.L;
  12661. path.addData(cmd, cpx, cpy);
  12662. break;
  12663. case 'm':
  12664. cpx += p[off++];
  12665. cpy += p[off++];
  12666. cmd = CMD.M;
  12667. path.addData(cmd, cpx, cpy);
  12668. c = 'l';
  12669. break;
  12670. case 'M':
  12671. cpx = p[off++];
  12672. cpy = p[off++];
  12673. cmd = CMD.M;
  12674. path.addData(cmd, cpx, cpy);
  12675. c = 'L';
  12676. break;
  12677. case 'h':
  12678. cpx += p[off++];
  12679. cmd = CMD.L;
  12680. path.addData(cmd, cpx, cpy);
  12681. break;
  12682. case 'H':
  12683. cpx = p[off++];
  12684. cmd = CMD.L;
  12685. path.addData(cmd, cpx, cpy);
  12686. break;
  12687. case 'v':
  12688. cpy += p[off++];
  12689. cmd = CMD.L;
  12690. path.addData(cmd, cpx, cpy);
  12691. break;
  12692. case 'V':
  12693. cpy = p[off++];
  12694. cmd = CMD.L;
  12695. path.addData(cmd, cpx, cpy);
  12696. break;
  12697. case 'C':
  12698. cmd = CMD.C;
  12699. path.addData(
  12700. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  12701. );
  12702. cpx = p[off - 2];
  12703. cpy = p[off - 1];
  12704. break;
  12705. case 'c':
  12706. cmd = CMD.C;
  12707. path.addData(
  12708. cmd,
  12709. p[off++] + cpx, p[off++] + cpy,
  12710. p[off++] + cpx, p[off++] + cpy,
  12711. p[off++] + cpx, p[off++] + cpy
  12712. );
  12713. cpx += p[off - 2];
  12714. cpy += p[off - 1];
  12715. break;
  12716. case 'S':
  12717. ctlPtx = cpx;
  12718. ctlPty = cpy;
  12719. var len = path.len();
  12720. var pathData = path.data;
  12721. if (prevCmd === CMD.C) {
  12722. ctlPtx += cpx - pathData[len - 4];
  12723. ctlPty += cpy - pathData[len - 3];
  12724. }
  12725. cmd = CMD.C;
  12726. x1 = p[off++];
  12727. y1 = p[off++];
  12728. cpx = p[off++];
  12729. cpy = p[off++];
  12730. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12731. break;
  12732. case 's':
  12733. ctlPtx = cpx;
  12734. ctlPty = cpy;
  12735. var len = path.len();
  12736. var pathData = path.data;
  12737. if (prevCmd === CMD.C) {
  12738. ctlPtx += cpx - pathData[len - 4];
  12739. ctlPty += cpy - pathData[len - 3];
  12740. }
  12741. cmd = CMD.C;
  12742. x1 = cpx + p[off++];
  12743. y1 = cpy + p[off++];
  12744. cpx += p[off++];
  12745. cpy += p[off++];
  12746. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12747. break;
  12748. case 'Q':
  12749. x1 = p[off++];
  12750. y1 = p[off++];
  12751. cpx = p[off++];
  12752. cpy = p[off++];
  12753. cmd = CMD.Q;
  12754. path.addData(cmd, x1, y1, cpx, cpy);
  12755. break;
  12756. case 'q':
  12757. x1 = p[off++] + cpx;
  12758. y1 = p[off++] + cpy;
  12759. cpx += p[off++];
  12760. cpy += p[off++];
  12761. cmd = CMD.Q;
  12762. path.addData(cmd, x1, y1, cpx, cpy);
  12763. break;
  12764. case 'T':
  12765. ctlPtx = cpx;
  12766. ctlPty = cpy;
  12767. var len = path.len();
  12768. var pathData = path.data;
  12769. if (prevCmd === CMD.Q) {
  12770. ctlPtx += cpx - pathData[len - 4];
  12771. ctlPty += cpy - pathData[len - 3];
  12772. }
  12773. cpx = p[off++];
  12774. cpy = p[off++];
  12775. cmd = CMD.Q;
  12776. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12777. break;
  12778. case 't':
  12779. ctlPtx = cpx;
  12780. ctlPty = cpy;
  12781. var len = path.len();
  12782. var pathData = path.data;
  12783. if (prevCmd === CMD.Q) {
  12784. ctlPtx += cpx - pathData[len - 4];
  12785. ctlPty += cpy - pathData[len - 3];
  12786. }
  12787. cpx += p[off++];
  12788. cpy += p[off++];
  12789. cmd = CMD.Q;
  12790. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12791. break;
  12792. case 'A':
  12793. rx = p[off++];
  12794. ry = p[off++];
  12795. psi = p[off++];
  12796. fa = p[off++];
  12797. fs = p[off++];
  12798. x1 = cpx, y1 = cpy;
  12799. cpx = p[off++];
  12800. cpy = p[off++];
  12801. cmd = CMD.A;
  12802. processArc(
  12803. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  12804. );
  12805. break;
  12806. case 'a':
  12807. rx = p[off++];
  12808. ry = p[off++];
  12809. psi = p[off++];
  12810. fa = p[off++];
  12811. fs = p[off++];
  12812. x1 = cpx, y1 = cpy;
  12813. cpx += p[off++];
  12814. cpy += p[off++];
  12815. cmd = CMD.A;
  12816. processArc(
  12817. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  12818. );
  12819. break;
  12820. }
  12821. }
  12822. if (c === 'z' || c === 'Z') {
  12823. cmd = CMD.Z;
  12824. path.addData(cmd);
  12825. }
  12826. prevCmd = cmd;
  12827. }
  12828. path.toStatic();
  12829. return path;
  12830. }
  12831. // TODO Optimize double memory cost problem
  12832. function createPathOptions(str, opts) {
  12833. var pathProxy = createPathProxyFromString(str);
  12834. opts = opts || {};
  12835. opts.buildPath = function (path) {
  12836. if (path.setData) {
  12837. path.setData(pathProxy.data);
  12838. // Svg and vml renderer don't have context
  12839. var ctx = path.getContext();
  12840. if (ctx) {
  12841. path.rebuildPath(ctx);
  12842. }
  12843. }
  12844. else {
  12845. var ctx = path;
  12846. pathProxy.rebuildPath(ctx);
  12847. }
  12848. };
  12849. opts.applyTransform = function (m) {
  12850. transformPath(pathProxy, m);
  12851. this.dirty(true);
  12852. };
  12853. return opts;
  12854. }
  12855. /**
  12856. * Create a Path object from path string data
  12857. * http://www.w3.org/TR/SVG/paths.html#PathData
  12858. * @param {Object} opts Other options
  12859. */
  12860. function createFromString(str, opts) {
  12861. return new Path(createPathOptions(str, opts));
  12862. }
  12863. /**
  12864. * Create a Path class from path string data
  12865. * @param {string} str
  12866. * @param {Object} opts Other options
  12867. */
  12868. function extendFromString(str, opts) {
  12869. return Path.extend(createPathOptions(str, opts));
  12870. }
  12871. /**
  12872. * Merge multiple paths
  12873. */
  12874. // TODO Apply transform
  12875. // TODO stroke dash
  12876. // TODO Optimize double memory cost problem
  12877. function mergePath$1(pathEls, opts) {
  12878. var pathList = [];
  12879. var len = pathEls.length;
  12880. for (var i = 0; i < len; i++) {
  12881. var pathEl = pathEls[i];
  12882. if (!pathEl.path) {
  12883. pathEl.createPathProxy();
  12884. }
  12885. if (pathEl.__dirtyPath) {
  12886. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  12887. }
  12888. pathList.push(pathEl.path);
  12889. }
  12890. var pathBundle = new Path(opts);
  12891. // Need path proxy.
  12892. pathBundle.createPathProxy();
  12893. pathBundle.buildPath = function (path) {
  12894. path.appendPath(pathList);
  12895. // Svg and vml renderer don't have context
  12896. var ctx = path.getContext();
  12897. if (ctx) {
  12898. path.rebuildPath(ctx);
  12899. }
  12900. };
  12901. return pathBundle;
  12902. }
  12903. /**
  12904. * @alias zrender/graphic/Text
  12905. * @extends module:zrender/graphic/Displayable
  12906. * @constructor
  12907. * @param {Object} opts
  12908. */
  12909. var Text = function (opts) { // jshint ignore:line
  12910. Displayable.call(this, opts);
  12911. };
  12912. Text.prototype = {
  12913. constructor: Text,
  12914. type: 'text',
  12915. brush: function (ctx, prevEl) {
  12916. var style = this.style;
  12917. // Optimize, avoid normalize every time.
  12918. this.__dirty && normalizeTextStyle(style, true);
  12919. // Use props with prefix 'text'.
  12920. style.fill = style.stroke = style.shadowBlur = style.shadowColor =
  12921. style.shadowOffsetX = style.shadowOffsetY = null;
  12922. var text = style.text;
  12923. // Convert to string
  12924. text != null && (text += '');
  12925. // Always bind style
  12926. style.bind(ctx, this, prevEl);
  12927. if (!needDrawText(text, style)) {
  12928. return;
  12929. }
  12930. this.setTransform(ctx);
  12931. renderText(this, ctx, text, style);
  12932. this.restoreTransform(ctx);
  12933. },
  12934. getBoundingRect: function () {
  12935. var style = this.style;
  12936. // Optimize, avoid normalize every time.
  12937. this.__dirty && normalizeTextStyle(style, true);
  12938. if (!this._rect) {
  12939. var text = style.text;
  12940. text != null ? (text += '') : (text = '');
  12941. var rect = getBoundingRect(
  12942. style.text + '',
  12943. style.font,
  12944. style.textAlign,
  12945. style.textVerticalAlign,
  12946. style.textPadding,
  12947. style.rich
  12948. );
  12949. rect.x += style.x || 0;
  12950. rect.y += style.y || 0;
  12951. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  12952. var w = style.textStrokeWidth;
  12953. rect.x -= w / 2;
  12954. rect.y -= w / 2;
  12955. rect.width += w;
  12956. rect.height += w;
  12957. }
  12958. this._rect = rect;
  12959. }
  12960. return this._rect;
  12961. }
  12962. };
  12963. inherits(Text, Displayable);
  12964. /**
  12965. * 圆形
  12966. * @module zrender/shape/Circle
  12967. */
  12968. var Circle = Path.extend({
  12969. type: 'circle',
  12970. shape: {
  12971. cx: 0,
  12972. cy: 0,
  12973. r: 0
  12974. },
  12975. buildPath : function (ctx, shape, inBundle) {
  12976. // Better stroking in ShapeBundle
  12977. // Always do it may have performence issue ( fill may be 2x more cost)
  12978. if (inBundle) {
  12979. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12980. }
  12981. // else {
  12982. // if (ctx.allocate && !ctx.data.length) {
  12983. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  12984. // }
  12985. // }
  12986. // Better stroking in ShapeBundle
  12987. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  12988. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  12989. }
  12990. });
  12991. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  12992. // where exception "unexpected call to method or property access"
  12993. // might be thrown when calling ctx.fill or ctx.stroke after a path
  12994. // whose area size is zero is drawn and ctx.clip() is called and
  12995. // shadowBlur is set. See #4572, #3112, #5777.
  12996. // (e.g.,
  12997. // ctx.moveTo(10, 10);
  12998. // ctx.lineTo(20, 10);
  12999. // ctx.closePath();
  13000. // ctx.clip();
  13001. // ctx.shadowBlur = 10;
  13002. // ...
  13003. // ctx.fill();
  13004. // )
  13005. var shadowTemp = [
  13006. ['shadowBlur', 0],
  13007. ['shadowColor', '#000'],
  13008. ['shadowOffsetX', 0],
  13009. ['shadowOffsetY', 0]
  13010. ];
  13011. var fixClipWithShadow = function (orignalBrush) {
  13012. // version string can be: '11.0'
  13013. return (env$1.browser.ie && env$1.browser.version >= 11)
  13014. ? function () {
  13015. var clipPaths = this.__clipPaths;
  13016. var style = this.style;
  13017. var modified;
  13018. if (clipPaths) {
  13019. for (var i = 0; i < clipPaths.length; i++) {
  13020. var clipPath = clipPaths[i];
  13021. var shape = clipPath && clipPath.shape;
  13022. var type = clipPath && clipPath.type;
  13023. if (shape && (
  13024. (type === 'sector' && shape.startAngle === shape.endAngle)
  13025. || (type === 'rect' && (!shape.width || !shape.height))
  13026. )) {
  13027. for (var j = 0; j < shadowTemp.length; j++) {
  13028. // It is save to put shadowTemp static, because shadowTemp
  13029. // will be all modified each item brush called.
  13030. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13031. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13032. }
  13033. modified = true;
  13034. break;
  13035. }
  13036. }
  13037. }
  13038. orignalBrush.apply(this, arguments);
  13039. if (modified) {
  13040. for (var j = 0; j < shadowTemp.length; j++) {
  13041. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13042. }
  13043. }
  13044. }
  13045. : orignalBrush;
  13046. };
  13047. /**
  13048. * 扇形
  13049. * @module zrender/graphic/shape/Sector
  13050. */
  13051. var Sector = Path.extend({
  13052. type: 'sector',
  13053. shape: {
  13054. cx: 0,
  13055. cy: 0,
  13056. r0: 0,
  13057. r: 0,
  13058. startAngle: 0,
  13059. endAngle: Math.PI * 2,
  13060. clockwise: true
  13061. },
  13062. brush: fixClipWithShadow(Path.prototype.brush),
  13063. buildPath: function (ctx, shape) {
  13064. var x = shape.cx;
  13065. var y = shape.cy;
  13066. var r0 = Math.max(shape.r0 || 0, 0);
  13067. var r = Math.max(shape.r, 0);
  13068. var startAngle = shape.startAngle;
  13069. var endAngle = shape.endAngle;
  13070. var clockwise = shape.clockwise;
  13071. var unitX = Math.cos(startAngle);
  13072. var unitY = Math.sin(startAngle);
  13073. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13074. ctx.lineTo(unitX * r + x, unitY * r + y);
  13075. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13076. ctx.lineTo(
  13077. Math.cos(endAngle) * r0 + x,
  13078. Math.sin(endAngle) * r0 + y
  13079. );
  13080. if (r0 !== 0) {
  13081. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13082. }
  13083. ctx.closePath();
  13084. }
  13085. });
  13086. /**
  13087. * 圆环
  13088. * @module zrender/graphic/shape/Ring
  13089. */
  13090. var Ring = Path.extend({
  13091. type: 'ring',
  13092. shape: {
  13093. cx: 0,
  13094. cy: 0,
  13095. r: 0,
  13096. r0: 0
  13097. },
  13098. buildPath: function (ctx, shape) {
  13099. var x = shape.cx;
  13100. var y = shape.cy;
  13101. var PI2 = Math.PI * 2;
  13102. ctx.moveTo(x + shape.r, y);
  13103. ctx.arc(x, y, shape.r, 0, PI2, false);
  13104. ctx.moveTo(x + shape.r0, y);
  13105. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13106. }
  13107. });
  13108. /**
  13109. * Catmull-Rom spline 插值折线
  13110. * @module zrender/shape/util/smoothSpline
  13111. * @author pissang (https://www.github.com/pissang)
  13112. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13113. * errorrik (errorrik@gmail.com)
  13114. */
  13115. /**
  13116. * @inner
  13117. */
  13118. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13119. var v0 = (p2 - p0) * 0.5;
  13120. var v1 = (p3 - p1) * 0.5;
  13121. return (2 * (p1 - p2) + v0 + v1) * t3
  13122. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  13123. + v0 * t + p1;
  13124. }
  13125. /**
  13126. * @alias module:zrender/shape/util/smoothSpline
  13127. * @param {Array} points 线段顶点数组
  13128. * @param {boolean} isLoop
  13129. * @return {Array}
  13130. */
  13131. var smoothSpline = function (points, isLoop) {
  13132. var len$$1 = points.length;
  13133. var ret = [];
  13134. var distance$$1 = 0;
  13135. for (var i = 1; i < len$$1; i++) {
  13136. distance$$1 += distance(points[i - 1], points[i]);
  13137. }
  13138. var segs = distance$$1 / 2;
  13139. segs = segs < len$$1 ? len$$1 : segs;
  13140. for (var i = 0; i < segs; i++) {
  13141. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13142. var idx = Math.floor(pos);
  13143. var w = pos - idx;
  13144. var p0;
  13145. var p1 = points[idx % len$$1];
  13146. var p2;
  13147. var p3;
  13148. if (!isLoop) {
  13149. p0 = points[idx === 0 ? idx : idx - 1];
  13150. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13151. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13152. }
  13153. else {
  13154. p0 = points[(idx - 1 + len$$1) % len$$1];
  13155. p2 = points[(idx + 1) % len$$1];
  13156. p3 = points[(idx + 2) % len$$1];
  13157. }
  13158. var w2 = w * w;
  13159. var w3 = w * w2;
  13160. ret.push([
  13161. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13162. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13163. ]);
  13164. }
  13165. return ret;
  13166. };
  13167. /**
  13168. * 贝塞尔平滑曲线
  13169. * @module zrender/shape/util/smoothBezier
  13170. * @author pissang (https://www.github.com/pissang)
  13171. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13172. * errorrik (errorrik@gmail.com)
  13173. */
  13174. /**
  13175. * 贝塞尔平滑曲线
  13176. * @alias module:zrender/shape/util/smoothBezier
  13177. * @param {Array} points 线段顶点数组
  13178. * @param {number} smooth 平滑等级, 0-1
  13179. * @param {boolean} isLoop
  13180. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13181. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13182. * 整个折线的包围盒做一个并集用来约束控制点。
  13183. * @param {Array} 计算出来的控制点数组
  13184. */
  13185. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13186. var cps = [];
  13187. var v = [];
  13188. var v1 = [];
  13189. var v2 = [];
  13190. var prevPoint;
  13191. var nextPoint;
  13192. var min$$1, max$$1;
  13193. if (constraint) {
  13194. min$$1 = [Infinity, Infinity];
  13195. max$$1 = [-Infinity, -Infinity];
  13196. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13197. min(min$$1, min$$1, points[i]);
  13198. max(max$$1, max$$1, points[i]);
  13199. }
  13200. // 与指定的包围盒做并集
  13201. min(min$$1, min$$1, constraint[0]);
  13202. max(max$$1, max$$1, constraint[1]);
  13203. }
  13204. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13205. var point = points[i];
  13206. if (isLoop) {
  13207. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13208. nextPoint = points[(i + 1) % len$$1];
  13209. }
  13210. else {
  13211. if (i === 0 || i === len$$1 - 1) {
  13212. cps.push(clone$1(points[i]));
  13213. continue;
  13214. }
  13215. else {
  13216. prevPoint = points[i - 1];
  13217. nextPoint = points[i + 1];
  13218. }
  13219. }
  13220. sub(v, nextPoint, prevPoint);
  13221. // use degree to scale the handle length
  13222. scale(v, v, smooth);
  13223. var d0 = distance(point, prevPoint);
  13224. var d1 = distance(point, nextPoint);
  13225. var sum = d0 + d1;
  13226. if (sum !== 0) {
  13227. d0 /= sum;
  13228. d1 /= sum;
  13229. }
  13230. scale(v1, v, -d0);
  13231. scale(v2, v, d1);
  13232. var cp0 = add([], point, v1);
  13233. var cp1 = add([], point, v2);
  13234. if (constraint) {
  13235. max(cp0, cp0, min$$1);
  13236. min(cp0, cp0, max$$1);
  13237. max(cp1, cp1, min$$1);
  13238. min(cp1, cp1, max$$1);
  13239. }
  13240. cps.push(cp0);
  13241. cps.push(cp1);
  13242. }
  13243. if (isLoop) {
  13244. cps.push(cps.shift());
  13245. }
  13246. return cps;
  13247. };
  13248. function buildPath$1(ctx, shape, closePath) {
  13249. var points = shape.points;
  13250. var smooth = shape.smooth;
  13251. if (points && points.length >= 2) {
  13252. if (smooth && smooth !== 'spline') {
  13253. var controlPoints = smoothBezier(
  13254. points, smooth, closePath, shape.smoothConstraint
  13255. );
  13256. ctx.moveTo(points[0][0], points[0][1]);
  13257. var len = points.length;
  13258. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13259. var cp1 = controlPoints[i * 2];
  13260. var cp2 = controlPoints[i * 2 + 1];
  13261. var p = points[(i + 1) % len];
  13262. ctx.bezierCurveTo(
  13263. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  13264. );
  13265. }
  13266. }
  13267. else {
  13268. if (smooth === 'spline') {
  13269. points = smoothSpline(points, closePath);
  13270. }
  13271. ctx.moveTo(points[0][0], points[0][1]);
  13272. for (var i = 1, l = points.length; i < l; i++) {
  13273. ctx.lineTo(points[i][0], points[i][1]);
  13274. }
  13275. }
  13276. closePath && ctx.closePath();
  13277. }
  13278. }
  13279. /**
  13280. * 多边形
  13281. * @module zrender/shape/Polygon
  13282. */
  13283. var Polygon = Path.extend({
  13284. type: 'polygon',
  13285. shape: {
  13286. points: null,
  13287. smooth: false,
  13288. smoothConstraint: null
  13289. },
  13290. buildPath: function (ctx, shape) {
  13291. buildPath$1(ctx, shape, true);
  13292. }
  13293. });
  13294. /**
  13295. * @module zrender/graphic/shape/Polyline
  13296. */
  13297. var Polyline = Path.extend({
  13298. type: 'polyline',
  13299. shape: {
  13300. points: null,
  13301. smooth: false,
  13302. smoothConstraint: null
  13303. },
  13304. style: {
  13305. stroke: '#000',
  13306. fill: null
  13307. },
  13308. buildPath: function (ctx, shape) {
  13309. buildPath$1(ctx, shape, false);
  13310. }
  13311. });
  13312. /**
  13313. * 矩形
  13314. * @module zrender/graphic/shape/Rect
  13315. */
  13316. var Rect = Path.extend({
  13317. type: 'rect',
  13318. shape: {
  13319. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  13320. // r缩写为1 相当于 [1, 1, 1, 1]
  13321. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13322. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  13323. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  13324. r: 0,
  13325. x: 0,
  13326. y: 0,
  13327. width: 0,
  13328. height: 0
  13329. },
  13330. buildPath: function (ctx, shape) {
  13331. var x = shape.x;
  13332. var y = shape.y;
  13333. var width = shape.width;
  13334. var height = shape.height;
  13335. if (!shape.r) {
  13336. ctx.rect(x, y, width, height);
  13337. }
  13338. else {
  13339. buildPath(ctx, shape);
  13340. }
  13341. ctx.closePath();
  13342. return;
  13343. }
  13344. });
  13345. /**
  13346. * 直线
  13347. * @module zrender/graphic/shape/Line
  13348. */
  13349. var Line = Path.extend({
  13350. type: 'line',
  13351. shape: {
  13352. // Start point
  13353. x1: 0,
  13354. y1: 0,
  13355. // End point
  13356. x2: 0,
  13357. y2: 0,
  13358. percent: 1
  13359. },
  13360. style: {
  13361. stroke: '#000',
  13362. fill: null
  13363. },
  13364. buildPath: function (ctx, shape) {
  13365. var x1 = shape.x1;
  13366. var y1 = shape.y1;
  13367. var x2 = shape.x2;
  13368. var y2 = shape.y2;
  13369. var percent = shape.percent;
  13370. if (percent === 0) {
  13371. return;
  13372. }
  13373. ctx.moveTo(x1, y1);
  13374. if (percent < 1) {
  13375. x2 = x1 * (1 - percent) + x2 * percent;
  13376. y2 = y1 * (1 - percent) + y2 * percent;
  13377. }
  13378. ctx.lineTo(x2, y2);
  13379. },
  13380. /**
  13381. * Get point at percent
  13382. * @param {number} percent
  13383. * @return {Array.<number>}
  13384. */
  13385. pointAt: function (p) {
  13386. var shape = this.shape;
  13387. return [
  13388. shape.x1 * (1 - p) + shape.x2 * p,
  13389. shape.y1 * (1 - p) + shape.y2 * p
  13390. ];
  13391. }
  13392. });
  13393. /**
  13394. * 贝塞尔曲线
  13395. * @module zrender/shape/BezierCurve
  13396. */
  13397. var out = [];
  13398. function someVectorAt(shape, t, isTangent) {
  13399. var cpx2 = shape.cpx2;
  13400. var cpy2 = shape.cpy2;
  13401. if (cpx2 === null || cpy2 === null) {
  13402. return [
  13403. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13404. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13405. ];
  13406. }
  13407. else {
  13408. return [
  13409. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13410. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13411. ];
  13412. }
  13413. }
  13414. var BezierCurve = Path.extend({
  13415. type: 'bezier-curve',
  13416. shape: {
  13417. x1: 0,
  13418. y1: 0,
  13419. x2: 0,
  13420. y2: 0,
  13421. cpx1: 0,
  13422. cpy1: 0,
  13423. // cpx2: 0,
  13424. // cpy2: 0
  13425. // Curve show percent, for animating
  13426. percent: 1
  13427. },
  13428. style: {
  13429. stroke: '#000',
  13430. fill: null
  13431. },
  13432. buildPath: function (ctx, shape) {
  13433. var x1 = shape.x1;
  13434. var y1 = shape.y1;
  13435. var x2 = shape.x2;
  13436. var y2 = shape.y2;
  13437. var cpx1 = shape.cpx1;
  13438. var cpy1 = shape.cpy1;
  13439. var cpx2 = shape.cpx2;
  13440. var cpy2 = shape.cpy2;
  13441. var percent = shape.percent;
  13442. if (percent === 0) {
  13443. return;
  13444. }
  13445. ctx.moveTo(x1, y1);
  13446. if (cpx2 == null || cpy2 == null) {
  13447. if (percent < 1) {
  13448. quadraticSubdivide(
  13449. x1, cpx1, x2, percent, out
  13450. );
  13451. cpx1 = out[1];
  13452. x2 = out[2];
  13453. quadraticSubdivide(
  13454. y1, cpy1, y2, percent, out
  13455. );
  13456. cpy1 = out[1];
  13457. y2 = out[2];
  13458. }
  13459. ctx.quadraticCurveTo(
  13460. cpx1, cpy1,
  13461. x2, y2
  13462. );
  13463. }
  13464. else {
  13465. if (percent < 1) {
  13466. cubicSubdivide(
  13467. x1, cpx1, cpx2, x2, percent, out
  13468. );
  13469. cpx1 = out[1];
  13470. cpx2 = out[2];
  13471. x2 = out[3];
  13472. cubicSubdivide(
  13473. y1, cpy1, cpy2, y2, percent, out
  13474. );
  13475. cpy1 = out[1];
  13476. cpy2 = out[2];
  13477. y2 = out[3];
  13478. }
  13479. ctx.bezierCurveTo(
  13480. cpx1, cpy1,
  13481. cpx2, cpy2,
  13482. x2, y2
  13483. );
  13484. }
  13485. },
  13486. /**
  13487. * Get point at percent
  13488. * @param {number} t
  13489. * @return {Array.<number>}
  13490. */
  13491. pointAt: function (t) {
  13492. return someVectorAt(this.shape, t, false);
  13493. },
  13494. /**
  13495. * Get tangent at percent
  13496. * @param {number} t
  13497. * @return {Array.<number>}
  13498. */
  13499. tangentAt: function (t) {
  13500. var p = someVectorAt(this.shape, t, true);
  13501. return normalize(p, p);
  13502. }
  13503. });
  13504. /**
  13505. * 圆弧
  13506. * @module zrender/graphic/shape/Arc
  13507. */
  13508. var Arc = Path.extend({
  13509. type: 'arc',
  13510. shape: {
  13511. cx: 0,
  13512. cy: 0,
  13513. r: 0,
  13514. startAngle: 0,
  13515. endAngle: Math.PI * 2,
  13516. clockwise: true
  13517. },
  13518. style: {
  13519. stroke: '#000',
  13520. fill: null
  13521. },
  13522. buildPath: function (ctx, shape) {
  13523. var x = shape.cx;
  13524. var y = shape.cy;
  13525. var r = Math.max(shape.r, 0);
  13526. var startAngle = shape.startAngle;
  13527. var endAngle = shape.endAngle;
  13528. var clockwise = shape.clockwise;
  13529. var unitX = Math.cos(startAngle);
  13530. var unitY = Math.sin(startAngle);
  13531. ctx.moveTo(unitX * r + x, unitY * r + y);
  13532. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13533. }
  13534. });
  13535. // CompoundPath to improve performance
  13536. var CompoundPath = Path.extend({
  13537. type: 'compound',
  13538. shape: {
  13539. paths: null
  13540. },
  13541. _updatePathDirty: function () {
  13542. var dirtyPath = this.__dirtyPath;
  13543. var paths = this.shape.paths;
  13544. for (var i = 0; i < paths.length; i++) {
  13545. // Mark as dirty if any subpath is dirty
  13546. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  13547. }
  13548. this.__dirtyPath = dirtyPath;
  13549. this.__dirty = this.__dirty || dirtyPath;
  13550. },
  13551. beforeBrush: function () {
  13552. this._updatePathDirty();
  13553. var paths = this.shape.paths || [];
  13554. var scale = this.getGlobalScale();
  13555. // Update path scale
  13556. for (var i = 0; i < paths.length; i++) {
  13557. if (!paths[i].path) {
  13558. paths[i].createPathProxy();
  13559. }
  13560. paths[i].path.setScale(scale[0], scale[1]);
  13561. }
  13562. },
  13563. buildPath: function (ctx, shape) {
  13564. var paths = shape.paths || [];
  13565. for (var i = 0; i < paths.length; i++) {
  13566. paths[i].buildPath(ctx, paths[i].shape, true);
  13567. }
  13568. },
  13569. afterBrush: function () {
  13570. var paths = this.shape.paths || [];
  13571. for (var i = 0; i < paths.length; i++) {
  13572. paths[i].__dirtyPath = false;
  13573. }
  13574. },
  13575. getBoundingRect: function () {
  13576. this._updatePathDirty();
  13577. return Path.prototype.getBoundingRect.call(this);
  13578. }
  13579. });
  13580. /**
  13581. * @param {Array.<Object>} colorStops
  13582. */
  13583. var Gradient = function (colorStops) {
  13584. this.colorStops = colorStops || [];
  13585. };
  13586. Gradient.prototype = {
  13587. constructor: Gradient,
  13588. addColorStop: function (offset, color) {
  13589. this.colorStops.push({
  13590. offset: offset,
  13591. color: color
  13592. });
  13593. }
  13594. };
  13595. /**
  13596. * x, y, x2, y2 are all percent from 0 to 1
  13597. * @param {number} [x=0]
  13598. * @param {number} [y=0]
  13599. * @param {number} [x2=1]
  13600. * @param {number} [y2=0]
  13601. * @param {Array.<Object>} colorStops
  13602. * @param {boolean} [globalCoord=false]
  13603. */
  13604. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  13605. // Should do nothing more in this constructor. Because gradient can be
  13606. // declard by `color: {type: 'linear', colorStops: ...}`, where
  13607. // this constructor will not be called.
  13608. this.x = x == null ? 0 : x;
  13609. this.y = y == null ? 0 : y;
  13610. this.x2 = x2 == null ? 1 : x2;
  13611. this.y2 = y2 == null ? 0 : y2;
  13612. // Can be cloned
  13613. this.type = 'linear';
  13614. // If use global coord
  13615. this.global = globalCoord || false;
  13616. Gradient.call(this, colorStops);
  13617. };
  13618. LinearGradient.prototype = {
  13619. constructor: LinearGradient
  13620. };
  13621. inherits(LinearGradient, Gradient);
  13622. /**
  13623. * x, y, r are all percent from 0 to 1
  13624. * @param {number} [x=0.5]
  13625. * @param {number} [y=0.5]
  13626. * @param {number} [r=0.5]
  13627. * @param {Array.<Object>} [colorStops]
  13628. * @param {boolean} [globalCoord=false]
  13629. */
  13630. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  13631. // Should do nothing more in this constructor. Because gradient can be
  13632. // declard by `color: {type: 'radial', colorStops: ...}`, where
  13633. // this constructor will not be called.
  13634. this.x = x == null ? 0.5 : x;
  13635. this.y = y == null ? 0.5 : y;
  13636. this.r = r == null ? 0.5 : r;
  13637. // Can be cloned
  13638. this.type = 'radial';
  13639. // If use global coord
  13640. this.global = globalCoord || false;
  13641. Gradient.call(this, colorStops);
  13642. };
  13643. RadialGradient.prototype = {
  13644. constructor: RadialGradient
  13645. };
  13646. inherits(RadialGradient, Gradient);
  13647. var round$1 = Math.round;
  13648. var mathMax$1 = Math.max;
  13649. var mathMin$1 = Math.min;
  13650. var EMPTY_OBJ = {};
  13651. /**
  13652. * Extend shape with parameters
  13653. */
  13654. function extendShape(opts) {
  13655. return Path.extend(opts);
  13656. }
  13657. /**
  13658. * Extend path
  13659. */
  13660. function extendPath(pathData, opts) {
  13661. return extendFromString(pathData, opts);
  13662. }
  13663. /**
  13664. * Create a path element from path data string
  13665. * @param {string} pathData
  13666. * @param {Object} opts
  13667. * @param {module:zrender/core/BoundingRect} rect
  13668. * @param {string} [layout=cover] 'center' or 'cover'
  13669. */
  13670. function makePath(pathData, opts, rect, layout) {
  13671. var path = createFromString(pathData, opts);
  13672. var boundingRect = path.getBoundingRect();
  13673. if (rect) {
  13674. if (layout === 'center') {
  13675. rect = centerGraphic(rect, boundingRect);
  13676. }
  13677. resizePath(path, rect);
  13678. }
  13679. return path;
  13680. }
  13681. /**
  13682. * Create a image element from image url
  13683. * @param {string} imageUrl image url
  13684. * @param {Object} opts options
  13685. * @param {module:zrender/core/BoundingRect} rect constrain rect
  13686. * @param {string} [layout=cover] 'center' or 'cover'
  13687. */
  13688. function makeImage(imageUrl, rect, layout) {
  13689. var path = new ZImage({
  13690. style: {
  13691. image: imageUrl,
  13692. x: rect.x,
  13693. y: rect.y,
  13694. width: rect.width,
  13695. height: rect.height
  13696. },
  13697. onload: function (img) {
  13698. if (layout === 'center') {
  13699. var boundingRect = {
  13700. width: img.width,
  13701. height: img.height
  13702. };
  13703. path.setStyle(centerGraphic(rect, boundingRect));
  13704. }
  13705. }
  13706. });
  13707. return path;
  13708. }
  13709. /**
  13710. * Get position of centered element in bounding box.
  13711. *
  13712. * @param {Object} rect element local bounding box
  13713. * @param {Object} boundingRect constraint bounding box
  13714. * @return {Object} element position containing x, y, width, and height
  13715. */
  13716. function centerGraphic(rect, boundingRect) {
  13717. // Set rect to center, keep width / height ratio.
  13718. var aspect = boundingRect.width / boundingRect.height;
  13719. var width = rect.height * aspect;
  13720. var height;
  13721. if (width <= rect.width) {
  13722. height = rect.height;
  13723. }
  13724. else {
  13725. width = rect.width;
  13726. height = width / aspect;
  13727. }
  13728. var cx = rect.x + rect.width / 2;
  13729. var cy = rect.y + rect.height / 2;
  13730. return {
  13731. x: cx - width / 2,
  13732. y: cy - height / 2,
  13733. width: width,
  13734. height: height
  13735. };
  13736. }
  13737. var mergePath = mergePath$1;
  13738. /**
  13739. * Resize a path to fit the rect
  13740. * @param {module:zrender/graphic/Path} path
  13741. * @param {Object} rect
  13742. */
  13743. function resizePath(path, rect) {
  13744. if (!path.applyTransform) {
  13745. return;
  13746. }
  13747. var pathRect = path.getBoundingRect();
  13748. var m = pathRect.calculateTransform(rect);
  13749. path.applyTransform(m);
  13750. }
  13751. /**
  13752. * Sub pixel optimize line for canvas
  13753. *
  13754. * @param {Object} param
  13755. * @param {Object} [param.shape]
  13756. * @param {number} [param.shape.x1]
  13757. * @param {number} [param.shape.y1]
  13758. * @param {number} [param.shape.x2]
  13759. * @param {number} [param.shape.y2]
  13760. * @param {Object} [param.style]
  13761. * @param {number} [param.style.lineWidth]
  13762. * @return {Object} Modified param
  13763. */
  13764. function subPixelOptimizeLine(param) {
  13765. var shape = param.shape;
  13766. var lineWidth = param.style.lineWidth;
  13767. if (round$1(shape.x1 * 2) === round$1(shape.x2 * 2)) {
  13768. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  13769. }
  13770. if (round$1(shape.y1 * 2) === round$1(shape.y2 * 2)) {
  13771. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  13772. }
  13773. return param;
  13774. }
  13775. /**
  13776. * Sub pixel optimize rect for canvas
  13777. *
  13778. * @param {Object} param
  13779. * @param {Object} [param.shape]
  13780. * @param {number} [param.shape.x]
  13781. * @param {number} [param.shape.y]
  13782. * @param {number} [param.shape.width]
  13783. * @param {number} [param.shape.height]
  13784. * @param {Object} [param.style]
  13785. * @param {number} [param.style.lineWidth]
  13786. * @return {Object} Modified param
  13787. */
  13788. function subPixelOptimizeRect(param) {
  13789. var shape = param.shape;
  13790. var lineWidth = param.style.lineWidth;
  13791. var originX = shape.x;
  13792. var originY = shape.y;
  13793. var originWidth = shape.width;
  13794. var originHeight = shape.height;
  13795. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  13796. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  13797. shape.width = Math.max(
  13798. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  13799. originWidth === 0 ? 0 : 1
  13800. );
  13801. shape.height = Math.max(
  13802. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  13803. originHeight === 0 ? 0 : 1
  13804. );
  13805. return param;
  13806. }
  13807. /**
  13808. * Sub pixel optimize for canvas
  13809. *
  13810. * @param {number} position Coordinate, such as x, y
  13811. * @param {number} lineWidth Should be nonnegative integer.
  13812. * @param {boolean=} positiveOrNegative Default false (negative).
  13813. * @return {number} Optimized position.
  13814. */
  13815. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  13816. // Assure that (position + lineWidth / 2) is near integer edge,
  13817. // otherwise line will be fuzzy in canvas.
  13818. var doubledPosition = round$1(position * 2);
  13819. return (doubledPosition + round$1(lineWidth)) % 2 === 0
  13820. ? doubledPosition / 2
  13821. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  13822. }
  13823. function hasFillOrStroke(fillOrStroke) {
  13824. return fillOrStroke != null && fillOrStroke != 'none';
  13825. }
  13826. function liftColor(color) {
  13827. return typeof color === 'string' ? lift(color, -0.1) : color;
  13828. }
  13829. /**
  13830. * @private
  13831. */
  13832. function cacheElementStl(el) {
  13833. if (el.__hoverStlDirty) {
  13834. var stroke = el.style.stroke;
  13835. var fill = el.style.fill;
  13836. // Create hoverStyle on mouseover
  13837. var hoverStyle = el.__hoverStl;
  13838. hoverStyle.fill = hoverStyle.fill
  13839. || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  13840. hoverStyle.stroke = hoverStyle.stroke
  13841. || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  13842. var normalStyle = {};
  13843. for (var name in hoverStyle) {
  13844. // See comment in `doSingleEnterHover`.
  13845. if (hoverStyle[name] != null) {
  13846. normalStyle[name] = el.style[name];
  13847. }
  13848. }
  13849. el.__normalStl = normalStyle;
  13850. el.__hoverStlDirty = false;
  13851. }
  13852. }
  13853. /**
  13854. * @private
  13855. */
  13856. function doSingleEnterHover(el) {
  13857. if (el.__isHover) {
  13858. return;
  13859. }
  13860. cacheElementStl(el);
  13861. if (el.useHoverLayer) {
  13862. el.__zr && el.__zr.addHover(el, el.__hoverStl);
  13863. }
  13864. else {
  13865. var style = el.style;
  13866. var insideRollbackOpt = style.insideRollbackOpt;
  13867. // Consider case: only `position: 'top'` is set on emphasis, then text
  13868. // color should be returned to `autoColor`, rather than remain '#fff'.
  13869. // So we should rollback then apply again after style merging.
  13870. insideRollbackOpt && rollbackInsideStyle(style);
  13871. // styles can be:
  13872. // {
  13873. // label: {
  13874. // normal: {
  13875. // show: false,
  13876. // position: 'outside',
  13877. // fontSize: 18
  13878. // },
  13879. // emphasis: {
  13880. // show: true
  13881. // }
  13882. // }
  13883. // },
  13884. // where properties of `emphasis` may not appear in `normal`. We previously use
  13885. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  13886. // But consider rich text and setOption in merge mode, it is impossible to cover
  13887. // all properties in merge. So we use merge mode when setting style here, where
  13888. // only properties that is not `null/undefined` can be set. The disadventage:
  13889. // null/undefined can not be used to remove style any more in `emphasis`.
  13890. style.extendFrom(el.__hoverStl);
  13891. // Do not save `insideRollback`.
  13892. if (insideRollbackOpt) {
  13893. applyInsideStyle(style, style.insideOriginalTextPosition, insideRollbackOpt);
  13894. // textFill may be rollbacked to null.
  13895. if (style.textFill == null) {
  13896. style.textFill = insideRollbackOpt.autoColor;
  13897. }
  13898. }
  13899. el.dirty(false);
  13900. el.z2 += 1;
  13901. }
  13902. el.__isHover = true;
  13903. }
  13904. /**
  13905. * @inner
  13906. */
  13907. function doSingleLeaveHover(el) {
  13908. if (!el.__isHover) {
  13909. return;
  13910. }
  13911. var normalStl = el.__normalStl;
  13912. if (el.useHoverLayer) {
  13913. el.__zr && el.__zr.removeHover(el);
  13914. }
  13915. else {
  13916. // Consider null/undefined value, should use
  13917. // `setStyle` but not `extendFrom(stl, true)`.
  13918. normalStl && el.setStyle(normalStl);
  13919. el.z2 -= 1;
  13920. }
  13921. el.__isHover = false;
  13922. }
  13923. /**
  13924. * @inner
  13925. */
  13926. function doEnterHover(el) {
  13927. el.type === 'group'
  13928. ? el.traverse(function (child) {
  13929. if (child.type !== 'group') {
  13930. doSingleEnterHover(child);
  13931. }
  13932. })
  13933. : doSingleEnterHover(el);
  13934. }
  13935. function doLeaveHover(el) {
  13936. el.type === 'group'
  13937. ? el.traverse(function (child) {
  13938. if (child.type !== 'group') {
  13939. doSingleLeaveHover(child);
  13940. }
  13941. })
  13942. : doSingleLeaveHover(el);
  13943. }
  13944. /**
  13945. * @inner
  13946. */
  13947. function setElementHoverStl(el, hoverStl) {
  13948. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  13949. // Often used when item group has a label element and it's hoverStyle is different
  13950. el.__hoverStl = el.hoverStyle || hoverStl || {};
  13951. el.__hoverStlDirty = true;
  13952. if (el.__isHover) {
  13953. cacheElementStl(el);
  13954. }
  13955. }
  13956. /**
  13957. * @inner
  13958. */
  13959. function onElementMouseOver(e) {
  13960. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  13961. return;
  13962. }
  13963. // Only if element is not in emphasis status
  13964. !this.__isEmphasis && doEnterHover(this);
  13965. }
  13966. /**
  13967. * @inner
  13968. */
  13969. function onElementMouseOut(e) {
  13970. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  13971. return;
  13972. }
  13973. // Only if element is not in emphasis status
  13974. !this.__isEmphasis && doLeaveHover(this);
  13975. }
  13976. /**
  13977. * @inner
  13978. */
  13979. function enterEmphasis() {
  13980. this.__isEmphasis = true;
  13981. doEnterHover(this);
  13982. }
  13983. /**
  13984. * @inner
  13985. */
  13986. function leaveEmphasis() {
  13987. this.__isEmphasis = false;
  13988. doLeaveHover(this);
  13989. }
  13990. /**
  13991. * Set hover style of element.
  13992. * This method can be called repeatly without side-effects.
  13993. * @param {module:zrender/Element} el
  13994. * @param {Object} [hoverStyle]
  13995. * @param {Object} [opt]
  13996. * @param {boolean} [opt.hoverSilentOnTouch=false]
  13997. * In touch device, mouseover event will be trigger on touchstart event
  13998. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  13999. * conviniently use hoverStyle when tap on touch screen without additional
  14000. * code for compatibility.
  14001. * But if the chart/component has select feature, which usually also use
  14002. * hoverStyle, there might be conflict between 'select-highlight' and
  14003. * 'hover-highlight' especially when roam is enabled (see geo for example).
  14004. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  14005. * on touch device.
  14006. */
  14007. function setHoverStyle(el, hoverStyle, opt) {
  14008. el.__hoverSilentOnTouch = opt && opt.hoverSilentOnTouch;
  14009. el.type === 'group'
  14010. ? el.traverse(function (child) {
  14011. if (child.type !== 'group') {
  14012. setElementHoverStl(child, hoverStyle);
  14013. }
  14014. })
  14015. : setElementHoverStl(el, hoverStyle);
  14016. // Duplicated function will be auto-ignored, see Eventful.js.
  14017. el.on('mouseover', onElementMouseOver)
  14018. .on('mouseout', onElementMouseOut);
  14019. // Emphasis, normal can be triggered manually
  14020. el.on('emphasis', enterEmphasis)
  14021. .on('normal', leaveEmphasis);
  14022. }
  14023. /**
  14024. * @param {Object|module:zrender/graphic/Style} normalStyle
  14025. * @param {Object} emphasisStyle
  14026. * @param {module:echarts/model/Model} normalModel
  14027. * @param {module:echarts/model/Model} emphasisModel
  14028. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  14029. * @param {Object} [opt.defaultText]
  14030. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  14031. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14032. * @param {module:echarts/model/Model} [opt.labelDataIndex] Fetch text by
  14033. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14034. * @param {module:echarts/model/Model} [opt.labelDimIndex] Fetch text by
  14035. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14036. * @param {Object} [normalSpecified]
  14037. * @param {Object} [emphasisSpecified]
  14038. */
  14039. function setLabelStyle(
  14040. normalStyle, emphasisStyle,
  14041. normalModel, emphasisModel,
  14042. opt,
  14043. normalSpecified, emphasisSpecified
  14044. ) {
  14045. opt = opt || EMPTY_OBJ;
  14046. var labelFetcher = opt.labelFetcher;
  14047. var labelDataIndex = opt.labelDataIndex;
  14048. var labelDimIndex = opt.labelDimIndex;
  14049. // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  14050. // is not supported util someone requests.
  14051. var showNormal = normalModel.getShallow('show');
  14052. var showEmphasis = emphasisModel.getShallow('show');
  14053. // Consider performance, only fetch label when necessary.
  14054. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  14055. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  14056. var baseText = (showNormal || showEmphasis)
  14057. ? retrieve2(
  14058. labelFetcher
  14059. ? labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex)
  14060. : null,
  14061. opt.defaultText
  14062. )
  14063. : null;
  14064. var normalStyleText = showNormal ? baseText : null;
  14065. var emphasisStyleText = showEmphasis
  14066. ? retrieve2(
  14067. labelFetcher
  14068. ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex)
  14069. : null,
  14070. baseText
  14071. )
  14072. : null;
  14073. // Optimize: If style.text is null, text will not be drawn.
  14074. if (normalStyleText != null || emphasisStyleText != null) {
  14075. // Always set `textStyle` even if `normalStyle.text` is null, because default
  14076. // values have to be set on `normalStyle`.
  14077. // If we set default values on `emphasisStyle`, consider case:
  14078. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  14079. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  14080. // Then the 'red' will not work on emphasis.
  14081. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  14082. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  14083. }
  14084. normalStyle.text = normalStyleText;
  14085. emphasisStyle.text = emphasisStyleText;
  14086. }
  14087. /**
  14088. * Set basic textStyle properties.
  14089. * @param {Object|module:zrender/graphic/Style} textStyle
  14090. * @param {module:echarts/model/Model} model
  14091. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  14092. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  14093. * @param {boolean} [isEmphasis]
  14094. */
  14095. function setTextStyle(
  14096. textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis
  14097. ) {
  14098. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  14099. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  14100. textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14101. return textStyle;
  14102. }
  14103. /**
  14104. * Set text option in the style.
  14105. * @deprecated
  14106. * @param {Object} textStyle
  14107. * @param {module:echarts/model/Model} labelModel
  14108. * @param {string|boolean} defaultColor Default text color.
  14109. * If set as false, it will be processed as a emphasis style.
  14110. */
  14111. function setText(textStyle, labelModel, defaultColor) {
  14112. var opt = {isRectText: true};
  14113. var isEmphasis;
  14114. if (defaultColor === false) {
  14115. isEmphasis = true;
  14116. }
  14117. else {
  14118. // Support setting color as 'auto' to get visual color.
  14119. opt.autoColor = defaultColor;
  14120. }
  14121. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);
  14122. textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14123. }
  14124. /**
  14125. * {
  14126. * disableBox: boolean, Whether diable drawing box of block (outer most).
  14127. * isRectText: boolean,
  14128. * autoColor: string, specify a color when color is 'auto',
  14129. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  14130. * If autoColor specified, it is used as default textFill.
  14131. * useInsideStyle:
  14132. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  14133. * if `textFill` is not specified.
  14134. * `false`: Do not use inside style.
  14135. * `null/undefined`: use inside style if `isRectText` is true and
  14136. * `textFill` is not specified and textPosition contains `'inside'`.
  14137. * forceRich: boolean
  14138. * }
  14139. */
  14140. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  14141. // Consider there will be abnormal when merge hover style to normal style if given default value.
  14142. opt = opt || EMPTY_OBJ;
  14143. if (opt.isRectText) {
  14144. var textPosition = textStyleModel.getShallow('position')
  14145. || (isEmphasis ? null : 'inside');
  14146. // 'outside' is not a valid zr textPostion value, but used
  14147. // in bar series, and magric type should be considered.
  14148. textPosition === 'outside' && (textPosition = 'top');
  14149. textStyle.textPosition = textPosition;
  14150. textStyle.textOffset = textStyleModel.getShallow('offset');
  14151. var labelRotate = textStyleModel.getShallow('rotate');
  14152. labelRotate != null && (labelRotate *= Math.PI / 180);
  14153. textStyle.textRotation = labelRotate;
  14154. textStyle.textDistance = retrieve2(
  14155. textStyleModel.getShallow('distance'), isEmphasis ? null : 5
  14156. );
  14157. }
  14158. var ecModel = textStyleModel.ecModel;
  14159. var globalTextStyle = ecModel && ecModel.option.textStyle;
  14160. // Consider case:
  14161. // {
  14162. // data: [{
  14163. // value: 12,
  14164. // label: {
  14165. // normal: {
  14166. // rich: {
  14167. // // no 'a' here but using parent 'a'.
  14168. // }
  14169. // }
  14170. // }
  14171. // }],
  14172. // rich: {
  14173. // a: { ... }
  14174. // }
  14175. // }
  14176. var richItemNames = getRichItemNames(textStyleModel);
  14177. var richResult;
  14178. if (richItemNames) {
  14179. richResult = {};
  14180. for (var name in richItemNames) {
  14181. if (richItemNames.hasOwnProperty(name)) {
  14182. // Cascade is supported in rich.
  14183. var richTextStyle = textStyleModel.getModel(['rich', name]);
  14184. // In rich, never `disableBox`.
  14185. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  14186. }
  14187. }
  14188. }
  14189. textStyle.rich = richResult;
  14190. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  14191. if (opt.forceRich && !opt.textStyle) {
  14192. opt.textStyle = {};
  14193. }
  14194. return textStyle;
  14195. }
  14196. // Consider case:
  14197. // {
  14198. // data: [{
  14199. // value: 12,
  14200. // label: {
  14201. // normal: {
  14202. // rich: {
  14203. // // no 'a' here but using parent 'a'.
  14204. // }
  14205. // }
  14206. // }
  14207. // }],
  14208. // rich: {
  14209. // a: { ... }
  14210. // }
  14211. // }
  14212. function getRichItemNames(textStyleModel) {
  14213. // Use object to remove duplicated names.
  14214. var richItemNameMap;
  14215. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  14216. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  14217. if (rich) {
  14218. richItemNameMap = richItemNameMap || {};
  14219. for (var name in rich) {
  14220. if (rich.hasOwnProperty(name)) {
  14221. richItemNameMap[name] = 1;
  14222. }
  14223. }
  14224. }
  14225. textStyleModel = textStyleModel.parentModel;
  14226. }
  14227. return richItemNameMap;
  14228. }
  14229. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  14230. // In merge mode, default value should not be given.
  14231. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  14232. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt)
  14233. || globalTextStyle.color;
  14234. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt)
  14235. || globalTextStyle.textBorderColor;
  14236. textStyle.textStrokeWidth = retrieve2(
  14237. textStyleModel.getShallow('textBorderWidth'),
  14238. globalTextStyle.textBorderWidth
  14239. );
  14240. if (!isEmphasis) {
  14241. if (isBlock) {
  14242. // Always set `insideRollback`, for clearing previous.
  14243. var originalTextPosition = textStyle.textPosition;
  14244. textStyle.insideRollback = applyInsideStyle(textStyle, originalTextPosition, opt);
  14245. // Save original textPosition, because style.textPosition will be repalced by
  14246. // real location (like [10, 30]) in zrender.
  14247. textStyle.insideOriginalTextPosition = originalTextPosition;
  14248. textStyle.insideRollbackOpt = opt;
  14249. }
  14250. // Set default finally.
  14251. if (textStyle.textFill == null) {
  14252. textStyle.textFill = opt.autoColor;
  14253. }
  14254. }
  14255. // Do not use `getFont` here, because merge should be supported, where
  14256. // part of these properties may be changed in emphasis style, and the
  14257. // others should remain their original value got from normal style.
  14258. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  14259. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  14260. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  14261. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  14262. textStyle.textAlign = textStyleModel.getShallow('align');
  14263. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign')
  14264. || textStyleModel.getShallow('baseline');
  14265. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  14266. textStyle.textWidth = textStyleModel.getShallow('width');
  14267. textStyle.textHeight = textStyleModel.getShallow('height');
  14268. textStyle.textTag = textStyleModel.getShallow('tag');
  14269. if (!isBlock || !opt.disableBox) {
  14270. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  14271. textStyle.textPadding = textStyleModel.getShallow('padding');
  14272. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  14273. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  14274. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  14275. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  14276. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  14277. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  14278. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  14279. }
  14280. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor')
  14281. || globalTextStyle.textShadowColor;
  14282. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur')
  14283. || globalTextStyle.textShadowBlur;
  14284. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX')
  14285. || globalTextStyle.textShadowOffsetX;
  14286. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY')
  14287. || globalTextStyle.textShadowOffsetY;
  14288. }
  14289. function getAutoColor(color, opt) {
  14290. return color !== 'auto' ? color : (opt && opt.autoColor) ? opt.autoColor : null;
  14291. }
  14292. function applyInsideStyle(textStyle, textPosition, opt) {
  14293. var useInsideStyle = opt.useInsideStyle;
  14294. var insideRollback;
  14295. if (textStyle.textFill == null
  14296. && useInsideStyle !== false
  14297. && (useInsideStyle === true
  14298. || (opt.isRectText
  14299. && textPosition
  14300. // textPosition can be [10, 30]
  14301. && typeof textPosition === 'string'
  14302. && textPosition.indexOf('inside') >= 0
  14303. )
  14304. )
  14305. ) {
  14306. insideRollback = {
  14307. textFill: null,
  14308. textStroke: textStyle.textStroke,
  14309. textStrokeWidth: textStyle.textStrokeWidth
  14310. };
  14311. textStyle.textFill = '#fff';
  14312. // Consider text with #fff overflow its container.
  14313. if (textStyle.textStroke == null) {
  14314. textStyle.textStroke = opt.autoColor;
  14315. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  14316. }
  14317. }
  14318. return insideRollback;
  14319. }
  14320. function rollbackInsideStyle(style) {
  14321. var insideRollback = style.insideRollback;
  14322. if (insideRollback) {
  14323. style.textFill = insideRollback.textFill;
  14324. style.textStroke = insideRollback.textStroke;
  14325. style.textStrokeWidth = insideRollback.textStrokeWidth;
  14326. }
  14327. }
  14328. function getFont(opt, ecModel) {
  14329. // ecModel or default text style model.
  14330. var gTextStyleModel = ecModel || ecModel.getModel('textStyle');
  14331. return [
  14332. // FIXME in node-canvas fontWeight is before fontStyle
  14333. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',
  14334. opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',
  14335. (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',
  14336. opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'
  14337. ].join(' ');
  14338. }
  14339. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  14340. if (typeof dataIndex === 'function') {
  14341. cb = dataIndex;
  14342. dataIndex = null;
  14343. }
  14344. // Do not check 'animation' property directly here. Consider this case:
  14345. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  14346. // but its parent model (`seriesModel`) does.
  14347. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  14348. if (animationEnabled) {
  14349. var postfix = isUpdate ? 'Update' : '';
  14350. var duration = animatableModel.getShallow('animationDuration' + postfix);
  14351. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  14352. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  14353. if (typeof animationDelay === 'function') {
  14354. animationDelay = animationDelay(
  14355. dataIndex,
  14356. animatableModel.getAnimationDelayParams
  14357. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  14358. : null
  14359. );
  14360. }
  14361. if (typeof duration === 'function') {
  14362. duration = duration(dataIndex);
  14363. }
  14364. duration > 0
  14365. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb)
  14366. : (el.stopAnimation(), el.attr(props), cb && cb());
  14367. }
  14368. else {
  14369. el.stopAnimation();
  14370. el.attr(props);
  14371. cb && cb();
  14372. }
  14373. }
  14374. /**
  14375. * Update graphic element properties with or without animation according to the
  14376. * configuration in series.
  14377. *
  14378. * Caution: this method will stop previous animation.
  14379. * So if do not use this method to one element twice before
  14380. * animation starts, unless you know what you are doing.
  14381. *
  14382. * @param {module:zrender/Element} el
  14383. * @param {Object} props
  14384. * @param {module:echarts/model/Model} [animatableModel]
  14385. * @param {number} [dataIndex]
  14386. * @param {Function} [cb]
  14387. * @example
  14388. * graphic.updateProps(el, {
  14389. * position: [100, 100]
  14390. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  14391. * // Or
  14392. * graphic.updateProps(el, {
  14393. * position: [100, 100]
  14394. * }, seriesModel, function () { console.log('Animation done!'); });
  14395. */
  14396. function updateProps(el, props, animatableModel, dataIndex, cb) {
  14397. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  14398. }
  14399. /**
  14400. * Init graphic element properties with or without animation according to the
  14401. * configuration in series.
  14402. *
  14403. * Caution: this method will stop previous animation.
  14404. * So if do not use this method to one element twice before
  14405. * animation starts, unless you know what you are doing.
  14406. *
  14407. * @param {module:zrender/Element} el
  14408. * @param {Object} props
  14409. * @param {module:echarts/model/Model} [animatableModel]
  14410. * @param {number} [dataIndex]
  14411. * @param {Function} cb
  14412. */
  14413. function initProps(el, props, animatableModel, dataIndex, cb) {
  14414. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  14415. }
  14416. /**
  14417. * Get transform matrix of target (param target),
  14418. * in coordinate of its ancestor (param ancestor)
  14419. *
  14420. * @param {module:zrender/mixin/Transformable} target
  14421. * @param {module:zrender/mixin/Transformable} [ancestor]
  14422. */
  14423. function getTransform(target, ancestor) {
  14424. var mat = identity([]);
  14425. while (target && target !== ancestor) {
  14426. mul$1(mat, target.getLocalTransform(), mat);
  14427. target = target.parent;
  14428. }
  14429. return mat;
  14430. }
  14431. /**
  14432. * Apply transform to an vertex.
  14433. * @param {Array.<number>} target [x, y]
  14434. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  14435. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  14436. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  14437. * @param {boolean=} invert Whether use invert matrix.
  14438. * @return {Array.<number>} [x, y]
  14439. */
  14440. function applyTransform$1(target, transform, invert$$1) {
  14441. if (transform && !isArrayLike(transform)) {
  14442. transform = Transformable.getLocalTransform(transform);
  14443. }
  14444. if (invert$$1) {
  14445. transform = invert([], transform);
  14446. }
  14447. return applyTransform([], target, transform);
  14448. }
  14449. /**
  14450. * @param {string} direction 'left' 'right' 'top' 'bottom'
  14451. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  14452. * @param {boolean=} invert Whether use invert matrix.
  14453. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  14454. */
  14455. function transformDirection(direction, transform, invert$$1) {
  14456. // Pick a base, ensure that transform result will not be (0, 0).
  14457. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  14458. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  14459. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  14460. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  14461. var vertex = [
  14462. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  14463. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  14464. ];
  14465. vertex = applyTransform$1(vertex, transform, invert$$1);
  14466. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  14467. ? (vertex[0] > 0 ? 'right' : 'left')
  14468. : (vertex[1] > 0 ? 'bottom' : 'top');
  14469. }
  14470. /**
  14471. * Apply group transition animation from g1 to g2.
  14472. * If no animatableModel, no animation.
  14473. */
  14474. function groupTransition(g1, g2, animatableModel, cb) {
  14475. if (!g1 || !g2) {
  14476. return;
  14477. }
  14478. function getElMap(g) {
  14479. var elMap = {};
  14480. g.traverse(function (el) {
  14481. if (!el.isGroup && el.anid) {
  14482. elMap[el.anid] = el;
  14483. }
  14484. });
  14485. return elMap;
  14486. }
  14487. function getAnimatableProps(el) {
  14488. var obj = {
  14489. position: clone$1(el.position),
  14490. rotation: el.rotation
  14491. };
  14492. if (el.shape) {
  14493. obj.shape = extend({}, el.shape);
  14494. }
  14495. return obj;
  14496. }
  14497. var elMap1 = getElMap(g1);
  14498. g2.traverse(function (el) {
  14499. if (!el.isGroup && el.anid) {
  14500. var oldEl = elMap1[el.anid];
  14501. if (oldEl) {
  14502. var newProp = getAnimatableProps(el);
  14503. el.attr(getAnimatableProps(oldEl));
  14504. updateProps(el, newProp, animatableModel, el.dataIndex);
  14505. }
  14506. // else {
  14507. // if (el.previousProps) {
  14508. // graphic.updateProps
  14509. // }
  14510. // }
  14511. }
  14512. });
  14513. }
  14514. /**
  14515. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  14516. * @param {Object} rect {x, y, width, height}
  14517. * @return {Array.<Array.<number>>} A new clipped points.
  14518. */
  14519. function clipPointsByRect(points, rect) {
  14520. return map(points, function (point) {
  14521. var x = point[0];
  14522. x = mathMax$1(x, rect.x);
  14523. x = mathMin$1(x, rect.x + rect.width);
  14524. var y = point[1];
  14525. y = mathMax$1(y, rect.y);
  14526. y = mathMin$1(y, rect.y + rect.height);
  14527. return [x, y];
  14528. });
  14529. }
  14530. /**
  14531. * @param {Object} targetRect {x, y, width, height}
  14532. * @param {Object} rect {x, y, width, height}
  14533. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  14534. */
  14535. function clipRectByRect(targetRect, rect) {
  14536. var x = mathMax$1(targetRect.x, rect.x);
  14537. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  14538. var y = mathMax$1(targetRect.y, rect.y);
  14539. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  14540. if (x2 >= x && y2 >= y) {
  14541. return {
  14542. x: x,
  14543. y: y,
  14544. width: x2 - x,
  14545. height: y2 - y
  14546. };
  14547. }
  14548. }
  14549. /**
  14550. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  14551. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  14552. * @param {Object} [rect] {x, y, width, height}
  14553. * @return {module:zrender/Element} Icon path or image element.
  14554. */
  14555. function createIcon(iconStr, opt, rect) {
  14556. opt = extend({rectHover: true}, opt);
  14557. var style = opt.style = {strokeNoScale: true};
  14558. rect = rect || {x: -1, y: -1, width: 2, height: 2};
  14559. if (iconStr) {
  14560. return iconStr.indexOf('image://') === 0
  14561. ? (
  14562. style.image = iconStr.slice(8),
  14563. defaults(style, rect),
  14564. new ZImage(opt)
  14565. )
  14566. : (
  14567. makePath(
  14568. iconStr.replace('path://', ''),
  14569. opt,
  14570. rect,
  14571. 'center'
  14572. )
  14573. );
  14574. }
  14575. }
  14576. var graphic = (Object.freeze || Object)({
  14577. extendShape: extendShape,
  14578. extendPath: extendPath,
  14579. makePath: makePath,
  14580. makeImage: makeImage,
  14581. mergePath: mergePath,
  14582. resizePath: resizePath,
  14583. subPixelOptimizeLine: subPixelOptimizeLine,
  14584. subPixelOptimizeRect: subPixelOptimizeRect,
  14585. subPixelOptimize: subPixelOptimize,
  14586. setHoverStyle: setHoverStyle,
  14587. setLabelStyle: setLabelStyle,
  14588. setTextStyle: setTextStyle,
  14589. setText: setText,
  14590. getFont: getFont,
  14591. updateProps: updateProps,
  14592. initProps: initProps,
  14593. getTransform: getTransform,
  14594. applyTransform: applyTransform$1,
  14595. transformDirection: transformDirection,
  14596. groupTransition: groupTransition,
  14597. clipPointsByRect: clipPointsByRect,
  14598. clipRectByRect: clipRectByRect,
  14599. createIcon: createIcon,
  14600. Group: Group,
  14601. Image: ZImage,
  14602. Text: Text,
  14603. Circle: Circle,
  14604. Sector: Sector,
  14605. Ring: Ring,
  14606. Polygon: Polygon,
  14607. Polyline: Polyline,
  14608. Rect: Rect,
  14609. Line: Line,
  14610. BezierCurve: BezierCurve,
  14611. Arc: Arc,
  14612. CompoundPath: CompoundPath,
  14613. LinearGradient: LinearGradient,
  14614. RadialGradient: RadialGradient,
  14615. BoundingRect: BoundingRect
  14616. });
  14617. var PATH_COLOR = ['textStyle', 'color'];
  14618. var textStyleMixin = {
  14619. /**
  14620. * Get color property or get color from option.textStyle.color
  14621. * @param {boolean} [isEmphasis]
  14622. * @return {string}
  14623. */
  14624. getTextColor: function (isEmphasis) {
  14625. var ecModel = this.ecModel;
  14626. return this.getShallow('color')
  14627. || (
  14628. (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null
  14629. );
  14630. },
  14631. /**
  14632. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  14633. * @return {string}
  14634. */
  14635. getFont: function () {
  14636. return getFont({
  14637. fontStyle: this.getShallow('fontStyle'),
  14638. fontWeight: this.getShallow('fontWeight'),
  14639. fontSize: this.getShallow('fontSize'),
  14640. fontFamily: this.getShallow('fontFamily')
  14641. }, this.ecModel);
  14642. },
  14643. getTextRect: function (text) {
  14644. return getBoundingRect(
  14645. text,
  14646. this.getFont(),
  14647. this.getShallow('align'),
  14648. this.getShallow('verticalAlign') || this.getShallow('baseline'),
  14649. this.getShallow('padding'),
  14650. this.getShallow('rich'),
  14651. this.getShallow('truncateText')
  14652. );
  14653. }
  14654. };
  14655. var getItemStyle = makeStyleMapper(
  14656. [
  14657. ['fill', 'color'],
  14658. ['stroke', 'borderColor'],
  14659. ['lineWidth', 'borderWidth'],
  14660. ['opacity'],
  14661. ['shadowBlur'],
  14662. ['shadowOffsetX'],
  14663. ['shadowOffsetY'],
  14664. ['shadowColor'],
  14665. ['textPosition'],
  14666. ['textAlign']
  14667. ]
  14668. );
  14669. var itemStyleMixin = {
  14670. getItemStyle: function (excludes, includes) {
  14671. var style = getItemStyle(this, excludes, includes);
  14672. var lineDash = this.getBorderLineDash();
  14673. lineDash && (style.lineDash = lineDash);
  14674. return style;
  14675. },
  14676. getBorderLineDash: function () {
  14677. var lineType = this.get('borderType');
  14678. return (lineType === 'solid' || lineType == null) ? null
  14679. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  14680. }
  14681. };
  14682. /**
  14683. * @module echarts/model/Model
  14684. */
  14685. var mixin$1 = mixin;
  14686. /**
  14687. * @alias module:echarts/model/Model
  14688. * @constructor
  14689. * @param {Object} option
  14690. * @param {module:echarts/model/Model} [parentModel]
  14691. * @param {module:echarts/model/Global} [ecModel]
  14692. */
  14693. function Model(option, parentModel, ecModel) {
  14694. /**
  14695. * @type {module:echarts/model/Model}
  14696. * @readOnly
  14697. */
  14698. this.parentModel = parentModel;
  14699. /**
  14700. * @type {module:echarts/model/Global}
  14701. * @readOnly
  14702. */
  14703. this.ecModel = ecModel;
  14704. /**
  14705. * @type {Object}
  14706. * @protected
  14707. */
  14708. this.option = option;
  14709. // Simple optimization
  14710. // if (this.init) {
  14711. // if (arguments.length <= 4) {
  14712. // this.init(option, parentModel, ecModel, extraOpt);
  14713. // }
  14714. // else {
  14715. // this.init.apply(this, arguments);
  14716. // }
  14717. // }
  14718. }
  14719. Model.prototype = {
  14720. constructor: Model,
  14721. /**
  14722. * Model 的初始化函数
  14723. * @param {Object} option
  14724. */
  14725. init: null,
  14726. /**
  14727. * 从新的 Option merge
  14728. */
  14729. mergeOption: function (option) {
  14730. merge(this.option, option, true);
  14731. },
  14732. /**
  14733. * @param {string|Array.<string>} path
  14734. * @param {boolean} [ignoreParent=false]
  14735. * @return {*}
  14736. */
  14737. get: function (path, ignoreParent) {
  14738. if (path == null) {
  14739. return this.option;
  14740. }
  14741. return doGet(
  14742. this.option,
  14743. this.parsePath(path),
  14744. !ignoreParent && getParent(this, path)
  14745. );
  14746. },
  14747. /**
  14748. * @param {string} key
  14749. * @param {boolean} [ignoreParent=false]
  14750. * @return {*}
  14751. */
  14752. getShallow: function (key, ignoreParent) {
  14753. var option = this.option;
  14754. var val = option == null ? option : option[key];
  14755. var parentModel = !ignoreParent && getParent(this, key);
  14756. if (val == null && parentModel) {
  14757. val = parentModel.getShallow(key);
  14758. }
  14759. return val;
  14760. },
  14761. /**
  14762. * @param {string|Array.<string>} [path]
  14763. * @param {module:echarts/model/Model} [parentModel]
  14764. * @return {module:echarts/model/Model}
  14765. */
  14766. getModel: function (path, parentModel) {
  14767. var obj = path == null
  14768. ? this.option
  14769. : doGet(this.option, path = this.parsePath(path));
  14770. var thisParentModel;
  14771. parentModel = parentModel || (
  14772. (thisParentModel = getParent(this, path))
  14773. && thisParentModel.getModel(path)
  14774. );
  14775. return new Model(obj, parentModel, this.ecModel);
  14776. },
  14777. /**
  14778. * If model has option
  14779. */
  14780. isEmpty: function () {
  14781. return this.option == null;
  14782. },
  14783. restoreData: function () {},
  14784. // Pending
  14785. clone: function () {
  14786. var Ctor = this.constructor;
  14787. return new Ctor(clone(this.option));
  14788. },
  14789. setReadOnly: function (properties) {
  14790. },
  14791. // If path is null/undefined, return null/undefined.
  14792. parsePath: function(path) {
  14793. if (typeof path === 'string') {
  14794. path = path.split('.');
  14795. }
  14796. return path;
  14797. },
  14798. /**
  14799. * @param {Function} getParentMethod
  14800. * param {Array.<string>|string} path
  14801. * return {module:echarts/model/Model}
  14802. */
  14803. customizeGetParent: function (getParentMethod) {
  14804. set$1(this, 'getParent', getParentMethod);
  14805. },
  14806. isAnimationEnabled: function () {
  14807. if (!env$1.node) {
  14808. if (this.option.animation != null) {
  14809. return !!this.option.animation;
  14810. }
  14811. else if (this.parentModel) {
  14812. return this.parentModel.isAnimationEnabled();
  14813. }
  14814. }
  14815. }
  14816. };
  14817. function doGet(obj, pathArr, parentModel) {
  14818. for (var i = 0; i < pathArr.length; i++) {
  14819. // Ignore empty
  14820. if (!pathArr[i]) {
  14821. continue;
  14822. }
  14823. // obj could be number/string/... (like 0)
  14824. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  14825. if (obj == null) {
  14826. break;
  14827. }
  14828. }
  14829. if (obj == null && parentModel) {
  14830. obj = parentModel.get(pathArr);
  14831. }
  14832. return obj;
  14833. }
  14834. // `path` can be null/undefined
  14835. function getParent(model, path) {
  14836. var getParentMethod = get(model, 'getParent');
  14837. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  14838. }
  14839. // Enable Model.extend.
  14840. enableClassExtend(Model);
  14841. mixin$1(Model, lineStyleMixin);
  14842. mixin$1(Model, areaStyleMixin);
  14843. mixin$1(Model, textStyleMixin);
  14844. mixin$1(Model, itemStyleMixin);
  14845. var each$3 = each$1;
  14846. var isObject$2 = isObject;
  14847. /**
  14848. * If value is not array, then translate it to array.
  14849. * @param {*} value
  14850. * @return {Array} [value] or value
  14851. */
  14852. function normalizeToArray(value) {
  14853. return value instanceof Array
  14854. ? value
  14855. : value == null
  14856. ? []
  14857. : [value];
  14858. }
  14859. /**
  14860. * Sync default option between normal and emphasis like `position` and `show`
  14861. * In case some one will write code like
  14862. * label: {
  14863. * normal: {
  14864. * show: false,
  14865. * position: 'outside',
  14866. * fontSize: 18
  14867. * },
  14868. * emphasis: {
  14869. * show: true
  14870. * }
  14871. * }
  14872. * @param {Object} opt
  14873. * @param {Array.<string>} subOpts
  14874. */
  14875. function defaultEmphasis(opt, subOpts) {
  14876. if (opt) {
  14877. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  14878. var normalOpt = opt.normal = opt.normal || {};
  14879. // Default emphasis option from normal
  14880. for (var i = 0, len = subOpts.length; i < len; i++) {
  14881. var subOptName = subOpts[i];
  14882. if (!emphasisOpt.hasOwnProperty(subOptName)
  14883. && normalOpt.hasOwnProperty(subOptName)
  14884. ) {
  14885. emphasisOpt[subOptName] = normalOpt[subOptName];
  14886. }
  14887. }
  14888. }
  14889. }
  14890. var TEXT_STYLE_OPTIONS = [
  14891. 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  14892. 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth',
  14893. 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline',
  14894. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
  14895. 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
  14896. 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'
  14897. ];
  14898. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  14899. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  14900. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  14901. // // FIXME: deprecated, check and remove it.
  14902. // 'textStyle'
  14903. // ]);
  14904. /**
  14905. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  14906. * This helper method retieves value from data.
  14907. * @param {string|number|Date|Array|Object} dataItem
  14908. * @return {number|string|Date|Array.<number|string|Date>}
  14909. */
  14910. function getDataItemValue(dataItem) {
  14911. // Performance sensitive.
  14912. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  14913. }
  14914. /**
  14915. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  14916. * This helper method determine if dataItem has extra option besides value
  14917. * @param {string|number|Date|Array|Object} dataItem
  14918. */
  14919. function isDataItemOption(dataItem) {
  14920. return isObject$2(dataItem)
  14921. && !(dataItem instanceof Array);
  14922. // // markLine data can be array
  14923. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  14924. }
  14925. /**
  14926. * This helper method convert value in data.
  14927. * @param {string|number|Date} value
  14928. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  14929. */
  14930. function converDataValue(value, dimInfo) {
  14931. // Performance sensitive.
  14932. var dimType = dimInfo && dimInfo.type;
  14933. if (dimType === 'ordinal') {
  14934. return value;
  14935. }
  14936. if (dimType === 'time'
  14937. // spead up when using timestamp
  14938. && typeof value !== 'number'
  14939. && value != null
  14940. && value !== '-'
  14941. ) {
  14942. value = +parseDate(value);
  14943. }
  14944. // dimType defaults 'number'.
  14945. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  14946. // parse to NaN.
  14947. return (value == null || value === '')
  14948. ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  14949. }
  14950. /**
  14951. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
  14952. * @param {module:echarts/data/List} data
  14953. * @param {Object} opt
  14954. * @param {string} [opt.seriesIndex]
  14955. * @param {Object} [opt.name]
  14956. * @param {Object} [opt.mainType]
  14957. * @param {Object} [opt.subType]
  14958. */
  14959. // PENDING A little ugly
  14960. var dataFormatMixin = {
  14961. /**
  14962. * Get params for formatter
  14963. * @param {number} dataIndex
  14964. * @param {string} [dataType]
  14965. * @return {Object}
  14966. */
  14967. getDataParams: function (dataIndex, dataType) {
  14968. var data = this.getData(dataType);
  14969. var rawValue = this.getRawValue(dataIndex, dataType);
  14970. var rawDataIndex = data.getRawIndex(dataIndex);
  14971. var name = data.getName(dataIndex, true);
  14972. var itemOpt = data.getRawDataItem(dataIndex);
  14973. var color = data.getItemVisual(dataIndex, 'color');
  14974. return {
  14975. componentType: this.mainType,
  14976. componentSubType: this.subType,
  14977. seriesType: this.mainType === 'series' ? this.subType : null,
  14978. seriesIndex: this.seriesIndex,
  14979. seriesId: this.id,
  14980. seriesName: this.name,
  14981. name: name,
  14982. dataIndex: rawDataIndex,
  14983. data: itemOpt,
  14984. dataType: dataType,
  14985. value: rawValue,
  14986. color: color,
  14987. marker: getTooltipMarker(color),
  14988. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  14989. $vars: ['seriesName', 'name', 'value']
  14990. };
  14991. },
  14992. /**
  14993. * Format label
  14994. * @param {number} dataIndex
  14995. * @param {string} [status='normal'] 'normal' or 'emphasis'
  14996. * @param {string} [dataType]
  14997. * @param {number} [dimIndex]
  14998. * @param {string} [labelProp='label']
  14999. * @return {string}
  15000. */
  15001. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  15002. status = status || 'normal';
  15003. var data = this.getData(dataType);
  15004. var itemModel = data.getItemModel(dataIndex);
  15005. var params = this.getDataParams(dataIndex, dataType);
  15006. if (dimIndex != null && (params.value instanceof Array)) {
  15007. params.value = params.value[dimIndex];
  15008. }
  15009. var formatter = itemModel.get([labelProp || 'label', status, 'formatter']);
  15010. if (typeof formatter === 'function') {
  15011. params.status = status;
  15012. return formatter(params);
  15013. }
  15014. else if (typeof formatter === 'string') {
  15015. return formatTpl(formatter, params);
  15016. }
  15017. },
  15018. /**
  15019. * Get raw value in option
  15020. * @param {number} idx
  15021. * @param {string} [dataType]
  15022. * @return {Object}
  15023. */
  15024. getRawValue: function (idx, dataType) {
  15025. var data = this.getData(dataType);
  15026. var dataItem = data.getRawDataItem(idx);
  15027. if (dataItem != null) {
  15028. return (isObject$2(dataItem) && !(dataItem instanceof Array))
  15029. ? dataItem.value : dataItem;
  15030. }
  15031. },
  15032. /**
  15033. * Should be implemented.
  15034. * @param {number} dataIndex
  15035. * @param {boolean} [multipleSeries=false]
  15036. * @param {number} [dataType]
  15037. * @return {string} tooltip string
  15038. */
  15039. formatTooltip: noop
  15040. };
  15041. /**
  15042. * Mapping to exists for merge.
  15043. *
  15044. * @public
  15045. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  15046. * @param {Object|Array.<Object>} newCptOptions
  15047. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  15048. * index of which is the same as exists.
  15049. */
  15050. function mappingToExists(exists, newCptOptions) {
  15051. // Mapping by the order by original option (but not order of
  15052. // new option) in merge mode. Because we should ensure
  15053. // some specified index (like xAxisIndex) is consistent with
  15054. // original option, which is easy to understand, espatially in
  15055. // media query. And in most case, merge option is used to
  15056. // update partial option but not be expected to change order.
  15057. newCptOptions = (newCptOptions || []).slice();
  15058. var result = map(exists || [], function (obj, index) {
  15059. return {exist: obj};
  15060. });
  15061. // Mapping by id or name if specified.
  15062. each$3(newCptOptions, function (cptOption, index) {
  15063. if (!isObject$2(cptOption)) {
  15064. return;
  15065. }
  15066. // id has highest priority.
  15067. for (var i = 0; i < result.length; i++) {
  15068. if (!result[i].option // Consider name: two map to one.
  15069. && cptOption.id != null
  15070. && result[i].exist.id === cptOption.id + ''
  15071. ) {
  15072. result[i].option = cptOption;
  15073. newCptOptions[index] = null;
  15074. return;
  15075. }
  15076. }
  15077. for (var i = 0; i < result.length; i++) {
  15078. var exist = result[i].exist;
  15079. if (!result[i].option // Consider name: two map to one.
  15080. // Can not match when both ids exist but different.
  15081. && (exist.id == null || cptOption.id == null)
  15082. && cptOption.name != null
  15083. && !isIdInner(cptOption)
  15084. && !isIdInner(exist)
  15085. && exist.name === cptOption.name + ''
  15086. ) {
  15087. result[i].option = cptOption;
  15088. newCptOptions[index] = null;
  15089. return;
  15090. }
  15091. }
  15092. });
  15093. // Otherwise mapping by index.
  15094. each$3(newCptOptions, function (cptOption, index) {
  15095. if (!isObject$2(cptOption)) {
  15096. return;
  15097. }
  15098. var i = 0;
  15099. for (; i < result.length; i++) {
  15100. var exist = result[i].exist;
  15101. if (!result[i].option
  15102. // Existing model that already has id should be able to
  15103. // mapped to (because after mapping performed model may
  15104. // be assigned with a id, whish should not affect next
  15105. // mapping), except those has inner id.
  15106. && !isIdInner(exist)
  15107. // Caution:
  15108. // Do not overwrite id. But name can be overwritten,
  15109. // because axis use name as 'show label text'.
  15110. // 'exist' always has id and name and we dont
  15111. // need to check it.
  15112. && cptOption.id == null
  15113. ) {
  15114. result[i].option = cptOption;
  15115. break;
  15116. }
  15117. }
  15118. if (i >= result.length) {
  15119. result.push({option: cptOption});
  15120. }
  15121. });
  15122. return result;
  15123. }
  15124. /**
  15125. * Make id and name for mapping result (result of mappingToExists)
  15126. * into `keyInfo` field.
  15127. *
  15128. * @public
  15129. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  15130. * which order is the same as exists.
  15131. * @return {Array.<Object>} The input.
  15132. */
  15133. function makeIdAndName(mapResult) {
  15134. // We use this id to hash component models and view instances
  15135. // in echarts. id can be specified by user, or auto generated.
  15136. // The id generation rule ensures new view instance are able
  15137. // to mapped to old instance when setOption are called in
  15138. // no-merge mode. So we generate model id by name and plus
  15139. // type in view id.
  15140. // name can be duplicated among components, which is convenient
  15141. // to specify multi components (like series) by one name.
  15142. // Ensure that each id is distinct.
  15143. var idMap = createHashMap();
  15144. each$3(mapResult, function (item, index) {
  15145. var existCpt = item.exist;
  15146. existCpt && idMap.set(existCpt.id, item);
  15147. });
  15148. each$3(mapResult, function (item, index) {
  15149. var opt = item.option;
  15150. assert(
  15151. !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
  15152. 'id duplicates: ' + (opt && opt.id)
  15153. );
  15154. opt && opt.id != null && idMap.set(opt.id, item);
  15155. !item.keyInfo && (item.keyInfo = {});
  15156. });
  15157. // Make name and id.
  15158. each$3(mapResult, function (item, index) {
  15159. var existCpt = item.exist;
  15160. var opt = item.option;
  15161. var keyInfo = item.keyInfo;
  15162. if (!isObject$2(opt)) {
  15163. return;
  15164. }
  15165. // name can be overwitten. Consider case: axis.name = '20km'.
  15166. // But id generated by name will not be changed, which affect
  15167. // only in that case: setOption with 'not merge mode' and view
  15168. // instance will be recreated, which can be accepted.
  15169. keyInfo.name = opt.name != null
  15170. ? opt.name + ''
  15171. : existCpt
  15172. ? existCpt.name
  15173. : '\0-'; // name may be displayed on screen, so use '-'.
  15174. if (existCpt) {
  15175. keyInfo.id = existCpt.id;
  15176. }
  15177. else if (opt.id != null) {
  15178. keyInfo.id = opt.id + '';
  15179. }
  15180. else {
  15181. // Consider this situatoin:
  15182. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  15183. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  15184. // Series with the same name between optionA and optionB
  15185. // should be mapped.
  15186. var idNum = 0;
  15187. do {
  15188. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  15189. }
  15190. while (idMap.get(keyInfo.id));
  15191. }
  15192. idMap.set(keyInfo.id, item);
  15193. });
  15194. }
  15195. /**
  15196. * @public
  15197. * @param {Object} cptOption
  15198. * @return {boolean}
  15199. */
  15200. function isIdInner(cptOption) {
  15201. return isObject$2(cptOption)
  15202. && cptOption.id
  15203. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  15204. }
  15205. /**
  15206. * A helper for removing duplicate items between batchA and batchB,
  15207. * and in themselves, and categorize by series.
  15208. *
  15209. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  15210. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  15211. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  15212. */
  15213. /**
  15214. * @param {module:echarts/data/List} data
  15215. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  15216. * each of which can be Array or primary type.
  15217. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  15218. */
  15219. function queryDataIndex(data, payload) {
  15220. if (payload.dataIndexInside != null) {
  15221. return payload.dataIndexInside;
  15222. }
  15223. else if (payload.dataIndex != null) {
  15224. return isArray(payload.dataIndex)
  15225. ? map(payload.dataIndex, function (value) {
  15226. return data.indexOfRawIndex(value);
  15227. })
  15228. : data.indexOfRawIndex(payload.dataIndex);
  15229. }
  15230. else if (payload.name != null) {
  15231. return isArray(payload.name)
  15232. ? map(payload.name, function (value) {
  15233. return data.indexOfName(value);
  15234. })
  15235. : data.indexOfName(payload.name);
  15236. }
  15237. }
  15238. /**
  15239. * Enable property storage to any host object.
  15240. * Notice: Serialization is not supported.
  15241. *
  15242. * For example:
  15243. * var get = modelUitl.makeGetter();
  15244. *
  15245. * function some(hostObj) {
  15246. * get(hostObj)._someProperty = 1212;
  15247. * ...
  15248. * }
  15249. *
  15250. * @return {Function}
  15251. */
  15252. var makeGetter = (function () {
  15253. var index = 0;
  15254. return function () {
  15255. var key = '\0__ec_prop_getter_' + index++;
  15256. return function (hostObj) {
  15257. return hostObj[key] || (hostObj[key] = {});
  15258. };
  15259. };
  15260. })();
  15261. /**
  15262. * @param {module:echarts/model/Global} ecModel
  15263. * @param {string|Object} finder
  15264. * If string, e.g., 'geo', means {geoIndex: 0}.
  15265. * If Object, could contain some of these properties below:
  15266. * {
  15267. * seriesIndex, seriesId, seriesName,
  15268. * geoIndex, geoId, geoName,
  15269. * bmapIndex, bmapId, bmapName,
  15270. * xAxisIndex, xAxisId, xAxisName,
  15271. * yAxisIndex, yAxisId, yAxisName,
  15272. * gridIndex, gridId, gridName,
  15273. * ... (can be extended)
  15274. * }
  15275. * Each properties can be number|string|Array.<number>|Array.<string>
  15276. * For example, a finder could be
  15277. * {
  15278. * seriesIndex: 3,
  15279. * geoId: ['aa', 'cc'],
  15280. * gridName: ['xx', 'rr']
  15281. * }
  15282. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  15283. * If nothing or null/undefined specified, return nothing.
  15284. * @param {Object} [opt]
  15285. * @param {string} [opt.defaultMainType]
  15286. * @param {Array.<string>} [opt.includeMainTypes]
  15287. * @return {Object} result like:
  15288. * {
  15289. * seriesModels: [seriesModel1, seriesModel2],
  15290. * seriesModel: seriesModel1, // The first model
  15291. * geoModels: [geoModel1, geoModel2],
  15292. * geoModel: geoModel1, // The first model
  15293. * ...
  15294. * }
  15295. */
  15296. function parseFinder(ecModel, finder, opt) {
  15297. if (isString(finder)) {
  15298. var obj = {};
  15299. obj[finder + 'Index'] = 0;
  15300. finder = obj;
  15301. }
  15302. var defaultMainType = opt && opt.defaultMainType;
  15303. if (defaultMainType
  15304. && !has(finder, defaultMainType + 'Index')
  15305. && !has(finder, defaultMainType + 'Id')
  15306. && !has(finder, defaultMainType + 'Name')
  15307. ) {
  15308. finder[defaultMainType + 'Index'] = 0;
  15309. }
  15310. var result = {};
  15311. each$3(finder, function (value, key) {
  15312. var value = finder[key];
  15313. // Exclude 'dataIndex' and other illgal keys.
  15314. if (key === 'dataIndex' || key === 'dataIndexInside') {
  15315. result[key] = value;
  15316. return;
  15317. }
  15318. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  15319. var mainType = parsedKey[1];
  15320. var queryType = (parsedKey[2] || '').toLowerCase();
  15321. if (!mainType
  15322. || !queryType
  15323. || value == null
  15324. || (queryType === 'index' && value === 'none')
  15325. || (opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0)
  15326. ) {
  15327. return;
  15328. }
  15329. var queryParam = {mainType: mainType};
  15330. if (queryType !== 'index' || value !== 'all') {
  15331. queryParam[queryType] = value;
  15332. }
  15333. var models = ecModel.queryComponents(queryParam);
  15334. result[mainType + 'Models'] = models;
  15335. result[mainType + 'Model'] = models[0];
  15336. });
  15337. return result;
  15338. }
  15339. /**
  15340. * @see {module:echarts/data/helper/completeDimensions}
  15341. * @param {module:echarts/data/List} data
  15342. * @param {string|number} dataDim
  15343. * @return {string}
  15344. */
  15345. function dataDimToCoordDim(data, dataDim) {
  15346. var dimensions = data.dimensions;
  15347. dataDim = data.getDimension(dataDim);
  15348. for (var i = 0; i < dimensions.length; i++) {
  15349. var dimItem = data.getDimensionInfo(dimensions[i]);
  15350. if (dimItem.name === dataDim) {
  15351. return dimItem.coordDim;
  15352. }
  15353. }
  15354. }
  15355. /**
  15356. * @see {module:echarts/data/helper/completeDimensions}
  15357. * @param {module:echarts/data/List} data
  15358. * @param {string} coordDim
  15359. * @return {Array.<string>} data dimensions on the coordDim.
  15360. */
  15361. function coordDimToDataDim(data, coordDim) {
  15362. var dataDim = [];
  15363. each$3(data.dimensions, function (dimName) {
  15364. var dimItem = data.getDimensionInfo(dimName);
  15365. if (dimItem.coordDim === coordDim) {
  15366. dataDim[dimItem.coordDimIndex] = dimItem.name;
  15367. }
  15368. });
  15369. return dataDim;
  15370. }
  15371. /**
  15372. * @see {module:echarts/data/helper/completeDimensions}
  15373. * @param {module:echarts/data/List} data
  15374. * @param {string} otherDim Can be `otherDims`
  15375. * like 'label' or 'tooltip'.
  15376. * @return {Array.<string>} data dimensions on the otherDim.
  15377. */
  15378. function otherDimToDataDim(data, otherDim) {
  15379. var dataDim = [];
  15380. each$3(data.dimensions, function (dimName) {
  15381. var dimItem = data.getDimensionInfo(dimName);
  15382. var otherDims = dimItem.otherDims;
  15383. var dimIndex = otherDims[otherDim];
  15384. if (dimIndex != null && dimIndex !== false) {
  15385. dataDim[dimIndex] = dimItem.name;
  15386. }
  15387. });
  15388. return dataDim;
  15389. }
  15390. function has(obj, prop) {
  15391. return obj && obj.hasOwnProperty(prop);
  15392. }
  15393. var base = 0;
  15394. var DELIMITER = '_';
  15395. /**
  15396. * @public
  15397. * @param {string} type
  15398. * @return {string}
  15399. */
  15400. function getUID(type) {
  15401. // Considering the case of crossing js context,
  15402. // use Math.random to make id as unique as possible.
  15403. return [(type || ''), base++, Math.random()].join(DELIMITER);
  15404. }
  15405. /**
  15406. * @inner
  15407. */
  15408. function enableSubTypeDefaulter(entity) {
  15409. var subTypeDefaulters = {};
  15410. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  15411. componentType = parseClassType$1(componentType);
  15412. subTypeDefaulters[componentType.main] = defaulter;
  15413. };
  15414. entity.determineSubType = function (componentType, option) {
  15415. var type = option.type;
  15416. if (!type) {
  15417. var componentTypeMain = parseClassType$1(componentType).main;
  15418. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15419. type = subTypeDefaulters[componentTypeMain](option);
  15420. }
  15421. }
  15422. return type;
  15423. };
  15424. return entity;
  15425. }
  15426. /**
  15427. * Topological travel on Activity Network (Activity On Vertices).
  15428. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15429. *
  15430. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15431. *
  15432. * If there is circle dependencey, Error will be thrown.
  15433. *
  15434. */
  15435. function enableTopologicalTravel(entity, dependencyGetter) {
  15436. /**
  15437. * @public
  15438. * @param {Array.<string>} targetNameList Target Component type list.
  15439. * Can be ['aa', 'bb', 'aa.xx']
  15440. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  15441. * @param {Function} callback Params: componentType, dependencies.
  15442. * @param {Object} context Scope of callback.
  15443. */
  15444. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15445. if (!targetNameList.length) {
  15446. return;
  15447. }
  15448. var result = makeDepndencyGraph(fullNameList);
  15449. var graph = result.graph;
  15450. var stack = result.noEntryList;
  15451. var targetNameSet = {};
  15452. each$1(targetNameList, function (name) {
  15453. targetNameSet[name] = true;
  15454. });
  15455. while (stack.length) {
  15456. var currComponentType = stack.pop();
  15457. var currVertex = graph[currComponentType];
  15458. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15459. if (isInTargetNameSet) {
  15460. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15461. delete targetNameSet[currComponentType];
  15462. }
  15463. each$1(
  15464. currVertex.successor,
  15465. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  15466. );
  15467. }
  15468. each$1(targetNameSet, function () {
  15469. throw new Error('Circle dependency may exists');
  15470. });
  15471. function removeEdge(succComponentType) {
  15472. graph[succComponentType].entryCount--;
  15473. if (graph[succComponentType].entryCount === 0) {
  15474. stack.push(succComponentType);
  15475. }
  15476. }
  15477. // Consider this case: legend depends on series, and we call
  15478. // chart.setOption({series: [...]}), where only series is in option.
  15479. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15480. // not be called, but only sereis.mergeOption is called. Thus legend
  15481. // have no chance to update its local record about series (like which
  15482. // name of series is available in legend).
  15483. function removeEdgeAndAdd(succComponentType) {
  15484. targetNameSet[succComponentType] = true;
  15485. removeEdge(succComponentType);
  15486. }
  15487. };
  15488. /**
  15489. * DepndencyGraph: {Object}
  15490. * key: conponentType,
  15491. * value: {
  15492. * successor: [conponentTypes...],
  15493. * originalDeps: [conponentTypes...],
  15494. * entryCount: {number}
  15495. * }
  15496. */
  15497. function makeDepndencyGraph(fullNameList) {
  15498. var graph = {};
  15499. var noEntryList = [];
  15500. each$1(fullNameList, function (name) {
  15501. var thisItem = createDependencyGraphItem(graph, name);
  15502. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15503. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15504. thisItem.entryCount = availableDeps.length;
  15505. if (thisItem.entryCount === 0) {
  15506. noEntryList.push(name);
  15507. }
  15508. each$1(availableDeps, function (dependentName) {
  15509. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15510. thisItem.predecessor.push(dependentName);
  15511. }
  15512. var thatItem = createDependencyGraphItem(graph, dependentName);
  15513. if (indexOf(thatItem.successor, dependentName) < 0) {
  15514. thatItem.successor.push(name);
  15515. }
  15516. });
  15517. });
  15518. return {graph: graph, noEntryList: noEntryList};
  15519. }
  15520. function createDependencyGraphItem(graph, name) {
  15521. if (!graph[name]) {
  15522. graph[name] = {predecessor: [], successor: []};
  15523. }
  15524. return graph[name];
  15525. }
  15526. function getAvailableDependencies(originalDeps, fullNameList) {
  15527. var availableDeps = [];
  15528. each$1(originalDeps, function (dep) {
  15529. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15530. });
  15531. return availableDeps;
  15532. }
  15533. }
  15534. // Layout helpers for each component positioning
  15535. var each$4 = each$1;
  15536. /**
  15537. * @public
  15538. */
  15539. var LOCATION_PARAMS = [
  15540. 'left', 'right', 'top', 'bottom', 'width', 'height'
  15541. ];
  15542. /**
  15543. * @public
  15544. */
  15545. var HV_NAMES = [
  15546. ['width', 'left', 'right'],
  15547. ['height', 'top', 'bottom']
  15548. ];
  15549. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  15550. var x = 0;
  15551. var y = 0;
  15552. if (maxWidth == null) {
  15553. maxWidth = Infinity;
  15554. }
  15555. if (maxHeight == null) {
  15556. maxHeight = Infinity;
  15557. }
  15558. var currentLineMaxSize = 0;
  15559. group.eachChild(function (child, idx) {
  15560. var position = child.position;
  15561. var rect = child.getBoundingRect();
  15562. var nextChild = group.childAt(idx + 1);
  15563. var nextChildRect = nextChild && nextChild.getBoundingRect();
  15564. var nextX;
  15565. var nextY;
  15566. if (orient === 'horizontal') {
  15567. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  15568. nextX = x + moveX;
  15569. // Wrap when width exceeds maxWidth or meet a `newline` group
  15570. // FIXME compare before adding gap?
  15571. if (nextX > maxWidth || child.newline) {
  15572. x = 0;
  15573. nextX = moveX;
  15574. y += currentLineMaxSize + gap;
  15575. currentLineMaxSize = rect.height;
  15576. }
  15577. else {
  15578. // FIXME: consider rect.y is not `0`?
  15579. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  15580. }
  15581. }
  15582. else {
  15583. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  15584. nextY = y + moveY;
  15585. // Wrap when width exceeds maxHeight or meet a `newline` group
  15586. if (nextY > maxHeight || child.newline) {
  15587. x += currentLineMaxSize + gap;
  15588. y = 0;
  15589. nextY = moveY;
  15590. currentLineMaxSize = rect.width;
  15591. }
  15592. else {
  15593. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  15594. }
  15595. }
  15596. if (child.newline) {
  15597. return;
  15598. }
  15599. position[0] = x;
  15600. position[1] = y;
  15601. orient === 'horizontal'
  15602. ? (x = nextX + gap)
  15603. : (y = nextY + gap);
  15604. });
  15605. }
  15606. /**
  15607. * VBox or HBox layouting
  15608. * @param {string} orient
  15609. * @param {module:zrender/container/Group} group
  15610. * @param {number} gap
  15611. * @param {number} [width=Infinity]
  15612. * @param {number} [height=Infinity]
  15613. */
  15614. var box = boxLayout;
  15615. /**
  15616. * VBox layouting
  15617. * @param {module:zrender/container/Group} group
  15618. * @param {number} gap
  15619. * @param {number} [width=Infinity]
  15620. * @param {number} [height=Infinity]
  15621. */
  15622. var vbox = curry(boxLayout, 'vertical');
  15623. /**
  15624. * HBox layouting
  15625. * @param {module:zrender/container/Group} group
  15626. * @param {number} gap
  15627. * @param {number} [width=Infinity]
  15628. * @param {number} [height=Infinity]
  15629. */
  15630. var hbox = curry(boxLayout, 'horizontal');
  15631. /**
  15632. * If x or x2 is not specified or 'center' 'left' 'right',
  15633. * the width would be as long as possible.
  15634. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  15635. * the height would be as long as possible.
  15636. *
  15637. * @param {Object} positionInfo
  15638. * @param {number|string} [positionInfo.x]
  15639. * @param {number|string} [positionInfo.y]
  15640. * @param {number|string} [positionInfo.x2]
  15641. * @param {number|string} [positionInfo.y2]
  15642. * @param {Object} containerRect {width, height}
  15643. * @param {string|number} margin
  15644. * @return {Object} {width, height}
  15645. */
  15646. /**
  15647. * Parse position info.
  15648. *
  15649. * @param {Object} positionInfo
  15650. * @param {number|string} [positionInfo.left]
  15651. * @param {number|string} [positionInfo.top]
  15652. * @param {number|string} [positionInfo.right]
  15653. * @param {number|string} [positionInfo.bottom]
  15654. * @param {number|string} [positionInfo.width]
  15655. * @param {number|string} [positionInfo.height]
  15656. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  15657. * @param {Object} containerRect
  15658. * @param {string|number} [margin]
  15659. *
  15660. * @return {module:zrender/core/BoundingRect}
  15661. */
  15662. function getLayoutRect(
  15663. positionInfo, containerRect, margin
  15664. ) {
  15665. margin = normalizeCssArray$1(margin || 0);
  15666. var containerWidth = containerRect.width;
  15667. var containerHeight = containerRect.height;
  15668. var left = parsePercent$1(positionInfo.left, containerWidth);
  15669. var top = parsePercent$1(positionInfo.top, containerHeight);
  15670. var right = parsePercent$1(positionInfo.right, containerWidth);
  15671. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  15672. var width = parsePercent$1(positionInfo.width, containerWidth);
  15673. var height = parsePercent$1(positionInfo.height, containerHeight);
  15674. var verticalMargin = margin[2] + margin[0];
  15675. var horizontalMargin = margin[1] + margin[3];
  15676. var aspect = positionInfo.aspect;
  15677. // If width is not specified, calculate width from left and right
  15678. if (isNaN(width)) {
  15679. width = containerWidth - right - horizontalMargin - left;
  15680. }
  15681. if (isNaN(height)) {
  15682. height = containerHeight - bottom - verticalMargin - top;
  15683. }
  15684. if (aspect != null) {
  15685. // If width and height are not given
  15686. // 1. Graph should not exceeds the container
  15687. // 2. Aspect must be keeped
  15688. // 3. Graph should take the space as more as possible
  15689. // FIXME
  15690. // Margin is not considered, because there is no case that both
  15691. // using margin and aspect so far.
  15692. if (isNaN(width) && isNaN(height)) {
  15693. if (aspect > containerWidth / containerHeight) {
  15694. width = containerWidth * 0.8;
  15695. }
  15696. else {
  15697. height = containerHeight * 0.8;
  15698. }
  15699. }
  15700. // Calculate width or height with given aspect
  15701. if (isNaN(width)) {
  15702. width = aspect * height;
  15703. }
  15704. if (isNaN(height)) {
  15705. height = width / aspect;
  15706. }
  15707. }
  15708. // If left is not specified, calculate left from right and width
  15709. if (isNaN(left)) {
  15710. left = containerWidth - right - width - horizontalMargin;
  15711. }
  15712. if (isNaN(top)) {
  15713. top = containerHeight - bottom - height - verticalMargin;
  15714. }
  15715. // Align left and top
  15716. switch (positionInfo.left || positionInfo.right) {
  15717. case 'center':
  15718. left = containerWidth / 2 - width / 2 - margin[3];
  15719. break;
  15720. case 'right':
  15721. left = containerWidth - width - horizontalMargin;
  15722. break;
  15723. }
  15724. switch (positionInfo.top || positionInfo.bottom) {
  15725. case 'middle':
  15726. case 'center':
  15727. top = containerHeight / 2 - height / 2 - margin[0];
  15728. break;
  15729. case 'bottom':
  15730. top = containerHeight - height - verticalMargin;
  15731. break;
  15732. }
  15733. // If something is wrong and left, top, width, height are calculated as NaN
  15734. left = left || 0;
  15735. top = top || 0;
  15736. if (isNaN(width)) {
  15737. // Width may be NaN if only one value is given except width
  15738. width = containerWidth - horizontalMargin - left - (right || 0);
  15739. }
  15740. if (isNaN(height)) {
  15741. // Height may be NaN if only one value is given except height
  15742. height = containerHeight - verticalMargin - top - (bottom || 0);
  15743. }
  15744. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  15745. rect.margin = margin;
  15746. return rect;
  15747. }
  15748. /**
  15749. * Position a zr element in viewport
  15750. * Group position is specified by either
  15751. * {left, top}, {right, bottom}
  15752. * If all properties exists, right and bottom will be igonred.
  15753. *
  15754. * Logic:
  15755. * 1. Scale (against origin point in parent coord)
  15756. * 2. Rotate (against origin point in parent coord)
  15757. * 3. Traslate (with el.position by this method)
  15758. * So this method only fixes the last step 'Traslate', which does not affect
  15759. * scaling and rotating.
  15760. *
  15761. * If be called repeatly with the same input el, the same result will be gotten.
  15762. *
  15763. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  15764. * @param {Object} positionInfo
  15765. * @param {number|string} [positionInfo.left]
  15766. * @param {number|string} [positionInfo.top]
  15767. * @param {number|string} [positionInfo.right]
  15768. * @param {number|string} [positionInfo.bottom]
  15769. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  15770. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  15771. * @param {Object} containerRect
  15772. * @param {string|number} margin
  15773. * @param {Object} [opt]
  15774. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  15775. * @param {Array.<number>} [opt.boundingMode='all']
  15776. * Specify how to calculate boundingRect when locating.
  15777. * 'all': Position the boundingRect that is transformed and uioned
  15778. * both itself and its descendants.
  15779. * This mode simplies confine the elements in the bounding
  15780. * of their container (e.g., using 'right: 0').
  15781. * 'raw': Position the boundingRect that is not transformed and only itself.
  15782. * This mode is useful when you want a element can overflow its
  15783. * container. (Consider a rotated circle needs to be located in a corner.)
  15784. * In this mode positionInfo.width/height can only be number.
  15785. */
  15786. function positionElement(el, positionInfo, containerRect, margin, opt) {
  15787. var h = !opt || !opt.hv || opt.hv[0];
  15788. var v = !opt || !opt.hv || opt.hv[1];
  15789. var boundingMode = opt && opt.boundingMode || 'all';
  15790. if (!h && !v) {
  15791. return;
  15792. }
  15793. var rect;
  15794. if (boundingMode === 'raw') {
  15795. rect = el.type === 'group'
  15796. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  15797. : el.getBoundingRect();
  15798. }
  15799. else {
  15800. rect = el.getBoundingRect();
  15801. if (el.needLocalTransform()) {
  15802. var transform = el.getLocalTransform();
  15803. // Notice: raw rect may be inner object of el,
  15804. // which should not be modified.
  15805. rect = rect.clone();
  15806. rect.applyTransform(transform);
  15807. }
  15808. }
  15809. // The real width and height can not be specified but calculated by the given el.
  15810. positionInfo = getLayoutRect(
  15811. defaults(
  15812. {width: rect.width, height: rect.height},
  15813. positionInfo
  15814. ),
  15815. containerRect,
  15816. margin
  15817. );
  15818. // Because 'tranlate' is the last step in transform
  15819. // (see zrender/core/Transformable#getLocalTransfrom),
  15820. // we can just only modify el.position to get final result.
  15821. var elPos = el.position;
  15822. var dx = h ? positionInfo.x - rect.x : 0;
  15823. var dy = v ? positionInfo.y - rect.y : 0;
  15824. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  15825. }
  15826. /**
  15827. * @param {Object} option Contains some of the properties in HV_NAMES.
  15828. * @param {number} hvIdx 0: horizontal; 1: vertical.
  15829. */
  15830. /**
  15831. * Consider Case:
  15832. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  15833. * through setOption or media query, using normal zrUtil.merge will cause
  15834. * {right: 0} does not take effect.
  15835. *
  15836. * @example
  15837. * ComponentModel.extend({
  15838. * init: function () {
  15839. * ...
  15840. * var inputPositionParams = layout.getLayoutParams(option);
  15841. * this.mergeOption(inputPositionParams);
  15842. * },
  15843. * mergeOption: function (newOption) {
  15844. * newOption && zrUtil.merge(thisOption, newOption, true);
  15845. * layout.mergeLayoutParam(thisOption, newOption);
  15846. * }
  15847. * });
  15848. *
  15849. * @param {Object} targetOption
  15850. * @param {Object} newOption
  15851. * @param {Object|string} [opt]
  15852. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  15853. * that width (or height) should not be calculated by left and right (or top and bottom).
  15854. */
  15855. function mergeLayoutParam(targetOption, newOption, opt) {
  15856. !isObject(opt) && (opt = {});
  15857. var ignoreSize = opt.ignoreSize;
  15858. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  15859. var hResult = merge$$1(HV_NAMES[0], 0);
  15860. var vResult = merge$$1(HV_NAMES[1], 1);
  15861. copy(HV_NAMES[0], targetOption, hResult);
  15862. copy(HV_NAMES[1], targetOption, vResult);
  15863. function merge$$1(names, hvIdx) {
  15864. var newParams = {};
  15865. var newValueCount = 0;
  15866. var merged = {};
  15867. var mergedValueCount = 0;
  15868. var enoughParamNumber = 2;
  15869. each$4(names, function (name) {
  15870. merged[name] = targetOption[name];
  15871. });
  15872. each$4(names, function (name) {
  15873. // Consider case: newOption.width is null, which is
  15874. // set by user for removing width setting.
  15875. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  15876. hasValue(newParams, name) && newValueCount++;
  15877. hasValue(merged, name) && mergedValueCount++;
  15878. });
  15879. if (ignoreSize[hvIdx]) {
  15880. // Only one of left/right is premitted to exist.
  15881. if (hasValue(newOption, names[1])) {
  15882. merged[names[2]] = null;
  15883. }
  15884. else if (hasValue(newOption, names[2])) {
  15885. merged[names[1]] = null;
  15886. }
  15887. return merged;
  15888. }
  15889. // Case: newOption: {width: ..., right: ...},
  15890. // or targetOption: {right: ...} and newOption: {width: ...},
  15891. // There is no conflict when merged only has params count
  15892. // little than enoughParamNumber.
  15893. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  15894. return merged;
  15895. }
  15896. // Case: newOption: {width: ..., right: ...},
  15897. // Than we can make sure user only want those two, and ignore
  15898. // all origin params in targetOption.
  15899. else if (newValueCount >= enoughParamNumber) {
  15900. return newParams;
  15901. }
  15902. else {
  15903. // Chose another param from targetOption by priority.
  15904. for (var i = 0; i < names.length; i++) {
  15905. var name = names[i];
  15906. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  15907. newParams[name] = targetOption[name];
  15908. break;
  15909. }
  15910. }
  15911. return newParams;
  15912. }
  15913. }
  15914. function hasProp(obj, name) {
  15915. return obj.hasOwnProperty(name);
  15916. }
  15917. function hasValue(obj, name) {
  15918. return obj[name] != null && obj[name] !== 'auto';
  15919. }
  15920. function copy(names, target, source) {
  15921. each$4(names, function (name) {
  15922. target[name] = source[name];
  15923. });
  15924. }
  15925. }
  15926. /**
  15927. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  15928. * @param {Object} source
  15929. * @return {Object} Result contains those props.
  15930. */
  15931. function getLayoutParams(source) {
  15932. return copyLayoutParams({}, source);
  15933. }
  15934. /**
  15935. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  15936. * @param {Object} source
  15937. * @return {Object} Result contains those props.
  15938. */
  15939. function copyLayoutParams(target, source) {
  15940. source && target && each$4(LOCATION_PARAMS, function (name) {
  15941. source.hasOwnProperty(name) && (target[name] = source[name]);
  15942. });
  15943. return target;
  15944. }
  15945. var boxLayoutMixin = {
  15946. getBoxLayoutParams: function () {
  15947. return {
  15948. left: this.get('left'),
  15949. top: this.get('top'),
  15950. right: this.get('right'),
  15951. bottom: this.get('bottom'),
  15952. width: this.get('width'),
  15953. height: this.get('height')
  15954. };
  15955. }
  15956. };
  15957. /**
  15958. * Component model
  15959. *
  15960. * @module echarts/model/Component
  15961. */
  15962. var arrayPush = Array.prototype.push;
  15963. /**
  15964. * @alias module:echarts/model/Component
  15965. * @constructor
  15966. * @param {Object} option
  15967. * @param {module:echarts/model/Model} parentModel
  15968. * @param {module:echarts/model/Model} ecModel
  15969. */
  15970. var ComponentModel = Model.extend({
  15971. type: 'component',
  15972. /**
  15973. * @readOnly
  15974. * @type {string}
  15975. */
  15976. id: '',
  15977. /**
  15978. * @readOnly
  15979. */
  15980. name: '',
  15981. /**
  15982. * @readOnly
  15983. * @type {string}
  15984. */
  15985. mainType: '',
  15986. /**
  15987. * @readOnly
  15988. * @type {string}
  15989. */
  15990. subType: '',
  15991. /**
  15992. * @readOnly
  15993. * @type {number}
  15994. */
  15995. componentIndex: 0,
  15996. /**
  15997. * @type {Object}
  15998. * @protected
  15999. */
  16000. defaultOption: null,
  16001. /**
  16002. * @type {module:echarts/model/Global}
  16003. * @readOnly
  16004. */
  16005. ecModel: null,
  16006. /**
  16007. * key: componentType
  16008. * value: Component model list, can not be null.
  16009. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  16010. * @readOnly
  16011. */
  16012. dependentModels: [],
  16013. /**
  16014. * @type {string}
  16015. * @readOnly
  16016. */
  16017. uid: null,
  16018. /**
  16019. * Support merge layout params.
  16020. * Only support 'box' now (left/right/top/bottom/width/height).
  16021. * @type {string|Object} Object can be {ignoreSize: true}
  16022. * @readOnly
  16023. */
  16024. layoutMode: null,
  16025. $constructor: function (option, parentModel, ecModel, extraOpt) {
  16026. Model.call(this, option, parentModel, ecModel, extraOpt);
  16027. this.uid = getUID('componentModel');
  16028. },
  16029. init: function (option, parentModel, ecModel, extraOpt) {
  16030. this.mergeDefaultAndTheme(option, ecModel);
  16031. },
  16032. mergeDefaultAndTheme: function (option, ecModel) {
  16033. var layoutMode = this.layoutMode;
  16034. var inputPositionParams = layoutMode
  16035. ? getLayoutParams(option) : {};
  16036. var themeModel = ecModel.getTheme();
  16037. merge(option, themeModel.get(this.mainType));
  16038. merge(option, this.getDefaultOption());
  16039. if (layoutMode) {
  16040. mergeLayoutParam(option, inputPositionParams, layoutMode);
  16041. }
  16042. },
  16043. mergeOption: function (option, extraOpt) {
  16044. merge(this.option, option, true);
  16045. var layoutMode = this.layoutMode;
  16046. if (layoutMode) {
  16047. mergeLayoutParam(this.option, option, layoutMode);
  16048. }
  16049. },
  16050. // Hooker after init or mergeOption
  16051. optionUpdated: function (newCptOption, isInit) {},
  16052. getDefaultOption: function () {
  16053. if (!hasOwn(this, '__defaultOption')) {
  16054. var optList = [];
  16055. var Class = this.constructor;
  16056. while (Class) {
  16057. var opt = Class.prototype.defaultOption;
  16058. opt && optList.push(opt);
  16059. Class = Class.superClass;
  16060. }
  16061. var defaultOption = {};
  16062. for (var i = optList.length - 1; i >= 0; i--) {
  16063. defaultOption = merge(defaultOption, optList[i], true);
  16064. }
  16065. set$1(this, '__defaultOption', defaultOption);
  16066. }
  16067. return get(this, '__defaultOption');
  16068. },
  16069. getReferringComponents: function (mainType) {
  16070. return this.ecModel.queryComponents({
  16071. mainType: mainType,
  16072. index: this.get(mainType + 'Index', true),
  16073. id: this.get(mainType + 'Id', true)
  16074. });
  16075. }
  16076. });
  16077. // Reset ComponentModel.extend, add preConstruct.
  16078. // clazzUtil.enableClassExtend(
  16079. // ComponentModel,
  16080. // function (option, parentModel, ecModel, extraOpt) {
  16081. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  16082. // zrUtil.extend(this, extraOpt);
  16083. // this.uid = componentUtil.getUID('componentModel');
  16084. // // this.setReadOnly([
  16085. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  16086. // // 'dependentModels', 'componentIndex'
  16087. // // ]);
  16088. // }
  16089. // );
  16090. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  16091. enableClassManagement(
  16092. ComponentModel, {registerWhenExtend: true}
  16093. );
  16094. enableSubTypeDefaulter(ComponentModel);
  16095. // Add capability of ComponentModel.topologicalTravel.
  16096. enableTopologicalTravel(ComponentModel, getDependencies);
  16097. function getDependencies(componentType) {
  16098. var deps = [];
  16099. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  16100. arrayPush.apply(deps, Clazz.prototype.dependencies || []);
  16101. });
  16102. // Ensure main type
  16103. return map(deps, function (type) {
  16104. return parseClassType$1(type).main;
  16105. });
  16106. }
  16107. mixin(ComponentModel, boxLayoutMixin);
  16108. var platform = '';
  16109. // Navigator not exists in node
  16110. if (typeof navigator !== 'undefined') {
  16111. platform = navigator.platform || '';
  16112. }
  16113. var globalDefault = {
  16114. // 全图默认背景
  16115. // backgroundColor: 'rgba(0,0,0,0)',
  16116. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  16117. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  16118. // 浅色
  16119. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  16120. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  16121. // 深色
  16122. color: ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  16123. // 默认需要 Grid 配置项
  16124. // grid: {},
  16125. // 主题,主题
  16126. textStyle: {
  16127. // color: '#000',
  16128. // decoration: 'none',
  16129. // PENDING
  16130. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  16131. // fontFamily: 'Arial, Verdana, sans-serif',
  16132. fontSize: 12,
  16133. fontStyle: 'normal',
  16134. fontWeight: 'normal'
  16135. },
  16136. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  16137. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  16138. // Default is source-over
  16139. blendMode: null,
  16140. animation: 'auto',
  16141. animationDuration: 1000,
  16142. animationDurationUpdate: 300,
  16143. animationEasing: 'exponentialOut',
  16144. animationEasingUpdate: 'cubicOut',
  16145. animationThreshold: 2000,
  16146. // Configuration for progressive/incremental rendering
  16147. progressiveThreshold: 3000,
  16148. progressive: 400,
  16149. // Threshold of if use single hover layer to optimize.
  16150. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  16151. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  16152. // which is unexpected.
  16153. // see example <echarts/test/heatmap-large.html>.
  16154. hoverLayerThreshold: 3000,
  16155. // See: module:echarts/scale/Time
  16156. useUTC: false
  16157. };
  16158. var colorPaletteMixin = {
  16159. clearColorPalette: function () {
  16160. set$1(this, 'colorIdx', 0);
  16161. set$1(this, 'colorNameMap', {});
  16162. },
  16163. getColorFromPalette: function (name, scope) {
  16164. scope = scope || this;
  16165. var colorIdx = get(scope, 'colorIdx') || 0;
  16166. var colorNameMap = get(scope, 'colorNameMap') || set$1(scope, 'colorNameMap', {});
  16167. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  16168. if (colorNameMap.hasOwnProperty(name)) {
  16169. return colorNameMap[name];
  16170. }
  16171. var colorPalette = this.get('color', true) || [];
  16172. if (!colorPalette.length) {
  16173. return;
  16174. }
  16175. var color = colorPalette[colorIdx];
  16176. if (name) {
  16177. colorNameMap[name] = color;
  16178. }
  16179. set$1(scope, 'colorIdx', (colorIdx + 1) % colorPalette.length);
  16180. return color;
  16181. }
  16182. };
  16183. /**
  16184. * ECharts global model
  16185. *
  16186. * @module {echarts/model/Global}
  16187. */
  16188. /**
  16189. * Caution: If the mechanism should be changed some day, these cases
  16190. * should be considered:
  16191. *
  16192. * (1) In `merge option` mode, if using the same option to call `setOption`
  16193. * many times, the result should be the same (try our best to ensure that).
  16194. * (2) In `merge option` mode, if a component has no id/name specified, it
  16195. * will be merged by index, and the result sequence of the components is
  16196. * consistent to the original sequence.
  16197. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  16198. * `mergeOption` in module:echarts/model/OptionManager.
  16199. */
  16200. var each$2 = each$1;
  16201. var filter$1 = filter;
  16202. var map$1 = map;
  16203. var isArray$1 = isArray;
  16204. var indexOf$1 = indexOf;
  16205. var isObject$1 = isObject;
  16206. var OPTION_INNER_KEY = '\0_ec_inner';
  16207. /**
  16208. * @alias module:echarts/model/Global
  16209. *
  16210. * @param {Object} option
  16211. * @param {module:echarts/model/Model} parentModel
  16212. * @param {Object} theme
  16213. */
  16214. var GlobalModel = Model.extend({
  16215. constructor: GlobalModel,
  16216. init: function (option, parentModel, theme, optionManager) {
  16217. theme = theme || {};
  16218. this.option = null; // Mark as not initialized.
  16219. /**
  16220. * @type {module:echarts/model/Model}
  16221. * @private
  16222. */
  16223. this._theme = new Model(theme);
  16224. /**
  16225. * @type {module:echarts/model/OptionManager}
  16226. */
  16227. this._optionManager = optionManager;
  16228. },
  16229. setOption: function (option, optionPreprocessorFuncs) {
  16230. assert(
  16231. !(OPTION_INNER_KEY in option),
  16232. 'please use chart.getOption()'
  16233. );
  16234. this._optionManager.setOption(option, optionPreprocessorFuncs);
  16235. this.resetOption(null);
  16236. },
  16237. /**
  16238. * @param {string} type null/undefined: reset all.
  16239. * 'recreate': force recreate all.
  16240. * 'timeline': only reset timeline option
  16241. * 'media': only reset media query option
  16242. * @return {boolean} Whether option changed.
  16243. */
  16244. resetOption: function (type) {
  16245. var optionChanged = false;
  16246. var optionManager = this._optionManager;
  16247. if (!type || type === 'recreate') {
  16248. var baseOption = optionManager.mountOption(type === 'recreate');
  16249. if (!this.option || type === 'recreate') {
  16250. initBase.call(this, baseOption);
  16251. }
  16252. else {
  16253. this.restoreData();
  16254. this.mergeOption(baseOption);
  16255. }
  16256. optionChanged = true;
  16257. }
  16258. if (type === 'timeline' || type === 'media') {
  16259. this.restoreData();
  16260. }
  16261. if (!type || type === 'recreate' || type === 'timeline') {
  16262. var timelineOption = optionManager.getTimelineOption(this);
  16263. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  16264. }
  16265. if (!type || type === 'recreate' || type === 'media') {
  16266. var mediaOptions = optionManager.getMediaOption(this, this._api);
  16267. if (mediaOptions.length) {
  16268. each$2(mediaOptions, function (mediaOption) {
  16269. this.mergeOption(mediaOption, optionChanged = true);
  16270. }, this);
  16271. }
  16272. }
  16273. return optionChanged;
  16274. },
  16275. /**
  16276. * @protected
  16277. */
  16278. mergeOption: function (newOption) {
  16279. var option = this.option;
  16280. var componentsMap = this._componentsMap;
  16281. var newCptTypes = [];
  16282. // 如果不存在对应的 component model 则直接 merge
  16283. each$2(newOption, function (componentOption, mainType) {
  16284. if (componentOption == null) {
  16285. return;
  16286. }
  16287. if (!ComponentModel.hasClass(mainType)) {
  16288. option[mainType] = option[mainType] == null
  16289. ? clone(componentOption)
  16290. : merge(option[mainType], componentOption, true);
  16291. }
  16292. else {
  16293. newCptTypes.push(mainType);
  16294. }
  16295. });
  16296. // FIXME OPTION 同步是否要改回原来的
  16297. ComponentModel.topologicalTravel(
  16298. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  16299. );
  16300. this._seriesIndices = this._seriesIndices || [];
  16301. function visitComponent(mainType, dependencies) {
  16302. var newCptOptionList = normalizeToArray(newOption[mainType]);
  16303. var mapResult = mappingToExists(
  16304. componentsMap.get(mainType), newCptOptionList
  16305. );
  16306. makeIdAndName(mapResult);
  16307. // Set mainType and complete subType.
  16308. each$2(mapResult, function (item, index) {
  16309. var opt = item.option;
  16310. if (isObject$1(opt)) {
  16311. item.keyInfo.mainType = mainType;
  16312. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  16313. }
  16314. });
  16315. var dependentModels = getComponentsByTypes(
  16316. componentsMap, dependencies
  16317. );
  16318. option[mainType] = [];
  16319. componentsMap.set(mainType, []);
  16320. each$2(mapResult, function (resultItem, index) {
  16321. var componentModel = resultItem.exist;
  16322. var newCptOption = resultItem.option;
  16323. assert(
  16324. isObject$1(newCptOption) || componentModel,
  16325. 'Empty component definition'
  16326. );
  16327. // Consider where is no new option and should be merged using {},
  16328. // see removeEdgeAndAdd in topologicalTravel and
  16329. // ComponentModel.getAllClassMainTypes.
  16330. if (!newCptOption) {
  16331. componentModel.mergeOption({}, this);
  16332. componentModel.optionUpdated({}, false);
  16333. }
  16334. else {
  16335. var ComponentModelClass = ComponentModel.getClass(
  16336. mainType, resultItem.keyInfo.subType, true
  16337. );
  16338. if (componentModel && componentModel instanceof ComponentModelClass) {
  16339. componentModel.name = resultItem.keyInfo.name;
  16340. componentModel.mergeOption(newCptOption, this);
  16341. componentModel.optionUpdated(newCptOption, false);
  16342. }
  16343. else {
  16344. // PENDING Global as parent ?
  16345. var extraOpt = extend(
  16346. {
  16347. dependentModels: dependentModels,
  16348. componentIndex: index
  16349. },
  16350. resultItem.keyInfo
  16351. );
  16352. componentModel = new ComponentModelClass(
  16353. newCptOption, this, this, extraOpt
  16354. );
  16355. extend(componentModel, extraOpt);
  16356. componentModel.init(newCptOption, this, this, extraOpt);
  16357. // Call optionUpdated after init.
  16358. // newCptOption has been used as componentModel.option
  16359. // and may be merged with theme and default, so pass null
  16360. // to avoid confusion.
  16361. componentModel.optionUpdated(null, true);
  16362. }
  16363. }
  16364. componentsMap.get(mainType)[index] = componentModel;
  16365. option[mainType][index] = componentModel.option;
  16366. }, this);
  16367. // Backup series for filtering.
  16368. if (mainType === 'series') {
  16369. this._seriesIndices = createSeriesIndices(componentsMap.get('series'));
  16370. }
  16371. }
  16372. },
  16373. /**
  16374. * Get option for output (cloned option and inner info removed)
  16375. * @public
  16376. * @return {Object}
  16377. */
  16378. getOption: function () {
  16379. var option = clone(this.option);
  16380. each$2(option, function (opts, mainType) {
  16381. if (ComponentModel.hasClass(mainType)) {
  16382. var opts = normalizeToArray(opts);
  16383. for (var i = opts.length - 1; i >= 0; i--) {
  16384. // Remove options with inner id.
  16385. if (isIdInner(opts[i])) {
  16386. opts.splice(i, 1);
  16387. }
  16388. }
  16389. option[mainType] = opts;
  16390. }
  16391. });
  16392. delete option[OPTION_INNER_KEY];
  16393. return option;
  16394. },
  16395. /**
  16396. * @return {module:echarts/model/Model}
  16397. */
  16398. getTheme: function () {
  16399. return this._theme;
  16400. },
  16401. /**
  16402. * @param {string} mainType
  16403. * @param {number} [idx=0]
  16404. * @return {module:echarts/model/Component}
  16405. */
  16406. getComponent: function (mainType, idx) {
  16407. var list = this._componentsMap.get(mainType);
  16408. if (list) {
  16409. return list[idx || 0];
  16410. }
  16411. },
  16412. /**
  16413. * If none of index and id and name used, return all components with mainType.
  16414. * @param {Object} condition
  16415. * @param {string} condition.mainType
  16416. * @param {string} [condition.subType] If ignore, only query by mainType
  16417. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  16418. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  16419. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  16420. * @return {Array.<module:echarts/model/Component>}
  16421. */
  16422. queryComponents: function (condition) {
  16423. var mainType = condition.mainType;
  16424. if (!mainType) {
  16425. return [];
  16426. }
  16427. var index = condition.index;
  16428. var id = condition.id;
  16429. var name = condition.name;
  16430. var cpts = this._componentsMap.get(mainType);
  16431. if (!cpts || !cpts.length) {
  16432. return [];
  16433. }
  16434. var result;
  16435. if (index != null) {
  16436. if (!isArray$1(index)) {
  16437. index = [index];
  16438. }
  16439. result = filter$1(map$1(index, function (idx) {
  16440. return cpts[idx];
  16441. }), function (val) {
  16442. return !!val;
  16443. });
  16444. }
  16445. else if (id != null) {
  16446. var isIdArray = isArray$1(id);
  16447. result = filter$1(cpts, function (cpt) {
  16448. return (isIdArray && indexOf$1(id, cpt.id) >= 0)
  16449. || (!isIdArray && cpt.id === id);
  16450. });
  16451. }
  16452. else if (name != null) {
  16453. var isNameArray = isArray$1(name);
  16454. result = filter$1(cpts, function (cpt) {
  16455. return (isNameArray && indexOf$1(name, cpt.name) >= 0)
  16456. || (!isNameArray && cpt.name === name);
  16457. });
  16458. }
  16459. else {
  16460. // Return all components with mainType
  16461. result = cpts.slice();
  16462. }
  16463. return filterBySubType(result, condition);
  16464. },
  16465. /**
  16466. * The interface is different from queryComponents,
  16467. * which is convenient for inner usage.
  16468. *
  16469. * @usage
  16470. * var result = findComponents(
  16471. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  16472. * );
  16473. * var result = findComponents(
  16474. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  16475. * );
  16476. * var result = findComponents(
  16477. * {mainType: 'series'},
  16478. * function (model, index) {...}
  16479. * );
  16480. * // result like [component0, componnet1, ...]
  16481. *
  16482. * @param {Object} condition
  16483. * @param {string} condition.mainType Mandatory.
  16484. * @param {string} [condition.subType] Optional.
  16485. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  16486. * where xxx is mainType.
  16487. * If query attribute is null/undefined or has no index/id/name,
  16488. * do not filtering by query conditions, which is convenient for
  16489. * no-payload situations or when target of action is global.
  16490. * @param {Function} [condition.filter] parameter: component, return boolean.
  16491. * @return {Array.<module:echarts/model/Component>}
  16492. */
  16493. findComponents: function (condition) {
  16494. var query = condition.query;
  16495. var mainType = condition.mainType;
  16496. var queryCond = getQueryCond(query);
  16497. var result = queryCond
  16498. ? this.queryComponents(queryCond)
  16499. : this._componentsMap.get(mainType);
  16500. return doFilter(filterBySubType(result, condition));
  16501. function getQueryCond(q) {
  16502. var indexAttr = mainType + 'Index';
  16503. var idAttr = mainType + 'Id';
  16504. var nameAttr = mainType + 'Name';
  16505. return q && (
  16506. q[indexAttr] != null
  16507. || q[idAttr] != null
  16508. || q[nameAttr] != null
  16509. )
  16510. ? {
  16511. mainType: mainType,
  16512. // subType will be filtered finally.
  16513. index: q[indexAttr],
  16514. id: q[idAttr],
  16515. name: q[nameAttr]
  16516. }
  16517. : null;
  16518. }
  16519. function doFilter(res) {
  16520. return condition.filter
  16521. ? filter$1(res, condition.filter)
  16522. : res;
  16523. }
  16524. },
  16525. /**
  16526. * @usage
  16527. * eachComponent('legend', function (legendModel, index) {
  16528. * ...
  16529. * });
  16530. * eachComponent(function (componentType, model, index) {
  16531. * // componentType does not include subType
  16532. * // (componentType is 'xxx' but not 'xxx.aa')
  16533. * });
  16534. * eachComponent(
  16535. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  16536. * function (model, index) {...}
  16537. * );
  16538. * eachComponent(
  16539. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  16540. * function (model, index) {...}
  16541. * );
  16542. *
  16543. * @param {string|Object=} mainType When mainType is object, the definition
  16544. * is the same as the method 'findComponents'.
  16545. * @param {Function} cb
  16546. * @param {*} context
  16547. */
  16548. eachComponent: function (mainType, cb, context) {
  16549. var componentsMap = this._componentsMap;
  16550. if (typeof mainType === 'function') {
  16551. context = cb;
  16552. cb = mainType;
  16553. componentsMap.each(function (components, componentType) {
  16554. each$2(components, function (component, index) {
  16555. cb.call(context, componentType, component, index);
  16556. });
  16557. });
  16558. }
  16559. else if (isString(mainType)) {
  16560. each$2(componentsMap.get(mainType), cb, context);
  16561. }
  16562. else if (isObject$1(mainType)) {
  16563. var queryResult = this.findComponents(mainType);
  16564. each$2(queryResult, cb, context);
  16565. }
  16566. },
  16567. /**
  16568. * @param {string} name
  16569. * @return {Array.<module:echarts/model/Series>}
  16570. */
  16571. getSeriesByName: function (name) {
  16572. var series = this._componentsMap.get('series');
  16573. return filter$1(series, function (oneSeries) {
  16574. return oneSeries.name === name;
  16575. });
  16576. },
  16577. /**
  16578. * @param {number} seriesIndex
  16579. * @return {module:echarts/model/Series}
  16580. */
  16581. getSeriesByIndex: function (seriesIndex) {
  16582. return this._componentsMap.get('series')[seriesIndex];
  16583. },
  16584. /**
  16585. * @param {string} subType
  16586. * @return {Array.<module:echarts/model/Series>}
  16587. */
  16588. getSeriesByType: function (subType) {
  16589. var series = this._componentsMap.get('series');
  16590. return filter$1(series, function (oneSeries) {
  16591. return oneSeries.subType === subType;
  16592. });
  16593. },
  16594. /**
  16595. * @return {Array.<module:echarts/model/Series>}
  16596. */
  16597. getSeries: function () {
  16598. return this._componentsMap.get('series').slice();
  16599. },
  16600. /**
  16601. * After filtering, series may be different
  16602. * frome raw series.
  16603. *
  16604. * @param {Function} cb
  16605. * @param {*} context
  16606. */
  16607. eachSeries: function (cb, context) {
  16608. assertSeriesInitialized(this);
  16609. each$2(this._seriesIndices, function (rawSeriesIndex) {
  16610. var series = this._componentsMap.get('series')[rawSeriesIndex];
  16611. cb.call(context, series, rawSeriesIndex);
  16612. }, this);
  16613. },
  16614. /**
  16615. * Iterate raw series before filtered.
  16616. *
  16617. * @param {Function} cb
  16618. * @param {*} context
  16619. */
  16620. eachRawSeries: function (cb, context) {
  16621. each$2(this._componentsMap.get('series'), cb, context);
  16622. },
  16623. /**
  16624. * After filtering, series may be different.
  16625. * frome raw series.
  16626. *
  16627. * @parma {string} subType
  16628. * @param {Function} cb
  16629. * @param {*} context
  16630. */
  16631. eachSeriesByType: function (subType, cb, context) {
  16632. assertSeriesInitialized(this);
  16633. each$2(this._seriesIndices, function (rawSeriesIndex) {
  16634. var series = this._componentsMap.get('series')[rawSeriesIndex];
  16635. if (series.subType === subType) {
  16636. cb.call(context, series, rawSeriesIndex);
  16637. }
  16638. }, this);
  16639. },
  16640. /**
  16641. * Iterate raw series before filtered of given type.
  16642. *
  16643. * @parma {string} subType
  16644. * @param {Function} cb
  16645. * @param {*} context
  16646. */
  16647. eachRawSeriesByType: function (subType, cb, context) {
  16648. return each$2(this.getSeriesByType(subType), cb, context);
  16649. },
  16650. /**
  16651. * @param {module:echarts/model/Series} seriesModel
  16652. */
  16653. isSeriesFiltered: function (seriesModel) {
  16654. assertSeriesInitialized(this);
  16655. return indexOf(this._seriesIndices, seriesModel.componentIndex) < 0;
  16656. },
  16657. /**
  16658. * @return {Array.<number>}
  16659. */
  16660. getCurrentSeriesIndices: function () {
  16661. return (this._seriesIndices || []).slice();
  16662. },
  16663. /**
  16664. * @param {Function} cb
  16665. * @param {*} context
  16666. */
  16667. filterSeries: function (cb, context) {
  16668. assertSeriesInitialized(this);
  16669. var filteredSeries = filter$1(
  16670. this._componentsMap.get('series'), cb, context
  16671. );
  16672. this._seriesIndices = createSeriesIndices(filteredSeries);
  16673. },
  16674. restoreData: function () {
  16675. var componentsMap = this._componentsMap;
  16676. this._seriesIndices = createSeriesIndices(componentsMap.get('series'));
  16677. var componentTypes = [];
  16678. componentsMap.each(function (components, componentType) {
  16679. componentTypes.push(componentType);
  16680. });
  16681. ComponentModel.topologicalTravel(
  16682. componentTypes,
  16683. ComponentModel.getAllClassMainTypes(),
  16684. function (componentType, dependencies) {
  16685. each$2(componentsMap.get(componentType), function (component) {
  16686. component.restoreData();
  16687. });
  16688. }
  16689. );
  16690. }
  16691. });
  16692. /**
  16693. * @inner
  16694. */
  16695. function mergeTheme(option, theme) {
  16696. each$1(theme, function (themeItem, name) {
  16697. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  16698. if (!ComponentModel.hasClass(name)) {
  16699. if (typeof themeItem === 'object') {
  16700. option[name] = !option[name]
  16701. ? clone(themeItem)
  16702. : merge(option[name], themeItem, false);
  16703. }
  16704. else {
  16705. if (option[name] == null) {
  16706. option[name] = themeItem;
  16707. }
  16708. }
  16709. }
  16710. });
  16711. }
  16712. function initBase(baseOption) {
  16713. baseOption = baseOption;
  16714. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  16715. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  16716. this.option = {};
  16717. this.option[OPTION_INNER_KEY] = 1;
  16718. /**
  16719. * Init with series: [], in case of calling findSeries method
  16720. * before series initialized.
  16721. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  16722. * @private
  16723. */
  16724. this._componentsMap = createHashMap({series: []});
  16725. /**
  16726. * Mapping between filtered series list and raw series list.
  16727. * key: filtered series indices, value: raw series indices.
  16728. * @type {Array.<nubmer>}
  16729. * @private
  16730. */
  16731. this._seriesIndices = null;
  16732. mergeTheme(baseOption, this._theme.option);
  16733. // TODO Needs clone when merging to the unexisted property
  16734. merge(baseOption, globalDefault, false);
  16735. this.mergeOption(baseOption);
  16736. }
  16737. /**
  16738. * @inner
  16739. * @param {Array.<string>|string} types model types
  16740. * @return {Object} key: {string} type, value: {Array.<Object>} models
  16741. */
  16742. function getComponentsByTypes(componentsMap, types) {
  16743. if (!isArray(types)) {
  16744. types = types ? [types] : [];
  16745. }
  16746. var ret = {};
  16747. each$2(types, function (type) {
  16748. ret[type] = (componentsMap.get(type) || []).slice();
  16749. });
  16750. return ret;
  16751. }
  16752. /**
  16753. * @inner
  16754. */
  16755. function determineSubType(mainType, newCptOption, existComponent) {
  16756. var subType = newCptOption.type
  16757. ? newCptOption.type
  16758. : existComponent
  16759. ? existComponent.subType
  16760. // Use determineSubType only when there is no existComponent.
  16761. : ComponentModel.determineSubType(mainType, newCptOption);
  16762. // tooltip, markline, markpoint may always has no subType
  16763. return subType;
  16764. }
  16765. /**
  16766. * @inner
  16767. */
  16768. function createSeriesIndices(seriesModels) {
  16769. return map$1(seriesModels, function (series) {
  16770. return series.componentIndex;
  16771. }) || [];
  16772. }
  16773. /**
  16774. * @inner
  16775. */
  16776. function filterBySubType(components, condition) {
  16777. // Using hasOwnProperty for restrict. Consider
  16778. // subType is undefined in user payload.
  16779. return condition.hasOwnProperty('subType')
  16780. ? filter$1(components, function (cpt) {
  16781. return cpt.subType === condition.subType;
  16782. })
  16783. : components;
  16784. }
  16785. /**
  16786. * @inner
  16787. */
  16788. function assertSeriesInitialized(ecModel) {
  16789. // Components that use _seriesIndices should depends on series component,
  16790. // which make sure that their initialization is after series.
  16791. if (__DEV__) {
  16792. if (!ecModel._seriesIndices) {
  16793. throw new Error('Option should contains series.');
  16794. }
  16795. }
  16796. }
  16797. mixin(GlobalModel, colorPaletteMixin);
  16798. var echartsAPIList = [
  16799. 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',
  16800. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',
  16801. 'getViewOfComponentModel', 'getViewOfSeriesModel'
  16802. ];
  16803. // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  16804. function ExtensionAPI(chartInstance) {
  16805. each$1(echartsAPIList, function (name) {
  16806. this[name] = bind(chartInstance[name], chartInstance);
  16807. }, this);
  16808. }
  16809. var coordinateSystemCreators = {};
  16810. function CoordinateSystemManager() {
  16811. this._coordinateSystems = [];
  16812. }
  16813. CoordinateSystemManager.prototype = {
  16814. constructor: CoordinateSystemManager,
  16815. create: function (ecModel, api) {
  16816. var coordinateSystems = [];
  16817. each$1(coordinateSystemCreators, function (creater, type) {
  16818. var list = creater.create(ecModel, api);
  16819. coordinateSystems = coordinateSystems.concat(list || []);
  16820. });
  16821. this._coordinateSystems = coordinateSystems;
  16822. },
  16823. update: function (ecModel, api) {
  16824. each$1(this._coordinateSystems, function (coordSys) {
  16825. // FIXME MUST have
  16826. coordSys.update && coordSys.update(ecModel, api);
  16827. });
  16828. },
  16829. getCoordinateSystems: function () {
  16830. return this._coordinateSystems.slice();
  16831. }
  16832. };
  16833. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  16834. coordinateSystemCreators[type] = coordinateSystemCreator;
  16835. };
  16836. CoordinateSystemManager.get = function (type) {
  16837. return coordinateSystemCreators[type];
  16838. };
  16839. /**
  16840. * ECharts option manager
  16841. *
  16842. * @module {echarts/model/OptionManager}
  16843. */
  16844. var each$5 = each$1;
  16845. var clone$2 = clone;
  16846. var map$2 = map;
  16847. var merge$1 = merge;
  16848. var QUERY_REG = /^(min|max)?(.+)$/;
  16849. /**
  16850. * TERM EXPLANATIONS:
  16851. *
  16852. * [option]:
  16853. *
  16854. * An object that contains definitions of components. For example:
  16855. * var option = {
  16856. * title: {...},
  16857. * legend: {...},
  16858. * visualMap: {...},
  16859. * series: [
  16860. * {data: [...]},
  16861. * {data: [...]},
  16862. * ...
  16863. * ]
  16864. * };
  16865. *
  16866. * [rawOption]:
  16867. *
  16868. * An object input to echarts.setOption. 'rawOption' may be an
  16869. * 'option', or may be an object contains multi-options. For example:
  16870. * var option = {
  16871. * baseOption: {
  16872. * title: {...},
  16873. * legend: {...},
  16874. * series: [
  16875. * {data: [...]},
  16876. * {data: [...]},
  16877. * ...
  16878. * ]
  16879. * },
  16880. * timeline: {...},
  16881. * options: [
  16882. * {title: {...}, series: {data: [...]}},
  16883. * {title: {...}, series: {data: [...]}},
  16884. * ...
  16885. * ],
  16886. * media: [
  16887. * {
  16888. * query: {maxWidth: 320},
  16889. * option: {series: {x: 20}, visualMap: {show: false}}
  16890. * },
  16891. * {
  16892. * query: {minWidth: 320, maxWidth: 720},
  16893. * option: {series: {x: 500}, visualMap: {show: true}}
  16894. * },
  16895. * {
  16896. * option: {series: {x: 1200}, visualMap: {show: true}}
  16897. * }
  16898. * ]
  16899. * };
  16900. *
  16901. * @alias module:echarts/model/OptionManager
  16902. * @param {module:echarts/ExtensionAPI} api
  16903. */
  16904. function OptionManager(api) {
  16905. /**
  16906. * @private
  16907. * @type {module:echarts/ExtensionAPI}
  16908. */
  16909. this._api = api;
  16910. /**
  16911. * @private
  16912. * @type {Array.<number>}
  16913. */
  16914. this._timelineOptions = [];
  16915. /**
  16916. * @private
  16917. * @type {Array.<Object>}
  16918. */
  16919. this._mediaList = [];
  16920. /**
  16921. * @private
  16922. * @type {Object}
  16923. */
  16924. this._mediaDefault;
  16925. /**
  16926. * -1, means default.
  16927. * empty means no media.
  16928. * @private
  16929. * @type {Array.<number>}
  16930. */
  16931. this._currentMediaIndices = [];
  16932. /**
  16933. * @private
  16934. * @type {Object}
  16935. */
  16936. this._optionBackup;
  16937. /**
  16938. * @private
  16939. * @type {Object}
  16940. */
  16941. this._newBaseOption;
  16942. }
  16943. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  16944. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  16945. // rawOption cloned and backuped when timeline changed, which does no
  16946. // good to performance. What's more, that both timeline and setOption
  16947. // method supply 'notMerge' brings complex and some problems.
  16948. // Consider this case:
  16949. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  16950. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  16951. OptionManager.prototype = {
  16952. constructor: OptionManager,
  16953. /**
  16954. * @public
  16955. * @param {Object} rawOption Raw option.
  16956. * @param {module:echarts/model/Global} ecModel
  16957. * @param {Array.<Function>} optionPreprocessorFuncs
  16958. * @return {Object} Init option
  16959. */
  16960. setOption: function (rawOption, optionPreprocessorFuncs) {
  16961. rawOption = clone$2(rawOption, true);
  16962. // FIXME
  16963. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  16964. var oldOptionBackup = this._optionBackup;
  16965. var newParsedOption = parseRawOption.call(
  16966. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  16967. );
  16968. this._newBaseOption = newParsedOption.baseOption;
  16969. // For setOption at second time (using merge mode);
  16970. if (oldOptionBackup) {
  16971. // Only baseOption can be merged.
  16972. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  16973. // For simplicity, timeline options and media options do not support merge,
  16974. // that is, if you `setOption` twice and both has timeline options, the latter
  16975. // timeline opitons will not be merged to the formers, but just substitude them.
  16976. if (newParsedOption.timelineOptions.length) {
  16977. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  16978. }
  16979. if (newParsedOption.mediaList.length) {
  16980. oldOptionBackup.mediaList = newParsedOption.mediaList;
  16981. }
  16982. if (newParsedOption.mediaDefault) {
  16983. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  16984. }
  16985. }
  16986. else {
  16987. this._optionBackup = newParsedOption;
  16988. }
  16989. },
  16990. /**
  16991. * @param {boolean} isRecreate
  16992. * @return {Object}
  16993. */
  16994. mountOption: function (isRecreate) {
  16995. var optionBackup = this._optionBackup;
  16996. // TODO
  16997. // 如果没有reset功能则不clone。
  16998. this._timelineOptions = map$2(optionBackup.timelineOptions, clone$2);
  16999. this._mediaList = map$2(optionBackup.mediaList, clone$2);
  17000. this._mediaDefault = clone$2(optionBackup.mediaDefault);
  17001. this._currentMediaIndices = [];
  17002. return clone$2(isRecreate
  17003. // this._optionBackup.baseOption, which is created at the first `setOption`
  17004. // called, and is merged into every new option by inner method `mergeOption`
  17005. // each time `setOption` called, can be only used in `isRecreate`, because
  17006. // its reliability is under suspicion. In other cases option merge is
  17007. // performed by `model.mergeOption`.
  17008. ? optionBackup.baseOption : this._newBaseOption
  17009. );
  17010. },
  17011. /**
  17012. * @param {module:echarts/model/Global} ecModel
  17013. * @return {Object}
  17014. */
  17015. getTimelineOption: function (ecModel) {
  17016. var option;
  17017. var timelineOptions = this._timelineOptions;
  17018. if (timelineOptions.length) {
  17019. // getTimelineOption can only be called after ecModel inited,
  17020. // so we can get currentIndex from timelineModel.
  17021. var timelineModel = ecModel.getComponent('timeline');
  17022. if (timelineModel) {
  17023. option = clone$2(
  17024. timelineOptions[timelineModel.getCurrentIndex()],
  17025. true
  17026. );
  17027. }
  17028. }
  17029. return option;
  17030. },
  17031. /**
  17032. * @param {module:echarts/model/Global} ecModel
  17033. * @return {Array.<Object>}
  17034. */
  17035. getMediaOption: function (ecModel) {
  17036. var ecWidth = this._api.getWidth();
  17037. var ecHeight = this._api.getHeight();
  17038. var mediaList = this._mediaList;
  17039. var mediaDefault = this._mediaDefault;
  17040. var indices = [];
  17041. var result = [];
  17042. // No media defined.
  17043. if (!mediaList.length && !mediaDefault) {
  17044. return result;
  17045. }
  17046. // Multi media may be applied, the latter defined media has higher priority.
  17047. for (var i = 0, len = mediaList.length; i < len; i++) {
  17048. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  17049. indices.push(i);
  17050. }
  17051. }
  17052. // FIXME
  17053. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  17054. if (!indices.length && mediaDefault) {
  17055. indices = [-1];
  17056. }
  17057. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  17058. result = map$2(indices, function (index) {
  17059. return clone$2(
  17060. index === -1 ? mediaDefault.option : mediaList[index].option
  17061. );
  17062. });
  17063. }
  17064. // Otherwise return nothing.
  17065. this._currentMediaIndices = indices;
  17066. return result;
  17067. }
  17068. };
  17069. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  17070. var timelineOptions = [];
  17071. var mediaList = [];
  17072. var mediaDefault;
  17073. var baseOption;
  17074. // Compatible with ec2.
  17075. var timelineOpt = rawOption.timeline;
  17076. if (rawOption.baseOption) {
  17077. baseOption = rawOption.baseOption;
  17078. }
  17079. // For timeline
  17080. if (timelineOpt || rawOption.options) {
  17081. baseOption = baseOption || {};
  17082. timelineOptions = (rawOption.options || []).slice();
  17083. }
  17084. // For media query
  17085. if (rawOption.media) {
  17086. baseOption = baseOption || {};
  17087. var media = rawOption.media;
  17088. each$5(media, function (singleMedia) {
  17089. if (singleMedia && singleMedia.option) {
  17090. if (singleMedia.query) {
  17091. mediaList.push(singleMedia);
  17092. }
  17093. else if (!mediaDefault) {
  17094. // Use the first media default.
  17095. mediaDefault = singleMedia;
  17096. }
  17097. }
  17098. });
  17099. }
  17100. // For normal option
  17101. if (!baseOption) {
  17102. baseOption = rawOption;
  17103. }
  17104. // Set timelineOpt to baseOption in ec3,
  17105. // which is convenient for merge option.
  17106. if (!baseOption.timeline) {
  17107. baseOption.timeline = timelineOpt;
  17108. }
  17109. // Preprocess.
  17110. each$5([baseOption].concat(timelineOptions)
  17111. .concat(map(mediaList, function (media) {
  17112. return media.option;
  17113. })),
  17114. function (option) {
  17115. each$5(optionPreprocessorFuncs, function (preProcess) {
  17116. preProcess(option, isNew);
  17117. });
  17118. }
  17119. );
  17120. return {
  17121. baseOption: baseOption,
  17122. timelineOptions: timelineOptions,
  17123. mediaDefault: mediaDefault,
  17124. mediaList: mediaList
  17125. };
  17126. }
  17127. /**
  17128. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  17129. * Support: width, height, aspectRatio
  17130. * Can use max or min as prefix.
  17131. */
  17132. function applyMediaQuery(query, ecWidth, ecHeight) {
  17133. var realMap = {
  17134. width: ecWidth,
  17135. height: ecHeight,
  17136. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  17137. };
  17138. var applicatable = true;
  17139. each$1(query, function (value, attr) {
  17140. var matched = attr.match(QUERY_REG);
  17141. if (!matched || !matched[1] || !matched[2]) {
  17142. return;
  17143. }
  17144. var operator = matched[1];
  17145. var realAttr = matched[2].toLowerCase();
  17146. if (!compare(realMap[realAttr], value, operator)) {
  17147. applicatable = false;
  17148. }
  17149. });
  17150. return applicatable;
  17151. }
  17152. function compare(real, expect, operator) {
  17153. if (operator === 'min') {
  17154. return real >= expect;
  17155. }
  17156. else if (operator === 'max') {
  17157. return real <= expect;
  17158. }
  17159. else { // Equals
  17160. return real === expect;
  17161. }
  17162. }
  17163. function indicesEquals(indices1, indices2) {
  17164. // indices is always order by asc and has only finite number.
  17165. return indices1.join(',') === indices2.join(',');
  17166. }
  17167. /**
  17168. * Consider case:
  17169. * `chart.setOption(opt1);`
  17170. * Then user do some interaction like dataZoom, dataView changing.
  17171. * `chart.setOption(opt2);`
  17172. * Then user press 'reset button' in toolbox.
  17173. *
  17174. * After doing that all of the interaction effects should be reset, the
  17175. * chart should be the same as the result of invoke
  17176. * `chart.setOption(opt1); chart.setOption(opt2);`.
  17177. *
  17178. * Although it is not able ensure that
  17179. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  17180. * `chart.setOption(merge(opt1, opt2));` exactly,
  17181. * this might be the only simple way to implement that feature.
  17182. *
  17183. * MEMO: We've considered some other approaches:
  17184. * 1. Each model handle its self restoration but not uniform treatment.
  17185. * (Too complex in logic and error-prone)
  17186. * 2. Use a shadow ecModel. (Performace expensive)
  17187. */
  17188. function mergeOption(oldOption, newOption) {
  17189. newOption = newOption || {};
  17190. each$5(newOption, function (newCptOpt, mainType) {
  17191. if (newCptOpt == null) {
  17192. return;
  17193. }
  17194. var oldCptOpt = oldOption[mainType];
  17195. if (!ComponentModel.hasClass(mainType)) {
  17196. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  17197. }
  17198. else {
  17199. newCptOpt = normalizeToArray(newCptOpt);
  17200. oldCptOpt = normalizeToArray(oldCptOpt);
  17201. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  17202. oldOption[mainType] = map$2(mapResult, function (item) {
  17203. return (item.option && item.exist)
  17204. ? merge$1(item.exist, item.option, true)
  17205. : (item.exist || item.option);
  17206. });
  17207. }
  17208. });
  17209. }
  17210. var each$6 = each$1;
  17211. var isObject$3 = isObject;
  17212. var POSSIBLE_STYLES = [
  17213. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  17214. 'chordStyle', 'label', 'labelLine'
  17215. ];
  17216. function compatItemStyle(opt) {
  17217. var itemStyleOpt = opt && opt.itemStyle;
  17218. if (!itemStyleOpt) {
  17219. return;
  17220. }
  17221. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  17222. var styleName = POSSIBLE_STYLES[i];
  17223. var normalItemStyleOpt = itemStyleOpt.normal;
  17224. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  17225. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  17226. opt[styleName] = opt[styleName] || {};
  17227. if (!opt[styleName].normal) {
  17228. opt[styleName].normal = normalItemStyleOpt[styleName];
  17229. }
  17230. else {
  17231. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  17232. }
  17233. normalItemStyleOpt[styleName] = null;
  17234. }
  17235. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  17236. opt[styleName] = opt[styleName] || {};
  17237. if (!opt[styleName].emphasis) {
  17238. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  17239. }
  17240. else {
  17241. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  17242. }
  17243. emphasisItemStyleOpt[styleName] = null;
  17244. }
  17245. }
  17246. }
  17247. function compatTextStyle(opt, propName) {
  17248. var labelOptSingle = isObject$3(opt) && opt[propName];
  17249. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  17250. if (textStyle) {
  17251. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  17252. var propName = TEXT_STYLE_OPTIONS[i];
  17253. if (textStyle.hasOwnProperty(propName)) {
  17254. labelOptSingle[propName] = textStyle[propName];
  17255. }
  17256. }
  17257. }
  17258. }
  17259. function compatLabelTextStyle(labelOpt) {
  17260. if (isObject$3(labelOpt)) {
  17261. compatTextStyle(labelOpt, 'normal');
  17262. compatTextStyle(labelOpt, 'emphasis');
  17263. }
  17264. }
  17265. function processSeries(seriesOpt) {
  17266. if (!isObject$3(seriesOpt)) {
  17267. return;
  17268. }
  17269. compatItemStyle(seriesOpt);
  17270. compatLabelTextStyle(seriesOpt.label);
  17271. // treemap
  17272. compatLabelTextStyle(seriesOpt.upperLabel);
  17273. // graph
  17274. compatLabelTextStyle(seriesOpt.edgeLabel);
  17275. var markPoint = seriesOpt.markPoint;
  17276. compatItemStyle(markPoint);
  17277. compatLabelTextStyle(markPoint && markPoint.label);
  17278. var markLine = seriesOpt.markLine;
  17279. compatItemStyle(seriesOpt.markLine);
  17280. compatLabelTextStyle(markLine && markLine.label);
  17281. var markArea = seriesOpt.markArea;
  17282. compatLabelTextStyle(markArea && markArea.label);
  17283. // For gauge
  17284. compatTextStyle(seriesOpt, 'axisLabel');
  17285. compatTextStyle(seriesOpt, 'title');
  17286. compatTextStyle(seriesOpt, 'detail');
  17287. var data = seriesOpt.data;
  17288. if (data) {
  17289. for (var i = 0; i < data.length; i++) {
  17290. compatItemStyle(data[i]);
  17291. compatLabelTextStyle(data[i] && data[i].label);
  17292. }
  17293. }
  17294. // mark point data
  17295. var markPoint = seriesOpt.markPoint;
  17296. if (markPoint && markPoint.data) {
  17297. var mpData = markPoint.data;
  17298. for (var i = 0; i < mpData.length; i++) {
  17299. compatItemStyle(mpData[i]);
  17300. compatLabelTextStyle(mpData[i] && mpData[i].label);
  17301. }
  17302. }
  17303. // mark line data
  17304. var markLine = seriesOpt.markLine;
  17305. if (markLine && markLine.data) {
  17306. var mlData = markLine.data;
  17307. for (var i = 0; i < mlData.length; i++) {
  17308. if (isArray(mlData[i])) {
  17309. compatItemStyle(mlData[i][0]);
  17310. compatLabelTextStyle(mlData[i][0] && mlData[i][0].label);
  17311. compatItemStyle(mlData[i][1]);
  17312. compatLabelTextStyle(mlData[i][1] && mlData[i][1].label);
  17313. }
  17314. else {
  17315. compatItemStyle(mlData[i]);
  17316. compatLabelTextStyle(mlData[i] && mlData[i].label);
  17317. }
  17318. }
  17319. }
  17320. }
  17321. function toArr(o) {
  17322. return isArray(o) ? o : o ? [o] : [];
  17323. }
  17324. function toObj(o) {
  17325. return (isArray(o) ? o[0] : o) || {};
  17326. }
  17327. var compatStyle = function (option, isTheme) {
  17328. each$6(toArr(option.series), function (seriesOpt) {
  17329. isObject$3(seriesOpt) && processSeries(seriesOpt);
  17330. });
  17331. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  17332. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  17333. each$6(
  17334. axes,
  17335. function (axisName) {
  17336. each$6(toArr(option[axisName]), function (axisOpt) {
  17337. if (axisOpt) {
  17338. compatTextStyle(axisOpt, 'axisLabel');
  17339. compatTextStyle(axisOpt.axisPointer, 'label');
  17340. }
  17341. });
  17342. }
  17343. );
  17344. each$6(toArr(option.parallel), function (parallelOpt) {
  17345. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  17346. compatTextStyle(parallelAxisDefault, 'axisLabel');
  17347. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  17348. });
  17349. each$6(toArr(option.calendar), function (calendarOpt) {
  17350. compatTextStyle(calendarOpt, 'dayLabel');
  17351. compatTextStyle(calendarOpt, 'monthLabel');
  17352. compatTextStyle(calendarOpt, 'yearLabel');
  17353. });
  17354. // radar.name.textStyle
  17355. each$6(toArr(option.radar), function (radarOpt) {
  17356. compatTextStyle(radarOpt, 'name');
  17357. });
  17358. each$6(toArr(option.geo), function (geoOpt) {
  17359. if (isObject$3(geoOpt)) {
  17360. compatLabelTextStyle(geoOpt.label);
  17361. each$6(toArr(geoOpt.regions), function (regionObj) {
  17362. compatLabelTextStyle(regionObj.label);
  17363. });
  17364. }
  17365. });
  17366. compatLabelTextStyle(toObj(option.timeline).label);
  17367. compatTextStyle(toObj(option.axisPointer), 'label');
  17368. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  17369. };
  17370. // Compatitable with 2.0
  17371. function get$1(opt, path) {
  17372. path = path.split(',');
  17373. var obj = opt;
  17374. for (var i = 0; i < path.length; i++) {
  17375. obj = obj && obj[path[i]];
  17376. if (obj == null) {
  17377. break;
  17378. }
  17379. }
  17380. return obj;
  17381. }
  17382. function set$2(opt, path, val, overwrite) {
  17383. path = path.split(',');
  17384. var obj = opt;
  17385. var key;
  17386. for (var i = 0; i < path.length - 1; i++) {
  17387. key = path[i];
  17388. if (obj[key] == null) {
  17389. obj[key] = {};
  17390. }
  17391. obj = obj[key];
  17392. }
  17393. if (overwrite || obj[path[i]] == null) {
  17394. obj[path[i]] = val;
  17395. }
  17396. }
  17397. function compatLayoutProperties(option) {
  17398. each$1(LAYOUT_PROPERTIES, function (prop) {
  17399. if (prop[0] in option && !(prop[1] in option)) {
  17400. option[prop[1]] = option[prop[0]];
  17401. }
  17402. });
  17403. }
  17404. var LAYOUT_PROPERTIES = [
  17405. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  17406. ];
  17407. var COMPATITABLE_COMPONENTS = [
  17408. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  17409. ];
  17410. var COMPATITABLE_SERIES = [
  17411. 'bar', 'boxplot', 'candlestick', 'chord', 'effectScatter',
  17412. 'funnel', 'gauge', 'lines', 'graph', 'heatmap', 'line', 'map', 'parallel',
  17413. 'pie', 'radar', 'sankey', 'scatter', 'treemap'
  17414. ];
  17415. var backwardCompat = function (option, isTheme) {
  17416. compatStyle(option, isTheme);
  17417. // Make sure series array for model initialization.
  17418. option.series = normalizeToArray(option.series);
  17419. each$1(option.series, function (seriesOpt) {
  17420. if (!isObject(seriesOpt)) {
  17421. return;
  17422. }
  17423. var seriesType = seriesOpt.type;
  17424. if (seriesType === 'pie' || seriesType === 'gauge') {
  17425. if (seriesOpt.clockWise != null) {
  17426. seriesOpt.clockwise = seriesOpt.clockWise;
  17427. }
  17428. }
  17429. if (seriesType === 'gauge') {
  17430. var pointerColor = get$1(seriesOpt, 'pointer.color');
  17431. pointerColor != null
  17432. && set$2(seriesOpt, 'itemStyle.normal.color', pointerColor);
  17433. }
  17434. for (var i = 0; i < COMPATITABLE_SERIES.length; i++) {
  17435. if (COMPATITABLE_SERIES[i] === seriesOpt.type) {
  17436. compatLayoutProperties(seriesOpt);
  17437. break;
  17438. }
  17439. }
  17440. });
  17441. // dataRange has changed to visualMap
  17442. if (option.dataRange) {
  17443. option.visualMap = option.dataRange;
  17444. }
  17445. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  17446. var options = option[componentName];
  17447. if (options) {
  17448. if (!isArray(options)) {
  17449. options = [options];
  17450. }
  17451. each$1(options, function (option) {
  17452. compatLayoutProperties(option);
  17453. });
  17454. }
  17455. });
  17456. };
  17457. var SeriesModel = ComponentModel.extend({
  17458. type: 'series.__base__',
  17459. /**
  17460. * @readOnly
  17461. */
  17462. seriesIndex: 0,
  17463. // coodinateSystem will be injected in the echarts/CoordinateSystem
  17464. coordinateSystem: null,
  17465. /**
  17466. * @type {Object}
  17467. * @protected
  17468. */
  17469. defaultOption: null,
  17470. /**
  17471. * Data provided for legend
  17472. * @type {Function}
  17473. */
  17474. // PENDING
  17475. legendDataProvider: null,
  17476. /**
  17477. * Access path of color for visual
  17478. */
  17479. visualColorAccessPath: 'itemStyle.normal.color',
  17480. /**
  17481. * Support merge layout params.
  17482. * Only support 'box' now (left/right/top/bottom/width/height).
  17483. * @type {string|Object} Object can be {ignoreSize: true}
  17484. * @readOnly
  17485. */
  17486. layoutMode: null,
  17487. init: function (option, parentModel, ecModel, extraOpt) {
  17488. /**
  17489. * @type {number}
  17490. * @readOnly
  17491. */
  17492. this.seriesIndex = this.componentIndex;
  17493. this.mergeDefaultAndTheme(option, ecModel);
  17494. var data = this.getInitialData(option, ecModel);
  17495. if (__DEV__) {
  17496. assert(data, 'getInitialData returned invalid data.');
  17497. }
  17498. /**
  17499. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  17500. * @private
  17501. */
  17502. set$1(this, 'dataBeforeProcessed', data);
  17503. // If we reverse the order (make data firstly, and then make
  17504. // dataBeforeProcessed by cloneShallow), cloneShallow will
  17505. // cause data.graph.data !== data when using
  17506. // module:echarts/data/Graph or module:echarts/data/Tree.
  17507. // See module:echarts/data/helper/linkList
  17508. this.restoreData();
  17509. },
  17510. /**
  17511. * Util for merge default and theme to option
  17512. * @param {Object} option
  17513. * @param {module:echarts/model/Global} ecModel
  17514. */
  17515. mergeDefaultAndTheme: function (option, ecModel) {
  17516. var layoutMode = this.layoutMode;
  17517. var inputPositionParams = layoutMode
  17518. ? getLayoutParams(option) : {};
  17519. // Backward compat: using subType on theme.
  17520. // But if name duplicate between series subType
  17521. // (for example: parallel) add component mainType,
  17522. // add suffix 'Series'.
  17523. var themeSubType = this.subType;
  17524. if (ComponentModel.hasClass(themeSubType)) {
  17525. themeSubType += 'Series';
  17526. }
  17527. merge(
  17528. option,
  17529. ecModel.getTheme().get(this.subType)
  17530. );
  17531. merge(option, this.getDefaultOption());
  17532. // Default label emphasis `show`
  17533. defaultEmphasis(option.label, ['show']);
  17534. this.fillDataTextStyle(option.data);
  17535. if (layoutMode) {
  17536. mergeLayoutParam(option, inputPositionParams, layoutMode);
  17537. }
  17538. },
  17539. mergeOption: function (newSeriesOption, ecModel) {
  17540. newSeriesOption = merge(this.option, newSeriesOption, true);
  17541. this.fillDataTextStyle(newSeriesOption.data);
  17542. var layoutMode = this.layoutMode;
  17543. if (layoutMode) {
  17544. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  17545. }
  17546. var data = this.getInitialData(newSeriesOption, ecModel);
  17547. // TODO Merge data?
  17548. if (data) {
  17549. set$1(this, 'data', data);
  17550. set$1(this, 'dataBeforeProcessed', data.cloneShallow());
  17551. }
  17552. },
  17553. fillDataTextStyle: function (data) {
  17554. // Default data label emphasis `show`
  17555. // FIXME Tree structure data ?
  17556. // FIXME Performance ?
  17557. if (data) {
  17558. var props = ['show'];
  17559. for (var i = 0; i < data.length; i++) {
  17560. if (data[i] && data[i].label) {
  17561. defaultEmphasis(data[i].label, props);
  17562. }
  17563. }
  17564. }
  17565. },
  17566. /**
  17567. * Init a data structure from data related option in series
  17568. * Must be overwritten
  17569. */
  17570. getInitialData: function () {},
  17571. /**
  17572. * @param {string} [dataType]
  17573. * @return {module:echarts/data/List}
  17574. */
  17575. getData: function (dataType) {
  17576. var data = get(this, 'data');
  17577. return dataType == null ? data : data.getLinkedData(dataType);
  17578. },
  17579. /**
  17580. * @param {module:echarts/data/List} data
  17581. */
  17582. setData: function (data) {
  17583. set$1(this, 'data', data);
  17584. },
  17585. /**
  17586. * Get data before processed
  17587. * @return {module:echarts/data/List}
  17588. */
  17589. getRawData: function () {
  17590. return get(this, 'dataBeforeProcessed');
  17591. },
  17592. /**
  17593. * Coord dimension to data dimension.
  17594. *
  17595. * By default the result is the same as dimensions of series data.
  17596. * But in some series data dimensions are different from coord dimensions (i.e.
  17597. * candlestick and boxplot). Override this method to handle those cases.
  17598. *
  17599. * Coord dimension to data dimension can be one-to-many
  17600. *
  17601. * @param {string} coordDim
  17602. * @return {Array.<string>} dimensions on the axis.
  17603. */
  17604. coordDimToDataDim: function (coordDim) {
  17605. return coordDimToDataDim(this.getData(), coordDim);
  17606. },
  17607. /**
  17608. * Convert data dimension to coord dimension.
  17609. *
  17610. * @param {string|number} dataDim
  17611. * @return {string}
  17612. */
  17613. dataDimToCoordDim: function (dataDim) {
  17614. return dataDimToCoordDim(this.getData(), dataDim);
  17615. },
  17616. /**
  17617. * Get base axis if has coordinate system and has axis.
  17618. * By default use coordSys.getBaseAxis();
  17619. * Can be overrided for some chart.
  17620. * @return {type} description
  17621. */
  17622. getBaseAxis: function () {
  17623. var coordSys = this.coordinateSystem;
  17624. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  17625. },
  17626. // FIXME
  17627. /**
  17628. * Default tooltip formatter
  17629. *
  17630. * @param {number} dataIndex
  17631. * @param {boolean} [multipleSeries=false]
  17632. * @param {number} [dataType]
  17633. */
  17634. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  17635. function formatArrayValue(value) {
  17636. var vertially = reduce(value, function (vertially, val, idx) {
  17637. var dimItem = data.getDimensionInfo(idx);
  17638. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.tooltipName != null;
  17639. }, 0);
  17640. var result = [];
  17641. var tooltipDims = otherDimToDataDim(data, 'tooltip');
  17642. tooltipDims.length
  17643. ? each$1(tooltipDims, function (dimIdx) {
  17644. setEachItem(data.get(dimIdx, dataIndex), dimIdx);
  17645. })
  17646. // By default, all dims is used on tooltip.
  17647. : each$1(value, setEachItem);
  17648. function setEachItem(val, dimIdx) {
  17649. var dimInfo = data.getDimensionInfo(dimIdx);
  17650. // If `dimInfo.tooltip` is not set, show tooltip.
  17651. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  17652. return;
  17653. }
  17654. var dimType = dimInfo.type;
  17655. var valStr = (vertially ? '- ' + (dimInfo.tooltipName || dimInfo.name) + ': ' : '')
  17656. + (dimType === 'ordinal'
  17657. ? val + ''
  17658. : dimType === 'time'
  17659. ? (multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val))
  17660. : addCommas(val)
  17661. );
  17662. valStr && result.push(encodeHTML(valStr));
  17663. }
  17664. return (vertially ? '<br/>' : '') + result.join(vertially ? '<br/>' : ', ');
  17665. }
  17666. var data = get(this, 'data');
  17667. var value = this.getRawValue(dataIndex);
  17668. var formattedValue = isArray(value)
  17669. ? formatArrayValue(value) : encodeHTML(addCommas(value));
  17670. var name = data.getName(dataIndex);
  17671. var color = data.getItemVisual(dataIndex, 'color');
  17672. if (isObject(color) && color.colorStops) {
  17673. color = (color.colorStops[0] || {}).color;
  17674. }
  17675. color = color || 'transparent';
  17676. var colorEl = getTooltipMarker(color);
  17677. var seriesName = this.name;
  17678. // FIXME
  17679. if (seriesName === '\0-') {
  17680. // Not show '-'
  17681. seriesName = '';
  17682. }
  17683. seriesName = seriesName
  17684. ? encodeHTML(seriesName) + (!multipleSeries ? '<br/>' : ': ')
  17685. : '';
  17686. return !multipleSeries
  17687. ? seriesName + colorEl
  17688. + (name
  17689. ? encodeHTML(name) + ': ' + formattedValue
  17690. : formattedValue
  17691. )
  17692. : colorEl + seriesName + formattedValue;
  17693. },
  17694. /**
  17695. * @return {boolean}
  17696. */
  17697. isAnimationEnabled: function () {
  17698. if (env$1.node) {
  17699. return false;
  17700. }
  17701. var animationEnabled = this.getShallow('animation');
  17702. if (animationEnabled) {
  17703. if (this.getData().count() > this.getShallow('animationThreshold')) {
  17704. animationEnabled = false;
  17705. }
  17706. }
  17707. return animationEnabled;
  17708. },
  17709. restoreData: function () {
  17710. set$1(this, 'data', get(this, 'dataBeforeProcessed').cloneShallow());
  17711. },
  17712. getColorFromPalette: function (name, scope) {
  17713. var ecModel = this.ecModel;
  17714. // PENDING
  17715. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope);
  17716. if (!color) {
  17717. color = ecModel.getColorFromPalette(name, scope);
  17718. }
  17719. return color;
  17720. },
  17721. /**
  17722. * Get data indices for show tooltip content. See tooltip.
  17723. * @abstract
  17724. * @param {Array.<string>|string} dim
  17725. * @param {Array.<number>} value
  17726. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  17727. * @return {Object} {dataIndices, nestestValue}.
  17728. */
  17729. getAxisTooltipData: null,
  17730. /**
  17731. * See tooltip.
  17732. * @abstract
  17733. * @param {number} dataIndex
  17734. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  17735. */
  17736. getTooltipPosition: null
  17737. });
  17738. mixin(SeriesModel, dataFormatMixin);
  17739. mixin(SeriesModel, colorPaletteMixin);
  17740. var Component$1 = function () {
  17741. /**
  17742. * @type {module:zrender/container/Group}
  17743. * @readOnly
  17744. */
  17745. this.group = new Group();
  17746. /**
  17747. * @type {string}
  17748. * @readOnly
  17749. */
  17750. this.uid = getUID('viewComponent');
  17751. };
  17752. Component$1.prototype = {
  17753. constructor: Component$1,
  17754. init: function (ecModel, api) {},
  17755. render: function (componentModel, ecModel, api, payload) {},
  17756. dispose: function () {}
  17757. };
  17758. var componentProto = Component$1.prototype;
  17759. componentProto.updateView
  17760. = componentProto.updateLayout
  17761. = componentProto.updateVisual
  17762. = function (seriesModel, ecModel, api, payload) {
  17763. // Do nothing;
  17764. };
  17765. // Enable Component.extend.
  17766. enableClassExtend(Component$1);
  17767. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  17768. enableClassManagement(Component$1, {registerWhenExtend: true});
  17769. function Chart() {
  17770. /**
  17771. * @type {module:zrender/container/Group}
  17772. * @readOnly
  17773. */
  17774. this.group = new Group();
  17775. /**
  17776. * @type {string}
  17777. * @readOnly
  17778. */
  17779. this.uid = getUID('viewChart');
  17780. }
  17781. Chart.prototype = {
  17782. type: 'chart',
  17783. /**
  17784. * Init the chart
  17785. * @param {module:echarts/model/Global} ecModel
  17786. * @param {module:echarts/ExtensionAPI} api
  17787. */
  17788. init: function (ecModel, api) {},
  17789. /**
  17790. * Render the chart
  17791. * @param {module:echarts/model/Series} seriesModel
  17792. * @param {module:echarts/model/Global} ecModel
  17793. * @param {module:echarts/ExtensionAPI} api
  17794. * @param {Object} payload
  17795. */
  17796. render: function (seriesModel, ecModel, api, payload) {},
  17797. /**
  17798. * Highlight series or specified data item
  17799. * @param {module:echarts/model/Series} seriesModel
  17800. * @param {module:echarts/model/Global} ecModel
  17801. * @param {module:echarts/ExtensionAPI} api
  17802. * @param {Object} payload
  17803. */
  17804. highlight: function (seriesModel, ecModel, api, payload) {
  17805. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  17806. },
  17807. /**
  17808. * Downplay series or specified data item
  17809. * @param {module:echarts/model/Series} seriesModel
  17810. * @param {module:echarts/model/Global} ecModel
  17811. * @param {module:echarts/ExtensionAPI} api
  17812. * @param {Object} payload
  17813. */
  17814. downplay: function (seriesModel, ecModel, api, payload) {
  17815. toggleHighlight(seriesModel.getData(), payload, 'normal');
  17816. },
  17817. /**
  17818. * Remove self
  17819. * @param {module:echarts/model/Global} ecModel
  17820. * @param {module:echarts/ExtensionAPI} api
  17821. */
  17822. remove: function (ecModel, api) {
  17823. this.group.removeAll();
  17824. },
  17825. /**
  17826. * Dispose self
  17827. * @param {module:echarts/model/Global} ecModel
  17828. * @param {module:echarts/ExtensionAPI} api
  17829. */
  17830. dispose: function () {}
  17831. /**
  17832. * The view contains the given point.
  17833. * @interface
  17834. * @param {Array.<number>} point
  17835. * @return {boolean}
  17836. */
  17837. // containPoint: function () {}
  17838. };
  17839. var chartProto = Chart.prototype;
  17840. chartProto.updateView
  17841. = chartProto.updateLayout
  17842. = chartProto.updateVisual
  17843. = function (seriesModel, ecModel, api, payload) {
  17844. this.render(seriesModel, ecModel, api, payload);
  17845. };
  17846. /**
  17847. * Set state of single element
  17848. * @param {module:zrender/Element} el
  17849. * @param {string} state
  17850. */
  17851. function elSetState(el, state) {
  17852. if (el) {
  17853. el.trigger(state);
  17854. if (el.type === 'group') {
  17855. for (var i = 0; i < el.childCount(); i++) {
  17856. elSetState(el.childAt(i), state);
  17857. }
  17858. }
  17859. }
  17860. }
  17861. /**
  17862. * @param {module:echarts/data/List} data
  17863. * @param {Object} payload
  17864. * @param {string} state 'normal'|'emphasis'
  17865. * @inner
  17866. */
  17867. function toggleHighlight(data, payload, state) {
  17868. var dataIndex = queryDataIndex(data, payload);
  17869. if (dataIndex != null) {
  17870. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  17871. elSetState(data.getItemGraphicEl(dataIdx), state);
  17872. });
  17873. }
  17874. else {
  17875. data.eachItemGraphicEl(function (el) {
  17876. elSetState(el, state);
  17877. });
  17878. }
  17879. }
  17880. // Enable Chart.extend.
  17881. enableClassExtend(Chart, ['dispose']);
  17882. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  17883. enableClassManagement(Chart, {registerWhenExtend: true});
  17884. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  17885. var RATE = '\0__throttleRate';
  17886. var THROTTLE_TYPE = '\0__throttleType';
  17887. /**
  17888. * @public
  17889. * @param {(Function)} fn
  17890. * @param {number} [delay=0] Unit: ms.
  17891. * @param {boolean} [debounce=false]
  17892. * true: If call interval less than `delay`, only the last call works.
  17893. * false: If call interval less than `delay, call works on fixed rate.
  17894. * @return {(Function)} throttled fn.
  17895. */
  17896. function throttle(fn, delay, debounce) {
  17897. var currCall;
  17898. var lastCall = 0;
  17899. var lastExec = 0;
  17900. var timer = null;
  17901. var diff;
  17902. var scope;
  17903. var args;
  17904. var debounceNextCall;
  17905. delay = delay || 0;
  17906. function exec() {
  17907. lastExec = (new Date()).getTime();
  17908. timer = null;
  17909. fn.apply(scope, args || []);
  17910. }
  17911. var cb = function () {
  17912. currCall = (new Date()).getTime();
  17913. scope = this;
  17914. args = arguments;
  17915. var thisDelay = debounceNextCall || delay;
  17916. var thisDebounce = debounceNextCall || debounce;
  17917. debounceNextCall = null;
  17918. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  17919. clearTimeout(timer);
  17920. if (thisDebounce) {
  17921. timer = setTimeout(exec, thisDelay);
  17922. }
  17923. else {
  17924. if (diff >= 0) {
  17925. exec();
  17926. }
  17927. else {
  17928. timer = setTimeout(exec, -diff);
  17929. }
  17930. }
  17931. lastCall = currCall;
  17932. };
  17933. /**
  17934. * Clear throttle.
  17935. * @public
  17936. */
  17937. cb.clear = function () {
  17938. if (timer) {
  17939. clearTimeout(timer);
  17940. timer = null;
  17941. }
  17942. };
  17943. /**
  17944. * Enable debounce once.
  17945. */
  17946. cb.debounceNextCall = function (debounceDelay) {
  17947. debounceNextCall = debounceDelay;
  17948. };
  17949. return cb;
  17950. }
  17951. /**
  17952. * Create throttle method or update throttle rate.
  17953. *
  17954. * @example
  17955. * ComponentView.prototype.render = function () {
  17956. * ...
  17957. * throttle.createOrUpdate(
  17958. * this,
  17959. * '_dispatchAction',
  17960. * this.model.get('throttle'),
  17961. * 'fixRate'
  17962. * );
  17963. * };
  17964. * ComponentView.prototype.remove = function () {
  17965. * throttle.clear(this, '_dispatchAction');
  17966. * };
  17967. * ComponentView.prototype.dispose = function () {
  17968. * throttle.clear(this, '_dispatchAction');
  17969. * };
  17970. *
  17971. * @public
  17972. * @param {Object} obj
  17973. * @param {string} fnAttr
  17974. * @param {number} [rate]
  17975. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  17976. * @return {Function} throttled function.
  17977. */
  17978. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  17979. var fn = obj[fnAttr];
  17980. if (!fn) {
  17981. return;
  17982. }
  17983. var originFn = fn[ORIGIN_METHOD] || fn;
  17984. var lastThrottleType = fn[THROTTLE_TYPE];
  17985. var lastRate = fn[RATE];
  17986. if (lastRate !== rate || lastThrottleType !== throttleType) {
  17987. if (rate == null || !throttleType) {
  17988. return (obj[fnAttr] = originFn);
  17989. }
  17990. fn = obj[fnAttr] = throttle(
  17991. originFn, rate, throttleType === 'debounce'
  17992. );
  17993. fn[ORIGIN_METHOD] = originFn;
  17994. fn[THROTTLE_TYPE] = throttleType;
  17995. fn[RATE] = rate;
  17996. }
  17997. return fn;
  17998. }
  17999. /**
  18000. * Clear throttle. Example see throttle.createOrUpdate.
  18001. *
  18002. * @public
  18003. * @param {Object} obj
  18004. * @param {string} fnAttr
  18005. */
  18006. function clear(obj, fnAttr) {
  18007. var fn = obj[fnAttr];
  18008. if (fn && fn[ORIGIN_METHOD]) {
  18009. obj[fnAttr] = fn[ORIGIN_METHOD];
  18010. }
  18011. }
  18012. var seriesColor = function (ecModel) {
  18013. function encodeColor(seriesModel) {
  18014. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.normal.color').split('.');
  18015. var data = seriesModel.getData();
  18016. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  18017. || seriesModel.getColorFromPalette(seriesModel.get('name')); // Default color
  18018. // FIXME Set color function or use the platte color
  18019. data.setVisual('color', color);
  18020. // Only visible series has each data be visual encoded
  18021. if (!ecModel.isSeriesFiltered(seriesModel)) {
  18022. if (typeof color === 'function' && !(color instanceof Gradient)) {
  18023. data.each(function (idx) {
  18024. data.setItemVisual(
  18025. idx, 'color', color(seriesModel.getDataParams(idx))
  18026. );
  18027. });
  18028. }
  18029. // itemStyle in each data item
  18030. data.each(function (idx) {
  18031. var itemModel = data.getItemModel(idx);
  18032. var color = itemModel.get(colorAccessPath, true);
  18033. if (color != null) {
  18034. data.setItemVisual(idx, 'color', color);
  18035. }
  18036. });
  18037. }
  18038. }
  18039. ecModel.eachRawSeries(encodeColor);
  18040. };
  18041. var PI$1 = Math.PI;
  18042. /**
  18043. * @param {module:echarts/ExtensionAPI} api
  18044. * @param {Object} [opts]
  18045. * @param {string} [opts.text]
  18046. * @param {string} [opts.color]
  18047. * @param {string} [opts.textColor]
  18048. * @return {module:zrender/Element}
  18049. */
  18050. var loadingDefault = function (api, opts) {
  18051. opts = opts || {};
  18052. defaults(opts, {
  18053. text: 'loading',
  18054. color: '#c23531',
  18055. textColor: '#000',
  18056. maskColor: 'rgba(255, 255, 255, 0.8)',
  18057. zlevel: 0
  18058. });
  18059. var mask = new Rect({
  18060. style: {
  18061. fill: opts.maskColor
  18062. },
  18063. zlevel: opts.zlevel,
  18064. z: 10000
  18065. });
  18066. var arc = new Arc({
  18067. shape: {
  18068. startAngle: -PI$1 / 2,
  18069. endAngle: -PI$1 / 2 + 0.1,
  18070. r: 10
  18071. },
  18072. style: {
  18073. stroke: opts.color,
  18074. lineCap: 'round',
  18075. lineWidth: 5
  18076. },
  18077. zlevel: opts.zlevel,
  18078. z: 10001
  18079. });
  18080. var labelRect = new Rect({
  18081. style: {
  18082. fill: 'none',
  18083. text: opts.text,
  18084. textPosition: 'right',
  18085. textDistance: 10,
  18086. textFill: opts.textColor
  18087. },
  18088. zlevel: opts.zlevel,
  18089. z: 10001
  18090. });
  18091. arc.animateShape(true)
  18092. .when(1000, {
  18093. endAngle: PI$1 * 3 / 2
  18094. })
  18095. .start('circularInOut');
  18096. arc.animateShape(true)
  18097. .when(1000, {
  18098. startAngle: PI$1 * 3 / 2
  18099. })
  18100. .delay(300)
  18101. .start('circularInOut');
  18102. var group = new Group();
  18103. group.add(arc);
  18104. group.add(labelRect);
  18105. group.add(mask);
  18106. // Inject resize
  18107. group.resize = function () {
  18108. var cx = api.getWidth() / 2;
  18109. var cy = api.getHeight() / 2;
  18110. arc.setShape({
  18111. cx: cx,
  18112. cy: cy
  18113. });
  18114. var r = arc.shape.r;
  18115. labelRect.setShape({
  18116. x: cx - r,
  18117. y: cy - r,
  18118. width: r * 2,
  18119. height: r * 2
  18120. });
  18121. mask.setShape({
  18122. x: 0,
  18123. y: 0,
  18124. width: api.getWidth(),
  18125. height: api.getHeight()
  18126. });
  18127. };
  18128. group.resize();
  18129. return group;
  18130. };
  18131. /*!
  18132. * ECharts, a javascript interactive chart library.
  18133. *
  18134. * Copyright (c) 2015, Baidu Inc.
  18135. * All rights reserved.
  18136. *
  18137. * LICENSE
  18138. * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
  18139. */
  18140. var each = each$1;
  18141. var parseClassType = ComponentModel.parseClassType;
  18142. var version = '3.8.5';
  18143. var dependencies = {
  18144. zrender: '3.7.4'
  18145. };
  18146. var PRIORITY_PROCESSOR_FILTER = 1000;
  18147. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  18148. var PRIORITY_VISUAL_LAYOUT = 1000;
  18149. var PRIORITY_VISUAL_GLOBAL = 2000;
  18150. var PRIORITY_VISUAL_CHART = 3000;
  18151. var PRIORITY_VISUAL_COMPONENT = 4000;
  18152. // FIXME
  18153. // necessary?
  18154. var PRIORITY_VISUAL_BRUSH = 5000;
  18155. var PRIORITY = {
  18156. PROCESSOR: {
  18157. FILTER: PRIORITY_PROCESSOR_FILTER,
  18158. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  18159. },
  18160. VISUAL: {
  18161. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  18162. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  18163. CHART: PRIORITY_VISUAL_CHART,
  18164. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  18165. BRUSH: PRIORITY_VISUAL_BRUSH
  18166. }
  18167. };
  18168. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  18169. // where they must not be invoked nestedly, except the only case: invoke
  18170. // dispatchAction with updateMethod "none" in main process.
  18171. // This flag is used to carry out this rule.
  18172. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  18173. var IN_MAIN_PROCESS = '__flagInMainProcess';
  18174. var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
  18175. var OPTION_UPDATED = '__optionUpdated';
  18176. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  18177. function createRegisterEventWithLowercaseName(method) {
  18178. return function (eventName, handler, context) {
  18179. // Event name is all lowercase
  18180. eventName = eventName && eventName.toLowerCase();
  18181. Eventful.prototype[method].call(this, eventName, handler, context);
  18182. };
  18183. }
  18184. /**
  18185. * @module echarts~MessageCenter
  18186. */
  18187. function MessageCenter() {
  18188. Eventful.call(this);
  18189. }
  18190. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  18191. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  18192. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  18193. mixin(MessageCenter, Eventful);
  18194. /**
  18195. * @module echarts~ECharts
  18196. */
  18197. function ECharts(dom, theme, opts) {
  18198. opts = opts || {};
  18199. // Get theme by name
  18200. if (typeof theme === 'string') {
  18201. theme = themeStorage[theme];
  18202. }
  18203. /**
  18204. * @type {string}
  18205. */
  18206. this.id;
  18207. /**
  18208. * Group id
  18209. * @type {string}
  18210. */
  18211. this.group;
  18212. /**
  18213. * @type {HTMLElement}
  18214. * @private
  18215. */
  18216. this._dom = dom;
  18217. var defaultRenderer = 'canvas';
  18218. if (__DEV__) {
  18219. defaultRenderer = (
  18220. typeof window === 'undefined' ? global : window
  18221. ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  18222. }
  18223. /**
  18224. * @type {module:zrender/ZRender}
  18225. * @private
  18226. */
  18227. var zr = this._zr = init$1(dom, {
  18228. renderer: opts.renderer || defaultRenderer,
  18229. devicePixelRatio: opts.devicePixelRatio,
  18230. width: opts.width,
  18231. height: opts.height
  18232. });
  18233. /**
  18234. * Expect 60 pfs.
  18235. * @type {Function}
  18236. * @private
  18237. */
  18238. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  18239. var theme = clone(theme);
  18240. theme && backwardCompat(theme, true);
  18241. /**
  18242. * @type {Object}
  18243. * @private
  18244. */
  18245. this._theme = theme;
  18246. /**
  18247. * @type {Array.<module:echarts/view/Chart>}
  18248. * @private
  18249. */
  18250. this._chartsViews = [];
  18251. /**
  18252. * @type {Object.<string, module:echarts/view/Chart>}
  18253. * @private
  18254. */
  18255. this._chartsMap = {};
  18256. /**
  18257. * @type {Array.<module:echarts/view/Component>}
  18258. * @private
  18259. */
  18260. this._componentsViews = [];
  18261. /**
  18262. * @type {Object.<string, module:echarts/view/Component>}
  18263. * @private
  18264. */
  18265. this._componentsMap = {};
  18266. /**
  18267. * @type {module:echarts/CoordinateSystem}
  18268. * @private
  18269. */
  18270. this._coordSysMgr = new CoordinateSystemManager();
  18271. /**
  18272. * @type {module:echarts/ExtensionAPI}
  18273. * @private
  18274. */
  18275. this._api = createExtensionAPI(this);
  18276. Eventful.call(this);
  18277. /**
  18278. * @type {module:echarts~MessageCenter}
  18279. * @private
  18280. */
  18281. this._messageCenter = new MessageCenter();
  18282. // Init mouse events
  18283. this._initEvents();
  18284. // In case some people write `window.onresize = chart.resize`
  18285. this.resize = bind(this.resize, this);
  18286. // Can't dispatch action during rendering procedure
  18287. this._pendingActions = [];
  18288. // Sort on demand
  18289. function prioritySortFunc(a, b) {
  18290. return a.prio - b.prio;
  18291. }
  18292. sort(visualFuncs, prioritySortFunc);
  18293. sort(dataProcessorFuncs, prioritySortFunc);
  18294. zr.animation.on('frame', this._onframe, this);
  18295. // ECharts instance can be used as value.
  18296. setAsPrimitive(this);
  18297. }
  18298. var echartsProto = ECharts.prototype;
  18299. echartsProto._onframe = function () {
  18300. // Lazy update
  18301. if (this[OPTION_UPDATED]) {
  18302. var silent = this[OPTION_UPDATED].silent;
  18303. this[IN_MAIN_PROCESS] = true;
  18304. updateMethods.prepareAndUpdate.call(this);
  18305. this[IN_MAIN_PROCESS] = false;
  18306. this[OPTION_UPDATED] = false;
  18307. flushPendingActions.call(this, silent);
  18308. triggerUpdatedEvent.call(this, silent);
  18309. }
  18310. };
  18311. /**
  18312. * @return {HTMLElement}
  18313. */
  18314. echartsProto.getDom = function () {
  18315. return this._dom;
  18316. };
  18317. /**
  18318. * @return {module:zrender~ZRender}
  18319. */
  18320. echartsProto.getZr = function () {
  18321. return this._zr;
  18322. };
  18323. /**
  18324. * Usage:
  18325. * chart.setOption(option, notMerge, lazyUpdate);
  18326. * chart.setOption(option, {
  18327. * notMerge: ...,
  18328. * lazyUpdate: ...,
  18329. * silent: ...
  18330. * });
  18331. *
  18332. * @param {Object} option
  18333. * @param {Object|boolean} [opts] opts or notMerge.
  18334. * @param {boolean} [opts.notMerge=false]
  18335. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  18336. */
  18337. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  18338. if (__DEV__) {
  18339. assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  18340. }
  18341. var silent;
  18342. if (isObject(notMerge)) {
  18343. lazyUpdate = notMerge.lazyUpdate;
  18344. silent = notMerge.silent;
  18345. notMerge = notMerge.notMerge;
  18346. }
  18347. this[IN_MAIN_PROCESS] = true;
  18348. if (!this._model || notMerge) {
  18349. var optionManager = new OptionManager(this._api);
  18350. var theme = this._theme;
  18351. var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
  18352. ecModel.init(null, null, theme, optionManager);
  18353. }
  18354. this._model.setOption(option, optionPreprocessorFuncs);
  18355. if (lazyUpdate) {
  18356. this[OPTION_UPDATED] = {silent: silent};
  18357. this[IN_MAIN_PROCESS] = false;
  18358. }
  18359. else {
  18360. updateMethods.prepareAndUpdate.call(this);
  18361. // Ensure zr refresh sychronously, and then pixel in canvas can be
  18362. // fetched after `setOption`.
  18363. this._zr.flush();
  18364. this[OPTION_UPDATED] = false;
  18365. this[IN_MAIN_PROCESS] = false;
  18366. flushPendingActions.call(this, silent);
  18367. triggerUpdatedEvent.call(this, silent);
  18368. }
  18369. };
  18370. /**
  18371. * @DEPRECATED
  18372. */
  18373. echartsProto.setTheme = function () {
  18374. console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  18375. };
  18376. /**
  18377. * @return {module:echarts/model/Global}
  18378. */
  18379. echartsProto.getModel = function () {
  18380. return this._model;
  18381. };
  18382. /**
  18383. * @return {Object}
  18384. */
  18385. echartsProto.getOption = function () {
  18386. return this._model && this._model.getOption();
  18387. };
  18388. /**
  18389. * @return {number}
  18390. */
  18391. echartsProto.getWidth = function () {
  18392. return this._zr.getWidth();
  18393. };
  18394. /**
  18395. * @return {number}
  18396. */
  18397. echartsProto.getHeight = function () {
  18398. return this._zr.getHeight();
  18399. };
  18400. /**
  18401. * @return {number}
  18402. */
  18403. echartsProto.getDevicePixelRatio = function () {
  18404. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  18405. };
  18406. /**
  18407. * Get canvas which has all thing rendered
  18408. * @param {Object} opts
  18409. * @param {string} [opts.backgroundColor]
  18410. * @return {string}
  18411. */
  18412. echartsProto.getRenderedCanvas = function (opts) {
  18413. if (!env$1.canvasSupported) {
  18414. return;
  18415. }
  18416. opts = opts || {};
  18417. opts.pixelRatio = opts.pixelRatio || 1;
  18418. opts.backgroundColor = opts.backgroundColor
  18419. || this._model.get('backgroundColor');
  18420. var zr = this._zr;
  18421. var list = zr.storage.getDisplayList();
  18422. // Stop animations
  18423. each$1(list, function (el) {
  18424. el.stopAnimation(true);
  18425. });
  18426. return zr.painter.getRenderedCanvas(opts);
  18427. };
  18428. /**
  18429. * Get svg data url
  18430. * @return {string}
  18431. */
  18432. echartsProto.getSvgDataUrl = function () {
  18433. if (!env$1.svgSupported) {
  18434. return;
  18435. }
  18436. var zr = this._zr;
  18437. var list = zr.storage.getDisplayList();
  18438. // Stop animations
  18439. each$1(list, function (el) {
  18440. el.stopAnimation(true);
  18441. });
  18442. return zr.painter.pathToSvg();
  18443. };
  18444. /**
  18445. * @return {string}
  18446. * @param {Object} opts
  18447. * @param {string} [opts.type='png']
  18448. * @param {string} [opts.pixelRatio=1]
  18449. * @param {string} [opts.backgroundColor]
  18450. * @param {string} [opts.excludeComponents]
  18451. */
  18452. echartsProto.getDataURL = function (opts) {
  18453. opts = opts || {};
  18454. var excludeComponents = opts.excludeComponents;
  18455. var ecModel = this._model;
  18456. var excludesComponentViews = [];
  18457. var self = this;
  18458. each(excludeComponents, function (componentType) {
  18459. ecModel.eachComponent({
  18460. mainType: componentType
  18461. }, function (component) {
  18462. var view = self._componentsMap[component.__viewId];
  18463. if (!view.group.ignore) {
  18464. excludesComponentViews.push(view);
  18465. view.group.ignore = true;
  18466. }
  18467. });
  18468. });
  18469. var url = this._zr.painter.getType() === 'svg'
  18470. ? this.getSvgDataUrl()
  18471. : this.getRenderedCanvas(opts).toDataURL(
  18472. 'image/' + (opts && opts.type || 'png')
  18473. );
  18474. each(excludesComponentViews, function (view) {
  18475. view.group.ignore = false;
  18476. });
  18477. return url;
  18478. };
  18479. /**
  18480. * @return {string}
  18481. * @param {Object} opts
  18482. * @param {string} [opts.type='png']
  18483. * @param {string} [opts.pixelRatio=1]
  18484. * @param {string} [opts.backgroundColor]
  18485. */
  18486. echartsProto.getConnectedDataURL = function (opts) {
  18487. if (!env$1.canvasSupported) {
  18488. return;
  18489. }
  18490. var groupId = this.group;
  18491. var mathMin = Math.min;
  18492. var mathMax = Math.max;
  18493. var MAX_NUMBER = Infinity;
  18494. if (connectedGroups[groupId]) {
  18495. var left = MAX_NUMBER;
  18496. var top = MAX_NUMBER;
  18497. var right = -MAX_NUMBER;
  18498. var bottom = -MAX_NUMBER;
  18499. var canvasList = [];
  18500. var dpr = (opts && opts.pixelRatio) || 1;
  18501. each$1(instances, function (chart, id) {
  18502. if (chart.group === groupId) {
  18503. var canvas = chart.getRenderedCanvas(
  18504. clone(opts)
  18505. );
  18506. var boundingRect = chart.getDom().getBoundingClientRect();
  18507. left = mathMin(boundingRect.left, left);
  18508. top = mathMin(boundingRect.top, top);
  18509. right = mathMax(boundingRect.right, right);
  18510. bottom = mathMax(boundingRect.bottom, bottom);
  18511. canvasList.push({
  18512. dom: canvas,
  18513. left: boundingRect.left,
  18514. top: boundingRect.top
  18515. });
  18516. }
  18517. });
  18518. left *= dpr;
  18519. top *= dpr;
  18520. right *= dpr;
  18521. bottom *= dpr;
  18522. var width = right - left;
  18523. var height = bottom - top;
  18524. var targetCanvas = createCanvas();
  18525. targetCanvas.width = width;
  18526. targetCanvas.height = height;
  18527. var zr = init$1(targetCanvas);
  18528. each(canvasList, function (item) {
  18529. var img = new ZImage({
  18530. style: {
  18531. x: item.left * dpr - left,
  18532. y: item.top * dpr - top,
  18533. image: item.dom
  18534. }
  18535. });
  18536. zr.add(img);
  18537. });
  18538. zr.refreshImmediately();
  18539. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  18540. }
  18541. else {
  18542. return this.getDataURL(opts);
  18543. }
  18544. };
  18545. /**
  18546. * Convert from logical coordinate system to pixel coordinate system.
  18547. * See CoordinateSystem#convertToPixel.
  18548. * @param {string|Object} finder
  18549. * If string, e.g., 'geo', means {geoIndex: 0}.
  18550. * If Object, could contain some of these properties below:
  18551. * {
  18552. * seriesIndex / seriesId / seriesName,
  18553. * geoIndex / geoId, geoName,
  18554. * bmapIndex / bmapId / bmapName,
  18555. * xAxisIndex / xAxisId / xAxisName,
  18556. * yAxisIndex / yAxisId / yAxisName,
  18557. * gridIndex / gridId / gridName,
  18558. * ... (can be extended)
  18559. * }
  18560. * @param {Array|number} value
  18561. * @return {Array|number} result
  18562. */
  18563. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  18564. /**
  18565. * Convert from pixel coordinate system to logical coordinate system.
  18566. * See CoordinateSystem#convertFromPixel.
  18567. * @param {string|Object} finder
  18568. * If string, e.g., 'geo', means {geoIndex: 0}.
  18569. * If Object, could contain some of these properties below:
  18570. * {
  18571. * seriesIndex / seriesId / seriesName,
  18572. * geoIndex / geoId / geoName,
  18573. * bmapIndex / bmapId / bmapName,
  18574. * xAxisIndex / xAxisId / xAxisName,
  18575. * yAxisIndex / yAxisId / yAxisName
  18576. * gridIndex / gridId / gridName,
  18577. * ... (can be extended)
  18578. * }
  18579. * @param {Array|number} value
  18580. * @return {Array|number} result
  18581. */
  18582. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  18583. function doConvertPixel(methodName, finder, value) {
  18584. var ecModel = this._model;
  18585. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  18586. var result;
  18587. finder = parseFinder(ecModel, finder);
  18588. for (var i = 0; i < coordSysList.length; i++) {
  18589. var coordSys = coordSysList[i];
  18590. if (coordSys[methodName]
  18591. && (result = coordSys[methodName](ecModel, finder, value)) != null
  18592. ) {
  18593. return result;
  18594. }
  18595. }
  18596. if (__DEV__) {
  18597. console.warn(
  18598. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  18599. );
  18600. }
  18601. }
  18602. /**
  18603. * Is the specified coordinate systems or components contain the given pixel point.
  18604. * @param {string|Object} finder
  18605. * If string, e.g., 'geo', means {geoIndex: 0}.
  18606. * If Object, could contain some of these properties below:
  18607. * {
  18608. * seriesIndex / seriesId / seriesName,
  18609. * geoIndex / geoId / geoName,
  18610. * bmapIndex / bmapId / bmapName,
  18611. * xAxisIndex / xAxisId / xAxisName,
  18612. * yAxisIndex / yAxisId / yAxisName,
  18613. * gridIndex / gridId / gridName,
  18614. * ... (can be extended)
  18615. * }
  18616. * @param {Array|number} value
  18617. * @return {boolean} result
  18618. */
  18619. echartsProto.containPixel = function (finder, value) {
  18620. var ecModel = this._model;
  18621. var result;
  18622. finder = parseFinder(ecModel, finder);
  18623. each$1(finder, function (models, key) {
  18624. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  18625. var coordSys = model.coordinateSystem;
  18626. if (coordSys && coordSys.containPoint) {
  18627. result |= !!coordSys.containPoint(value);
  18628. }
  18629. else if (key === 'seriesModels') {
  18630. var view = this._chartsMap[model.__viewId];
  18631. if (view && view.containPoint) {
  18632. result |= view.containPoint(value, model);
  18633. }
  18634. else {
  18635. if (__DEV__) {
  18636. console.warn(key + ': ' + (view
  18637. ? 'The found component do not support containPoint.'
  18638. : 'No view mapping to the found component.'
  18639. ));
  18640. }
  18641. }
  18642. }
  18643. else {
  18644. if (__DEV__) {
  18645. console.warn(key + ': containPoint is not supported');
  18646. }
  18647. }
  18648. }, this);
  18649. }, this);
  18650. return !!result;
  18651. };
  18652. /**
  18653. * Get visual from series or data.
  18654. * @param {string|Object} finder
  18655. * If string, e.g., 'series', means {seriesIndex: 0}.
  18656. * If Object, could contain some of these properties below:
  18657. * {
  18658. * seriesIndex / seriesId / seriesName,
  18659. * dataIndex / dataIndexInside
  18660. * }
  18661. * If dataIndex is not specified, series visual will be fetched,
  18662. * but not data item visual.
  18663. * If all of seriesIndex, seriesId, seriesName are not specified,
  18664. * visual will be fetched from first series.
  18665. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  18666. */
  18667. echartsProto.getVisual = function (finder, visualType) {
  18668. var ecModel = this._model;
  18669. finder = parseFinder(ecModel, finder, {defaultMainType: 'series'});
  18670. var seriesModel = finder.seriesModel;
  18671. if (__DEV__) {
  18672. if (!seriesModel) {
  18673. console.warn('There is no specified seires model');
  18674. }
  18675. }
  18676. var data = seriesModel.getData();
  18677. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  18678. ? finder.dataIndexInside
  18679. : finder.hasOwnProperty('dataIndex')
  18680. ? data.indexOfRawIndex(finder.dataIndex)
  18681. : null;
  18682. return dataIndexInside != null
  18683. ? data.getItemVisual(dataIndexInside, visualType)
  18684. : data.getVisual(visualType);
  18685. };
  18686. /**
  18687. * Get view of corresponding component model
  18688. * @param {module:echarts/model/Component} componentModel
  18689. * @return {module:echarts/view/Component}
  18690. */
  18691. echartsProto.getViewOfComponentModel = function (componentModel) {
  18692. return this._componentsMap[componentModel.__viewId];
  18693. };
  18694. /**
  18695. * Get view of corresponding series model
  18696. * @param {module:echarts/model/Series} seriesModel
  18697. * @return {module:echarts/view/Chart}
  18698. */
  18699. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  18700. return this._chartsMap[seriesModel.__viewId];
  18701. };
  18702. var updateMethods = {
  18703. /**
  18704. * @param {Object} payload
  18705. * @private
  18706. */
  18707. update: function (payload) {
  18708. // console.profile && console.profile('update');
  18709. var ecModel = this._model;
  18710. var api = this._api;
  18711. var coordSysMgr = this._coordSysMgr;
  18712. var zr = this._zr;
  18713. // update before setOption
  18714. if (!ecModel) {
  18715. return;
  18716. }
  18717. // Fixme First time update ?
  18718. ecModel.restoreData();
  18719. // TODO
  18720. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  18721. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  18722. // Create new coordinate system each update
  18723. // In LineView may save the old coordinate system and use it to get the orignal point
  18724. coordSysMgr.create(this._model, this._api);
  18725. processData.call(this, ecModel, api);
  18726. stackSeriesData.call(this, ecModel);
  18727. coordSysMgr.update(ecModel, api);
  18728. doVisualEncoding.call(this, ecModel, payload);
  18729. doRender.call(this, ecModel, payload);
  18730. // Set background
  18731. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  18732. var painter = zr.painter;
  18733. // TODO all use clearColor ?
  18734. if (painter.isSingleCanvas && painter.isSingleCanvas()) {
  18735. zr.configLayer(0, {
  18736. clearColor: backgroundColor
  18737. });
  18738. }
  18739. else {
  18740. // In IE8
  18741. if (!env$1.canvasSupported) {
  18742. var colorArr = parse(backgroundColor);
  18743. backgroundColor = stringify(colorArr, 'rgb');
  18744. if (colorArr[3] === 0) {
  18745. backgroundColor = 'transparent';
  18746. }
  18747. }
  18748. if (backgroundColor.colorStops || backgroundColor.image) {
  18749. // Gradient background
  18750. // FIXME Fixed layer?
  18751. zr.configLayer(0, {
  18752. clearColor: backgroundColor
  18753. });
  18754. this[HAS_GRADIENT_OR_PATTERN_BG] = true;
  18755. this._dom.style.background = 'transparent';
  18756. }
  18757. else {
  18758. if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
  18759. zr.configLayer(0, {
  18760. clearColor: null
  18761. });
  18762. }
  18763. this[HAS_GRADIENT_OR_PATTERN_BG] = false;
  18764. this._dom.style.background = backgroundColor;
  18765. }
  18766. }
  18767. each(postUpdateFuncs, function (func) {
  18768. func(ecModel, api);
  18769. });
  18770. // console.profile && console.profileEnd('update');
  18771. },
  18772. /**
  18773. * @param {Object} payload
  18774. * @private
  18775. */
  18776. updateView: function (payload) {
  18777. var ecModel = this._model;
  18778. // update before setOption
  18779. if (!ecModel) {
  18780. return;
  18781. }
  18782. ecModel.eachSeries(function (seriesModel) {
  18783. seriesModel.getData().clearAllVisual();
  18784. });
  18785. doVisualEncoding.call(this, ecModel, payload);
  18786. invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
  18787. },
  18788. /**
  18789. * @param {Object} payload
  18790. * @private
  18791. */
  18792. updateVisual: function (payload) {
  18793. var ecModel = this._model;
  18794. // update before setOption
  18795. if (!ecModel) {
  18796. return;
  18797. }
  18798. ecModel.eachSeries(function (seriesModel) {
  18799. seriesModel.getData().clearAllVisual();
  18800. });
  18801. doVisualEncoding.call(this, ecModel, payload, true);
  18802. invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
  18803. },
  18804. /**
  18805. * @param {Object} payload
  18806. * @private
  18807. */
  18808. updateLayout: function (payload) {
  18809. var ecModel = this._model;
  18810. // update before setOption
  18811. if (!ecModel) {
  18812. return;
  18813. }
  18814. doLayout.call(this, ecModel, payload);
  18815. invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
  18816. },
  18817. /**
  18818. * @param {Object} payload
  18819. * @private
  18820. */
  18821. prepareAndUpdate: function (payload) {
  18822. var ecModel = this._model;
  18823. prepareView.call(this, 'component', ecModel);
  18824. prepareView.call(this, 'chart', ecModel);
  18825. updateMethods.update.call(this, payload);
  18826. }
  18827. };
  18828. /**
  18829. * @private
  18830. */
  18831. function updateDirectly(ecIns, method, payload, mainType, subType) {
  18832. var ecModel = ecIns._model;
  18833. // broadcast
  18834. if (!mainType) {
  18835. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  18836. return;
  18837. }
  18838. var query = {};
  18839. query[mainType + 'Id'] = payload[mainType + 'Id'];
  18840. query[mainType + 'Index'] = payload[mainType + 'Index'];
  18841. query[mainType + 'Name'] = payload[mainType + 'Name'];
  18842. var condition = {mainType: mainType, query: query};
  18843. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  18844. // If dispatchAction before setOption, do nothing.
  18845. ecModel && ecModel.eachComponent(condition, function (model, index) {
  18846. callView(ecIns[
  18847. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  18848. ][model.__viewId]);
  18849. }, ecIns);
  18850. function callView(view) {
  18851. view && view.__alive && view[method] && view[method](
  18852. view.__model, ecModel, ecIns._api, payload
  18853. );
  18854. }
  18855. }
  18856. /**
  18857. * Resize the chart
  18858. * @param {Object} opts
  18859. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  18860. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  18861. * @param {boolean} [opts.silent=false]
  18862. */
  18863. echartsProto.resize = function (opts) {
  18864. if (__DEV__) {
  18865. assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  18866. }
  18867. this[IN_MAIN_PROCESS] = true;
  18868. this._zr.resize(opts);
  18869. var optionChanged = this._model && this._model.resetOption('media');
  18870. var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
  18871. updateMethods[updateMethod].call(this);
  18872. // Resize loading effect
  18873. this._loadingFX && this._loadingFX.resize();
  18874. this[IN_MAIN_PROCESS] = false;
  18875. var silent = opts && opts.silent;
  18876. flushPendingActions.call(this, silent);
  18877. triggerUpdatedEvent.call(this, silent);
  18878. };
  18879. /**
  18880. * Show loading effect
  18881. * @param {string} [name='default']
  18882. * @param {Object} [cfg]
  18883. */
  18884. echartsProto.showLoading = function (name, cfg) {
  18885. if (isObject(name)) {
  18886. cfg = name;
  18887. name = '';
  18888. }
  18889. name = name || 'default';
  18890. this.hideLoading();
  18891. if (!loadingEffects[name]) {
  18892. if (__DEV__) {
  18893. console.warn('Loading effects ' + name + ' not exists.');
  18894. }
  18895. return;
  18896. }
  18897. var el = loadingEffects[name](this._api, cfg);
  18898. var zr = this._zr;
  18899. this._loadingFX = el;
  18900. zr.add(el);
  18901. };
  18902. /**
  18903. * Hide loading effect
  18904. */
  18905. echartsProto.hideLoading = function () {
  18906. this._loadingFX && this._zr.remove(this._loadingFX);
  18907. this._loadingFX = null;
  18908. };
  18909. /**
  18910. * @param {Object} eventObj
  18911. * @return {Object}
  18912. */
  18913. echartsProto.makeActionFromEvent = function (eventObj) {
  18914. var payload = extend({}, eventObj);
  18915. payload.type = eventActionMap[eventObj.type];
  18916. return payload;
  18917. };
  18918. /**
  18919. * @pubilc
  18920. * @param {Object} payload
  18921. * @param {string} [payload.type] Action type
  18922. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  18923. * @param {boolean} [opt.silent=false] Whether trigger events.
  18924. * @param {boolean} [opt.flush=undefined]
  18925. * true: Flush immediately, and then pixel in canvas can be fetched
  18926. * immediately. Caution: it might affect performance.
  18927. * false: Not not flush.
  18928. * undefined: Auto decide whether perform flush.
  18929. */
  18930. echartsProto.dispatchAction = function (payload, opt) {
  18931. if (!isObject(opt)) {
  18932. opt = {silent: !!opt};
  18933. }
  18934. if (!actions[payload.type]) {
  18935. return;
  18936. }
  18937. // Avoid dispatch action before setOption. Especially in `connect`.
  18938. if (!this._model) {
  18939. return;
  18940. }
  18941. // May dispatchAction in rendering procedure
  18942. if (this[IN_MAIN_PROCESS]) {
  18943. this._pendingActions.push(payload);
  18944. return;
  18945. }
  18946. doDispatchAction.call(this, payload, opt.silent);
  18947. if (opt.flush) {
  18948. this._zr.flush(true);
  18949. }
  18950. else if (opt.flush !== false && env$1.browser.weChat) {
  18951. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  18952. // hang when sliding page (on touch event), which cause that zr does not
  18953. // refresh util user interaction finished, which is not expected.
  18954. // But `dispatchAction` may be called too frequently when pan on touch
  18955. // screen, which impacts performance if do not throttle them.
  18956. this._throttledZrFlush();
  18957. }
  18958. flushPendingActions.call(this, opt.silent);
  18959. triggerUpdatedEvent.call(this, opt.silent);
  18960. };
  18961. function doDispatchAction(payload, silent) {
  18962. var payloadType = payload.type;
  18963. var escapeConnect = payload.escapeConnect;
  18964. var actionWrap = actions[payloadType];
  18965. var actionInfo = actionWrap.actionInfo;
  18966. var cptType = (actionInfo.update || 'update').split(':');
  18967. var updateMethod = cptType.pop();
  18968. cptType = cptType[0] != null && parseClassType(cptType[0]);
  18969. this[IN_MAIN_PROCESS] = true;
  18970. var payloads = [payload];
  18971. var batched = false;
  18972. // Batch action
  18973. if (payload.batch) {
  18974. batched = true;
  18975. payloads = map(payload.batch, function (item) {
  18976. item = defaults(extend({}, item), payload);
  18977. item.batch = null;
  18978. return item;
  18979. });
  18980. }
  18981. var eventObjBatch = [];
  18982. var eventObj;
  18983. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  18984. each(payloads, function (batchItem) {
  18985. // Action can specify the event by return it.
  18986. eventObj = actionWrap.action(batchItem, this._model, this._api);
  18987. // Emit event outside
  18988. eventObj = eventObj || extend({}, batchItem);
  18989. // Convert type to eventType
  18990. eventObj.type = actionInfo.event || eventObj.type;
  18991. eventObjBatch.push(eventObj);
  18992. // light update does not perform data process, layout and visual.
  18993. if (isHighDown) {
  18994. // method, payload, mainType, subType
  18995. updateDirectly(this, updateMethod, batchItem, 'series');
  18996. }
  18997. else if (cptType) {
  18998. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  18999. }
  19000. }, this);
  19001. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  19002. // Still dirty
  19003. if (this[OPTION_UPDATED]) {
  19004. // FIXME Pass payload ?
  19005. updateMethods.prepareAndUpdate.call(this, payload);
  19006. this[OPTION_UPDATED] = false;
  19007. }
  19008. else {
  19009. updateMethods[updateMethod].call(this, payload);
  19010. }
  19011. }
  19012. // Follow the rule of action batch
  19013. if (batched) {
  19014. eventObj = {
  19015. type: actionInfo.event || payloadType,
  19016. escapeConnect: escapeConnect,
  19017. batch: eventObjBatch
  19018. };
  19019. }
  19020. else {
  19021. eventObj = eventObjBatch[0];
  19022. }
  19023. this[IN_MAIN_PROCESS] = false;
  19024. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  19025. }
  19026. function flushPendingActions(silent) {
  19027. var pendingActions = this._pendingActions;
  19028. while (pendingActions.length) {
  19029. var payload = pendingActions.shift();
  19030. doDispatchAction.call(this, payload, silent);
  19031. }
  19032. }
  19033. function triggerUpdatedEvent(silent) {
  19034. !silent && this.trigger('updated');
  19035. }
  19036. /**
  19037. * Register event
  19038. * @method
  19039. */
  19040. echartsProto.on = createRegisterEventWithLowercaseName('on');
  19041. echartsProto.off = createRegisterEventWithLowercaseName('off');
  19042. echartsProto.one = createRegisterEventWithLowercaseName('one');
  19043. /**
  19044. * @param {string} methodName
  19045. * @private
  19046. */
  19047. function invokeUpdateMethod(methodName, ecModel, payload) {
  19048. var api = this._api;
  19049. // Update all components
  19050. each(this._componentsViews, function (component) {
  19051. var componentModel = component.__model;
  19052. component[methodName](componentModel, ecModel, api, payload);
  19053. updateZ(componentModel, component);
  19054. }, this);
  19055. // Upate all charts
  19056. ecModel.eachSeries(function (seriesModel, idx) {
  19057. var chart = this._chartsMap[seriesModel.__viewId];
  19058. chart[methodName](seriesModel, ecModel, api, payload);
  19059. updateZ(seriesModel, chart);
  19060. updateProgressiveAndBlend(seriesModel, chart);
  19061. }, this);
  19062. // If use hover layer
  19063. updateHoverLayerStatus(this._zr, ecModel);
  19064. // Post render
  19065. each(postUpdateFuncs, function (func) {
  19066. func(ecModel, api);
  19067. });
  19068. }
  19069. /**
  19070. * Prepare view instances of charts and components
  19071. * @param {module:echarts/model/Global} ecModel
  19072. * @private
  19073. */
  19074. function prepareView(type, ecModel) {
  19075. var isComponent = type === 'component';
  19076. var viewList = isComponent ? this._componentsViews : this._chartsViews;
  19077. var viewMap = isComponent ? this._componentsMap : this._chartsMap;
  19078. var zr = this._zr;
  19079. for (var i = 0; i < viewList.length; i++) {
  19080. viewList[i].__alive = false;
  19081. }
  19082. ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
  19083. if (isComponent) {
  19084. if (componentType === 'series') {
  19085. return;
  19086. }
  19087. }
  19088. else {
  19089. model = componentType;
  19090. }
  19091. // Consider: id same and type changed.
  19092. var viewId = '_ec_' + model.id + '_' + model.type;
  19093. var view = viewMap[viewId];
  19094. if (!view) {
  19095. var classType = parseClassType(model.type);
  19096. var Clazz = isComponent
  19097. ? Component$1.getClass(classType.main, classType.sub)
  19098. : Chart.getClass(classType.sub);
  19099. if (Clazz) {
  19100. view = new Clazz();
  19101. view.init(ecModel, this._api);
  19102. viewMap[viewId] = view;
  19103. viewList.push(view);
  19104. zr.add(view.group);
  19105. }
  19106. else {
  19107. // Error
  19108. return;
  19109. }
  19110. }
  19111. model.__viewId = view.__id = viewId;
  19112. view.__alive = true;
  19113. view.__model = model;
  19114. view.group.__ecComponentInfo = {
  19115. mainType: model.mainType,
  19116. index: model.componentIndex
  19117. };
  19118. }, this);
  19119. for (var i = 0; i < viewList.length;) {
  19120. var view = viewList[i];
  19121. if (!view.__alive) {
  19122. zr.remove(view.group);
  19123. view.dispose(ecModel, this._api);
  19124. viewList.splice(i, 1);
  19125. delete viewMap[view.__id];
  19126. view.__id = view.group.__ecComponentInfo = null;
  19127. }
  19128. else {
  19129. i++;
  19130. }
  19131. }
  19132. }
  19133. /**
  19134. * Processor data in each series
  19135. *
  19136. * @param {module:echarts/model/Global} ecModel
  19137. * @private
  19138. */
  19139. function processData(ecModel, api) {
  19140. each(dataProcessorFuncs, function (process) {
  19141. process.func(ecModel, api);
  19142. });
  19143. }
  19144. /**
  19145. * @private
  19146. */
  19147. function stackSeriesData(ecModel) {
  19148. var stackedDataMap = {};
  19149. ecModel.eachSeries(function (series) {
  19150. var stack = series.get('stack');
  19151. var data = series.getData();
  19152. if (stack && data.type === 'list') {
  19153. var previousStack = stackedDataMap[stack];
  19154. // Avoid conflict with Object.prototype
  19155. if (stackedDataMap.hasOwnProperty(stack) && previousStack) {
  19156. data.stackedOn = previousStack;
  19157. }
  19158. stackedDataMap[stack] = data;
  19159. }
  19160. });
  19161. }
  19162. /**
  19163. * Layout before each chart render there series, special visual encoding stage
  19164. *
  19165. * @param {module:echarts/model/Global} ecModel
  19166. * @private
  19167. */
  19168. function doLayout(ecModel, payload) {
  19169. var api = this._api;
  19170. each(visualFuncs, function (visual) {
  19171. if (visual.isLayout) {
  19172. visual.func(ecModel, api, payload);
  19173. }
  19174. });
  19175. }
  19176. /**
  19177. * Encode visual infomation from data after data processing
  19178. *
  19179. * @param {module:echarts/model/Global} ecModel
  19180. * @param {object} layout
  19181. * @param {boolean} [excludesLayout]
  19182. * @private
  19183. */
  19184. function doVisualEncoding(ecModel, payload, excludesLayout) {
  19185. var api = this._api;
  19186. ecModel.clearColorPalette();
  19187. ecModel.eachSeries(function (seriesModel) {
  19188. seriesModel.clearColorPalette();
  19189. });
  19190. each(visualFuncs, function (visual) {
  19191. (!excludesLayout || !visual.isLayout)
  19192. && visual.func(ecModel, api, payload);
  19193. });
  19194. }
  19195. /**
  19196. * Render each chart and component
  19197. * @private
  19198. */
  19199. function doRender(ecModel, payload) {
  19200. var api = this._api;
  19201. // Render all components
  19202. each(this._componentsViews, function (componentView) {
  19203. var componentModel = componentView.__model;
  19204. componentView.render(componentModel, ecModel, api, payload);
  19205. updateZ(componentModel, componentView);
  19206. }, this);
  19207. each(this._chartsViews, function (chart) {
  19208. chart.__alive = false;
  19209. }, this);
  19210. // Render all charts
  19211. ecModel.eachSeries(function (seriesModel, idx) {
  19212. var chartView = this._chartsMap[seriesModel.__viewId];
  19213. chartView.__alive = true;
  19214. chartView.render(seriesModel, ecModel, api, payload);
  19215. chartView.group.silent = !!seriesModel.get('silent');
  19216. updateZ(seriesModel, chartView);
  19217. updateProgressiveAndBlend(seriesModel, chartView);
  19218. }, this);
  19219. // If use hover layer
  19220. updateHoverLayerStatus(this._zr, ecModel);
  19221. // Remove groups of unrendered charts
  19222. each(this._chartsViews, function (chart) {
  19223. if (!chart.__alive) {
  19224. chart.remove(ecModel, api);
  19225. }
  19226. }, this);
  19227. }
  19228. var MOUSE_EVENT_NAMES = [
  19229. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  19230. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  19231. ];
  19232. /**
  19233. * @private
  19234. */
  19235. echartsProto._initEvents = function () {
  19236. each(MOUSE_EVENT_NAMES, function (eveName) {
  19237. this._zr.on(eveName, function (e) {
  19238. var ecModel = this.getModel();
  19239. var el = e.target;
  19240. var params;
  19241. // no e.target when 'globalout'.
  19242. if (eveName === 'globalout') {
  19243. params = {};
  19244. }
  19245. else if (el && el.dataIndex != null) {
  19246. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  19247. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
  19248. }
  19249. // If element has custom eventData of components
  19250. else if (el && el.eventData) {
  19251. params = extend({}, el.eventData);
  19252. }
  19253. if (params) {
  19254. params.event = e;
  19255. params.type = eveName;
  19256. this.trigger(eveName, params);
  19257. }
  19258. }, this);
  19259. }, this);
  19260. each(eventActionMap, function (actionType, eventType) {
  19261. this._messageCenter.on(eventType, function (event) {
  19262. this.trigger(eventType, event);
  19263. }, this);
  19264. }, this);
  19265. };
  19266. /**
  19267. * @return {boolean}
  19268. */
  19269. echartsProto.isDisposed = function () {
  19270. return this._disposed;
  19271. };
  19272. /**
  19273. * Clear
  19274. */
  19275. echartsProto.clear = function () {
  19276. this.setOption({ series: [] }, true);
  19277. };
  19278. /**
  19279. * Dispose instance
  19280. */
  19281. echartsProto.dispose = function () {
  19282. if (this._disposed) {
  19283. if (__DEV__) {
  19284. console.warn('Instance ' + this.id + ' has been disposed');
  19285. }
  19286. return;
  19287. }
  19288. this._disposed = true;
  19289. var api = this._api;
  19290. var ecModel = this._model;
  19291. each(this._componentsViews, function (component) {
  19292. component.dispose(ecModel, api);
  19293. });
  19294. each(this._chartsViews, function (chart) {
  19295. chart.dispose(ecModel, api);
  19296. });
  19297. // Dispose after all views disposed
  19298. this._zr.dispose();
  19299. delete instances[this.id];
  19300. };
  19301. mixin(ECharts, Eventful);
  19302. function updateHoverLayerStatus(zr, ecModel) {
  19303. var storage = zr.storage;
  19304. var elCount = 0;
  19305. storage.traverse(function (el) {
  19306. if (!el.isGroup) {
  19307. elCount++;
  19308. }
  19309. });
  19310. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  19311. storage.traverse(function (el) {
  19312. if (!el.isGroup) {
  19313. el.useHoverLayer = true;
  19314. }
  19315. });
  19316. }
  19317. }
  19318. /**
  19319. * Update chart progressive and blend.
  19320. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  19321. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  19322. */
  19323. function updateProgressiveAndBlend(seriesModel, chartView) {
  19324. // Progressive configuration
  19325. var elCount = 0;
  19326. chartView.group.traverse(function (el) {
  19327. if (el.type !== 'group' && !el.ignore) {
  19328. elCount++;
  19329. }
  19330. });
  19331. var frameDrawNum = +seriesModel.get('progressive');
  19332. var needProgressive = elCount > seriesModel.get('progressiveThreshold') && frameDrawNum && !env$1.node;
  19333. if (needProgressive) {
  19334. chartView.group.traverse(function (el) {
  19335. // FIXME marker and other components
  19336. if (!el.isGroup) {
  19337. el.progressive = needProgressive ?
  19338. Math.floor(elCount++ / frameDrawNum) : -1;
  19339. if (needProgressive) {
  19340. el.stopAnimation(true);
  19341. }
  19342. }
  19343. });
  19344. }
  19345. // Blend configration
  19346. var blendMode = seriesModel.get('blendMode') || null;
  19347. if (__DEV__) {
  19348. if (!env$1.canvasSupported && blendMode && blendMode !== 'source-over') {
  19349. console.warn('Only canvas support blendMode');
  19350. }
  19351. }
  19352. chartView.group.traverse(function (el) {
  19353. // FIXME marker and other components
  19354. if (!el.isGroup) {
  19355. el.setStyle('blend', blendMode);
  19356. }
  19357. });
  19358. }
  19359. /**
  19360. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  19361. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  19362. */
  19363. function updateZ(model, view) {
  19364. var z = model.get('z');
  19365. var zlevel = model.get('zlevel');
  19366. // Set z and zlevel
  19367. view.group.traverse(function (el) {
  19368. if (el.type !== 'group') {
  19369. z != null && (el.z = z);
  19370. zlevel != null && (el.zlevel = zlevel);
  19371. }
  19372. });
  19373. }
  19374. function createExtensionAPI(ecInstance) {
  19375. var coordSysMgr = ecInstance._coordSysMgr;
  19376. return extend(new ExtensionAPI(ecInstance), {
  19377. // Inject methods
  19378. getCoordinateSystems: bind(
  19379. coordSysMgr.getCoordinateSystems, coordSysMgr
  19380. ),
  19381. getComponentByElement: function (el) {
  19382. while (el) {
  19383. var modelInfo = el.__ecComponentInfo;
  19384. if (modelInfo != null) {
  19385. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  19386. }
  19387. el = el.parent;
  19388. }
  19389. }
  19390. });
  19391. }
  19392. /**
  19393. * @type {Object} key: actionType.
  19394. * @inner
  19395. */
  19396. var actions = {};
  19397. /**
  19398. * Map eventType to actionType
  19399. * @type {Object}
  19400. */
  19401. var eventActionMap = {};
  19402. /**
  19403. * Data processor functions of each stage
  19404. * @type {Array.<Object.<string, Function>>}
  19405. * @inner
  19406. */
  19407. var dataProcessorFuncs = [];
  19408. /**
  19409. * @type {Array.<Function>}
  19410. * @inner
  19411. */
  19412. var optionPreprocessorFuncs = [];
  19413. /**
  19414. * @type {Array.<Function>}
  19415. * @inner
  19416. */
  19417. var postUpdateFuncs = [];
  19418. /**
  19419. * Visual encoding functions of each stage
  19420. * @type {Array.<Object.<string, Function>>}
  19421. * @inner
  19422. */
  19423. var visualFuncs = [];
  19424. /**
  19425. * Theme storage
  19426. * @type {Object.<key, Object>}
  19427. */
  19428. var themeStorage = {};
  19429. /**
  19430. * Loading effects
  19431. */
  19432. var loadingEffects = {};
  19433. var instances = {};
  19434. var connectedGroups = {};
  19435. var idBase = new Date() - 0;
  19436. var groupIdBase = new Date() - 0;
  19437. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  19438. var mapDataStores = {};
  19439. function enableConnect(chart) {
  19440. var STATUS_PENDING = 0;
  19441. var STATUS_UPDATING = 1;
  19442. var STATUS_UPDATED = 2;
  19443. var STATUS_KEY = '__connectUpdateStatus';
  19444. function updateConnectedChartsStatus(charts, status) {
  19445. for (var i = 0; i < charts.length; i++) {
  19446. var otherChart = charts[i];
  19447. otherChart[STATUS_KEY] = status;
  19448. }
  19449. }
  19450. each$1(eventActionMap, function (actionType, eventType) {
  19451. chart._messageCenter.on(eventType, function (event) {
  19452. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  19453. if (event && event.escapeConnect) {
  19454. return;
  19455. }
  19456. var action = chart.makeActionFromEvent(event);
  19457. var otherCharts = [];
  19458. each$1(instances, function (otherChart) {
  19459. if (otherChart !== chart && otherChart.group === chart.group) {
  19460. otherCharts.push(otherChart);
  19461. }
  19462. });
  19463. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  19464. each(otherCharts, function (otherChart) {
  19465. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  19466. otherChart.dispatchAction(action);
  19467. }
  19468. });
  19469. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  19470. }
  19471. });
  19472. });
  19473. }
  19474. /**
  19475. * @param {HTMLElement} dom
  19476. * @param {Object} [theme]
  19477. * @param {Object} opts
  19478. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  19479. * @param {string} [opts.renderer] Currently only 'canvas' is supported.
  19480. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  19481. * Can be 'auto' (the same as null/undefined)
  19482. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  19483. * Can be 'auto' (the same as null/undefined)
  19484. */
  19485. function init(dom, theme, opts) {
  19486. if (__DEV__) {
  19487. // Check version
  19488. if ((version$1.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {
  19489. throw new Error(
  19490. 'zrender/src ' + version$1
  19491. + ' is too old for ECharts ' + version
  19492. + '. Current version need ZRender '
  19493. + dependencies.zrender + '+'
  19494. );
  19495. }
  19496. if (!dom) {
  19497. throw new Error('Initialize failed: invalid dom.');
  19498. }
  19499. }
  19500. var existInstance = getInstanceByDom(dom);
  19501. if (existInstance) {
  19502. if (__DEV__) {
  19503. console.warn('There is a chart instance already initialized on the dom.');
  19504. }
  19505. return existInstance;
  19506. }
  19507. if (__DEV__) {
  19508. if (isDom(dom)
  19509. && dom.nodeName.toUpperCase() !== 'CANVAS'
  19510. && (
  19511. (!dom.clientWidth && (!opts || opts.width == null))
  19512. || (!dom.clientHeight && (!opts || opts.height == null))
  19513. )
  19514. ) {
  19515. console.warn('Can\'t get dom width or height');
  19516. }
  19517. }
  19518. var chart = new ECharts(dom, theme, opts);
  19519. chart.id = 'ec_' + idBase++;
  19520. instances[chart.id] = chart;
  19521. if (dom.setAttribute) {
  19522. dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
  19523. }
  19524. else {
  19525. dom[DOM_ATTRIBUTE_KEY] = chart.id;
  19526. }
  19527. enableConnect(chart);
  19528. return chart;
  19529. }
  19530. /**
  19531. * @return {string|Array.<module:echarts~ECharts>} groupId
  19532. */
  19533. function connect(groupId) {
  19534. // Is array of charts
  19535. if (isArray(groupId)) {
  19536. var charts = groupId;
  19537. groupId = null;
  19538. // If any chart has group
  19539. each$1(charts, function (chart) {
  19540. if (chart.group != null) {
  19541. groupId = chart.group;
  19542. }
  19543. });
  19544. groupId = groupId || ('g_' + groupIdBase++);
  19545. each$1(charts, function (chart) {
  19546. chart.group = groupId;
  19547. });
  19548. }
  19549. connectedGroups[groupId] = true;
  19550. return groupId;
  19551. }
  19552. /**
  19553. * @DEPRECATED
  19554. * @return {string} groupId
  19555. */
  19556. function disConnect(groupId) {
  19557. connectedGroups[groupId] = false;
  19558. }
  19559. /**
  19560. * @return {string} groupId
  19561. */
  19562. var disconnect = disConnect;
  19563. /**
  19564. * Dispose a chart instance
  19565. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  19566. */
  19567. function dispose(chart) {
  19568. if (typeof chart === 'string') {
  19569. chart = instances[chart];
  19570. }
  19571. else if (!(chart instanceof ECharts)){
  19572. // Try to treat as dom
  19573. chart = getInstanceByDom(chart);
  19574. }
  19575. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  19576. chart.dispose();
  19577. }
  19578. }
  19579. /**
  19580. * @param {HTMLElement} dom
  19581. * @return {echarts~ECharts}
  19582. */
  19583. function getInstanceByDom(dom) {
  19584. var key;
  19585. if (dom.getAttribute) {
  19586. key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  19587. }
  19588. else {
  19589. key = dom[DOM_ATTRIBUTE_KEY];
  19590. }
  19591. return instances[key];
  19592. }
  19593. /**
  19594. * @param {string} key
  19595. * @return {echarts~ECharts}
  19596. */
  19597. function getInstanceById(key) {
  19598. return instances[key];
  19599. }
  19600. /**
  19601. * Register theme
  19602. */
  19603. function registerTheme(name, theme) {
  19604. themeStorage[name] = theme;
  19605. }
  19606. /**
  19607. * Register option preprocessor
  19608. * @param {Function} preprocessorFunc
  19609. */
  19610. function registerPreprocessor(preprocessorFunc) {
  19611. optionPreprocessorFuncs.push(preprocessorFunc);
  19612. }
  19613. /**
  19614. * @param {number} [priority=1000]
  19615. * @param {Function} processorFunc
  19616. */
  19617. function registerProcessor(priority, processorFunc) {
  19618. if (typeof priority === 'function') {
  19619. processorFunc = priority;
  19620. priority = PRIORITY_PROCESSOR_FILTER;
  19621. }
  19622. if (__DEV__) {
  19623. if (isNaN(priority)) {
  19624. throw new Error('Unkown processor priority');
  19625. }
  19626. }
  19627. dataProcessorFuncs.push({
  19628. prio: priority,
  19629. func: processorFunc
  19630. });
  19631. }
  19632. /**
  19633. * Register postUpdater
  19634. * @param {Function} postUpdateFunc
  19635. */
  19636. function registerPostUpdate(postUpdateFunc) {
  19637. postUpdateFuncs.push(postUpdateFunc);
  19638. }
  19639. /**
  19640. * Usage:
  19641. * registerAction('someAction', 'someEvent', function () { ... });
  19642. * registerAction('someAction', function () { ... });
  19643. * registerAction(
  19644. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  19645. * function () { ... }
  19646. * );
  19647. *
  19648. * @param {(string|Object)} actionInfo
  19649. * @param {string} actionInfo.type
  19650. * @param {string} [actionInfo.event]
  19651. * @param {string} [actionInfo.update]
  19652. * @param {string} [eventName]
  19653. * @param {Function} action
  19654. */
  19655. function registerAction(actionInfo, eventName, action) {
  19656. if (typeof eventName === 'function') {
  19657. action = eventName;
  19658. eventName = '';
  19659. }
  19660. var actionType = isObject(actionInfo)
  19661. ? actionInfo.type
  19662. : ([actionInfo, actionInfo = {
  19663. event: eventName
  19664. }][0]);
  19665. // Event name is all lowercase
  19666. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  19667. eventName = actionInfo.event;
  19668. // Validate action type and event name.
  19669. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  19670. if (!actions[actionType]) {
  19671. actions[actionType] = {action: action, actionInfo: actionInfo};
  19672. }
  19673. eventActionMap[eventName] = actionType;
  19674. }
  19675. /**
  19676. * @param {string} type
  19677. * @param {*} CoordinateSystem
  19678. */
  19679. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  19680. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  19681. }
  19682. /**
  19683. * Get dimensions of specified coordinate system.
  19684. * @param {string} type
  19685. * @return {Array.<string|Object>}
  19686. */
  19687. function getCoordinateSystemDimensions(type) {
  19688. var coordSysCreator = CoordinateSystemManager.get(type);
  19689. if (coordSysCreator) {
  19690. return coordSysCreator.getDimensionsInfo
  19691. ? coordSysCreator.getDimensionsInfo()
  19692. : coordSysCreator.dimensions.slice();
  19693. }
  19694. }
  19695. /**
  19696. * Layout is a special stage of visual encoding
  19697. * Most visual encoding like color are common for different chart
  19698. * But each chart has it's own layout algorithm
  19699. *
  19700. * @param {number} [priority=1000]
  19701. * @param {Function} layoutFunc
  19702. */
  19703. function registerLayout(priority, layoutFunc) {
  19704. if (typeof priority === 'function') {
  19705. layoutFunc = priority;
  19706. priority = PRIORITY_VISUAL_LAYOUT;
  19707. }
  19708. if (__DEV__) {
  19709. if (isNaN(priority)) {
  19710. throw new Error('Unkown layout priority');
  19711. }
  19712. }
  19713. visualFuncs.push({
  19714. prio: priority,
  19715. func: layoutFunc,
  19716. isLayout: true
  19717. });
  19718. }
  19719. /**
  19720. * @param {number} [priority=3000]
  19721. * @param {Function} visualFunc
  19722. */
  19723. function registerVisual(priority, visualFunc) {
  19724. if (typeof priority === 'function') {
  19725. visualFunc = priority;
  19726. priority = PRIORITY_VISUAL_CHART;
  19727. }
  19728. if (__DEV__) {
  19729. if (isNaN(priority)) {
  19730. throw new Error('Unkown visual priority');
  19731. }
  19732. }
  19733. visualFuncs.push({
  19734. prio: priority,
  19735. func: visualFunc
  19736. });
  19737. }
  19738. /**
  19739. * @param {string} name
  19740. */
  19741. function registerLoading(name, loadingFx) {
  19742. loadingEffects[name] = loadingFx;
  19743. }
  19744. /**
  19745. * @param {Object} opts
  19746. * @param {string} [superClass]
  19747. */
  19748. function extendComponentModel(opts/*, superClass*/) {
  19749. // var Clazz = ComponentModel;
  19750. // if (superClass) {
  19751. // var classType = parseClassType(superClass);
  19752. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  19753. // }
  19754. return ComponentModel.extend(opts);
  19755. }
  19756. /**
  19757. * @param {Object} opts
  19758. * @param {string} [superClass]
  19759. */
  19760. function extendComponentView(opts/*, superClass*/) {
  19761. // var Clazz = ComponentView;
  19762. // if (superClass) {
  19763. // var classType = parseClassType(superClass);
  19764. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  19765. // }
  19766. return Component$1.extend(opts);
  19767. }
  19768. /**
  19769. * @param {Object} opts
  19770. * @param {string} [superClass]
  19771. */
  19772. function extendSeriesModel(opts/*, superClass*/) {
  19773. // var Clazz = SeriesModel;
  19774. // if (superClass) {
  19775. // superClass = 'series.' + superClass.replace('series.', '');
  19776. // var classType = parseClassType(superClass);
  19777. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  19778. // }
  19779. return SeriesModel.extend(opts);
  19780. }
  19781. /**
  19782. * @param {Object} opts
  19783. * @param {string} [superClass]
  19784. */
  19785. function extendChartView(opts/*, superClass*/) {
  19786. // var Clazz = ChartView;
  19787. // if (superClass) {
  19788. // superClass = superClass.replace('series.', '');
  19789. // var classType = parseClassType(superClass);
  19790. // Clazz = ChartView.getClass(classType.main, true);
  19791. // }
  19792. return Chart.extend(opts);
  19793. }
  19794. /**
  19795. * ZRender need a canvas context to do measureText.
  19796. * But in node environment canvas may be created by node-canvas.
  19797. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  19798. *
  19799. * Be careful of using it in the browser.
  19800. *
  19801. * @param {Function} creator
  19802. * @example
  19803. * var Canvas = require('canvas');
  19804. * var echarts = require('echarts');
  19805. * echarts.setCanvasCreator(function () {
  19806. * // Small size is enough.
  19807. * return new Canvas(32, 32);
  19808. * });
  19809. */
  19810. function setCanvasCreator(creator) {
  19811. $override('createCanvas', creator);
  19812. }
  19813. /**
  19814. * @param {string} mapName
  19815. * @param {Object|string} geoJson
  19816. * @param {Object} [specialAreas]
  19817. *
  19818. * @example
  19819. * $.get('USA.json', function (geoJson) {
  19820. * echarts.registerMap('USA', geoJson);
  19821. * // Or
  19822. * echarts.registerMap('USA', {
  19823. * geoJson: geoJson,
  19824. * specialAreas: {}
  19825. * })
  19826. * });
  19827. */
  19828. function registerMap(mapName, geoJson, specialAreas) {
  19829. if (geoJson.geoJson && !geoJson.features) {
  19830. specialAreas = geoJson.specialAreas;
  19831. geoJson = geoJson.geoJson;
  19832. }
  19833. if (typeof geoJson === 'string') {
  19834. geoJson = (typeof JSON !== 'undefined' && JSON.parse)
  19835. ? JSON.parse(geoJson) : (new Function('return (' + geoJson + ');'))();
  19836. }
  19837. mapDataStores[mapName] = {
  19838. geoJson: geoJson,
  19839. specialAreas: specialAreas
  19840. };
  19841. }
  19842. /**
  19843. * @param {string} mapName
  19844. * @return {Object}
  19845. */
  19846. function getMap(mapName) {
  19847. return mapDataStores[mapName];
  19848. }
  19849. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  19850. registerPreprocessor(backwardCompat);
  19851. registerLoading('default', loadingDefault);
  19852. // Default actions
  19853. registerAction({
  19854. type: 'highlight',
  19855. event: 'highlight',
  19856. update: 'highlight'
  19857. }, noop);
  19858. registerAction({
  19859. type: 'downplay',
  19860. event: 'downplay',
  19861. update: 'downplay'
  19862. }, noop);
  19863. // For backward compatibility, where the namespace `dataTool` will
  19864. // be mounted on `echarts` is the extension `dataTool` is imported.
  19865. var dataTool = {};
  19866. function defaultKeyGetter(item) {
  19867. return item;
  19868. }
  19869. /**
  19870. * @param {Array} oldArr
  19871. * @param {Array} newArr
  19872. * @param {Function} oldKeyGetter
  19873. * @param {Function} newKeyGetter
  19874. * @param {Object} [context] Can be visited by this.context in callback.
  19875. */
  19876. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  19877. this._old = oldArr;
  19878. this._new = newArr;
  19879. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  19880. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  19881. this.context = context;
  19882. }
  19883. DataDiffer.prototype = {
  19884. constructor: DataDiffer,
  19885. /**
  19886. * Callback function when add a data
  19887. */
  19888. add: function (func) {
  19889. this._add = func;
  19890. return this;
  19891. },
  19892. /**
  19893. * Callback function when update a data
  19894. */
  19895. update: function (func) {
  19896. this._update = func;
  19897. return this;
  19898. },
  19899. /**
  19900. * Callback function when remove a data
  19901. */
  19902. remove: function (func) {
  19903. this._remove = func;
  19904. return this;
  19905. },
  19906. execute: function () {
  19907. var oldArr = this._old;
  19908. var newArr = this._new;
  19909. var oldDataIndexMap = {};
  19910. var newDataIndexMap = {};
  19911. var oldDataKeyArr = [];
  19912. var newDataKeyArr = [];
  19913. var i;
  19914. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  19915. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  19916. // Travel by inverted order to make sure order consistency
  19917. // when duplicate keys exists (consider newDataIndex.pop() below).
  19918. // For performance consideration, these code below do not look neat.
  19919. for (i = 0; i < oldArr.length; i++) {
  19920. var key = oldDataKeyArr[i];
  19921. var idx = newDataIndexMap[key];
  19922. // idx can never be empty array here. see 'set null' logic below.
  19923. if (idx != null) {
  19924. // Consider there is duplicate key (for example, use dataItem.name as key).
  19925. // We should make sure every item in newArr and oldArr can be visited.
  19926. var len = idx.length;
  19927. if (len) {
  19928. len === 1 && (newDataIndexMap[key] = null);
  19929. idx = idx.unshift();
  19930. }
  19931. else {
  19932. newDataIndexMap[key] = null;
  19933. }
  19934. this._update && this._update(idx, i);
  19935. }
  19936. else {
  19937. this._remove && this._remove(i);
  19938. }
  19939. }
  19940. for (var i = 0; i < newDataKeyArr.length; i++) {
  19941. var key = newDataKeyArr[i];
  19942. if (newDataIndexMap.hasOwnProperty(key)) {
  19943. var idx = newDataIndexMap[key];
  19944. if (idx == null) {
  19945. continue;
  19946. }
  19947. // idx can never be empty array here. see 'set null' logic above.
  19948. if (!idx.length) {
  19949. this._add && this._add(idx);
  19950. }
  19951. else {
  19952. for (var j = 0, len = idx.length; j < len; j++) {
  19953. this._add && this._add(idx[j]);
  19954. }
  19955. }
  19956. }
  19957. }
  19958. }
  19959. };
  19960. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  19961. for (var i = 0; i < arr.length; i++) {
  19962. // Add prefix to avoid conflict with Object.prototype.
  19963. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  19964. var existence = map[key];
  19965. if (existence == null) {
  19966. keyArr.push(key);
  19967. map[key] = i;
  19968. }
  19969. else {
  19970. if (!existence.length) {
  19971. map[key] = existence = [existence];
  19972. }
  19973. existence.push(i);
  19974. }
  19975. }
  19976. }
  19977. /**
  19978. * List for data storage
  19979. * @module echarts/data/List
  19980. */
  19981. var isObject$4 = isObject;
  19982. var UNDEFINED = 'undefined';
  19983. var globalObj = typeof window === UNDEFINED ? global : window;
  19984. var dataCtors = {
  19985. 'float': typeof globalObj.Float64Array === UNDEFINED
  19986. ? Array : globalObj.Float64Array,
  19987. 'int': typeof globalObj.Int32Array === UNDEFINED
  19988. ? Array : globalObj.Int32Array,
  19989. // Ordinal data type can be string or int
  19990. 'ordinal': Array,
  19991. 'number': Array,
  19992. 'time': Array
  19993. };
  19994. var TRANSFERABLE_PROPERTIES = [
  19995. 'stackedOn', 'hasItemOption', '_nameList', '_idList', '_rawData'
  19996. ];
  19997. function transferProperties(a, b) {
  19998. each$1(TRANSFERABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
  19999. if (b.hasOwnProperty(propName)) {
  20000. a[propName] = b[propName];
  20001. }
  20002. });
  20003. a.__wrappedMethods = b.__wrappedMethods;
  20004. }
  20005. function DefaultDataProvider(dataArray) {
  20006. this._array = dataArray || [];
  20007. }
  20008. DefaultDataProvider.prototype.pure = false;
  20009. DefaultDataProvider.prototype.count = function () {
  20010. return this._array.length;
  20011. };
  20012. DefaultDataProvider.prototype.getItem = function (idx) {
  20013. return this._array[idx];
  20014. };
  20015. /**
  20016. * @constructor
  20017. * @alias module:echarts/data/List
  20018. *
  20019. * @param {Array.<string|Object>} dimensions
  20020. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  20021. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  20022. * @param {module:echarts/model/Model} hostModel
  20023. */
  20024. var List = function (dimensions, hostModel) {
  20025. dimensions = dimensions || ['x', 'y'];
  20026. var dimensionInfos = {};
  20027. var dimensionNames = [];
  20028. for (var i = 0; i < dimensions.length; i++) {
  20029. var dimensionName;
  20030. var dimensionInfo = {};
  20031. if (typeof dimensions[i] === 'string') {
  20032. dimensionName = dimensions[i];
  20033. dimensionInfo = {
  20034. name: dimensionName,
  20035. coordDim: dimensionName,
  20036. coordDimIndex: 0,
  20037. stackable: false,
  20038. // Type can be 'float', 'int', 'number'
  20039. // Default is number, Precision of float may not enough
  20040. type: 'number'
  20041. };
  20042. }
  20043. else {
  20044. dimensionInfo = dimensions[i];
  20045. dimensionName = dimensionInfo.name;
  20046. dimensionInfo.type = dimensionInfo.type || 'number';
  20047. if (!dimensionInfo.coordDim) {
  20048. dimensionInfo.coordDim = dimensionName;
  20049. dimensionInfo.coordDimIndex = 0;
  20050. }
  20051. }
  20052. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  20053. dimensionNames.push(dimensionName);
  20054. dimensionInfos[dimensionName] = dimensionInfo;
  20055. }
  20056. /**
  20057. * @readOnly
  20058. * @type {Array.<string>}
  20059. */
  20060. this.dimensions = dimensionNames;
  20061. /**
  20062. * Infomation of each data dimension, like data type.
  20063. * @type {Object}
  20064. */
  20065. this._dimensionInfos = dimensionInfos;
  20066. /**
  20067. * @type {module:echarts/model/Model}
  20068. */
  20069. this.hostModel = hostModel;
  20070. /**
  20071. * @type {module:echarts/model/Model}
  20072. */
  20073. this.dataType;
  20074. /**
  20075. * Indices stores the indices of data subset after filtered.
  20076. * This data subset will be used in chart.
  20077. * @type {Array.<number>}
  20078. * @readOnly
  20079. */
  20080. this.indices = [];
  20081. /**
  20082. * Data storage
  20083. * @type {Object.<key, TypedArray|Array>}
  20084. * @private
  20085. */
  20086. this._storage = {};
  20087. /**
  20088. * @type {Array.<string>}
  20089. */
  20090. this._nameList = [];
  20091. /**
  20092. * @type {Array.<string>}
  20093. */
  20094. this._idList = [];
  20095. /**
  20096. * Models of data option is stored sparse for optimizing memory cost
  20097. * @type {Array.<module:echarts/model/Model>}
  20098. * @private
  20099. */
  20100. this._optionModels = [];
  20101. /**
  20102. * @param {module:echarts/data/List}
  20103. */
  20104. this.stackedOn = null;
  20105. /**
  20106. * Global visual properties after visual coding
  20107. * @type {Object}
  20108. * @private
  20109. */
  20110. this._visual = {};
  20111. /**
  20112. * Globel layout properties.
  20113. * @type {Object}
  20114. * @private
  20115. */
  20116. this._layout = {};
  20117. /**
  20118. * Item visual properties after visual coding
  20119. * @type {Array.<Object>}
  20120. * @private
  20121. */
  20122. this._itemVisuals = [];
  20123. /**
  20124. * Item layout properties after layout
  20125. * @type {Array.<Object>}
  20126. * @private
  20127. */
  20128. this._itemLayouts = [];
  20129. /**
  20130. * Graphic elemnents
  20131. * @type {Array.<module:zrender/Element>}
  20132. * @private
  20133. */
  20134. this._graphicEls = [];
  20135. /**
  20136. * @type {Array.<Array|Object>}
  20137. * @private
  20138. */
  20139. this._rawData;
  20140. /**
  20141. * @type {Object}
  20142. * @private
  20143. */
  20144. this._extent;
  20145. };
  20146. var listProto = List.prototype;
  20147. listProto.type = 'list';
  20148. /**
  20149. * If each data item has it's own option
  20150. * @type {boolean}
  20151. */
  20152. listProto.hasItemOption = true;
  20153. /**
  20154. * Get dimension name
  20155. * @param {string|number} dim
  20156. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  20157. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  20158. * @return {string} Concrete dim name.
  20159. */
  20160. listProto.getDimension = function (dim) {
  20161. if (!isNaN(dim)) {
  20162. dim = this.dimensions[dim] || dim;
  20163. }
  20164. return dim;
  20165. };
  20166. /**
  20167. * Get type and stackable info of particular dimension
  20168. * @param {string|number} dim
  20169. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  20170. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  20171. */
  20172. listProto.getDimensionInfo = function (dim) {
  20173. return clone(this._dimensionInfos[this.getDimension(dim)]);
  20174. };
  20175. /**
  20176. * Initialize from data
  20177. * @param {Array.<Object|number|Array>} data
  20178. * @param {Array.<string>} [nameList]
  20179. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  20180. */
  20181. listProto.initData = function (data, nameList, dimValueGetter) {
  20182. data = data || [];
  20183. var isDataArray = isArray(data);
  20184. if (isDataArray) {
  20185. data = new DefaultDataProvider(data);
  20186. }
  20187. if (__DEV__) {
  20188. if (!isDataArray && (typeof data.getItem != 'function' || typeof data.count != 'function')) {
  20189. throw new Error('Inavlid data provider.');
  20190. }
  20191. }
  20192. this._rawData = data;
  20193. // Clear
  20194. var storage = this._storage = {};
  20195. var indices = this.indices = [];
  20196. var dimensions = this.dimensions;
  20197. var dimensionInfoMap = this._dimensionInfos;
  20198. var size = data.count();
  20199. var idList = [];
  20200. var nameRepeatCount = {};
  20201. var nameDimIdx;
  20202. nameList = nameList || [];
  20203. // Init storage
  20204. for (var i = 0; i < dimensions.length; i++) {
  20205. var dimInfo = dimensionInfoMap[dimensions[i]];
  20206. dimInfo.otherDims.itemName === 0 && (nameDimIdx = i);
  20207. var DataCtor = dataCtors[dimInfo.type];
  20208. storage[dimensions[i]] = new DataCtor(size);
  20209. }
  20210. var self = this;
  20211. if (!dimValueGetter) {
  20212. self.hasItemOption = false;
  20213. }
  20214. // Default dim value getter
  20215. dimValueGetter = dimValueGetter || function (dataItem, dimName, dataIndex, dimIndex) {
  20216. var value = getDataItemValue(dataItem);
  20217. // If any dataItem is like { value: 10 }
  20218. if (isDataItemOption(dataItem)) {
  20219. self.hasItemOption = true;
  20220. }
  20221. return converDataValue(
  20222. (value instanceof Array)
  20223. ? value[dimIndex]
  20224. // If value is a single number or something else not array.
  20225. : value,
  20226. dimensionInfoMap[dimName]
  20227. );
  20228. };
  20229. for (var i = 0; i < size; i++) {
  20230. // NOTICE: Try not to write things into dataItem
  20231. var dataItem = data.getItem(i);
  20232. // Each data item is value
  20233. // [1, 2]
  20234. // 2
  20235. // Bar chart, line chart which uses category axis
  20236. // only gives the 'y' value. 'x' value is the indices of cateogry
  20237. // Use a tempValue to normalize the value to be a (x, y) value
  20238. // Store the data by dimensions
  20239. for (var k = 0; k < dimensions.length; k++) {
  20240. var dim = dimensions[k];
  20241. var dimStorage = storage[dim];
  20242. // PENDING NULL is empty or zero
  20243. dimStorage[i] = dimValueGetter(dataItem, dim, i, k);
  20244. }
  20245. indices.push(i);
  20246. }
  20247. // Use the name in option and create id
  20248. for (var i = 0; i < size; i++) {
  20249. var dataItem = data.getItem(i);
  20250. if (!nameList[i] && dataItem) {
  20251. if (dataItem.name != null) {
  20252. nameList[i] = dataItem.name;
  20253. }
  20254. else if (nameDimIdx != null) {
  20255. nameList[i] = storage[dimensions[nameDimIdx]][i];
  20256. }
  20257. }
  20258. var name = nameList[i] || '';
  20259. // Try using the id in option
  20260. var id = dataItem && dataItem.id;
  20261. if (!id && name) {
  20262. // Use name as id and add counter to avoid same name
  20263. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  20264. id = name;
  20265. if (nameRepeatCount[name] > 0) {
  20266. id += '__ec__' + nameRepeatCount[name];
  20267. }
  20268. nameRepeatCount[name]++;
  20269. }
  20270. id && (idList[i] = id);
  20271. }
  20272. this._nameList = nameList;
  20273. this._idList = idList;
  20274. };
  20275. /**
  20276. * @return {number}
  20277. */
  20278. listProto.count = function () {
  20279. return this.indices.length;
  20280. };
  20281. /**
  20282. * Get value. Return NaN if idx is out of range.
  20283. * @param {string} dim Dim must be concrete name.
  20284. * @param {number} idx
  20285. * @param {boolean} stack
  20286. * @return {number}
  20287. */
  20288. listProto.get = function (dim, idx, stack) {
  20289. var storage = this._storage;
  20290. var dataIndex = this.indices[idx];
  20291. // If value not exists
  20292. if (dataIndex == null || !storage[dim]) {
  20293. return NaN;
  20294. }
  20295. var value = storage[dim][dataIndex];
  20296. // FIXME ordinal data type is not stackable
  20297. if (stack) {
  20298. var dimensionInfo = this._dimensionInfos[dim];
  20299. if (dimensionInfo && dimensionInfo.stackable) {
  20300. var stackedOn = this.stackedOn;
  20301. while (stackedOn) {
  20302. // Get no stacked data of stacked on
  20303. var stackedValue = stackedOn.get(dim, idx);
  20304. // Considering positive stack, negative stack and empty data
  20305. if ((value >= 0 && stackedValue > 0) // Positive stack
  20306. || (value <= 0 && stackedValue < 0) // Negative stack
  20307. ) {
  20308. value += stackedValue;
  20309. }
  20310. stackedOn = stackedOn.stackedOn;
  20311. }
  20312. }
  20313. }
  20314. return value;
  20315. };
  20316. /**
  20317. * Get value for multi dimensions.
  20318. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  20319. * @param {number} idx
  20320. * @param {boolean} stack
  20321. * @return {number}
  20322. */
  20323. listProto.getValues = function (dimensions, idx, stack) {
  20324. var values = [];
  20325. if (!isArray(dimensions)) {
  20326. stack = idx;
  20327. idx = dimensions;
  20328. dimensions = this.dimensions;
  20329. }
  20330. for (var i = 0, len = dimensions.length; i < len; i++) {
  20331. values.push(this.get(dimensions[i], idx, stack));
  20332. }
  20333. return values;
  20334. };
  20335. /**
  20336. * If value is NaN. Inlcuding '-'
  20337. * @param {string} dim
  20338. * @param {number} idx
  20339. * @return {number}
  20340. */
  20341. listProto.hasValue = function (idx) {
  20342. var dimensions = this.dimensions;
  20343. var dimensionInfos = this._dimensionInfos;
  20344. for (var i = 0, len = dimensions.length; i < len; i++) {
  20345. if (
  20346. // Ordinal type can be string or number
  20347. dimensionInfos[dimensions[i]].type !== 'ordinal'
  20348. && isNaN(this.get(dimensions[i], idx))
  20349. ) {
  20350. return false;
  20351. }
  20352. }
  20353. return true;
  20354. };
  20355. /**
  20356. * Get extent of data in one dimension
  20357. * @param {string} dim
  20358. * @param {boolean} stack
  20359. * @param {Function} filter
  20360. */
  20361. listProto.getDataExtent = function (dim, stack, filter$$1) {
  20362. dim = this.getDimension(dim);
  20363. var dimData = this._storage[dim];
  20364. var dimInfo = this.getDimensionInfo(dim);
  20365. stack = (dimInfo && dimInfo.stackable) && stack;
  20366. var dimExtent = (this._extent || (this._extent = {}))[dim + (!!stack)];
  20367. var value;
  20368. if (dimExtent) {
  20369. return dimExtent;
  20370. }
  20371. // var dimInfo = this._dimensionInfos[dim];
  20372. if (dimData) {
  20373. var min = Infinity;
  20374. var max = -Infinity;
  20375. // var isOrdinal = dimInfo.type === 'ordinal';
  20376. for (var i = 0, len = this.count(); i < len; i++) {
  20377. value = this.get(dim, i, stack);
  20378. // FIXME
  20379. // if (isOrdinal && typeof value === 'string') {
  20380. // value = zrUtil.indexOf(dimData, value);
  20381. // }
  20382. if (!filter$$1 || filter$$1(value, dim, i)) {
  20383. value < min && (min = value);
  20384. value > max && (max = value);
  20385. }
  20386. }
  20387. return (this._extent[dim + !!stack] = [min, max]);
  20388. }
  20389. else {
  20390. return [Infinity, -Infinity];
  20391. }
  20392. };
  20393. /**
  20394. * Get sum of data in one dimension
  20395. * @param {string} dim
  20396. * @param {boolean} stack
  20397. */
  20398. listProto.getSum = function (dim, stack) {
  20399. var dimData = this._storage[dim];
  20400. var sum = 0;
  20401. if (dimData) {
  20402. for (var i = 0, len = this.count(); i < len; i++) {
  20403. var value = this.get(dim, i, stack);
  20404. if (!isNaN(value)) {
  20405. sum += value;
  20406. }
  20407. }
  20408. }
  20409. return sum;
  20410. };
  20411. /**
  20412. * Retreive the index with given value
  20413. * @param {number} idx
  20414. * @param {number} value
  20415. * @return {number}
  20416. */
  20417. // FIXME Precision of float value
  20418. listProto.indexOf = function (dim, value) {
  20419. var storage = this._storage;
  20420. var dimData = storage[dim];
  20421. var indices = this.indices;
  20422. if (dimData) {
  20423. for (var i = 0, len = indices.length; i < len; i++) {
  20424. var rawIndex = indices[i];
  20425. if (dimData[rawIndex] === value) {
  20426. return i;
  20427. }
  20428. }
  20429. }
  20430. return -1;
  20431. };
  20432. /**
  20433. * Retreive the index with given name
  20434. * @param {number} idx
  20435. * @param {number} name
  20436. * @return {number}
  20437. */
  20438. listProto.indexOfName = function (name) {
  20439. var indices = this.indices;
  20440. var nameList = this._nameList;
  20441. for (var i = 0, len = indices.length; i < len; i++) {
  20442. var rawIndex = indices[i];
  20443. if (nameList[rawIndex] === name) {
  20444. return i;
  20445. }
  20446. }
  20447. return -1;
  20448. };
  20449. /**
  20450. * Retreive the index with given raw data index
  20451. * @param {number} idx
  20452. * @param {number} name
  20453. * @return {number}
  20454. */
  20455. listProto.indexOfRawIndex = function (rawIndex) {
  20456. // Indices are ascending
  20457. var indices = this.indices;
  20458. // If rawIndex === dataIndex
  20459. var rawDataIndex = indices[rawIndex];
  20460. if (rawDataIndex != null && rawDataIndex === rawIndex) {
  20461. return rawIndex;
  20462. }
  20463. var left = 0;
  20464. var right = indices.length - 1;
  20465. while (left <= right) {
  20466. var mid = (left + right) / 2 | 0;
  20467. if (indices[mid] < rawIndex) {
  20468. left = mid + 1;
  20469. }
  20470. else if (indices[mid] > rawIndex) {
  20471. right = mid - 1;
  20472. }
  20473. else {
  20474. return mid;
  20475. }
  20476. }
  20477. return -1;
  20478. };
  20479. /**
  20480. * Retreive the index of nearest value
  20481. * @param {string} dim
  20482. * @param {number} value
  20483. * @param {boolean} stack If given value is after stacked
  20484. * @param {number} [maxDistance=Infinity]
  20485. * @return {Array.<number>} Considere multiple points has the same value.
  20486. */
  20487. listProto.indicesOfNearest = function (dim, value, stack, maxDistance) {
  20488. var storage = this._storage;
  20489. var dimData = storage[dim];
  20490. var nearestIndices = [];
  20491. if (!dimData) {
  20492. return nearestIndices;
  20493. }
  20494. if (maxDistance == null) {
  20495. maxDistance = Infinity;
  20496. }
  20497. var minDist = Number.MAX_VALUE;
  20498. var minDiff = -1;
  20499. for (var i = 0, len = this.count(); i < len; i++) {
  20500. var diff = value - this.get(dim, i, stack);
  20501. var dist = Math.abs(diff);
  20502. if (diff <= maxDistance && dist <= minDist) {
  20503. // For the case of two data are same on xAxis, which has sequence data.
  20504. // Show the nearest index
  20505. // https://github.com/ecomfe/echarts/issues/2869
  20506. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  20507. minDist = dist;
  20508. minDiff = diff;
  20509. nearestIndices.length = 0;
  20510. }
  20511. nearestIndices.push(i);
  20512. }
  20513. }
  20514. return nearestIndices;
  20515. };
  20516. /**
  20517. * Get raw data index
  20518. * @param {number} idx
  20519. * @return {number}
  20520. */
  20521. listProto.getRawIndex = function (idx) {
  20522. var rawIdx = this.indices[idx];
  20523. return rawIdx == null ? -1 : rawIdx;
  20524. };
  20525. /**
  20526. * Get raw data item
  20527. * @param {number} idx
  20528. * @return {number}
  20529. */
  20530. listProto.getRawDataItem = function (idx) {
  20531. return this._rawData.getItem(this.getRawIndex(idx));
  20532. };
  20533. /**
  20534. * @param {number} idx
  20535. * @param {boolean} [notDefaultIdx=false]
  20536. * @return {string}
  20537. */
  20538. listProto.getName = function (idx) {
  20539. return this._nameList[this.indices[idx]] || '';
  20540. };
  20541. /**
  20542. * @param {number} idx
  20543. * @param {boolean} [notDefaultIdx=false]
  20544. * @return {string}
  20545. */
  20546. listProto.getId = function (idx) {
  20547. return this._idList[this.indices[idx]] || (this.getRawIndex(idx) + '');
  20548. };
  20549. function normalizeDimensions(dimensions) {
  20550. if (!isArray(dimensions)) {
  20551. dimensions = [dimensions];
  20552. }
  20553. return dimensions;
  20554. }
  20555. /**
  20556. * Data iteration
  20557. * @param {string|Array.<string>}
  20558. * @param {Function} cb
  20559. * @param {boolean} [stack=false]
  20560. * @param {*} [context=this]
  20561. *
  20562. * @example
  20563. * list.each('x', function (x, idx) {});
  20564. * list.each(['x', 'y'], function (x, y, idx) {});
  20565. * list.each(function (idx) {})
  20566. */
  20567. listProto.each = function (dims, cb, stack, context) {
  20568. if (typeof dims === 'function') {
  20569. context = stack;
  20570. stack = cb;
  20571. cb = dims;
  20572. dims = [];
  20573. }
  20574. dims = map(normalizeDimensions(dims), this.getDimension, this);
  20575. var value = [];
  20576. var dimSize = dims.length;
  20577. var indices = this.indices;
  20578. context = context || this;
  20579. for (var i = 0; i < indices.length; i++) {
  20580. // Simple optimization
  20581. switch (dimSize) {
  20582. case 0:
  20583. cb.call(context, i);
  20584. break;
  20585. case 1:
  20586. cb.call(context, this.get(dims[0], i, stack), i);
  20587. break;
  20588. case 2:
  20589. cb.call(context, this.get(dims[0], i, stack), this.get(dims[1], i, stack), i);
  20590. break;
  20591. default:
  20592. for (var k = 0; k < dimSize; k++) {
  20593. value[k] = this.get(dims[k], i, stack);
  20594. }
  20595. // Index
  20596. value[k] = i;
  20597. cb.apply(context, value);
  20598. }
  20599. }
  20600. };
  20601. /**
  20602. * Data filter
  20603. * @param {string|Array.<string>}
  20604. * @param {Function} cb
  20605. * @param {boolean} [stack=false]
  20606. * @param {*} [context=this]
  20607. */
  20608. listProto.filterSelf = function (dimensions, cb, stack, context) {
  20609. if (typeof dimensions === 'function') {
  20610. context = stack;
  20611. stack = cb;
  20612. cb = dimensions;
  20613. dimensions = [];
  20614. }
  20615. dimensions = map(
  20616. normalizeDimensions(dimensions), this.getDimension, this
  20617. );
  20618. var newIndices = [];
  20619. var value = [];
  20620. var dimSize = dimensions.length;
  20621. var indices = this.indices;
  20622. context = context || this;
  20623. for (var i = 0; i < indices.length; i++) {
  20624. var keep;
  20625. // Simple optimization
  20626. if (!dimSize) {
  20627. keep = cb.call(context, i);
  20628. }
  20629. else if (dimSize === 1) {
  20630. keep = cb.call(
  20631. context, this.get(dimensions[0], i, stack), i
  20632. );
  20633. }
  20634. else {
  20635. for (var k = 0; k < dimSize; k++) {
  20636. value[k] = this.get(dimensions[k], i, stack);
  20637. }
  20638. value[k] = i;
  20639. keep = cb.apply(context, value);
  20640. }
  20641. if (keep) {
  20642. newIndices.push(indices[i]);
  20643. }
  20644. }
  20645. this.indices = newIndices;
  20646. // Reset data extent
  20647. this._extent = {};
  20648. return this;
  20649. };
  20650. /**
  20651. * Data mapping to a plain array
  20652. * @param {string|Array.<string>} [dimensions]
  20653. * @param {Function} cb
  20654. * @param {boolean} [stack=false]
  20655. * @param {*} [context=this]
  20656. * @return {Array}
  20657. */
  20658. listProto.mapArray = function (dimensions, cb, stack, context) {
  20659. if (typeof dimensions === 'function') {
  20660. context = stack;
  20661. stack = cb;
  20662. cb = dimensions;
  20663. dimensions = [];
  20664. }
  20665. var result = [];
  20666. this.each(dimensions, function () {
  20667. result.push(cb && cb.apply(this, arguments));
  20668. }, stack, context);
  20669. return result;
  20670. };
  20671. function cloneListForMapAndSample(original, excludeDimensions) {
  20672. var allDimensions = original.dimensions;
  20673. var list = new List(
  20674. map(allDimensions, original.getDimensionInfo, original),
  20675. original.hostModel
  20676. );
  20677. // FIXME If needs stackedOn, value may already been stacked
  20678. transferProperties(list, original);
  20679. var storage = list._storage = {};
  20680. var originalStorage = original._storage;
  20681. // Init storage
  20682. for (var i = 0; i < allDimensions.length; i++) {
  20683. var dim = allDimensions[i];
  20684. var dimStore = originalStorage[dim];
  20685. if (indexOf(excludeDimensions, dim) >= 0) {
  20686. storage[dim] = new dimStore.constructor(
  20687. originalStorage[dim].length
  20688. );
  20689. }
  20690. else {
  20691. // Direct reference for other dimensions
  20692. storage[dim] = originalStorage[dim];
  20693. }
  20694. }
  20695. return list;
  20696. }
  20697. /**
  20698. * Data mapping to a new List with given dimensions
  20699. * @param {string|Array.<string>} dimensions
  20700. * @param {Function} cb
  20701. * @param {boolean} [stack=false]
  20702. * @param {*} [context=this]
  20703. * @return {Array}
  20704. */
  20705. listProto.map = function (dimensions, cb, stack, context) {
  20706. dimensions = map(
  20707. normalizeDimensions(dimensions), this.getDimension, this
  20708. );
  20709. var list = cloneListForMapAndSample(this, dimensions);
  20710. // Following properties are all immutable.
  20711. // So we can reference to the same value
  20712. var indices = list.indices = this.indices;
  20713. var storage = list._storage;
  20714. var tmpRetValue = [];
  20715. this.each(dimensions, function () {
  20716. var idx = arguments[arguments.length - 1];
  20717. var retValue = cb && cb.apply(this, arguments);
  20718. if (retValue != null) {
  20719. // a number
  20720. if (typeof retValue === 'number') {
  20721. tmpRetValue[0] = retValue;
  20722. retValue = tmpRetValue;
  20723. }
  20724. for (var i = 0; i < retValue.length; i++) {
  20725. var dim = dimensions[i];
  20726. var dimStore = storage[dim];
  20727. var rawIdx = indices[idx];
  20728. if (dimStore) {
  20729. dimStore[rawIdx] = retValue[i];
  20730. }
  20731. }
  20732. }
  20733. }, stack, context);
  20734. return list;
  20735. };
  20736. /**
  20737. * Large data down sampling on given dimension
  20738. * @param {string} dimension
  20739. * @param {number} rate
  20740. * @param {Function} sampleValue
  20741. * @param {Function} sampleIndex Sample index for name and id
  20742. */
  20743. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  20744. var list = cloneListForMapAndSample(this, [dimension]);
  20745. var storage = this._storage;
  20746. var targetStorage = list._storage;
  20747. var originalIndices = this.indices;
  20748. var indices = list.indices = [];
  20749. var frameValues = [];
  20750. var frameIndices = [];
  20751. var frameSize = Math.floor(1 / rate);
  20752. var dimStore = targetStorage[dimension];
  20753. var len = this.count();
  20754. // Copy data from original data
  20755. for (var i = 0; i < storage[dimension].length; i++) {
  20756. targetStorage[dimension][i] = storage[dimension][i];
  20757. }
  20758. for (var i = 0; i < len; i += frameSize) {
  20759. // Last frame
  20760. if (frameSize > len - i) {
  20761. frameSize = len - i;
  20762. frameValues.length = frameSize;
  20763. }
  20764. for (var k = 0; k < frameSize; k++) {
  20765. var idx = originalIndices[i + k];
  20766. frameValues[k] = dimStore[idx];
  20767. frameIndices[k] = idx;
  20768. }
  20769. var value = sampleValue(frameValues);
  20770. var idx = frameIndices[sampleIndex(frameValues, value) || 0];
  20771. // Only write value on the filtered data
  20772. dimStore[idx] = value;
  20773. indices.push(idx);
  20774. }
  20775. return list;
  20776. };
  20777. /**
  20778. * Get model of one data item.
  20779. *
  20780. * @param {number} idx
  20781. */
  20782. // FIXME Model proxy ?
  20783. listProto.getItemModel = function (idx) {
  20784. var hostModel = this.hostModel;
  20785. idx = this.indices[idx];
  20786. return new Model(this._rawData.getItem(idx), hostModel, hostModel && hostModel.ecModel);
  20787. };
  20788. /**
  20789. * Create a data differ
  20790. * @param {module:echarts/data/List} otherList
  20791. * @return {module:echarts/data/DataDiffer}
  20792. */
  20793. listProto.diff = function (otherList) {
  20794. var idList = this._idList;
  20795. var otherIdList = otherList && otherList._idList;
  20796. var val;
  20797. // Use prefix to avoid index to be the same as otherIdList[idx],
  20798. // which will cause weird udpate animation.
  20799. var prefix = 'e\0\0';
  20800. return new DataDiffer(
  20801. otherList ? otherList.indices : [],
  20802. this.indices,
  20803. function (idx) {
  20804. return (val = otherIdList[idx]) != null ? val : prefix + idx;
  20805. },
  20806. function (idx) {
  20807. return (val = idList[idx]) != null ? val : prefix + idx;
  20808. }
  20809. );
  20810. };
  20811. /**
  20812. * Get visual property.
  20813. * @param {string} key
  20814. */
  20815. listProto.getVisual = function (key) {
  20816. var visual = this._visual;
  20817. return visual && visual[key];
  20818. };
  20819. /**
  20820. * Set visual property
  20821. * @param {string|Object} key
  20822. * @param {*} [value]
  20823. *
  20824. * @example
  20825. * setVisual('color', color);
  20826. * setVisual({
  20827. * 'color': color
  20828. * });
  20829. */
  20830. listProto.setVisual = function (key, val) {
  20831. if (isObject$4(key)) {
  20832. for (var name in key) {
  20833. if (key.hasOwnProperty(name)) {
  20834. this.setVisual(name, key[name]);
  20835. }
  20836. }
  20837. return;
  20838. }
  20839. this._visual = this._visual || {};
  20840. this._visual[key] = val;
  20841. };
  20842. /**
  20843. * Set layout property.
  20844. * @param {string|Object} key
  20845. * @param {*} [val]
  20846. */
  20847. listProto.setLayout = function (key, val) {
  20848. if (isObject$4(key)) {
  20849. for (var name in key) {
  20850. if (key.hasOwnProperty(name)) {
  20851. this.setLayout(name, key[name]);
  20852. }
  20853. }
  20854. return;
  20855. }
  20856. this._layout[key] = val;
  20857. };
  20858. /**
  20859. * Get layout property.
  20860. * @param {string} key.
  20861. * @return {*}
  20862. */
  20863. listProto.getLayout = function (key) {
  20864. return this._layout[key];
  20865. };
  20866. /**
  20867. * Get layout of single data item
  20868. * @param {number} idx
  20869. */
  20870. listProto.getItemLayout = function (idx) {
  20871. return this._itemLayouts[idx];
  20872. };
  20873. /**
  20874. * Set layout of single data item
  20875. * @param {number} idx
  20876. * @param {Object} layout
  20877. * @param {boolean=} [merge=false]
  20878. */
  20879. listProto.setItemLayout = function (idx, layout, merge$$1) {
  20880. this._itemLayouts[idx] = merge$$1
  20881. ? extend(this._itemLayouts[idx] || {}, layout)
  20882. : layout;
  20883. };
  20884. /**
  20885. * Clear all layout of single data item
  20886. */
  20887. listProto.clearItemLayouts = function () {
  20888. this._itemLayouts.length = 0;
  20889. };
  20890. /**
  20891. * Get visual property of single data item
  20892. * @param {number} idx
  20893. * @param {string} key
  20894. * @param {boolean} [ignoreParent=false]
  20895. */
  20896. listProto.getItemVisual = function (idx, key, ignoreParent) {
  20897. var itemVisual = this._itemVisuals[idx];
  20898. var val = itemVisual && itemVisual[key];
  20899. if (val == null && !ignoreParent) {
  20900. // Use global visual property
  20901. return this.getVisual(key);
  20902. }
  20903. return val;
  20904. };
  20905. /**
  20906. * Set visual property of single data item
  20907. *
  20908. * @param {number} idx
  20909. * @param {string|Object} key
  20910. * @param {*} [value]
  20911. *
  20912. * @example
  20913. * setItemVisual(0, 'color', color);
  20914. * setItemVisual(0, {
  20915. * 'color': color
  20916. * });
  20917. */
  20918. listProto.setItemVisual = function (idx, key, value) {
  20919. var itemVisual = this._itemVisuals[idx] || {};
  20920. this._itemVisuals[idx] = itemVisual;
  20921. if (isObject$4(key)) {
  20922. for (var name in key) {
  20923. if (key.hasOwnProperty(name)) {
  20924. itemVisual[name] = key[name];
  20925. }
  20926. }
  20927. return;
  20928. }
  20929. itemVisual[key] = value;
  20930. };
  20931. /**
  20932. * Clear itemVisuals and list visual.
  20933. */
  20934. listProto.clearAllVisual = function () {
  20935. this._visual = {};
  20936. this._itemVisuals = [];
  20937. };
  20938. var setItemDataAndSeriesIndex = function (child) {
  20939. child.seriesIndex = this.seriesIndex;
  20940. child.dataIndex = this.dataIndex;
  20941. child.dataType = this.dataType;
  20942. };
  20943. /**
  20944. * Set graphic element relative to data. It can be set as null
  20945. * @param {number} idx
  20946. * @param {module:zrender/Element} [el]
  20947. */
  20948. listProto.setItemGraphicEl = function (idx, el) {
  20949. var hostModel = this.hostModel;
  20950. if (el) {
  20951. // Add data index and series index for indexing the data by element
  20952. // Useful in tooltip
  20953. el.dataIndex = idx;
  20954. el.dataType = this.dataType;
  20955. el.seriesIndex = hostModel && hostModel.seriesIndex;
  20956. if (el.type === 'group') {
  20957. el.traverse(setItemDataAndSeriesIndex, el);
  20958. }
  20959. }
  20960. this._graphicEls[idx] = el;
  20961. };
  20962. /**
  20963. * @param {number} idx
  20964. * @return {module:zrender/Element}
  20965. */
  20966. listProto.getItemGraphicEl = function (idx) {
  20967. return this._graphicEls[idx];
  20968. };
  20969. /**
  20970. * @param {Function} cb
  20971. * @param {*} context
  20972. */
  20973. listProto.eachItemGraphicEl = function (cb, context) {
  20974. each$1(this._graphicEls, function (el, idx) {
  20975. if (el) {
  20976. cb && cb.call(context, el, idx);
  20977. }
  20978. });
  20979. };
  20980. /**
  20981. * Shallow clone a new list except visual and layout properties, and graph elements.
  20982. * New list only change the indices.
  20983. */
  20984. listProto.cloneShallow = function () {
  20985. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  20986. var list = new List(dimensionInfoList, this.hostModel);
  20987. // FIXME
  20988. list._storage = this._storage;
  20989. transferProperties(list, this);
  20990. // Clone will not change the data extent and indices
  20991. list.indices = this.indices.slice();
  20992. if (this._extent) {
  20993. list._extent = extend({}, this._extent);
  20994. }
  20995. return list;
  20996. };
  20997. /**
  20998. * Wrap some method to add more feature
  20999. * @param {string} methodName
  21000. * @param {Function} injectFunction
  21001. */
  21002. listProto.wrapMethod = function (methodName, injectFunction) {
  21003. var originalMethod = this[methodName];
  21004. if (typeof originalMethod !== 'function') {
  21005. return;
  21006. }
  21007. this.__wrappedMethods = this.__wrappedMethods || [];
  21008. this.__wrappedMethods.push(methodName);
  21009. this[methodName] = function () {
  21010. var res = originalMethod.apply(this, arguments);
  21011. return injectFunction.apply(this, [res].concat(slice(arguments)));
  21012. };
  21013. };
  21014. // Methods that create a new list based on this list should be listed here.
  21015. // Notice that those method should `RETURN` the new list.
  21016. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  21017. // Methods that change indices of this list should be listed here.
  21018. listProto.CHANGABLE_METHODS = ['filterSelf'];
  21019. /**
  21020. * Complete dimensions by data (guess dimension).
  21021. */
  21022. var each$7 = each$1;
  21023. var isString$1 = isString;
  21024. var defaults$1 = defaults;
  21025. var OTHER_DIMS = {tooltip: 1, label: 1, itemName: 1};
  21026. /**
  21027. * Complete the dimensions array, by user defined `dimension` and `encode`,
  21028. * and guessing from the data structure.
  21029. * If no 'value' dimension specified, the first no-named dimension will be
  21030. * named as 'value'.
  21031. *
  21032. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  21033. * provides not only dim template, but also default order.
  21034. * `name` of each item provides default coord name.
  21035. * [{dimsDef: []}, ...] can be specified to give names.
  21036. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]].
  21037. * @param {Object} [opt]
  21038. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  21039. * For example: ['asdf', {name, type}, ...].
  21040. * @param {Object} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  21041. * @param {string} [opt.extraPrefix] Prefix of name when filling the left dimensions.
  21042. * @param {string} [opt.extraFromZero] If specified, extra dim names will be:
  21043. * extraPrefix + 0, extraPrefix + extraBaseIndex + 1 ...
  21044. * If not specified, extra dim names will be:
  21045. * extraPrefix, extraPrefix + 0, extraPrefix + 1 ...
  21046. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  21047. * @return {Array.<Object>} [{
  21048. * name: string mandatory,
  21049. * coordDim: string mandatory,
  21050. * coordDimIndex: number mandatory,
  21051. * type: string optional,
  21052. * tooltipName: string optional,
  21053. * otherDims: {
  21054. * tooltip: number optional,
  21055. * label: number optional
  21056. * },
  21057. * isExtraCoord: boolean true or undefined.
  21058. * other props ...
  21059. * }]
  21060. */
  21061. function completeDimensions(sysDims, data, opt) {
  21062. data = data || [];
  21063. opt = opt || {};
  21064. sysDims = (sysDims || []).slice();
  21065. var dimsDef = (opt.dimsDef || []).slice();
  21066. var encodeDef = createHashMap(opt.encodeDef);
  21067. var dataDimNameMap = createHashMap();
  21068. var coordDimNameMap = createHashMap();
  21069. // var valueCandidate;
  21070. var result = [];
  21071. var dimCount = opt.dimCount;
  21072. if (dimCount == null) {
  21073. var value0 = retrieveValue(data[0]);
  21074. dimCount = Math.max(
  21075. isArray(value0) && value0.length || 1,
  21076. sysDims.length,
  21077. dimsDef.length
  21078. );
  21079. each$7(sysDims, function (sysDimItem) {
  21080. var sysDimItemDimsDef = sysDimItem.dimsDef;
  21081. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  21082. });
  21083. }
  21084. // Apply user defined dims (`name` and `type`) and init result.
  21085. for (var i = 0; i < dimCount; i++) {
  21086. var dimDefItem = isString$1(dimsDef[i]) ? {name: dimsDef[i]} : (dimsDef[i] || {});
  21087. var userDimName = dimDefItem.name;
  21088. var resultItem = result[i] = {otherDims: {}};
  21089. // Name will be applied later for avoiding duplication.
  21090. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  21091. // Only if `series.dimensions` is defined in option, tooltipName
  21092. // will be set, and dimension will be diplayed vertically in
  21093. // tooltip by default.
  21094. resultItem.name = resultItem.tooltipName = userDimName;
  21095. dataDimNameMap.set(userDimName, i);
  21096. }
  21097. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  21098. }
  21099. // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  21100. encodeDef.each(function (dataDims, coordDim) {
  21101. dataDims = encodeDef.set(coordDim, normalizeToArray(dataDims).slice());
  21102. each$7(dataDims, function (resultDimIdx, coordDimIndex) {
  21103. // The input resultDimIdx can be dim name or index.
  21104. isString$1(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  21105. if (resultDimIdx != null && resultDimIdx < dimCount) {
  21106. dataDims[coordDimIndex] = resultDimIdx;
  21107. applyDim(result[resultDimIdx], coordDim, coordDimIndex);
  21108. }
  21109. });
  21110. });
  21111. // Apply templetes and default order from `sysDims`.
  21112. var availDimIdx = 0;
  21113. each$7(sysDims, function (sysDimItem, sysDimIndex) {
  21114. var coordDim;
  21115. var sysDimItem;
  21116. var sysDimItemDimsDef;
  21117. var sysDimItemOtherDims;
  21118. if (isString$1(sysDimItem)) {
  21119. coordDim = sysDimItem;
  21120. sysDimItem = {};
  21121. }
  21122. else {
  21123. coordDim = sysDimItem.name;
  21124. sysDimItem = clone(sysDimItem);
  21125. // `coordDimIndex` should not be set directly.
  21126. sysDimItemDimsDef = sysDimItem.dimsDef;
  21127. sysDimItemOtherDims = sysDimItem.otherDims;
  21128. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex
  21129. = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  21130. }
  21131. var dataDims = normalizeToArray(encodeDef.get(coordDim));
  21132. // dimensions provides default dim sequences.
  21133. if (!dataDims.length) {
  21134. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  21135. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  21136. availDimIdx++;
  21137. }
  21138. availDimIdx < result.length && dataDims.push(availDimIdx++);
  21139. }
  21140. }
  21141. // Apply templates.
  21142. each$7(dataDims, function (resultDimIdx, coordDimIndex) {
  21143. var resultItem = result[resultDimIdx];
  21144. applyDim(defaults$1(resultItem, sysDimItem), coordDim, coordDimIndex);
  21145. if (resultItem.name == null && sysDimItemDimsDef) {
  21146. resultItem.name = resultItem.tooltipName = sysDimItemDimsDef[coordDimIndex];
  21147. }
  21148. sysDimItemOtherDims && defaults$1(resultItem.otherDims, sysDimItemOtherDims);
  21149. });
  21150. });
  21151. // Make sure the first extra dim is 'value'.
  21152. var extra = opt.extraPrefix || 'value';
  21153. // Set dim `name` and other `coordDim` and other props.
  21154. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  21155. var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
  21156. var coordDim = resultItem.coordDim;
  21157. coordDim == null && (
  21158. resultItem.coordDim = genName(extra, coordDimNameMap, opt.extraFromZero),
  21159. resultItem.coordDimIndex = 0,
  21160. resultItem.isExtraCoord = true
  21161. );
  21162. resultItem.name == null && (resultItem.name = genName(
  21163. resultItem.coordDim,
  21164. dataDimNameMap
  21165. ));
  21166. resultItem.type == null && guessOrdinal(data, resultDimIdx)
  21167. && (resultItem.type = 'ordinal');
  21168. }
  21169. return result;
  21170. function applyDim(resultItem, coordDim, coordDimIndex) {
  21171. if (OTHER_DIMS[coordDim]) {
  21172. resultItem.otherDims[coordDim] = coordDimIndex;
  21173. }
  21174. else {
  21175. resultItem.coordDim = coordDim;
  21176. resultItem.coordDimIndex = coordDimIndex;
  21177. coordDimNameMap.set(coordDim, true);
  21178. }
  21179. }
  21180. function genName(name, map$$1, fromZero) {
  21181. if (fromZero || map$$1.get(name) != null) {
  21182. var i = 0;
  21183. while (map$$1.get(name + i) != null) {
  21184. i++;
  21185. }
  21186. name += i;
  21187. }
  21188. map$$1.set(name, true);
  21189. return name;
  21190. }
  21191. }
  21192. // The rule should not be complex, otherwise user might not
  21193. // be able to known where the data is wrong.
  21194. var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) {
  21195. for (var i = 0, len = data.length; i < len; i++) {
  21196. var value = retrieveValue(data[i]);
  21197. if (!isArray(value)) {
  21198. return false;
  21199. }
  21200. var value = value[dimIndex];
  21201. // Consider usage convenience, '1', '2' will be treated as "number".
  21202. // `isFinit('')` get `true`.
  21203. if (value != null && isFinite(value) && value !== '') {
  21204. return false;
  21205. }
  21206. else if (isString$1(value) && value !== '-') {
  21207. return true;
  21208. }
  21209. }
  21210. return false;
  21211. };
  21212. function retrieveValue(o) {
  21213. return isArray(o) ? o : isObject(o) ? o.value: o;
  21214. }
  21215. function firstDataNotNull(data) {
  21216. var i = 0;
  21217. while (i < data.length && data[i] == null) {
  21218. i++;
  21219. }
  21220. return data[i];
  21221. }
  21222. function ifNeedCompleteOrdinalData(data) {
  21223. var sampleItem = firstDataNotNull(data);
  21224. return sampleItem != null
  21225. && !isArray(getDataItemValue(sampleItem));
  21226. }
  21227. /**
  21228. * Helper function to create a list from option data
  21229. */
  21230. function createListFromArray(data, seriesModel, ecModel) {
  21231. // If data is undefined
  21232. data = data || [];
  21233. if (__DEV__) {
  21234. if (!isArray(data)) {
  21235. throw new Error('Invalid data.');
  21236. }
  21237. }
  21238. var coordSysName = seriesModel.get('coordinateSystem');
  21239. var creator = creators[coordSysName];
  21240. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  21241. var completeDimOpt = {
  21242. encodeDef: seriesModel.get('encode'),
  21243. dimsDef: seriesModel.get('dimensions')
  21244. };
  21245. // FIXME
  21246. var axesInfo = creator && creator(data, seriesModel, ecModel, completeDimOpt);
  21247. var dimensions = axesInfo && axesInfo.dimensions;
  21248. if (!dimensions) {
  21249. // Get dimensions from registered coordinate system
  21250. dimensions = (registeredCoordSys && (
  21251. registeredCoordSys.getDimensionsInfo
  21252. ? registeredCoordSys.getDimensionsInfo()
  21253. : registeredCoordSys.dimensions.slice()
  21254. )) || ['x', 'y'];
  21255. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21256. }
  21257. var categoryIndex = axesInfo ? axesInfo.categoryIndex : -1;
  21258. var list = new List(dimensions, seriesModel);
  21259. var nameList = createNameList(axesInfo, data);
  21260. var categories = {};
  21261. var dimValueGetter = (categoryIndex >= 0 && ifNeedCompleteOrdinalData(data))
  21262. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  21263. // If any dataItem is like { value: 10 }
  21264. if (isDataItemOption(itemOpt)) {
  21265. list.hasItemOption = true;
  21266. }
  21267. // Use dataIndex as ordinal value in categoryAxis
  21268. return dimIndex === categoryIndex
  21269. ? dataIndex
  21270. : converDataValue(getDataItemValue(itemOpt), dimensions[dimIndex]);
  21271. }
  21272. : function (itemOpt, dimName, dataIndex, dimIndex) {
  21273. var value = getDataItemValue(itemOpt);
  21274. var val = converDataValue(value && value[dimIndex], dimensions[dimIndex]);
  21275. // If any dataItem is like { value: 10 }
  21276. if (isDataItemOption(itemOpt)) {
  21277. list.hasItemOption = true;
  21278. }
  21279. var categoryAxesModels = axesInfo && axesInfo.categoryAxesModels;
  21280. if (categoryAxesModels && categoryAxesModels[dimName]) {
  21281. // If given value is a category string
  21282. if (typeof val === 'string') {
  21283. // Lazy get categories
  21284. categories[dimName] = categories[dimName]
  21285. || categoryAxesModels[dimName].getCategories();
  21286. val = indexOf(categories[dimName], val);
  21287. if (val < 0 && !isNaN(val)) {
  21288. // In case some one write '1', '2' istead of 1, 2
  21289. val = +val;
  21290. }
  21291. }
  21292. }
  21293. return val;
  21294. };
  21295. list.hasItemOption = false;
  21296. list.initData(data, nameList, dimValueGetter);
  21297. return list;
  21298. }
  21299. function isStackable(axisType) {
  21300. return axisType !== 'category' && axisType !== 'time';
  21301. }
  21302. function getDimTypeByAxis(axisType) {
  21303. return axisType === 'category'
  21304. ? 'ordinal'
  21305. : axisType === 'time'
  21306. ? 'time'
  21307. : 'float';
  21308. }
  21309. /**
  21310. * Creaters for each coord system.
  21311. */
  21312. var creators = {
  21313. cartesian2d: function (data, seriesModel, ecModel, completeDimOpt) {
  21314. var axesModels = map(['xAxis', 'yAxis'], function (name) {
  21315. return ecModel.queryComponents({
  21316. mainType: name,
  21317. index: seriesModel.get(name + 'Index'),
  21318. id: seriesModel.get(name + 'Id')
  21319. })[0];
  21320. });
  21321. var xAxisModel = axesModels[0];
  21322. var yAxisModel = axesModels[1];
  21323. if (__DEV__) {
  21324. if (!xAxisModel) {
  21325. throw new Error('xAxis "' + retrieve(
  21326. seriesModel.get('xAxisIndex'),
  21327. seriesModel.get('xAxisId'),
  21328. 0
  21329. ) + '" not found');
  21330. }
  21331. if (!yAxisModel) {
  21332. throw new Error('yAxis "' + retrieve(
  21333. seriesModel.get('xAxisIndex'),
  21334. seriesModel.get('yAxisId'),
  21335. 0
  21336. ) + '" not found');
  21337. }
  21338. }
  21339. var xAxisType = xAxisModel.get('type');
  21340. var yAxisType = yAxisModel.get('type');
  21341. var dimensions = [
  21342. {
  21343. name: 'x',
  21344. type: getDimTypeByAxis(xAxisType),
  21345. stackable: isStackable(xAxisType)
  21346. },
  21347. {
  21348. name: 'y',
  21349. // If two category axes
  21350. type: getDimTypeByAxis(yAxisType),
  21351. stackable: isStackable(yAxisType)
  21352. }
  21353. ];
  21354. var isXAxisCateogry = xAxisType === 'category';
  21355. var isYAxisCategory = yAxisType === 'category';
  21356. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21357. var categoryAxesModels = {};
  21358. if (isXAxisCateogry) {
  21359. categoryAxesModels.x = xAxisModel;
  21360. }
  21361. if (isYAxisCategory) {
  21362. categoryAxesModels.y = yAxisModel;
  21363. }
  21364. return {
  21365. dimensions: dimensions,
  21366. categoryIndex: isXAxisCateogry ? 0 : (isYAxisCategory ? 1 : -1),
  21367. categoryAxesModels: categoryAxesModels
  21368. };
  21369. },
  21370. singleAxis: function (data, seriesModel, ecModel, completeDimOpt) {
  21371. var singleAxisModel = ecModel.queryComponents({
  21372. mainType: 'singleAxis',
  21373. index: seriesModel.get('singleAxisIndex'),
  21374. id: seriesModel.get('singleAxisId')
  21375. })[0];
  21376. if (__DEV__) {
  21377. if (!singleAxisModel) {
  21378. throw new Error('singleAxis should be specified.');
  21379. }
  21380. }
  21381. var singleAxisType = singleAxisModel.get('type');
  21382. var isCategory = singleAxisType === 'category';
  21383. var dimensions = [{
  21384. name: 'single',
  21385. type: getDimTypeByAxis(singleAxisType),
  21386. stackable: isStackable(singleAxisType)
  21387. }];
  21388. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21389. var categoryAxesModels = {};
  21390. if (isCategory) {
  21391. categoryAxesModels.single = singleAxisModel;
  21392. }
  21393. return {
  21394. dimensions: dimensions,
  21395. categoryIndex: isCategory ? 0 : -1,
  21396. categoryAxesModels: categoryAxesModels
  21397. };
  21398. },
  21399. polar: function (data, seriesModel, ecModel, completeDimOpt) {
  21400. var polarModel = ecModel.queryComponents({
  21401. mainType: 'polar',
  21402. index: seriesModel.get('polarIndex'),
  21403. id: seriesModel.get('polarId')
  21404. })[0];
  21405. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  21406. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  21407. if (__DEV__) {
  21408. if (!angleAxisModel) {
  21409. throw new Error('angleAxis option not found');
  21410. }
  21411. if (!radiusAxisModel) {
  21412. throw new Error('radiusAxis option not found');
  21413. }
  21414. }
  21415. var radiusAxisType = radiusAxisModel.get('type');
  21416. var angleAxisType = angleAxisModel.get('type');
  21417. var dimensions = [
  21418. {
  21419. name: 'radius',
  21420. type: getDimTypeByAxis(radiusAxisType),
  21421. stackable: isStackable(radiusAxisType)
  21422. },
  21423. {
  21424. name: 'angle',
  21425. type: getDimTypeByAxis(angleAxisType),
  21426. stackable: isStackable(angleAxisType)
  21427. }
  21428. ];
  21429. var isAngleAxisCateogry = angleAxisType === 'category';
  21430. var isRadiusAxisCateogry = radiusAxisType === 'category';
  21431. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21432. var categoryAxesModels = {};
  21433. if (isRadiusAxisCateogry) {
  21434. categoryAxesModels.radius = radiusAxisModel;
  21435. }
  21436. if (isAngleAxisCateogry) {
  21437. categoryAxesModels.angle = angleAxisModel;
  21438. }
  21439. return {
  21440. dimensions: dimensions,
  21441. categoryIndex: isAngleAxisCateogry ? 1 : (isRadiusAxisCateogry ? 0 : -1),
  21442. categoryAxesModels: categoryAxesModels
  21443. };
  21444. },
  21445. geo: function (data, seriesModel, ecModel, completeDimOpt) {
  21446. // TODO Region
  21447. // 多个散点图系列在同一个地区的时候
  21448. return {
  21449. dimensions: completeDimensions([
  21450. {name: 'lng'},
  21451. {name: 'lat'}
  21452. ], data, completeDimOpt)
  21453. };
  21454. }
  21455. };
  21456. function createNameList(result, data) {
  21457. var nameList = [];
  21458. var categoryDim = result && result.dimensions[result.categoryIndex];
  21459. var categoryAxisModel;
  21460. if (categoryDim) {
  21461. categoryAxisModel = result.categoryAxesModels[categoryDim.name];
  21462. }
  21463. if (categoryAxisModel) {
  21464. // FIXME Two category axis
  21465. var categories = categoryAxisModel.getCategories();
  21466. if (categories) {
  21467. var dataLen = data.length;
  21468. // Ordered data is given explicitly like
  21469. // [[3, 0.2], [1, 0.3], [2, 0.15]]
  21470. // or given scatter data,
  21471. // pick the category
  21472. if (isArray(data[0]) && data[0].length > 1) {
  21473. nameList = [];
  21474. for (var i = 0; i < dataLen; i++) {
  21475. nameList[i] = categories[data[i][result.categoryIndex || 0]];
  21476. }
  21477. }
  21478. else {
  21479. nameList = categories.slice(0);
  21480. }
  21481. }
  21482. }
  21483. return nameList;
  21484. }
  21485. /**
  21486. * // Scale class management
  21487. * @module echarts/scale/Scale
  21488. */
  21489. /**
  21490. * @param {Object} [setting]
  21491. */
  21492. function Scale(setting) {
  21493. this._setting = setting || {};
  21494. /**
  21495. * Extent
  21496. * @type {Array.<number>}
  21497. * @protected
  21498. */
  21499. this._extent = [Infinity, -Infinity];
  21500. /**
  21501. * Step is calculated in adjustExtent
  21502. * @type {Array.<number>}
  21503. * @protected
  21504. */
  21505. this._interval = 0;
  21506. this.init && this.init.apply(this, arguments);
  21507. }
  21508. /**
  21509. * Parse input val to valid inner number.
  21510. * @param {*} val
  21511. * @return {number}
  21512. */
  21513. Scale.prototype.parse = function (val) {
  21514. // Notice: This would be a trap here, If the implementation
  21515. // of this method depends on extent, and this method is used
  21516. // before extent set (like in dataZoom), it would be wrong.
  21517. // Nevertheless, parse does not depend on extent generally.
  21518. return val;
  21519. };
  21520. Scale.prototype.getSetting = function (name) {
  21521. return this._setting[name];
  21522. };
  21523. Scale.prototype.contain = function (val) {
  21524. var extent = this._extent;
  21525. return val >= extent[0] && val <= extent[1];
  21526. };
  21527. /**
  21528. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  21529. * @param {number} val
  21530. * @return {number}
  21531. */
  21532. Scale.prototype.normalize = function (val) {
  21533. var extent = this._extent;
  21534. if (extent[1] === extent[0]) {
  21535. return 0.5;
  21536. }
  21537. return (val - extent[0]) / (extent[1] - extent[0]);
  21538. };
  21539. /**
  21540. * Scale normalized value
  21541. * @param {number} val
  21542. * @return {number}
  21543. */
  21544. Scale.prototype.scale = function (val) {
  21545. var extent = this._extent;
  21546. return val * (extent[1] - extent[0]) + extent[0];
  21547. };
  21548. /**
  21549. * Set extent from data
  21550. * @param {Array.<number>} other
  21551. */
  21552. Scale.prototype.unionExtent = function (other) {
  21553. var extent = this._extent;
  21554. other[0] < extent[0] && (extent[0] = other[0]);
  21555. other[1] > extent[1] && (extent[1] = other[1]);
  21556. // not setExtent because in log axis it may transformed to power
  21557. // this.setExtent(extent[0], extent[1]);
  21558. };
  21559. /**
  21560. * Set extent from data
  21561. * @param {module:echarts/data/List} data
  21562. * @param {string} dim
  21563. */
  21564. Scale.prototype.unionExtentFromData = function (data, dim) {
  21565. this.unionExtent(data.getDataExtent(dim, true));
  21566. };
  21567. /**
  21568. * Get extent
  21569. * @return {Array.<number>}
  21570. */
  21571. Scale.prototype.getExtent = function () {
  21572. return this._extent.slice();
  21573. };
  21574. /**
  21575. * Set extent
  21576. * @param {number} start
  21577. * @param {number} end
  21578. */
  21579. Scale.prototype.setExtent = function (start, end) {
  21580. var thisExtent = this._extent;
  21581. if (!isNaN(start)) {
  21582. thisExtent[0] = start;
  21583. }
  21584. if (!isNaN(end)) {
  21585. thisExtent[1] = end;
  21586. }
  21587. };
  21588. /**
  21589. * @return {Array.<string>}
  21590. */
  21591. Scale.prototype.getTicksLabels = function () {
  21592. var labels = [];
  21593. var ticks = this.getTicks();
  21594. for (var i = 0; i < ticks.length; i++) {
  21595. labels.push(this.getLabel(ticks[i]));
  21596. }
  21597. return labels;
  21598. };
  21599. /**
  21600. * When axis extent depends on data and no data exists,
  21601. * axis ticks should not be drawn, which is named 'blank'.
  21602. */
  21603. Scale.prototype.isBlank = function () {
  21604. return this._isBlank;
  21605. },
  21606. /**
  21607. * When axis extent depends on data and no data exists,
  21608. * axis ticks should not be drawn, which is named 'blank'.
  21609. */
  21610. Scale.prototype.setBlank = function (isBlank) {
  21611. this._isBlank = isBlank;
  21612. };
  21613. enableClassExtend(Scale);
  21614. enableClassManagement(Scale, {
  21615. registerWhenExtend: true
  21616. });
  21617. /**
  21618. * Linear continuous scale
  21619. * @module echarts/coord/scale/Ordinal
  21620. *
  21621. * http://en.wikipedia.org/wiki/Level_of_measurement
  21622. */
  21623. // FIXME only one data
  21624. var scaleProto = Scale.prototype;
  21625. var OrdinalScale = Scale.extend({
  21626. type: 'ordinal',
  21627. init: function (data, extent) {
  21628. this._data = data;
  21629. this._extent = extent || [0, data.length - 1];
  21630. },
  21631. parse: function (val) {
  21632. return typeof val === 'string'
  21633. ? indexOf(this._data, val)
  21634. // val might be float.
  21635. : Math.round(val);
  21636. },
  21637. contain: function (rank) {
  21638. rank = this.parse(rank);
  21639. return scaleProto.contain.call(this, rank)
  21640. && this._data[rank] != null;
  21641. },
  21642. /**
  21643. * Normalize given rank or name to linear [0, 1]
  21644. * @param {number|string} [val]
  21645. * @return {number}
  21646. */
  21647. normalize: function (val) {
  21648. return scaleProto.normalize.call(this, this.parse(val));
  21649. },
  21650. scale: function (val) {
  21651. return Math.round(scaleProto.scale.call(this, val));
  21652. },
  21653. /**
  21654. * @return {Array}
  21655. */
  21656. getTicks: function () {
  21657. var ticks = [];
  21658. var extent = this._extent;
  21659. var rank = extent[0];
  21660. while (rank <= extent[1]) {
  21661. ticks.push(rank);
  21662. rank++;
  21663. }
  21664. return ticks;
  21665. },
  21666. /**
  21667. * Get item on rank n
  21668. * @param {number} n
  21669. * @return {string}
  21670. */
  21671. getLabel: function (n) {
  21672. return this._data[n];
  21673. },
  21674. /**
  21675. * @return {number}
  21676. */
  21677. count: function () {
  21678. return this._extent[1] - this._extent[0] + 1;
  21679. },
  21680. /**
  21681. * @override
  21682. */
  21683. unionExtentFromData: function (data, dim) {
  21684. this.unionExtent(data.getDataExtent(dim, false));
  21685. },
  21686. niceTicks: noop,
  21687. niceExtent: noop
  21688. });
  21689. /**
  21690. * @return {module:echarts/scale/Time}
  21691. */
  21692. OrdinalScale.create = function () {
  21693. return new OrdinalScale();
  21694. };
  21695. /**
  21696. * For testable.
  21697. */
  21698. var roundNumber$1 = round;
  21699. /**
  21700. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  21701. * Should be extent[0] < extent[1].
  21702. * @param {number} splitNumber splitNumber should be >= 1.
  21703. * @param {number} [minInterval]
  21704. * @param {number} [maxInterval]
  21705. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  21706. */
  21707. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  21708. var result = {};
  21709. var span = extent[1] - extent[0];
  21710. var interval = result.interval = nice(span / splitNumber, true);
  21711. if (minInterval != null && interval < minInterval) {
  21712. interval = result.interval = minInterval;
  21713. }
  21714. if (maxInterval != null && interval > maxInterval) {
  21715. interval = result.interval = maxInterval;
  21716. }
  21717. // Tow more digital for tick.
  21718. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  21719. // Niced extent inside original extent
  21720. var niceTickExtent = result.niceTickExtent = [
  21721. roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision),
  21722. roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)
  21723. ];
  21724. fixExtent(niceTickExtent, extent);
  21725. return result;
  21726. }
  21727. /**
  21728. * @param {number} interval
  21729. * @return {number} interval precision
  21730. */
  21731. function getIntervalPrecision(interval) {
  21732. // Tow more digital for tick.
  21733. return getPrecisionSafe(interval) + 2;
  21734. }
  21735. function clamp(niceTickExtent, idx, extent) {
  21736. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  21737. }
  21738. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  21739. function fixExtent(niceTickExtent, extent) {
  21740. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  21741. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  21742. clamp(niceTickExtent, 0, extent);
  21743. clamp(niceTickExtent, 1, extent);
  21744. if (niceTickExtent[0] > niceTickExtent[1]) {
  21745. niceTickExtent[0] = niceTickExtent[1];
  21746. }
  21747. }
  21748. function intervalScaleGetTicks(interval, extent, niceTickExtent, intervalPrecision) {
  21749. var ticks = [];
  21750. // If interval is 0, return [];
  21751. if (!interval) {
  21752. return ticks;
  21753. }
  21754. // Consider this case: using dataZoom toolbox, zoom and zoom.
  21755. var safeLimit = 10000;
  21756. if (extent[0] < niceTickExtent[0]) {
  21757. ticks.push(extent[0]);
  21758. }
  21759. var tick = niceTickExtent[0];
  21760. while (tick <= niceTickExtent[1]) {
  21761. ticks.push(tick);
  21762. // Avoid rounding error
  21763. tick = roundNumber$1(tick + interval, intervalPrecision);
  21764. if (tick === ticks[ticks.length - 1]) {
  21765. // Consider out of safe float point, e.g.,
  21766. // -3711126.9907707 + 2e-10 === -3711126.9907707
  21767. break;
  21768. }
  21769. if (ticks.length > safeLimit) {
  21770. return [];
  21771. }
  21772. }
  21773. // Consider this case: the last item of ticks is smaller
  21774. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  21775. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1])) {
  21776. ticks.push(extent[1]);
  21777. }
  21778. return ticks;
  21779. }
  21780. /**
  21781. * Interval scale
  21782. * @module echarts/scale/Interval
  21783. */
  21784. var roundNumber = round;
  21785. /**
  21786. * @alias module:echarts/coord/scale/Interval
  21787. * @constructor
  21788. */
  21789. var IntervalScale = Scale.extend({
  21790. type: 'interval',
  21791. _interval: 0,
  21792. _intervalPrecision: 2,
  21793. setExtent: function (start, end) {
  21794. var thisExtent = this._extent;
  21795. //start,end may be a Number like '25',so...
  21796. if (!isNaN(start)) {
  21797. thisExtent[0] = parseFloat(start);
  21798. }
  21799. if (!isNaN(end)) {
  21800. thisExtent[1] = parseFloat(end);
  21801. }
  21802. },
  21803. unionExtent: function (other) {
  21804. var extent = this._extent;
  21805. other[0] < extent[0] && (extent[0] = other[0]);
  21806. other[1] > extent[1] && (extent[1] = other[1]);
  21807. // unionExtent may called by it's sub classes
  21808. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  21809. },
  21810. /**
  21811. * Get interval
  21812. */
  21813. getInterval: function () {
  21814. return this._interval;
  21815. },
  21816. /**
  21817. * Set interval
  21818. */
  21819. setInterval: function (interval) {
  21820. this._interval = interval;
  21821. // Dropped auto calculated niceExtent and use user setted extent
  21822. // We assume user wan't to set both interval, min, max to get a better result
  21823. this._niceExtent = this._extent.slice();
  21824. this._intervalPrecision = getIntervalPrecision(interval);
  21825. },
  21826. /**
  21827. * @return {Array.<number>}
  21828. */
  21829. getTicks: function () {
  21830. return intervalScaleGetTicks(
  21831. this._interval, this._extent, this._niceExtent, this._intervalPrecision
  21832. );
  21833. },
  21834. /**
  21835. * @return {Array.<string>}
  21836. */
  21837. getTicksLabels: function () {
  21838. var labels = [];
  21839. var ticks = this.getTicks();
  21840. for (var i = 0; i < ticks.length; i++) {
  21841. labels.push(this.getLabel(ticks[i]));
  21842. }
  21843. return labels;
  21844. },
  21845. /**
  21846. * @param {number} data
  21847. * @param {Object} [opt]
  21848. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  21849. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  21850. * @return {string}
  21851. */
  21852. getLabel: function (data, opt) {
  21853. if (data == null) {
  21854. return '';
  21855. }
  21856. var precision = opt && opt.precision;
  21857. if (precision == null) {
  21858. precision = getPrecisionSafe(data) || 0;
  21859. }
  21860. else if (precision === 'auto') {
  21861. // Should be more precise then tick.
  21862. precision = this._intervalPrecision;
  21863. }
  21864. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  21865. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  21866. data = roundNumber(data, precision, true);
  21867. return addCommas(data);
  21868. },
  21869. /**
  21870. * Update interval and extent of intervals for nice ticks
  21871. *
  21872. * @param {number} [splitNumber = 5] Desired number of ticks
  21873. * @param {number} [minInterval]
  21874. * @param {number} [maxInterval]
  21875. */
  21876. niceTicks: function (splitNumber, minInterval, maxInterval) {
  21877. splitNumber = splitNumber || 5;
  21878. var extent = this._extent;
  21879. var span = extent[1] - extent[0];
  21880. if (!isFinite(span)) {
  21881. return;
  21882. }
  21883. // User may set axis min 0 and data are all negative
  21884. // FIXME If it needs to reverse ?
  21885. if (span < 0) {
  21886. span = -span;
  21887. extent.reverse();
  21888. }
  21889. var result = intervalScaleNiceTicks(
  21890. extent, splitNumber, minInterval, maxInterval
  21891. );
  21892. this._intervalPrecision = result.intervalPrecision;
  21893. this._interval = result.interval;
  21894. this._niceExtent = result.niceTickExtent;
  21895. },
  21896. /**
  21897. * Nice extent.
  21898. * @param {Object} opt
  21899. * @param {number} [opt.splitNumber = 5] Given approx tick number
  21900. * @param {boolean} [opt.fixMin=false]
  21901. * @param {boolean} [opt.fixMax=false]
  21902. * @param {boolean} [opt.minInterval]
  21903. * @param {boolean} [opt.maxInterval]
  21904. */
  21905. niceExtent: function (opt) {
  21906. var extent = this._extent;
  21907. // If extent start and end are same, expand them
  21908. if (extent[0] === extent[1]) {
  21909. if (extent[0] !== 0) {
  21910. // Expand extent
  21911. var expandSize = extent[0];
  21912. // In the fowllowing case
  21913. // Axis has been fixed max 100
  21914. // Plus data are all 100 and axis extent are [100, 100].
  21915. // Extend to the both side will cause expanded max is larger than fixed max.
  21916. // So only expand to the smaller side.
  21917. if (!opt.fixMax) {
  21918. extent[1] += expandSize / 2;
  21919. extent[0] -= expandSize / 2;
  21920. }
  21921. else {
  21922. extent[0] -= expandSize / 2;
  21923. }
  21924. }
  21925. else {
  21926. extent[1] = 1;
  21927. }
  21928. }
  21929. var span = extent[1] - extent[0];
  21930. // If there are no data and extent are [Infinity, -Infinity]
  21931. if (!isFinite(span)) {
  21932. extent[0] = 0;
  21933. extent[1] = 1;
  21934. }
  21935. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  21936. // var extent = this._extent;
  21937. var interval = this._interval;
  21938. if (!opt.fixMin) {
  21939. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  21940. }
  21941. if (!opt.fixMax) {
  21942. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  21943. }
  21944. }
  21945. });
  21946. /**
  21947. * @return {module:echarts/scale/Time}
  21948. */
  21949. IntervalScale.create = function () {
  21950. return new IntervalScale();
  21951. };
  21952. // [About UTC and local time zone]:
  21953. // In most cases, `number.parseDate` will treat input data string as local time
  21954. // (except time zone is specified in time string). And `format.formateTime` returns
  21955. // local time by default. option.useUTC is false by default. This design have
  21956. // concidered these common case:
  21957. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  21958. // in local time by default.
  21959. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  21960. // as its original time, without any time difference.
  21961. var intervalScaleProto = IntervalScale.prototype;
  21962. var mathCeil = Math.ceil;
  21963. var mathFloor = Math.floor;
  21964. var ONE_SECOND = 1000;
  21965. var ONE_MINUTE = ONE_SECOND * 60;
  21966. var ONE_HOUR = ONE_MINUTE * 60;
  21967. var ONE_DAY = ONE_HOUR * 24;
  21968. // FIXME 公用?
  21969. var bisect = function (a, x, lo, hi) {
  21970. while (lo < hi) {
  21971. var mid = lo + hi >>> 1;
  21972. if (a[mid][1] < x) {
  21973. lo = mid + 1;
  21974. }
  21975. else {
  21976. hi = mid;
  21977. }
  21978. }
  21979. return lo;
  21980. };
  21981. /**
  21982. * @alias module:echarts/coord/scale/Time
  21983. * @constructor
  21984. */
  21985. var TimeScale = IntervalScale.extend({
  21986. type: 'time',
  21987. /**
  21988. * @override
  21989. */
  21990. getLabel: function (val) {
  21991. var stepLvl = this._stepLvl;
  21992. var date = new Date(val);
  21993. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  21994. },
  21995. /**
  21996. * @override
  21997. */
  21998. niceExtent: function (opt) {
  21999. var extent = this._extent;
  22000. // If extent start and end are same, expand them
  22001. if (extent[0] === extent[1]) {
  22002. // Expand extent
  22003. extent[0] -= ONE_DAY;
  22004. extent[1] += ONE_DAY;
  22005. }
  22006. // If there are no data and extent are [Infinity, -Infinity]
  22007. if (extent[1] === -Infinity && extent[0] === Infinity) {
  22008. var d = new Date();
  22009. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  22010. extent[0] = extent[1] - ONE_DAY;
  22011. }
  22012. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  22013. // var extent = this._extent;
  22014. var interval = this._interval;
  22015. if (!opt.fixMin) {
  22016. extent[0] = round(mathFloor(extent[0] / interval) * interval);
  22017. }
  22018. if (!opt.fixMax) {
  22019. extent[1] = round(mathCeil(extent[1] / interval) * interval);
  22020. }
  22021. },
  22022. /**
  22023. * @override
  22024. */
  22025. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  22026. approxTickNum = approxTickNum || 10;
  22027. var extent = this._extent;
  22028. var span = extent[1] - extent[0];
  22029. var approxInterval = span / approxTickNum;
  22030. if (minInterval != null && approxInterval < minInterval) {
  22031. approxInterval = minInterval;
  22032. }
  22033. if (maxInterval != null && approxInterval > maxInterval) {
  22034. approxInterval = maxInterval;
  22035. }
  22036. var scaleLevelsLen = scaleLevels.length;
  22037. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  22038. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  22039. var interval = level[1];
  22040. // Same with interval scale if span is much larger than 1 year
  22041. if (level[0] === 'year') {
  22042. var yearSpan = span / interval;
  22043. // From "Nice Numbers for Graph Labels" of Graphic Gems
  22044. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  22045. var yearStep = nice(yearSpan / approxTickNum, true);
  22046. interval *= yearStep;
  22047. }
  22048. var timezoneOffset = this.getSetting('useUTC')
  22049. ? 0 : (new Date(+extent[0] || +extent[1])).getTimezoneOffset() * 60 * 1000;
  22050. var niceExtent = [
  22051. Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
  22052. Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)
  22053. ];
  22054. fixExtent(niceExtent, extent);
  22055. this._stepLvl = level;
  22056. // Interval will be used in getTicks
  22057. this._interval = interval;
  22058. this._niceExtent = niceExtent;
  22059. },
  22060. parse: function (val) {
  22061. // val might be float.
  22062. return +parseDate(val);
  22063. }
  22064. });
  22065. each$1(['contain', 'normalize'], function (methodName) {
  22066. TimeScale.prototype[methodName] = function (val) {
  22067. return intervalScaleProto[methodName].call(this, this.parse(val));
  22068. };
  22069. });
  22070. // Steps from d3
  22071. var scaleLevels = [
  22072. // Format interval
  22073. ['hh:mm:ss', ONE_SECOND], // 1s
  22074. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  22075. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  22076. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  22077. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  22078. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  22079. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  22080. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  22081. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  22082. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  22083. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  22084. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  22085. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  22086. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  22087. ['MM-dd\nyyyy', ONE_DAY], // 1d
  22088. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  22089. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  22090. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  22091. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  22092. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  22093. ['week', ONE_DAY * 7], // 7d
  22094. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  22095. ['week', ONE_DAY * 14], // 2w
  22096. ['week', ONE_DAY * 21], // 3w
  22097. ['month', ONE_DAY * 31], // 1M
  22098. ['week', ONE_DAY * 42], // 6w
  22099. ['month', ONE_DAY * 62], // 2M
  22100. ['week', ONE_DAY * 42], // 10w
  22101. ['quarter', ONE_DAY * 380 / 4], // 3M
  22102. ['month', ONE_DAY * 31 * 4], // 4M
  22103. ['month', ONE_DAY * 31 * 5], // 5M
  22104. ['half-year', ONE_DAY * 380 / 2], // 6M
  22105. ['month', ONE_DAY * 31 * 8], // 8M
  22106. ['month', ONE_DAY * 31 * 10], // 10M
  22107. ['year', ONE_DAY * 380] // 1Y
  22108. ];
  22109. /**
  22110. * @param {module:echarts/model/Model}
  22111. * @return {module:echarts/scale/Time}
  22112. */
  22113. TimeScale.create = function (model) {
  22114. return new TimeScale({useUTC: model.ecModel.get('useUTC')});
  22115. };
  22116. /**
  22117. * Log scale
  22118. * @module echarts/scale/Log
  22119. */
  22120. // Use some method of IntervalScale
  22121. var scaleProto$1 = Scale.prototype;
  22122. var intervalScaleProto$1 = IntervalScale.prototype;
  22123. var getPrecisionSafe$1 = getPrecisionSafe;
  22124. var roundingErrorFix = round;
  22125. var mathFloor$1 = Math.floor;
  22126. var mathCeil$1 = Math.ceil;
  22127. var mathPow$1 = Math.pow;
  22128. var mathLog = Math.log;
  22129. var LogScale = Scale.extend({
  22130. type: 'log',
  22131. base: 10,
  22132. $constructor: function () {
  22133. Scale.apply(this, arguments);
  22134. this._originalScale = new IntervalScale();
  22135. },
  22136. /**
  22137. * @return {Array.<number>}
  22138. */
  22139. getTicks: function () {
  22140. var originalScale = this._originalScale;
  22141. var extent = this._extent;
  22142. var originalExtent = originalScale.getExtent();
  22143. return map(intervalScaleProto$1.getTicks.call(this), function (val) {
  22144. var powVal = round(mathPow$1(this.base, val));
  22145. // Fix #4158
  22146. powVal = (val === extent[0] && originalScale.__fixMin)
  22147. ? fixRoundingError(powVal, originalExtent[0])
  22148. : powVal;
  22149. powVal = (val === extent[1] && originalScale.__fixMax)
  22150. ? fixRoundingError(powVal, originalExtent[1])
  22151. : powVal;
  22152. return powVal;
  22153. }, this);
  22154. },
  22155. /**
  22156. * @param {number} val
  22157. * @return {string}
  22158. */
  22159. getLabel: intervalScaleProto$1.getLabel,
  22160. /**
  22161. * @param {number} val
  22162. * @return {number}
  22163. */
  22164. scale: function (val) {
  22165. val = scaleProto$1.scale.call(this, val);
  22166. return mathPow$1(this.base, val);
  22167. },
  22168. /**
  22169. * @param {number} start
  22170. * @param {number} end
  22171. */
  22172. setExtent: function (start, end) {
  22173. var base = this.base;
  22174. start = mathLog(start) / mathLog(base);
  22175. end = mathLog(end) / mathLog(base);
  22176. intervalScaleProto$1.setExtent.call(this, start, end);
  22177. },
  22178. /**
  22179. * @return {number} end
  22180. */
  22181. getExtent: function () {
  22182. var base = this.base;
  22183. var extent = scaleProto$1.getExtent.call(this);
  22184. extent[0] = mathPow$1(base, extent[0]);
  22185. extent[1] = mathPow$1(base, extent[1]);
  22186. // Fix #4158
  22187. var originalScale = this._originalScale;
  22188. var originalExtent = originalScale.getExtent();
  22189. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  22190. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  22191. return extent;
  22192. },
  22193. /**
  22194. * @param {Array.<number>} extent
  22195. */
  22196. unionExtent: function (extent) {
  22197. this._originalScale.unionExtent(extent);
  22198. var base = this.base;
  22199. extent[0] = mathLog(extent[0]) / mathLog(base);
  22200. extent[1] = mathLog(extent[1]) / mathLog(base);
  22201. scaleProto$1.unionExtent.call(this, extent);
  22202. },
  22203. /**
  22204. * @override
  22205. */
  22206. unionExtentFromData: function (data, dim) {
  22207. this.unionExtent(data.getDataExtent(dim, true, function (val) {
  22208. return val > 0;
  22209. }));
  22210. },
  22211. /**
  22212. * Update interval and extent of intervals for nice ticks
  22213. * @param {number} [approxTickNum = 10] Given approx tick number
  22214. */
  22215. niceTicks: function (approxTickNum) {
  22216. approxTickNum = approxTickNum || 10;
  22217. var extent = this._extent;
  22218. var span = extent[1] - extent[0];
  22219. if (span === Infinity || span <= 0) {
  22220. return;
  22221. }
  22222. var interval = quantity(span);
  22223. var err = approxTickNum / span * interval;
  22224. // Filter ticks to get closer to the desired count.
  22225. if (err <= 0.5) {
  22226. interval *= 10;
  22227. }
  22228. // Interval should be integer
  22229. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  22230. interval *= 10;
  22231. }
  22232. var niceExtent = [
  22233. round(mathCeil$1(extent[0] / interval) * interval),
  22234. round(mathFloor$1(extent[1] / interval) * interval)
  22235. ];
  22236. this._interval = interval;
  22237. this._niceExtent = niceExtent;
  22238. },
  22239. /**
  22240. * Nice extent.
  22241. * @override
  22242. */
  22243. niceExtent: function (opt) {
  22244. intervalScaleProto$1.niceExtent.call(this, opt);
  22245. var originalScale = this._originalScale;
  22246. originalScale.__fixMin = opt.fixMin;
  22247. originalScale.__fixMax = opt.fixMax;
  22248. }
  22249. });
  22250. each$1(['contain', 'normalize'], function (methodName) {
  22251. LogScale.prototype[methodName] = function (val) {
  22252. val = mathLog(val) / mathLog(this.base);
  22253. return scaleProto$1[methodName].call(this, val);
  22254. };
  22255. });
  22256. LogScale.create = function () {
  22257. return new LogScale();
  22258. };
  22259. function fixRoundingError(val, originalVal) {
  22260. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  22261. }
  22262. /**
  22263. * Get axis scale extent before niced.
  22264. * Item of returned array can only be number (including Infinity and NaN).
  22265. */
  22266. function getScaleExtent(scale, model) {
  22267. var scaleType = scale.type;
  22268. var min = model.getMin();
  22269. var max = model.getMax();
  22270. var fixMin = min != null;
  22271. var fixMax = max != null;
  22272. var originalExtent = scale.getExtent();
  22273. var axisDataLen;
  22274. var boundaryGap;
  22275. var span;
  22276. if (scaleType === 'ordinal') {
  22277. axisDataLen = (model.get('data') || []).length;
  22278. }
  22279. else {
  22280. boundaryGap = model.get('boundaryGap');
  22281. if (!isArray(boundaryGap)) {
  22282. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  22283. }
  22284. if (typeof boundaryGap[0] === 'boolean') {
  22285. if (__DEV__) {
  22286. console.warn('Boolean type for boundaryGap is only '
  22287. + 'allowed for ordinal axis. Please use string in '
  22288. + 'percentage instead, e.g., "20%". Currently, '
  22289. + 'boundaryGap is set to be 0.');
  22290. }
  22291. boundaryGap = [0, 0];
  22292. }
  22293. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  22294. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  22295. span = (originalExtent[1] - originalExtent[0])
  22296. || Math.abs(originalExtent[0]);
  22297. }
  22298. // Notice: When min/max is not set (that is, when there are null/undefined,
  22299. // which is the most common case), these cases should be ensured:
  22300. // (1) For 'ordinal', show all axis.data.
  22301. // (2) For others:
  22302. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  22303. // disabled).
  22304. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  22305. // be the result that originalExtent enlarged by boundaryGap.
  22306. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  22307. // FIXME
  22308. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  22309. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  22310. // that the results processed by boundaryGap are positive/negative?
  22311. if (min == null) {
  22312. min = scaleType === 'ordinal'
  22313. ? (axisDataLen ? 0 : NaN)
  22314. : originalExtent[0] - boundaryGap[0] * span;
  22315. }
  22316. if (max == null) {
  22317. max = scaleType === 'ordinal'
  22318. ? (axisDataLen ? axisDataLen - 1 : NaN)
  22319. : originalExtent[1] + boundaryGap[1] * span;
  22320. }
  22321. if (min === 'dataMin') {
  22322. min = originalExtent[0];
  22323. }
  22324. else if (typeof min === 'function') {
  22325. min = min({
  22326. min: originalExtent[0],
  22327. max: originalExtent[1]
  22328. });
  22329. }
  22330. if (max === 'dataMax') {
  22331. max = originalExtent[1];
  22332. }
  22333. else if (typeof max === 'function') {
  22334. max = max({
  22335. min: originalExtent[0],
  22336. max: originalExtent[1]
  22337. });
  22338. }
  22339. (min == null || !isFinite(min)) && (min = NaN);
  22340. (max == null || !isFinite(max)) && (max = NaN);
  22341. scale.setBlank(eqNaN(min) || eqNaN(max));
  22342. // Evaluate if axis needs cross zero
  22343. if (model.getNeedCrossZero()) {
  22344. // Axis is over zero and min is not set
  22345. if (min > 0 && max > 0 && !fixMin) {
  22346. min = 0;
  22347. }
  22348. // Axis is under zero and max is not set
  22349. if (min < 0 && max < 0 && !fixMax) {
  22350. max = 0;
  22351. }
  22352. }
  22353. return [min, max];
  22354. }
  22355. function niceScaleExtent(scale, model) {
  22356. var extent = getScaleExtent(scale, model);
  22357. var fixMin = model.getMin() != null;
  22358. var fixMax = model.getMax() != null;
  22359. var splitNumber = model.get('splitNumber');
  22360. if (scale.type === 'log') {
  22361. scale.base = model.get('logBase');
  22362. }
  22363. var scaleType = scale.type;
  22364. scale.setExtent(extent[0], extent[1]);
  22365. scale.niceExtent({
  22366. splitNumber: splitNumber,
  22367. fixMin: fixMin,
  22368. fixMax: fixMax,
  22369. minInterval: (scaleType === 'interval' || scaleType === 'time')
  22370. ? model.get('minInterval') : null,
  22371. maxInterval: (scaleType === 'interval' || scaleType === 'time')
  22372. ? model.get('maxInterval') : null
  22373. });
  22374. // If some one specified the min, max. And the default calculated interval
  22375. // is not good enough. He can specify the interval. It is often appeared
  22376. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  22377. // to be 60.
  22378. // FIXME
  22379. var interval = model.get('interval');
  22380. if (interval != null) {
  22381. scale.setInterval && scale.setInterval(interval);
  22382. }
  22383. }
  22384. /**
  22385. * @param {module:echarts/model/Model} model
  22386. * @param {string} [axisType] Default retrieve from model.type
  22387. * @return {module:echarts/scale/*}
  22388. */
  22389. function createScaleByModel(model, axisType) {
  22390. axisType = axisType || model.get('type');
  22391. if (axisType) {
  22392. switch (axisType) {
  22393. // Buildin scale
  22394. case 'category':
  22395. return new OrdinalScale(
  22396. model.getCategories(), [Infinity, -Infinity]
  22397. );
  22398. case 'value':
  22399. return new IntervalScale();
  22400. // Extended scale, like time and log
  22401. default:
  22402. return (Scale.getClass(axisType) || IntervalScale).create(model);
  22403. }
  22404. }
  22405. }
  22406. /**
  22407. * Check if the axis corss 0
  22408. */
  22409. function ifAxisCrossZero(axis) {
  22410. var dataExtent = axis.scale.getExtent();
  22411. var min = dataExtent[0];
  22412. var max = dataExtent[1];
  22413. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  22414. }
  22415. /**
  22416. * @param {Array.<number>} tickCoords In axis self coordinate.
  22417. * @param {Array.<string>} labels
  22418. * @param {string} font
  22419. * @param {number} axisRotate 0: towards right horizontally, clock-wise is negative.
  22420. * @param {number} [labelRotate=0] 0: towards right horizontally, clock-wise is negative.
  22421. * @return {number}
  22422. */
  22423. function getAxisLabelInterval(tickCoords, labels, font, axisRotate, labelRotate) {
  22424. var textSpaceTakenRect;
  22425. var autoLabelInterval = 0;
  22426. var accumulatedLabelInterval = 0;
  22427. var rotation = (axisRotate - labelRotate) / 180 * Math.PI;
  22428. var step = 1;
  22429. if (labels.length > 40) {
  22430. // Simple optimization for large amount of labels
  22431. step = Math.floor(labels.length / 40);
  22432. }
  22433. for (var i = 0; i < tickCoords.length; i += step) {
  22434. var tickCoord = tickCoords[i];
  22435. // Not precise, do not consider align and vertical align
  22436. // and each distance from axis line yet.
  22437. var rect = getBoundingRect(
  22438. labels[i], font, 'center', 'top'
  22439. );
  22440. rect.x += tickCoord * Math.cos(rotation);
  22441. rect.y += tickCoord * Math.sin(rotation);
  22442. // Magic number
  22443. rect.width *= 1.3;
  22444. rect.height *= 1.3;
  22445. if (!textSpaceTakenRect) {
  22446. textSpaceTakenRect = rect.clone();
  22447. }
  22448. // There is no space for current label;
  22449. else if (textSpaceTakenRect.intersect(rect)) {
  22450. accumulatedLabelInterval++;
  22451. autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
  22452. }
  22453. else {
  22454. textSpaceTakenRect.union(rect);
  22455. // Reset
  22456. accumulatedLabelInterval = 0;
  22457. }
  22458. }
  22459. if (autoLabelInterval === 0 && step > 1) {
  22460. return step;
  22461. }
  22462. return (autoLabelInterval + 1) * step - 1;
  22463. }
  22464. /**
  22465. * @param {Object} axis
  22466. * @param {Function} labelFormatter
  22467. * @return {Array.<string>}
  22468. */
  22469. function getFormattedLabels(axis, labelFormatter) {
  22470. var scale = axis.scale;
  22471. var labels = scale.getTicksLabels();
  22472. var ticks = scale.getTicks();
  22473. if (typeof labelFormatter === 'string') {
  22474. labelFormatter = (function (tpl) {
  22475. return function (val) {
  22476. return tpl.replace('{value}', val != null ? val : '');
  22477. };
  22478. })(labelFormatter);
  22479. // Consider empty array
  22480. return map(labels, labelFormatter);
  22481. }
  22482. else if (typeof labelFormatter === 'function') {
  22483. return map(ticks, function (tick, idx) {
  22484. return labelFormatter(
  22485. getAxisRawValue(axis, tick),
  22486. idx
  22487. );
  22488. }, this);
  22489. }
  22490. else {
  22491. return labels;
  22492. }
  22493. }
  22494. function getAxisRawValue(axis, value) {
  22495. // In category axis with data zoom, tick is not the original
  22496. // index of axis.data. So tick should not be exposed to user
  22497. // in category axis.
  22498. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  22499. }
  22500. function getName(obj) {
  22501. if (isObject(obj) && obj.value != null) {
  22502. return obj.value;
  22503. }
  22504. else {
  22505. return obj + '';
  22506. }
  22507. }
  22508. var axisModelCommonMixin = {
  22509. /**
  22510. * Format labels
  22511. * @return {Array.<string>}
  22512. */
  22513. getFormattedLabels: function () {
  22514. return getFormattedLabels(
  22515. this.axis,
  22516. this.get('axisLabel.formatter')
  22517. );
  22518. },
  22519. /**
  22520. * Get categories
  22521. */
  22522. getCategories: function () {
  22523. return this.get('type') === 'category'
  22524. && map(this.get('data'), getName);
  22525. },
  22526. /**
  22527. * @param {boolean} origin
  22528. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  22529. */
  22530. getMin: function (origin) {
  22531. var option = this.option;
  22532. var min = (!origin && option.rangeStart != null)
  22533. ? option.rangeStart : option.min;
  22534. if (this.axis
  22535. && min != null
  22536. && min !== 'dataMin'
  22537. && typeof min !== 'function'
  22538. && !eqNaN(min)
  22539. ) {
  22540. min = this.axis.scale.parse(min);
  22541. }
  22542. return min;
  22543. },
  22544. /**
  22545. * @param {boolean} origin
  22546. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  22547. */
  22548. getMax: function (origin) {
  22549. var option = this.option;
  22550. var max = (!origin && option.rangeEnd != null)
  22551. ? option.rangeEnd : option.max;
  22552. if (this.axis
  22553. && max != null
  22554. && max !== 'dataMax'
  22555. && typeof max !== 'function'
  22556. && !eqNaN(max)
  22557. ) {
  22558. max = this.axis.scale.parse(max);
  22559. }
  22560. return max;
  22561. },
  22562. /**
  22563. * @return {boolean}
  22564. */
  22565. getNeedCrossZero: function () {
  22566. var option = this.option;
  22567. return (option.rangeStart != null || option.rangeEnd != null)
  22568. ? false : !option.scale;
  22569. },
  22570. /**
  22571. * Should be implemented by each axis model if necessary.
  22572. * @return {module:echarts/model/Component} coordinate system model
  22573. */
  22574. getCoordSysModel: noop,
  22575. /**
  22576. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  22577. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  22578. */
  22579. setRange: function (rangeStart, rangeEnd) {
  22580. this.option.rangeStart = rangeStart;
  22581. this.option.rangeEnd = rangeEnd;
  22582. },
  22583. /**
  22584. * Reset range
  22585. */
  22586. resetRange: function () {
  22587. // rangeStart and rangeEnd is readonly.
  22588. this.option.rangeStart = this.option.rangeEnd = null;
  22589. }
  22590. };
  22591. // Symbol factory
  22592. /**
  22593. * Triangle shape
  22594. * @inner
  22595. */
  22596. var Triangle = extendShape({
  22597. type: 'triangle',
  22598. shape: {
  22599. cx: 0,
  22600. cy: 0,
  22601. width: 0,
  22602. height: 0
  22603. },
  22604. buildPath: function (path, shape) {
  22605. var cx = shape.cx;
  22606. var cy = shape.cy;
  22607. var width = shape.width / 2;
  22608. var height = shape.height / 2;
  22609. path.moveTo(cx, cy - height);
  22610. path.lineTo(cx + width, cy + height);
  22611. path.lineTo(cx - width, cy + height);
  22612. path.closePath();
  22613. }
  22614. });
  22615. /**
  22616. * Diamond shape
  22617. * @inner
  22618. */
  22619. var Diamond = extendShape({
  22620. type: 'diamond',
  22621. shape: {
  22622. cx: 0,
  22623. cy: 0,
  22624. width: 0,
  22625. height: 0
  22626. },
  22627. buildPath: function (path, shape) {
  22628. var cx = shape.cx;
  22629. var cy = shape.cy;
  22630. var width = shape.width / 2;
  22631. var height = shape.height / 2;
  22632. path.moveTo(cx, cy - height);
  22633. path.lineTo(cx + width, cy);
  22634. path.lineTo(cx, cy + height);
  22635. path.lineTo(cx - width, cy);
  22636. path.closePath();
  22637. }
  22638. });
  22639. /**
  22640. * Pin shape
  22641. * @inner
  22642. */
  22643. var Pin = extendShape({
  22644. type: 'pin',
  22645. shape: {
  22646. // x, y on the cusp
  22647. x: 0,
  22648. y: 0,
  22649. width: 0,
  22650. height: 0
  22651. },
  22652. buildPath: function (path, shape) {
  22653. var x = shape.x;
  22654. var y = shape.y;
  22655. var w = shape.width / 5 * 3;
  22656. // Height must be larger than width
  22657. var h = Math.max(w, shape.height);
  22658. var r = w / 2;
  22659. // Dist on y with tangent point and circle center
  22660. var dy = r * r / (h - r);
  22661. var cy = y - h + r + dy;
  22662. var angle = Math.asin(dy / r);
  22663. // Dist on x with tangent point and circle center
  22664. var dx = Math.cos(angle) * r;
  22665. var tanX = Math.sin(angle);
  22666. var tanY = Math.cos(angle);
  22667. var cpLen = r * 0.6;
  22668. var cpLen2 = r * 0.7;
  22669. path.moveTo(x - dx, cy + dy);
  22670. path.arc(
  22671. x, cy, r,
  22672. Math.PI - angle,
  22673. Math.PI * 2 + angle
  22674. );
  22675. path.bezierCurveTo(
  22676. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  22677. x, y - cpLen2,
  22678. x, y
  22679. );
  22680. path.bezierCurveTo(
  22681. x, y - cpLen2,
  22682. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  22683. x - dx, cy + dy
  22684. );
  22685. path.closePath();
  22686. }
  22687. });
  22688. /**
  22689. * Arrow shape
  22690. * @inner
  22691. */
  22692. var Arrow = extendShape({
  22693. type: 'arrow',
  22694. shape: {
  22695. x: 0,
  22696. y: 0,
  22697. width: 0,
  22698. height: 0
  22699. },
  22700. buildPath: function (ctx, shape) {
  22701. var height = shape.height;
  22702. var width = shape.width;
  22703. var x = shape.x;
  22704. var y = shape.y;
  22705. var dx = width / 3 * 2;
  22706. ctx.moveTo(x, y);
  22707. ctx.lineTo(x + dx, y + height);
  22708. ctx.lineTo(x, y + height / 4 * 3);
  22709. ctx.lineTo(x - dx, y + height);
  22710. ctx.lineTo(x, y);
  22711. ctx.closePath();
  22712. }
  22713. });
  22714. /**
  22715. * Map of path contructors
  22716. * @type {Object.<string, module:zrender/graphic/Path>}
  22717. */
  22718. var symbolCtors = {
  22719. line: Line,
  22720. rect: Rect,
  22721. roundRect: Rect,
  22722. square: Rect,
  22723. circle: Circle,
  22724. diamond: Diamond,
  22725. pin: Pin,
  22726. arrow: Arrow,
  22727. triangle: Triangle
  22728. };
  22729. var symbolShapeMakers = {
  22730. line: function (x, y, w, h, shape) {
  22731. // FIXME
  22732. shape.x1 = x;
  22733. shape.y1 = y + h / 2;
  22734. shape.x2 = x + w;
  22735. shape.y2 = y + h / 2;
  22736. },
  22737. rect: function (x, y, w, h, shape) {
  22738. shape.x = x;
  22739. shape.y = y;
  22740. shape.width = w;
  22741. shape.height = h;
  22742. },
  22743. roundRect: function (x, y, w, h, shape) {
  22744. shape.x = x;
  22745. shape.y = y;
  22746. shape.width = w;
  22747. shape.height = h;
  22748. shape.r = Math.min(w, h) / 4;
  22749. },
  22750. square: function (x, y, w, h, shape) {
  22751. var size = Math.min(w, h);
  22752. shape.x = x;
  22753. shape.y = y;
  22754. shape.width = size;
  22755. shape.height = size;
  22756. },
  22757. circle: function (x, y, w, h, shape) {
  22758. // Put circle in the center of square
  22759. shape.cx = x + w / 2;
  22760. shape.cy = y + h / 2;
  22761. shape.r = Math.min(w, h) / 2;
  22762. },
  22763. diamond: function (x, y, w, h, shape) {
  22764. shape.cx = x + w / 2;
  22765. shape.cy = y + h / 2;
  22766. shape.width = w;
  22767. shape.height = h;
  22768. },
  22769. pin: function (x, y, w, h, shape) {
  22770. shape.x = x + w / 2;
  22771. shape.y = y + h / 2;
  22772. shape.width = w;
  22773. shape.height = h;
  22774. },
  22775. arrow: function (x, y, w, h, shape) {
  22776. shape.x = x + w / 2;
  22777. shape.y = y + h / 2;
  22778. shape.width = w;
  22779. shape.height = h;
  22780. },
  22781. triangle: function (x, y, w, h, shape) {
  22782. shape.cx = x + w / 2;
  22783. shape.cy = y + h / 2;
  22784. shape.width = w;
  22785. shape.height = h;
  22786. }
  22787. };
  22788. var symbolBuildProxies = {};
  22789. each$1(symbolCtors, function (Ctor, name) {
  22790. symbolBuildProxies[name] = new Ctor();
  22791. });
  22792. var SymbolClz = extendShape({
  22793. type: 'symbol',
  22794. shape: {
  22795. symbolType: '',
  22796. x: 0,
  22797. y: 0,
  22798. width: 0,
  22799. height: 0
  22800. },
  22801. beforeBrush: function () {
  22802. var style = this.style;
  22803. var shape = this.shape;
  22804. // FIXME
  22805. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  22806. style.textPosition = ['50%', '40%'];
  22807. style.textAlign = 'center';
  22808. style.textVerticalAlign = 'middle';
  22809. }
  22810. },
  22811. buildPath: function (ctx, shape, inBundle) {
  22812. var symbolType = shape.symbolType;
  22813. var proxySymbol = symbolBuildProxies[symbolType];
  22814. if (shape.symbolType !== 'none') {
  22815. if (!proxySymbol) {
  22816. // Default rect
  22817. symbolType = 'rect';
  22818. proxySymbol = symbolBuildProxies[symbolType];
  22819. }
  22820. symbolShapeMakers[symbolType](
  22821. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  22822. );
  22823. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  22824. }
  22825. }
  22826. });
  22827. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  22828. function symbolPathSetColor(color, innerColor) {
  22829. if (this.type !== 'image') {
  22830. var symbolStyle = this.style;
  22831. var symbolShape = this.shape;
  22832. if (symbolShape && symbolShape.symbolType === 'line') {
  22833. symbolStyle.stroke = color;
  22834. }
  22835. else if (this.__isEmptyBrush) {
  22836. symbolStyle.stroke = color;
  22837. symbolStyle.fill = innerColor || '#fff';
  22838. }
  22839. else {
  22840. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  22841. symbolStyle.fill && (symbolStyle.fill = color);
  22842. symbolStyle.stroke && (symbolStyle.stroke = color);
  22843. }
  22844. this.dirty(false);
  22845. }
  22846. }
  22847. /**
  22848. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  22849. * @param {string} symbolType
  22850. * @param {number} x
  22851. * @param {number} y
  22852. * @param {number} w
  22853. * @param {number} h
  22854. * @param {string} color
  22855. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  22856. * for path and image only.
  22857. */
  22858. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  22859. // TODO Support image object, DynamicImage.
  22860. var isEmpty = symbolType.indexOf('empty') === 0;
  22861. if (isEmpty) {
  22862. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  22863. }
  22864. var symbolPath;
  22865. if (symbolType.indexOf('image://') === 0) {
  22866. symbolPath = makeImage(
  22867. symbolType.slice(8),
  22868. new BoundingRect(x, y, w, h),
  22869. keepAspect ? 'center' : 'cover'
  22870. );
  22871. }
  22872. else if (symbolType.indexOf('path://') === 0) {
  22873. symbolPath = makePath(
  22874. symbolType.slice(7),
  22875. {},
  22876. new BoundingRect(x, y, w, h),
  22877. keepAspect ? 'center' : 'cover'
  22878. );
  22879. }
  22880. else {
  22881. symbolPath = new SymbolClz({
  22882. shape: {
  22883. symbolType: symbolType,
  22884. x: x,
  22885. y: y,
  22886. width: w,
  22887. height: h
  22888. }
  22889. });
  22890. }
  22891. symbolPath.__isEmptyBrush = isEmpty;
  22892. symbolPath.setColor = symbolPathSetColor;
  22893. symbolPath.setColor(color);
  22894. return symbolPath;
  22895. }
  22896. /**
  22897. * Create a muti dimension List structure from seriesModel.
  22898. * @param {module:echarts/model/Model} seriesModel
  22899. * @return {module:echarts/data/List} list
  22900. */
  22901. function createList(seriesModel) {
  22902. var data = seriesModel.get('data');
  22903. return createListFromArray(data, seriesModel, seriesModel.ecModel);
  22904. }
  22905. /**
  22906. * Create scale
  22907. * @param {Array.<number>} dataExtent
  22908. * @param {Object|module:echarts/Model} option
  22909. */
  22910. function createScale(dataExtent, option) {
  22911. var axisModel = option;
  22912. if (!(option instanceof Model)) {
  22913. axisModel = new Model(option);
  22914. mixin(axisModel, axisModelCommonMixin);
  22915. }
  22916. var scale = createScaleByModel(axisModel);
  22917. scale.setExtent(dataExtent[0], dataExtent[1]);
  22918. niceScaleExtent(scale, axisModel);
  22919. return scale;
  22920. }
  22921. /**
  22922. * Mixin common methods to axis model,
  22923. *
  22924. * Inlcude methods
  22925. * `getFormattedLabels() => Array.<string>`
  22926. * `getCategories() => Array.<string>`
  22927. * `getMin(origin: boolean) => number`
  22928. * `getMax(origin: boolean) => number`
  22929. * `getNeedCrossZero() => boolean`
  22930. * `setRange(start: number, end: number)`
  22931. * `resetRange()`
  22932. */
  22933. function mixinAxisModelCommonMethods(Model$$1) {
  22934. mixin(Model$$1, axisModelCommonMixin);
  22935. }
  22936. var helper = (Object.freeze || Object)({
  22937. createList: createList,
  22938. createScale: createScale,
  22939. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  22940. completeDimensions: completeDimensions,
  22941. createSymbol: createSymbol
  22942. });
  22943. var linearMap$1 = linearMap;
  22944. function fixExtentWithBands(extent, nTick) {
  22945. var size = extent[1] - extent[0];
  22946. var len = nTick;
  22947. var margin = size / len / 2;
  22948. extent[0] += margin;
  22949. extent[1] -= margin;
  22950. }
  22951. var normalizedExtent = [0, 1];
  22952. /**
  22953. * @name module:echarts/coord/CartesianAxis
  22954. * @constructor
  22955. */
  22956. var Axis = function (dim, scale, extent) {
  22957. /**
  22958. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'
  22959. * @type {string}
  22960. */
  22961. this.dim = dim;
  22962. /**
  22963. * Axis scale
  22964. * @type {module:echarts/coord/scale/*}
  22965. */
  22966. this.scale = scale;
  22967. /**
  22968. * @type {Array.<number>}
  22969. * @private
  22970. */
  22971. this._extent = extent || [0, 0];
  22972. /**
  22973. * @type {boolean}
  22974. */
  22975. this.inverse = false;
  22976. /**
  22977. * Usually true when axis has a ordinal scale
  22978. * @type {boolean}
  22979. */
  22980. this.onBand = false;
  22981. /**
  22982. * @private
  22983. * @type {number}
  22984. */
  22985. this._labelInterval;
  22986. };
  22987. Axis.prototype = {
  22988. constructor: Axis,
  22989. /**
  22990. * If axis extent contain given coord
  22991. * @param {number} coord
  22992. * @return {boolean}
  22993. */
  22994. contain: function (coord) {
  22995. var extent = this._extent;
  22996. var min = Math.min(extent[0], extent[1]);
  22997. var max = Math.max(extent[0], extent[1]);
  22998. return coord >= min && coord <= max;
  22999. },
  23000. /**
  23001. * If axis extent contain given data
  23002. * @param {number} data
  23003. * @return {boolean}
  23004. */
  23005. containData: function (data) {
  23006. return this.contain(this.dataToCoord(data));
  23007. },
  23008. /**
  23009. * Get coord extent.
  23010. * @return {Array.<number>}
  23011. */
  23012. getExtent: function () {
  23013. return this._extent.slice();
  23014. },
  23015. /**
  23016. * Get precision used for formatting
  23017. * @param {Array.<number>} [dataExtent]
  23018. * @return {number}
  23019. */
  23020. getPixelPrecision: function (dataExtent) {
  23021. return getPixelPrecision(
  23022. dataExtent || this.scale.getExtent(),
  23023. this._extent
  23024. );
  23025. },
  23026. /**
  23027. * Set coord extent
  23028. * @param {number} start
  23029. * @param {number} end
  23030. */
  23031. setExtent: function (start, end) {
  23032. var extent = this._extent;
  23033. extent[0] = start;
  23034. extent[1] = end;
  23035. },
  23036. /**
  23037. * Convert data to coord. Data is the rank if it has a ordinal scale
  23038. * @param {number} data
  23039. * @param {boolean} clamp
  23040. * @return {number}
  23041. */
  23042. dataToCoord: function (data, clamp) {
  23043. var extent = this._extent;
  23044. var scale = this.scale;
  23045. data = scale.normalize(data);
  23046. if (this.onBand && scale.type === 'ordinal') {
  23047. extent = extent.slice();
  23048. fixExtentWithBands(extent, scale.count());
  23049. }
  23050. return linearMap$1(data, normalizedExtent, extent, clamp);
  23051. },
  23052. /**
  23053. * Convert coord to data. Data is the rank if it has a ordinal scale
  23054. * @param {number} coord
  23055. * @param {boolean} clamp
  23056. * @return {number}
  23057. */
  23058. coordToData: function (coord, clamp) {
  23059. var extent = this._extent;
  23060. var scale = this.scale;
  23061. if (this.onBand && scale.type === 'ordinal') {
  23062. extent = extent.slice();
  23063. fixExtentWithBands(extent, scale.count());
  23064. }
  23065. var t = linearMap$1(coord, extent, normalizedExtent, clamp);
  23066. return this.scale.scale(t);
  23067. },
  23068. /**
  23069. * Convert pixel point to data in axis
  23070. * @param {Array.<number>} point
  23071. * @param {boolean} clamp
  23072. * @return {number} data
  23073. */
  23074. pointToData: function (point, clamp) {
  23075. // Should be implemented in derived class if necessary.
  23076. },
  23077. /**
  23078. * @return {Array.<number>}
  23079. */
  23080. getTicksCoords: function (alignWithLabel) {
  23081. if (this.onBand && !alignWithLabel) {
  23082. var bands = this.getBands();
  23083. var coords = [];
  23084. for (var i = 0; i < bands.length; i++) {
  23085. coords.push(bands[i][0]);
  23086. }
  23087. if (bands[i - 1]) {
  23088. coords.push(bands[i - 1][1]);
  23089. }
  23090. return coords;
  23091. }
  23092. else {
  23093. return map(this.scale.getTicks(), this.dataToCoord, this);
  23094. }
  23095. },
  23096. /**
  23097. * Coords of labels are on the ticks or on the middle of bands
  23098. * @return {Array.<number>}
  23099. */
  23100. getLabelsCoords: function () {
  23101. return map(this.scale.getTicks(), this.dataToCoord, this);
  23102. },
  23103. /**
  23104. * Get bands.
  23105. *
  23106. * If axis has labels [1, 2, 3, 4]. Bands on the axis are
  23107. * |---1---|---2---|---3---|---4---|.
  23108. *
  23109. * @return {Array}
  23110. */
  23111. // FIXME Situation when labels is on ticks
  23112. getBands: function () {
  23113. var extent = this.getExtent();
  23114. var bands = [];
  23115. var len = this.scale.count();
  23116. var start = extent[0];
  23117. var end = extent[1];
  23118. var span = end - start;
  23119. for (var i = 0; i < len; i++) {
  23120. bands.push([
  23121. span * i / len + start,
  23122. span * (i + 1) / len + start
  23123. ]);
  23124. }
  23125. return bands;
  23126. },
  23127. /**
  23128. * Get width of band
  23129. * @return {number}
  23130. */
  23131. getBandWidth: function () {
  23132. var axisExtent = this._extent;
  23133. var dataExtent = this.scale.getExtent();
  23134. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  23135. // Fix #2728, avoid NaN when only one data.
  23136. len === 0 && (len = 1);
  23137. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  23138. return Math.abs(size) / len;
  23139. },
  23140. /**
  23141. * @abstract
  23142. * @return {boolean} Is horizontal
  23143. */
  23144. isHorizontal: null,
  23145. /**
  23146. * @abstract
  23147. * @return {number} Get axis rotate, by degree.
  23148. */
  23149. getRotate: null,
  23150. /**
  23151. * Get interval of the axis label.
  23152. * To get precise result, at least one of `getRotate` and `isHorizontal`
  23153. * should be implemented.
  23154. * @return {number}
  23155. */
  23156. getLabelInterval: function () {
  23157. var labelInterval = this._labelInterval;
  23158. if (!labelInterval) {
  23159. var axisModel = this.model;
  23160. var labelModel = axisModel.getModel('axisLabel');
  23161. labelInterval = labelModel.get('interval');
  23162. if (this.type === 'category'
  23163. && (labelInterval == null || labelInterval === 'auto')
  23164. ) {
  23165. labelInterval = getAxisLabelInterval(
  23166. map(this.scale.getTicks(), this.dataToCoord, this),
  23167. axisModel.getFormattedLabels(),
  23168. labelModel.getFont(),
  23169. this.getRotate
  23170. ? this.getRotate()
  23171. : (this.isHorizontal && !this.isHorizontal())
  23172. ? 90
  23173. : 0,
  23174. labelModel.get('rotate')
  23175. );
  23176. }
  23177. this._labelInterval = labelInterval;
  23178. }
  23179. return labelInterval;
  23180. }
  23181. };
  23182. var EPSILON$3 = 1e-8;
  23183. function isAroundEqual$1(a, b) {
  23184. return Math.abs(a - b) < EPSILON$3;
  23185. }
  23186. function contain$1(points, x, y) {
  23187. var w = 0;
  23188. var p = points[0];
  23189. if (!p) {
  23190. return false;
  23191. }
  23192. for (var i = 1; i < points.length; i++) {
  23193. var p2 = points[i];
  23194. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  23195. p = p2;
  23196. }
  23197. // Close polygon
  23198. var p0 = points[0];
  23199. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  23200. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  23201. }
  23202. return w !== 0;
  23203. }
  23204. /**
  23205. * @module echarts/coord/geo/Region
  23206. */
  23207. /**
  23208. * @param {string} name
  23209. * @param {Array} geometries
  23210. * @param {Array.<number>} cp
  23211. */
  23212. function Region(name, geometries, cp) {
  23213. /**
  23214. * @type {string}
  23215. * @readOnly
  23216. */
  23217. this.name = name;
  23218. /**
  23219. * @type {Array.<Array>}
  23220. * @readOnly
  23221. */
  23222. this.geometries = geometries;
  23223. if (!cp) {
  23224. var rect = this.getBoundingRect();
  23225. cp = [
  23226. rect.x + rect.width / 2,
  23227. rect.y + rect.height / 2
  23228. ];
  23229. }
  23230. else {
  23231. cp = [cp[0], cp[1]];
  23232. }
  23233. /**
  23234. * @type {Array.<number>}
  23235. */
  23236. this.center = cp;
  23237. }
  23238. Region.prototype = {
  23239. constructor: Region,
  23240. properties: null,
  23241. /**
  23242. * @return {module:zrender/core/BoundingRect}
  23243. */
  23244. getBoundingRect: function () {
  23245. var rect = this._rect;
  23246. if (rect) {
  23247. return rect;
  23248. }
  23249. var MAX_NUMBER = Number.MAX_VALUE;
  23250. var min$$1 = [MAX_NUMBER, MAX_NUMBER];
  23251. var max$$1 = [-MAX_NUMBER, -MAX_NUMBER];
  23252. var min2 = [];
  23253. var max2 = [];
  23254. var geometries = this.geometries;
  23255. for (var i = 0; i < geometries.length; i++) {
  23256. // Only support polygon
  23257. if (geometries[i].type !== 'polygon') {
  23258. continue;
  23259. }
  23260. // Doesn't consider hole
  23261. var exterior = geometries[i].exterior;
  23262. fromPoints(exterior, min2, max2);
  23263. min(min$$1, min$$1, min2);
  23264. max(max$$1, max$$1, max2);
  23265. }
  23266. // No data
  23267. if (i === 0) {
  23268. min$$1[0] = min$$1[1] = max$$1[0] = max$$1[1] = 0;
  23269. }
  23270. return (this._rect = new BoundingRect(
  23271. min$$1[0], min$$1[1], max$$1[0] - min$$1[0], max$$1[1] - min$$1[1]
  23272. ));
  23273. },
  23274. /**
  23275. * @param {<Array.<number>} coord
  23276. * @return {boolean}
  23277. */
  23278. contain: function (coord) {
  23279. var rect = this.getBoundingRect();
  23280. var geometries = this.geometries;
  23281. if (!rect.contain(coord[0], coord[1])) {
  23282. return false;
  23283. }
  23284. loopGeo: for (var i = 0, len$$1 = geometries.length; i < len$$1; i++) {
  23285. // Only support polygon.
  23286. if (geometries[i].type !== 'polygon') {
  23287. continue;
  23288. }
  23289. var exterior = geometries[i].exterior;
  23290. var interiors = geometries[i].interiors;
  23291. if (contain$1(exterior, coord[0], coord[1])) {
  23292. // Not in the region if point is in the hole.
  23293. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  23294. if (contain$1(interiors[k])) {
  23295. continue loopGeo;
  23296. }
  23297. }
  23298. return true;
  23299. }
  23300. }
  23301. return false;
  23302. },
  23303. transformTo: function (x, y, width, height) {
  23304. var rect = this.getBoundingRect();
  23305. var aspect = rect.width / rect.height;
  23306. if (!width) {
  23307. width = aspect * height;
  23308. }
  23309. else if (!height) {
  23310. height = width / aspect ;
  23311. }
  23312. var target = new BoundingRect(x, y, width, height);
  23313. var transform = rect.calculateTransform(target);
  23314. var geometries = this.geometries;
  23315. for (var i = 0; i < geometries.length; i++) {
  23316. // Only support polygon.
  23317. if (geometries[i].type !== 'polygon') {
  23318. continue;
  23319. }
  23320. var exterior = geometries[i].exterior;
  23321. var interiors = geometries[i].interiors;
  23322. for (var p = 0; p < exterior.length; p++) {
  23323. applyTransform(exterior[p], exterior[p], transform);
  23324. }
  23325. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  23326. for (var p = 0; p < interiors[h].length; p++) {
  23327. applyTransform(interiors[h][p], interiors[h][p], transform);
  23328. }
  23329. }
  23330. }
  23331. rect = this._rect;
  23332. rect.copy(target);
  23333. // Update center
  23334. this.center = [
  23335. rect.x + rect.width / 2,
  23336. rect.y + rect.height / 2
  23337. ];
  23338. }
  23339. };
  23340. /**
  23341. * Parse and decode geo json
  23342. * @module echarts/coord/geo/parseGeoJson
  23343. */
  23344. function decode(json) {
  23345. if (!json.UTF8Encoding) {
  23346. return json;
  23347. }
  23348. var encodeScale = json.UTF8Scale;
  23349. if (encodeScale == null) {
  23350. encodeScale = 1024;
  23351. }
  23352. var features = json.features;
  23353. for (var f = 0; f < features.length; f++) {
  23354. var feature = features[f];
  23355. var geometry = feature.geometry;
  23356. var coordinates = geometry.coordinates;
  23357. var encodeOffsets = geometry.encodeOffsets;
  23358. for (var c = 0; c < coordinates.length; c++) {
  23359. var coordinate = coordinates[c];
  23360. if (geometry.type === 'Polygon') {
  23361. coordinates[c] = decodePolygon(
  23362. coordinate,
  23363. encodeOffsets[c],
  23364. encodeScale
  23365. );
  23366. }
  23367. else if (geometry.type === 'MultiPolygon') {
  23368. for (var c2 = 0; c2 < coordinate.length; c2++) {
  23369. var polygon = coordinate[c2];
  23370. coordinate[c2] = decodePolygon(
  23371. polygon,
  23372. encodeOffsets[c][c2],
  23373. encodeScale
  23374. );
  23375. }
  23376. }
  23377. }
  23378. }
  23379. // Has been decoded
  23380. json.UTF8Encoding = false;
  23381. return json;
  23382. }
  23383. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  23384. var result = [];
  23385. var prevX = encodeOffsets[0];
  23386. var prevY = encodeOffsets[1];
  23387. for (var i = 0; i < coordinate.length; i += 2) {
  23388. var x = coordinate.charCodeAt(i) - 64;
  23389. var y = coordinate.charCodeAt(i + 1) - 64;
  23390. // ZigZag decoding
  23391. x = (x >> 1) ^ (-(x & 1));
  23392. y = (y >> 1) ^ (-(y & 1));
  23393. // Delta deocding
  23394. x += prevX;
  23395. y += prevY;
  23396. prevX = x;
  23397. prevY = y;
  23398. // Dequantize
  23399. result.push([x / encodeScale, y / encodeScale]);
  23400. }
  23401. return result;
  23402. }
  23403. /**
  23404. * @alias module:echarts/coord/geo/parseGeoJson
  23405. * @param {Object} geoJson
  23406. * @return {module:zrender/container/Group}
  23407. */
  23408. var parseGeoJson = function (geoJson) {
  23409. decode(geoJson);
  23410. return map(filter(geoJson.features, function (featureObj) {
  23411. // Output of mapshaper may have geometry null
  23412. return featureObj.geometry
  23413. && featureObj.properties
  23414. && featureObj.geometry.coordinates.length > 0;
  23415. }), function (featureObj) {
  23416. var properties = featureObj.properties;
  23417. var geo = featureObj.geometry;
  23418. var coordinates = geo.coordinates;
  23419. var geometries = [];
  23420. if (geo.type === 'Polygon') {
  23421. geometries.push({
  23422. type: 'polygon',
  23423. // According to the GeoJSON specification.
  23424. // First must be exterior, and the rest are all interior(holes).
  23425. exterior: coordinates[0],
  23426. interiors: coordinates.slice(1)
  23427. });
  23428. }
  23429. if (geo.type === 'MultiPolygon') {
  23430. each$1(coordinates, function (item) {
  23431. if (item[0]) {
  23432. geometries.push({
  23433. type: 'polygon',
  23434. exterior: item[0],
  23435. interiors: item.slice(1)
  23436. });
  23437. }
  23438. });
  23439. }
  23440. var region = new Region(
  23441. properties.name,
  23442. geometries,
  23443. properties.cp
  23444. );
  23445. region.properties = properties;
  23446. return region;
  23447. });
  23448. };
  23449. /**
  23450. * Do not mount those modules on 'src/echarts' for better tree shaking.
  23451. */
  23452. var ecUtil = {};
  23453. each$1([
  23454. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  23455. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  23456. 'extend', 'defaults', 'clone', 'merge'
  23457. ],
  23458. function (name) {
  23459. ecUtil[name] = zrUtil[name];
  23460. }
  23461. );
  23462. SeriesModel.extend({
  23463. type: 'series.line',
  23464. dependencies: ['grid', 'polar'],
  23465. getInitialData: function (option, ecModel) {
  23466. if (__DEV__) {
  23467. var coordSys = option.coordinateSystem;
  23468. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  23469. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  23470. }
  23471. }
  23472. return createListFromArray(option.data, this, ecModel);
  23473. },
  23474. defaultOption: {
  23475. zlevel: 0, // 一级层叠
  23476. z: 2, // 二级层叠
  23477. coordinateSystem: 'cartesian2d',
  23478. legendHoverLink: true,
  23479. hoverAnimation: true,
  23480. // stack: null
  23481. // xAxisIndex: 0,
  23482. // yAxisIndex: 0,
  23483. // polarIndex: 0,
  23484. // If clip the overflow value
  23485. clipOverflow: true,
  23486. // cursor: null,
  23487. label: {
  23488. normal: {
  23489. position: 'top'
  23490. }
  23491. },
  23492. // itemStyle: {
  23493. // normal: {},
  23494. // emphasis: {}
  23495. // },
  23496. lineStyle: {
  23497. normal: {
  23498. width: 2,
  23499. type: 'solid'
  23500. }
  23501. },
  23502. // areaStyle: {},
  23503. // false, 'start', 'end', 'middle'
  23504. step: false,
  23505. // Disabled if step is true
  23506. smooth: false,
  23507. smoothMonotone: null,
  23508. // 拐点图形类型
  23509. symbol: 'emptyCircle',
  23510. // 拐点图形大小
  23511. symbolSize: 4,
  23512. // 拐点图形旋转控制
  23513. symbolRotate: null,
  23514. // 是否显示 symbol, 只有在 tooltip hover 的时候显示
  23515. showSymbol: true,
  23516. // 标志图形默认只有主轴显示(随主轴标签间隔隐藏策略)
  23517. showAllSymbol: false,
  23518. // 是否连接断点
  23519. connectNulls: false,
  23520. // 数据过滤,'average', 'max', 'min', 'sum'
  23521. sampling: 'none',
  23522. animationEasing: 'linear',
  23523. // Disable progressive
  23524. progressive: 0,
  23525. hoverLayerThreshold: Infinity
  23526. }
  23527. });
  23528. /**
  23529. * @module echarts/chart/helper/Symbol
  23530. */
  23531. function findLabelValueDim(data) {
  23532. var valueDim;
  23533. var labelDims = otherDimToDataDim(data, 'label');
  23534. if (labelDims.length) {
  23535. valueDim = labelDims[0];
  23536. }
  23537. else {
  23538. // Get last value dim
  23539. var dimensions = data.dimensions.slice();
  23540. var dataType;
  23541. while (dimensions.length && (
  23542. valueDim = dimensions.pop(),
  23543. dataType = data.getDimensionInfo(valueDim).type,
  23544. dataType === 'ordinal' || dataType === 'time'
  23545. )) {} // jshint ignore:line
  23546. }
  23547. return valueDim;
  23548. }
  23549. /**
  23550. * @module echarts/chart/helper/Symbol
  23551. */
  23552. function getSymbolSize(data, idx) {
  23553. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  23554. return symbolSize instanceof Array
  23555. ? symbolSize.slice()
  23556. : [+symbolSize, +symbolSize];
  23557. }
  23558. function getScale(symbolSize) {
  23559. return [symbolSize[0] / 2, symbolSize[1] / 2];
  23560. }
  23561. /**
  23562. * @constructor
  23563. * @alias {module:echarts/chart/helper/Symbol}
  23564. * @param {module:echarts/data/List} data
  23565. * @param {number} idx
  23566. * @extends {module:zrender/graphic/Group}
  23567. */
  23568. function SymbolClz$1(data, idx, seriesScope) {
  23569. Group.call(this);
  23570. this.updateData(data, idx, seriesScope);
  23571. }
  23572. var symbolProto = SymbolClz$1.prototype;
  23573. function driftSymbol(dx, dy) {
  23574. this.parent.drift(dx, dy);
  23575. }
  23576. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize) {
  23577. // Remove paths created before
  23578. this.removeAll();
  23579. var color = data.getItemVisual(idx, 'color');
  23580. // var symbolPath = createSymbol(
  23581. // symbolType, -0.5, -0.5, 1, 1, color
  23582. // );
  23583. // If width/height are set too small (e.g., set to 1) on ios10
  23584. // and macOS Sierra, a circle stroke become a rect, no matter what
  23585. // the scale is set. So we set width/height as 2. See #4150.
  23586. var symbolPath = createSymbol(
  23587. symbolType, -1, -1, 2, 2, color
  23588. );
  23589. symbolPath.attr({
  23590. z2: 100,
  23591. culling: true,
  23592. scale: getScale(symbolSize)
  23593. });
  23594. // Rewrite drift method
  23595. symbolPath.drift = driftSymbol;
  23596. this._symbolType = symbolType;
  23597. this.add(symbolPath);
  23598. };
  23599. /**
  23600. * Stop animation
  23601. * @param {boolean} toLastFrame
  23602. */
  23603. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  23604. this.childAt(0).stopAnimation(toLastFrame);
  23605. };
  23606. /**
  23607. * FIXME:
  23608. * Caution: This method breaks the encapsulation of this module,
  23609. * but it indeed brings convenience. So do not use the method
  23610. * unless you detailedly know all the implements of `Symbol`,
  23611. * especially animation.
  23612. *
  23613. * Get symbol path element.
  23614. */
  23615. symbolProto.getSymbolPath = function () {
  23616. return this.childAt(0);
  23617. };
  23618. /**
  23619. * Get scale(aka, current symbol size).
  23620. * Including the change caused by animation
  23621. */
  23622. symbolProto.getScale = function () {
  23623. return this.childAt(0).scale;
  23624. };
  23625. /**
  23626. * Highlight symbol
  23627. */
  23628. symbolProto.highlight = function () {
  23629. this.childAt(0).trigger('emphasis');
  23630. };
  23631. /**
  23632. * Downplay symbol
  23633. */
  23634. symbolProto.downplay = function () {
  23635. this.childAt(0).trigger('normal');
  23636. };
  23637. /**
  23638. * @param {number} zlevel
  23639. * @param {number} z
  23640. */
  23641. symbolProto.setZ = function (zlevel, z) {
  23642. var symbolPath = this.childAt(0);
  23643. symbolPath.zlevel = zlevel;
  23644. symbolPath.z = z;
  23645. };
  23646. symbolProto.setDraggable = function (draggable) {
  23647. var symbolPath = this.childAt(0);
  23648. symbolPath.draggable = draggable;
  23649. symbolPath.cursor = draggable ? 'move' : 'pointer';
  23650. };
  23651. /**
  23652. * Update symbol properties
  23653. * @param {module:echarts/data/List} data
  23654. * @param {number} idx
  23655. * @param {Object} [seriesScope]
  23656. * @param {Object} [seriesScope.itemStyle]
  23657. * @param {Object} [seriesScope.hoverItemStyle]
  23658. * @param {Object} [seriesScope.symbolRotate]
  23659. * @param {Object} [seriesScope.symbolOffset]
  23660. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  23661. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  23662. * @param {boolean} [seriesScope.hoverAnimation]
  23663. * @param {Object} [seriesScope.cursorStyle]
  23664. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  23665. * @param {string} [seriesScope.symbolInnerColor]
  23666. * @param {Object} [seriesScope.fadeIn=false]
  23667. */
  23668. symbolProto.updateData = function (data, idx, seriesScope) {
  23669. this.silent = false;
  23670. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  23671. var seriesModel = data.hostModel;
  23672. var symbolSize = getSymbolSize(data, idx);
  23673. var isInit = symbolType !== this._symbolType;
  23674. if (isInit) {
  23675. this._createSymbol(symbolType, data, idx, symbolSize);
  23676. }
  23677. else {
  23678. var symbolPath = this.childAt(0);
  23679. symbolPath.silent = false;
  23680. updateProps(symbolPath, {
  23681. scale: getScale(symbolSize)
  23682. }, seriesModel, idx);
  23683. }
  23684. this._updateCommon(data, idx, symbolSize, seriesScope);
  23685. if (isInit) {
  23686. var symbolPath = this.childAt(0);
  23687. var fadeIn = seriesScope && seriesScope.fadeIn;
  23688. var target = {scale: symbolPath.scale.slice()};
  23689. fadeIn && (target.style = {opacity: symbolPath.style.opacity});
  23690. symbolPath.scale = [0, 0];
  23691. fadeIn && (symbolPath.style.opacity = 0);
  23692. initProps(symbolPath, target, seriesModel, idx);
  23693. }
  23694. this._seriesModel = seriesModel;
  23695. };
  23696. // Update common properties
  23697. var normalStyleAccessPath = ['itemStyle', 'normal'];
  23698. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  23699. var normalLabelAccessPath = ['label', 'normal'];
  23700. var emphasisLabelAccessPath = ['label', 'emphasis'];
  23701. /**
  23702. * @param {module:echarts/data/List} data
  23703. * @param {number} idx
  23704. * @param {Array.<number>} symbolSize
  23705. * @param {Object} [seriesScope]
  23706. */
  23707. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  23708. var symbolPath = this.childAt(0);
  23709. var seriesModel = data.hostModel;
  23710. var color = data.getItemVisual(idx, 'color');
  23711. // Reset style
  23712. if (symbolPath.type !== 'image') {
  23713. symbolPath.useStyle({
  23714. strokeNoScale: true
  23715. });
  23716. }
  23717. var itemStyle = seriesScope && seriesScope.itemStyle;
  23718. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  23719. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  23720. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  23721. var labelModel = seriesScope && seriesScope.labelModel;
  23722. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  23723. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  23724. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  23725. if (!seriesScope || data.hasItemOption) {
  23726. var itemModel = (seriesScope && seriesScope.itemModel)
  23727. ? seriesScope.itemModel : data.getItemModel(idx);
  23728. // Color must be excluded.
  23729. // Because symbol provide setColor individually to set fill and stroke
  23730. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  23731. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  23732. symbolRotate = itemModel.getShallow('symbolRotate');
  23733. symbolOffset = itemModel.getShallow('symbolOffset');
  23734. labelModel = itemModel.getModel(normalLabelAccessPath);
  23735. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  23736. hoverAnimation = itemModel.getShallow('hoverAnimation');
  23737. cursorStyle = itemModel.getShallow('cursor');
  23738. }
  23739. else {
  23740. hoverItemStyle = extend({}, hoverItemStyle);
  23741. }
  23742. var elStyle = symbolPath.style;
  23743. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  23744. if (symbolOffset) {
  23745. symbolPath.attr('position', [
  23746. parsePercent$1(symbolOffset[0], symbolSize[0]),
  23747. parsePercent$1(symbolOffset[1], symbolSize[1])
  23748. ]);
  23749. }
  23750. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  23751. // PENDING setColor before setStyle!!!
  23752. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  23753. symbolPath.setStyle(itemStyle);
  23754. var opacity = data.getItemVisual(idx, 'opacity');
  23755. if (opacity != null) {
  23756. elStyle.opacity = opacity;
  23757. }
  23758. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  23759. var valueDim = !useNameLabel && findLabelValueDim(data);
  23760. if (useNameLabel || valueDim != null) {
  23761. setLabelStyle(
  23762. elStyle, hoverItemStyle, labelModel, hoverLabelModel,
  23763. {
  23764. labelFetcher: seriesModel,
  23765. labelDataIndex: idx,
  23766. defaultText: useNameLabel ? data.getName(idx) : data.get(valueDim, idx),
  23767. isRectText: true,
  23768. autoColor: color
  23769. }
  23770. );
  23771. }
  23772. symbolPath.off('mouseover')
  23773. .off('mouseout')
  23774. .off('emphasis')
  23775. .off('normal');
  23776. symbolPath.hoverStyle = hoverItemStyle;
  23777. // FIXME
  23778. // Do not use symbol.trigger('emphasis'), but use symbol.highlight() instead.
  23779. setHoverStyle(symbolPath);
  23780. var scale = getScale(symbolSize);
  23781. if (hoverAnimation && seriesModel.isAnimationEnabled()) {
  23782. var onEmphasis = function() {
  23783. var ratio = scale[1] / scale[0];
  23784. this.animateTo({
  23785. scale: [
  23786. Math.max(scale[0] * 1.1, scale[0] + 3),
  23787. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  23788. ]
  23789. }, 400, 'elasticOut');
  23790. };
  23791. var onNormal = function() {
  23792. this.animateTo({
  23793. scale: scale
  23794. }, 400, 'elasticOut');
  23795. };
  23796. symbolPath.on('mouseover', onEmphasis)
  23797. .on('mouseout', onNormal)
  23798. .on('emphasis', onEmphasis)
  23799. .on('normal', onNormal);
  23800. }
  23801. };
  23802. /**
  23803. * @param {Function} cb
  23804. * @param {Object} [opt]
  23805. * @param {Object} [opt.keepLabel=true]
  23806. */
  23807. symbolProto.fadeOut = function (cb, opt) {
  23808. var symbolPath = this.childAt(0);
  23809. // Avoid mistaken hover when fading out
  23810. this.silent = symbolPath.silent = true;
  23811. // Not show text when animating
  23812. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  23813. updateProps(
  23814. symbolPath,
  23815. {
  23816. style: {opacity: 0},
  23817. scale: [0, 0]
  23818. },
  23819. this._seriesModel,
  23820. this.dataIndex,
  23821. cb
  23822. );
  23823. };
  23824. inherits(SymbolClz$1, Group);
  23825. /**
  23826. * @module echarts/chart/helper/SymbolDraw
  23827. */
  23828. /**
  23829. * @constructor
  23830. * @alias module:echarts/chart/helper/SymbolDraw
  23831. * @param {module:zrender/graphic/Group} [symbolCtor]
  23832. */
  23833. function SymbolDraw(symbolCtor) {
  23834. this.group = new Group();
  23835. this._symbolCtor = symbolCtor || SymbolClz$1;
  23836. }
  23837. var symbolDrawProto = SymbolDraw.prototype;
  23838. function symbolNeedsDraw(data, idx, isIgnore) {
  23839. var point = data.getItemLayout(idx);
  23840. // Is an object
  23841. // if (point && point.hasOwnProperty('point')) {
  23842. // point = point.point;
  23843. // }
  23844. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(isIgnore && isIgnore(idx))
  23845. && data.getItemVisual(idx, 'symbol') !== 'none';
  23846. }
  23847. /**
  23848. * Update symbols draw by new data
  23849. * @param {module:echarts/data/List} data
  23850. * @param {Array.<boolean>} [isIgnore]
  23851. */
  23852. symbolDrawProto.updateData = function (data, isIgnore) {
  23853. var group = this.group;
  23854. var seriesModel = data.hostModel;
  23855. var oldData = this._data;
  23856. var SymbolCtor = this._symbolCtor;
  23857. var seriesScope = {
  23858. itemStyle: seriesModel.getModel('itemStyle.normal').getItemStyle(['color']),
  23859. hoverItemStyle: seriesModel.getModel('itemStyle.emphasis').getItemStyle(),
  23860. symbolRotate: seriesModel.get('symbolRotate'),
  23861. symbolOffset: seriesModel.get('symbolOffset'),
  23862. hoverAnimation: seriesModel.get('hoverAnimation'),
  23863. labelModel: seriesModel.getModel('label.normal'),
  23864. hoverLabelModel: seriesModel.getModel('label.emphasis'),
  23865. cursorStyle: seriesModel.get('cursor')
  23866. };
  23867. data.diff(oldData)
  23868. .add(function (newIdx) {
  23869. var point = data.getItemLayout(newIdx);
  23870. if (symbolNeedsDraw(data, newIdx, isIgnore)) {
  23871. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  23872. symbolEl.attr('position', point);
  23873. data.setItemGraphicEl(newIdx, symbolEl);
  23874. group.add(symbolEl);
  23875. }
  23876. })
  23877. .update(function (newIdx, oldIdx) {
  23878. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  23879. var point = data.getItemLayout(newIdx);
  23880. if (!symbolNeedsDraw(data, newIdx, isIgnore)) {
  23881. group.remove(symbolEl);
  23882. return;
  23883. }
  23884. if (!symbolEl) {
  23885. symbolEl = new SymbolCtor(data, newIdx);
  23886. symbolEl.attr('position', point);
  23887. }
  23888. else {
  23889. symbolEl.updateData(data, newIdx, seriesScope);
  23890. updateProps(symbolEl, {
  23891. position: point
  23892. }, seriesModel);
  23893. }
  23894. // Add back
  23895. group.add(symbolEl);
  23896. data.setItemGraphicEl(newIdx, symbolEl);
  23897. })
  23898. .remove(function (oldIdx) {
  23899. var el = oldData.getItemGraphicEl(oldIdx);
  23900. el && el.fadeOut(function () {
  23901. group.remove(el);
  23902. });
  23903. })
  23904. .execute();
  23905. this._data = data;
  23906. };
  23907. symbolDrawProto.updateLayout = function () {
  23908. var data = this._data;
  23909. if (data) {
  23910. // Not use animation
  23911. data.eachItemGraphicEl(function (el, idx) {
  23912. var point = data.getItemLayout(idx);
  23913. el.attr('position', point);
  23914. });
  23915. }
  23916. };
  23917. symbolDrawProto.remove = function (enableAnimation) {
  23918. var group = this.group;
  23919. var data = this._data;
  23920. if (data) {
  23921. if (enableAnimation) {
  23922. data.eachItemGraphicEl(function (el) {
  23923. el.fadeOut(function () {
  23924. group.remove(el);
  23925. });
  23926. });
  23927. }
  23928. else {
  23929. group.removeAll();
  23930. }
  23931. }
  23932. };
  23933. // var arrayDiff = require('zrender/src/core/arrayDiff');
  23934. // 'zrender/src/core/arrayDiff' has been used before, but it did
  23935. // not do well in performance when roam with fixed dataZoom window.
  23936. function sign$1(val) {
  23937. return val >= 0 ? 1 : -1;
  23938. }
  23939. function getStackedOnPoint(coordSys, data, idx) {
  23940. var baseAxis = coordSys.getBaseAxis();
  23941. var valueAxis = coordSys.getOtherAxis(baseAxis);
  23942. var valueStart = baseAxis.onZero
  23943. ? 0 : valueAxis.scale.getExtent()[0];
  23944. var valueDim = valueAxis.dim;
  23945. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  23946. var stackedOnSameSign;
  23947. var stackedOn = data.stackedOn;
  23948. var val = data.get(valueDim, idx);
  23949. // Find first stacked value with same sign
  23950. while (stackedOn &&
  23951. sign$1(stackedOn.get(valueDim, idx)) === sign$1(val)
  23952. ) {
  23953. stackedOnSameSign = stackedOn;
  23954. break;
  23955. }
  23956. var stackedData = [];
  23957. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  23958. stackedData[1 - baseDataOffset] = stackedOnSameSign
  23959. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  23960. return coordSys.dataToPoint(stackedData);
  23961. }
  23962. // function convertToIntId(newIdList, oldIdList) {
  23963. // // Generate int id instead of string id.
  23964. // // Compare string maybe slow in score function of arrDiff
  23965. // // Assume id in idList are all unique
  23966. // var idIndicesMap = {};
  23967. // var idx = 0;
  23968. // for (var i = 0; i < newIdList.length; i++) {
  23969. // idIndicesMap[newIdList[i]] = idx;
  23970. // newIdList[i] = idx++;
  23971. // }
  23972. // for (var i = 0; i < oldIdList.length; i++) {
  23973. // var oldId = oldIdList[i];
  23974. // // Same with newIdList
  23975. // if (idIndicesMap[oldId]) {
  23976. // oldIdList[i] = idIndicesMap[oldId];
  23977. // }
  23978. // else {
  23979. // oldIdList[i] = idx++;
  23980. // }
  23981. // }
  23982. // }
  23983. function diffData(oldData, newData) {
  23984. var diffResult = [];
  23985. newData.diff(oldData)
  23986. .add(function (idx) {
  23987. diffResult.push({cmd: '+', idx: idx});
  23988. })
  23989. .update(function (newIdx, oldIdx) {
  23990. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  23991. })
  23992. .remove(function (idx) {
  23993. diffResult.push({cmd: '-', idx: idx});
  23994. })
  23995. .execute();
  23996. return diffResult;
  23997. }
  23998. var lineAnimationDiff = function (
  23999. oldData, newData,
  24000. oldStackedOnPoints, newStackedOnPoints,
  24001. oldCoordSys, newCoordSys
  24002. ) {
  24003. var diff = diffData(oldData, newData);
  24004. // var newIdList = newData.mapArray(newData.getId);
  24005. // var oldIdList = oldData.mapArray(oldData.getId);
  24006. // convertToIntId(newIdList, oldIdList);
  24007. // // FIXME One data ?
  24008. // diff = arrayDiff(oldIdList, newIdList);
  24009. var currPoints = [];
  24010. var nextPoints = [];
  24011. // Points for stacking base line
  24012. var currStackedPoints = [];
  24013. var nextStackedPoints = [];
  24014. var status = [];
  24015. var sortedIndices = [];
  24016. var rawIndices = [];
  24017. var dims = newCoordSys.dimensions;
  24018. for (var i = 0; i < diff.length; i++) {
  24019. var diffItem = diff[i];
  24020. var pointAdded = true;
  24021. // FIXME, animation is not so perfect when dataZoom window moves fast
  24022. // Which is in case remvoing or add more than one data in the tail or head
  24023. switch (diffItem.cmd) {
  24024. case '=':
  24025. var currentPt = oldData.getItemLayout(diffItem.idx);
  24026. var nextPt = newData.getItemLayout(diffItem.idx1);
  24027. // If previous data is NaN, use next point directly
  24028. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  24029. currentPt = nextPt.slice();
  24030. }
  24031. currPoints.push(currentPt);
  24032. nextPoints.push(nextPt);
  24033. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  24034. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  24035. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  24036. break;
  24037. case '+':
  24038. var idx = diffItem.idx;
  24039. currPoints.push(
  24040. oldCoordSys.dataToPoint([
  24041. newData.get(dims[0], idx, true), newData.get(dims[1], idx, true)
  24042. ])
  24043. );
  24044. nextPoints.push(newData.getItemLayout(idx).slice());
  24045. currStackedPoints.push(
  24046. getStackedOnPoint(oldCoordSys, newData, idx)
  24047. );
  24048. nextStackedPoints.push(newStackedOnPoints[idx]);
  24049. rawIndices.push(newData.getRawIndex(idx));
  24050. break;
  24051. case '-':
  24052. var idx = diffItem.idx;
  24053. var rawIndex = oldData.getRawIndex(idx);
  24054. // Data is replaced. In the case of dynamic data queue
  24055. // FIXME FIXME FIXME
  24056. if (rawIndex !== idx) {
  24057. currPoints.push(oldData.getItemLayout(idx));
  24058. nextPoints.push(newCoordSys.dataToPoint([
  24059. oldData.get(dims[0], idx, true), oldData.get(dims[1], idx, true)
  24060. ]));
  24061. currStackedPoints.push(oldStackedOnPoints[idx]);
  24062. nextStackedPoints.push(
  24063. getStackedOnPoint(
  24064. newCoordSys, oldData, idx
  24065. )
  24066. );
  24067. rawIndices.push(rawIndex);
  24068. }
  24069. else {
  24070. pointAdded = false;
  24071. }
  24072. }
  24073. // Original indices
  24074. if (pointAdded) {
  24075. status.push(diffItem);
  24076. sortedIndices.push(sortedIndices.length);
  24077. }
  24078. }
  24079. // Diff result may be crossed if all items are changed
  24080. // Sort by data index
  24081. sortedIndices.sort(function (a, b) {
  24082. return rawIndices[a] - rawIndices[b];
  24083. });
  24084. var sortedCurrPoints = [];
  24085. var sortedNextPoints = [];
  24086. var sortedCurrStackedPoints = [];
  24087. var sortedNextStackedPoints = [];
  24088. var sortedStatus = [];
  24089. for (var i = 0; i < sortedIndices.length; i++) {
  24090. var idx = sortedIndices[i];
  24091. sortedCurrPoints[i] = currPoints[idx];
  24092. sortedNextPoints[i] = nextPoints[idx];
  24093. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  24094. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  24095. sortedStatus[i] = status[idx];
  24096. }
  24097. return {
  24098. current: sortedCurrPoints,
  24099. next: sortedNextPoints,
  24100. stackedOnCurrent: sortedCurrStackedPoints,
  24101. stackedOnNext: sortedNextStackedPoints,
  24102. status: sortedStatus
  24103. };
  24104. };
  24105. // Poly path support NaN point
  24106. var vec2Min = min;
  24107. var vec2Max = max;
  24108. var scaleAndAdd$1 = scaleAndAdd;
  24109. var v2Copy = copy;
  24110. // Temporary variable
  24111. var v = [];
  24112. var cp0 = [];
  24113. var cp1 = [];
  24114. function isPointNull(p) {
  24115. return isNaN(p[0]) || isNaN(p[1]);
  24116. }
  24117. function drawSegment(
  24118. ctx, points, start, segLen, allLen,
  24119. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  24120. ) {
  24121. var prevIdx = 0;
  24122. var idx = start;
  24123. for (var k = 0; k < segLen; k++) {
  24124. var p = points[idx];
  24125. if (idx >= allLen || idx < 0) {
  24126. break;
  24127. }
  24128. if (isPointNull(p)) {
  24129. if (connectNulls) {
  24130. idx += dir;
  24131. continue;
  24132. }
  24133. break;
  24134. }
  24135. if (idx === start) {
  24136. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  24137. v2Copy(cp0, p);
  24138. }
  24139. else {
  24140. if (smooth > 0) {
  24141. var nextIdx = idx + dir;
  24142. var nextP = points[nextIdx];
  24143. if (connectNulls) {
  24144. // Find next point not null
  24145. while (nextP && isPointNull(points[nextIdx])) {
  24146. nextIdx += dir;
  24147. nextP = points[nextIdx];
  24148. }
  24149. }
  24150. var ratioNextSeg = 0.5;
  24151. var prevP = points[prevIdx];
  24152. var nextP = points[nextIdx];
  24153. // Last point
  24154. if (!nextP || isPointNull(nextP)) {
  24155. v2Copy(cp1, p);
  24156. }
  24157. else {
  24158. // If next data is null in not connect case
  24159. if (isPointNull(nextP) && !connectNulls) {
  24160. nextP = p;
  24161. }
  24162. sub(v, nextP, prevP);
  24163. var lenPrevSeg;
  24164. var lenNextSeg;
  24165. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  24166. var dim = smoothMonotone === 'x' ? 0 : 1;
  24167. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  24168. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  24169. }
  24170. else {
  24171. lenPrevSeg = dist(p, prevP);
  24172. lenNextSeg = dist(p, nextP);
  24173. }
  24174. // Use ratio of seg length
  24175. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  24176. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  24177. }
  24178. // Smooth constraint
  24179. vec2Min(cp0, cp0, smoothMax);
  24180. vec2Max(cp0, cp0, smoothMin);
  24181. vec2Min(cp1, cp1, smoothMax);
  24182. vec2Max(cp1, cp1, smoothMin);
  24183. ctx.bezierCurveTo(
  24184. cp0[0], cp0[1],
  24185. cp1[0], cp1[1],
  24186. p[0], p[1]
  24187. );
  24188. // cp0 of next segment
  24189. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  24190. }
  24191. else {
  24192. ctx.lineTo(p[0], p[1]);
  24193. }
  24194. }
  24195. prevIdx = idx;
  24196. idx += dir;
  24197. }
  24198. return k;
  24199. }
  24200. function getBoundingBox(points, smoothConstraint) {
  24201. var ptMin = [Infinity, Infinity];
  24202. var ptMax = [-Infinity, -Infinity];
  24203. if (smoothConstraint) {
  24204. for (var i = 0; i < points.length; i++) {
  24205. var pt = points[i];
  24206. if (pt[0] < ptMin[0]) { ptMin[0] = pt[0]; }
  24207. if (pt[1] < ptMin[1]) { ptMin[1] = pt[1]; }
  24208. if (pt[0] > ptMax[0]) { ptMax[0] = pt[0]; }
  24209. if (pt[1] > ptMax[1]) { ptMax[1] = pt[1]; }
  24210. }
  24211. }
  24212. return {
  24213. min: smoothConstraint ? ptMin : ptMax,
  24214. max: smoothConstraint ? ptMax : ptMin
  24215. };
  24216. }
  24217. var Polyline$1 = Path.extend({
  24218. type: 'ec-polyline',
  24219. shape: {
  24220. points: [],
  24221. smooth: 0,
  24222. smoothConstraint: true,
  24223. smoothMonotone: null,
  24224. connectNulls: false
  24225. },
  24226. style: {
  24227. fill: null,
  24228. stroke: '#000'
  24229. },
  24230. brush: fixClipWithShadow(Path.prototype.brush),
  24231. buildPath: function (ctx, shape) {
  24232. var points = shape.points;
  24233. var i = 0;
  24234. var len$$1 = points.length;
  24235. var result = getBoundingBox(points, shape.smoothConstraint);
  24236. if (shape.connectNulls) {
  24237. // Must remove first and last null values avoid draw error in polygon
  24238. for (; len$$1 > 0; len$$1--) {
  24239. if (!isPointNull(points[len$$1 - 1])) {
  24240. break;
  24241. }
  24242. }
  24243. for (; i < len$$1; i++) {
  24244. if (!isPointNull(points[i])) {
  24245. break;
  24246. }
  24247. }
  24248. }
  24249. while (i < len$$1) {
  24250. i += drawSegment(
  24251. ctx, points, i, len$$1, len$$1,
  24252. 1, result.min, result.max, shape.smooth,
  24253. shape.smoothMonotone, shape.connectNulls
  24254. ) + 1;
  24255. }
  24256. }
  24257. });
  24258. var Polygon$1 = Path.extend({
  24259. type: 'ec-polygon',
  24260. shape: {
  24261. points: [],
  24262. // Offset between stacked base points and points
  24263. stackedOnPoints: [],
  24264. smooth: 0,
  24265. stackedOnSmooth: 0,
  24266. smoothConstraint: true,
  24267. smoothMonotone: null,
  24268. connectNulls: false
  24269. },
  24270. brush: fixClipWithShadow(Path.prototype.brush),
  24271. buildPath: function (ctx, shape) {
  24272. var points = shape.points;
  24273. var stackedOnPoints = shape.stackedOnPoints;
  24274. var i = 0;
  24275. var len$$1 = points.length;
  24276. var smoothMonotone = shape.smoothMonotone;
  24277. var bbox = getBoundingBox(points, shape.smoothConstraint);
  24278. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  24279. if (shape.connectNulls) {
  24280. // Must remove first and last null values avoid draw error in polygon
  24281. for (; len$$1 > 0; len$$1--) {
  24282. if (!isPointNull(points[len$$1 - 1])) {
  24283. break;
  24284. }
  24285. }
  24286. for (; i < len$$1; i++) {
  24287. if (!isPointNull(points[i])) {
  24288. break;
  24289. }
  24290. }
  24291. }
  24292. while (i < len$$1) {
  24293. var k = drawSegment(
  24294. ctx, points, i, len$$1, len$$1,
  24295. 1, bbox.min, bbox.max, shape.smooth,
  24296. smoothMonotone, shape.connectNulls
  24297. );
  24298. drawSegment(
  24299. ctx, stackedOnPoints, i + k - 1, k, len$$1,
  24300. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  24301. smoothMonotone, shape.connectNulls
  24302. );
  24303. i += k + 1;
  24304. ctx.closePath();
  24305. }
  24306. }
  24307. });
  24308. // FIXME step not support polar
  24309. function isPointsSame(points1, points2) {
  24310. if (points1.length !== points2.length) {
  24311. return;
  24312. }
  24313. for (var i = 0; i < points1.length; i++) {
  24314. var p1 = points1[i];
  24315. var p2 = points2[i];
  24316. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  24317. return;
  24318. }
  24319. }
  24320. return true;
  24321. }
  24322. function getSmooth(smooth) {
  24323. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.3 : 0);
  24324. }
  24325. function getAxisExtentWithGap(axis) {
  24326. var extent = axis.getGlobalExtent();
  24327. if (axis.onBand) {
  24328. // Remove extra 1px to avoid line miter in clipped edge
  24329. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  24330. var dir = extent[1] > extent[0] ? 1 : -1;
  24331. extent[0] += dir * halfBandWidth;
  24332. extent[1] -= dir * halfBandWidth;
  24333. }
  24334. return extent;
  24335. }
  24336. function sign(val) {
  24337. return val >= 0 ? 1 : -1;
  24338. }
  24339. /**
  24340. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  24341. * @param {module:echarts/data/List} data
  24342. * @param {Array.<Array.<number>>} points
  24343. * @private
  24344. */
  24345. function getStackedOnPoints(coordSys, data) {
  24346. var baseAxis = coordSys.getBaseAxis();
  24347. var valueAxis = coordSys.getOtherAxis(baseAxis);
  24348. var valueStart = 0;
  24349. if (!baseAxis.onZero) {
  24350. var extent = valueAxis.scale.getExtent();
  24351. if (extent[0] > 0) {
  24352. // Both positive
  24353. valueStart = extent[0];
  24354. }
  24355. else if (extent[1] < 0) {
  24356. // Both negative
  24357. valueStart = extent[1];
  24358. }
  24359. // If is one positive, and one negative, onZero shall be true
  24360. }
  24361. var valueDim = valueAxis.dim;
  24362. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  24363. return data.mapArray([valueDim], function (val, idx) {
  24364. var stackedOnSameSign;
  24365. var stackedOn = data.stackedOn;
  24366. // Find first stacked value with same sign
  24367. while (stackedOn &&
  24368. sign(stackedOn.get(valueDim, idx)) === sign(val)
  24369. ) {
  24370. stackedOnSameSign = stackedOn;
  24371. break;
  24372. }
  24373. var stackedData = [];
  24374. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  24375. stackedData[1 - baseDataOffset] = stackedOnSameSign
  24376. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  24377. return coordSys.dataToPoint(stackedData);
  24378. }, true);
  24379. }
  24380. function createGridClipShape(cartesian, hasAnimation, seriesModel) {
  24381. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  24382. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  24383. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  24384. var x = Math.min(xExtent[0], xExtent[1]);
  24385. var y = Math.min(yExtent[0], yExtent[1]);
  24386. var width = Math.max(xExtent[0], xExtent[1]) - x;
  24387. var height = Math.max(yExtent[0], yExtent[1]) - y;
  24388. var lineWidth = seriesModel.get('lineStyle.normal.width') || 2;
  24389. // Expand clip shape to avoid clipping when line value exceeds axis
  24390. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  24391. if (isHorizontal) {
  24392. y -= expandSize;
  24393. height += expandSize * 2;
  24394. }
  24395. else {
  24396. x -= expandSize;
  24397. width += expandSize * 2;
  24398. }
  24399. var clipPath = new Rect({
  24400. shape: {
  24401. x: x,
  24402. y: y,
  24403. width: width,
  24404. height: height
  24405. }
  24406. });
  24407. if (hasAnimation) {
  24408. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  24409. initProps(clipPath, {
  24410. shape: {
  24411. width: width,
  24412. height: height
  24413. }
  24414. }, seriesModel);
  24415. }
  24416. return clipPath;
  24417. }
  24418. function createPolarClipShape(polar, hasAnimation, seriesModel) {
  24419. var angleAxis = polar.getAngleAxis();
  24420. var radiusAxis = polar.getRadiusAxis();
  24421. var radiusExtent = radiusAxis.getExtent();
  24422. var angleExtent = angleAxis.getExtent();
  24423. var RADIAN = Math.PI / 180;
  24424. var clipPath = new Sector({
  24425. shape: {
  24426. cx: polar.cx,
  24427. cy: polar.cy,
  24428. r0: radiusExtent[0],
  24429. r: radiusExtent[1],
  24430. startAngle: -angleExtent[0] * RADIAN,
  24431. endAngle: -angleExtent[1] * RADIAN,
  24432. clockwise: angleAxis.inverse
  24433. }
  24434. });
  24435. if (hasAnimation) {
  24436. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  24437. initProps(clipPath, {
  24438. shape: {
  24439. endAngle: -angleExtent[1] * RADIAN
  24440. }
  24441. }, seriesModel);
  24442. }
  24443. return clipPath;
  24444. }
  24445. function createClipShape(coordSys, hasAnimation, seriesModel) {
  24446. return coordSys.type === 'polar'
  24447. ? createPolarClipShape(coordSys, hasAnimation, seriesModel)
  24448. : createGridClipShape(coordSys, hasAnimation, seriesModel);
  24449. }
  24450. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  24451. var baseAxis = coordSys.getBaseAxis();
  24452. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  24453. var stepPoints = [];
  24454. for (var i = 0; i < points.length - 1; i++) {
  24455. var nextPt = points[i + 1];
  24456. var pt = points[i];
  24457. stepPoints.push(pt);
  24458. var stepPt = [];
  24459. switch (stepTurnAt) {
  24460. case 'end':
  24461. stepPt[baseIndex] = nextPt[baseIndex];
  24462. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  24463. // default is start
  24464. stepPoints.push(stepPt);
  24465. break;
  24466. case 'middle':
  24467. // default is start
  24468. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  24469. var stepPt2 = [];
  24470. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  24471. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  24472. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  24473. stepPoints.push(stepPt);
  24474. stepPoints.push(stepPt2);
  24475. break;
  24476. default:
  24477. stepPt[baseIndex] = pt[baseIndex];
  24478. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  24479. // default is start
  24480. stepPoints.push(stepPt);
  24481. }
  24482. }
  24483. // Last points
  24484. points[i] && stepPoints.push(points[i]);
  24485. return stepPoints;
  24486. }
  24487. function getVisualGradient(data, coordSys) {
  24488. var visualMetaList = data.getVisual('visualMeta');
  24489. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  24490. // When data.count() is 0, gradient range can not be calculated.
  24491. return;
  24492. }
  24493. var visualMeta;
  24494. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  24495. // Can only be x or y
  24496. if (visualMetaList[i].dimension < 2) {
  24497. visualMeta = visualMetaList[i];
  24498. break;
  24499. }
  24500. }
  24501. if (!visualMeta || coordSys.type !== 'cartesian2d') {
  24502. if (__DEV__) {
  24503. console.warn('Visual map on line style only support x or y dimension.');
  24504. }
  24505. return;
  24506. }
  24507. // If the area to be rendered is bigger than area defined by LinearGradient,
  24508. // the canvas spec prescribes that the color of the first stop and the last
  24509. // stop should be used. But if two stops are added at offset 0, in effect
  24510. // browsers use the color of the second stop to render area outside
  24511. // LinearGradient. So we can only infinitesimally extend area defined in
  24512. // LinearGradient to render `outerColors`.
  24513. var dimension = visualMeta.dimension;
  24514. var dimName = data.dimensions[dimension];
  24515. var axis = coordSys.getAxis(dimName);
  24516. // dataToCoor mapping may not be linear, but must be monotonic.
  24517. var colorStops = map(visualMeta.stops, function (stop) {
  24518. return {
  24519. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  24520. color: stop.color
  24521. };
  24522. });
  24523. var stopLen = colorStops.length;
  24524. var outerColors = visualMeta.outerColors.slice();
  24525. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  24526. colorStops.reverse();
  24527. outerColors.reverse();
  24528. }
  24529. var tinyExtent = 10; // Arbitrary value: 10px
  24530. var minCoord = colorStops[0].coord - tinyExtent;
  24531. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  24532. var coordSpan = maxCoord - minCoord;
  24533. if (coordSpan < 1e-3) {
  24534. return 'transparent';
  24535. }
  24536. each$1(colorStops, function (stop) {
  24537. stop.offset = (stop.coord - minCoord) / coordSpan;
  24538. });
  24539. colorStops.push({
  24540. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  24541. color: outerColors[1] || 'transparent'
  24542. });
  24543. colorStops.unshift({ // notice colorStops.length have been changed.
  24544. offset: stopLen ? colorStops[0].offset : 0.5,
  24545. color: outerColors[0] || 'transparent'
  24546. });
  24547. // zrUtil.each(colorStops, function (colorStop) {
  24548. // // Make sure each offset has rounded px to avoid not sharp edge
  24549. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  24550. // });
  24551. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  24552. gradient[dimName] = minCoord;
  24553. gradient[dimName + '2'] = maxCoord;
  24554. return gradient;
  24555. }
  24556. Chart.extend({
  24557. type: 'line',
  24558. init: function () {
  24559. var lineGroup = new Group();
  24560. var symbolDraw = new SymbolDraw();
  24561. this.group.add(symbolDraw.group);
  24562. this._symbolDraw = symbolDraw;
  24563. this._lineGroup = lineGroup;
  24564. },
  24565. render: function (seriesModel, ecModel, api) {
  24566. var coordSys = seriesModel.coordinateSystem;
  24567. var group = this.group;
  24568. var data = seriesModel.getData();
  24569. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  24570. var areaStyleModel = seriesModel.getModel('areaStyle.normal');
  24571. var points = data.mapArray(data.getItemLayout, true);
  24572. var isCoordSysPolar = coordSys.type === 'polar';
  24573. var prevCoordSys = this._coordSys;
  24574. var symbolDraw = this._symbolDraw;
  24575. var polyline = this._polyline;
  24576. var polygon = this._polygon;
  24577. var lineGroup = this._lineGroup;
  24578. var hasAnimation = seriesModel.get('animation');
  24579. var isAreaChart = !areaStyleModel.isEmpty();
  24580. var stackedOnPoints = getStackedOnPoints(coordSys, data);
  24581. var showSymbol = seriesModel.get('showSymbol');
  24582. var isSymbolIgnore = showSymbol && !isCoordSysPolar && !seriesModel.get('showAllSymbol')
  24583. && this._getSymbolIgnoreFunc(data, coordSys);
  24584. // Remove temporary symbols
  24585. var oldData = this._data;
  24586. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  24587. if (el.__temp) {
  24588. group.remove(el);
  24589. oldData.setItemGraphicEl(idx, null);
  24590. }
  24591. });
  24592. // Remove previous created symbols if showSymbol changed to false
  24593. if (!showSymbol) {
  24594. symbolDraw.remove();
  24595. }
  24596. group.add(lineGroup);
  24597. // FIXME step not support polar
  24598. var step = !isCoordSysPolar && seriesModel.get('step');
  24599. // Initialization animation or coordinate system changed
  24600. if (
  24601. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  24602. ) {
  24603. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  24604. if (step) {
  24605. // TODO If stacked series is not step
  24606. points = turnPointsIntoStep(points, coordSys, step);
  24607. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  24608. }
  24609. polyline = this._newPolyline(points, coordSys, hasAnimation);
  24610. if (isAreaChart) {
  24611. polygon = this._newPolygon(
  24612. points, stackedOnPoints,
  24613. coordSys, hasAnimation
  24614. );
  24615. }
  24616. lineGroup.setClipPath(createClipShape(coordSys, true, seriesModel));
  24617. }
  24618. else {
  24619. if (isAreaChart && !polygon) {
  24620. // If areaStyle is added
  24621. polygon = this._newPolygon(
  24622. points, stackedOnPoints,
  24623. coordSys, hasAnimation
  24624. );
  24625. }
  24626. else if (polygon && !isAreaChart) {
  24627. // If areaStyle is removed
  24628. lineGroup.remove(polygon);
  24629. polygon = this._polygon = null;
  24630. }
  24631. // Update clipPath
  24632. lineGroup.setClipPath(createClipShape(coordSys, false, seriesModel));
  24633. // Always update, or it is wrong in the case turning on legend
  24634. // because points are not changed
  24635. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  24636. // Stop symbol animation and sync with line points
  24637. // FIXME performance?
  24638. data.eachItemGraphicEl(function (el) {
  24639. el.stopAnimation(true);
  24640. });
  24641. // In the case data zoom triggerred refreshing frequently
  24642. // Data may not change if line has a category axis. So it should animate nothing
  24643. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  24644. || !isPointsSame(this._points, points)
  24645. ) {
  24646. if (hasAnimation) {
  24647. this._updateAnimation(
  24648. data, stackedOnPoints, coordSys, api, step
  24649. );
  24650. }
  24651. else {
  24652. // Not do it in update with animation
  24653. if (step) {
  24654. // TODO If stacked series is not step
  24655. points = turnPointsIntoStep(points, coordSys, step);
  24656. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  24657. }
  24658. polyline.setShape({
  24659. points: points
  24660. });
  24661. polygon && polygon.setShape({
  24662. points: points,
  24663. stackedOnPoints: stackedOnPoints
  24664. });
  24665. }
  24666. }
  24667. }
  24668. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  24669. polyline.useStyle(defaults(
  24670. // Use color in lineStyle first
  24671. lineStyleModel.getLineStyle(),
  24672. {
  24673. fill: 'none',
  24674. stroke: visualColor,
  24675. lineJoin: 'bevel'
  24676. }
  24677. ));
  24678. var smooth = seriesModel.get('smooth');
  24679. smooth = getSmooth(seriesModel.get('smooth'));
  24680. polyline.setShape({
  24681. smooth: smooth,
  24682. smoothMonotone: seriesModel.get('smoothMonotone'),
  24683. connectNulls: seriesModel.get('connectNulls')
  24684. });
  24685. if (polygon) {
  24686. var stackedOn = data.stackedOn;
  24687. var stackedOnSmooth = 0;
  24688. polygon.useStyle(defaults(
  24689. areaStyleModel.getAreaStyle(),
  24690. {
  24691. fill: visualColor,
  24692. opacity: 0.7,
  24693. lineJoin: 'bevel'
  24694. }
  24695. ));
  24696. if (stackedOn) {
  24697. var stackedOnSeries = stackedOn.hostModel;
  24698. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  24699. }
  24700. polygon.setShape({
  24701. smooth: smooth,
  24702. stackedOnSmooth: stackedOnSmooth,
  24703. smoothMonotone: seriesModel.get('smoothMonotone'),
  24704. connectNulls: seriesModel.get('connectNulls')
  24705. });
  24706. }
  24707. this._data = data;
  24708. // Save the coordinate system for transition animation when data changed
  24709. this._coordSys = coordSys;
  24710. this._stackedOnPoints = stackedOnPoints;
  24711. this._points = points;
  24712. this._step = step;
  24713. },
  24714. dispose: function () {},
  24715. highlight: function (seriesModel, ecModel, api, payload) {
  24716. var data = seriesModel.getData();
  24717. var dataIndex = queryDataIndex(data, payload);
  24718. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  24719. var symbol = data.getItemGraphicEl(dataIndex);
  24720. if (!symbol) {
  24721. // Create a temporary symbol if it is not exists
  24722. var pt = data.getItemLayout(dataIndex);
  24723. if (!pt) {
  24724. // Null data
  24725. return;
  24726. }
  24727. symbol = new SymbolClz$1(data, dataIndex);
  24728. symbol.position = pt;
  24729. symbol.setZ(
  24730. seriesModel.get('zlevel'),
  24731. seriesModel.get('z')
  24732. );
  24733. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  24734. symbol.__temp = true;
  24735. data.setItemGraphicEl(dataIndex, symbol);
  24736. // Stop scale animation
  24737. symbol.stopSymbolAnimation(true);
  24738. this.group.add(symbol);
  24739. }
  24740. symbol.highlight();
  24741. }
  24742. else {
  24743. // Highlight whole series
  24744. Chart.prototype.highlight.call(
  24745. this, seriesModel, ecModel, api, payload
  24746. );
  24747. }
  24748. },
  24749. downplay: function (seriesModel, ecModel, api, payload) {
  24750. var data = seriesModel.getData();
  24751. var dataIndex = queryDataIndex(data, payload);
  24752. if (dataIndex != null && dataIndex >= 0) {
  24753. var symbol = data.getItemGraphicEl(dataIndex);
  24754. if (symbol) {
  24755. if (symbol.__temp) {
  24756. data.setItemGraphicEl(dataIndex, null);
  24757. this.group.remove(symbol);
  24758. }
  24759. else {
  24760. symbol.downplay();
  24761. }
  24762. }
  24763. }
  24764. else {
  24765. // FIXME
  24766. // can not downplay completely.
  24767. // Downplay whole series
  24768. Chart.prototype.downplay.call(
  24769. this, seriesModel, ecModel, api, payload
  24770. );
  24771. }
  24772. },
  24773. /**
  24774. * @param {module:zrender/container/Group} group
  24775. * @param {Array.<Array.<number>>} points
  24776. * @private
  24777. */
  24778. _newPolyline: function (points) {
  24779. var polyline = this._polyline;
  24780. // Remove previous created polyline
  24781. if (polyline) {
  24782. this._lineGroup.remove(polyline);
  24783. }
  24784. polyline = new Polyline$1({
  24785. shape: {
  24786. points: points
  24787. },
  24788. silent: true,
  24789. z2: 10
  24790. });
  24791. this._lineGroup.add(polyline);
  24792. this._polyline = polyline;
  24793. return polyline;
  24794. },
  24795. /**
  24796. * @param {module:zrender/container/Group} group
  24797. * @param {Array.<Array.<number>>} stackedOnPoints
  24798. * @param {Array.<Array.<number>>} points
  24799. * @private
  24800. */
  24801. _newPolygon: function (points, stackedOnPoints) {
  24802. var polygon = this._polygon;
  24803. // Remove previous created polygon
  24804. if (polygon) {
  24805. this._lineGroup.remove(polygon);
  24806. }
  24807. polygon = new Polygon$1({
  24808. shape: {
  24809. points: points,
  24810. stackedOnPoints: stackedOnPoints
  24811. },
  24812. silent: true
  24813. });
  24814. this._lineGroup.add(polygon);
  24815. this._polygon = polygon;
  24816. return polygon;
  24817. },
  24818. /**
  24819. * @private
  24820. */
  24821. _getSymbolIgnoreFunc: function (data, coordSys) {
  24822. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  24823. // `getLabelInterval` is provided by echarts/component/axis
  24824. if (categoryAxis && categoryAxis.isLabelIgnored) {
  24825. return bind(categoryAxis.isLabelIgnored, categoryAxis);
  24826. }
  24827. },
  24828. /**
  24829. * @private
  24830. */
  24831. // FIXME Two value axis
  24832. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step) {
  24833. var polyline = this._polyline;
  24834. var polygon = this._polygon;
  24835. var seriesModel = data.hostModel;
  24836. var diff = lineAnimationDiff(
  24837. this._data, data,
  24838. this._stackedOnPoints, stackedOnPoints,
  24839. this._coordSys, coordSys
  24840. );
  24841. var current = diff.current;
  24842. var stackedOnCurrent = diff.stackedOnCurrent;
  24843. var next = diff.next;
  24844. var stackedOnNext = diff.stackedOnNext;
  24845. if (step) {
  24846. // TODO If stacked series is not step
  24847. current = turnPointsIntoStep(diff.current, coordSys, step);
  24848. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  24849. next = turnPointsIntoStep(diff.next, coordSys, step);
  24850. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  24851. }
  24852. // `diff.current` is subset of `current` (which should be ensured by
  24853. // turnPointsIntoStep), so points in `__points` can be updated when
  24854. // points in `current` are update during animation.
  24855. polyline.shape.__points = diff.current;
  24856. polyline.shape.points = current;
  24857. updateProps(polyline, {
  24858. shape: {
  24859. points: next
  24860. }
  24861. }, seriesModel);
  24862. if (polygon) {
  24863. polygon.setShape({
  24864. points: current,
  24865. stackedOnPoints: stackedOnCurrent
  24866. });
  24867. updateProps(polygon, {
  24868. shape: {
  24869. points: next,
  24870. stackedOnPoints: stackedOnNext
  24871. }
  24872. }, seriesModel);
  24873. }
  24874. var updatedDataInfo = [];
  24875. var diffStatus = diff.status;
  24876. for (var i = 0; i < diffStatus.length; i++) {
  24877. var cmd = diffStatus[i].cmd;
  24878. if (cmd === '=') {
  24879. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  24880. if (el) {
  24881. updatedDataInfo.push({
  24882. el: el,
  24883. ptIdx: i // Index of points
  24884. });
  24885. }
  24886. }
  24887. }
  24888. if (polyline.animators && polyline.animators.length) {
  24889. polyline.animators[0].during(function () {
  24890. for (var i = 0; i < updatedDataInfo.length; i++) {
  24891. var el = updatedDataInfo[i].el;
  24892. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  24893. }
  24894. });
  24895. }
  24896. },
  24897. remove: function (ecModel) {
  24898. var group = this.group;
  24899. var oldData = this._data;
  24900. this._lineGroup.removeAll();
  24901. this._symbolDraw.remove(true);
  24902. // Remove temporary created elements when highlighting
  24903. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  24904. if (el.__temp) {
  24905. group.remove(el);
  24906. oldData.setItemGraphicEl(idx, null);
  24907. }
  24908. });
  24909. this._polyline =
  24910. this._polygon =
  24911. this._coordSys =
  24912. this._points =
  24913. this._stackedOnPoints =
  24914. this._data = null;
  24915. }
  24916. });
  24917. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol, ecModel, api) {
  24918. // Encoding visual for all series include which is filtered for legend drawing
  24919. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  24920. var data = seriesModel.getData();
  24921. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  24922. var symbolSize = seriesModel.get('symbolSize');
  24923. data.setVisual({
  24924. legendSymbol: legendSymbol || symbolType,
  24925. symbol: symbolType,
  24926. symbolSize: symbolSize
  24927. });
  24928. // Only visible series has each data be visual encoded
  24929. if (!ecModel.isSeriesFiltered(seriesModel)) {
  24930. if (typeof symbolSize === 'function') {
  24931. data.each(function (idx) {
  24932. var rawValue = seriesModel.getRawValue(idx);
  24933. // FIXME
  24934. var params = seriesModel.getDataParams(idx);
  24935. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  24936. });
  24937. }
  24938. data.each(function (idx) {
  24939. var itemModel = data.getItemModel(idx);
  24940. var itemSymbolType = itemModel.getShallow('symbol', true);
  24941. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  24942. // If has item symbol
  24943. if (itemSymbolType != null) {
  24944. data.setItemVisual(idx, 'symbol', itemSymbolType);
  24945. }
  24946. if (itemSymbolSize != null) {
  24947. // PENDING Transform symbolSize ?
  24948. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  24949. }
  24950. });
  24951. }
  24952. });
  24953. };
  24954. var layoutPoints = function (seriesType, ecModel) {
  24955. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  24956. var data = seriesModel.getData();
  24957. var coordSys = seriesModel.coordinateSystem;
  24958. if (!coordSys) {
  24959. return;
  24960. }
  24961. var dims = [];
  24962. var coordDims = coordSys.dimensions;
  24963. for (var i = 0; i < coordDims.length; i++) {
  24964. dims.push(seriesModel.coordDimToDataDim(coordSys.dimensions[i])[0]);
  24965. }
  24966. if (dims.length === 1) {
  24967. data.each(dims[0], function (x, idx) {
  24968. // Also {Array.<number>}, not undefined to avoid if...else... statement
  24969. data.setItemLayout(idx, isNaN(x) ? [NaN, NaN] : coordSys.dataToPoint(x));
  24970. });
  24971. }
  24972. else if (dims.length === 2) {
  24973. data.each(dims, function (x, y, idx) {
  24974. // Also {Array.<number>}, not undefined to avoid if...else... statement
  24975. data.setItemLayout(
  24976. idx, (isNaN(x) || isNaN(y)) ? [NaN, NaN] : coordSys.dataToPoint([x, y])
  24977. );
  24978. }, true);
  24979. }
  24980. });
  24981. };
  24982. var samplers = {
  24983. average: function (frame) {
  24984. var sum = 0;
  24985. var count = 0;
  24986. for (var i = 0; i < frame.length; i++) {
  24987. if (!isNaN(frame[i])) {
  24988. sum += frame[i];
  24989. count++;
  24990. }
  24991. }
  24992. // Return NaN if count is 0
  24993. return count === 0 ? NaN : sum / count;
  24994. },
  24995. sum: function (frame) {
  24996. var sum = 0;
  24997. for (var i = 0; i < frame.length; i++) {
  24998. // Ignore NaN
  24999. sum += frame[i] || 0;
  25000. }
  25001. return sum;
  25002. },
  25003. max: function (frame) {
  25004. var max = -Infinity;
  25005. for (var i = 0; i < frame.length; i++) {
  25006. frame[i] > max && (max = frame[i]);
  25007. }
  25008. return max;
  25009. },
  25010. min: function (frame) {
  25011. var min = Infinity;
  25012. for (var i = 0; i < frame.length; i++) {
  25013. frame[i] < min && (min = frame[i]);
  25014. }
  25015. return min;
  25016. },
  25017. // TODO
  25018. // Median
  25019. nearest: function (frame) {
  25020. return frame[0];
  25021. }
  25022. };
  25023. var indexSampler = function (frame, value) {
  25024. return Math.round(frame.length / 2);
  25025. };
  25026. var dataSample = function (seriesType, ecModel, api) {
  25027. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  25028. var data = seriesModel.getData();
  25029. var sampling = seriesModel.get('sampling');
  25030. var coordSys = seriesModel.coordinateSystem;
  25031. // Only cartesian2d support down sampling
  25032. if (coordSys.type === 'cartesian2d' && sampling) {
  25033. var baseAxis = coordSys.getBaseAxis();
  25034. var valueAxis = coordSys.getOtherAxis(baseAxis);
  25035. var extent = baseAxis.getExtent();
  25036. // Coordinste system has been resized
  25037. var size = extent[1] - extent[0];
  25038. var rate = Math.round(data.count() / size);
  25039. if (rate > 1) {
  25040. var sampler;
  25041. if (typeof sampling === 'string') {
  25042. sampler = samplers[sampling];
  25043. }
  25044. else if (typeof sampling === 'function') {
  25045. sampler = sampling;
  25046. }
  25047. if (sampler) {
  25048. data = data.downSample(
  25049. valueAxis.dim, 1 / rate, sampler, indexSampler
  25050. );
  25051. seriesModel.setData(data);
  25052. }
  25053. }
  25054. }
  25055. }, this);
  25056. };
  25057. /**
  25058. * Cartesian coordinate system
  25059. * @module echarts/coord/Cartesian
  25060. *
  25061. */
  25062. function dimAxisMapper(dim) {
  25063. return this._axes[dim];
  25064. }
  25065. /**
  25066. * @alias module:echarts/coord/Cartesian
  25067. * @constructor
  25068. */
  25069. var Cartesian = function (name) {
  25070. this._axes = {};
  25071. this._dimList = [];
  25072. /**
  25073. * @type {string}
  25074. */
  25075. this.name = name || '';
  25076. };
  25077. Cartesian.prototype = {
  25078. constructor: Cartesian,
  25079. type: 'cartesian',
  25080. /**
  25081. * Get axis
  25082. * @param {number|string} dim
  25083. * @return {module:echarts/coord/Cartesian~Axis}
  25084. */
  25085. getAxis: function (dim) {
  25086. return this._axes[dim];
  25087. },
  25088. /**
  25089. * Get axes list
  25090. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  25091. */
  25092. getAxes: function () {
  25093. return map(this._dimList, dimAxisMapper, this);
  25094. },
  25095. /**
  25096. * Get axes list by given scale type
  25097. */
  25098. getAxesByScale: function (scaleType) {
  25099. scaleType = scaleType.toLowerCase();
  25100. return filter(
  25101. this.getAxes(),
  25102. function (axis) {
  25103. return axis.scale.type === scaleType;
  25104. }
  25105. );
  25106. },
  25107. /**
  25108. * Add axis
  25109. * @param {module:echarts/coord/Cartesian.Axis}
  25110. */
  25111. addAxis: function (axis) {
  25112. var dim = axis.dim;
  25113. this._axes[dim] = axis;
  25114. this._dimList.push(dim);
  25115. },
  25116. /**
  25117. * Convert data to coord in nd space
  25118. * @param {Array.<number>|Object.<string, number>} val
  25119. * @return {Array.<number>|Object.<string, number>}
  25120. */
  25121. dataToCoord: function (val) {
  25122. return this._dataCoordConvert(val, 'dataToCoord');
  25123. },
  25124. /**
  25125. * Convert coord in nd space to data
  25126. * @param {Array.<number>|Object.<string, number>} val
  25127. * @return {Array.<number>|Object.<string, number>}
  25128. */
  25129. coordToData: function (val) {
  25130. return this._dataCoordConvert(val, 'coordToData');
  25131. },
  25132. _dataCoordConvert: function (input, method) {
  25133. var dimList = this._dimList;
  25134. var output = input instanceof Array ? [] : {};
  25135. for (var i = 0; i < dimList.length; i++) {
  25136. var dim = dimList[i];
  25137. var axis = this._axes[dim];
  25138. output[dim] = axis[method](input[dim]);
  25139. }
  25140. return output;
  25141. }
  25142. };
  25143. function Cartesian2D(name) {
  25144. Cartesian.call(this, name);
  25145. }
  25146. Cartesian2D.prototype = {
  25147. constructor: Cartesian2D,
  25148. type: 'cartesian2d',
  25149. /**
  25150. * @type {Array.<string>}
  25151. * @readOnly
  25152. */
  25153. dimensions: ['x', 'y'],
  25154. /**
  25155. * Base axis will be used on stacking.
  25156. *
  25157. * @return {module:echarts/coord/cartesian/Axis2D}
  25158. */
  25159. getBaseAxis: function () {
  25160. return this.getAxesByScale('ordinal')[0]
  25161. || this.getAxesByScale('time')[0]
  25162. || this.getAxis('x');
  25163. },
  25164. /**
  25165. * If contain point
  25166. * @param {Array.<number>} point
  25167. * @return {boolean}
  25168. */
  25169. containPoint: function (point) {
  25170. var axisX = this.getAxis('x');
  25171. var axisY = this.getAxis('y');
  25172. return axisX.contain(axisX.toLocalCoord(point[0]))
  25173. && axisY.contain(axisY.toLocalCoord(point[1]));
  25174. },
  25175. /**
  25176. * If contain data
  25177. * @param {Array.<number>} data
  25178. * @return {boolean}
  25179. */
  25180. containData: function (data) {
  25181. return this.getAxis('x').containData(data[0])
  25182. && this.getAxis('y').containData(data[1]);
  25183. },
  25184. /**
  25185. * @param {Array.<number>} data
  25186. * @param {boolean} [clamp=false]
  25187. * @return {Array.<number>}
  25188. */
  25189. dataToPoint: function (data, clamp) {
  25190. var xAxis = this.getAxis('x');
  25191. var yAxis = this.getAxis('y');
  25192. return [
  25193. xAxis.toGlobalCoord(xAxis.dataToCoord(data[0], clamp)),
  25194. yAxis.toGlobalCoord(yAxis.dataToCoord(data[1], clamp))
  25195. ];
  25196. },
  25197. /**
  25198. * @param {Array.<number>} point
  25199. * @param {boolean} [clamp=false]
  25200. * @return {Array.<number>}
  25201. */
  25202. pointToData: function (point, clamp) {
  25203. var xAxis = this.getAxis('x');
  25204. var yAxis = this.getAxis('y');
  25205. return [
  25206. xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp),
  25207. yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp)
  25208. ];
  25209. },
  25210. /**
  25211. * Get other axis
  25212. * @param {module:echarts/coord/cartesian/Axis2D} axis
  25213. */
  25214. getOtherAxis: function (axis) {
  25215. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  25216. }
  25217. };
  25218. inherits(Cartesian2D, Cartesian);
  25219. /**
  25220. * Extend axis 2d
  25221. * @constructor module:echarts/coord/cartesian/Axis2D
  25222. * @extends {module:echarts/coord/cartesian/Axis}
  25223. * @param {string} dim
  25224. * @param {*} scale
  25225. * @param {Array.<number>} coordExtent
  25226. * @param {string} axisType
  25227. * @param {string} position
  25228. */
  25229. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  25230. Axis.call(this, dim, scale, coordExtent);
  25231. /**
  25232. * Axis type
  25233. * - 'category'
  25234. * - 'value'
  25235. * - 'time'
  25236. * - 'log'
  25237. * @type {string}
  25238. */
  25239. this.type = axisType || 'value';
  25240. /**
  25241. * Axis position
  25242. * - 'top'
  25243. * - 'bottom'
  25244. * - 'left'
  25245. * - 'right'
  25246. */
  25247. this.position = position || 'bottom';
  25248. };
  25249. Axis2D.prototype = {
  25250. constructor: Axis2D,
  25251. /**
  25252. * Index of axis, can be used as key
  25253. */
  25254. index: 0,
  25255. /**
  25256. * If axis is on the zero position of the other axis
  25257. * @type {boolean}
  25258. */
  25259. onZero: false,
  25260. /**
  25261. * Axis model
  25262. * @param {module:echarts/coord/cartesian/AxisModel}
  25263. */
  25264. model: null,
  25265. isHorizontal: function () {
  25266. var position = this.position;
  25267. return position === 'top' || position === 'bottom';
  25268. },
  25269. /**
  25270. * Each item cooresponds to this.getExtent(), which
  25271. * means globalExtent[0] may greater than globalExtent[1],
  25272. * unless `asc` is input.
  25273. *
  25274. * @param {boolean} [asc]
  25275. * @return {Array.<number>}
  25276. */
  25277. getGlobalExtent: function (asc) {
  25278. var ret = this.getExtent();
  25279. ret[0] = this.toGlobalCoord(ret[0]);
  25280. ret[1] = this.toGlobalCoord(ret[1]);
  25281. asc && ret[0] > ret[1] && ret.reverse();
  25282. return ret;
  25283. },
  25284. getOtherAxis: function () {
  25285. this.grid.getOtherAxis();
  25286. },
  25287. /**
  25288. * If label is ignored.
  25289. * Automatically used when axis is category and label can not be all shown
  25290. * @param {number} idx
  25291. * @return {boolean}
  25292. */
  25293. isLabelIgnored: function (idx) {
  25294. if (this.type === 'category') {
  25295. var labelInterval = this.getLabelInterval();
  25296. return ((typeof labelInterval === 'function')
  25297. && !labelInterval(idx, this.scale.getLabel(idx)))
  25298. || idx % (labelInterval + 1);
  25299. }
  25300. },
  25301. /**
  25302. * @override
  25303. */
  25304. pointToData: function (point, clamp) {
  25305. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  25306. },
  25307. /**
  25308. * Transform global coord to local coord,
  25309. * i.e. var localCoord = axis.toLocalCoord(80);
  25310. * designate by module:echarts/coord/cartesian/Grid.
  25311. * @type {Function}
  25312. */
  25313. toLocalCoord: null,
  25314. /**
  25315. * Transform global coord to local coord,
  25316. * i.e. var globalCoord = axis.toLocalCoord(40);
  25317. * designate by module:echarts/coord/cartesian/Grid.
  25318. * @type {Function}
  25319. */
  25320. toGlobalCoord: null
  25321. };
  25322. inherits(Axis2D, Axis);
  25323. var defaultOption = {
  25324. show: true,
  25325. zlevel: 0, // 一级层叠
  25326. z: 0, // 二级层叠
  25327. // 反向坐标轴
  25328. inverse: false,
  25329. // 坐标轴名字,默认为空
  25330. name: '',
  25331. // 坐标轴名字位置,支持'start' | 'middle' | 'end'
  25332. nameLocation: 'end',
  25333. // 坐标轴名字旋转,degree。
  25334. nameRotate: null, // Adapt to axis rotate, when nameLocation is 'middle'.
  25335. nameTruncate: {
  25336. maxWidth: null,
  25337. ellipsis: '...',
  25338. placeholder: '.'
  25339. },
  25340. // 坐标轴文字样式,默认取全局样式
  25341. nameTextStyle: {},
  25342. // 文字与轴线距离
  25343. nameGap: 15,
  25344. silent: false, // Default false to support tooltip.
  25345. triggerEvent: false, // Default false to avoid legacy user event listener fail.
  25346. tooltip: {
  25347. show: false
  25348. },
  25349. axisPointer: {},
  25350. // 坐标轴线
  25351. axisLine: {
  25352. // 默认显示,属性show控制显示与否
  25353. show: true,
  25354. onZero: true,
  25355. onZeroAxisIndex: null,
  25356. // 属性lineStyle控制线条样式
  25357. lineStyle: {
  25358. color: '#333',
  25359. width: 1,
  25360. type: 'solid'
  25361. },
  25362. // 坐标轴两端的箭头
  25363. symbol: ['none', 'none'],
  25364. symbolSize: [10, 15]
  25365. },
  25366. // 坐标轴小标记
  25367. axisTick: {
  25368. // 属性show控制显示与否,默认显示
  25369. show: true,
  25370. // 控制小标记是否在grid里
  25371. inside: false,
  25372. // 属性length控制线长
  25373. length: 5,
  25374. // 属性lineStyle控制线条样式
  25375. lineStyle: {
  25376. width: 1
  25377. }
  25378. },
  25379. // 坐标轴文本标签,详见axis.axisLabel
  25380. axisLabel: {
  25381. show: true,
  25382. // 控制文本标签是否在grid里
  25383. inside: false,
  25384. rotate: 0,
  25385. showMinLabel: null, // true | false | null (auto)
  25386. showMaxLabel: null, // true | false | null (auto)
  25387. margin: 8,
  25388. // formatter: null,
  25389. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  25390. fontSize: 12
  25391. },
  25392. // 分隔线
  25393. splitLine: {
  25394. // 默认显示,属性show控制显示与否
  25395. show: true,
  25396. // 属性lineStyle(详见lineStyle)控制线条样式
  25397. lineStyle: {
  25398. color: ['#ccc'],
  25399. width: 1,
  25400. type: 'solid'
  25401. }
  25402. },
  25403. // 分隔区域
  25404. splitArea: {
  25405. // 默认不显示,属性show控制显示与否
  25406. show: false,
  25407. // 属性areaStyle(详见areaStyle)控制区域样式
  25408. areaStyle: {
  25409. color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
  25410. }
  25411. }
  25412. };
  25413. var axisDefault = {};
  25414. axisDefault.categoryAxis = merge({
  25415. // 类目起始和结束两端空白策略
  25416. boundaryGap: true,
  25417. // splitArea: {
  25418. // show: false
  25419. // },
  25420. splitLine: {
  25421. show: false
  25422. },
  25423. // 坐标轴小标记
  25424. axisTick: {
  25425. // If tick is align with label when boundaryGap is true
  25426. alignWithLabel: false,
  25427. interval: 'auto'
  25428. },
  25429. // 坐标轴文本标签,详见axis.axisLabel
  25430. axisLabel: {
  25431. interval: 'auto'
  25432. }
  25433. }, defaultOption);
  25434. axisDefault.valueAxis = merge({
  25435. // 数值起始和结束两端空白策略
  25436. boundaryGap: [0, 0],
  25437. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  25438. // min: null,
  25439. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  25440. // max: null,
  25441. // Readonly prop, specifies start value of the range when using data zoom.
  25442. // rangeStart: null
  25443. // Readonly prop, specifies end value of the range when using data zoom.
  25444. // rangeEnd: null
  25445. // 脱离0值比例,放大聚焦到最终_min,_max区间
  25446. // scale: false,
  25447. // 分割段数,默认为5
  25448. splitNumber: 5
  25449. // Minimum interval
  25450. // minInterval: null
  25451. // maxInterval: null
  25452. }, defaultOption);
  25453. // FIXME
  25454. axisDefault.timeAxis = defaults({
  25455. scale: true,
  25456. min: 'dataMin',
  25457. max: 'dataMax'
  25458. }, axisDefault.valueAxis);
  25459. axisDefault.logAxis = defaults({
  25460. scale: true,
  25461. logBase: 10
  25462. }, axisDefault.valueAxis);
  25463. // FIXME axisType is fixed ?
  25464. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  25465. /**
  25466. * Generate sub axis model class
  25467. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  25468. * @param {module:echarts/model/Component} BaseAxisModelClass
  25469. * @param {Function} axisTypeDefaulter
  25470. * @param {Object} [extraDefaultOption]
  25471. */
  25472. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  25473. each$1(AXIS_TYPES, function (axisType) {
  25474. BaseAxisModelClass.extend({
  25475. type: axisName + 'Axis.' + axisType,
  25476. mergeDefaultAndTheme: function (option, ecModel) {
  25477. var layoutMode = this.layoutMode;
  25478. var inputPositionParams = layoutMode
  25479. ? getLayoutParams(option) : {};
  25480. var themeModel = ecModel.getTheme();
  25481. merge(option, themeModel.get(axisType + 'Axis'));
  25482. merge(option, this.getDefaultOption());
  25483. option.type = axisTypeDefaulter(axisName, option);
  25484. if (layoutMode) {
  25485. mergeLayoutParam(option, inputPositionParams, layoutMode);
  25486. }
  25487. },
  25488. defaultOption: mergeAll(
  25489. [
  25490. {},
  25491. axisDefault[axisType + 'Axis'],
  25492. extraDefaultOption
  25493. ],
  25494. true
  25495. )
  25496. });
  25497. });
  25498. ComponentModel.registerSubTypeDefaulter(
  25499. axisName + 'Axis',
  25500. curry(axisTypeDefaulter, axisName)
  25501. );
  25502. };
  25503. var AxisModel = ComponentModel.extend({
  25504. type: 'cartesian2dAxis',
  25505. /**
  25506. * @type {module:echarts/coord/cartesian/Axis2D}
  25507. */
  25508. axis: null,
  25509. /**
  25510. * @override
  25511. */
  25512. init: function () {
  25513. AxisModel.superApply(this, 'init', arguments);
  25514. this.resetRange();
  25515. },
  25516. /**
  25517. * @override
  25518. */
  25519. mergeOption: function () {
  25520. AxisModel.superApply(this, 'mergeOption', arguments);
  25521. this.resetRange();
  25522. },
  25523. /**
  25524. * @override
  25525. */
  25526. restoreData: function () {
  25527. AxisModel.superApply(this, 'restoreData', arguments);
  25528. this.resetRange();
  25529. },
  25530. /**
  25531. * @override
  25532. * @return {module:echarts/model/Component}
  25533. */
  25534. getCoordSysModel: function () {
  25535. return this.ecModel.queryComponents({
  25536. mainType: 'grid',
  25537. index: this.option.gridIndex,
  25538. id: this.option.gridId
  25539. })[0];
  25540. }
  25541. });
  25542. function getAxisType(axisDim, option) {
  25543. // Default axis with data is category axis
  25544. return option.type || (option.data ? 'category' : 'value');
  25545. }
  25546. merge(AxisModel.prototype, axisModelCommonMixin);
  25547. var extraOption = {
  25548. // gridIndex: 0,
  25549. // gridId: '',
  25550. // Offset is for multiple axis on the same position
  25551. offset: 0
  25552. };
  25553. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  25554. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  25555. // Grid 是在有直角坐标系的时候必须要存在的
  25556. // 所以这里也要被 Cartesian2D 依赖
  25557. ComponentModel.extend({
  25558. type: 'grid',
  25559. dependencies: ['xAxis', 'yAxis'],
  25560. layoutMode: 'box',
  25561. /**
  25562. * @type {module:echarts/coord/cartesian/Grid}
  25563. */
  25564. coordinateSystem: null,
  25565. defaultOption: {
  25566. show: false,
  25567. zlevel: 0,
  25568. z: 0,
  25569. left: '10%',
  25570. top: 60,
  25571. right: '10%',
  25572. bottom: 60,
  25573. // If grid size contain label
  25574. containLabel: false,
  25575. // width: {totalWidth} - left - right,
  25576. // height: {totalHeight} - top - bottom,
  25577. backgroundColor: 'rgba(0,0,0,0)',
  25578. borderWidth: 1,
  25579. borderColor: '#ccc'
  25580. }
  25581. });
  25582. /**
  25583. * Grid is a region which contains at most 4 cartesian systems
  25584. *
  25585. * TODO Default cartesian
  25586. */
  25587. // Depends on GridModel, AxisModel, which performs preprocess.
  25588. var each$8 = each$1;
  25589. var ifAxisCrossZero$1 = ifAxisCrossZero;
  25590. var niceScaleExtent$1 = niceScaleExtent;
  25591. /**
  25592. * Check if the axis is used in the specified grid
  25593. * @inner
  25594. */
  25595. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  25596. return axisModel.getCoordSysModel() === gridModel;
  25597. }
  25598. function rotateTextRect(textRect, rotate) {
  25599. var rotateRadians = rotate * Math.PI / 180;
  25600. var boundingBox = textRect.plain();
  25601. var beforeWidth = boundingBox.width;
  25602. var beforeHeight = boundingBox.height;
  25603. var afterWidth = beforeWidth * Math.cos(rotateRadians) + beforeHeight * Math.sin(rotateRadians);
  25604. var afterHeight = beforeWidth * Math.sin(rotateRadians) + beforeHeight * Math.cos(rotateRadians);
  25605. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  25606. return rotatedRect;
  25607. }
  25608. function getLabelUnionRect(axis) {
  25609. var axisModel = axis.model;
  25610. var labels = axisModel.getFormattedLabels();
  25611. var axisLabelModel = axisModel.getModel('axisLabel');
  25612. var rect;
  25613. var step = 1;
  25614. var labelCount = labels.length;
  25615. if (labelCount > 40) {
  25616. // Simple optimization for large amount of labels
  25617. step = Math.ceil(labelCount / 40);
  25618. }
  25619. for (var i = 0; i < labelCount; i += step) {
  25620. if (!axis.isLabelIgnored(i)) {
  25621. var unrotatedSingleRect = axisLabelModel.getTextRect(labels[i]);
  25622. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  25623. rect ? rect.union(singleRect) : (rect = singleRect);
  25624. }
  25625. }
  25626. return rect;
  25627. }
  25628. function Grid(gridModel, ecModel, api) {
  25629. /**
  25630. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  25631. * @private
  25632. */
  25633. this._coordsMap = {};
  25634. /**
  25635. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  25636. * @private
  25637. */
  25638. this._coordsList = [];
  25639. /**
  25640. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  25641. * @private
  25642. */
  25643. this._axesMap = {};
  25644. /**
  25645. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  25646. * @private
  25647. */
  25648. this._axesList = [];
  25649. this._initCartesian(gridModel, ecModel, api);
  25650. this.model = gridModel;
  25651. }
  25652. var gridProto = Grid.prototype;
  25653. gridProto.type = 'grid';
  25654. gridProto.axisPointerEnabled = true;
  25655. gridProto.getRect = function () {
  25656. return this._rect;
  25657. };
  25658. gridProto.update = function (ecModel, api) {
  25659. var axesMap = this._axesMap;
  25660. this._updateScale(ecModel, this.model);
  25661. each$8(axesMap.x, function (xAxis) {
  25662. niceScaleExtent$1(xAxis.scale, xAxis.model);
  25663. });
  25664. each$8(axesMap.y, function (yAxis) {
  25665. niceScaleExtent$1(yAxis.scale, yAxis.model);
  25666. });
  25667. each$8(axesMap.x, function (xAxis) {
  25668. fixAxisOnZero(axesMap, 'y', xAxis);
  25669. });
  25670. each$8(axesMap.y, function (yAxis) {
  25671. fixAxisOnZero(axesMap, 'x', yAxis);
  25672. });
  25673. // Resize again if containLabel is enabled
  25674. // FIXME It may cause getting wrong grid size in data processing stage
  25675. this.resize(this.model, api);
  25676. };
  25677. function fixAxisOnZero(axesMap, otherAxisDim, axis) {
  25678. // onZero can not be enabled in these two situations:
  25679. // 1. When any other axis is a category axis.
  25680. // 2. When no axis is cross 0 point.
  25681. var axes = axesMap[otherAxisDim];
  25682. if (!axis.onZero) {
  25683. return;
  25684. }
  25685. var onZeroAxisIndex = axis.onZeroAxisIndex;
  25686. // If target axis is specified.
  25687. if (onZeroAxisIndex != null) {
  25688. var otherAxis = axes[onZeroAxisIndex];
  25689. if (otherAxis && canNotOnZeroToAxis(otherAxis)) {
  25690. axis.onZero = false;
  25691. }
  25692. return;
  25693. }
  25694. for (var idx in axes) {
  25695. if (axes.hasOwnProperty(idx)) {
  25696. var otherAxis = axes[idx];
  25697. if (otherAxis && !canNotOnZeroToAxis(otherAxis)) {
  25698. onZeroAxisIndex = +idx;
  25699. break;
  25700. }
  25701. }
  25702. }
  25703. if (onZeroAxisIndex == null) {
  25704. axis.onZero = false;
  25705. }
  25706. axis.onZeroAxisIndex = onZeroAxisIndex;
  25707. }
  25708. function canNotOnZeroToAxis(axis) {
  25709. return axis.type === 'category' || axis.type === 'time' || !ifAxisCrossZero$1(axis);
  25710. }
  25711. /**
  25712. * Resize the grid
  25713. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  25714. * @param {module:echarts/ExtensionAPI} api
  25715. */
  25716. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  25717. var gridRect = getLayoutRect(
  25718. gridModel.getBoxLayoutParams(), {
  25719. width: api.getWidth(),
  25720. height: api.getHeight()
  25721. });
  25722. this._rect = gridRect;
  25723. var axesList = this._axesList;
  25724. adjustAxes();
  25725. // Minus label size
  25726. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  25727. each$8(axesList, function (axis) {
  25728. if (!axis.model.get('axisLabel.inside')) {
  25729. var labelUnionRect = getLabelUnionRect(axis);
  25730. if (labelUnionRect) {
  25731. var dim = axis.isHorizontal() ? 'height' : 'width';
  25732. var margin = axis.model.get('axisLabel.margin');
  25733. gridRect[dim] -= labelUnionRect[dim] + margin;
  25734. if (axis.position === 'top') {
  25735. gridRect.y += labelUnionRect.height + margin;
  25736. }
  25737. else if (axis.position === 'left') {
  25738. gridRect.x += labelUnionRect.width + margin;
  25739. }
  25740. }
  25741. }
  25742. });
  25743. adjustAxes();
  25744. }
  25745. function adjustAxes() {
  25746. each$8(axesList, function (axis) {
  25747. var isHorizontal = axis.isHorizontal();
  25748. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  25749. var idx = axis.inverse ? 1 : 0;
  25750. axis.setExtent(extent[idx], extent[1 - idx]);
  25751. updateAxisTransfrom(axis, isHorizontal ? gridRect.x : gridRect.y);
  25752. });
  25753. }
  25754. };
  25755. /**
  25756. * @param {string} axisType
  25757. * @param {number} [axisIndex]
  25758. */
  25759. gridProto.getAxis = function (axisType, axisIndex) {
  25760. var axesMapOnDim = this._axesMap[axisType];
  25761. if (axesMapOnDim != null) {
  25762. if (axisIndex == null) {
  25763. // Find first axis
  25764. for (var name in axesMapOnDim) {
  25765. if (axesMapOnDim.hasOwnProperty(name)) {
  25766. return axesMapOnDim[name];
  25767. }
  25768. }
  25769. }
  25770. return axesMapOnDim[axisIndex];
  25771. }
  25772. };
  25773. /**
  25774. * @return {Array.<module:echarts/coord/Axis>}
  25775. */
  25776. gridProto.getAxes = function () {
  25777. return this._axesList.slice();
  25778. };
  25779. /**
  25780. * Usage:
  25781. * grid.getCartesian(xAxisIndex, yAxisIndex);
  25782. * grid.getCartesian(xAxisIndex);
  25783. * grid.getCartesian(null, yAxisIndex);
  25784. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  25785. *
  25786. * @param {number|Object} [xAxisIndex]
  25787. * @param {number} [yAxisIndex]
  25788. */
  25789. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  25790. if (xAxisIndex != null && yAxisIndex != null) {
  25791. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  25792. return this._coordsMap[key];
  25793. }
  25794. if (isObject(xAxisIndex)) {
  25795. yAxisIndex = xAxisIndex.yAxisIndex;
  25796. xAxisIndex = xAxisIndex.xAxisIndex;
  25797. }
  25798. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  25799. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  25800. if (coordList[i].getAxis('x').index === xAxisIndex
  25801. || coordList[i].getAxis('y').index === yAxisIndex
  25802. ) {
  25803. return coordList[i];
  25804. }
  25805. }
  25806. };
  25807. gridProto.getCartesians = function () {
  25808. return this._coordsList.slice();
  25809. };
  25810. /**
  25811. * @implements
  25812. * see {module:echarts/CoodinateSystem}
  25813. */
  25814. gridProto.convertToPixel = function (ecModel, finder, value) {
  25815. var target = this._findConvertTarget(ecModel, finder);
  25816. return target.cartesian
  25817. ? target.cartesian.dataToPoint(value)
  25818. : target.axis
  25819. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  25820. : null;
  25821. };
  25822. /**
  25823. * @implements
  25824. * see {module:echarts/CoodinateSystem}
  25825. */
  25826. gridProto.convertFromPixel = function (ecModel, finder, value) {
  25827. var target = this._findConvertTarget(ecModel, finder);
  25828. return target.cartesian
  25829. ? target.cartesian.pointToData(value)
  25830. : target.axis
  25831. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  25832. : null;
  25833. };
  25834. /**
  25835. * @inner
  25836. */
  25837. gridProto._findConvertTarget = function (ecModel, finder) {
  25838. var seriesModel = finder.seriesModel;
  25839. var xAxisModel = finder.xAxisModel
  25840. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  25841. var yAxisModel = finder.yAxisModel
  25842. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  25843. var gridModel = finder.gridModel;
  25844. var coordsList = this._coordsList;
  25845. var cartesian;
  25846. var axis;
  25847. if (seriesModel) {
  25848. cartesian = seriesModel.coordinateSystem;
  25849. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  25850. }
  25851. else if (xAxisModel && yAxisModel) {
  25852. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  25853. }
  25854. else if (xAxisModel) {
  25855. axis = this.getAxis('x', xAxisModel.componentIndex);
  25856. }
  25857. else if (yAxisModel) {
  25858. axis = this.getAxis('y', yAxisModel.componentIndex);
  25859. }
  25860. // Lowest priority.
  25861. else if (gridModel) {
  25862. var grid = gridModel.coordinateSystem;
  25863. if (grid === this) {
  25864. cartesian = this._coordsList[0];
  25865. }
  25866. }
  25867. return {cartesian: cartesian, axis: axis};
  25868. };
  25869. /**
  25870. * @implements
  25871. * see {module:echarts/CoodinateSystem}
  25872. */
  25873. gridProto.containPoint = function (point) {
  25874. var coord = this._coordsList[0];
  25875. if (coord) {
  25876. return coord.containPoint(point);
  25877. }
  25878. };
  25879. /**
  25880. * Initialize cartesian coordinate systems
  25881. * @private
  25882. */
  25883. gridProto._initCartesian = function (gridModel, ecModel, api) {
  25884. var axisPositionUsed = {
  25885. left: false,
  25886. right: false,
  25887. top: false,
  25888. bottom: false
  25889. };
  25890. var axesMap = {
  25891. x: {},
  25892. y: {}
  25893. };
  25894. var axesCount = {
  25895. x: 0,
  25896. y: 0
  25897. };
  25898. /// Create axis
  25899. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  25900. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  25901. if (!axesCount.x || !axesCount.y) {
  25902. // Roll back when there no either x or y axis
  25903. this._axesMap = {};
  25904. this._axesList = [];
  25905. return;
  25906. }
  25907. this._axesMap = axesMap;
  25908. /// Create cartesian2d
  25909. each$8(axesMap.x, function (xAxis, xAxisIndex) {
  25910. each$8(axesMap.y, function (yAxis, yAxisIndex) {
  25911. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  25912. var cartesian = new Cartesian2D(key);
  25913. cartesian.grid = this;
  25914. cartesian.model = gridModel;
  25915. this._coordsMap[key] = cartesian;
  25916. this._coordsList.push(cartesian);
  25917. cartesian.addAxis(xAxis);
  25918. cartesian.addAxis(yAxis);
  25919. }, this);
  25920. }, this);
  25921. function createAxisCreator(axisType) {
  25922. return function (axisModel, idx) {
  25923. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  25924. return;
  25925. }
  25926. var axisPosition = axisModel.get('position');
  25927. if (axisType === 'x') {
  25928. // Fix position
  25929. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  25930. // Default bottom of X
  25931. axisPosition = 'bottom';
  25932. if (axisPositionUsed[axisPosition]) {
  25933. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  25934. }
  25935. }
  25936. }
  25937. else {
  25938. // Fix position
  25939. if (axisPosition !== 'left' && axisPosition !== 'right') {
  25940. // Default left of Y
  25941. axisPosition = 'left';
  25942. if (axisPositionUsed[axisPosition]) {
  25943. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  25944. }
  25945. }
  25946. }
  25947. axisPositionUsed[axisPosition] = true;
  25948. var axis = new Axis2D(
  25949. axisType, createScaleByModel(axisModel),
  25950. [0, 0],
  25951. axisModel.get('type'),
  25952. axisPosition
  25953. );
  25954. var isCategory = axis.type === 'category';
  25955. axis.onBand = isCategory && axisModel.get('boundaryGap');
  25956. axis.inverse = axisModel.get('inverse');
  25957. axis.onZero = axisModel.get('axisLine.onZero');
  25958. axis.onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  25959. // Inject axis into axisModel
  25960. axisModel.axis = axis;
  25961. // Inject axisModel into axis
  25962. axis.model = axisModel;
  25963. // Inject grid info axis
  25964. axis.grid = this;
  25965. // Index of axis, can be used as key
  25966. axis.index = idx;
  25967. this._axesList.push(axis);
  25968. axesMap[axisType][idx] = axis;
  25969. axesCount[axisType]++;
  25970. };
  25971. }
  25972. };
  25973. /**
  25974. * Update cartesian properties from series
  25975. * @param {module:echarts/model/Option} option
  25976. * @private
  25977. */
  25978. gridProto._updateScale = function (ecModel, gridModel) {
  25979. // Reset scale
  25980. each$1(this._axesList, function (axis) {
  25981. axis.scale.setExtent(Infinity, -Infinity);
  25982. });
  25983. ecModel.eachSeries(function (seriesModel) {
  25984. if (isCartesian2D(seriesModel)) {
  25985. var axesModels = findAxesModels(seriesModel, ecModel);
  25986. var xAxisModel = axesModels[0];
  25987. var yAxisModel = axesModels[1];
  25988. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  25989. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  25990. ) {
  25991. return;
  25992. }
  25993. var cartesian = this.getCartesian(
  25994. xAxisModel.componentIndex, yAxisModel.componentIndex
  25995. );
  25996. var data = seriesModel.getData();
  25997. var xAxis = cartesian.getAxis('x');
  25998. var yAxis = cartesian.getAxis('y');
  25999. if (data.type === 'list') {
  26000. unionExtent(data, xAxis, seriesModel);
  26001. unionExtent(data, yAxis, seriesModel);
  26002. }
  26003. }
  26004. }, this);
  26005. function unionExtent(data, axis, seriesModel) {
  26006. each$8(seriesModel.coordDimToDataDim(axis.dim), function (dim) {
  26007. axis.scale.unionExtentFromData(data, dim);
  26008. });
  26009. }
  26010. };
  26011. /**
  26012. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  26013. * @return {Object} {baseAxes: [], otherAxes: []}
  26014. */
  26015. gridProto.getTooltipAxes = function (dim) {
  26016. var baseAxes = [];
  26017. var otherAxes = [];
  26018. each$8(this.getCartesians(), function (cartesian) {
  26019. var baseAxis = (dim != null && dim !== 'auto')
  26020. ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  26021. var otherAxis = cartesian.getOtherAxis(baseAxis);
  26022. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  26023. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  26024. });
  26025. return {baseAxes: baseAxes, otherAxes: otherAxes};
  26026. };
  26027. /**
  26028. * @inner
  26029. */
  26030. function updateAxisTransfrom(axis, coordBase) {
  26031. var axisExtent = axis.getExtent();
  26032. var axisExtentSum = axisExtent[0] + axisExtent[1];
  26033. // Fast transform
  26034. axis.toGlobalCoord = axis.dim === 'x'
  26035. ? function (coord) {
  26036. return coord + coordBase;
  26037. }
  26038. : function (coord) {
  26039. return axisExtentSum - coord + coordBase;
  26040. };
  26041. axis.toLocalCoord = axis.dim === 'x'
  26042. ? function (coord) {
  26043. return coord - coordBase;
  26044. }
  26045. : function (coord) {
  26046. return axisExtentSum - coord + coordBase;
  26047. };
  26048. }
  26049. var axesTypes = ['xAxis', 'yAxis'];
  26050. /**
  26051. * @inner
  26052. */
  26053. function findAxesModels(seriesModel, ecModel) {
  26054. return map(axesTypes, function (axisType) {
  26055. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  26056. if (__DEV__) {
  26057. if (!axisModel) {
  26058. throw new Error(axisType + ' "' + retrieve(
  26059. seriesModel.get(axisType + 'Index'),
  26060. seriesModel.get(axisType + 'Id'),
  26061. 0
  26062. ) + '" not found');
  26063. }
  26064. }
  26065. return axisModel;
  26066. });
  26067. }
  26068. /**
  26069. * @inner
  26070. */
  26071. function isCartesian2D(seriesModel) {
  26072. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  26073. }
  26074. Grid.create = function (ecModel, api) {
  26075. var grids = [];
  26076. ecModel.eachComponent('grid', function (gridModel, idx) {
  26077. var grid = new Grid(gridModel, ecModel, api);
  26078. grid.name = 'grid_' + idx;
  26079. // dataSampling requires axis extent, so resize
  26080. // should be performed in create stage.
  26081. grid.resize(gridModel, api, true);
  26082. gridModel.coordinateSystem = grid;
  26083. grids.push(grid);
  26084. });
  26085. // Inject the coordinateSystems into seriesModel
  26086. ecModel.eachSeries(function (seriesModel) {
  26087. if (!isCartesian2D(seriesModel)) {
  26088. return;
  26089. }
  26090. var axesModels = findAxesModels(seriesModel, ecModel);
  26091. var xAxisModel = axesModels[0];
  26092. var yAxisModel = axesModels[1];
  26093. var gridModel = xAxisModel.getCoordSysModel();
  26094. if (__DEV__) {
  26095. if (!gridModel) {
  26096. throw new Error(
  26097. 'Grid "' + retrieve(
  26098. xAxisModel.get('gridIndex'),
  26099. xAxisModel.get('gridId'),
  26100. 0
  26101. ) + '" not found'
  26102. );
  26103. }
  26104. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  26105. throw new Error('xAxis and yAxis must use the same grid');
  26106. }
  26107. }
  26108. var grid = gridModel.coordinateSystem;
  26109. seriesModel.coordinateSystem = grid.getCartesian(
  26110. xAxisModel.componentIndex, yAxisModel.componentIndex
  26111. );
  26112. });
  26113. return grids;
  26114. };
  26115. // For deciding which dimensions to use when creating list data
  26116. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  26117. CoordinateSystemManager.register('cartesian2d', Grid);
  26118. var PI$2 = Math.PI;
  26119. function makeAxisEventDataBase(axisModel) {
  26120. var eventData = {
  26121. componentType: axisModel.mainType
  26122. };
  26123. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  26124. return eventData;
  26125. }
  26126. /**
  26127. * A final axis is translated and rotated from a "standard axis".
  26128. * So opt.position and opt.rotation is required.
  26129. *
  26130. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  26131. * for example: (0, 0) ------------> (0, 50)
  26132. *
  26133. * nameDirection or tickDirection or labelDirection is 1 means tick
  26134. * or label is below the standard axis, whereas is -1 means above
  26135. * the standard axis. labelOffset means offset between label and axis,
  26136. * which is useful when 'onZero', where axisLabel is in the grid and
  26137. * label in outside grid.
  26138. *
  26139. * Tips: like always,
  26140. * positive rotation represents anticlockwise, and negative rotation
  26141. * represents clockwise.
  26142. * The direction of position coordinate is the same as the direction
  26143. * of screen coordinate.
  26144. *
  26145. * Do not need to consider axis 'inverse', which is auto processed by
  26146. * axis extent.
  26147. *
  26148. * @param {module:zrender/container/Group} group
  26149. * @param {Object} axisModel
  26150. * @param {Object} opt Standard axis parameters.
  26151. * @param {Array.<number>} opt.position [x, y]
  26152. * @param {number} opt.rotation by radian
  26153. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  26154. * @param {number} [opt.tickDirection=1] 1 or -1
  26155. * @param {number} [opt.labelDirection=1] 1 or -1
  26156. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  26157. * @param {string} [opt.axisLabelShow] default get from axisModel.
  26158. * @param {string} [opt.axisName] default get from axisModel.
  26159. * @param {number} [opt.axisNameAvailableWidth]
  26160. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  26161. * @param {number} [opt.labelInterval] Default label interval when label
  26162. * interval from model is null or 'auto'.
  26163. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  26164. * @param {number} [opt.nameTruncateMaxWidth]
  26165. */
  26166. var AxisBuilder = function (axisModel, opt) {
  26167. /**
  26168. * @readOnly
  26169. */
  26170. this.opt = opt;
  26171. /**
  26172. * @readOnly
  26173. */
  26174. this.axisModel = axisModel;
  26175. // Default value
  26176. defaults(
  26177. opt,
  26178. {
  26179. labelOffset: 0,
  26180. nameDirection: 1,
  26181. tickDirection: 1,
  26182. labelDirection: 1,
  26183. silent: true
  26184. }
  26185. );
  26186. /**
  26187. * @readOnly
  26188. */
  26189. this.group = new Group();
  26190. // FIXME Not use a seperate text group?
  26191. var dumbGroup = new Group({
  26192. position: opt.position.slice(),
  26193. rotation: opt.rotation
  26194. });
  26195. // this.group.add(dumbGroup);
  26196. // this._dumbGroup = dumbGroup;
  26197. dumbGroup.updateTransform();
  26198. this._transform = dumbGroup.transform;
  26199. this._dumbGroup = dumbGroup;
  26200. };
  26201. AxisBuilder.prototype = {
  26202. constructor: AxisBuilder,
  26203. hasBuilder: function (name) {
  26204. return !!builders[name];
  26205. },
  26206. add: function (name) {
  26207. builders[name].call(this);
  26208. },
  26209. getGroup: function () {
  26210. return this.group;
  26211. }
  26212. };
  26213. var builders = {
  26214. /**
  26215. * @private
  26216. */
  26217. axisLine: function () {
  26218. var opt = this.opt;
  26219. var axisModel = this.axisModel;
  26220. if (!axisModel.get('axisLine.show')) {
  26221. return;
  26222. }
  26223. var extent = this.axisModel.axis.getExtent();
  26224. var matrix = this._transform;
  26225. var pt1 = [extent[0], 0];
  26226. var pt2 = [extent[1], 0];
  26227. if (matrix) {
  26228. applyTransform(pt1, pt1, matrix);
  26229. applyTransform(pt2, pt2, matrix);
  26230. }
  26231. var lineStyle = extend(
  26232. {
  26233. lineCap: 'round'
  26234. },
  26235. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  26236. );
  26237. this.group.add(new Line(subPixelOptimizeLine({
  26238. // Id for animation
  26239. anid: 'line',
  26240. shape: {
  26241. x1: pt1[0],
  26242. y1: pt1[1],
  26243. x2: pt2[0],
  26244. y2: pt2[1]
  26245. },
  26246. style: lineStyle,
  26247. strokeContainThreshold: opt.strokeContainThreshold || 5,
  26248. silent: true,
  26249. z2: 1
  26250. })));
  26251. var arrows = axisModel.get('axisLine.symbol');
  26252. var arrowSize = axisModel.get('axisLine.symbolSize');
  26253. if (arrows != null) {
  26254. if (typeof arrows === 'string') {
  26255. // Use the same arrow for start and end point
  26256. arrows = [arrows, arrows];
  26257. }
  26258. if (typeof arrowSize === 'string'
  26259. || typeof arrowSize === 'number'
  26260. ) {
  26261. // Use the same size for width and height
  26262. arrowSize = [arrowSize, arrowSize];
  26263. }
  26264. var symbolWidth = arrowSize[0];
  26265. var symbolHeight = arrowSize[1];
  26266. each$1([
  26267. [opt.rotation + Math.PI / 2, pt1],
  26268. [opt.rotation - Math.PI / 2, pt2]
  26269. ], function (item, index) {
  26270. if (arrows[index] !== 'none' && arrows[index] != null) {
  26271. var symbol = createSymbol(
  26272. arrows[index],
  26273. -symbolWidth / 2,
  26274. -symbolHeight / 2,
  26275. symbolWidth,
  26276. symbolHeight,
  26277. lineStyle.stroke,
  26278. true
  26279. );
  26280. symbol.attr({
  26281. rotation: item[0],
  26282. position: item[1],
  26283. silent: true
  26284. });
  26285. this.group.add(symbol);
  26286. }
  26287. }, this);
  26288. }
  26289. },
  26290. /**
  26291. * @private
  26292. */
  26293. axisTickLabel: function () {
  26294. var axisModel = this.axisModel;
  26295. var opt = this.opt;
  26296. var tickEls = buildAxisTick(this, axisModel, opt);
  26297. var labelEls = buildAxisLabel(this, axisModel, opt);
  26298. fixMinMaxLabelShow(axisModel, labelEls, tickEls);
  26299. },
  26300. /**
  26301. * @private
  26302. */
  26303. axisName: function () {
  26304. var opt = this.opt;
  26305. var axisModel = this.axisModel;
  26306. var name = retrieve(opt.axisName, axisModel.get('name'));
  26307. if (!name) {
  26308. return;
  26309. }
  26310. var nameLocation = axisModel.get('nameLocation');
  26311. var nameDirection = opt.nameDirection;
  26312. var textStyleModel = axisModel.getModel('nameTextStyle');
  26313. var gap = axisModel.get('nameGap') || 0;
  26314. var extent = this.axisModel.axis.getExtent();
  26315. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  26316. var pos = [
  26317. nameLocation === 'start'
  26318. ? extent[0] - gapSignal * gap
  26319. : nameLocation === 'end'
  26320. ? extent[1] + gapSignal * gap
  26321. : (extent[0] + extent[1]) / 2, // 'middle'
  26322. // Reuse labelOffset.
  26323. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0
  26324. ];
  26325. var labelLayout;
  26326. var nameRotation = axisModel.get('nameRotate');
  26327. if (nameRotation != null) {
  26328. nameRotation = nameRotation * PI$2 / 180; // To radian.
  26329. }
  26330. var axisNameAvailableWidth;
  26331. if (isNameLocationCenter(nameLocation)) {
  26332. labelLayout = innerTextLayout(
  26333. opt.rotation,
  26334. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  26335. nameDirection
  26336. );
  26337. }
  26338. else {
  26339. labelLayout = endTextLayout(
  26340. opt, nameLocation, nameRotation || 0, extent
  26341. );
  26342. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  26343. if (axisNameAvailableWidth != null) {
  26344. axisNameAvailableWidth = Math.abs(
  26345. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  26346. );
  26347. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  26348. }
  26349. }
  26350. var textFont = textStyleModel.getFont();
  26351. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  26352. var ellipsis = truncateOpt.ellipsis;
  26353. var maxWidth = retrieve(
  26354. opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth
  26355. );
  26356. // FIXME
  26357. // truncate rich text? (consider performance)
  26358. var truncatedText = (ellipsis != null && maxWidth != null)
  26359. ? truncateText$1(
  26360. name, maxWidth, textFont, ellipsis,
  26361. {minChar: 2, placeholder: truncateOpt.placeholder}
  26362. )
  26363. : name;
  26364. var tooltipOpt = axisModel.get('tooltip', true);
  26365. var mainType = axisModel.mainType;
  26366. var formatterParams = {
  26367. componentType: mainType,
  26368. name: name,
  26369. $vars: ['name']
  26370. };
  26371. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  26372. var textEl = new Text({
  26373. // Id for animation
  26374. anid: 'name',
  26375. __fullText: name,
  26376. __truncatedText: truncatedText,
  26377. position: pos,
  26378. rotation: labelLayout.rotation,
  26379. silent: isSilent(axisModel),
  26380. z2: 1,
  26381. tooltip: (tooltipOpt && tooltipOpt.show)
  26382. ? extend({
  26383. content: name,
  26384. formatter: function () {
  26385. return name;
  26386. },
  26387. formatterParams: formatterParams
  26388. }, tooltipOpt)
  26389. : null
  26390. });
  26391. setTextStyle(textEl.style, textStyleModel, {
  26392. text: truncatedText,
  26393. textFont: textFont,
  26394. textFill: textStyleModel.getTextColor()
  26395. || axisModel.get('axisLine.lineStyle.color'),
  26396. textAlign: labelLayout.textAlign,
  26397. textVerticalAlign: labelLayout.textVerticalAlign
  26398. });
  26399. if (axisModel.get('triggerEvent')) {
  26400. textEl.eventData = makeAxisEventDataBase(axisModel);
  26401. textEl.eventData.targetType = 'axisName';
  26402. textEl.eventData.name = name;
  26403. }
  26404. // FIXME
  26405. this._dumbGroup.add(textEl);
  26406. textEl.updateTransform();
  26407. this.group.add(textEl);
  26408. textEl.decomposeTransform();
  26409. }
  26410. };
  26411. /**
  26412. * @public
  26413. * @static
  26414. * @param {Object} opt
  26415. * @param {number} axisRotation in radian
  26416. * @param {number} textRotation in radian
  26417. * @param {number} direction
  26418. * @return {Object} {
  26419. * rotation, // according to axis
  26420. * textAlign,
  26421. * textVerticalAlign
  26422. * }
  26423. */
  26424. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  26425. var rotationDiff = remRadian(textRotation - axisRotation);
  26426. var textAlign;
  26427. var textVerticalAlign;
  26428. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  26429. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  26430. textAlign = 'center';
  26431. }
  26432. else if (isRadianAroundZero(rotationDiff - PI$2)) { // Label is inverse parallel with axis line.
  26433. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  26434. textAlign = 'center';
  26435. }
  26436. else {
  26437. textVerticalAlign = 'middle';
  26438. if (rotationDiff > 0 && rotationDiff < PI$2) {
  26439. textAlign = direction > 0 ? 'right' : 'left';
  26440. }
  26441. else {
  26442. textAlign = direction > 0 ? 'left' : 'right';
  26443. }
  26444. }
  26445. return {
  26446. rotation: rotationDiff,
  26447. textAlign: textAlign,
  26448. textVerticalAlign: textVerticalAlign
  26449. };
  26450. };
  26451. function endTextLayout(opt, textPosition, textRotate, extent) {
  26452. var rotationDiff = remRadian(textRotate - opt.rotation);
  26453. var textAlign;
  26454. var textVerticalAlign;
  26455. var inverse = extent[0] > extent[1];
  26456. var onLeft = (textPosition === 'start' && !inverse)
  26457. || (textPosition !== 'start' && inverse);
  26458. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  26459. textVerticalAlign = onLeft ? 'bottom' : 'top';
  26460. textAlign = 'center';
  26461. }
  26462. else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  26463. textVerticalAlign = onLeft ? 'top' : 'bottom';
  26464. textAlign = 'center';
  26465. }
  26466. else {
  26467. textVerticalAlign = 'middle';
  26468. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  26469. textAlign = onLeft ? 'left' : 'right';
  26470. }
  26471. else {
  26472. textAlign = onLeft ? 'right' : 'left';
  26473. }
  26474. }
  26475. return {
  26476. rotation: rotationDiff,
  26477. textAlign: textAlign,
  26478. textVerticalAlign: textVerticalAlign
  26479. };
  26480. }
  26481. function isSilent(axisModel) {
  26482. var tooltipOpt = axisModel.get('tooltip');
  26483. return axisModel.get('silent')
  26484. // Consider mouse cursor, add these restrictions.
  26485. || !(
  26486. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  26487. );
  26488. }
  26489. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  26490. // If min or max are user set, we need to check
  26491. // If the tick on min(max) are overlap on their neighbour tick
  26492. // If they are overlapped, we need to hide the min(max) tick label
  26493. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  26494. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  26495. // FIXME
  26496. // Have not consider onBand yet, where tick els is more than label els.
  26497. labelEls = labelEls || [];
  26498. tickEls = tickEls || [];
  26499. var firstLabel = labelEls[0];
  26500. var nextLabel = labelEls[1];
  26501. var lastLabel = labelEls[labelEls.length - 1];
  26502. var prevLabel = labelEls[labelEls.length - 2];
  26503. var firstTick = tickEls[0];
  26504. var nextTick = tickEls[1];
  26505. var lastTick = tickEls[tickEls.length - 1];
  26506. var prevTick = tickEls[tickEls.length - 2];
  26507. if (showMinLabel === false) {
  26508. ignoreEl(firstLabel);
  26509. ignoreEl(firstTick);
  26510. }
  26511. else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  26512. if (showMinLabel) {
  26513. ignoreEl(nextLabel);
  26514. ignoreEl(nextTick);
  26515. }
  26516. else {
  26517. ignoreEl(firstLabel);
  26518. ignoreEl(firstTick);
  26519. }
  26520. }
  26521. if (showMaxLabel === false) {
  26522. ignoreEl(lastLabel);
  26523. ignoreEl(lastTick);
  26524. }
  26525. else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  26526. if (showMaxLabel) {
  26527. ignoreEl(prevLabel);
  26528. ignoreEl(prevTick);
  26529. }
  26530. else {
  26531. ignoreEl(lastLabel);
  26532. ignoreEl(lastTick);
  26533. }
  26534. }
  26535. }
  26536. function ignoreEl(el) {
  26537. el && (el.ignore = true);
  26538. }
  26539. function isTwoLabelOverlapped(current, next, labelLayout) {
  26540. // current and next has the same rotation.
  26541. var firstRect = current && current.getBoundingRect().clone();
  26542. var nextRect = next && next.getBoundingRect().clone();
  26543. if (!firstRect || !nextRect) {
  26544. return;
  26545. }
  26546. // When checking intersect of two rotated labels, we use mRotationBack
  26547. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  26548. var mRotationBack = identity([]);
  26549. rotate(mRotationBack, mRotationBack, -current.rotation);
  26550. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  26551. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  26552. return firstRect.intersect(nextRect);
  26553. }
  26554. function isNameLocationCenter(nameLocation) {
  26555. return nameLocation === 'middle' || nameLocation === 'center';
  26556. }
  26557. /**
  26558. * @static
  26559. */
  26560. var ifIgnoreOnTick$1 = AxisBuilder.ifIgnoreOnTick = function (
  26561. axis,
  26562. i,
  26563. interval,
  26564. ticksCnt,
  26565. showMinLabel,
  26566. showMaxLabel
  26567. ) {
  26568. if (i === 0 && showMinLabel || i === ticksCnt - 1 && showMaxLabel) {
  26569. return false;
  26570. }
  26571. // FIXME
  26572. // Have not consider label overlap (if label is too long) yet.
  26573. var rawTick;
  26574. var scale$$1 = axis.scale;
  26575. return scale$$1.type === 'ordinal'
  26576. && (
  26577. typeof interval === 'function'
  26578. ? (
  26579. rawTick = scale$$1.getTicks()[i],
  26580. !interval(rawTick, scale$$1.getLabel(rawTick))
  26581. )
  26582. : i % (interval + 1)
  26583. );
  26584. };
  26585. /**
  26586. * @static
  26587. */
  26588. var getInterval$1 = AxisBuilder.getInterval = function (model, labelInterval) {
  26589. var interval = model.get('interval');
  26590. if (interval == null || interval == 'auto') {
  26591. interval = labelInterval;
  26592. }
  26593. return interval;
  26594. };
  26595. function buildAxisTick(axisBuilder, axisModel, opt) {
  26596. var axis = axisModel.axis;
  26597. if (!axisModel.get('axisTick.show') || axis.scale.isBlank()) {
  26598. return;
  26599. }
  26600. var tickModel = axisModel.getModel('axisTick');
  26601. var lineStyleModel = tickModel.getModel('lineStyle');
  26602. var tickLen = tickModel.get('length');
  26603. var tickInterval = getInterval$1(tickModel, opt.labelInterval);
  26604. var ticksCoords = axis.getTicksCoords(tickModel.get('alignWithLabel'));
  26605. // FIXME
  26606. // Corresponds to ticksCoords ?
  26607. var ticks = axis.scale.getTicks();
  26608. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  26609. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  26610. var pt1 = [];
  26611. var pt2 = [];
  26612. var matrix = axisBuilder._transform;
  26613. var tickEls = [];
  26614. var ticksCnt = ticksCoords.length;
  26615. for (var i = 0; i < ticksCnt; i++) {
  26616. // Only ordinal scale support tick interval
  26617. if (ifIgnoreOnTick$1(
  26618. axis, i, tickInterval, ticksCnt,
  26619. showMinLabel, showMaxLabel
  26620. )) {
  26621. continue;
  26622. }
  26623. var tickCoord = ticksCoords[i];
  26624. pt1[0] = tickCoord;
  26625. pt1[1] = 0;
  26626. pt2[0] = tickCoord;
  26627. pt2[1] = opt.tickDirection * tickLen;
  26628. if (matrix) {
  26629. applyTransform(pt1, pt1, matrix);
  26630. applyTransform(pt2, pt2, matrix);
  26631. }
  26632. // Tick line, Not use group transform to have better line draw
  26633. var tickEl = new Line(subPixelOptimizeLine({
  26634. // Id for animation
  26635. anid: 'tick_' + ticks[i],
  26636. shape: {
  26637. x1: pt1[0],
  26638. y1: pt1[1],
  26639. x2: pt2[0],
  26640. y2: pt2[1]
  26641. },
  26642. style: defaults(
  26643. lineStyleModel.getLineStyle(),
  26644. {
  26645. stroke: axisModel.get('axisLine.lineStyle.color')
  26646. }
  26647. ),
  26648. z2: 2,
  26649. silent: true
  26650. }));
  26651. axisBuilder.group.add(tickEl);
  26652. tickEls.push(tickEl);
  26653. }
  26654. return tickEls;
  26655. }
  26656. function buildAxisLabel(axisBuilder, axisModel, opt) {
  26657. var axis = axisModel.axis;
  26658. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  26659. if (!show || axis.scale.isBlank()) {
  26660. return;
  26661. }
  26662. var labelModel = axisModel.getModel('axisLabel');
  26663. var labelMargin = labelModel.get('margin');
  26664. var ticks = axis.scale.getTicks();
  26665. var labels = axisModel.getFormattedLabels();
  26666. // Special label rotate.
  26667. var labelRotation = (
  26668. retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
  26669. ) * PI$2 / 180;
  26670. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  26671. var categoryData = axisModel.get('data');
  26672. var labelEls = [];
  26673. var silent = isSilent(axisModel);
  26674. var triggerEvent = axisModel.get('triggerEvent');
  26675. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  26676. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  26677. each$1(ticks, function (tickVal, index) {
  26678. if (ifIgnoreOnTick$1(
  26679. axis, index, opt.labelInterval, ticks.length,
  26680. showMinLabel, showMaxLabel
  26681. )) {
  26682. return;
  26683. }
  26684. var itemLabelModel = labelModel;
  26685. if (categoryData && categoryData[tickVal] && categoryData[tickVal].textStyle) {
  26686. itemLabelModel = new Model(
  26687. categoryData[tickVal].textStyle, labelModel, axisModel.ecModel
  26688. );
  26689. }
  26690. var textColor = itemLabelModel.getTextColor()
  26691. || axisModel.get('axisLine.lineStyle.color');
  26692. var tickCoord = axis.dataToCoord(tickVal);
  26693. var pos = [
  26694. tickCoord,
  26695. opt.labelOffset + opt.labelDirection * labelMargin
  26696. ];
  26697. var labelStr = axis.scale.getLabel(tickVal);
  26698. var textEl = new Text({
  26699. // Id for animation
  26700. anid: 'label_' + tickVal,
  26701. position: pos,
  26702. rotation: labelLayout.rotation,
  26703. silent: silent,
  26704. z2: 10
  26705. });
  26706. setTextStyle(textEl.style, itemLabelModel, {
  26707. text: labels[index],
  26708. textAlign: itemLabelModel.getShallow('align', true)
  26709. || labelLayout.textAlign,
  26710. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true)
  26711. || itemLabelModel.getShallow('baseline', true)
  26712. || labelLayout.textVerticalAlign,
  26713. textFill: typeof textColor === 'function'
  26714. ? textColor(
  26715. // (1) In category axis with data zoom, tick is not the original
  26716. // index of axis.data. So tick should not be exposed to user
  26717. // in category axis.
  26718. // (2) Compatible with previous version, which always returns labelStr.
  26719. // But in interval scale labelStr is like '223,445', which maked
  26720. // user repalce ','. So we modify it to return original val but remain
  26721. // it as 'string' to avoid error in replacing.
  26722. axis.type === 'category' ? labelStr : axis.type === 'value' ? tickVal + '' : tickVal,
  26723. index
  26724. )
  26725. : textColor
  26726. });
  26727. // Pack data for mouse event
  26728. if (triggerEvent) {
  26729. textEl.eventData = makeAxisEventDataBase(axisModel);
  26730. textEl.eventData.targetType = 'axisLabel';
  26731. textEl.eventData.value = labelStr;
  26732. }
  26733. // FIXME
  26734. axisBuilder._dumbGroup.add(textEl);
  26735. textEl.updateTransform();
  26736. labelEls.push(textEl);
  26737. axisBuilder.group.add(textEl);
  26738. textEl.decomposeTransform();
  26739. });
  26740. return labelEls;
  26741. }
  26742. var each$9 = each$1;
  26743. var curry$1 = curry;
  26744. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  26745. // allAxesInfo should be updated when setOption performed.
  26746. function collect(ecModel, api) {
  26747. var result = {
  26748. /**
  26749. * key: makeKey(axis.model)
  26750. * value: {
  26751. * axis,
  26752. * coordSys,
  26753. * axisPointerModel,
  26754. * triggerTooltip,
  26755. * involveSeries,
  26756. * snap,
  26757. * seriesModels,
  26758. * seriesDataCount
  26759. * }
  26760. */
  26761. axesInfo: {},
  26762. seriesInvolved: false,
  26763. /**
  26764. * key: makeKey(coordSys.model)
  26765. * value: Object: key makeKey(axis.model), value: axisInfo
  26766. */
  26767. coordSysAxesInfo: {},
  26768. coordSysMap: {}
  26769. };
  26770. collectAxesInfo(result, ecModel, api);
  26771. // Check seriesInvolved for performance, in case too many series in some chart.
  26772. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  26773. return result;
  26774. }
  26775. function collectAxesInfo(result, ecModel, api) {
  26776. var globalTooltipModel = ecModel.getComponent('tooltip');
  26777. var globalAxisPointerModel = ecModel.getComponent('axisPointer');
  26778. // links can only be set on global.
  26779. var linksOption = globalAxisPointerModel.get('link', true) || [];
  26780. var linkGroups = [];
  26781. // Collect axes info.
  26782. each$9(api.getCoordinateSystems(), function (coordSys) {
  26783. // Some coordinate system do not support axes, like geo.
  26784. if (!coordSys.axisPointerEnabled) {
  26785. return;
  26786. }
  26787. var coordSysKey = makeKey(coordSys.model);
  26788. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  26789. result.coordSysMap[coordSysKey] = coordSys;
  26790. // Set tooltip (like 'cross') is a convienent way to show axisPointer
  26791. // for user. So we enable seting tooltip on coordSys model.
  26792. var coordSysModel = coordSys.model;
  26793. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  26794. each$9(coordSys.getAxes(), curry$1(saveTooltipAxisInfo, false, null));
  26795. // If axis tooltip used, choose tooltip axis for each coordSys.
  26796. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  26797. if (coordSys.getTooltipAxes
  26798. && globalTooltipModel
  26799. // If tooltip.showContent is set as false, tooltip will not
  26800. // show but axisPointer will show as normal.
  26801. && baseTooltipModel.get('show')
  26802. ) {
  26803. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  26804. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  26805. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  26806. var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
  26807. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
  26808. if (triggerAxis || cross) {
  26809. each$9(tooltipAxes.baseAxes, curry$1(
  26810. saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis
  26811. ));
  26812. }
  26813. if (cross) {
  26814. each$9(tooltipAxes.otherAxes, curry$1(saveTooltipAxisInfo, 'cross', false));
  26815. }
  26816. }
  26817. // fromTooltip: true | false | 'cross'
  26818. // triggerTooltip: true | false | null
  26819. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  26820. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  26821. var axisPointerShow = axisPointerModel.get('show');
  26822. if (!axisPointerShow || (
  26823. axisPointerShow === 'auto'
  26824. && !fromTooltip
  26825. && !isHandleTrigger(axisPointerModel)
  26826. )) {
  26827. return;
  26828. }
  26829. if (triggerTooltip == null) {
  26830. triggerTooltip = axisPointerModel.get('triggerTooltip');
  26831. }
  26832. axisPointerModel = fromTooltip
  26833. ? makeAxisPointerModel(
  26834. axis, baseTooltipModel, globalAxisPointerModel, ecModel,
  26835. fromTooltip, triggerTooltip
  26836. )
  26837. : axisPointerModel;
  26838. var snap = axisPointerModel.get('snap');
  26839. var key = makeKey(axis.model);
  26840. var involveSeries = triggerTooltip || snap || axis.type === 'category';
  26841. // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  26842. var axisInfo = result.axesInfo[key] = {
  26843. key: key,
  26844. axis: axis,
  26845. coordSys: coordSys,
  26846. axisPointerModel: axisPointerModel,
  26847. triggerTooltip: triggerTooltip,
  26848. involveSeries: involveSeries,
  26849. snap: snap,
  26850. useHandle: isHandleTrigger(axisPointerModel),
  26851. seriesModels: []
  26852. };
  26853. axesInfoInCoordSys[key] = axisInfo;
  26854. result.seriesInvolved |= involveSeries;
  26855. var groupIndex = getLinkGroupIndex(linksOption, axis);
  26856. if (groupIndex != null) {
  26857. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {axesInfo: {}});
  26858. linkGroup.axesInfo[key] = axisInfo;
  26859. linkGroup.mapper = linksOption[groupIndex].mapper;
  26860. axisInfo.linkGroup = linkGroup;
  26861. }
  26862. }
  26863. });
  26864. }
  26865. function makeAxisPointerModel(
  26866. axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip
  26867. ) {
  26868. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  26869. var volatileOption = {};
  26870. each$9(
  26871. [
  26872. 'type', 'snap', 'lineStyle', 'shadowStyle', 'label',
  26873. 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'
  26874. ],
  26875. function (field) {
  26876. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  26877. }
  26878. );
  26879. // category axis do not auto snap, otherwise some tick that do not
  26880. // has value can not be hovered. value/time/log axis default snap if
  26881. // triggered from tooltip and trigger tooltip.
  26882. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip;
  26883. // Compatibel with previous behavior, tooltip axis do not show label by default.
  26884. // Only these properties can be overrided from tooltip to axisPointer.
  26885. if (tooltipAxisPointerModel.get('type') === 'cross') {
  26886. volatileOption.type = 'line';
  26887. }
  26888. var labelOption = volatileOption.label || (volatileOption.label = {});
  26889. // Follow the convention, do not show label when triggered by tooltip by default.
  26890. labelOption.show == null && (labelOption.show = false);
  26891. if (fromTooltip === 'cross') {
  26892. // When 'cross', both axes show labels.
  26893. labelOption.show = true;
  26894. // If triggerTooltip, this is a base axis, which should better not use cross style
  26895. // (cross style is dashed by default)
  26896. if (!triggerTooltip) {
  26897. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  26898. crossStyle && defaults(labelOption, crossStyle.textStyle);
  26899. }
  26900. }
  26901. return axis.model.getModel(
  26902. 'axisPointer',
  26903. new Model(volatileOption, globalAxisPointerModel, ecModel)
  26904. );
  26905. }
  26906. function collectSeriesInfo(result, ecModel) {
  26907. // Prepare data for axis trigger
  26908. ecModel.eachSeries(function (seriesModel) {
  26909. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  26910. var coordSys = seriesModel.coordinateSystem;
  26911. var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
  26912. var seriesTooltipShow = seriesModel.get('tooltip.show', true);
  26913. if (!coordSys
  26914. || seriesTooltipTrigger === 'none'
  26915. || seriesTooltipTrigger === false
  26916. || seriesTooltipTrigger === 'item'
  26917. || seriesTooltipShow === false
  26918. || seriesModel.get('axisPointer.show', true) === false
  26919. ) {
  26920. return;
  26921. }
  26922. each$9(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  26923. var axis = axisInfo.axis;
  26924. if (coordSys.getAxis(axis.dim) === axis) {
  26925. axisInfo.seriesModels.push(seriesModel);
  26926. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  26927. axisInfo.seriesDataCount += seriesModel.getData().count();
  26928. }
  26929. });
  26930. }, this);
  26931. }
  26932. /**
  26933. * For example:
  26934. * {
  26935. * axisPointer: {
  26936. * links: [{
  26937. * xAxisIndex: [2, 4],
  26938. * yAxisIndex: 'all'
  26939. * }, {
  26940. * xAxisId: ['a5', 'a7'],
  26941. * xAxisName: 'xxx'
  26942. * }]
  26943. * }
  26944. * }
  26945. */
  26946. function getLinkGroupIndex(linksOption, axis) {
  26947. var axisModel = axis.model;
  26948. var dim = axis.dim;
  26949. for (var i = 0; i < linksOption.length; i++) {
  26950. var linkOption = linksOption[i] || {};
  26951. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id)
  26952. || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex)
  26953. || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)
  26954. ) {
  26955. return i;
  26956. }
  26957. }
  26958. }
  26959. function checkPropInLink(linkPropValue, axisPropValue) {
  26960. return linkPropValue === 'all'
  26961. || (isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0)
  26962. || linkPropValue === axisPropValue;
  26963. }
  26964. function fixValue(axisModel) {
  26965. var axisInfo = getAxisInfo(axisModel);
  26966. if (!axisInfo) {
  26967. return;
  26968. }
  26969. var axisPointerModel = axisInfo.axisPointerModel;
  26970. var scale = axisInfo.axis.scale;
  26971. var option = axisPointerModel.option;
  26972. var status = axisPointerModel.get('status');
  26973. var value = axisPointerModel.get('value');
  26974. // Parse init value for category and time axis.
  26975. if (value != null) {
  26976. value = scale.parse(value);
  26977. }
  26978. var useHandle = isHandleTrigger(axisPointerModel);
  26979. // If `handle` used, `axisPointer` will always be displayed, so value
  26980. // and status should be initialized.
  26981. if (status == null) {
  26982. option.status = useHandle ? 'show' : 'hide';
  26983. }
  26984. var extent = scale.getExtent().slice();
  26985. extent[0] > extent[1] && extent.reverse();
  26986. if (// Pick a value on axis when initializing.
  26987. value == null
  26988. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  26989. // where we should re-pick a value to keep `handle` displaying normally.
  26990. || value > extent[1]
  26991. ) {
  26992. // Make handle displayed on the end of the axis when init, which looks better.
  26993. value = extent[1];
  26994. }
  26995. if (value < extent[0]) {
  26996. value = extent[0];
  26997. }
  26998. option.value = value;
  26999. if (useHandle) {
  27000. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  27001. }
  27002. }
  27003. function getAxisInfo(axisModel) {
  27004. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  27005. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  27006. }
  27007. function getAxisPointerModel(axisModel) {
  27008. var axisInfo = getAxisInfo(axisModel);
  27009. return axisInfo && axisInfo.axisPointerModel;
  27010. }
  27011. function isHandleTrigger(axisPointerModel) {
  27012. return !!axisPointerModel.get('handle.show');
  27013. }
  27014. /**
  27015. * @param {module:echarts/model/Model} model
  27016. * @return {string} unique key
  27017. */
  27018. function makeKey(model) {
  27019. return model.type + '||' + model.id;
  27020. }
  27021. /**
  27022. * Base class of AxisView.
  27023. */
  27024. var AxisView = extendComponentView({
  27025. type: 'axis',
  27026. /**
  27027. * @private
  27028. */
  27029. _axisPointer: null,
  27030. /**
  27031. * @protected
  27032. * @type {string}
  27033. */
  27034. axisPointerClass: null,
  27035. /**
  27036. * @override
  27037. */
  27038. render: function (axisModel, ecModel, api, payload) {
  27039. // FIXME
  27040. // This process should proformed after coordinate systems updated
  27041. // (axis scale updated), and should be performed each time update.
  27042. // So put it here temporarily, although it is not appropriate to
  27043. // put a model-writing procedure in `view`.
  27044. this.axisPointerClass && fixValue(axisModel);
  27045. AxisView.superApply(this, 'render', arguments);
  27046. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  27047. },
  27048. /**
  27049. * Action handler.
  27050. * @public
  27051. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  27052. * @param {module:echarts/model/Global} ecModel
  27053. * @param {module:echarts/ExtensionAPI} api
  27054. * @param {Object} payload
  27055. */
  27056. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  27057. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  27058. },
  27059. /**
  27060. * @override
  27061. */
  27062. remove: function (ecModel, api) {
  27063. var axisPointer = this._axisPointer;
  27064. axisPointer && axisPointer.remove(api);
  27065. AxisView.superApply(this, 'remove', arguments);
  27066. },
  27067. /**
  27068. * @override
  27069. */
  27070. dispose: function (ecModel, api) {
  27071. disposeAxisPointer(this, api);
  27072. AxisView.superApply(this, 'dispose', arguments);
  27073. }
  27074. });
  27075. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  27076. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  27077. if (!Clazz) {
  27078. return;
  27079. }
  27080. var axisPointerModel = getAxisPointerModel(axisModel);
  27081. axisPointerModel
  27082. ? (axisView._axisPointer || (axisView._axisPointer = new Clazz()))
  27083. .render(axisModel, axisPointerModel, api, forceRender)
  27084. : disposeAxisPointer(axisView, api);
  27085. }
  27086. function disposeAxisPointer(axisView, ecModel, api) {
  27087. var axisPointer = axisView._axisPointer;
  27088. axisPointer && axisPointer.dispose(ecModel, api);
  27089. axisView._axisPointer = null;
  27090. }
  27091. var axisPointerClazz = [];
  27092. AxisView.registerAxisPointerClass = function (type, clazz) {
  27093. if (__DEV__) {
  27094. if (axisPointerClazz[type]) {
  27095. throw new Error('axisPointer ' + type + ' exists');
  27096. }
  27097. }
  27098. axisPointerClazz[type] = clazz;
  27099. };
  27100. AxisView.getAxisPointerClass = function (type) {
  27101. return type && axisPointerClazz[type];
  27102. };
  27103. /**
  27104. * @param {Object} opt {labelInside}
  27105. * @return {Object} {
  27106. * position, rotation, labelDirection, labelOffset,
  27107. * tickDirection, labelRotate, labelInterval, z2
  27108. * }
  27109. */
  27110. function layout(gridModel, axisModel, opt) {
  27111. opt = opt || {};
  27112. var grid = gridModel.coordinateSystem;
  27113. var axis = axisModel.axis;
  27114. var layout = {};
  27115. var rawAxisPosition = axis.position;
  27116. var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition;
  27117. var axisDim = axis.dim;
  27118. var rect = grid.getRect();
  27119. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  27120. var idx = {left: 0, right: 1, top: 0, bottom: 1, onZero: 2};
  27121. var axisOffset = axisModel.get('offset') || 0;
  27122. var posBound = axisDim === 'x'
  27123. ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset]
  27124. : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  27125. if (axis.onZero) {
  27126. var otherAxis = grid.getAxis(axisDim === 'x' ? 'y' : 'x', axis.onZeroAxisIndex);
  27127. var onZeroCoord = otherAxis.toGlobalCoord(otherAxis.dataToCoord(0));
  27128. posBound[idx['onZero']] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  27129. }
  27130. // Axis position
  27131. layout.position = [
  27132. axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0],
  27133. axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]
  27134. ];
  27135. // Axis rotation
  27136. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  27137. // Tick and label direction, x y is axisDim
  27138. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  27139. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  27140. layout.labelOffset = axis.onZero ? posBound[idx[rawAxisPosition]] - posBound[idx['onZero']] : 0;
  27141. if (axisModel.get('axisTick.inside')) {
  27142. layout.tickDirection = -layout.tickDirection;
  27143. }
  27144. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  27145. layout.labelDirection = -layout.labelDirection;
  27146. }
  27147. // Special label rotation
  27148. var labelRotate = axisModel.get('axisLabel.rotate');
  27149. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  27150. // label interval when auto mode.
  27151. layout.labelInterval = axis.getLabelInterval();
  27152. // Over splitLine and splitArea
  27153. layout.z2 = 1;
  27154. return layout;
  27155. }
  27156. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  27157. var getInterval = AxisBuilder.getInterval;
  27158. var axisBuilderAttrs = [
  27159. 'axisLine', 'axisTickLabel', 'axisName'
  27160. ];
  27161. var selfBuilderAttrs = [
  27162. 'splitArea', 'splitLine'
  27163. ];
  27164. // function getAlignWithLabel(model, axisModel) {
  27165. // var alignWithLabel = model.get('alignWithLabel');
  27166. // if (alignWithLabel === 'auto') {
  27167. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  27168. // }
  27169. // return alignWithLabel;
  27170. // }
  27171. var CartesianAxisView = AxisView.extend({
  27172. type: 'cartesianAxis',
  27173. axisPointerClass: 'CartesianAxisPointer',
  27174. /**
  27175. * @override
  27176. */
  27177. render: function (axisModel, ecModel, api, payload) {
  27178. this.group.removeAll();
  27179. var oldAxisGroup = this._axisGroup;
  27180. this._axisGroup = new Group();
  27181. this.group.add(this._axisGroup);
  27182. if (!axisModel.get('show')) {
  27183. return;
  27184. }
  27185. var gridModel = axisModel.getCoordSysModel();
  27186. var layout$$1 = layout(gridModel, axisModel);
  27187. var axisBuilder = new AxisBuilder(axisModel, layout$$1);
  27188. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  27189. this._axisGroup.add(axisBuilder.getGroup());
  27190. each$1(selfBuilderAttrs, function (name) {
  27191. if (axisModel.get(name + '.show')) {
  27192. this['_' + name](axisModel, gridModel, layout$$1.labelInterval);
  27193. }
  27194. }, this);
  27195. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  27196. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  27197. },
  27198. /**
  27199. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  27200. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  27201. * @param {number|Function} labelInterval
  27202. * @private
  27203. */
  27204. _splitLine: function (axisModel, gridModel, labelInterval) {
  27205. var axis = axisModel.axis;
  27206. if (axis.scale.isBlank()) {
  27207. return;
  27208. }
  27209. var splitLineModel = axisModel.getModel('splitLine');
  27210. var lineStyleModel = splitLineModel.getModel('lineStyle');
  27211. var lineColors = lineStyleModel.get('color');
  27212. var lineInterval = getInterval(splitLineModel, labelInterval);
  27213. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  27214. var gridRect = gridModel.coordinateSystem.getRect();
  27215. var isHorizontal = axis.isHorizontal();
  27216. var lineCount = 0;
  27217. var ticksCoords = axis.getTicksCoords(
  27218. // splitLineModel.get('alignWithLabel')
  27219. );
  27220. var ticks = axis.scale.getTicks();
  27221. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  27222. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  27223. var p1 = [];
  27224. var p2 = [];
  27225. // Simple optimization
  27226. // Batching the lines if color are the same
  27227. var lineStyle = lineStyleModel.getLineStyle();
  27228. for (var i = 0; i < ticksCoords.length; i++) {
  27229. if (ifIgnoreOnTick(
  27230. axis, i, lineInterval, ticksCoords.length,
  27231. showMinLabel, showMaxLabel
  27232. )) {
  27233. continue;
  27234. }
  27235. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  27236. if (isHorizontal) {
  27237. p1[0] = tickCoord;
  27238. p1[1] = gridRect.y;
  27239. p2[0] = tickCoord;
  27240. p2[1] = gridRect.y + gridRect.height;
  27241. }
  27242. else {
  27243. p1[0] = gridRect.x;
  27244. p1[1] = tickCoord;
  27245. p2[0] = gridRect.x + gridRect.width;
  27246. p2[1] = tickCoord;
  27247. }
  27248. var colorIndex = (lineCount++) % lineColors.length;
  27249. this._axisGroup.add(new Line(subPixelOptimizeLine({
  27250. anid: 'line_' + ticks[i],
  27251. shape: {
  27252. x1: p1[0],
  27253. y1: p1[1],
  27254. x2: p2[0],
  27255. y2: p2[1]
  27256. },
  27257. style: defaults({
  27258. stroke: lineColors[colorIndex]
  27259. }, lineStyle),
  27260. silent: true
  27261. })));
  27262. }
  27263. },
  27264. /**
  27265. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  27266. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  27267. * @param {number|Function} labelInterval
  27268. * @private
  27269. */
  27270. _splitArea: function (axisModel, gridModel, labelInterval) {
  27271. var axis = axisModel.axis;
  27272. if (axis.scale.isBlank()) {
  27273. return;
  27274. }
  27275. var splitAreaModel = axisModel.getModel('splitArea');
  27276. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  27277. var areaColors = areaStyleModel.get('color');
  27278. var gridRect = gridModel.coordinateSystem.getRect();
  27279. var ticksCoords = axis.getTicksCoords(
  27280. // splitAreaModel.get('alignWithLabel')
  27281. );
  27282. var ticks = axis.scale.getTicks();
  27283. var prevX = axis.toGlobalCoord(ticksCoords[0]);
  27284. var prevY = axis.toGlobalCoord(ticksCoords[0]);
  27285. var count = 0;
  27286. var areaInterval = getInterval(splitAreaModel, labelInterval);
  27287. var areaStyle = areaStyleModel.getAreaStyle();
  27288. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  27289. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  27290. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  27291. for (var i = 1; i < ticksCoords.length; i++) {
  27292. if (ifIgnoreOnTick(
  27293. axis, i, areaInterval, ticksCoords.length,
  27294. showMinLabel, showMaxLabel
  27295. )) {
  27296. continue;
  27297. }
  27298. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  27299. var x;
  27300. var y;
  27301. var width;
  27302. var height;
  27303. if (axis.isHorizontal()) {
  27304. x = prevX;
  27305. y = gridRect.y;
  27306. width = tickCoord - x;
  27307. height = gridRect.height;
  27308. }
  27309. else {
  27310. x = gridRect.x;
  27311. y = prevY;
  27312. width = gridRect.width;
  27313. height = tickCoord - y;
  27314. }
  27315. var colorIndex = (count++) % areaColors.length;
  27316. this._axisGroup.add(new Rect({
  27317. anid: 'area_' + ticks[i],
  27318. shape: {
  27319. x: x,
  27320. y: y,
  27321. width: width,
  27322. height: height
  27323. },
  27324. style: defaults({
  27325. fill: areaColors[colorIndex]
  27326. }, areaStyle),
  27327. silent: true
  27328. }));
  27329. prevX = x + width;
  27330. prevY = y + height;
  27331. }
  27332. }
  27333. });
  27334. CartesianAxisView.extend({
  27335. type: 'xAxis'
  27336. });
  27337. CartesianAxisView.extend({
  27338. type: 'yAxis'
  27339. });
  27340. // Grid view
  27341. extendComponentView({
  27342. type: 'grid',
  27343. render: function (gridModel, ecModel) {
  27344. this.group.removeAll();
  27345. if (gridModel.get('show')) {
  27346. this.group.add(new Rect({
  27347. shape: gridModel.coordinateSystem.getRect(),
  27348. style: defaults({
  27349. fill: gridModel.get('backgroundColor')
  27350. }, gridModel.getItemStyle()),
  27351. silent: true,
  27352. z2: -1
  27353. }));
  27354. }
  27355. }
  27356. });
  27357. registerPreprocessor(function (option) {
  27358. // Only create grid when need
  27359. if (option.xAxis && option.yAxis && !option.grid) {
  27360. option.grid = {};
  27361. }
  27362. });
  27363. // In case developer forget to include grid component
  27364. registerVisual(curry(
  27365. visualSymbol, 'line', 'circle', 'line'
  27366. ));
  27367. registerLayout(curry(
  27368. layoutPoints, 'line'
  27369. ));
  27370. // Down sample after filter
  27371. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, curry(
  27372. dataSample, 'line'
  27373. ));
  27374. var STACK_PREFIX = '__ec_stack_';
  27375. function getSeriesStackId(seriesModel) {
  27376. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  27377. }
  27378. function getAxisKey(axis) {
  27379. return axis.dim + axis.index;
  27380. }
  27381. /**
  27382. * @param {Object} opt
  27383. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  27384. * @param {number} opt.count Positive interger.
  27385. * @param {number} [opt.barWidth]
  27386. * @param {number} [opt.barMaxWidth]
  27387. * @param {number} [opt.barGap]
  27388. * @param {number} [opt.barCategoryGap]
  27389. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  27390. */
  27391. function getLayoutOnAxis(opt, api) {
  27392. var params = [];
  27393. var baseAxis = opt.axis;
  27394. var axisKey = 'axis0';
  27395. if (baseAxis.type !== 'category') {
  27396. return;
  27397. }
  27398. var bandWidth = baseAxis.getBandWidth();
  27399. for (var i = 0; i < opt.count || 0; i++) {
  27400. params.push(defaults({
  27401. bandWidth: bandWidth,
  27402. axisKey: axisKey,
  27403. stackId: STACK_PREFIX + i
  27404. }, opt));
  27405. }
  27406. var widthAndOffsets = doCalBarWidthAndOffset(params, api);
  27407. var result = [];
  27408. for (var i = 0; i < opt.count; i++) {
  27409. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  27410. item.offsetCenter = item.offset + item.width / 2;
  27411. result.push(item);
  27412. }
  27413. return result;
  27414. }
  27415. function calBarWidthAndOffset(barSeries, api) {
  27416. var seriesInfoList = map(barSeries, function (seriesModel) {
  27417. var data = seriesModel.getData();
  27418. var cartesian = seriesModel.coordinateSystem;
  27419. var baseAxis = cartesian.getBaseAxis();
  27420. var axisExtent = baseAxis.getExtent();
  27421. var bandWidth = baseAxis.type === 'category'
  27422. ? baseAxis.getBandWidth()
  27423. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  27424. var barWidth = parsePercent$1(
  27425. seriesModel.get('barWidth'), bandWidth
  27426. );
  27427. var barMaxWidth = parsePercent$1(
  27428. seriesModel.get('barMaxWidth'), bandWidth
  27429. );
  27430. var barGap = seriesModel.get('barGap');
  27431. var barCategoryGap = seriesModel.get('barCategoryGap');
  27432. return {
  27433. bandWidth: bandWidth,
  27434. barWidth: barWidth,
  27435. barMaxWidth: barMaxWidth,
  27436. barGap: barGap,
  27437. barCategoryGap: barCategoryGap,
  27438. axisKey: getAxisKey(baseAxis),
  27439. stackId: getSeriesStackId(seriesModel)
  27440. };
  27441. });
  27442. return doCalBarWidthAndOffset(seriesInfoList, api);
  27443. }
  27444. function doCalBarWidthAndOffset(seriesInfoList, api) {
  27445. // Columns info on each category axis. Key is cartesian name
  27446. var columnsMap = {};
  27447. each$1(seriesInfoList, function (seriesInfo, idx) {
  27448. var axisKey = seriesInfo.axisKey;
  27449. var bandWidth = seriesInfo.bandWidth;
  27450. var columnsOnAxis = columnsMap[axisKey] || {
  27451. bandWidth: bandWidth,
  27452. remainedWidth: bandWidth,
  27453. autoWidthCount: 0,
  27454. categoryGap: '20%',
  27455. gap: '30%',
  27456. stacks: {}
  27457. };
  27458. var stacks = columnsOnAxis.stacks;
  27459. columnsMap[axisKey] = columnsOnAxis;
  27460. var stackId = seriesInfo.stackId;
  27461. if (!stacks[stackId]) {
  27462. columnsOnAxis.autoWidthCount++;
  27463. }
  27464. stacks[stackId] = stacks[stackId] || {
  27465. width: 0,
  27466. maxWidth: 0
  27467. };
  27468. // Caution: In a single coordinate system, these barGrid attributes
  27469. // will be shared by series. Consider that they have default values,
  27470. // only the attributes set on the last series will work.
  27471. // Do not change this fact unless there will be a break change.
  27472. // TODO
  27473. var barWidth = seriesInfo.barWidth;
  27474. if (barWidth && !stacks[stackId].width) {
  27475. // See #6312, do not restrict width.
  27476. stacks[stackId].width = barWidth;
  27477. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  27478. columnsOnAxis.remainedWidth -= barWidth;
  27479. }
  27480. var barMaxWidth = seriesInfo.barMaxWidth;
  27481. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  27482. var barGap = seriesInfo.barGap;
  27483. (barGap != null) && (columnsOnAxis.gap = barGap);
  27484. var barCategoryGap = seriesInfo.barCategoryGap;
  27485. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  27486. });
  27487. var result = {};
  27488. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  27489. result[coordSysName] = {};
  27490. var stacks = columnsOnAxis.stacks;
  27491. var bandWidth = columnsOnAxis.bandWidth;
  27492. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  27493. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  27494. var remainedWidth = columnsOnAxis.remainedWidth;
  27495. var autoWidthCount = columnsOnAxis.autoWidthCount;
  27496. var autoWidth = (remainedWidth - categoryGap)
  27497. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27498. autoWidth = Math.max(autoWidth, 0);
  27499. // Find if any auto calculated bar exceeded maxBarWidth
  27500. each$1(stacks, function (column, stack) {
  27501. var maxWidth = column.maxWidth;
  27502. if (maxWidth && maxWidth < autoWidth) {
  27503. maxWidth = Math.min(maxWidth, remainedWidth);
  27504. if (column.width) {
  27505. maxWidth = Math.min(maxWidth, column.width);
  27506. }
  27507. remainedWidth -= maxWidth;
  27508. column.width = maxWidth;
  27509. autoWidthCount--;
  27510. }
  27511. });
  27512. // Recalculate width again
  27513. autoWidth = (remainedWidth - categoryGap)
  27514. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27515. autoWidth = Math.max(autoWidth, 0);
  27516. var widthSum = 0;
  27517. var lastColumn;
  27518. each$1(stacks, function (column, idx) {
  27519. if (!column.width) {
  27520. column.width = autoWidth;
  27521. }
  27522. lastColumn = column;
  27523. widthSum += column.width * (1 + barGapPercent);
  27524. });
  27525. if (lastColumn) {
  27526. widthSum -= lastColumn.width * barGapPercent;
  27527. }
  27528. var offset = -widthSum / 2;
  27529. each$1(stacks, function (column, stackId) {
  27530. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  27531. offset: offset,
  27532. width: column.width
  27533. };
  27534. offset += column.width * (1 + barGapPercent);
  27535. });
  27536. });
  27537. return result;
  27538. }
  27539. /**
  27540. * @param {string} seriesType
  27541. * @param {module:echarts/model/Global} ecModel
  27542. * @param {module:echarts/ExtensionAPI} api
  27543. */
  27544. function barLayoutGrid(seriesType, ecModel, api) {
  27545. var barWidthAndOffset = calBarWidthAndOffset(
  27546. filter(
  27547. ecModel.getSeriesByType(seriesType),
  27548. function (seriesModel) {
  27549. return !ecModel.isSeriesFiltered(seriesModel)
  27550. && seriesModel.coordinateSystem
  27551. && seriesModel.coordinateSystem.type === 'cartesian2d';
  27552. }
  27553. )
  27554. );
  27555. var lastStackCoords = {};
  27556. var lastStackCoordsOrigin = {};
  27557. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  27558. // Check series coordinate, do layout for cartesian2d only
  27559. if (seriesModel.coordinateSystem.type !== 'cartesian2d') {
  27560. return;
  27561. }
  27562. var data = seriesModel.getData();
  27563. var cartesian = seriesModel.coordinateSystem;
  27564. var baseAxis = cartesian.getBaseAxis();
  27565. var stackId = getSeriesStackId(seriesModel);
  27566. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  27567. var columnOffset = columnLayoutInfo.offset;
  27568. var columnWidth = columnLayoutInfo.width;
  27569. var valueAxis = cartesian.getOtherAxis(baseAxis);
  27570. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  27571. var valueAxisStart = baseAxis.onZero
  27572. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
  27573. : valueAxis.getGlobalExtent()[0];
  27574. var coordDims = [
  27575. seriesModel.coordDimToDataDim('x')[0],
  27576. seriesModel.coordDimToDataDim('y')[0]
  27577. ];
  27578. var coords = data.mapArray(coordDims, function (x, y) {
  27579. return cartesian.dataToPoint([x, y]);
  27580. }, true);
  27581. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  27582. lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
  27583. data.setLayout({
  27584. offset: columnOffset,
  27585. size: columnWidth
  27586. });
  27587. data.each(seriesModel.coordDimToDataDim(valueAxis.dim)[0], function (value, idx) {
  27588. if (isNaN(value)) {
  27589. return;
  27590. }
  27591. if (!lastStackCoords[stackId][idx]) {
  27592. lastStackCoords[stackId][idx] = {
  27593. p: valueAxisStart, // Positive stack
  27594. n: valueAxisStart // Negative stack
  27595. };
  27596. lastStackCoordsOrigin[stackId][idx] = {
  27597. p: valueAxisStart, // Positive stack
  27598. n: valueAxisStart // Negative stack
  27599. };
  27600. }
  27601. var sign = value >= 0 ? 'p' : 'n';
  27602. var coord = coords[idx];
  27603. var lastCoord = lastStackCoords[stackId][idx][sign];
  27604. var lastCoordOrigin = lastStackCoordsOrigin[stackId][idx][sign];
  27605. var x;
  27606. var y;
  27607. var width;
  27608. var height;
  27609. if (valueAxis.isHorizontal()) {
  27610. x = lastCoord;
  27611. y = coord[1] + columnOffset;
  27612. width = coord[0] - lastCoordOrigin;
  27613. height = columnWidth;
  27614. lastStackCoordsOrigin[stackId][idx][sign] += width;
  27615. if (Math.abs(width) < barMinHeight) {
  27616. width = (width < 0 ? -1 : 1) * barMinHeight;
  27617. }
  27618. lastStackCoords[stackId][idx][sign] += width;
  27619. }
  27620. else {
  27621. x = coord[0] + columnOffset;
  27622. y = lastCoord;
  27623. width = columnWidth;
  27624. height = coord[1] - lastCoordOrigin;
  27625. lastStackCoordsOrigin[stackId][idx][sign] += height;
  27626. if (Math.abs(height) < barMinHeight) {
  27627. // Include zero to has a positive bar
  27628. height = (height <= 0 ? -1 : 1) * barMinHeight;
  27629. }
  27630. lastStackCoords[stackId][idx][sign] += height;
  27631. }
  27632. data.setItemLayout(idx, {
  27633. x: x,
  27634. y: y,
  27635. width: width,
  27636. height: height
  27637. });
  27638. }, true);
  27639. }, this);
  27640. }
  27641. barLayoutGrid.getLayoutOnAxis = getLayoutOnAxis;
  27642. var BaseBarSeries = SeriesModel.extend({
  27643. type: 'series.__base_bar__',
  27644. getInitialData: function (option, ecModel) {
  27645. return createListFromArray(option.data, this, ecModel);
  27646. },
  27647. getMarkerPosition: function (value) {
  27648. var coordSys = this.coordinateSystem;
  27649. if (coordSys) {
  27650. // PENDING if clamp ?
  27651. var pt = coordSys.dataToPoint(value, true);
  27652. var data = this.getData();
  27653. var offset = data.getLayout('offset');
  27654. var size = data.getLayout('size');
  27655. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  27656. pt[offsetIndex] += offset + size / 2;
  27657. return pt;
  27658. }
  27659. return [NaN, NaN];
  27660. },
  27661. defaultOption: {
  27662. zlevel: 0, // 一级层叠
  27663. z: 2, // 二级层叠
  27664. coordinateSystem: 'cartesian2d',
  27665. legendHoverLink: true,
  27666. // stack: null
  27667. // Cartesian coordinate system
  27668. // xAxisIndex: 0,
  27669. // yAxisIndex: 0,
  27670. // 最小高度改为0
  27671. barMinHeight: 0,
  27672. // 最小角度为0,仅对极坐标系下的柱状图有效
  27673. barMinAngle: 0,
  27674. // cursor: null,
  27675. // barMaxWidth: null,
  27676. // 默认自适应
  27677. // barWidth: null,
  27678. // 柱间距离,默认为柱形宽度的30%,可设固定值
  27679. // barGap: '30%',
  27680. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  27681. // barCategoryGap: '20%',
  27682. // label: {
  27683. // normal: {
  27684. // show: false
  27685. // }
  27686. // },
  27687. itemStyle: {
  27688. // normal: {
  27689. // color: '各异'
  27690. // },
  27691. // emphasis: {}
  27692. }
  27693. }
  27694. });
  27695. BaseBarSeries.extend({
  27696. type: 'series.bar',
  27697. dependencies: ['grid', 'polar'],
  27698. brushSelector: 'rect'
  27699. });
  27700. function setLabel(
  27701. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  27702. ) {
  27703. var labelModel = itemModel.getModel('label.normal');
  27704. var hoverLabelModel = itemModel.getModel('label.emphasis');
  27705. setLabelStyle(
  27706. normalStyle, hoverStyle, labelModel, hoverLabelModel,
  27707. {
  27708. labelFetcher: seriesModel,
  27709. labelDataIndex: dataIndex,
  27710. defaultText: seriesModel.getRawValue(dataIndex),
  27711. isRectText: true,
  27712. autoColor: color
  27713. }
  27714. );
  27715. fixPosition(normalStyle);
  27716. fixPosition(hoverStyle);
  27717. }
  27718. function fixPosition(style, labelPositionOutside) {
  27719. if (style.textPosition === 'outside') {
  27720. style.textPosition = labelPositionOutside;
  27721. }
  27722. }
  27723. var getBarItemStyle = makeStyleMapper(
  27724. [
  27725. ['fill', 'color'],
  27726. ['stroke', 'borderColor'],
  27727. ['lineWidth', 'borderWidth'],
  27728. // Compatitable with 2
  27729. ['stroke', 'barBorderColor'],
  27730. ['lineWidth', 'barBorderWidth'],
  27731. ['opacity'],
  27732. ['shadowBlur'],
  27733. ['shadowOffsetX'],
  27734. ['shadowOffsetY'],
  27735. ['shadowColor']
  27736. ]
  27737. );
  27738. var barItemStyle = {
  27739. getBarItemStyle: function (excludes) {
  27740. var style = getBarItemStyle(this, excludes);
  27741. if (this.getBorderLineDash) {
  27742. var lineDash = this.getBorderLineDash();
  27743. lineDash && (style.lineDash = lineDash);
  27744. }
  27745. return style;
  27746. }
  27747. };
  27748. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'normal', 'barBorderWidth'];
  27749. // FIXME
  27750. // Just for compatible with ec2.
  27751. extend(Model.prototype, barItemStyle);
  27752. extendChartView({
  27753. type: 'bar',
  27754. render: function (seriesModel, ecModel, api) {
  27755. var coordinateSystemType = seriesModel.get('coordinateSystem');
  27756. if (coordinateSystemType === 'cartesian2d'
  27757. || coordinateSystemType === 'polar'
  27758. ) {
  27759. this._render(seriesModel, ecModel, api);
  27760. }
  27761. else if (__DEV__) {
  27762. console.warn('Only cartesian2d and polar supported for bar.');
  27763. }
  27764. return this.group;
  27765. },
  27766. dispose: noop,
  27767. _render: function (seriesModel, ecModel, api) {
  27768. var group = this.group;
  27769. var data = seriesModel.getData();
  27770. var oldData = this._data;
  27771. var coord = seriesModel.coordinateSystem;
  27772. var baseAxis = coord.getBaseAxis();
  27773. var isHorizontalOrRadial;
  27774. if (coord.type === 'cartesian2d') {
  27775. isHorizontalOrRadial = baseAxis.isHorizontal();
  27776. }
  27777. else if (coord.type === 'polar') {
  27778. isHorizontalOrRadial = baseAxis.dim === 'angle';
  27779. }
  27780. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  27781. data.diff(oldData)
  27782. .add(function (dataIndex) {
  27783. if (!data.hasValue(dataIndex)) {
  27784. return;
  27785. }
  27786. var itemModel = data.getItemModel(dataIndex);
  27787. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  27788. var el = elementCreator[coord.type](
  27789. data, dataIndex, itemModel, layout, isHorizontalOrRadial, animationModel
  27790. );
  27791. data.setItemGraphicEl(dataIndex, el);
  27792. group.add(el);
  27793. updateStyle(
  27794. el, data, dataIndex, itemModel, layout,
  27795. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  27796. );
  27797. })
  27798. .update(function (newIndex, oldIndex) {
  27799. var el = oldData.getItemGraphicEl(oldIndex);
  27800. if (!data.hasValue(newIndex)) {
  27801. group.remove(el);
  27802. return;
  27803. }
  27804. var itemModel = data.getItemModel(newIndex);
  27805. var layout = getLayout[coord.type](data, newIndex, itemModel);
  27806. if (el) {
  27807. updateProps(el, {shape: layout}, animationModel, newIndex);
  27808. }
  27809. else {
  27810. el = elementCreator[coord.type](
  27811. data, newIndex, itemModel, layout, isHorizontalOrRadial, animationModel, true
  27812. );
  27813. }
  27814. data.setItemGraphicEl(newIndex, el);
  27815. // Add back
  27816. group.add(el);
  27817. updateStyle(
  27818. el, data, newIndex, itemModel, layout,
  27819. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  27820. );
  27821. })
  27822. .remove(function (dataIndex) {
  27823. var el = oldData.getItemGraphicEl(dataIndex);
  27824. if (coord.type === 'cartesian2d') {
  27825. el && removeRect(dataIndex, animationModel, el);
  27826. }
  27827. else {
  27828. el && removeSector(dataIndex, animationModel, el);
  27829. }
  27830. })
  27831. .execute();
  27832. this._data = data;
  27833. },
  27834. remove: function (ecModel, api) {
  27835. var group = this.group;
  27836. var data = this._data;
  27837. if (ecModel.get('animation')) {
  27838. if (data) {
  27839. data.eachItemGraphicEl(function (el) {
  27840. if (el.type === 'sector') {
  27841. removeSector(el.dataIndex, ecModel, el);
  27842. }
  27843. else {
  27844. removeRect(el.dataIndex, ecModel, el);
  27845. }
  27846. });
  27847. }
  27848. }
  27849. else {
  27850. group.removeAll();
  27851. }
  27852. }
  27853. });
  27854. var elementCreator = {
  27855. cartesian2d: function (
  27856. data, dataIndex, itemModel, layout, isHorizontal,
  27857. animationModel, isUpdate
  27858. ) {
  27859. var rect = new Rect({shape: extend({}, layout)});
  27860. // Animation
  27861. if (animationModel) {
  27862. var rectShape = rect.shape;
  27863. var animateProperty = isHorizontal ? 'height' : 'width';
  27864. var animateTarget = {};
  27865. rectShape[animateProperty] = 0;
  27866. animateTarget[animateProperty] = layout[animateProperty];
  27867. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  27868. shape: animateTarget
  27869. }, animationModel, dataIndex);
  27870. }
  27871. return rect;
  27872. },
  27873. polar: function (
  27874. data, dataIndex, itemModel, layout, isRadial,
  27875. animationModel, isUpdate
  27876. ) {
  27877. var sector = new Sector({shape: extend({}, layout)});
  27878. // Animation
  27879. if (animationModel) {
  27880. var sectorShape = sector.shape;
  27881. var animateProperty = isRadial ? 'r' : 'endAngle';
  27882. var animateTarget = {};
  27883. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  27884. animateTarget[animateProperty] = layout[animateProperty];
  27885. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  27886. shape: animateTarget
  27887. }, animationModel, dataIndex);
  27888. }
  27889. return sector;
  27890. }
  27891. };
  27892. function removeRect(dataIndex, animationModel, el) {
  27893. // Not show text when animating
  27894. el.style.text = null;
  27895. updateProps(el, {
  27896. shape: {
  27897. width: 0
  27898. }
  27899. }, animationModel, dataIndex, function () {
  27900. el.parent && el.parent.remove(el);
  27901. });
  27902. }
  27903. function removeSector(dataIndex, animationModel, el) {
  27904. // Not show text when animating
  27905. el.style.text = null;
  27906. updateProps(el, {
  27907. shape: {
  27908. r: el.shape.r0
  27909. }
  27910. }, animationModel, dataIndex, function () {
  27911. el.parent && el.parent.remove(el);
  27912. });
  27913. }
  27914. var getLayout = {
  27915. cartesian2d: function (data, dataIndex, itemModel) {
  27916. var layout = data.getItemLayout(dataIndex);
  27917. var fixedLineWidth = getLineWidth(itemModel, layout);
  27918. // fix layout with lineWidth
  27919. var signX = layout.width > 0 ? 1 : -1;
  27920. var signY = layout.height > 0 ? 1 : -1;
  27921. return {
  27922. x: layout.x + signX * fixedLineWidth / 2,
  27923. y: layout.y + signY * fixedLineWidth / 2,
  27924. width: layout.width - signX * fixedLineWidth,
  27925. height: layout.height - signY * fixedLineWidth
  27926. };
  27927. },
  27928. polar: function (data, dataIndex, itemModel) {
  27929. var layout = data.getItemLayout(dataIndex);
  27930. return {
  27931. cx: layout.cx,
  27932. cy: layout.cy,
  27933. r0: layout.r0,
  27934. r: layout.r,
  27935. startAngle: layout.startAngle,
  27936. endAngle: layout.endAngle
  27937. };
  27938. }
  27939. };
  27940. function updateStyle(
  27941. el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar
  27942. ) {
  27943. var color = data.getItemVisual(dataIndex, 'color');
  27944. var opacity = data.getItemVisual(dataIndex, 'opacity');
  27945. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  27946. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getBarItemStyle();
  27947. if (!isPolar) {
  27948. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  27949. }
  27950. el.useStyle(defaults(
  27951. {
  27952. fill: color,
  27953. opacity: opacity
  27954. },
  27955. itemStyleModel.getBarItemStyle()
  27956. ));
  27957. var cursorStyle = itemModel.getShallow('cursor');
  27958. cursorStyle && el.attr('cursor', cursorStyle);
  27959. var labelPositionOutside = isHorizontal
  27960. ? (layout.height > 0 ? 'bottom' : 'top')
  27961. : (layout.width > 0 ? 'left' : 'right');
  27962. if (!isPolar) {
  27963. setLabel(
  27964. el.style, hoverStyle, itemModel, color,
  27965. seriesModel, dataIndex, labelPositionOutside
  27966. );
  27967. }
  27968. setHoverStyle(el, hoverStyle);
  27969. }
  27970. // In case width or height are too small.
  27971. function getLineWidth(itemModel, rawLayout) {
  27972. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  27973. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  27974. }
  27975. // In case developer forget to include grid component
  27976. registerLayout(curry(barLayoutGrid, 'bar'));
  27977. // Visual coding for legend
  27978. registerVisual(function (ecModel) {
  27979. ecModel.eachSeriesByType('bar', function (seriesModel) {
  27980. var data = seriesModel.getData();
  27981. data.setVisual('legendSymbol', 'roundRect');
  27982. });
  27983. });
  27984. /**
  27985. * Data selectable mixin for chart series.
  27986. * To eanble data select, option of series must have `selectedMode`.
  27987. * And each data item will use `selected` to toggle itself selected status
  27988. */
  27989. var dataSelectableMixin = {
  27990. updateSelectedMap: function (targetList) {
  27991. this._targetList = targetList.slice();
  27992. this._selectTargetMap = reduce(targetList || [], function (targetMap, target) {
  27993. targetMap.set(target.name, target);
  27994. return targetMap;
  27995. }, createHashMap());
  27996. },
  27997. /**
  27998. * Either name or id should be passed as input here.
  27999. * If both of them are defined, id is used.
  28000. *
  28001. * @param {string|undefined} name name of data
  28002. * @param {number|undefined} id dataIndex of data
  28003. */
  28004. // PENGING If selectedMode is null ?
  28005. select: function (name, id) {
  28006. var target = id != null
  28007. ? this._targetList[id]
  28008. : this._selectTargetMap.get(name);
  28009. var selectedMode = this.get('selectedMode');
  28010. if (selectedMode === 'single') {
  28011. this._selectTargetMap.each(function (target) {
  28012. target.selected = false;
  28013. });
  28014. }
  28015. target && (target.selected = true);
  28016. },
  28017. /**
  28018. * Either name or id should be passed as input here.
  28019. * If both of them are defined, id is used.
  28020. *
  28021. * @param {string|undefined} name name of data
  28022. * @param {number|undefined} id dataIndex of data
  28023. */
  28024. unSelect: function (name, id) {
  28025. var target = id != null
  28026. ? this._targetList[id]
  28027. : this._selectTargetMap.get(name);
  28028. // var selectedMode = this.get('selectedMode');
  28029. // selectedMode !== 'single' && target && (target.selected = false);
  28030. target && (target.selected = false);
  28031. },
  28032. /**
  28033. * Either name or id should be passed as input here.
  28034. * If both of them are defined, id is used.
  28035. *
  28036. * @param {string|undefined} name name of data
  28037. * @param {number|undefined} id dataIndex of data
  28038. */
  28039. toggleSelected: function (name, id) {
  28040. var target = id != null
  28041. ? this._targetList[id]
  28042. : this._selectTargetMap.get(name);
  28043. if (target != null) {
  28044. this[target.selected ? 'unSelect' : 'select'](name, id);
  28045. return target.selected;
  28046. }
  28047. },
  28048. /**
  28049. * Either name or id should be passed as input here.
  28050. * If both of them are defined, id is used.
  28051. *
  28052. * @param {string|undefined} name name of data
  28053. * @param {number|undefined} id dataIndex of data
  28054. */
  28055. isSelected: function (name, id) {
  28056. var target = id != null
  28057. ? this._targetList[id]
  28058. : this._selectTargetMap.get(name);
  28059. return target && target.selected;
  28060. }
  28061. };
  28062. var PieSeries = extendSeriesModel({
  28063. type: 'series.pie',
  28064. // Overwrite
  28065. init: function (option) {
  28066. PieSeries.superApply(this, 'init', arguments);
  28067. // Enable legend selection for each data item
  28068. // Use a function instead of direct access because data reference may changed
  28069. this.legendDataProvider = function () {
  28070. return this.getRawData();
  28071. };
  28072. this.updateSelectedMap(option.data);
  28073. this._defaultLabelLine(option);
  28074. },
  28075. // Overwrite
  28076. mergeOption: function (newOption) {
  28077. PieSeries.superCall(this, 'mergeOption', newOption);
  28078. this.updateSelectedMap(this.option.data);
  28079. },
  28080. getInitialData: function (option, ecModel) {
  28081. var dimensions = completeDimensions(['value'], option.data);
  28082. var list = new List(dimensions, this);
  28083. list.initData(option.data);
  28084. return list;
  28085. },
  28086. // Overwrite
  28087. getDataParams: function (dataIndex) {
  28088. var data = this.getData();
  28089. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  28090. // FIXME toFixed?
  28091. var valueList = [];
  28092. data.each('value', function (value) {
  28093. valueList.push(value);
  28094. });
  28095. params.percent = getPercentWithPrecision(
  28096. valueList,
  28097. dataIndex,
  28098. data.hostModel.get('percentPrecision')
  28099. );
  28100. params.$vars.push('percent');
  28101. return params;
  28102. },
  28103. _defaultLabelLine: function (option) {
  28104. // Extend labelLine emphasis
  28105. defaultEmphasis(option.labelLine, ['show']);
  28106. var labelLineNormalOpt = option.labelLine.normal;
  28107. var labelLineEmphasisOpt = option.labelLine.emphasis;
  28108. // Not show label line if `label.normal.show = false`
  28109. labelLineNormalOpt.show = labelLineNormalOpt.show
  28110. && option.label.normal.show;
  28111. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  28112. && option.label.emphasis.show;
  28113. },
  28114. defaultOption: {
  28115. zlevel: 0,
  28116. z: 2,
  28117. legendHoverLink: true,
  28118. hoverAnimation: true,
  28119. // 默认全局居中
  28120. center: ['50%', '50%'],
  28121. radius: [0, '75%'],
  28122. // 默认顺时针
  28123. clockwise: true,
  28124. startAngle: 90,
  28125. // 最小角度改为0
  28126. minAngle: 0,
  28127. // 选中时扇区偏移量
  28128. selectedOffset: 10,
  28129. // 高亮扇区偏移量
  28130. hoverOffset: 10,
  28131. // If use strategy to avoid label overlapping
  28132. avoidLabelOverlap: true,
  28133. // 选择模式,默认关闭,可选single,multiple
  28134. // selectedMode: false,
  28135. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  28136. // roseType: null,
  28137. percentPrecision: 2,
  28138. // If still show when all data zero.
  28139. stillShowZeroSum: true,
  28140. // cursor: null,
  28141. label: {
  28142. normal: {
  28143. // If rotate around circle
  28144. rotate: false,
  28145. show: true,
  28146. // 'outer', 'inside', 'center'
  28147. position: 'outer'
  28148. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  28149. // 默认使用全局文本样式,详见TEXTSTYLE
  28150. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  28151. },
  28152. emphasis: {}
  28153. },
  28154. // Enabled when label.normal.position is 'outer'
  28155. labelLine: {
  28156. normal: {
  28157. show: true,
  28158. // 引导线两段中的第一段长度
  28159. length: 15,
  28160. // 引导线两段中的第二段长度
  28161. length2: 15,
  28162. smooth: false,
  28163. lineStyle: {
  28164. // color: 各异,
  28165. width: 1,
  28166. type: 'solid'
  28167. }
  28168. }
  28169. },
  28170. itemStyle: {
  28171. normal: {
  28172. borderWidth: 1
  28173. },
  28174. emphasis: {}
  28175. },
  28176. // Animation type canbe expansion, scale
  28177. animationType: 'expansion',
  28178. animationEasing: 'cubicOut',
  28179. data: []
  28180. }
  28181. });
  28182. mixin(PieSeries, dataSelectableMixin);
  28183. /**
  28184. * @param {module:echarts/model/Series} seriesModel
  28185. * @param {boolean} hasAnimation
  28186. * @inner
  28187. */
  28188. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  28189. var data = seriesModel.getData();
  28190. var dataIndex = this.dataIndex;
  28191. var name = data.getName(dataIndex);
  28192. var selectedOffset = seriesModel.get('selectedOffset');
  28193. api.dispatchAction({
  28194. type: 'pieToggleSelect',
  28195. from: uid,
  28196. name: name,
  28197. seriesId: seriesModel.id
  28198. });
  28199. data.each(function (idx) {
  28200. toggleItemSelected(
  28201. data.getItemGraphicEl(idx),
  28202. data.getItemLayout(idx),
  28203. seriesModel.isSelected(data.getName(idx)),
  28204. selectedOffset,
  28205. hasAnimation
  28206. );
  28207. });
  28208. }
  28209. /**
  28210. * @param {module:zrender/graphic/Sector} el
  28211. * @param {Object} layout
  28212. * @param {boolean} isSelected
  28213. * @param {number} selectedOffset
  28214. * @param {boolean} hasAnimation
  28215. * @inner
  28216. */
  28217. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  28218. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  28219. var dx = Math.cos(midAngle);
  28220. var dy = Math.sin(midAngle);
  28221. var offset = isSelected ? selectedOffset : 0;
  28222. var position = [dx * offset, dy * offset];
  28223. hasAnimation
  28224. // animateTo will stop revious animation like update transition
  28225. ? el.animate()
  28226. .when(200, {
  28227. position: position
  28228. })
  28229. .start('bounceOut')
  28230. : el.attr('position', position);
  28231. }
  28232. /**
  28233. * Piece of pie including Sector, Label, LabelLine
  28234. * @constructor
  28235. * @extends {module:zrender/graphic/Group}
  28236. */
  28237. function PiePiece(data, idx) {
  28238. Group.call(this);
  28239. var sector = new Sector({
  28240. z2: 2
  28241. });
  28242. var polyline = new Polyline();
  28243. var text = new Text();
  28244. this.add(sector);
  28245. this.add(polyline);
  28246. this.add(text);
  28247. this.updateData(data, idx, true);
  28248. // Hover to change label and labelLine
  28249. function onEmphasis() {
  28250. polyline.ignore = polyline.hoverIgnore;
  28251. text.ignore = text.hoverIgnore;
  28252. }
  28253. function onNormal() {
  28254. polyline.ignore = polyline.normalIgnore;
  28255. text.ignore = text.normalIgnore;
  28256. }
  28257. this.on('emphasis', onEmphasis)
  28258. .on('normal', onNormal)
  28259. .on('mouseover', onEmphasis)
  28260. .on('mouseout', onNormal);
  28261. }
  28262. var piePieceProto = PiePiece.prototype;
  28263. piePieceProto.updateData = function (data, idx, firstCreate) {
  28264. var sector = this.childAt(0);
  28265. var seriesModel = data.hostModel;
  28266. var itemModel = data.getItemModel(idx);
  28267. var layout = data.getItemLayout(idx);
  28268. var sectorShape = extend({}, layout);
  28269. sectorShape.label = null;
  28270. if (firstCreate) {
  28271. sector.setShape(sectorShape);
  28272. var animationType = seriesModel.getShallow('animationType');
  28273. if (animationType === 'scale') {
  28274. sector.shape.r = layout.r0;
  28275. initProps(sector, {
  28276. shape: {
  28277. r: layout.r
  28278. }
  28279. }, seriesModel, idx);
  28280. }
  28281. // Expansion
  28282. else {
  28283. sector.shape.endAngle = layout.startAngle;
  28284. updateProps(sector, {
  28285. shape: {
  28286. endAngle: layout.endAngle
  28287. }
  28288. }, seriesModel, idx);
  28289. }
  28290. }
  28291. else {
  28292. updateProps(sector, {
  28293. shape: sectorShape
  28294. }, seriesModel, idx);
  28295. }
  28296. // Update common style
  28297. var itemStyleModel = itemModel.getModel('itemStyle');
  28298. var visualColor = data.getItemVisual(idx, 'color');
  28299. sector.useStyle(
  28300. defaults(
  28301. {
  28302. lineJoin: 'bevel',
  28303. fill: visualColor
  28304. },
  28305. itemStyleModel.getModel('normal').getItemStyle()
  28306. )
  28307. );
  28308. sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  28309. var cursorStyle = itemModel.getShallow('cursor');
  28310. cursorStyle && sector.attr('cursor', cursorStyle);
  28311. // Toggle selected
  28312. toggleItemSelected(
  28313. this,
  28314. data.getItemLayout(idx),
  28315. itemModel.get('selected'),
  28316. seriesModel.get('selectedOffset'),
  28317. seriesModel.get('animation')
  28318. );
  28319. function onEmphasis() {
  28320. // Sector may has animation of updating data. Force to move to the last frame
  28321. // Or it may stopped on the wrong shape
  28322. sector.stopAnimation(true);
  28323. sector.animateTo({
  28324. shape: {
  28325. r: layout.r + seriesModel.get('hoverOffset')
  28326. }
  28327. }, 300, 'elasticOut');
  28328. }
  28329. function onNormal() {
  28330. sector.stopAnimation(true);
  28331. sector.animateTo({
  28332. shape: {
  28333. r: layout.r
  28334. }
  28335. }, 300, 'elasticOut');
  28336. }
  28337. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  28338. if (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) {
  28339. sector
  28340. .on('mouseover', onEmphasis)
  28341. .on('mouseout', onNormal)
  28342. .on('emphasis', onEmphasis)
  28343. .on('normal', onNormal);
  28344. }
  28345. this._updateLabel(data, idx);
  28346. setHoverStyle(this);
  28347. };
  28348. piePieceProto._updateLabel = function (data, idx) {
  28349. var labelLine = this.childAt(1);
  28350. var labelText = this.childAt(2);
  28351. var seriesModel = data.hostModel;
  28352. var itemModel = data.getItemModel(idx);
  28353. var layout = data.getItemLayout(idx);
  28354. var labelLayout = layout.label;
  28355. var visualColor = data.getItemVisual(idx, 'color');
  28356. updateProps(labelLine, {
  28357. shape: {
  28358. points: labelLayout.linePoints || [
  28359. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  28360. ]
  28361. }
  28362. }, seriesModel, idx);
  28363. updateProps(labelText, {
  28364. style: {
  28365. x: labelLayout.x,
  28366. y: labelLayout.y
  28367. }
  28368. }, seriesModel, idx);
  28369. labelText.attr({
  28370. rotation: labelLayout.rotation,
  28371. origin: [labelLayout.x, labelLayout.y],
  28372. z2: 10
  28373. });
  28374. var labelModel = itemModel.getModel('label.normal');
  28375. var labelHoverModel = itemModel.getModel('label.emphasis');
  28376. var labelLineModel = itemModel.getModel('labelLine.normal');
  28377. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  28378. var visualColor = data.getItemVisual(idx, 'color');
  28379. setLabelStyle(
  28380. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  28381. {
  28382. labelFetcher: data.hostModel,
  28383. labelDataIndex: idx,
  28384. defaultText: data.getName(idx),
  28385. autoColor: visualColor,
  28386. useInsideStyle: !!labelLayout.inside
  28387. },
  28388. {
  28389. textAlign: labelLayout.textAlign,
  28390. textVerticalAlign: labelLayout.verticalAlign,
  28391. opacity: data.getItemVisual(idx, 'opacity')
  28392. }
  28393. );
  28394. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  28395. labelText.hoverIgnore = !labelHoverModel.get('show');
  28396. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  28397. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  28398. // Default use item visual color
  28399. labelLine.setStyle({
  28400. stroke: visualColor,
  28401. opacity: data.getItemVisual(idx, 'opacity')
  28402. });
  28403. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  28404. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  28405. var smooth = labelLineModel.get('smooth');
  28406. if (smooth && smooth === true) {
  28407. smooth = 0.4;
  28408. }
  28409. labelLine.setShape({
  28410. smooth: smooth
  28411. });
  28412. };
  28413. inherits(PiePiece, Group);
  28414. // Pie view
  28415. var PieView = Chart.extend({
  28416. type: 'pie',
  28417. init: function () {
  28418. var sectorGroup = new Group();
  28419. this._sectorGroup = sectorGroup;
  28420. },
  28421. render: function (seriesModel, ecModel, api, payload) {
  28422. if (payload && (payload.from === this.uid)) {
  28423. return;
  28424. }
  28425. var data = seriesModel.getData();
  28426. var oldData = this._data;
  28427. var group = this.group;
  28428. var hasAnimation = ecModel.get('animation');
  28429. var isFirstRender = !oldData;
  28430. var animationType = seriesModel.get('animationType');
  28431. var onSectorClick = curry(
  28432. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  28433. );
  28434. var selectedMode = seriesModel.get('selectedMode');
  28435. data.diff(oldData)
  28436. .add(function (idx) {
  28437. var piePiece = new PiePiece(data, idx);
  28438. // Default expansion animation
  28439. if (isFirstRender && animationType !== 'scale') {
  28440. piePiece.eachChild(function (child) {
  28441. child.stopAnimation(true);
  28442. });
  28443. }
  28444. selectedMode && piePiece.on('click', onSectorClick);
  28445. data.setItemGraphicEl(idx, piePiece);
  28446. group.add(piePiece);
  28447. })
  28448. .update(function (newIdx, oldIdx) {
  28449. var piePiece = oldData.getItemGraphicEl(oldIdx);
  28450. piePiece.updateData(data, newIdx);
  28451. piePiece.off('click');
  28452. selectedMode && piePiece.on('click', onSectorClick);
  28453. group.add(piePiece);
  28454. data.setItemGraphicEl(newIdx, piePiece);
  28455. })
  28456. .remove(function (idx) {
  28457. var piePiece = oldData.getItemGraphicEl(idx);
  28458. group.remove(piePiece);
  28459. })
  28460. .execute();
  28461. if (
  28462. hasAnimation && isFirstRender && data.count() > 0
  28463. // Default expansion animation
  28464. && animationType !== 'scale'
  28465. ) {
  28466. var shape = data.getItemLayout(0);
  28467. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  28468. var removeClipPath = bind(group.removeClipPath, group);
  28469. group.setClipPath(this._createClipPath(
  28470. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  28471. ));
  28472. }
  28473. this._data = data;
  28474. },
  28475. dispose: function () {},
  28476. _createClipPath: function (
  28477. cx, cy, r, startAngle, clockwise, cb, seriesModel
  28478. ) {
  28479. var clipPath = new Sector({
  28480. shape: {
  28481. cx: cx,
  28482. cy: cy,
  28483. r0: 0,
  28484. r: r,
  28485. startAngle: startAngle,
  28486. endAngle: startAngle,
  28487. clockwise: clockwise
  28488. }
  28489. });
  28490. initProps(clipPath, {
  28491. shape: {
  28492. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  28493. }
  28494. }, seriesModel, cb);
  28495. return clipPath;
  28496. },
  28497. /**
  28498. * @implement
  28499. */
  28500. containPoint: function (point, seriesModel) {
  28501. var data = seriesModel.getData();
  28502. var itemLayout = data.getItemLayout(0);
  28503. if (itemLayout) {
  28504. var dx = point[0] - itemLayout.cx;
  28505. var dy = point[1] - itemLayout.cy;
  28506. var radius = Math.sqrt(dx * dx + dy * dy);
  28507. return radius <= itemLayout.r && radius >= itemLayout.r0;
  28508. }
  28509. }
  28510. });
  28511. var createDataSelectAction = function (seriesType, actionInfos) {
  28512. each$1(actionInfos, function (actionInfo) {
  28513. actionInfo.update = 'updateView';
  28514. /**
  28515. * @payload
  28516. * @property {string} seriesName
  28517. * @property {string} name
  28518. */
  28519. registerAction(actionInfo, function (payload, ecModel) {
  28520. var selected = {};
  28521. ecModel.eachComponent(
  28522. {mainType: 'series', subType: seriesType, query: payload},
  28523. function (seriesModel) {
  28524. if (seriesModel[actionInfo.method]) {
  28525. seriesModel[actionInfo.method](
  28526. payload.name,
  28527. payload.dataIndex
  28528. );
  28529. }
  28530. var data = seriesModel.getData();
  28531. // Create selected map
  28532. data.each(function (idx) {
  28533. var name = data.getName(idx);
  28534. selected[name] = seriesModel.isSelected(name)
  28535. || false;
  28536. });
  28537. }
  28538. );
  28539. return {
  28540. name: payload.name,
  28541. selected: selected
  28542. };
  28543. });
  28544. });
  28545. };
  28546. // Pick color from palette for each data item.
  28547. // Applicable for charts that require applying color palette
  28548. // in data level (like pie, funnel, chord).
  28549. var dataColor = function (seriesType, ecModel) {
  28550. // Pie and funnel may use diferrent scope
  28551. var paletteScope = {};
  28552. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  28553. var dataAll = seriesModel.getRawData();
  28554. var idxMap = {};
  28555. if (!ecModel.isSeriesFiltered(seriesModel)) {
  28556. var data = seriesModel.getData();
  28557. data.each(function (idx) {
  28558. var rawIdx = data.getRawIndex(idx);
  28559. idxMap[rawIdx] = idx;
  28560. });
  28561. dataAll.each(function (rawIdx) {
  28562. var filteredIdx = idxMap[rawIdx];
  28563. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  28564. var singleDataColor = filteredIdx != null
  28565. && data.getItemVisual(filteredIdx, 'color', true);
  28566. if (!singleDataColor) {
  28567. // FIXME Performance
  28568. var itemModel = dataAll.getItemModel(rawIdx);
  28569. var color = itemModel.get('itemStyle.normal.color')
  28570. || seriesModel.getColorFromPalette(dataAll.getName(rawIdx), paletteScope);
  28571. // Legend may use the visual info in data before processed
  28572. dataAll.setItemVisual(rawIdx, 'color', color);
  28573. // Data is not filtered
  28574. if (filteredIdx != null) {
  28575. data.setItemVisual(filteredIdx, 'color', color);
  28576. }
  28577. }
  28578. else {
  28579. // Set data all color for legend
  28580. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  28581. }
  28582. });
  28583. }
  28584. });
  28585. };
  28586. // FIXME emphasis label position is not same with normal label position
  28587. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  28588. list.sort(function (a, b) {
  28589. return a.y - b.y;
  28590. });
  28591. // 压
  28592. function shiftDown(start, end, delta, dir) {
  28593. for (var j = start; j < end; j++) {
  28594. list[j].y += delta;
  28595. if (j > start
  28596. && j + 1 < end
  28597. && list[j + 1].y > list[j].y + list[j].height
  28598. ) {
  28599. shiftUp(j, delta / 2);
  28600. return;
  28601. }
  28602. }
  28603. shiftUp(end - 1, delta / 2);
  28604. }
  28605. // 弹
  28606. function shiftUp(end, delta) {
  28607. for (var j = end; j >= 0; j--) {
  28608. list[j].y -= delta;
  28609. if (j > 0
  28610. && list[j].y > list[j - 1].y + list[j - 1].height
  28611. ) {
  28612. break;
  28613. }
  28614. }
  28615. }
  28616. function changeX(list, isDownList, cx, cy, r, dir) {
  28617. var lastDeltaX = dir > 0
  28618. ? isDownList // 右侧
  28619. ? Number.MAX_VALUE // 下
  28620. : 0 // 上
  28621. : isDownList // 左侧
  28622. ? Number.MAX_VALUE // 下
  28623. : 0; // 上
  28624. for (var i = 0, l = list.length; i < l; i++) {
  28625. // Not change x for center label
  28626. if (list[i].position === 'center') {
  28627. continue;
  28628. }
  28629. var deltaY = Math.abs(list[i].y - cy);
  28630. var length = list[i].len;
  28631. var length2 = list[i].len2;
  28632. var deltaX = (deltaY < r + length)
  28633. ? Math.sqrt(
  28634. (r + length + length2) * (r + length + length2)
  28635. - deltaY * deltaY
  28636. )
  28637. : Math.abs(list[i].x - cx);
  28638. if (isDownList && deltaX >= lastDeltaX) {
  28639. // 右下,左下
  28640. deltaX = lastDeltaX - 10;
  28641. }
  28642. if (!isDownList && deltaX <= lastDeltaX) {
  28643. // 右上,左上
  28644. deltaX = lastDeltaX + 10;
  28645. }
  28646. list[i].x = cx + deltaX * dir;
  28647. lastDeltaX = deltaX;
  28648. }
  28649. }
  28650. var lastY = 0;
  28651. var delta;
  28652. var len = list.length;
  28653. var upList = [];
  28654. var downList = [];
  28655. for (var i = 0; i < len; i++) {
  28656. delta = list[i].y - lastY;
  28657. if (delta < 0) {
  28658. shiftDown(i, len, -delta, dir);
  28659. }
  28660. lastY = list[i].y + list[i].height;
  28661. }
  28662. if (viewHeight - lastY < 0) {
  28663. shiftUp(len - 1, lastY - viewHeight);
  28664. }
  28665. for (var i = 0; i < len; i++) {
  28666. if (list[i].y >= cy) {
  28667. downList.push(list[i]);
  28668. }
  28669. else {
  28670. upList.push(list[i]);
  28671. }
  28672. }
  28673. changeX(upList, false, cx, cy, r, dir);
  28674. changeX(downList, true, cx, cy, r, dir);
  28675. }
  28676. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  28677. var leftList = [];
  28678. var rightList = [];
  28679. for (var i = 0; i < labelLayoutList.length; i++) {
  28680. if (labelLayoutList[i].x < cx) {
  28681. leftList.push(labelLayoutList[i]);
  28682. }
  28683. else {
  28684. rightList.push(labelLayoutList[i]);
  28685. }
  28686. }
  28687. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  28688. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  28689. for (var i = 0; i < labelLayoutList.length; i++) {
  28690. var linePoints = labelLayoutList[i].linePoints;
  28691. if (linePoints) {
  28692. var dist = linePoints[1][0] - linePoints[2][0];
  28693. if (labelLayoutList[i].x < cx) {
  28694. linePoints[2][0] = labelLayoutList[i].x + 3;
  28695. }
  28696. else {
  28697. linePoints[2][0] = labelLayoutList[i].x - 3;
  28698. }
  28699. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  28700. linePoints[1][0] = linePoints[2][0] + dist;
  28701. }
  28702. }
  28703. }
  28704. var labelLayout = function (seriesModel, r, viewWidth, viewHeight) {
  28705. var data = seriesModel.getData();
  28706. var labelLayoutList = [];
  28707. var cx;
  28708. var cy;
  28709. var hasLabelRotate = false;
  28710. data.each(function (idx) {
  28711. var layout = data.getItemLayout(idx);
  28712. var itemModel = data.getItemModel(idx);
  28713. var labelModel = itemModel.getModel('label.normal');
  28714. // Use position in normal or emphasis
  28715. var labelPosition = labelModel.get('position') || itemModel.get('label.emphasis.position');
  28716. var labelLineModel = itemModel.getModel('labelLine.normal');
  28717. var labelLineLen = labelLineModel.get('length');
  28718. var labelLineLen2 = labelLineModel.get('length2');
  28719. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  28720. var dx = Math.cos(midAngle);
  28721. var dy = Math.sin(midAngle);
  28722. var textX;
  28723. var textY;
  28724. var linePoints;
  28725. var textAlign;
  28726. cx = layout.cx;
  28727. cy = layout.cy;
  28728. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  28729. if (labelPosition === 'center') {
  28730. textX = layout.cx;
  28731. textY = layout.cy;
  28732. textAlign = 'center';
  28733. }
  28734. else {
  28735. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  28736. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  28737. textX = x1 + dx * 3;
  28738. textY = y1 + dy * 3;
  28739. if (!isLabelInside) {
  28740. // For roseType
  28741. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  28742. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  28743. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  28744. var y3 = y2;
  28745. textX = x3 + (dx < 0 ? -5 : 5);
  28746. textY = y3;
  28747. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  28748. }
  28749. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  28750. }
  28751. var font = labelModel.getFont();
  28752. var labelRotate = labelModel.get('rotate')
  28753. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  28754. var text = seriesModel.getFormattedLabel(idx, 'normal')
  28755. || data.getName(idx);
  28756. var textRect = getBoundingRect(
  28757. text, font, textAlign, 'top'
  28758. );
  28759. hasLabelRotate = !!labelRotate;
  28760. layout.label = {
  28761. x: textX,
  28762. y: textY,
  28763. position: labelPosition,
  28764. height: textRect.height,
  28765. len: labelLineLen,
  28766. len2: labelLineLen2,
  28767. linePoints: linePoints,
  28768. textAlign: textAlign,
  28769. verticalAlign: 'middle',
  28770. rotation: labelRotate,
  28771. inside: isLabelInside
  28772. };
  28773. // Not layout the inside label
  28774. if (!isLabelInside) {
  28775. labelLayoutList.push(layout.label);
  28776. }
  28777. });
  28778. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  28779. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  28780. }
  28781. };
  28782. var PI2$4 = Math.PI * 2;
  28783. var RADIAN = Math.PI / 180;
  28784. var pieLayout = function (seriesType, ecModel, api, payload) {
  28785. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  28786. var center = seriesModel.get('center');
  28787. var radius = seriesModel.get('radius');
  28788. if (!isArray(radius)) {
  28789. radius = [0, radius];
  28790. }
  28791. if (!isArray(center)) {
  28792. center = [center, center];
  28793. }
  28794. var width = api.getWidth();
  28795. var height = api.getHeight();
  28796. var size = Math.min(width, height);
  28797. var cx = parsePercent$1(center[0], width);
  28798. var cy = parsePercent$1(center[1], height);
  28799. var r0 = parsePercent$1(radius[0], size / 2);
  28800. var r = parsePercent$1(radius[1], size / 2);
  28801. var data = seriesModel.getData();
  28802. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  28803. var minAngle = seriesModel.get('minAngle') * RADIAN;
  28804. var validDataCount = 0;
  28805. data.each('value', function (value) {
  28806. !isNaN(value) && validDataCount++;
  28807. });
  28808. var sum = data.getSum('value');
  28809. // Sum may be 0
  28810. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  28811. var clockwise = seriesModel.get('clockwise');
  28812. var roseType = seriesModel.get('roseType');
  28813. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  28814. // [0...max]
  28815. var extent = data.getDataExtent('value');
  28816. extent[0] = 0;
  28817. // In the case some sector angle is smaller than minAngle
  28818. var restAngle = PI2$4;
  28819. var valueSumLargerThanMinAngle = 0;
  28820. var currentAngle = startAngle;
  28821. var dir = clockwise ? 1 : -1;
  28822. data.each('value', function (value, idx) {
  28823. var angle;
  28824. if (isNaN(value)) {
  28825. data.setItemLayout(idx, {
  28826. angle: NaN,
  28827. startAngle: NaN,
  28828. endAngle: NaN,
  28829. clockwise: clockwise,
  28830. cx: cx,
  28831. cy: cy,
  28832. r0: r0,
  28833. r: roseType
  28834. ? NaN
  28835. : r
  28836. });
  28837. return;
  28838. }
  28839. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  28840. if (roseType !== 'area') {
  28841. angle = (sum === 0 && stillShowZeroSum)
  28842. ? unitRadian : (value * unitRadian);
  28843. }
  28844. else {
  28845. angle = PI2$4 / validDataCount;
  28846. }
  28847. if (angle < minAngle) {
  28848. angle = minAngle;
  28849. restAngle -= minAngle;
  28850. }
  28851. else {
  28852. valueSumLargerThanMinAngle += value;
  28853. }
  28854. var endAngle = currentAngle + dir * angle;
  28855. data.setItemLayout(idx, {
  28856. angle: angle,
  28857. startAngle: currentAngle,
  28858. endAngle: endAngle,
  28859. clockwise: clockwise,
  28860. cx: cx,
  28861. cy: cy,
  28862. r0: r0,
  28863. r: roseType
  28864. ? linearMap(value, extent, [r0, r])
  28865. : r
  28866. });
  28867. currentAngle = endAngle;
  28868. }, true);
  28869. // Some sector is constrained by minAngle
  28870. // Rest sectors needs recalculate angle
  28871. if (restAngle < PI2$4 && validDataCount) {
  28872. // Average the angle if rest angle is not enough after all angles is
  28873. // Constrained by minAngle
  28874. if (restAngle <= 1e-3) {
  28875. var angle = PI2$4 / validDataCount;
  28876. data.each('value', function (value, idx) {
  28877. if (!isNaN(value)) {
  28878. var layout = data.getItemLayout(idx);
  28879. layout.angle = angle;
  28880. layout.startAngle = startAngle + dir * idx * angle;
  28881. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  28882. }
  28883. });
  28884. }
  28885. else {
  28886. unitRadian = restAngle / valueSumLargerThanMinAngle;
  28887. currentAngle = startAngle;
  28888. data.each('value', function (value, idx) {
  28889. if (!isNaN(value)) {
  28890. var layout = data.getItemLayout(idx);
  28891. var angle = layout.angle === minAngle
  28892. ? minAngle : value * unitRadian;
  28893. layout.startAngle = currentAngle;
  28894. layout.endAngle = currentAngle + dir * angle;
  28895. currentAngle += dir * angle;
  28896. }
  28897. });
  28898. }
  28899. }
  28900. labelLayout(seriesModel, r, width, height);
  28901. });
  28902. };
  28903. var dataFilter = function (seriesType, ecModel) {
  28904. var legendModels = ecModel.findComponents({
  28905. mainType: 'legend'
  28906. });
  28907. if (!legendModels || !legendModels.length) {
  28908. return;
  28909. }
  28910. ecModel.eachSeriesByType(seriesType, function (series) {
  28911. var data = series.getData();
  28912. data.filterSelf(function (idx) {
  28913. var name = data.getName(idx);
  28914. // If in any legend component the status is not selected.
  28915. for (var i = 0; i < legendModels.length; i++) {
  28916. if (!legendModels[i].isSelected(name)) {
  28917. return false;
  28918. }
  28919. }
  28920. return true;
  28921. }, this);
  28922. }, this);
  28923. };
  28924. createDataSelectAction('pie', [{
  28925. type: 'pieToggleSelect',
  28926. event: 'pieselectchanged',
  28927. method: 'toggleSelected'
  28928. }, {
  28929. type: 'pieSelect',
  28930. event: 'pieselected',
  28931. method: 'select'
  28932. }, {
  28933. type: 'pieUnSelect',
  28934. event: 'pieunselected',
  28935. method: 'unSelect'
  28936. }]);
  28937. registerVisual(curry(dataColor, 'pie'));
  28938. registerLayout(curry(pieLayout, 'pie'));
  28939. registerProcessor(curry(dataFilter, 'pie'));
  28940. SeriesModel.extend({
  28941. type: 'series.scatter',
  28942. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  28943. getInitialData: function (option, ecModel) {
  28944. return createListFromArray(option.data, this, ecModel);
  28945. },
  28946. brushSelector: 'point',
  28947. defaultOption: {
  28948. coordinateSystem: 'cartesian2d',
  28949. zlevel: 0,
  28950. z: 2,
  28951. legendHoverLink: true,
  28952. hoverAnimation: true,
  28953. // Cartesian coordinate system
  28954. // xAxisIndex: 0,
  28955. // yAxisIndex: 0,
  28956. // Polar coordinate system
  28957. // polarIndex: 0,
  28958. // Geo coordinate system
  28959. // geoIndex: 0,
  28960. // symbol: null, // 图形类型
  28961. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  28962. // symbolRotate: null, // 图形旋转控制
  28963. large: false,
  28964. // Available when large is true
  28965. largeThreshold: 2000,
  28966. // cursor: null,
  28967. // label: {
  28968. // normal: {
  28969. // show: false
  28970. // distance: 5,
  28971. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  28972. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  28973. // 'inside'|'left'|'right'|'top'|'bottom'
  28974. // 默认使用全局文本样式,详见TEXTSTYLE
  28975. // }
  28976. // },
  28977. itemStyle: {
  28978. normal: {
  28979. opacity: 0.8
  28980. // color: 各异
  28981. }
  28982. }
  28983. }
  28984. });
  28985. // TODO Batch by color
  28986. var LargeSymbolPath = extendShape({
  28987. shape: {
  28988. points: null,
  28989. sizes: null
  28990. },
  28991. symbolProxy: null,
  28992. buildPath: function (path, shape) {
  28993. var points = shape.points;
  28994. var sizes = shape.sizes;
  28995. var symbolProxy = this.symbolProxy;
  28996. var symbolProxyShape = symbolProxy.shape;
  28997. for (var i = 0; i < points.length; i++) {
  28998. var pt = points[i];
  28999. if (isNaN(pt[0]) || isNaN(pt[1])) {
  29000. continue;
  29001. }
  29002. var size = sizes[i];
  29003. if (size[0] < 4) {
  29004. // Optimize for small symbol
  29005. path.rect(
  29006. pt[0] - size[0] / 2, pt[1] - size[1] / 2,
  29007. size[0], size[1]
  29008. );
  29009. }
  29010. else {
  29011. symbolProxyShape.x = pt[0] - size[0] / 2;
  29012. symbolProxyShape.y = pt[1] - size[1] / 2;
  29013. symbolProxyShape.width = size[0];
  29014. symbolProxyShape.height = size[1];
  29015. symbolProxy.buildPath(path, symbolProxyShape, true);
  29016. }
  29017. }
  29018. },
  29019. findDataIndex: function (x, y) {
  29020. var shape = this.shape;
  29021. var points = shape.points;
  29022. var sizes = shape.sizes;
  29023. // Not consider transform
  29024. // Treat each element as a rect
  29025. // top down traverse
  29026. for (var i = points.length - 1; i >= 0; i--) {
  29027. var pt = points[i];
  29028. var size = sizes[i];
  29029. var x0 = pt[0] - size[0] / 2;
  29030. var y0 = pt[1] - size[1] / 2;
  29031. if (x >= x0 && y >= y0 && x <= x0 + size[0] && y <= y0 + size[1]) {
  29032. // i is dataIndex
  29033. return i;
  29034. }
  29035. }
  29036. return -1;
  29037. }
  29038. });
  29039. function LargeSymbolDraw() {
  29040. this.group = new Group();
  29041. this._symbolEl = new LargeSymbolPath({
  29042. // rectHover: true,
  29043. // cursor: 'default'
  29044. });
  29045. }
  29046. var largeSymbolProto = LargeSymbolDraw.prototype;
  29047. /**
  29048. * Update symbols draw by new data
  29049. * @param {module:echarts/data/List} data
  29050. */
  29051. largeSymbolProto.updateData = function (data) {
  29052. this.group.removeAll();
  29053. var symbolEl = this._symbolEl;
  29054. var seriesModel = data.hostModel;
  29055. symbolEl.setShape({
  29056. points: data.mapArray(data.getItemLayout),
  29057. sizes: data.mapArray(
  29058. function (idx) {
  29059. var size = data.getItemVisual(idx, 'symbolSize');
  29060. if (!(size instanceof Array)) {
  29061. size = [size, size];
  29062. }
  29063. return size;
  29064. }
  29065. )
  29066. });
  29067. // Create symbolProxy to build path for each data
  29068. symbolEl.symbolProxy = createSymbol(
  29069. data.getVisual('symbol'), 0, 0, 0, 0
  29070. );
  29071. // Use symbolProxy setColor method
  29072. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  29073. symbolEl.useStyle(
  29074. seriesModel.getModel('itemStyle.normal').getItemStyle(['color'])
  29075. );
  29076. var visualColor = data.getVisual('color');
  29077. if (visualColor) {
  29078. symbolEl.setColor(visualColor);
  29079. }
  29080. // Enable tooltip
  29081. // PENDING May have performance issue when path is extremely large
  29082. symbolEl.seriesIndex = seriesModel.seriesIndex;
  29083. symbolEl.on('mousemove', function (e) {
  29084. symbolEl.dataIndex = null;
  29085. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  29086. if (dataIndex >= 0) {
  29087. // Provide dataIndex for tooltip
  29088. symbolEl.dataIndex = dataIndex;
  29089. }
  29090. });
  29091. // Add back
  29092. this.group.add(symbolEl);
  29093. };
  29094. largeSymbolProto.updateLayout = function (seriesModel) {
  29095. var data = seriesModel.getData();
  29096. this._symbolEl.setShape({
  29097. points: data.mapArray(data.getItemLayout)
  29098. });
  29099. };
  29100. largeSymbolProto.remove = function () {
  29101. this.group.removeAll();
  29102. };
  29103. extendChartView({
  29104. type: 'scatter',
  29105. init: function () {
  29106. this._normalSymbolDraw = new SymbolDraw();
  29107. this._largeSymbolDraw = new LargeSymbolDraw();
  29108. },
  29109. render: function (seriesModel, ecModel, api) {
  29110. var data = seriesModel.getData();
  29111. var largeSymbolDraw = this._largeSymbolDraw;
  29112. var normalSymbolDraw = this._normalSymbolDraw;
  29113. var group = this.group;
  29114. var symbolDraw = seriesModel.get('large') && data.count() > seriesModel.get('largeThreshold')
  29115. ? largeSymbolDraw : normalSymbolDraw;
  29116. this._symbolDraw = symbolDraw;
  29117. symbolDraw.updateData(data);
  29118. group.add(symbolDraw.group);
  29119. group.remove(
  29120. symbolDraw === largeSymbolDraw
  29121. ? normalSymbolDraw.group : largeSymbolDraw.group
  29122. );
  29123. },
  29124. updateLayout: function (seriesModel) {
  29125. this._symbolDraw.updateLayout(seriesModel);
  29126. },
  29127. remove: function (ecModel, api) {
  29128. this._symbolDraw && this._symbolDraw.remove(api, true);
  29129. },
  29130. dispose: function () {}
  29131. });
  29132. // In case developer forget to include grid component
  29133. registerVisual(curry(visualSymbol, 'scatter', 'circle', null));
  29134. registerLayout(curry(layoutPoints, 'scatter'));
  29135. // -------------
  29136. // Preprocessor
  29137. // -------------
  29138. registerPreprocessor(function (option) {
  29139. var graphicOption = option.graphic;
  29140. // Convert
  29141. // {graphic: [{left: 10, type: 'circle'}, ...]}
  29142. // or
  29143. // {graphic: {left: 10, type: 'circle'}}
  29144. // to
  29145. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  29146. if (isArray(graphicOption)) {
  29147. if (!graphicOption[0] || !graphicOption[0].elements) {
  29148. option.graphic = [{elements: graphicOption}];
  29149. }
  29150. else {
  29151. // Only one graphic instance can be instantiated. (We dont
  29152. // want that too many views are created in echarts._viewMap)
  29153. option.graphic = [option.graphic[0]];
  29154. }
  29155. }
  29156. else if (graphicOption && !graphicOption.elements) {
  29157. option.graphic = [{elements: [graphicOption]}];
  29158. }
  29159. });
  29160. // ------
  29161. // Model
  29162. // ------
  29163. var GraphicModel = extendComponentModel({
  29164. type: 'graphic',
  29165. defaultOption: {
  29166. // Extra properties for each elements:
  29167. //
  29168. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  29169. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  29170. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  29171. // This mechanism is useful when you want to position a group/element
  29172. // against the right side or the center of this container.
  29173. //
  29174. // width/height: (can only be pixel value, default 0)
  29175. // Only be used to specify contianer(group) size, if needed. And
  29176. // can not be percentage value (like '33%'). See the reason in the
  29177. // layout algorithm below.
  29178. //
  29179. // bounding: (enum: 'all' (default) | 'raw')
  29180. // Specify how to calculate boundingRect when locating.
  29181. // 'all': Get uioned and transformed boundingRect
  29182. // from both itself and its descendants.
  29183. // This mode simplies confining a group of elements in the bounding
  29184. // of their ancester container (e.g., using 'right: 0').
  29185. // 'raw': Only use the boundingRect of itself and before transformed.
  29186. // This mode is similar to css behavior, which is useful when you
  29187. // want an element to be able to overflow its container. (Consider
  29188. // a rotated circle needs to be located in a corner.)
  29189. // Note: elements is always behind its ancestors in this elements array.
  29190. elements: [],
  29191. parentId: null
  29192. },
  29193. /**
  29194. * Save el options for the sake of the performance (only update modified graphics).
  29195. * The order is the same as those in option. (ancesters -> descendants)
  29196. *
  29197. * @private
  29198. * @type {Array.<Object>}
  29199. */
  29200. _elOptionsToUpdate: null,
  29201. /**
  29202. * @override
  29203. */
  29204. mergeOption: function (option) {
  29205. // Prevent default merge to elements
  29206. var elements = this.option.elements;
  29207. this.option.elements = null;
  29208. GraphicModel.superApply(this, 'mergeOption', arguments);
  29209. this.option.elements = elements;
  29210. },
  29211. /**
  29212. * @override
  29213. */
  29214. optionUpdated: function (newOption, isInit) {
  29215. var thisOption = this.option;
  29216. var newList = (isInit ? thisOption : newOption).elements;
  29217. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  29218. var flattenedList = [];
  29219. this._flatten(newList, flattenedList);
  29220. var mappingResult = mappingToExists(existList, flattenedList);
  29221. makeIdAndName(mappingResult);
  29222. // Clear elOptionsToUpdate
  29223. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  29224. each$1(mappingResult, function (resultItem, index) {
  29225. var newElOption = resultItem.option;
  29226. if (__DEV__) {
  29227. assert(
  29228. isObject(newElOption) || resultItem.exist,
  29229. 'Empty graphic option definition'
  29230. );
  29231. }
  29232. if (!newElOption) {
  29233. return;
  29234. }
  29235. elOptionsToUpdate.push(newElOption);
  29236. setKeyInfoToNewElOption(resultItem, newElOption);
  29237. mergeNewElOptionToExist(existList, index, newElOption);
  29238. setLayoutInfoToExist(existList[index], newElOption);
  29239. }, this);
  29240. // Clean
  29241. for (var i = existList.length - 1; i >= 0; i--) {
  29242. if (existList[i] == null) {
  29243. existList.splice(i, 1);
  29244. }
  29245. else {
  29246. // $action should be volatile, otherwise option gotten from
  29247. // `getOption` will contain unexpected $action.
  29248. delete existList[i].$action;
  29249. }
  29250. }
  29251. },
  29252. /**
  29253. * Convert
  29254. * [{
  29255. * type: 'group',
  29256. * id: 'xx',
  29257. * children: [{type: 'circle'}, {type: 'polygon'}]
  29258. * }]
  29259. * to
  29260. * [
  29261. * {type: 'group', id: 'xx'},
  29262. * {type: 'circle', parentId: 'xx'},
  29263. * {type: 'polygon', parentId: 'xx'}
  29264. * ]
  29265. *
  29266. * @private
  29267. * @param {Array.<Object>} optionList option list
  29268. * @param {Array.<Object>} result result of flatten
  29269. * @param {Object} parentOption parent option
  29270. */
  29271. _flatten: function (optionList, result, parentOption) {
  29272. each$1(optionList, function (option) {
  29273. if (!option) {
  29274. return;
  29275. }
  29276. if (parentOption) {
  29277. option.parentOption = parentOption;
  29278. }
  29279. result.push(option);
  29280. var children = option.children;
  29281. if (option.type === 'group' && children) {
  29282. this._flatten(children, result, option);
  29283. }
  29284. // Deleting for JSON output, and for not affecting group creation.
  29285. delete option.children;
  29286. }, this);
  29287. },
  29288. // FIXME
  29289. // Pass to view using payload? setOption has a payload?
  29290. useElOptionsToUpdate: function () {
  29291. var els = this._elOptionsToUpdate;
  29292. // Clear to avoid render duplicately when zooming.
  29293. this._elOptionsToUpdate = null;
  29294. return els;
  29295. }
  29296. });
  29297. // -----
  29298. // View
  29299. // -----
  29300. extendComponentView({
  29301. type: 'graphic',
  29302. /**
  29303. * @override
  29304. */
  29305. init: function (ecModel, api) {
  29306. /**
  29307. * @private
  29308. * @type {module:zrender/core/util.HashMap}
  29309. */
  29310. this._elMap = createHashMap();
  29311. /**
  29312. * @private
  29313. * @type {module:echarts/graphic/GraphicModel}
  29314. */
  29315. this._lastGraphicModel;
  29316. },
  29317. /**
  29318. * @override
  29319. */
  29320. render: function (graphicModel, ecModel, api) {
  29321. // Having leveraged between use cases and algorithm complexity, a very
  29322. // simple layout mechanism is used:
  29323. // The size(width/height) can be determined by itself or its parent (not
  29324. // implemented yet), but can not by its children. (Top-down travel)
  29325. // The location(x/y) can be determined by the bounding rect of itself
  29326. // (can including its descendants or not) and the size of its parent.
  29327. // (Bottom-up travel)
  29328. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  29329. // view will be reused.
  29330. if (graphicModel !== this._lastGraphicModel) {
  29331. this._clear();
  29332. }
  29333. this._lastGraphicModel = graphicModel;
  29334. this._updateElements(graphicModel, api);
  29335. this._relocate(graphicModel, api);
  29336. },
  29337. /**
  29338. * Update graphic elements.
  29339. *
  29340. * @private
  29341. * @param {Object} graphicModel graphic model
  29342. * @param {module:echarts/ExtensionAPI} api extension API
  29343. */
  29344. _updateElements: function (graphicModel, api) {
  29345. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  29346. if (!elOptionsToUpdate) {
  29347. return;
  29348. }
  29349. var elMap = this._elMap;
  29350. var rootGroup = this.group;
  29351. // Top-down tranverse to assign graphic settings to each elements.
  29352. each$1(elOptionsToUpdate, function (elOption) {
  29353. var $action = elOption.$action;
  29354. var id = elOption.id;
  29355. var existEl = elMap.get(id);
  29356. var parentId = elOption.parentId;
  29357. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  29358. if (elOption.type === 'text') {
  29359. var elOptionStyle = elOption.style;
  29360. // In top/bottom mode, textVerticalAlign should not be used, which cause
  29361. // inaccurately locating.
  29362. if (elOption.hv && elOption.hv[1]) {
  29363. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = null;
  29364. }
  29365. // Compatible with previous setting: both support fill and textFill,
  29366. // stroke and textStroke.
  29367. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (
  29368. elOptionStyle.textFill = elOptionStyle.fill
  29369. );
  29370. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (
  29371. elOptionStyle.textStroke = elOptionStyle.stroke
  29372. );
  29373. }
  29374. // Remove unnecessary props to avoid potential problems.
  29375. var elOptionCleaned = getCleanedElOption(elOption);
  29376. // For simple, do not support parent change, otherwise reorder is needed.
  29377. if (__DEV__) {
  29378. existEl && assert(
  29379. targetElParent === existEl.parent,
  29380. 'Changing parent is not supported.'
  29381. );
  29382. }
  29383. if (!$action || $action === 'merge') {
  29384. existEl
  29385. ? existEl.attr(elOptionCleaned)
  29386. : createEl(id, targetElParent, elOptionCleaned, elMap);
  29387. }
  29388. else if ($action === 'replace') {
  29389. removeEl(existEl, elMap);
  29390. createEl(id, targetElParent, elOptionCleaned, elMap);
  29391. }
  29392. else if ($action === 'remove') {
  29393. removeEl(existEl, elMap);
  29394. }
  29395. var el = elMap.get(id);
  29396. if (el) {
  29397. el.__ecGraphicWidth = elOption.width;
  29398. el.__ecGraphicHeight = elOption.height;
  29399. }
  29400. });
  29401. },
  29402. /**
  29403. * Locate graphic elements.
  29404. *
  29405. * @private
  29406. * @param {Object} graphicModel graphic model
  29407. * @param {module:echarts/ExtensionAPI} api extension API
  29408. */
  29409. _relocate: function (graphicModel, api) {
  29410. var elOptions = graphicModel.option.elements;
  29411. var rootGroup = this.group;
  29412. var elMap = this._elMap;
  29413. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  29414. for (var i = elOptions.length - 1; i >= 0; i--) {
  29415. var elOption = elOptions[i];
  29416. var el = elMap.get(elOption.id);
  29417. if (!el) {
  29418. continue;
  29419. }
  29420. var parentEl = el.parent;
  29421. var containerInfo = parentEl === rootGroup
  29422. ? {
  29423. width: api.getWidth(),
  29424. height: api.getHeight()
  29425. }
  29426. : { // Like 'position:absolut' in css, default 0.
  29427. width: parentEl.__ecGraphicWidth || 0,
  29428. height: parentEl.__ecGraphicHeight || 0
  29429. };
  29430. positionElement(
  29431. el, elOption, containerInfo, null,
  29432. {hv: elOption.hv, boundingMode: elOption.bounding}
  29433. );
  29434. }
  29435. },
  29436. /**
  29437. * Clear all elements.
  29438. *
  29439. * @private
  29440. */
  29441. _clear: function () {
  29442. var elMap = this._elMap;
  29443. elMap.each(function (el) {
  29444. removeEl(el, elMap);
  29445. });
  29446. this._elMap = createHashMap();
  29447. },
  29448. /**
  29449. * @override
  29450. */
  29451. dispose: function () {
  29452. this._clear();
  29453. }
  29454. });
  29455. function createEl(id, targetElParent, elOption, elMap) {
  29456. var graphicType = elOption.type;
  29457. if (__DEV__) {
  29458. assert(graphicType, 'graphic type MUST be set');
  29459. }
  29460. var Clz = graphic[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  29461. if (__DEV__) {
  29462. assert(Clz, 'graphic type can not be found');
  29463. }
  29464. var el = new Clz(elOption);
  29465. targetElParent.add(el);
  29466. elMap.set(id, el);
  29467. el.__ecGraphicId = id;
  29468. }
  29469. function removeEl(existEl, elMap) {
  29470. var existElParent = existEl && existEl.parent;
  29471. if (existElParent) {
  29472. existEl.type === 'group' && existEl.traverse(function (el) {
  29473. removeEl(el, elMap);
  29474. });
  29475. elMap.removeKey(existEl.__ecGraphicId);
  29476. existElParent.remove(existEl);
  29477. }
  29478. }
  29479. // Remove unnecessary props to avoid potential problems.
  29480. function getCleanedElOption(elOption) {
  29481. elOption = extend({}, elOption);
  29482. each$1(
  29483. ['id', 'parentId', '$action', 'hv', 'bounding'].concat(LOCATION_PARAMS),
  29484. function (name) {
  29485. delete elOption[name];
  29486. }
  29487. );
  29488. return elOption;
  29489. }
  29490. function isSetLoc(obj, props) {
  29491. var isSet;
  29492. each$1(props, function (prop) {
  29493. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  29494. });
  29495. return isSet;
  29496. }
  29497. function setKeyInfoToNewElOption(resultItem, newElOption) {
  29498. var existElOption = resultItem.exist;
  29499. // Set id and type after id assigned.
  29500. newElOption.id = resultItem.keyInfo.id;
  29501. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  29502. // Set parent id if not specified
  29503. if (newElOption.parentId == null) {
  29504. var newElParentOption = newElOption.parentOption;
  29505. if (newElParentOption) {
  29506. newElOption.parentId = newElParentOption.id;
  29507. }
  29508. else if (existElOption) {
  29509. newElOption.parentId = existElOption.parentId;
  29510. }
  29511. }
  29512. // Clear
  29513. newElOption.parentOption = null;
  29514. }
  29515. function mergeNewElOptionToExist(existList, index, newElOption) {
  29516. // Update existing options, for `getOption` feature.
  29517. var newElOptCopy = extend({}, newElOption);
  29518. var existElOption = existList[index];
  29519. var $action = newElOption.$action || 'merge';
  29520. if ($action === 'merge') {
  29521. if (existElOption) {
  29522. if (__DEV__) {
  29523. var newType = newElOption.type;
  29524. assert(
  29525. !newType || existElOption.type === newType,
  29526. 'Please set $action: "replace" to change `type`'
  29527. );
  29528. }
  29529. // We can ensure that newElOptCopy and existElOption are not
  29530. // the same object, so `merge` will not change newElOptCopy.
  29531. merge(existElOption, newElOptCopy, true);
  29532. // Rigid body, use ignoreSize.
  29533. mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
  29534. // Will be used in render.
  29535. copyLayoutParams(newElOption, existElOption);
  29536. }
  29537. else {
  29538. existList[index] = newElOptCopy;
  29539. }
  29540. }
  29541. else if ($action === 'replace') {
  29542. existList[index] = newElOptCopy;
  29543. }
  29544. else if ($action === 'remove') {
  29545. // null will be cleaned later.
  29546. existElOption && (existList[index] = null);
  29547. }
  29548. }
  29549. function setLayoutInfoToExist(existItem, newElOption) {
  29550. if (!existItem) {
  29551. return;
  29552. }
  29553. existItem.hv = newElOption.hv = [
  29554. // Rigid body, dont care `width`.
  29555. isSetLoc(newElOption, ['left', 'right']),
  29556. // Rigid body, dont care `height`.
  29557. isSetLoc(newElOption, ['top', 'bottom'])
  29558. ];
  29559. // Give default group size. Otherwise layout error may occur.
  29560. if (existItem.type === 'group') {
  29561. existItem.width == null && (existItem.width = newElOption.width = 0);
  29562. existItem.height == null && (existItem.height = newElOption.height = 0);
  29563. }
  29564. }
  29565. /**
  29566. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  29567. * @param {module:echarts/model/Global} ecModel
  29568. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  29569. */
  29570. var findPointFromSeries = function (finder, ecModel) {
  29571. var point = [];
  29572. var seriesIndex = finder.seriesIndex;
  29573. var seriesModel;
  29574. if (seriesIndex == null || !(
  29575. seriesModel = ecModel.getSeriesByIndex(seriesIndex)
  29576. )) {
  29577. return {point: []};
  29578. }
  29579. var data = seriesModel.getData();
  29580. var dataIndex = queryDataIndex(data, finder);
  29581. if (dataIndex == null || isArray(dataIndex)) {
  29582. return {point: []};
  29583. }
  29584. var el = data.getItemGraphicEl(dataIndex);
  29585. var coordSys = seriesModel.coordinateSystem;
  29586. if (seriesModel.getTooltipPosition) {
  29587. point = seriesModel.getTooltipPosition(dataIndex) || [];
  29588. }
  29589. else if (coordSys && coordSys.dataToPoint) {
  29590. point = coordSys.dataToPoint(
  29591. data.getValues(
  29592. map(coordSys.dimensions, function (dim) {
  29593. return seriesModel.coordDimToDataDim(dim)[0];
  29594. }), dataIndex, true
  29595. )
  29596. ) || [];
  29597. }
  29598. else if (el) {
  29599. // Use graphic bounding rect
  29600. var rect = el.getBoundingRect().clone();
  29601. rect.applyTransform(el.transform);
  29602. point = [
  29603. rect.x + rect.width / 2,
  29604. rect.y + rect.height / 2
  29605. ];
  29606. }
  29607. return {point: point, el: el};
  29608. };
  29609. var each$10 = each$1;
  29610. var curry$2 = curry;
  29611. var get$2 = makeGetter();
  29612. /**
  29613. * Basic logic: check all axis, if they do not demand show/highlight,
  29614. * then hide/downplay them.
  29615. *
  29616. * @param {Object} coordSysAxesInfo
  29617. * @param {Object} payload
  29618. * @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
  29619. * @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
  29620. * trigger axisPointer and tooltip.
  29621. * @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
  29622. * trigger axisPointer and tooltip.
  29623. * @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
  29624. * @param {Object} [payload.dataIndex] finder, restrict target axes.
  29625. * @param {Object} [payload.axesInfo] finder, restrict target axes.
  29626. * [{
  29627. * axisDim: 'x'|'y'|'angle'|...,
  29628. * axisIndex: ...,
  29629. * value: ...
  29630. * }, ...]
  29631. * @param {Function} [payload.dispatchAction]
  29632. * @param {Object} [payload.tooltipOption]
  29633. * @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
  29634. * which can be specified in dispatchAction
  29635. * @param {module:echarts/model/Global} ecModel
  29636. * @param {module:echarts/ExtensionAPI} api
  29637. * @return {Object} content of event obj for echarts.connect.
  29638. */
  29639. var axisTrigger = function (payload, ecModel, api) {
  29640. var currTrigger = payload.currTrigger;
  29641. var point = [payload.x, payload.y];
  29642. var finder = payload;
  29643. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  29644. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  29645. // Pending
  29646. // See #6121. But we are not able to reproduce it yet.
  29647. if (!coordSysAxesInfo) {
  29648. return;
  29649. }
  29650. if (illegalPoint(point)) {
  29651. // Used in the default behavior of `connection`: use the sample seriesIndex
  29652. // and dataIndex. And also used in the tooltipView trigger.
  29653. point = findPointFromSeries({
  29654. seriesIndex: finder.seriesIndex,
  29655. // Do not use dataIndexInside from other ec instance.
  29656. // FIXME: auto detect it?
  29657. dataIndex: finder.dataIndex
  29658. }, ecModel).point;
  29659. }
  29660. var isIllegalPoint = illegalPoint(point);
  29661. // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  29662. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  29663. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  29664. // and dataIndex.
  29665. var inputAxesInfo = finder.axesInfo;
  29666. var axesInfo = coordSysAxesInfo.axesInfo;
  29667. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  29668. var outputFinder = {};
  29669. var showValueMap = {};
  29670. var dataByCoordSys = {list: [], map: {}};
  29671. var updaters = {
  29672. showPointer: curry$2(showPointer, showValueMap),
  29673. showTooltip: curry$2(showTooltip, dataByCoordSys)
  29674. };
  29675. // Process for triggered axes.
  29676. each$10(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  29677. // If a point given, it must be contained by the coordinate system.
  29678. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  29679. each$10(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  29680. var axis = axisInfo.axis;
  29681. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo);
  29682. // If no inputAxesInfo, no axis is restricted.
  29683. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  29684. var val = inputAxisInfo && inputAxisInfo.value;
  29685. if (val == null && !isIllegalPoint) {
  29686. val = axis.pointToData(point);
  29687. }
  29688. val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
  29689. }
  29690. });
  29691. });
  29692. // Process for linked axes.
  29693. var linkTriggers = {};
  29694. each$10(axesInfo, function (tarAxisInfo, tarKey) {
  29695. var linkGroup = tarAxisInfo.linkGroup;
  29696. // If axis has been triggered in the previous stage, it should not be triggered by link.
  29697. if (linkGroup && !showValueMap[tarKey]) {
  29698. each$10(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  29699. var srcValItem = showValueMap[srcKey];
  29700. // If srcValItem exist, source axis is triggered, so link to target axis.
  29701. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  29702. var val = srcValItem.value;
  29703. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(
  29704. val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo)
  29705. )));
  29706. linkTriggers[tarAxisInfo.key] = val;
  29707. }
  29708. });
  29709. }
  29710. });
  29711. each$10(linkTriggers, function (val, tarKey) {
  29712. processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
  29713. });
  29714. updateModelActually(showValueMap, axesInfo, outputFinder);
  29715. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  29716. dispatchHighDownActually(axesInfo, dispatchAction, api);
  29717. return outputFinder;
  29718. };
  29719. function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
  29720. var axis = axisInfo.axis;
  29721. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  29722. return;
  29723. }
  29724. if (!axisInfo.involveSeries) {
  29725. updaters.showPointer(axisInfo, newValue);
  29726. return;
  29727. }
  29728. // Heavy calculation. So put it after axis.containData checking.
  29729. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  29730. var payloadBatch = payloadInfo.payloadBatch;
  29731. var snapToValue = payloadInfo.snapToValue;
  29732. // Fill content of event obj for echarts.connect.
  29733. // By defualt use the first involved series data as a sample to connect.
  29734. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  29735. extend(outputFinder, payloadBatch[0]);
  29736. }
  29737. // If no linkSource input, this process is for collecting link
  29738. // target, where snap should not be accepted.
  29739. if (!dontSnap && axisInfo.snap) {
  29740. if (axis.containData(snapToValue) && snapToValue != null) {
  29741. newValue = snapToValue;
  29742. }
  29743. }
  29744. updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder);
  29745. // Tooltip should always be snapToValue, otherwise there will be
  29746. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  29747. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  29748. }
  29749. function buildPayloadsBySeries(value, axisInfo) {
  29750. var axis = axisInfo.axis;
  29751. var dim = axis.dim;
  29752. var snapToValue = value;
  29753. var payloadBatch = [];
  29754. var minDist = Number.MAX_VALUE;
  29755. var minDiff = -1;
  29756. each$10(axisInfo.seriesModels, function (series, idx) {
  29757. var dataDim = series.coordDimToDataDim(dim);
  29758. var seriesNestestValue;
  29759. var dataIndices;
  29760. if (series.getAxisTooltipData) {
  29761. var result = series.getAxisTooltipData(dataDim, value, axis);
  29762. dataIndices = result.dataIndices;
  29763. seriesNestestValue = result.nestestValue;
  29764. }
  29765. else {
  29766. dataIndices = series.getData().indicesOfNearest(
  29767. dataDim[0],
  29768. value,
  29769. // Add a threshold to avoid find the wrong dataIndex
  29770. // when data length is not same.
  29771. false, axis.type === 'category' ? 0.5 : null
  29772. );
  29773. if (!dataIndices.length) {
  29774. return;
  29775. }
  29776. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  29777. }
  29778. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  29779. return;
  29780. }
  29781. var diff = value - seriesNestestValue;
  29782. var dist = Math.abs(diff);
  29783. // Consider category case
  29784. if (dist <= minDist) {
  29785. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  29786. minDist = dist;
  29787. minDiff = diff;
  29788. snapToValue = seriesNestestValue;
  29789. payloadBatch.length = 0;
  29790. }
  29791. each$10(dataIndices, function (dataIndex) {
  29792. payloadBatch.push({
  29793. seriesIndex: series.seriesIndex,
  29794. dataIndexInside: dataIndex,
  29795. dataIndex: series.getData().getRawIndex(dataIndex)
  29796. });
  29797. });
  29798. }
  29799. });
  29800. return {
  29801. payloadBatch: payloadBatch,
  29802. snapToValue: snapToValue
  29803. };
  29804. }
  29805. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  29806. showValueMap[axisInfo.key] = {value: value, payloadBatch: payloadBatch};
  29807. }
  29808. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  29809. var payloadBatch = payloadInfo.payloadBatch;
  29810. var axis = axisInfo.axis;
  29811. var axisModel = axis.model;
  29812. var axisPointerModel = axisInfo.axisPointerModel;
  29813. // If no data, do not create anything in dataByCoordSys,
  29814. // whose length will be used to judge whether dispatch action.
  29815. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  29816. return;
  29817. }
  29818. var coordSysModel = axisInfo.coordSys.model;
  29819. var coordSysKey = makeKey(coordSysModel);
  29820. var coordSysItem = dataByCoordSys.map[coordSysKey];
  29821. if (!coordSysItem) {
  29822. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  29823. coordSysId: coordSysModel.id,
  29824. coordSysIndex: coordSysModel.componentIndex,
  29825. coordSysType: coordSysModel.type,
  29826. coordSysMainType: coordSysModel.mainType,
  29827. dataByAxis: []
  29828. };
  29829. dataByCoordSys.list.push(coordSysItem);
  29830. }
  29831. coordSysItem.dataByAxis.push({
  29832. axisDim: axis.dim,
  29833. axisIndex: axisModel.componentIndex,
  29834. axisType: axisModel.type,
  29835. axisId: axisModel.id,
  29836. value: value,
  29837. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  29838. // depends that all models have been updated. So it should not be performed
  29839. // here. Considering axisPointerModel used here is volatile, which is hard
  29840. // to be retrieve in TooltipView, we prepare parameters here.
  29841. valueLabelOpt: {
  29842. precision: axisPointerModel.get('label.precision'),
  29843. formatter: axisPointerModel.get('label.formatter')
  29844. },
  29845. seriesDataIndices: payloadBatch.slice()
  29846. });
  29847. }
  29848. function updateModelActually(showValueMap, axesInfo, outputFinder) {
  29849. var outputAxesInfo = outputFinder.axesInfo = [];
  29850. // Basic logic: If no 'show' required, 'hide' this axisPointer.
  29851. each$10(axesInfo, function (axisInfo, key) {
  29852. var option = axisInfo.axisPointerModel.option;
  29853. var valItem = showValueMap[key];
  29854. if (valItem) {
  29855. !axisInfo.useHandle && (option.status = 'show');
  29856. option.value = valItem.value;
  29857. // For label formatter param and highlight.
  29858. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  29859. }
  29860. // When always show (e.g., handle used), remain
  29861. // original value and status.
  29862. else {
  29863. // If hide, value still need to be set, consider
  29864. // click legend to toggle axis blank.
  29865. !axisInfo.useHandle && (option.status = 'hide');
  29866. }
  29867. // If status is 'hide', should be no info in payload.
  29868. option.status === 'show' && outputAxesInfo.push({
  29869. axisDim: axisInfo.axis.dim,
  29870. axisIndex: axisInfo.axis.model.componentIndex,
  29871. value: option.value
  29872. });
  29873. });
  29874. }
  29875. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  29876. // Basic logic: If no showTip required, hideTip will be dispatched.
  29877. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  29878. dispatchAction({type: 'hideTip'});
  29879. return;
  29880. }
  29881. // In most case only one axis (or event one series is used). It is
  29882. // convinient to fetch payload.seriesIndex and payload.dataIndex
  29883. // dirtectly. So put the first seriesIndex and dataIndex of the first
  29884. // axis on the payload.
  29885. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  29886. dispatchAction({
  29887. type: 'showTip',
  29888. escapeConnect: true,
  29889. x: point[0],
  29890. y: point[1],
  29891. tooltipOption: payload.tooltipOption,
  29892. position: payload.position,
  29893. dataIndexInside: sampleItem.dataIndexInside,
  29894. dataIndex: sampleItem.dataIndex,
  29895. seriesIndex: sampleItem.seriesIndex,
  29896. dataByCoordSys: dataByCoordSys.list
  29897. });
  29898. }
  29899. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  29900. // FIXME
  29901. // highlight status modification shoule be a stage of main process?
  29902. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  29903. var zr = api.getZr();
  29904. var highDownKey = 'axisPointerLastHighlights';
  29905. var lastHighlights = get$2(zr)[highDownKey] || {};
  29906. var newHighlights = get$2(zr)[highDownKey] = {};
  29907. // Update highlight/downplay status according to axisPointer model.
  29908. // Build hash map and remove duplicate incidentally.
  29909. each$10(axesInfo, function (axisInfo, key) {
  29910. var option = axisInfo.axisPointerModel.option;
  29911. option.status === 'show' && each$10(option.seriesDataIndices, function (batchItem) {
  29912. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  29913. newHighlights[key] = batchItem;
  29914. });
  29915. });
  29916. // Diff.
  29917. var toHighlight = [];
  29918. var toDownplay = [];
  29919. each$1(lastHighlights, function (batchItem, key) {
  29920. !newHighlights[key] && toDownplay.push(batchItem);
  29921. });
  29922. each$1(newHighlights, function (batchItem, key) {
  29923. !lastHighlights[key] && toHighlight.push(batchItem);
  29924. });
  29925. toDownplay.length && api.dispatchAction({
  29926. type: 'downplay', escapeConnect: true, batch: toDownplay
  29927. });
  29928. toHighlight.length && api.dispatchAction({
  29929. type: 'highlight', escapeConnect: true, batch: toHighlight
  29930. });
  29931. }
  29932. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  29933. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  29934. var inputAxisInfo = inputAxesInfo[i];
  29935. if (axisInfo.axis.dim === inputAxisInfo.axisDim
  29936. && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex
  29937. ) {
  29938. return inputAxisInfo;
  29939. }
  29940. }
  29941. }
  29942. function makeMapperParam(axisInfo) {
  29943. var axisModel = axisInfo.axis.model;
  29944. var item = {};
  29945. var dim = item.axisDim = axisInfo.axis.dim;
  29946. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  29947. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  29948. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  29949. return item;
  29950. }
  29951. function illegalPoint(point) {
  29952. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  29953. }
  29954. var AxisPointerModel = extendComponentModel({
  29955. type: 'axisPointer',
  29956. coordSysAxesInfo: null,
  29957. defaultOption: {
  29958. // 'auto' means that show when triggered by tooltip or handle.
  29959. show: 'auto',
  29960. // 'click' | 'mousemove' | 'none'
  29961. triggerOn: null, // set default in AxisPonterView.js
  29962. zlevel: 0,
  29963. z: 50,
  29964. type: 'line',
  29965. // axispointer triggered by tootip determine snap automatically,
  29966. // see `modelHelper`.
  29967. snap: false,
  29968. triggerTooltip: true,
  29969. value: null,
  29970. status: null, // Init value depends on whether handle is used.
  29971. // [group0, group1, ...]
  29972. // Each group can be: {
  29973. // mapper: function () {},
  29974. // singleTooltip: 'multiple', // 'multiple' or 'single'
  29975. // xAxisId: ...,
  29976. // yAxisName: ...,
  29977. // angleAxisIndex: ...
  29978. // }
  29979. // mapper: can be ignored.
  29980. // input: {axisInfo, value}
  29981. // output: {axisInfo, value}
  29982. link: [],
  29983. // Do not set 'auto' here, otherwise global animation: false
  29984. // will not effect at this axispointer.
  29985. animation: null,
  29986. animationDurationUpdate: 200,
  29987. lineStyle: {
  29988. color: '#aaa',
  29989. width: 1,
  29990. type: 'solid'
  29991. },
  29992. shadowStyle: {
  29993. color: 'rgba(150,150,150,0.3)'
  29994. },
  29995. label: {
  29996. show: true,
  29997. formatter: null, // string | Function
  29998. precision: 'auto', // Or a number like 0, 1, 2 ...
  29999. margin: 3,
  30000. color: '#fff',
  30001. padding: [5, 7, 5, 7],
  30002. backgroundColor: 'auto', // default: axis line color
  30003. borderColor: null,
  30004. borderWidth: 0,
  30005. shadowBlur: 3,
  30006. shadowColor: '#aaa'
  30007. // Considering applicability, common style should
  30008. // better not have shadowOffset.
  30009. // shadowOffsetX: 0,
  30010. // shadowOffsetY: 2
  30011. },
  30012. handle: {
  30013. show: false,
  30014. 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', // jshint ignore:line
  30015. size: 45,
  30016. // handle margin is from symbol center to axis, which is stable when circular move.
  30017. margin: 50,
  30018. // color: '#1b8bbd'
  30019. // color: '#2f4554'
  30020. color: '#333',
  30021. shadowBlur: 3,
  30022. shadowColor: '#aaa',
  30023. shadowOffsetX: 0,
  30024. shadowOffsetY: 2,
  30025. // For mobile performance
  30026. throttle: 40
  30027. }
  30028. }
  30029. });
  30030. var get$3 = makeGetter();
  30031. var each$11 = each$1;
  30032. /**
  30033. * @param {string} key
  30034. * @param {module:echarts/ExtensionAPI} api
  30035. * @param {Function} handler
  30036. * param: {string} currTrigger
  30037. * param: {Array.<number>} point
  30038. */
  30039. function register(key, api, handler) {
  30040. if (env$1.node) {
  30041. return;
  30042. }
  30043. var zr = api.getZr();
  30044. get$3(zr).records || (get$3(zr).records = {});
  30045. initGlobalListeners(zr, api);
  30046. var record = get$3(zr).records[key] || (get$3(zr).records[key] = {});
  30047. record.handler = handler;
  30048. }
  30049. function initGlobalListeners(zr, api) {
  30050. if (get$3(zr).initialized) {
  30051. return;
  30052. }
  30053. get$3(zr).initialized = true;
  30054. useHandler('click', curry(doEnter, 'click'));
  30055. useHandler('mousemove', curry(doEnter, 'mousemove'));
  30056. // useHandler('mouseout', onLeave);
  30057. useHandler('globalout', onLeave);
  30058. function useHandler(eventType, cb) {
  30059. zr.on(eventType, function (e) {
  30060. var dis = makeDispatchAction(api);
  30061. each$11(get$3(zr).records, function (record) {
  30062. record && cb(record, e, dis.dispatchAction);
  30063. });
  30064. dispatchTooltipFinally(dis.pendings, api);
  30065. });
  30066. }
  30067. }
  30068. function dispatchTooltipFinally(pendings, api) {
  30069. var showLen = pendings.showTip.length;
  30070. var hideLen = pendings.hideTip.length;
  30071. var actuallyPayload;
  30072. if (showLen) {
  30073. actuallyPayload = pendings.showTip[showLen - 1];
  30074. }
  30075. else if (hideLen) {
  30076. actuallyPayload = pendings.hideTip[hideLen - 1];
  30077. }
  30078. if (actuallyPayload) {
  30079. actuallyPayload.dispatchAction = null;
  30080. api.dispatchAction(actuallyPayload);
  30081. }
  30082. }
  30083. function onLeave(record, e, dispatchAction) {
  30084. record.handler('leave', null, dispatchAction);
  30085. }
  30086. function doEnter(currTrigger, record, e, dispatchAction) {
  30087. record.handler(currTrigger, e, dispatchAction);
  30088. }
  30089. function makeDispatchAction(api) {
  30090. var pendings = {
  30091. showTip: [],
  30092. hideTip: []
  30093. };
  30094. // FIXME
  30095. // better approach?
  30096. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  30097. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  30098. // So we have to add "final stage" to merge those dispatched actions.
  30099. var dispatchAction = function (payload) {
  30100. var pendingList = pendings[payload.type];
  30101. if (pendingList) {
  30102. pendingList.push(payload);
  30103. }
  30104. else {
  30105. payload.dispatchAction = dispatchAction;
  30106. api.dispatchAction(payload);
  30107. }
  30108. };
  30109. return {
  30110. dispatchAction: dispatchAction,
  30111. pendings: pendings
  30112. };
  30113. }
  30114. /**
  30115. * @param {string} key
  30116. * @param {module:echarts/ExtensionAPI} api
  30117. */
  30118. function unregister(key, api) {
  30119. if (env$1.node) {
  30120. return;
  30121. }
  30122. var zr = api.getZr();
  30123. var record = (get$3(zr).records || {})[key];
  30124. if (record) {
  30125. get$3(zr).records[key] = null;
  30126. }
  30127. }
  30128. var AxisPointerView = extendComponentView({
  30129. type: 'axisPointer',
  30130. render: function (globalAxisPointerModel, ecModel, api) {
  30131. var globalTooltipModel = ecModel.getComponent('tooltip');
  30132. var triggerOn = globalAxisPointerModel.get('triggerOn')
  30133. || (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click');
  30134. // Register global listener in AxisPointerView to enable
  30135. // AxisPointerView to be independent to Tooltip.
  30136. register(
  30137. 'axisPointer',
  30138. api,
  30139. function (currTrigger, e, dispatchAction) {
  30140. // If 'none', it is not controlled by mouse totally.
  30141. if (triggerOn !== 'none'
  30142. && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)
  30143. ) {
  30144. dispatchAction({
  30145. type: 'updateAxisPointer',
  30146. currTrigger: currTrigger,
  30147. x: e && e.offsetX,
  30148. y: e && e.offsetY
  30149. });
  30150. }
  30151. }
  30152. );
  30153. },
  30154. /**
  30155. * @override
  30156. */
  30157. remove: function (ecModel, api) {
  30158. unregister(api.getZr(), 'axisPointer');
  30159. AxisPointerView.superApply(this._model, 'remove', arguments);
  30160. },
  30161. /**
  30162. * @override
  30163. */
  30164. dispose: function (ecModel, api) {
  30165. unregister('axisPointer', api);
  30166. AxisPointerView.superApply(this._model, 'dispose', arguments);
  30167. }
  30168. });
  30169. var get$4 = makeGetter();
  30170. var clone$3 = clone;
  30171. var bind$1 = bind;
  30172. /**
  30173. * Base axis pointer class in 2D.
  30174. * Implemenents {module:echarts/component/axis/IAxisPointer}.
  30175. */
  30176. function BaseAxisPointer () {
  30177. }
  30178. BaseAxisPointer.prototype = {
  30179. /**
  30180. * @private
  30181. */
  30182. _group: null,
  30183. /**
  30184. * @private
  30185. */
  30186. _lastGraphicKey: null,
  30187. /**
  30188. * @private
  30189. */
  30190. _handle: null,
  30191. /**
  30192. * @private
  30193. */
  30194. _dragging: false,
  30195. /**
  30196. * @private
  30197. */
  30198. _lastValue: null,
  30199. /**
  30200. * @private
  30201. */
  30202. _lastStatus: null,
  30203. /**
  30204. * @private
  30205. */
  30206. _payloadInfo: null,
  30207. /**
  30208. * In px, arbitrary value. Do not set too small,
  30209. * no animation is ok for most cases.
  30210. * @protected
  30211. */
  30212. animationThreshold: 15,
  30213. /**
  30214. * @implement
  30215. */
  30216. render: function (axisModel, axisPointerModel, api, forceRender) {
  30217. var value = axisPointerModel.get('value');
  30218. var status = axisPointerModel.get('status');
  30219. // Bind them to `this`, not in closure, otherwise they will not
  30220. // be replaced when user calling setOption in not merge mode.
  30221. this._axisModel = axisModel;
  30222. this._axisPointerModel = axisPointerModel;
  30223. this._api = api;
  30224. // Optimize: `render` will be called repeatly during mouse move.
  30225. // So it is power consuming if performing `render` each time,
  30226. // especially on mobile device.
  30227. if (!forceRender
  30228. && this._lastValue === value
  30229. && this._lastStatus === status
  30230. ) {
  30231. return;
  30232. }
  30233. this._lastValue = value;
  30234. this._lastStatus = status;
  30235. var group = this._group;
  30236. var handle = this._handle;
  30237. if (!status || status === 'hide') {
  30238. // Do not clear here, for animation better.
  30239. group && group.hide();
  30240. handle && handle.hide();
  30241. return;
  30242. }
  30243. group && group.show();
  30244. handle && handle.show();
  30245. // Otherwise status is 'show'
  30246. var elOption = {};
  30247. this.makeElOption(elOption, value, axisModel, axisPointerModel, api);
  30248. // Enable change axis pointer type.
  30249. var graphicKey = elOption.graphicKey;
  30250. if (graphicKey !== this._lastGraphicKey) {
  30251. this.clear(api);
  30252. }
  30253. this._lastGraphicKey = graphicKey;
  30254. var moveAnimation = this._moveAnimation =
  30255. this.determineAnimation(axisModel, axisPointerModel);
  30256. if (!group) {
  30257. group = this._group = new Group();
  30258. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  30259. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  30260. api.getZr().add(group);
  30261. }
  30262. else {
  30263. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  30264. this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
  30265. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  30266. }
  30267. updateMandatoryProps(group, axisPointerModel, true);
  30268. this._renderHandle(value);
  30269. },
  30270. /**
  30271. * @implement
  30272. */
  30273. remove: function (api) {
  30274. this.clear(api);
  30275. },
  30276. /**
  30277. * @implement
  30278. */
  30279. dispose: function (api) {
  30280. this.clear(api);
  30281. },
  30282. /**
  30283. * @protected
  30284. */
  30285. determineAnimation: function (axisModel, axisPointerModel) {
  30286. var animation = axisPointerModel.get('animation');
  30287. var axis = axisModel.axis;
  30288. var isCategoryAxis = axis.type === 'category';
  30289. var useSnap = axisPointerModel.get('snap');
  30290. // Value axis without snap always do not snap.
  30291. if (!useSnap && !isCategoryAxis) {
  30292. return false;
  30293. }
  30294. if (animation === 'auto' || animation == null) {
  30295. var animationThreshold = this.animationThreshold;
  30296. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  30297. return true;
  30298. }
  30299. // It is important to auto animation when snap used. Consider if there is
  30300. // a dataZoom, animation will be disabled when too many points exist, while
  30301. // it will be enabled for better visual effect when little points exist.
  30302. if (useSnap) {
  30303. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  30304. var axisExtent = axis.getExtent();
  30305. // Approximate band width
  30306. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  30307. }
  30308. return false;
  30309. }
  30310. return animation === true;
  30311. },
  30312. /**
  30313. * add {pointer, label, graphicKey} to elOption
  30314. * @protected
  30315. */
  30316. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  30317. // Shoule be implemenented by sub-class.
  30318. },
  30319. /**
  30320. * @protected
  30321. */
  30322. createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
  30323. var pointerOption = elOption.pointer;
  30324. if (pointerOption) {
  30325. var pointerEl = get$4(group).pointerEl = new graphic[pointerOption.type](
  30326. clone$3(elOption.pointer)
  30327. );
  30328. group.add(pointerEl);
  30329. }
  30330. },
  30331. /**
  30332. * @protected
  30333. */
  30334. createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
  30335. if (elOption.label) {
  30336. var labelEl = get$4(group).labelEl = new Rect(
  30337. clone$3(elOption.label)
  30338. );
  30339. group.add(labelEl);
  30340. updateLabelShowHide(labelEl, axisPointerModel);
  30341. }
  30342. },
  30343. /**
  30344. * @protected
  30345. */
  30346. updatePointerEl: function (group, elOption, updateProps$$1) {
  30347. var pointerEl = get$4(group).pointerEl;
  30348. if (pointerEl) {
  30349. pointerEl.setStyle(elOption.pointer.style);
  30350. updateProps$$1(pointerEl, {shape: elOption.pointer.shape});
  30351. }
  30352. },
  30353. /**
  30354. * @protected
  30355. */
  30356. updateLabelEl: function (group, elOption, updateProps$$1, axisPointerModel) {
  30357. var labelEl = get$4(group).labelEl;
  30358. if (labelEl) {
  30359. labelEl.setStyle(elOption.label.style);
  30360. updateProps$$1(labelEl, {
  30361. // Consider text length change in vertical axis, animation should
  30362. // be used on shape, otherwise the effect will be weird.
  30363. shape: elOption.label.shape,
  30364. position: elOption.label.position
  30365. });
  30366. updateLabelShowHide(labelEl, axisPointerModel);
  30367. }
  30368. },
  30369. /**
  30370. * @private
  30371. */
  30372. _renderHandle: function (value) {
  30373. if (this._dragging || !this.updateHandleTransform) {
  30374. return;
  30375. }
  30376. var axisPointerModel = this._axisPointerModel;
  30377. var zr = this._api.getZr();
  30378. var handle = this._handle;
  30379. var handleModel = axisPointerModel.getModel('handle');
  30380. var status = axisPointerModel.get('status');
  30381. if (!handleModel.get('show') || !status || status === 'hide') {
  30382. handle && zr.remove(handle);
  30383. this._handle = null;
  30384. return;
  30385. }
  30386. var isInit;
  30387. if (!this._handle) {
  30388. isInit = true;
  30389. handle = this._handle = createIcon(
  30390. handleModel.get('icon'),
  30391. {
  30392. cursor: 'move',
  30393. draggable: true,
  30394. onmousemove: function (e) {
  30395. // Fot mobile devicem, prevent screen slider on the button.
  30396. stop(e.event);
  30397. },
  30398. onmousedown: bind$1(this._onHandleDragMove, this, 0, 0),
  30399. drift: bind$1(this._onHandleDragMove, this),
  30400. ondragend: bind$1(this._onHandleDragEnd, this)
  30401. }
  30402. );
  30403. zr.add(handle);
  30404. }
  30405. updateMandatoryProps(handle, axisPointerModel, false);
  30406. // update style
  30407. var includeStyles = [
  30408. 'color', 'borderColor', 'borderWidth', 'opacity',
  30409. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'
  30410. ];
  30411. handle.setStyle(handleModel.getItemStyle(null, includeStyles));
  30412. // update position
  30413. var handleSize = handleModel.get('size');
  30414. if (!isArray(handleSize)) {
  30415. handleSize = [handleSize, handleSize];
  30416. }
  30417. handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
  30418. createOrUpdate(
  30419. this,
  30420. '_doDispatchAxisPointer',
  30421. handleModel.get('throttle') || 0,
  30422. 'fixRate'
  30423. );
  30424. this._moveHandleToValue(value, isInit);
  30425. },
  30426. /**
  30427. * @private
  30428. */
  30429. _moveHandleToValue: function (value, isInit) {
  30430. updateProps$1(
  30431. this._axisPointerModel,
  30432. !isInit && this._moveAnimation,
  30433. this._handle,
  30434. getHandleTransProps(this.getHandleTransform(
  30435. value, this._axisModel, this._axisPointerModel
  30436. ))
  30437. );
  30438. },
  30439. /**
  30440. * @private
  30441. */
  30442. _onHandleDragMove: function (dx, dy) {
  30443. var handle = this._handle;
  30444. if (!handle) {
  30445. return;
  30446. }
  30447. this._dragging = true;
  30448. // Persistent for throttle.
  30449. var trans = this.updateHandleTransform(
  30450. getHandleTransProps(handle),
  30451. [dx, dy],
  30452. this._axisModel,
  30453. this._axisPointerModel
  30454. );
  30455. this._payloadInfo = trans;
  30456. handle.stopAnimation();
  30457. handle.attr(getHandleTransProps(trans));
  30458. get$4(handle).lastProp = null;
  30459. this._doDispatchAxisPointer();
  30460. },
  30461. /**
  30462. * Throttled method.
  30463. * @private
  30464. */
  30465. _doDispatchAxisPointer: function () {
  30466. var handle = this._handle;
  30467. if (!handle) {
  30468. return;
  30469. }
  30470. var payloadInfo = this._payloadInfo;
  30471. var axisModel = this._axisModel;
  30472. this._api.dispatchAction({
  30473. type: 'updateAxisPointer',
  30474. x: payloadInfo.cursorPoint[0],
  30475. y: payloadInfo.cursorPoint[1],
  30476. tooltipOption: payloadInfo.tooltipOption,
  30477. axesInfo: [{
  30478. axisDim: axisModel.axis.dim,
  30479. axisIndex: axisModel.componentIndex
  30480. }]
  30481. });
  30482. },
  30483. /**
  30484. * @private
  30485. */
  30486. _onHandleDragEnd: function (moveAnimation) {
  30487. this._dragging = false;
  30488. var handle = this._handle;
  30489. if (!handle) {
  30490. return;
  30491. }
  30492. var value = this._axisPointerModel.get('value');
  30493. // Consider snap or categroy axis, handle may be not consistent with
  30494. // axisPointer. So move handle to align the exact value position when
  30495. // drag ended.
  30496. this._moveHandleToValue(value);
  30497. // For the effect: tooltip will be shown when finger holding on handle
  30498. // button, and will be hidden after finger left handle button.
  30499. this._api.dispatchAction({
  30500. type: 'hideTip'
  30501. });
  30502. },
  30503. /**
  30504. * Should be implemenented by sub-class if support `handle`.
  30505. * @protected
  30506. * @param {number} value
  30507. * @param {module:echarts/model/Model} axisModel
  30508. * @param {module:echarts/model/Model} axisPointerModel
  30509. * @return {Object} {position: [x, y], rotation: 0}
  30510. */
  30511. getHandleTransform: null,
  30512. /**
  30513. * * Should be implemenented by sub-class if support `handle`.
  30514. * @protected
  30515. * @param {Object} transform {position, rotation}
  30516. * @param {Array.<number>} delta [dx, dy]
  30517. * @param {module:echarts/model/Model} axisModel
  30518. * @param {module:echarts/model/Model} axisPointerModel
  30519. * @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
  30520. */
  30521. updateHandleTransform: null,
  30522. /**
  30523. * @private
  30524. */
  30525. clear: function (api) {
  30526. this._lastValue = null;
  30527. this._lastStatus = null;
  30528. var zr = api.getZr();
  30529. var group = this._group;
  30530. var handle = this._handle;
  30531. if (zr && group) {
  30532. this._lastGraphicKey = null;
  30533. group && zr.remove(group);
  30534. handle && zr.remove(handle);
  30535. this._group = null;
  30536. this._handle = null;
  30537. this._payloadInfo = null;
  30538. }
  30539. },
  30540. /**
  30541. * @protected
  30542. */
  30543. doClear: function () {
  30544. // Implemented by sub-class if necessary.
  30545. },
  30546. /**
  30547. * @protected
  30548. * @param {Array.<number>} xy
  30549. * @param {Array.<number>} wh
  30550. * @param {number} [xDimIndex=0] or 1
  30551. */
  30552. buildLabel: function (xy, wh, xDimIndex) {
  30553. xDimIndex = xDimIndex || 0;
  30554. return {
  30555. x: xy[xDimIndex],
  30556. y: xy[1 - xDimIndex],
  30557. width: wh[xDimIndex],
  30558. height: wh[1 - xDimIndex]
  30559. };
  30560. }
  30561. };
  30562. BaseAxisPointer.prototype.constructor = BaseAxisPointer;
  30563. function updateProps$1(animationModel, moveAnimation, el, props) {
  30564. // Animation optimize.
  30565. if (!propsEqual(get$4(el).lastProp, props)) {
  30566. get$4(el).lastProp = props;
  30567. moveAnimation
  30568. ? updateProps(el, props, animationModel)
  30569. : (el.stopAnimation(), el.attr(props));
  30570. }
  30571. }
  30572. function propsEqual(lastProps, newProps) {
  30573. if (isObject(lastProps) && isObject(newProps)) {
  30574. var equals = true;
  30575. each$1(newProps, function (item, key) {
  30576. equals = equals && propsEqual(lastProps[key], item);
  30577. });
  30578. return !!equals;
  30579. }
  30580. else {
  30581. return lastProps === newProps;
  30582. }
  30583. }
  30584. function updateLabelShowHide(labelEl, axisPointerModel) {
  30585. labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
  30586. }
  30587. function getHandleTransProps(trans) {
  30588. return {
  30589. position: trans.position.slice(),
  30590. rotation: trans.rotation || 0
  30591. };
  30592. }
  30593. function updateMandatoryProps(group, axisPointerModel, silent) {
  30594. var z = axisPointerModel.get('z');
  30595. var zlevel = axisPointerModel.get('zlevel');
  30596. group && group.traverse(function (el) {
  30597. if (el.type !== 'group') {
  30598. z != null && (el.z = z);
  30599. zlevel != null && (el.zlevel = zlevel);
  30600. el.silent = silent;
  30601. }
  30602. });
  30603. }
  30604. enableClassExtend(BaseAxisPointer);
  30605. /**
  30606. * @param {module:echarts/model/Model} axisPointerModel
  30607. */
  30608. function buildElStyle(axisPointerModel) {
  30609. var axisPointerType = axisPointerModel.get('type');
  30610. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  30611. var style;
  30612. if (axisPointerType === 'line') {
  30613. style = styleModel.getLineStyle();
  30614. style.fill = null;
  30615. }
  30616. else if (axisPointerType === 'shadow') {
  30617. style = styleModel.getAreaStyle();
  30618. style.stroke = null;
  30619. }
  30620. return style;
  30621. }
  30622. /**
  30623. * @param {Function} labelPos {align, verticalAlign, position}
  30624. */
  30625. function buildLabelElOption(
  30626. elOption, axisModel, axisPointerModel, api, labelPos
  30627. ) {
  30628. var value = axisPointerModel.get('value');
  30629. var text = getValueLabel(
  30630. value, axisModel.axis, axisModel.ecModel,
  30631. axisPointerModel.get('seriesDataIndices'),
  30632. {
  30633. precision: axisPointerModel.get('label.precision'),
  30634. formatter: axisPointerModel.get('label.formatter')
  30635. }
  30636. );
  30637. var labelModel = axisPointerModel.getModel('label');
  30638. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  30639. var font = labelModel.getFont();
  30640. var textRect = getBoundingRect(text, font);
  30641. var position = labelPos.position;
  30642. var width = textRect.width + paddings[1] + paddings[3];
  30643. var height = textRect.height + paddings[0] + paddings[2];
  30644. // Adjust by align.
  30645. var align = labelPos.align;
  30646. align === 'right' && (position[0] -= width);
  30647. align === 'center' && (position[0] -= width / 2);
  30648. var verticalAlign = labelPos.verticalAlign;
  30649. verticalAlign === 'bottom' && (position[1] -= height);
  30650. verticalAlign === 'middle' && (position[1] -= height / 2);
  30651. // Not overflow ec container
  30652. confineInContainer(position, width, height, api);
  30653. var bgColor = labelModel.get('backgroundColor');
  30654. if (!bgColor || bgColor === 'auto') {
  30655. bgColor = axisModel.get('axisLine.lineStyle.color');
  30656. }
  30657. elOption.label = {
  30658. shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  30659. position: position.slice(),
  30660. // TODO: rich
  30661. style: {
  30662. text: text,
  30663. textFont: font,
  30664. textFill: labelModel.getTextColor(),
  30665. textPosition: 'inside',
  30666. fill: bgColor,
  30667. stroke: labelModel.get('borderColor') || 'transparent',
  30668. lineWidth: labelModel.get('borderWidth') || 0,
  30669. shadowBlur: labelModel.get('shadowBlur'),
  30670. shadowColor: labelModel.get('shadowColor'),
  30671. shadowOffsetX: labelModel.get('shadowOffsetX'),
  30672. shadowOffsetY: labelModel.get('shadowOffsetY')
  30673. },
  30674. // Lable should be over axisPointer.
  30675. z2: 10
  30676. };
  30677. }
  30678. // Do not overflow ec container
  30679. function confineInContainer(position, width, height, api) {
  30680. var viewWidth = api.getWidth();
  30681. var viewHeight = api.getHeight();
  30682. position[0] = Math.min(position[0] + width, viewWidth) - width;
  30683. position[1] = Math.min(position[1] + height, viewHeight) - height;
  30684. position[0] = Math.max(position[0], 0);
  30685. position[1] = Math.max(position[1], 0);
  30686. }
  30687. /**
  30688. * @param {number} value
  30689. * @param {module:echarts/coord/Axis} axis
  30690. * @param {module:echarts/model/Global} ecModel
  30691. * @param {Object} opt
  30692. * @param {Array.<Object>} seriesDataIndices
  30693. * @param {number|string} opt.precision 'auto' or a number
  30694. * @param {string|Function} opt.formatter label formatter
  30695. */
  30696. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  30697. var text = axis.scale.getLabel(
  30698. // If `precision` is set, width can be fixed (like '12.00500'), which
  30699. // helps to debounce when when moving label.
  30700. value, {precision: opt.precision}
  30701. );
  30702. var formatter = opt.formatter;
  30703. if (formatter) {
  30704. var params = {
  30705. value: getAxisRawValue(axis, value),
  30706. seriesData: []
  30707. };
  30708. each$1(seriesDataIndices, function (idxItem) {
  30709. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  30710. var dataIndex = idxItem.dataIndexInside;
  30711. var dataParams = series && series.getDataParams(dataIndex);
  30712. dataParams && params.seriesData.push(dataParams);
  30713. });
  30714. if (isString(formatter)) {
  30715. text = formatter.replace('{value}', text);
  30716. }
  30717. else if (isFunction(formatter)) {
  30718. text = formatter(params);
  30719. }
  30720. }
  30721. return text;
  30722. }
  30723. /**
  30724. * @param {module:echarts/coord/Axis} axis
  30725. * @param {number} value
  30726. * @param {Object} layoutInfo {
  30727. * rotation, position, labelOffset, labelDirection, labelMargin
  30728. * }
  30729. */
  30730. function getTransformedPosition (axis, value, layoutInfo) {
  30731. var transform = create$1();
  30732. rotate(transform, transform, layoutInfo.rotation);
  30733. translate(transform, transform, layoutInfo.position);
  30734. return applyTransform$1([
  30735. axis.dataToCoord(value),
  30736. (layoutInfo.labelOffset || 0)
  30737. + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)
  30738. ], transform);
  30739. }
  30740. function buildCartesianSingleLabelElOption(
  30741. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  30742. ) {
  30743. var textLayout = AxisBuilder.innerTextLayout(
  30744. layoutInfo.rotation, 0, layoutInfo.labelDirection
  30745. );
  30746. layoutInfo.labelMargin = axisPointerModel.get('label.margin');
  30747. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  30748. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  30749. align: textLayout.textAlign,
  30750. verticalAlign: textLayout.textVerticalAlign
  30751. });
  30752. }
  30753. /**
  30754. * @param {Array.<number>} p1
  30755. * @param {Array.<number>} p2
  30756. * @param {number} [xDimIndex=0] or 1
  30757. */
  30758. function makeLineShape(p1, p2, xDimIndex) {
  30759. xDimIndex = xDimIndex || 0;
  30760. return {
  30761. x1: p1[xDimIndex],
  30762. y1: p1[1 - xDimIndex],
  30763. x2: p2[xDimIndex],
  30764. y2: p2[1 - xDimIndex]
  30765. };
  30766. }
  30767. /**
  30768. * @param {Array.<number>} xy
  30769. * @param {Array.<number>} wh
  30770. * @param {number} [xDimIndex=0] or 1
  30771. */
  30772. function makeRectShape(xy, wh, xDimIndex) {
  30773. xDimIndex = xDimIndex || 0;
  30774. return {
  30775. x: xy[xDimIndex],
  30776. y: xy[1 - xDimIndex],
  30777. width: wh[xDimIndex],
  30778. height: wh[1 - xDimIndex]
  30779. };
  30780. }
  30781. var CartesianAxisPointer = BaseAxisPointer.extend({
  30782. /**
  30783. * @override
  30784. */
  30785. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  30786. var axis = axisModel.axis;
  30787. var grid = axis.grid;
  30788. var axisPointerType = axisPointerModel.get('type');
  30789. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  30790. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  30791. if (axisPointerType && axisPointerType !== 'none') {
  30792. var elStyle = buildElStyle(axisPointerModel);
  30793. var pointerOption = pointerShapeBuilder[axisPointerType](
  30794. axis, pixelValue, otherExtent, elStyle
  30795. );
  30796. pointerOption.style = elStyle;
  30797. elOption.graphicKey = pointerOption.type;
  30798. elOption.pointer = pointerOption;
  30799. }
  30800. var layoutInfo = layout(grid.model, axisModel);
  30801. buildCartesianSingleLabelElOption(
  30802. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  30803. );
  30804. },
  30805. /**
  30806. * @override
  30807. */
  30808. getHandleTransform: function (value, axisModel, axisPointerModel) {
  30809. var layoutInfo = layout(axisModel.axis.grid.model, axisModel, {
  30810. labelInside: false
  30811. });
  30812. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  30813. return {
  30814. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  30815. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  30816. };
  30817. },
  30818. /**
  30819. * @override
  30820. */
  30821. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  30822. var axis = axisModel.axis;
  30823. var grid = axis.grid;
  30824. var axisExtent = axis.getGlobalExtent(true);
  30825. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  30826. var dimIndex = axis.dim === 'x' ? 0 : 1;
  30827. var currPosition = transform.position;
  30828. currPosition[dimIndex] += delta[dimIndex];
  30829. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  30830. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  30831. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  30832. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  30833. cursorPoint[dimIndex] = currPosition[dimIndex];
  30834. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  30835. var tooltipOptions = [{verticalAlign: 'middle'}, {align: 'center'}];
  30836. return {
  30837. position: currPosition,
  30838. rotation: transform.rotation,
  30839. cursorPoint: cursorPoint,
  30840. tooltipOption: tooltipOptions[dimIndex]
  30841. };
  30842. }
  30843. });
  30844. function getCartesian(grid, axis) {
  30845. var opt = {};
  30846. opt[axis.dim + 'AxisIndex'] = axis.index;
  30847. return grid.getCartesian(opt);
  30848. }
  30849. var pointerShapeBuilder = {
  30850. line: function (axis, pixelValue, otherExtent, elStyle) {
  30851. var targetShape = makeLineShape(
  30852. [pixelValue, otherExtent[0]],
  30853. [pixelValue, otherExtent[1]],
  30854. getAxisDimIndex(axis)
  30855. );
  30856. subPixelOptimizeLine({
  30857. shape: targetShape,
  30858. style: elStyle
  30859. });
  30860. return {
  30861. type: 'Line',
  30862. shape: targetShape
  30863. };
  30864. },
  30865. shadow: function (axis, pixelValue, otherExtent, elStyle) {
  30866. var bandWidth = axis.getBandWidth();
  30867. var span = otherExtent[1] - otherExtent[0];
  30868. return {
  30869. type: 'Rect',
  30870. shape: makeRectShape(
  30871. [pixelValue - bandWidth / 2, otherExtent[0]],
  30872. [bandWidth, span],
  30873. getAxisDimIndex(axis)
  30874. )
  30875. };
  30876. }
  30877. };
  30878. function getAxisDimIndex(axis) {
  30879. return axis.dim === 'x' ? 0 : 1;
  30880. }
  30881. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  30882. // CartesianAxisPointer is not supposed to be required here. But consider
  30883. // echarts.simple.js and online build tooltip, which only require gridSimple,
  30884. // CartesianAxisPointer should be able to required somewhere.
  30885. registerPreprocessor(function (option) {
  30886. // Always has a global axisPointerModel for default setting.
  30887. if (option) {
  30888. (!option.axisPointer || option.axisPointer.length === 0)
  30889. && (option.axisPointer = {});
  30890. var link = option.axisPointer.link;
  30891. // Normalize to array to avoid object mergin. But if link
  30892. // is not set, remain null/undefined, otherwise it will
  30893. // override existent link setting.
  30894. if (link && !isArray(link)) {
  30895. option.axisPointer.link = [link];
  30896. }
  30897. }
  30898. });
  30899. // This process should proformed after coordinate systems created
  30900. // and series data processed. So put it on statistic processing stage.
  30901. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  30902. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  30903. // allAxesInfo should be updated when setOption performed.
  30904. ecModel.getComponent('axisPointer').coordSysAxesInfo
  30905. = collect(ecModel, api);
  30906. });
  30907. // Broadcast to all views.
  30908. registerAction({
  30909. type: 'updateAxisPointer',
  30910. event: 'updateAxisPointer',
  30911. update: ':updateAxisPointer'
  30912. }, axisTrigger);
  30913. extendComponentModel({
  30914. type: 'tooltip',
  30915. dependencies: ['axisPointer'],
  30916. defaultOption: {
  30917. zlevel: 0,
  30918. z: 8,
  30919. show: true,
  30920. // tooltip主体内容
  30921. showContent: true,
  30922. // 'trigger' only works on coordinate system.
  30923. // 'item' | 'axis' | 'none'
  30924. trigger: 'item',
  30925. // 'click' | 'mousemove' | 'none'
  30926. triggerOn: 'mousemove|click',
  30927. alwaysShowContent: false,
  30928. displayMode: 'single', // 'single' | 'multipleByCoordSys'
  30929. // 位置 {Array} | {Function}
  30930. // position: null
  30931. // Consider triggered from axisPointer handle, verticalAlign should be 'middle'
  30932. // align: null,
  30933. // verticalAlign: null,
  30934. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  30935. confine: false,
  30936. // 内容格式器:{string}(Template) ¦ {Function}
  30937. // formatter: null
  30938. showDelay: 0,
  30939. // 隐藏延迟,单位ms
  30940. hideDelay: 100,
  30941. // 动画变换时间,单位s
  30942. transitionDuration: 0.4,
  30943. enterable: false,
  30944. // 提示背景颜色,默认为透明度为0.7的黑色
  30945. backgroundColor: 'rgba(50,50,50,0.7)',
  30946. // 提示边框颜色
  30947. borderColor: '#333',
  30948. // 提示边框圆角,单位px,默认为4
  30949. borderRadius: 4,
  30950. // 提示边框线宽,单位px,默认为0(无边框)
  30951. borderWidth: 0,
  30952. // 提示内边距,单位px,默认各方向内边距为5,
  30953. // 接受数组分别设定上右下左边距,同css
  30954. padding: 5,
  30955. // Extra css text
  30956. extraCssText: '',
  30957. // 坐标轴指示器,坐标轴触发有效
  30958. axisPointer: {
  30959. // 默认为直线
  30960. // 可选为:'line' | 'shadow' | 'cross'
  30961. type: 'line',
  30962. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  30963. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  30964. // 默认 'auto',会选择类型为 cateogry 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  30965. // 极坐标系会默认选择 angle 轴
  30966. axis: 'auto',
  30967. animation: 'auto',
  30968. animationDurationUpdate: 200,
  30969. animationEasingUpdate: 'exponentialOut',
  30970. crossStyle: {
  30971. color: '#999',
  30972. width: 1,
  30973. type: 'dashed',
  30974. // TODO formatter
  30975. textStyle: {}
  30976. }
  30977. // lineStyle and shadowStyle should not be specified here,
  30978. // otherwise it will always override those styles on option.axisPointer.
  30979. },
  30980. textStyle: {
  30981. color: '#fff',
  30982. fontSize: 14
  30983. }
  30984. }
  30985. });
  30986. var each$13 = each$1;
  30987. var toCamelCase$1 = toCamelCase;
  30988. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  30989. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  30990. /**
  30991. * @param {number} duration
  30992. * @return {string}
  30993. * @inner
  30994. */
  30995. function assembleTransition(duration) {
  30996. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  30997. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  30998. + 'top ' + duration + 's ' + transitionCurve;
  30999. return map(vendors, function (vendorPrefix) {
  31000. return vendorPrefix + 'transition:' + transitionText;
  31001. }).join(';');
  31002. }
  31003. /**
  31004. * @param {Object} textStyle
  31005. * @return {string}
  31006. * @inner
  31007. */
  31008. function assembleFont(textStyleModel) {
  31009. var cssText = [];
  31010. var fontSize = textStyleModel.get('fontSize');
  31011. var color = textStyleModel.getTextColor();
  31012. color && cssText.push('color:' + color);
  31013. cssText.push('font:' + textStyleModel.getFont());
  31014. fontSize &&
  31015. cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  31016. each$13(['decoration', 'align'], function (name) {
  31017. var val = textStyleModel.get(name);
  31018. val && cssText.push('text-' + name + ':' + val);
  31019. });
  31020. return cssText.join(';');
  31021. }
  31022. /**
  31023. * @param {Object} tooltipModel
  31024. * @return {string}
  31025. * @inner
  31026. */
  31027. function assembleCssText(tooltipModel) {
  31028. var cssText = [];
  31029. var transitionDuration = tooltipModel.get('transitionDuration');
  31030. var backgroundColor = tooltipModel.get('backgroundColor');
  31031. var textStyleModel = tooltipModel.getModel('textStyle');
  31032. var padding = tooltipModel.get('padding');
  31033. // Animation transition. Do not animate when transitionDuration is 0.
  31034. transitionDuration &&
  31035. cssText.push(assembleTransition(transitionDuration));
  31036. if (backgroundColor) {
  31037. if (env$1.canvasSupported) {
  31038. cssText.push('background-Color:' + backgroundColor);
  31039. }
  31040. else {
  31041. // for ie
  31042. cssText.push(
  31043. 'background-Color:#' + toHex(backgroundColor)
  31044. );
  31045. cssText.push('filter:alpha(opacity=70)');
  31046. }
  31047. }
  31048. // Border style
  31049. each$13(['width', 'color', 'radius'], function (name) {
  31050. var borderName = 'border-' + name;
  31051. var camelCase = toCamelCase$1(borderName);
  31052. var val = tooltipModel.get(camelCase);
  31053. val != null &&
  31054. cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  31055. });
  31056. // Text style
  31057. cssText.push(assembleFont(textStyleModel));
  31058. // Padding
  31059. if (padding != null) {
  31060. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  31061. }
  31062. return cssText.join(';') + ';';
  31063. }
  31064. /**
  31065. * @alias module:echarts/component/tooltip/TooltipContent
  31066. * @constructor
  31067. */
  31068. function TooltipContent(container, api) {
  31069. var el = document.createElement('div');
  31070. var zr = this._zr = api.getZr();
  31071. this.el = el;
  31072. this._x = api.getWidth() / 2;
  31073. this._y = api.getHeight() / 2;
  31074. container.appendChild(el);
  31075. this._container = container;
  31076. this._show = false;
  31077. /**
  31078. * @private
  31079. */
  31080. this._hideTimeout;
  31081. var self = this;
  31082. el.onmouseenter = function () {
  31083. // clear the timeout in hideLater and keep showing tooltip
  31084. if (self._enterable) {
  31085. clearTimeout(self._hideTimeout);
  31086. self._show = true;
  31087. }
  31088. self._inContent = true;
  31089. };
  31090. el.onmousemove = function (e) {
  31091. e = e || window.event;
  31092. if (!self._enterable) {
  31093. // Try trigger zrender event to avoid mouse
  31094. // in and out shape too frequently
  31095. var handler = zr.handler;
  31096. normalizeEvent(container, e, true);
  31097. handler.dispatch('mousemove', e);
  31098. }
  31099. };
  31100. el.onmouseleave = function () {
  31101. if (self._enterable) {
  31102. if (self._show) {
  31103. self.hideLater(self._hideDelay);
  31104. }
  31105. }
  31106. self._inContent = false;
  31107. };
  31108. }
  31109. TooltipContent.prototype = {
  31110. constructor: TooltipContent,
  31111. /**
  31112. * @private
  31113. * @type {boolean}
  31114. */
  31115. _enterable: true,
  31116. /**
  31117. * Update when tooltip is rendered
  31118. */
  31119. update: function () {
  31120. // FIXME
  31121. // Move this logic to ec main?
  31122. var container = this._container;
  31123. var stl = container.currentStyle
  31124. || document.defaultView.getComputedStyle(container);
  31125. var domStyle = container.style;
  31126. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  31127. domStyle.position = 'relative';
  31128. }
  31129. // Hide the tooltip
  31130. // PENDING
  31131. // this.hide();
  31132. },
  31133. show: function (tooltipModel) {
  31134. clearTimeout(this._hideTimeout);
  31135. var el = this.el;
  31136. el.style.cssText = gCssText + assembleCssText(tooltipModel)
  31137. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  31138. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  31139. + (tooltipModel.get('extraCssText') || '');
  31140. el.style.display = el.innerHTML ? 'block' : 'none';
  31141. this._show = true;
  31142. },
  31143. setContent: function (content) {
  31144. this.el.innerHTML = content == null ? '' : content;
  31145. },
  31146. setEnterable: function (enterable) {
  31147. this._enterable = enterable;
  31148. },
  31149. getSize: function () {
  31150. var el = this.el;
  31151. return [el.clientWidth, el.clientHeight];
  31152. },
  31153. moveTo: function (x, y) {
  31154. // xy should be based on canvas root. But tooltipContent is
  31155. // the sibling of canvas root. So padding of ec container
  31156. // should be considered here.
  31157. var zr = this._zr;
  31158. var viewportRootOffset;
  31159. if (zr && zr.painter && (viewportRootOffset = zr.painter.getViewportRootOffset())) {
  31160. x += viewportRootOffset.offsetLeft;
  31161. y += viewportRootOffset.offsetTop;
  31162. }
  31163. var style = this.el.style;
  31164. style.left = x + 'px';
  31165. style.top = y + 'px';
  31166. this._x = x;
  31167. this._y = y;
  31168. },
  31169. hide: function () {
  31170. this.el.style.display = 'none';
  31171. this._show = false;
  31172. },
  31173. hideLater: function (time) {
  31174. if (this._show && !(this._inContent && this._enterable)) {
  31175. if (time) {
  31176. this._hideDelay = time;
  31177. // Set show false to avoid invoke hideLater mutiple times
  31178. this._show = false;
  31179. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  31180. }
  31181. else {
  31182. this.hide();
  31183. }
  31184. }
  31185. },
  31186. isShow: function () {
  31187. return this._show;
  31188. }
  31189. };
  31190. var bind$2 = bind;
  31191. var each$12 = each$1;
  31192. var parsePercent$2 = parsePercent$1;
  31193. var proxyRect = new Rect({
  31194. shape: {x: -1, y: -1, width: 2, height: 2}
  31195. });
  31196. extendComponentView({
  31197. type: 'tooltip',
  31198. init: function (ecModel, api) {
  31199. if (env$1.node) {
  31200. return;
  31201. }
  31202. var tooltipContent = new TooltipContent(api.getDom(), api);
  31203. this._tooltipContent = tooltipContent;
  31204. },
  31205. render: function (tooltipModel, ecModel, api) {
  31206. if (env$1.node) {
  31207. return;
  31208. }
  31209. // Reset
  31210. this.group.removeAll();
  31211. /**
  31212. * @private
  31213. * @type {module:echarts/component/tooltip/TooltipModel}
  31214. */
  31215. this._tooltipModel = tooltipModel;
  31216. /**
  31217. * @private
  31218. * @type {module:echarts/model/Global}
  31219. */
  31220. this._ecModel = ecModel;
  31221. /**
  31222. * @private
  31223. * @type {module:echarts/ExtensionAPI}
  31224. */
  31225. this._api = api;
  31226. /**
  31227. * Should be cleaned when render.
  31228. * @private
  31229. * @type {Array.<Array.<Object>>}
  31230. */
  31231. this._lastDataByCoordSys = null;
  31232. /**
  31233. * @private
  31234. * @type {boolean}
  31235. */
  31236. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  31237. var tooltipContent = this._tooltipContent;
  31238. tooltipContent.update();
  31239. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  31240. this._initGlobalListener();
  31241. this._keepShow();
  31242. },
  31243. _initGlobalListener: function () {
  31244. var tooltipModel = this._tooltipModel;
  31245. var triggerOn = tooltipModel.get('triggerOn');
  31246. register(
  31247. 'itemTooltip',
  31248. this._api,
  31249. bind$2(function (currTrigger, e, dispatchAction) {
  31250. // If 'none', it is not controlled by mouse totally.
  31251. if (triggerOn !== 'none') {
  31252. if (triggerOn.indexOf(currTrigger) >= 0) {
  31253. this._tryShow(e, dispatchAction);
  31254. }
  31255. else if (currTrigger === 'leave') {
  31256. this._hide(dispatchAction);
  31257. }
  31258. }
  31259. }, this)
  31260. );
  31261. },
  31262. _keepShow: function () {
  31263. var tooltipModel = this._tooltipModel;
  31264. var ecModel = this._ecModel;
  31265. var api = this._api;
  31266. // Try to keep the tooltip show when refreshing
  31267. if (this._lastX != null
  31268. && this._lastY != null
  31269. // When user is willing to control tooltip totally using API,
  31270. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  31271. // which is not expected.
  31272. && tooltipModel.get('triggerOn') !== 'none'
  31273. ) {
  31274. var self = this;
  31275. clearTimeout(this._refreshUpdateTimeout);
  31276. this._refreshUpdateTimeout = setTimeout(function () {
  31277. // Show tip next tick after other charts are rendered
  31278. // In case highlight action has wrong result
  31279. // FIXME
  31280. self.manuallyShowTip(tooltipModel, ecModel, api, {
  31281. x: self._lastX,
  31282. y: self._lastY
  31283. });
  31284. });
  31285. }
  31286. },
  31287. /**
  31288. * Show tip manually by
  31289. * dispatchAction({
  31290. * type: 'showTip',
  31291. * x: 10,
  31292. * y: 10
  31293. * });
  31294. * Or
  31295. * dispatchAction({
  31296. * type: 'showTip',
  31297. * seriesIndex: 0,
  31298. * dataIndex or dataIndexInside or name
  31299. * });
  31300. *
  31301. * TODO Batch
  31302. */
  31303. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  31304. if (payload.from === this.uid || env$1.node) {
  31305. return;
  31306. }
  31307. var dispatchAction = makeDispatchAction$1(payload, api);
  31308. // Reset ticket
  31309. this._ticket = '';
  31310. // When triggered from axisPointer.
  31311. var dataByCoordSys = payload.dataByCoordSys;
  31312. if (payload.tooltip && payload.x != null && payload.y != null) {
  31313. var el = proxyRect;
  31314. el.position = [payload.x, payload.y];
  31315. el.update();
  31316. el.tooltip = payload.tooltip;
  31317. // Manually show tooltip while view is not using zrender elements.
  31318. this._tryShow({
  31319. offsetX: payload.x,
  31320. offsetY: payload.y,
  31321. target: el
  31322. }, dispatchAction);
  31323. }
  31324. else if (dataByCoordSys) {
  31325. this._tryShow({
  31326. offsetX: payload.x,
  31327. offsetY: payload.y,
  31328. position: payload.position,
  31329. event: {},
  31330. dataByCoordSys: payload.dataByCoordSys,
  31331. tooltipOption: payload.tooltipOption
  31332. }, dispatchAction);
  31333. }
  31334. else if (payload.seriesIndex != null) {
  31335. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  31336. return;
  31337. }
  31338. var pointInfo = findPointFromSeries(payload, ecModel);
  31339. var cx = pointInfo.point[0];
  31340. var cy = pointInfo.point[1];
  31341. if (cx != null && cy != null) {
  31342. this._tryShow({
  31343. offsetX: cx,
  31344. offsetY: cy,
  31345. position: payload.position,
  31346. target: pointInfo.el,
  31347. event: {}
  31348. }, dispatchAction);
  31349. }
  31350. }
  31351. else if (payload.x != null && payload.y != null) {
  31352. // FIXME
  31353. // should wrap dispatchAction like `axisPointer/globalListener` ?
  31354. api.dispatchAction({
  31355. type: 'updateAxisPointer',
  31356. x: payload.x,
  31357. y: payload.y
  31358. });
  31359. this._tryShow({
  31360. offsetX: payload.x,
  31361. offsetY: payload.y,
  31362. position: payload.position,
  31363. target: api.getZr().findHover(payload.x, payload.y).target,
  31364. event: {}
  31365. }, dispatchAction);
  31366. }
  31367. },
  31368. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  31369. var tooltipContent = this._tooltipContent;
  31370. if (!this._alwaysShowContent) {
  31371. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  31372. }
  31373. this._lastX = this._lastY = null;
  31374. if (payload.from !== this.uid) {
  31375. this._hide(makeDispatchAction$1(payload, api));
  31376. }
  31377. },
  31378. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  31379. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  31380. // and tooltip.
  31381. _manuallyAxisShowTip: function (tooltipModel, ecModel, api, payload) {
  31382. var seriesIndex = payload.seriesIndex;
  31383. var dataIndex = payload.dataIndex;
  31384. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  31385. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  31386. return;
  31387. }
  31388. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  31389. if (!seriesModel) {
  31390. return;
  31391. }
  31392. var data = seriesModel.getData();
  31393. var tooltipModel = buildTooltipModel([
  31394. data.getItemModel(dataIndex),
  31395. seriesModel,
  31396. (seriesModel.coordinateSystem || {}).model,
  31397. tooltipModel
  31398. ]);
  31399. if (tooltipModel.get('trigger') !== 'axis') {
  31400. return;
  31401. }
  31402. api.dispatchAction({
  31403. type: 'updateAxisPointer',
  31404. seriesIndex: seriesIndex,
  31405. dataIndex: dataIndex,
  31406. position: payload.position
  31407. });
  31408. return true;
  31409. },
  31410. _tryShow: function (e, dispatchAction) {
  31411. var el = e.target;
  31412. var tooltipModel = this._tooltipModel;
  31413. if (!tooltipModel) {
  31414. return;
  31415. }
  31416. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  31417. this._lastX = e.offsetX;
  31418. this._lastY = e.offsetY;
  31419. var dataByCoordSys = e.dataByCoordSys;
  31420. if (dataByCoordSys && dataByCoordSys.length) {
  31421. this._showAxisTooltip(dataByCoordSys, e);
  31422. }
  31423. // Always show item tooltip if mouse is on the element with dataIndex
  31424. else if (el && el.dataIndex != null) {
  31425. this._lastDataByCoordSys = null;
  31426. this._showSeriesItemTooltip(e, el, dispatchAction);
  31427. }
  31428. // Tooltip provided directly. Like legend.
  31429. else if (el && el.tooltip) {
  31430. this._lastDataByCoordSys = null;
  31431. this._showComponentItemTooltip(e, el, dispatchAction);
  31432. }
  31433. else {
  31434. this._lastDataByCoordSys = null;
  31435. this._hide(dispatchAction);
  31436. }
  31437. },
  31438. _showOrMove: function (tooltipModel, cb) {
  31439. // showDelay is used in this case: tooltip.enterable is set
  31440. // as true. User intent to move mouse into tooltip and click
  31441. // something. `showDelay` makes it easyer to enter the content
  31442. // but tooltip do not move immediately.
  31443. var delay = tooltipModel.get('showDelay');
  31444. cb = bind(cb, this);
  31445. clearTimeout(this._showTimout);
  31446. delay > 0
  31447. ? (this._showTimout = setTimeout(cb, delay))
  31448. : cb();
  31449. },
  31450. _showAxisTooltip: function (dataByCoordSys, e) {
  31451. var ecModel = this._ecModel;
  31452. var globalTooltipModel = this._tooltipModel;
  31453. var point = [e.offsetX, e.offsetY];
  31454. var singleDefaultHTML = [];
  31455. var singleParamsList = [];
  31456. var singleTooltipModel = buildTooltipModel([
  31457. e.tooltipOption,
  31458. globalTooltipModel
  31459. ]);
  31460. each$12(dataByCoordSys, function (itemCoordSys) {
  31461. // var coordParamList = [];
  31462. // var coordDefaultHTML = [];
  31463. // var coordTooltipModel = buildTooltipModel([
  31464. // e.tooltipOption,
  31465. // itemCoordSys.tooltipOption,
  31466. // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex),
  31467. // globalTooltipModel
  31468. // ]);
  31469. // var displayMode = coordTooltipModel.get('displayMode');
  31470. // var paramsList = displayMode === 'single' ? singleParamsList : [];
  31471. each$12(itemCoordSys.dataByAxis, function (item) {
  31472. var axisModel = ecModel.getComponent(item.axisDim + 'Axis', item.axisIndex);
  31473. var axisValue = item.value;
  31474. var seriesDefaultHTML = [];
  31475. if (!axisModel || axisValue == null) {
  31476. return;
  31477. }
  31478. var valueLabel = getValueLabel(
  31479. axisValue, axisModel.axis, ecModel,
  31480. item.seriesDataIndices,
  31481. item.valueLabelOpt
  31482. );
  31483. each$1(item.seriesDataIndices, function (idxItem) {
  31484. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  31485. var dataIndex = idxItem.dataIndexInside;
  31486. var dataParams = series && series.getDataParams(dataIndex);
  31487. dataParams.axisDim = item.axisDim;
  31488. dataParams.axisIndex = item.axisIndex;
  31489. dataParams.axisType = item.axisType;
  31490. dataParams.axisId = item.axisId;
  31491. dataParams.axisValue = getAxisRawValue(axisModel.axis, axisValue);
  31492. dataParams.axisValueLabel = valueLabel;
  31493. if (dataParams) {
  31494. singleParamsList.push(dataParams);
  31495. seriesDefaultHTML.push(series.formatTooltip(dataIndex, true));
  31496. }
  31497. });
  31498. // Default tooltip content
  31499. // FIXME
  31500. // (1) shold be the first data which has name?
  31501. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  31502. var firstLine = valueLabel;
  31503. singleDefaultHTML.push(
  31504. (firstLine ? encodeHTML(firstLine) + '<br />' : '')
  31505. + seriesDefaultHTML.join('<br />')
  31506. );
  31507. });
  31508. }, this);
  31509. // In most case, the second axis is shown upper than the first one.
  31510. singleDefaultHTML.reverse();
  31511. singleDefaultHTML = singleDefaultHTML.join('<br /><br />');
  31512. var positionExpr = e.position;
  31513. this._showOrMove(singleTooltipModel, function () {
  31514. if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
  31515. this._updatePosition(
  31516. singleTooltipModel,
  31517. positionExpr,
  31518. point[0], point[1],
  31519. this._tooltipContent,
  31520. singleParamsList
  31521. );
  31522. }
  31523. else {
  31524. this._showTooltipContent(
  31525. singleTooltipModel, singleDefaultHTML, singleParamsList, Math.random(),
  31526. point[0], point[1], positionExpr
  31527. );
  31528. }
  31529. });
  31530. // Do not trigger events here, because this branch only be entered
  31531. // from dispatchAction.
  31532. },
  31533. _showSeriesItemTooltip: function (e, el, dispatchAction) {
  31534. var ecModel = this._ecModel;
  31535. // Use dataModel in element if possible
  31536. // Used when mouseover on a element like markPoint or edge
  31537. // In which case, the data is not main data in series.
  31538. var seriesIndex = el.seriesIndex;
  31539. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  31540. // For example, graph link.
  31541. var dataModel = el.dataModel || seriesModel;
  31542. var dataIndex = el.dataIndex;
  31543. var dataType = el.dataType;
  31544. var data = dataModel.getData();
  31545. var tooltipModel = buildTooltipModel([
  31546. data.getItemModel(dataIndex),
  31547. dataModel,
  31548. seriesModel && (seriesModel.coordinateSystem || {}).model,
  31549. this._tooltipModel
  31550. ]);
  31551. var tooltipTrigger = tooltipModel.get('trigger');
  31552. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  31553. return;
  31554. }
  31555. var params = dataModel.getDataParams(dataIndex, dataType);
  31556. var defaultHtml = dataModel.formatTooltip(dataIndex, false, dataType);
  31557. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  31558. this._showOrMove(tooltipModel, function () {
  31559. this._showTooltipContent(
  31560. tooltipModel, defaultHtml, params, asyncTicket,
  31561. e.offsetX, e.offsetY, e.position, e.target
  31562. );
  31563. });
  31564. // FIXME
  31565. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  31566. dispatchAction({
  31567. type: 'showTip',
  31568. dataIndexInside: dataIndex,
  31569. dataIndex: data.getRawIndex(dataIndex),
  31570. seriesIndex: seriesIndex,
  31571. from: this.uid
  31572. });
  31573. },
  31574. _showComponentItemTooltip: function (e, el, dispatchAction) {
  31575. var tooltipOpt = el.tooltip;
  31576. if (typeof tooltipOpt === 'string') {
  31577. var content = tooltipOpt;
  31578. tooltipOpt = {
  31579. content: content,
  31580. // Fixed formatter
  31581. formatter: content
  31582. };
  31583. }
  31584. var subTooltipModel = new Model(tooltipOpt, this._tooltipModel, this._ecModel);
  31585. var defaultHtml = subTooltipModel.get('content');
  31586. var asyncTicket = Math.random();
  31587. // Do not check whether `trigger` is 'none' here, because `trigger`
  31588. // only works on cooridinate system. In fact, we have not found case
  31589. // that requires setting `trigger` nothing on component yet.
  31590. this._showOrMove(subTooltipModel, function () {
  31591. this._showTooltipContent(
  31592. subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
  31593. asyncTicket, e.offsetX, e.offsetY, e.position, el
  31594. );
  31595. });
  31596. // If not dispatch showTip, tip may be hide triggered by axis.
  31597. dispatchAction({
  31598. type: 'showTip',
  31599. from: this.uid
  31600. });
  31601. },
  31602. _showTooltipContent: function (
  31603. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el
  31604. ) {
  31605. // Reset ticket
  31606. this._ticket = '';
  31607. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  31608. return;
  31609. }
  31610. var tooltipContent = this._tooltipContent;
  31611. var formatter = tooltipModel.get('formatter');
  31612. positionExpr = positionExpr || tooltipModel.get('position');
  31613. var html = defaultHtml;
  31614. if (formatter && typeof formatter === 'string') {
  31615. html = formatTpl(formatter, params, true);
  31616. }
  31617. else if (typeof formatter === 'function') {
  31618. var callback = bind$2(function (cbTicket, html) {
  31619. if (cbTicket === this._ticket) {
  31620. tooltipContent.setContent(html);
  31621. this._updatePosition(
  31622. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  31623. );
  31624. }
  31625. }, this);
  31626. this._ticket = asyncTicket;
  31627. html = formatter(params, asyncTicket, callback);
  31628. }
  31629. tooltipContent.setContent(html);
  31630. tooltipContent.show(tooltipModel);
  31631. this._updatePosition(
  31632. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  31633. );
  31634. },
  31635. /**
  31636. * @param {string|Function|Array.<number>|Object} positionExpr
  31637. * @param {number} x Mouse x
  31638. * @param {number} y Mouse y
  31639. * @param {boolean} confine Whether confine tooltip content in view rect.
  31640. * @param {Object|<Array.<Object>} params
  31641. * @param {module:zrender/Element} el target element
  31642. * @param {module:echarts/ExtensionAPI} api
  31643. * @return {Array.<number>}
  31644. */
  31645. _updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
  31646. var viewWidth = this._api.getWidth();
  31647. var viewHeight = this._api.getHeight();
  31648. positionExpr = positionExpr || tooltipModel.get('position');
  31649. var contentSize = content.getSize();
  31650. var align = tooltipModel.get('align');
  31651. var vAlign = tooltipModel.get('verticalAlign');
  31652. var rect = el && el.getBoundingRect().clone();
  31653. el && rect.applyTransform(el.transform);
  31654. if (typeof positionExpr === 'function') {
  31655. // Callback of position can be an array or a string specify the position
  31656. positionExpr = positionExpr([x, y], params, content.el, rect, {
  31657. viewSize: [viewWidth, viewHeight],
  31658. contentSize: contentSize.slice()
  31659. });
  31660. }
  31661. if (isArray(positionExpr)) {
  31662. x = parsePercent$2(positionExpr[0], viewWidth);
  31663. y = parsePercent$2(positionExpr[1], viewHeight);
  31664. }
  31665. else if (isObject(positionExpr)) {
  31666. positionExpr.width = contentSize[0];
  31667. positionExpr.height = contentSize[1];
  31668. var layoutRect = getLayoutRect(
  31669. positionExpr, {width: viewWidth, height: viewHeight}
  31670. );
  31671. x = layoutRect.x;
  31672. y = layoutRect.y;
  31673. align = null;
  31674. // When positionExpr is left/top/right/bottom,
  31675. // align and verticalAlign will not work.
  31676. vAlign = null;
  31677. }
  31678. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  31679. else if (typeof positionExpr === 'string' && el) {
  31680. var pos = calcTooltipPosition(
  31681. positionExpr, rect, contentSize
  31682. );
  31683. x = pos[0];
  31684. y = pos[1];
  31685. }
  31686. else {
  31687. var pos = refixTooltipPosition(
  31688. x, y, content.el, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20
  31689. );
  31690. x = pos[0];
  31691. y = pos[1];
  31692. }
  31693. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  31694. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  31695. if (tooltipModel.get('confine')) {
  31696. var pos = confineTooltipPosition(
  31697. x, y, content.el, viewWidth, viewHeight
  31698. );
  31699. x = pos[0];
  31700. y = pos[1];
  31701. }
  31702. content.moveTo(x, y);
  31703. },
  31704. // FIXME
  31705. // Should we remove this but leave this to user?
  31706. _updateContentNotChangedOnAxis: function (dataByCoordSys) {
  31707. var lastCoordSys = this._lastDataByCoordSys;
  31708. var contentNotChanged = !!lastCoordSys
  31709. && lastCoordSys.length === dataByCoordSys.length;
  31710. contentNotChanged && each$12(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  31711. var lastDataByAxis = lastItemCoordSys.dataByAxis || {};
  31712. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  31713. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  31714. contentNotChanged &= lastDataByAxis.length === thisDataByAxis.length;
  31715. contentNotChanged && each$12(lastDataByAxis, function (lastItem, indexAxis) {
  31716. var thisItem = thisDataByAxis[indexAxis] || {};
  31717. var lastIndices = lastItem.seriesDataIndices || [];
  31718. var newIndices = thisItem.seriesDataIndices || [];
  31719. contentNotChanged &=
  31720. lastItem.value === thisItem.value
  31721. && lastItem.axisType === thisItem.axisType
  31722. && lastItem.axisId === thisItem.axisId
  31723. && lastIndices.length === newIndices.length;
  31724. contentNotChanged && each$12(lastIndices, function (lastIdxItem, j) {
  31725. var newIdxItem = newIndices[j];
  31726. contentNotChanged &=
  31727. lastIdxItem.seriesIndex === newIdxItem.seriesIndex
  31728. && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  31729. });
  31730. });
  31731. });
  31732. this._lastDataByCoordSys = dataByCoordSys;
  31733. return !!contentNotChanged;
  31734. },
  31735. _hide: function (dispatchAction) {
  31736. // Do not directly hideLater here, because this behavior may be prevented
  31737. // in dispatchAction when showTip is dispatched.
  31738. // FIXME
  31739. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  31740. this._lastDataByCoordSys = null;
  31741. dispatchAction({
  31742. type: 'hideTip',
  31743. from: this.uid
  31744. });
  31745. },
  31746. dispose: function (ecModel, api) {
  31747. if (env$1.node) {
  31748. return;
  31749. }
  31750. this._tooltipContent.hide();
  31751. unregister('itemTooltip', api);
  31752. }
  31753. });
  31754. /**
  31755. * @param {Array.<Object|module:echarts/model/Model>} modelCascade
  31756. * From top to bottom. (the last one should be globalTooltipModel);
  31757. */
  31758. function buildTooltipModel(modelCascade) {
  31759. var resultModel = modelCascade.pop();
  31760. while (modelCascade.length) {
  31761. var tooltipOpt = modelCascade.pop();
  31762. if (tooltipOpt) {
  31763. if (tooltipOpt instanceof Model) {
  31764. tooltipOpt = tooltipOpt.get('tooltip', true);
  31765. }
  31766. // In each data item tooltip can be simply write:
  31767. // {
  31768. // value: 10,
  31769. // tooltip: 'Something you need to know'
  31770. // }
  31771. if (typeof tooltipOpt === 'string') {
  31772. tooltipOpt = {formatter: tooltipOpt};
  31773. }
  31774. resultModel = new Model(tooltipOpt, resultModel, resultModel.ecModel);
  31775. }
  31776. }
  31777. return resultModel;
  31778. }
  31779. function makeDispatchAction$1(payload, api) {
  31780. return payload.dispatchAction || bind(api.dispatchAction, api);
  31781. }
  31782. function refixTooltipPosition(x, y, el, viewWidth, viewHeight, gapH, gapV) {
  31783. var size = getOuterSize(el);
  31784. var width = size.width;
  31785. var height = size.height;
  31786. if (gapH != null) {
  31787. if (x + width + gapH > viewWidth) {
  31788. x -= width + gapH;
  31789. }
  31790. else {
  31791. x += gapH;
  31792. }
  31793. }
  31794. if (gapV != null) {
  31795. if (y + height + gapV > viewHeight) {
  31796. y -= height + gapV;
  31797. }
  31798. else {
  31799. y += gapV;
  31800. }
  31801. }
  31802. return [x, y];
  31803. }
  31804. function confineTooltipPosition(x, y, el, viewWidth, viewHeight) {
  31805. var size = getOuterSize(el);
  31806. var width = size.width;
  31807. var height = size.height;
  31808. x = Math.min(x + width, viewWidth) - width;
  31809. y = Math.min(y + height, viewHeight) - height;
  31810. x = Math.max(x, 0);
  31811. y = Math.max(y, 0);
  31812. return [x, y];
  31813. }
  31814. function getOuterSize(el) {
  31815. var width = el.clientWidth;
  31816. var height = el.clientHeight;
  31817. // Consider browser compatibility.
  31818. // IE8 does not support getComputedStyle.
  31819. if (document.defaultView && document.defaultView.getComputedStyle) {
  31820. var stl = document.defaultView.getComputedStyle(el);
  31821. if (stl) {
  31822. width += parseInt(stl.paddingLeft, 10) + parseInt(stl.paddingRight, 10)
  31823. + parseInt(stl.borderLeftWidth, 10) + parseInt(stl.borderRightWidth, 10);
  31824. height += parseInt(stl.paddingTop, 10) + parseInt(stl.paddingBottom, 10)
  31825. + parseInt(stl.borderTopWidth, 10) + parseInt(stl.borderBottomWidth, 10);
  31826. }
  31827. }
  31828. return {width: width, height: height};
  31829. }
  31830. function calcTooltipPosition(position, rect, contentSize) {
  31831. var domWidth = contentSize[0];
  31832. var domHeight = contentSize[1];
  31833. var gap = 5;
  31834. var x = 0;
  31835. var y = 0;
  31836. var rectWidth = rect.width;
  31837. var rectHeight = rect.height;
  31838. switch (position) {
  31839. case 'inside':
  31840. x = rect.x + rectWidth / 2 - domWidth / 2;
  31841. y = rect.y + rectHeight / 2 - domHeight / 2;
  31842. break;
  31843. case 'top':
  31844. x = rect.x + rectWidth / 2 - domWidth / 2;
  31845. y = rect.y - domHeight - gap;
  31846. break;
  31847. case 'bottom':
  31848. x = rect.x + rectWidth / 2 - domWidth / 2;
  31849. y = rect.y + rectHeight + gap;
  31850. break;
  31851. case 'left':
  31852. x = rect.x - domWidth - gap;
  31853. y = rect.y + rectHeight / 2 - domHeight / 2;
  31854. break;
  31855. case 'right':
  31856. x = rect.x + rectWidth + gap;
  31857. y = rect.y + rectHeight / 2 - domHeight / 2;
  31858. }
  31859. return [x, y];
  31860. }
  31861. function isCenterAlign(align) {
  31862. return align === 'center' || align === 'middle';
  31863. }
  31864. // FIXME Better way to pack data in graphic element
  31865. /**
  31866. * @action
  31867. * @property {string} type
  31868. * @property {number} seriesIndex
  31869. * @property {number} dataIndex
  31870. * @property {number} [x]
  31871. * @property {number} [y]
  31872. */
  31873. registerAction(
  31874. {
  31875. type: 'showTip',
  31876. event: 'showTip',
  31877. update: 'tooltip:manuallyShowTip'
  31878. },
  31879. // noop
  31880. function () {}
  31881. );
  31882. registerAction(
  31883. {
  31884. type: 'hideTip',
  31885. event: 'hideTip',
  31886. update: 'tooltip:manuallyHideTip'
  31887. },
  31888. // noop
  31889. function () {}
  31890. );
  31891. var LegendModel = extendComponentModel({
  31892. type: 'legend.plain',
  31893. dependencies: ['series'],
  31894. layoutMode: {
  31895. type: 'box',
  31896. // legend.width/height are maxWidth/maxHeight actually,
  31897. // whereas realy width/height is calculated by its content.
  31898. // (Setting {left: 10, right: 10} does not make sense).
  31899. // So consider the case:
  31900. // `setOption({legend: {left: 10});`
  31901. // then `setOption({legend: {right: 10});`
  31902. // The previous `left` should be cleared by setting `ignoreSize`.
  31903. ignoreSize: true
  31904. },
  31905. init: function (option, parentModel, ecModel) {
  31906. this.mergeDefaultAndTheme(option, ecModel);
  31907. option.selected = option.selected || {};
  31908. },
  31909. mergeOption: function (option) {
  31910. LegendModel.superCall(this, 'mergeOption', option);
  31911. },
  31912. optionUpdated: function () {
  31913. this._updateData(this.ecModel);
  31914. var legendData = this._data;
  31915. // If selectedMode is single, try to select one
  31916. if (legendData[0] && this.get('selectedMode') === 'single') {
  31917. var hasSelected = false;
  31918. // If has any selected in option.selected
  31919. for (var i = 0; i < legendData.length; i++) {
  31920. var name = legendData[i].get('name');
  31921. if (this.isSelected(name)) {
  31922. // Force to unselect others
  31923. this.select(name);
  31924. hasSelected = true;
  31925. break;
  31926. }
  31927. }
  31928. // Try select the first if selectedMode is single
  31929. !hasSelected && this.select(legendData[0].get('name'));
  31930. }
  31931. },
  31932. _updateData: function (ecModel) {
  31933. var legendData = map(this.get('data') || [], function (dataItem) {
  31934. // Can be string or number
  31935. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  31936. dataItem = {
  31937. name: dataItem
  31938. };
  31939. }
  31940. return new Model(dataItem, this, this.ecModel);
  31941. }, this);
  31942. this._data = legendData;
  31943. var availableNames = map(ecModel.getSeries(), function (series) {
  31944. return series.name;
  31945. });
  31946. ecModel.eachSeries(function (seriesModel) {
  31947. if (seriesModel.legendDataProvider) {
  31948. var data = seriesModel.legendDataProvider();
  31949. availableNames = availableNames.concat(data.mapArray(data.getName));
  31950. }
  31951. });
  31952. /**
  31953. * @type {Array.<string>}
  31954. * @private
  31955. */
  31956. this._availableNames = availableNames;
  31957. },
  31958. /**
  31959. * @return {Array.<module:echarts/model/Model>}
  31960. */
  31961. getData: function () {
  31962. return this._data;
  31963. },
  31964. /**
  31965. * @param {string} name
  31966. */
  31967. select: function (name) {
  31968. var selected = this.option.selected;
  31969. var selectedMode = this.get('selectedMode');
  31970. if (selectedMode === 'single') {
  31971. var data = this._data;
  31972. each$1(data, function (dataItem) {
  31973. selected[dataItem.get('name')] = false;
  31974. });
  31975. }
  31976. selected[name] = true;
  31977. },
  31978. /**
  31979. * @param {string} name
  31980. */
  31981. unSelect: function (name) {
  31982. if (this.get('selectedMode') !== 'single') {
  31983. this.option.selected[name] = false;
  31984. }
  31985. },
  31986. /**
  31987. * @param {string} name
  31988. */
  31989. toggleSelected: function (name) {
  31990. var selected = this.option.selected;
  31991. // Default is true
  31992. if (!selected.hasOwnProperty(name)) {
  31993. selected[name] = true;
  31994. }
  31995. this[selected[name] ? 'unSelect' : 'select'](name);
  31996. },
  31997. /**
  31998. * @param {string} name
  31999. */
  32000. isSelected: function (name) {
  32001. var selected = this.option.selected;
  32002. return !(selected.hasOwnProperty(name) && !selected[name])
  32003. && indexOf(this._availableNames, name) >= 0;
  32004. },
  32005. defaultOption: {
  32006. // 一级层叠
  32007. zlevel: 0,
  32008. // 二级层叠
  32009. z: 4,
  32010. show: true,
  32011. // 布局方式,默认为水平布局,可选为:
  32012. // 'horizontal' | 'vertical'
  32013. orient: 'horizontal',
  32014. left: 'center',
  32015. // right: 'center',
  32016. top: 0,
  32017. // bottom: null,
  32018. // 水平对齐
  32019. // 'auto' | 'left' | 'right'
  32020. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  32021. align: 'auto',
  32022. backgroundColor: 'rgba(0,0,0,0)',
  32023. // 图例边框颜色
  32024. borderColor: '#ccc',
  32025. borderRadius: 0,
  32026. // 图例边框线宽,单位px,默认为0(无边框)
  32027. borderWidth: 0,
  32028. // 图例内边距,单位px,默认各方向内边距为5,
  32029. // 接受数组分别设定上右下左边距,同css
  32030. padding: 5,
  32031. // 各个item之间的间隔,单位px,默认为10,
  32032. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  32033. itemGap: 10,
  32034. // 图例图形宽度
  32035. itemWidth: 25,
  32036. // 图例图形高度
  32037. itemHeight: 14,
  32038. // 图例关闭时候的颜色
  32039. inactiveColor: '#ccc',
  32040. textStyle: {
  32041. // 图例文字颜色
  32042. color: '#333'
  32043. },
  32044. // formatter: '',
  32045. // 选择模式,默认开启图例开关
  32046. selectedMode: true,
  32047. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  32048. // selected: null,
  32049. // 图例内容(详见legend.data,数组中每一项代表一个item
  32050. // data: [],
  32051. // Tooltip 相关配置
  32052. tooltip: {
  32053. show: false
  32054. }
  32055. }
  32056. });
  32057. function legendSelectActionHandler(methodName, payload, ecModel) {
  32058. var selectedMap = {};
  32059. var isToggleSelect = methodName === 'toggleSelected';
  32060. var isSelected;
  32061. // Update all legend components
  32062. ecModel.eachComponent('legend', function (legendModel) {
  32063. if (isToggleSelect && isSelected != null) {
  32064. // Force other legend has same selected status
  32065. // Or the first is toggled to true and other are toggled to false
  32066. // In the case one legend has some item unSelected in option. And if other legend
  32067. // doesn't has the item, they will assume it is selected.
  32068. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  32069. }
  32070. else {
  32071. legendModel[methodName](payload.name);
  32072. isSelected = legendModel.isSelected(payload.name);
  32073. }
  32074. var legendData = legendModel.getData();
  32075. each$1(legendData, function (model) {
  32076. var name = model.get('name');
  32077. // Wrap element
  32078. if (name === '\n' || name === '') {
  32079. return;
  32080. }
  32081. var isItemSelected = legendModel.isSelected(name);
  32082. if (selectedMap.hasOwnProperty(name)) {
  32083. // Unselected if any legend is unselected
  32084. selectedMap[name] = selectedMap[name] && isItemSelected;
  32085. }
  32086. else {
  32087. selectedMap[name] = isItemSelected;
  32088. }
  32089. });
  32090. });
  32091. // Return the event explicitly
  32092. return {
  32093. name: payload.name,
  32094. selected: selectedMap
  32095. };
  32096. }
  32097. /**
  32098. * @event legendToggleSelect
  32099. * @type {Object}
  32100. * @property {string} type 'legendToggleSelect'
  32101. * @property {string} [from]
  32102. * @property {string} name Series name or data item name
  32103. */
  32104. registerAction(
  32105. 'legendToggleSelect', 'legendselectchanged',
  32106. curry(legendSelectActionHandler, 'toggleSelected')
  32107. );
  32108. /**
  32109. * @event legendSelect
  32110. * @type {Object}
  32111. * @property {string} type 'legendSelect'
  32112. * @property {string} name Series name or data item name
  32113. */
  32114. registerAction(
  32115. 'legendSelect', 'legendselected',
  32116. curry(legendSelectActionHandler, 'select')
  32117. );
  32118. /**
  32119. * @event legendUnSelect
  32120. * @type {Object}
  32121. * @property {string} type 'legendUnSelect'
  32122. * @property {string} name Series name or data item name
  32123. */
  32124. registerAction(
  32125. 'legendUnSelect', 'legendunselected',
  32126. curry(legendSelectActionHandler, 'unSelect')
  32127. );
  32128. /**
  32129. * Layout list like component.
  32130. * It will box layout each items in group of component and then position the whole group in the viewport
  32131. * @param {module:zrender/group/Group} group
  32132. * @param {module:echarts/model/Component} componentModel
  32133. * @param {module:echarts/ExtensionAPI}
  32134. */
  32135. function layout$1(group, componentModel, api) {
  32136. var boxLayoutParams = componentModel.getBoxLayoutParams();
  32137. var padding = componentModel.get('padding');
  32138. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  32139. var rect = getLayoutRect(
  32140. boxLayoutParams,
  32141. viewportSize,
  32142. padding
  32143. );
  32144. box(
  32145. componentModel.get('orient'),
  32146. group,
  32147. componentModel.get('itemGap'),
  32148. rect.width,
  32149. rect.height
  32150. );
  32151. positionElement(
  32152. group,
  32153. boxLayoutParams,
  32154. viewportSize,
  32155. padding
  32156. );
  32157. }
  32158. function makeBackground(rect, componentModel) {
  32159. var padding = normalizeCssArray$1(
  32160. componentModel.get('padding')
  32161. );
  32162. var style = componentModel.getItemStyle(['color', 'opacity']);
  32163. style.fill = componentModel.get('backgroundColor');
  32164. var rect = new Rect({
  32165. shape: {
  32166. x: rect.x - padding[3],
  32167. y: rect.y - padding[0],
  32168. width: rect.width + padding[1] + padding[3],
  32169. height: rect.height + padding[0] + padding[2],
  32170. r: componentModel.get('borderRadius')
  32171. },
  32172. style: style,
  32173. silent: true,
  32174. z2: -1
  32175. });
  32176. // FIXME
  32177. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  32178. // and background rect when setting like `left: 0`, `top: 0`.
  32179. // graphic.subPixelOptimizeRect(rect);
  32180. return rect;
  32181. }
  32182. var curry$3 = curry;
  32183. var each$14 = each$1;
  32184. var Group$2 = Group;
  32185. var LegendView = extendComponentView({
  32186. type: 'legend.plain',
  32187. newlineDisabled: false,
  32188. /**
  32189. * @override
  32190. */
  32191. init: function () {
  32192. /**
  32193. * @private
  32194. * @type {module:zrender/container/Group}
  32195. */
  32196. this.group.add(this._contentGroup = new Group$2());
  32197. /**
  32198. * @private
  32199. * @type {module:zrender/Element}
  32200. */
  32201. this._backgroundEl;
  32202. },
  32203. /**
  32204. * @protected
  32205. */
  32206. getContentGroup: function () {
  32207. return this._contentGroup;
  32208. },
  32209. /**
  32210. * @override
  32211. */
  32212. render: function (legendModel, ecModel, api) {
  32213. this.resetInner();
  32214. if (!legendModel.get('show', true)) {
  32215. return;
  32216. }
  32217. var itemAlign = legendModel.get('align');
  32218. if (!itemAlign || itemAlign === 'auto') {
  32219. itemAlign = (
  32220. legendModel.get('left') === 'right'
  32221. && legendModel.get('orient') === 'vertical'
  32222. ) ? 'right' : 'left';
  32223. }
  32224. this.renderInner(itemAlign, legendModel, ecModel, api);
  32225. // Perform layout.
  32226. var positionInfo = legendModel.getBoxLayoutParams();
  32227. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  32228. var padding = legendModel.get('padding');
  32229. var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
  32230. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize);
  32231. // Place mainGroup, based on the calculated `mainRect`.
  32232. var layoutRect = getLayoutRect(
  32233. defaults({width: mainRect.width, height: mainRect.height}, positionInfo),
  32234. viewportSize,
  32235. padding
  32236. );
  32237. this.group.attr('position', [layoutRect.x - mainRect.x, layoutRect.y - mainRect.y]);
  32238. // Render background after group is layout.
  32239. this.group.add(
  32240. this._backgroundEl = makeBackground(mainRect, legendModel)
  32241. );
  32242. },
  32243. /**
  32244. * @protected
  32245. */
  32246. resetInner: function () {
  32247. this.getContentGroup().removeAll();
  32248. this._backgroundEl && this.group.remove(this._backgroundEl);
  32249. },
  32250. /**
  32251. * @protected
  32252. */
  32253. renderInner: function (itemAlign, legendModel, ecModel, api) {
  32254. var contentGroup = this.getContentGroup();
  32255. var legendDrawnMap = createHashMap();
  32256. var selectMode = legendModel.get('selectedMode');
  32257. each$14(legendModel.getData(), function (itemModel, dataIndex) {
  32258. var name = itemModel.get('name');
  32259. // Use empty string or \n as a newline string
  32260. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  32261. contentGroup.add(new Group$2({
  32262. newline: true
  32263. }));
  32264. return;
  32265. }
  32266. var seriesModel = ecModel.getSeriesByName(name)[0];
  32267. if (legendDrawnMap.get(name)) {
  32268. // Have been drawed
  32269. return;
  32270. }
  32271. // Series legend
  32272. if (seriesModel) {
  32273. var data = seriesModel.getData();
  32274. var color = data.getVisual('color');
  32275. // If color is a callback function
  32276. if (typeof color === 'function') {
  32277. // Use the first data
  32278. color = color(seriesModel.getDataParams(0));
  32279. }
  32280. // Using rect symbol defaultly
  32281. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  32282. var symbolType = data.getVisual('symbol');
  32283. var itemGroup = this._createItem(
  32284. name, dataIndex, itemModel, legendModel,
  32285. legendSymbolType, symbolType,
  32286. itemAlign, color,
  32287. selectMode
  32288. );
  32289. itemGroup.on('click', curry$3(dispatchSelectAction, name, api))
  32290. .on('mouseover', curry$3(dispatchHighlightAction, seriesModel, null, api))
  32291. .on('mouseout', curry$3(dispatchDownplayAction, seriesModel, null, api));
  32292. legendDrawnMap.set(name, true);
  32293. }
  32294. else {
  32295. // Data legend of pie, funnel
  32296. ecModel.eachRawSeries(function (seriesModel) {
  32297. // In case multiple series has same data name
  32298. if (legendDrawnMap.get(name)) {
  32299. return;
  32300. }
  32301. if (seriesModel.legendDataProvider) {
  32302. var data = seriesModel.legendDataProvider();
  32303. var idx = data.indexOfName(name);
  32304. if (idx < 0) {
  32305. return;
  32306. }
  32307. var color = data.getItemVisual(idx, 'color');
  32308. var legendSymbolType = 'roundRect';
  32309. var itemGroup = this._createItem(
  32310. name, dataIndex, itemModel, legendModel,
  32311. legendSymbolType, null,
  32312. itemAlign, color,
  32313. selectMode
  32314. );
  32315. itemGroup.on('click', curry$3(dispatchSelectAction, name, api))
  32316. // FIXME Should not specify the series name
  32317. .on('mouseover', curry$3(dispatchHighlightAction, seriesModel, name, api))
  32318. .on('mouseout', curry$3(dispatchDownplayAction, seriesModel, name, api));
  32319. legendDrawnMap.set(name, true);
  32320. }
  32321. }, this);
  32322. }
  32323. if (__DEV__) {
  32324. if (!legendDrawnMap.get(name)) {
  32325. console.warn(name + ' series not exists. Legend data should be same with series name or data name.');
  32326. }
  32327. }
  32328. }, this);
  32329. },
  32330. _createItem: function (
  32331. name, dataIndex, itemModel, legendModel,
  32332. legendSymbolType, symbolType,
  32333. itemAlign, color, selectMode
  32334. ) {
  32335. var itemWidth = legendModel.get('itemWidth');
  32336. var itemHeight = legendModel.get('itemHeight');
  32337. var inactiveColor = legendModel.get('inactiveColor');
  32338. var isSelected = legendModel.isSelected(name);
  32339. var itemGroup = new Group$2();
  32340. var textStyleModel = itemModel.getModel('textStyle');
  32341. var itemIcon = itemModel.get('icon');
  32342. var tooltipModel = itemModel.getModel('tooltip');
  32343. var legendGlobalTooltipModel = tooltipModel.parentModel;
  32344. // Use user given icon first
  32345. legendSymbolType = itemIcon || legendSymbolType;
  32346. itemGroup.add(createSymbol(
  32347. legendSymbolType,
  32348. 0,
  32349. 0,
  32350. itemWidth,
  32351. itemHeight,
  32352. isSelected ? color : inactiveColor,
  32353. true
  32354. ));
  32355. // Compose symbols
  32356. // PENDING
  32357. if (!itemIcon && symbolType
  32358. // At least show one symbol, can't be all none
  32359. && ((symbolType !== legendSymbolType) || symbolType == 'none')
  32360. ) {
  32361. var size = itemHeight * 0.8;
  32362. if (symbolType === 'none') {
  32363. symbolType = 'circle';
  32364. }
  32365. // Put symbol in the center
  32366. itemGroup.add(createSymbol(
  32367. symbolType, (itemWidth - size) / 2, (itemHeight - size) / 2, size, size,
  32368. isSelected ? color : inactiveColor
  32369. ));
  32370. }
  32371. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  32372. var textAlign = itemAlign;
  32373. var formatter = legendModel.get('formatter');
  32374. var content = name;
  32375. if (typeof formatter === 'string' && formatter) {
  32376. content = formatter.replace('{name}', name != null ? name : '');
  32377. }
  32378. else if (typeof formatter === 'function') {
  32379. content = formatter(name);
  32380. }
  32381. itemGroup.add(new Text({
  32382. style: setTextStyle({}, textStyleModel, {
  32383. text: content,
  32384. x: textX,
  32385. y: itemHeight / 2,
  32386. textFill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  32387. textAlign: textAlign,
  32388. textVerticalAlign: 'middle'
  32389. })
  32390. }));
  32391. // Add a invisible rect to increase the area of mouse hover
  32392. var hitRect = new Rect({
  32393. shape: itemGroup.getBoundingRect(),
  32394. invisible: true,
  32395. tooltip: tooltipModel.get('show') ? extend({
  32396. content: name,
  32397. // Defaul formatter
  32398. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  32399. return name;
  32400. },
  32401. formatterParams: {
  32402. componentType: 'legend',
  32403. legendIndex: legendModel.componentIndex,
  32404. name: name,
  32405. $vars: ['name']
  32406. }
  32407. }, tooltipModel.option) : null
  32408. });
  32409. itemGroup.add(hitRect);
  32410. itemGroup.eachChild(function (child) {
  32411. child.silent = true;
  32412. });
  32413. hitRect.silent = !selectMode;
  32414. this.getContentGroup().add(itemGroup);
  32415. setHoverStyle(itemGroup);
  32416. itemGroup.__legendDataIndex = dataIndex;
  32417. return itemGroup;
  32418. },
  32419. /**
  32420. * @protected
  32421. */
  32422. layoutInner: function (legendModel, itemAlign, maxSize) {
  32423. var contentGroup = this.getContentGroup();
  32424. // Place items in contentGroup.
  32425. box(
  32426. legendModel.get('orient'),
  32427. contentGroup,
  32428. legendModel.get('itemGap'),
  32429. maxSize.width,
  32430. maxSize.height
  32431. );
  32432. var contentRect = contentGroup.getBoundingRect();
  32433. contentGroup.attr('position', [-contentRect.x, -contentRect.y]);
  32434. return this.group.getBoundingRect();
  32435. }
  32436. });
  32437. function dispatchSelectAction(name, api) {
  32438. api.dispatchAction({
  32439. type: 'legendToggleSelect',
  32440. name: name
  32441. });
  32442. }
  32443. function dispatchHighlightAction(seriesModel, dataName, api) {
  32444. // If element hover will move to a hoverLayer.
  32445. var el = api.getZr().storage.getDisplayList()[0];
  32446. if (!(el && el.useHoverLayer)) {
  32447. seriesModel.get('legendHoverLink') && api.dispatchAction({
  32448. type: 'highlight',
  32449. seriesName: seriesModel.name,
  32450. name: dataName
  32451. });
  32452. }
  32453. }
  32454. function dispatchDownplayAction(seriesModel, dataName, api) {
  32455. // If element hover will move to a hoverLayer.
  32456. var el = api.getZr().storage.getDisplayList()[0];
  32457. if (!(el && el.useHoverLayer)) {
  32458. seriesModel.get('legendHoverLink') && api.dispatchAction({
  32459. type: 'downplay',
  32460. seriesName: seriesModel.name,
  32461. name: dataName
  32462. });
  32463. }
  32464. }
  32465. var legendFilter = function (ecModel) {
  32466. var legendModels = ecModel.findComponents({
  32467. mainType: 'legend'
  32468. });
  32469. if (legendModels && legendModels.length) {
  32470. ecModel.filterSeries(function (series) {
  32471. // If in any legend component the status is not selected.
  32472. // Because in legend series is assumed selected when it is not in the legend data.
  32473. for (var i = 0; i < legendModels.length; i++) {
  32474. if (!legendModels[i].isSelected(series.name)) {
  32475. return false;
  32476. }
  32477. }
  32478. return true;
  32479. });
  32480. }
  32481. };
  32482. // Do not contain scrollable legend, for sake of file size.
  32483. // Series Filter
  32484. registerProcessor(legendFilter);
  32485. ComponentModel.registerSubTypeDefaulter('legend', function () {
  32486. // Default 'plain' when no type specified.
  32487. return 'plain';
  32488. });
  32489. var ScrollableLegendModel = LegendModel.extend({
  32490. type: 'legend.scroll',
  32491. /**
  32492. * @param {number} scrollDataIndex
  32493. */
  32494. setScrollDataIndex: function (scrollDataIndex) {
  32495. this.option.scrollDataIndex = scrollDataIndex;
  32496. },
  32497. defaultOption: {
  32498. scrollDataIndex: 0,
  32499. pageButtonItemGap: 5,
  32500. pageButtonGap: null,
  32501. pageButtonPosition: 'end', // 'start' or 'end'
  32502. pageFormatter: '{current}/{total}', // If null/undefined, do not show page.
  32503. pageIcons: {
  32504. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  32505. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  32506. },
  32507. pageIconColor: '#2f4554',
  32508. pageIconInactiveColor: '#aaa',
  32509. pageIconSize: 15, // Can be [10, 3], which represents [width, height]
  32510. pageTextStyle: {
  32511. color: '#333'
  32512. },
  32513. animationDurationUpdate: 800
  32514. },
  32515. /**
  32516. * @override
  32517. */
  32518. init: function (option, parentModel, ecModel, extraOpt) {
  32519. var inputPositionParams = getLayoutParams(option);
  32520. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  32521. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  32522. },
  32523. /**
  32524. * @override
  32525. */
  32526. mergeOption: function (option, extraOpt) {
  32527. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  32528. mergeAndNormalizeLayoutParams(this, this.option, option);
  32529. },
  32530. getOrient: function () {
  32531. return this.get('orient') === 'vertical'
  32532. ? {index: 1, name: 'vertical'}
  32533. : {index: 0, name: 'horizontal'};
  32534. }
  32535. });
  32536. // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  32537. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  32538. var orient = legendModel.getOrient();
  32539. var ignoreSize = [1, 1];
  32540. ignoreSize[orient.index] = 0;
  32541. mergeLayoutParam(target, raw, {
  32542. type: 'box', ignoreSize: ignoreSize
  32543. });
  32544. }
  32545. /**
  32546. * Separate legend and scrollable legend to reduce package size.
  32547. */
  32548. var Group$3 = Group;
  32549. var WH = ['width', 'height'];
  32550. var XY = ['x', 'y'];
  32551. var ScrollableLegendView = LegendView.extend({
  32552. type: 'legend.scroll',
  32553. newlineDisabled: true,
  32554. init: function () {
  32555. ScrollableLegendView.superCall(this, 'init');
  32556. /**
  32557. * @private
  32558. * @type {number} For `scroll`.
  32559. */
  32560. this._currentIndex = 0;
  32561. /**
  32562. * @private
  32563. * @type {module:zrender/container/Group}
  32564. */
  32565. this.group.add(this._containerGroup = new Group$3());
  32566. this._containerGroup.add(this.getContentGroup());
  32567. /**
  32568. * @private
  32569. * @type {module:zrender/container/Group}
  32570. */
  32571. this.group.add(this._controllerGroup = new Group$3());
  32572. /**
  32573. *
  32574. * @private
  32575. */
  32576. this._showController;
  32577. },
  32578. /**
  32579. * @override
  32580. */
  32581. resetInner: function () {
  32582. ScrollableLegendView.superCall(this, 'resetInner');
  32583. this._controllerGroup.removeAll();
  32584. this._containerGroup.removeClipPath();
  32585. this._containerGroup.__rectSize = null;
  32586. },
  32587. /**
  32588. * @override
  32589. */
  32590. renderInner: function (itemAlign, legendModel, ecModel, api) {
  32591. var me = this;
  32592. // Render content items.
  32593. ScrollableLegendView.superCall(this, 'renderInner', itemAlign, legendModel, ecModel, api);
  32594. var controllerGroup = this._controllerGroup;
  32595. var pageIconSize = legendModel.get('pageIconSize', true);
  32596. if (!isArray(pageIconSize)) {
  32597. pageIconSize = [pageIconSize, pageIconSize];
  32598. }
  32599. createPageButton('pagePrev', 0);
  32600. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  32601. controllerGroup.add(new Text({
  32602. name: 'pageText',
  32603. style: {
  32604. textFill: pageTextStyleModel.getTextColor(),
  32605. font: pageTextStyleModel.getFont(),
  32606. textVerticalAlign: 'middle',
  32607. textAlign: 'center'
  32608. },
  32609. silent: true
  32610. }));
  32611. createPageButton('pageNext', 1);
  32612. function createPageButton(name, iconIdx) {
  32613. var pageDataIndexName = name + 'DataIndex';
  32614. var icon = createIcon(
  32615. legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx],
  32616. {
  32617. // Buttons will be created in each render, so we do not need
  32618. // to worry about avoiding using legendModel kept in scope.
  32619. onclick: bind(
  32620. me._pageGo, me, pageDataIndexName, legendModel, api
  32621. )
  32622. },
  32623. {
  32624. x: -pageIconSize[0] / 2,
  32625. y: -pageIconSize[1] / 2,
  32626. width: pageIconSize[0],
  32627. height: pageIconSize[1]
  32628. }
  32629. );
  32630. icon.name = name;
  32631. controllerGroup.add(icon);
  32632. }
  32633. },
  32634. /**
  32635. * @override
  32636. */
  32637. layoutInner: function (legendModel, itemAlign, maxSize) {
  32638. var contentGroup = this.getContentGroup();
  32639. var containerGroup = this._containerGroup;
  32640. var controllerGroup = this._controllerGroup;
  32641. var orientIdx = legendModel.getOrient().index;
  32642. var wh = WH[orientIdx];
  32643. var hw = WH[1 - orientIdx];
  32644. var yx = XY[1 - orientIdx];
  32645. // Place items in contentGroup.
  32646. box(
  32647. legendModel.get('orient'),
  32648. contentGroup,
  32649. legendModel.get('itemGap'),
  32650. !orientIdx ? null : maxSize.width,
  32651. orientIdx ? null : maxSize.height
  32652. );
  32653. box(
  32654. // Buttons in controller are layout always horizontally.
  32655. 'horizontal',
  32656. controllerGroup,
  32657. legendModel.get('pageButtonItemGap', true)
  32658. );
  32659. var contentRect = contentGroup.getBoundingRect();
  32660. var controllerRect = controllerGroup.getBoundingRect();
  32661. var showController = this._showController = contentRect[wh] > maxSize[wh];
  32662. var contentPos = [-contentRect.x, -contentRect.y];
  32663. // Remain contentPos when scroll animation perfroming.
  32664. contentPos[orientIdx] = contentGroup.position[orientIdx];
  32665. // Layout container group based on 0.
  32666. var containerPos = [0, 0];
  32667. var controllerPos = [-controllerRect.x, -controllerRect.y];
  32668. var pageButtonGap = retrieve2(
  32669. legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)
  32670. );
  32671. // Place containerGroup and controllerGroup and contentGroup.
  32672. if (showController) {
  32673. var pageButtonPosition = legendModel.get('pageButtonPosition', true);
  32674. // controller is on the right / bottom.
  32675. if (pageButtonPosition === 'end') {
  32676. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  32677. }
  32678. // controller is on the left / top.
  32679. else {
  32680. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  32681. }
  32682. }
  32683. // Always align controller to content as 'middle'.
  32684. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  32685. contentGroup.attr('position', contentPos);
  32686. containerGroup.attr('position', containerPos);
  32687. controllerGroup.attr('position', controllerPos);
  32688. // Calculate `mainRect` and set `clipPath`.
  32689. // mainRect should not be calculated by `this.group.getBoundingRect()`
  32690. // for sake of the overflow.
  32691. var mainRect = this.group.getBoundingRect();
  32692. var mainRect = {x: 0, y: 0};
  32693. // Consider content may be overflow (should be clipped).
  32694. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  32695. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]);
  32696. // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  32697. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  32698. containerGroup.__rectSize = maxSize[wh];
  32699. if (showController) {
  32700. var clipShape = {x: 0, y: 0};
  32701. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  32702. clipShape[hw] = mainRect[hw];
  32703. containerGroup.setClipPath(new Rect({shape: clipShape}));
  32704. // Consider content may be larger than container, container rect
  32705. // can not be obtained from `containerGroup.getBoundingRect()`.
  32706. containerGroup.__rectSize = clipShape[wh];
  32707. }
  32708. else {
  32709. // Do not remove or ignore controller. Keep them set as place holders.
  32710. controllerGroup.eachChild(function (child) {
  32711. child.attr({invisible: true, silent: true});
  32712. });
  32713. }
  32714. // Content translate animation.
  32715. var pageInfo = this._getPageInfo(legendModel);
  32716. pageInfo.pageIndex != null && updateProps(
  32717. contentGroup,
  32718. {position: pageInfo.contentPosition},
  32719. // When switch from "show controller" to "not show controller", view should be
  32720. // updated immediately without animation, otherwise causes weird efffect.
  32721. showController ? legendModel : false
  32722. );
  32723. this._updatePageInfoView(legendModel, pageInfo);
  32724. return mainRect;
  32725. },
  32726. _pageGo: function (to, legendModel, api) {
  32727. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  32728. scrollDataIndex != null && api.dispatchAction({
  32729. type: 'legendScroll',
  32730. scrollDataIndex: scrollDataIndex,
  32731. legendId: legendModel.id
  32732. });
  32733. },
  32734. _updatePageInfoView: function (legendModel, pageInfo) {
  32735. var controllerGroup = this._controllerGroup;
  32736. each$1(['pagePrev', 'pageNext'], function (name) {
  32737. var canJump = pageInfo[name + 'DataIndex'] != null;
  32738. var icon = controllerGroup.childOfName(name);
  32739. if (icon) {
  32740. icon.setStyle(
  32741. 'fill',
  32742. canJump
  32743. ? legendModel.get('pageIconColor', true)
  32744. : legendModel.get('pageIconInactiveColor', true)
  32745. );
  32746. icon.cursor = canJump ? 'pointer' : 'default';
  32747. }
  32748. });
  32749. var pageText = controllerGroup.childOfName('pageText');
  32750. var pageFormatter = legendModel.get('pageFormatter');
  32751. var pageIndex = pageInfo.pageIndex;
  32752. var current = pageIndex != null ? pageIndex + 1 : 0;
  32753. var total = pageInfo.pageCount;
  32754. pageText && pageFormatter && pageText.setStyle(
  32755. 'text',
  32756. isString(pageFormatter)
  32757. ? pageFormatter.replace('{current}', current).replace('{total}', total)
  32758. : pageFormatter({current: current, total: total})
  32759. );
  32760. },
  32761. /**
  32762. * @param {module:echarts/model/Model} legendModel
  32763. * @return {Object} {
  32764. * contentPosition: Array.<number>, null when data item not found.
  32765. * pageIndex: number, null when data item not found.
  32766. * pageCount: number, always be a number, can be 0.
  32767. * pagePrevDataIndex: number, null when no next page.
  32768. * pageNextDataIndex: number, null when no previous page.
  32769. * }
  32770. */
  32771. _getPageInfo: function (legendModel) {
  32772. // Align left or top by the current dataIndex.
  32773. var currDataIndex = legendModel.get('scrollDataIndex', true);
  32774. var contentGroup = this.getContentGroup();
  32775. var contentRect = contentGroup.getBoundingRect();
  32776. var containerRectSize = this._containerGroup.__rectSize;
  32777. var orientIdx = legendModel.getOrient().index;
  32778. var wh = WH[orientIdx];
  32779. var hw = WH[1 - orientIdx];
  32780. var xy = XY[orientIdx];
  32781. var contentPos = contentGroup.position.slice();
  32782. var pageIndex;
  32783. var pagePrevDataIndex;
  32784. var pageNextDataIndex;
  32785. var targetItemGroup;
  32786. if (this._showController) {
  32787. contentGroup.eachChild(function (child) {
  32788. if (child.__legendDataIndex === currDataIndex) {
  32789. targetItemGroup = child;
  32790. }
  32791. });
  32792. }
  32793. else {
  32794. targetItemGroup = contentGroup.childAt(0);
  32795. }
  32796. var pageCount = containerRectSize ? Math.ceil(contentRect[wh] / containerRectSize) : 0;
  32797. if (targetItemGroup) {
  32798. var itemRect = targetItemGroup.getBoundingRect();
  32799. var itemLoc = targetItemGroup.position[orientIdx] + itemRect[xy];
  32800. contentPos[orientIdx] = -itemLoc - contentRect[xy];
  32801. pageIndex = Math.floor(
  32802. pageCount * (itemLoc + itemRect[xy] + containerRectSize / 2) / contentRect[wh]
  32803. );
  32804. pageIndex = (contentRect[wh] && pageCount)
  32805. ? Math.max(0, Math.min(pageCount - 1, pageIndex))
  32806. : -1;
  32807. var winRect = {x: 0, y: 0};
  32808. winRect[wh] = containerRectSize;
  32809. winRect[hw] = contentRect[hw];
  32810. winRect[xy] = -contentPos[orientIdx] - contentRect[xy];
  32811. var startIdx;
  32812. var children = contentGroup.children();
  32813. contentGroup.eachChild(function (child, index) {
  32814. var itemRect = getItemRect(child);
  32815. if (itemRect.intersect(winRect)) {
  32816. startIdx == null && (startIdx = index);
  32817. // It is user-friendly that the last item shown in the
  32818. // current window is shown at the begining of next window.
  32819. pageNextDataIndex = child.__legendDataIndex;
  32820. }
  32821. // If the last item is shown entirely, no next page.
  32822. if (index === children.length - 1
  32823. && itemRect[xy] + itemRect[wh] <= winRect[xy] + winRect[wh]
  32824. ) {
  32825. pageNextDataIndex = null;
  32826. }
  32827. });
  32828. // Always align based on the left/top most item, so the left/top most
  32829. // item in the previous window is needed to be found here.
  32830. if (startIdx != null) {
  32831. var startItem = children[startIdx];
  32832. var startRect = getItemRect(startItem);
  32833. winRect[xy] = startRect[xy] + startRect[wh] - winRect[wh];
  32834. // If the first item is shown entirely, no previous page.
  32835. if (startIdx <= 0 && startRect[xy] >= winRect[xy]) {
  32836. pagePrevDataIndex = null;
  32837. }
  32838. else {
  32839. while (startIdx > 0 && getItemRect(children[startIdx - 1]).intersect(winRect)) {
  32840. startIdx--;
  32841. }
  32842. pagePrevDataIndex = children[startIdx].__legendDataIndex;
  32843. }
  32844. }
  32845. }
  32846. return {
  32847. contentPosition: contentPos,
  32848. pageIndex: pageIndex,
  32849. pageCount: pageCount,
  32850. pagePrevDataIndex: pagePrevDataIndex,
  32851. pageNextDataIndex: pageNextDataIndex
  32852. };
  32853. function getItemRect(el) {
  32854. var itemRect = el.getBoundingRect().clone();
  32855. itemRect[xy] += el.position[orientIdx];
  32856. return itemRect;
  32857. }
  32858. }
  32859. });
  32860. /**
  32861. * @event legendScroll
  32862. * @type {Object}
  32863. * @property {string} type 'legendScroll'
  32864. * @property {string} scrollDataIndex
  32865. */
  32866. registerAction(
  32867. 'legendScroll', 'legendscroll',
  32868. function (payload, ecModel) {
  32869. var scrollDataIndex = payload.scrollDataIndex;
  32870. scrollDataIndex != null && ecModel.eachComponent(
  32871. {mainType: 'legend', subType: 'scroll', query: payload},
  32872. function (legendModel) {
  32873. legendModel.setScrollDataIndex(scrollDataIndex);
  32874. }
  32875. );
  32876. }
  32877. );
  32878. /**
  32879. * Legend component entry file8
  32880. */
  32881. // Model
  32882. extendComponentModel({
  32883. type: 'title',
  32884. layoutMode: {type: 'box', ignoreSize: true},
  32885. defaultOption: {
  32886. // 一级层叠
  32887. zlevel: 0,
  32888. // 二级层叠
  32889. z: 6,
  32890. show: true,
  32891. text: '',
  32892. // 超链接跳转
  32893. // link: null,
  32894. // 仅支持self | blank
  32895. target: 'blank',
  32896. subtext: '',
  32897. // 超链接跳转
  32898. // sublink: null,
  32899. // 仅支持self | blank
  32900. subtarget: 'blank',
  32901. // 'center' ¦ 'left' ¦ 'right'
  32902. // ¦ {number}(x坐标,单位px)
  32903. left: 0,
  32904. // 'top' ¦ 'bottom' ¦ 'center'
  32905. // ¦ {number}(y坐标,单位px)
  32906. top: 0,
  32907. // 水平对齐
  32908. // 'auto' | 'left' | 'right' | 'center'
  32909. // 默认根据 left 的位置判断是左对齐还是右对齐
  32910. // textAlign: null
  32911. //
  32912. // 垂直对齐
  32913. // 'auto' | 'top' | 'bottom' | 'middle'
  32914. // 默认根据 top 位置判断是上对齐还是下对齐
  32915. // textBaseline: null
  32916. backgroundColor: 'rgba(0,0,0,0)',
  32917. // 标题边框颜色
  32918. borderColor: '#ccc',
  32919. // 标题边框线宽,单位px,默认为0(无边框)
  32920. borderWidth: 0,
  32921. // 标题内边距,单位px,默认各方向内边距为5,
  32922. // 接受数组分别设定上右下左边距,同css
  32923. padding: 5,
  32924. // 主副标题纵向间隔,单位px,默认为10,
  32925. itemGap: 10,
  32926. textStyle: {
  32927. fontSize: 18,
  32928. fontWeight: 'bolder',
  32929. color: '#333'
  32930. },
  32931. subtextStyle: {
  32932. color: '#aaa'
  32933. }
  32934. }
  32935. });
  32936. // View
  32937. extendComponentView({
  32938. type: 'title',
  32939. render: function (titleModel, ecModel, api) {
  32940. this.group.removeAll();
  32941. if (!titleModel.get('show')) {
  32942. return;
  32943. }
  32944. var group = this.group;
  32945. var textStyleModel = titleModel.getModel('textStyle');
  32946. var subtextStyleModel = titleModel.getModel('subtextStyle');
  32947. var textAlign = titleModel.get('textAlign');
  32948. var textBaseline = titleModel.get('textBaseline');
  32949. var textEl = new Text({
  32950. style: setTextStyle({}, textStyleModel, {
  32951. text: titleModel.get('text'),
  32952. textFill: textStyleModel.getTextColor()
  32953. }, {disableBox: true}),
  32954. z2: 10
  32955. });
  32956. var textRect = textEl.getBoundingRect();
  32957. var subText = titleModel.get('subtext');
  32958. var subTextEl = new Text({
  32959. style: setTextStyle({}, subtextStyleModel, {
  32960. text: subText,
  32961. textFill: subtextStyleModel.getTextColor(),
  32962. y: textRect.height + titleModel.get('itemGap'),
  32963. textVerticalAlign: 'top'
  32964. }, {disableBox: true}),
  32965. z2: 10
  32966. });
  32967. var link = titleModel.get('link');
  32968. var sublink = titleModel.get('sublink');
  32969. textEl.silent = !link;
  32970. subTextEl.silent = !sublink;
  32971. if (link) {
  32972. textEl.on('click', function () {
  32973. window.open(link, '_' + titleModel.get('target'));
  32974. });
  32975. }
  32976. if (sublink) {
  32977. subTextEl.on('click', function () {
  32978. window.open(sublink, '_' + titleModel.get('subtarget'));
  32979. });
  32980. }
  32981. group.add(textEl);
  32982. subText && group.add(subTextEl);
  32983. // If no subText, but add subTextEl, there will be an empty line.
  32984. var groupRect = group.getBoundingRect();
  32985. var layoutOption = titleModel.getBoxLayoutParams();
  32986. layoutOption.width = groupRect.width;
  32987. layoutOption.height = groupRect.height;
  32988. var layoutRect = getLayoutRect(
  32989. layoutOption, {
  32990. width: api.getWidth(),
  32991. height: api.getHeight()
  32992. }, titleModel.get('padding')
  32993. );
  32994. // Adjust text align based on position
  32995. if (!textAlign) {
  32996. // Align left if title is on the left. center and right is same
  32997. textAlign = titleModel.get('left') || titleModel.get('right');
  32998. if (textAlign === 'middle') {
  32999. textAlign = 'center';
  33000. }
  33001. // Adjust layout by text align
  33002. if (textAlign === 'right') {
  33003. layoutRect.x += layoutRect.width;
  33004. }
  33005. else if (textAlign === 'center') {
  33006. layoutRect.x += layoutRect.width / 2;
  33007. }
  33008. }
  33009. if (!textBaseline) {
  33010. textBaseline = titleModel.get('top') || titleModel.get('bottom');
  33011. if (textBaseline === 'center') {
  33012. textBaseline = 'middle';
  33013. }
  33014. if (textBaseline === 'bottom') {
  33015. layoutRect.y += layoutRect.height;
  33016. }
  33017. else if (textBaseline === 'middle') {
  33018. layoutRect.y += layoutRect.height / 2;
  33019. }
  33020. textBaseline = textBaseline || 'top';
  33021. }
  33022. group.attr('position', [layoutRect.x, layoutRect.y]);
  33023. var alignStyle = {
  33024. textAlign: textAlign,
  33025. textVerticalAlign: textBaseline
  33026. };
  33027. textEl.setStyle(alignStyle);
  33028. subTextEl.setStyle(alignStyle);
  33029. // Render background
  33030. // Get groupRect again because textAlign has been changed
  33031. groupRect = group.getBoundingRect();
  33032. var padding = layoutRect.margin;
  33033. var style = titleModel.getItemStyle(['color', 'opacity']);
  33034. style.fill = titleModel.get('backgroundColor');
  33035. var rect = new Rect({
  33036. shape: {
  33037. x: groupRect.x - padding[3],
  33038. y: groupRect.y - padding[0],
  33039. width: groupRect.width + padding[1] + padding[3],
  33040. height: groupRect.height + padding[0] + padding[2],
  33041. r: titleModel.get('borderRadius')
  33042. },
  33043. style: style,
  33044. silent: true
  33045. });
  33046. subPixelOptimizeRect(rect);
  33047. group.add(rect);
  33048. }
  33049. });
  33050. var addCommas$1 = addCommas;
  33051. var encodeHTML$1 = encodeHTML;
  33052. function fillLabel(opt) {
  33053. defaultEmphasis(opt.label, ['show']);
  33054. }
  33055. var MarkerModel = extendComponentModel({
  33056. type: 'marker',
  33057. dependencies: ['series', 'grid', 'polar', 'geo'],
  33058. /**
  33059. * @overrite
  33060. */
  33061. init: function (option, parentModel, ecModel, extraOpt) {
  33062. if (__DEV__) {
  33063. if (this.type === 'marker') {
  33064. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  33065. }
  33066. }
  33067. this.mergeDefaultAndTheme(option, ecModel);
  33068. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  33069. },
  33070. /**
  33071. * @return {boolean}
  33072. */
  33073. isAnimationEnabled: function () {
  33074. if (env$1.node) {
  33075. return false;
  33076. }
  33077. var hostSeries = this.__hostSeries;
  33078. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  33079. },
  33080. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  33081. var MarkerModel = this.constructor;
  33082. var modelPropName = this.mainType + 'Model';
  33083. if (!createdBySelf) {
  33084. ecModel.eachSeries(function (seriesModel) {
  33085. var markerOpt = seriesModel.get(this.mainType);
  33086. var markerModel = seriesModel[modelPropName];
  33087. if (!markerOpt || !markerOpt.data) {
  33088. seriesModel[modelPropName] = null;
  33089. return;
  33090. }
  33091. if (!markerModel) {
  33092. if (isInit) {
  33093. // Default label emphasis `position` and `show`
  33094. fillLabel(markerOpt);
  33095. }
  33096. each$1(markerOpt.data, function (item) {
  33097. // FIXME Overwrite fillLabel method ?
  33098. if (item instanceof Array) {
  33099. fillLabel(item[0]);
  33100. fillLabel(item[1]);
  33101. }
  33102. else {
  33103. fillLabel(item);
  33104. }
  33105. });
  33106. markerModel = new MarkerModel(
  33107. markerOpt, this, ecModel
  33108. );
  33109. extend(markerModel, {
  33110. mainType: this.mainType,
  33111. // Use the same series index and name
  33112. seriesIndex: seriesModel.seriesIndex,
  33113. name: seriesModel.name,
  33114. createdBySelf: true
  33115. });
  33116. markerModel.__hostSeries = seriesModel;
  33117. }
  33118. else {
  33119. markerModel.mergeOption(markerOpt, ecModel, true);
  33120. }
  33121. seriesModel[modelPropName] = markerModel;
  33122. }, this);
  33123. }
  33124. },
  33125. formatTooltip: function (dataIndex) {
  33126. var data = this.getData();
  33127. var value = this.getRawValue(dataIndex);
  33128. var formattedValue = isArray(value)
  33129. ? map(value, addCommas$1).join(', ') : addCommas$1(value);
  33130. var name = data.getName(dataIndex);
  33131. var html = encodeHTML$1(this.name);
  33132. if (value != null || name) {
  33133. html += '<br />';
  33134. }
  33135. if (name) {
  33136. html += encodeHTML$1(name);
  33137. if (value != null) {
  33138. html += ' : ';
  33139. }
  33140. }
  33141. if (value != null) {
  33142. html += encodeHTML$1(formattedValue);
  33143. }
  33144. return html;
  33145. },
  33146. getData: function () {
  33147. return this._data;
  33148. },
  33149. setData: function (data) {
  33150. this._data = data;
  33151. }
  33152. });
  33153. mixin(MarkerModel, dataFormatMixin);
  33154. MarkerModel.extend({
  33155. type: 'markPoint',
  33156. defaultOption: {
  33157. zlevel: 0,
  33158. z: 5,
  33159. symbol: 'pin',
  33160. symbolSize: 50,
  33161. //symbolRotate: 0,
  33162. //symbolOffset: [0, 0]
  33163. tooltip: {
  33164. trigger: 'item'
  33165. },
  33166. label: {
  33167. normal: {
  33168. show: true,
  33169. position: 'inside'
  33170. },
  33171. emphasis: {
  33172. show: true
  33173. }
  33174. },
  33175. itemStyle: {
  33176. normal: {
  33177. borderWidth: 2
  33178. }
  33179. }
  33180. }
  33181. });
  33182. var indexOf$2 = indexOf;
  33183. function hasXOrY(item) {
  33184. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  33185. }
  33186. function hasXAndY(item) {
  33187. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  33188. }
  33189. function getPrecision$1(data, valueAxisDim, dataIndex) {
  33190. var precision = -1;
  33191. do {
  33192. precision = Math.max(
  33193. getPrecision(data.get(
  33194. valueAxisDim, dataIndex
  33195. )),
  33196. precision
  33197. );
  33198. data = data.stackedOn;
  33199. } while (data);
  33200. return precision;
  33201. }
  33202. function markerTypeCalculatorWithExtent(
  33203. mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex
  33204. ) {
  33205. var coordArr = [];
  33206. var value = numCalculate(data, targetDataDim, mlType);
  33207. var dataIndex = data.indicesOfNearest(targetDataDim, value, true)[0];
  33208. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex, true);
  33209. coordArr[targetCoordIndex] = data.get(targetDataDim, dataIndex, true);
  33210. var precision = getPrecision$1(data, targetDataDim, dataIndex);
  33211. precision = Math.min(precision, 20);
  33212. if (precision >= 0) {
  33213. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  33214. }
  33215. return coordArr;
  33216. }
  33217. var curry$4 = curry;
  33218. // TODO Specified percent
  33219. var markerTypeCalculator = {
  33220. /**
  33221. * @method
  33222. * @param {module:echarts/data/List} data
  33223. * @param {string} baseAxisDim
  33224. * @param {string} valueAxisDim
  33225. */
  33226. min: curry$4(markerTypeCalculatorWithExtent, 'min'),
  33227. /**
  33228. * @method
  33229. * @param {module:echarts/data/List} data
  33230. * @param {string} baseAxisDim
  33231. * @param {string} valueAxisDim
  33232. */
  33233. max: curry$4(markerTypeCalculatorWithExtent, 'max'),
  33234. /**
  33235. * @method
  33236. * @param {module:echarts/data/List} data
  33237. * @param {string} baseAxisDim
  33238. * @param {string} valueAxisDim
  33239. */
  33240. average: curry$4(markerTypeCalculatorWithExtent, 'average')
  33241. };
  33242. /**
  33243. * Transform markPoint data item to format used in List by do the following
  33244. * 1. Calculate statistic like `max`, `min`, `average`
  33245. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  33246. * @param {module:echarts/model/Series} seriesModel
  33247. * @param {module:echarts/coord/*} [coordSys]
  33248. * @param {Object} item
  33249. * @return {Object}
  33250. */
  33251. function dataTransform(seriesModel, item) {
  33252. var data = seriesModel.getData();
  33253. var coordSys = seriesModel.coordinateSystem;
  33254. // 1. If not specify the position with pixel directly
  33255. // 2. If `coord` is not a data array. Which uses `xAxis`,
  33256. // `yAxis` to specify the coord on each dimension
  33257. // parseFloat first because item.x and item.y can be percent string like '20%'
  33258. if (item && !hasXAndY(item) && !isArray(item.coord) && coordSys) {
  33259. var dims = coordSys.dimensions;
  33260. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  33261. // Clone the option
  33262. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  33263. item = clone(item);
  33264. if (item.type
  33265. && markerTypeCalculator[item.type]
  33266. && axisInfo.baseAxis && axisInfo.valueAxis
  33267. ) {
  33268. var otherCoordIndex = indexOf$2(dims, axisInfo.baseAxis.dim);
  33269. var targetCoordIndex = indexOf$2(dims, axisInfo.valueAxis.dim);
  33270. item.coord = markerTypeCalculator[item.type](
  33271. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  33272. otherCoordIndex, targetCoordIndex
  33273. );
  33274. // Force to use the value of calculated value.
  33275. item.value = item.coord[targetCoordIndex];
  33276. }
  33277. else {
  33278. // FIXME Only has one of xAxis and yAxis.
  33279. var coord = [
  33280. item.xAxis != null ? item.xAxis : item.radiusAxis,
  33281. item.yAxis != null ? item.yAxis : item.angleAxis
  33282. ];
  33283. // Each coord support max, min, average
  33284. for (var i = 0; i < 2; i++) {
  33285. if (markerTypeCalculator[coord[i]]) {
  33286. var dataDim = seriesModel.coordDimToDataDim(dims[i])[0];
  33287. coord[i] = numCalculate(data, dataDim, coord[i]);
  33288. }
  33289. }
  33290. item.coord = coord;
  33291. }
  33292. }
  33293. return item;
  33294. }
  33295. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  33296. var ret = {};
  33297. if (item.valueIndex != null || item.valueDim != null) {
  33298. ret.valueDataDim = item.valueIndex != null
  33299. ? data.getDimension(item.valueIndex) : item.valueDim;
  33300. ret.valueAxis = coordSys.getAxis(seriesModel.dataDimToCoordDim(ret.valueDataDim));
  33301. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  33302. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  33303. }
  33304. else {
  33305. ret.baseAxis = seriesModel.getBaseAxis();
  33306. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  33307. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  33308. ret.valueDataDim = seriesModel.coordDimToDataDim(ret.valueAxis.dim)[0];
  33309. }
  33310. return ret;
  33311. }
  33312. /**
  33313. * Filter data which is out of coordinateSystem range
  33314. * [dataFilter description]
  33315. * @param {module:echarts/coord/*} [coordSys]
  33316. * @param {Object} item
  33317. * @return {boolean}
  33318. */
  33319. function dataFilter$1(coordSys, item) {
  33320. // Alwalys return true if there is no coordSys
  33321. return (coordSys && coordSys.containData && item.coord && !hasXOrY(item))
  33322. ? coordSys.containData(item.coord) : true;
  33323. }
  33324. function dimValueGetter(item, dimName, dataIndex, dimIndex) {
  33325. // x, y, radius, angle
  33326. if (dimIndex < 2) {
  33327. return item.coord && item.coord[dimIndex];
  33328. }
  33329. return item.value;
  33330. }
  33331. function numCalculate(data, valueDataDim, type) {
  33332. if (type === 'average') {
  33333. var sum = 0;
  33334. var count = 0;
  33335. data.each(valueDataDim, function (val, idx) {
  33336. if (!isNaN(val)) {
  33337. sum += val;
  33338. count++;
  33339. }
  33340. }, true);
  33341. return sum / count;
  33342. }
  33343. else {
  33344. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  33345. }
  33346. }
  33347. var MarkerView = extendComponentView({
  33348. type: 'marker',
  33349. init: function () {
  33350. /**
  33351. * Markline grouped by series
  33352. * @private
  33353. * @type {module:zrender/core/util.HashMap}
  33354. */
  33355. this.markerGroupMap = createHashMap();
  33356. },
  33357. render: function (markerModel, ecModel, api) {
  33358. var markerGroupMap = this.markerGroupMap;
  33359. markerGroupMap.each(function (item) {
  33360. item.__keep = false;
  33361. });
  33362. var markerModelKey = this.type + 'Model';
  33363. ecModel.eachSeries(function (seriesModel) {
  33364. var markerModel = seriesModel[markerModelKey];
  33365. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  33366. }, this);
  33367. markerGroupMap.each(function (item) {
  33368. !item.__keep && this.group.remove(item.group);
  33369. }, this);
  33370. },
  33371. renderSeries: function () {}
  33372. });
  33373. function updateMarkerLayout(mpData, seriesModel, api) {
  33374. var coordSys = seriesModel.coordinateSystem;
  33375. mpData.each(function (idx) {
  33376. var itemModel = mpData.getItemModel(idx);
  33377. var point;
  33378. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  33379. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  33380. if (!isNaN(xPx) && !isNaN(yPx)) {
  33381. point = [xPx, yPx];
  33382. }
  33383. // Chart like bar may have there own marker positioning logic
  33384. else if (seriesModel.getMarkerPosition) {
  33385. // Use the getMarkerPoisition
  33386. point = seriesModel.getMarkerPosition(
  33387. mpData.getValues(mpData.dimensions, idx)
  33388. );
  33389. }
  33390. else if (coordSys) {
  33391. var x = mpData.get(coordSys.dimensions[0], idx);
  33392. var y = mpData.get(coordSys.dimensions[1], idx);
  33393. point = coordSys.dataToPoint([x, y]);
  33394. }
  33395. // Use x, y if has any
  33396. if (!isNaN(xPx)) {
  33397. point[0] = xPx;
  33398. }
  33399. if (!isNaN(yPx)) {
  33400. point[1] = yPx;
  33401. }
  33402. mpData.setItemLayout(idx, point);
  33403. });
  33404. }
  33405. MarkerView.extend({
  33406. type: 'markPoint',
  33407. updateLayout: function (markPointModel, ecModel, api) {
  33408. ecModel.eachSeries(function (seriesModel) {
  33409. var mpModel = seriesModel.markPointModel;
  33410. if (mpModel) {
  33411. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  33412. this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  33413. }
  33414. }, this);
  33415. },
  33416. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  33417. var coordSys = seriesModel.coordinateSystem;
  33418. var seriesId = seriesModel.id;
  33419. var seriesData = seriesModel.getData();
  33420. var symbolDrawMap = this.markerGroupMap;
  33421. var symbolDraw = symbolDrawMap.get(seriesId)
  33422. || symbolDrawMap.set(seriesId, new SymbolDraw());
  33423. var mpData = createList$1(coordSys, seriesModel, mpModel);
  33424. // FIXME
  33425. mpModel.setData(mpData);
  33426. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  33427. mpData.each(function (idx) {
  33428. var itemModel = mpData.getItemModel(idx);
  33429. var symbolSize = itemModel.getShallow('symbolSize');
  33430. if (typeof symbolSize === 'function') {
  33431. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  33432. symbolSize = symbolSize(
  33433. mpModel.getRawValue(idx), mpModel.getDataParams(idx)
  33434. );
  33435. }
  33436. mpData.setItemVisual(idx, {
  33437. symbolSize: symbolSize,
  33438. color: itemModel.get('itemStyle.normal.color')
  33439. || seriesData.getVisual('color'),
  33440. symbol: itemModel.getShallow('symbol')
  33441. });
  33442. });
  33443. // TODO Text are wrong
  33444. symbolDraw.updateData(mpData);
  33445. this.group.add(symbolDraw.group);
  33446. // Set host model for tooltip
  33447. // FIXME
  33448. mpData.eachItemGraphicEl(function (el) {
  33449. el.traverse(function (child) {
  33450. child.dataModel = mpModel;
  33451. });
  33452. });
  33453. symbolDraw.__keep = true;
  33454. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  33455. }
  33456. });
  33457. /**
  33458. * @inner
  33459. * @param {module:echarts/coord/*} [coordSys]
  33460. * @param {module:echarts/model/Series} seriesModel
  33461. * @param {module:echarts/model/Model} mpModel
  33462. */
  33463. function createList$1(coordSys, seriesModel, mpModel) {
  33464. var coordDimsInfos;
  33465. if (coordSys) {
  33466. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  33467. var info = seriesModel.getData().getDimensionInfo(
  33468. seriesModel.coordDimToDataDim(coordDim)[0]
  33469. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  33470. info.name = coordDim;
  33471. return info;
  33472. });
  33473. }
  33474. else {
  33475. coordDimsInfos =[{
  33476. name: 'value',
  33477. type: 'float'
  33478. }];
  33479. }
  33480. var mpData = new List(coordDimsInfos, mpModel);
  33481. var dataOpt = map(mpModel.get('data'), curry(
  33482. dataTransform, seriesModel
  33483. ));
  33484. if (coordSys) {
  33485. dataOpt = filter(
  33486. dataOpt, curry(dataFilter$1, coordSys)
  33487. );
  33488. }
  33489. mpData.initData(dataOpt, null,
  33490. coordSys ? dimValueGetter : function (item) {
  33491. return item.value;
  33492. }
  33493. );
  33494. return mpData;
  33495. }
  33496. // HINT Markpoint can't be used too much
  33497. registerPreprocessor(function (opt) {
  33498. // Make sure markPoint component is enabled
  33499. opt.markPoint = opt.markPoint || {};
  33500. });
  33501. MarkerModel.extend({
  33502. type: 'markLine',
  33503. defaultOption: {
  33504. zlevel: 0,
  33505. z: 5,
  33506. symbol: ['circle', 'arrow'],
  33507. symbolSize: [8, 16],
  33508. //symbolRotate: 0,
  33509. precision: 2,
  33510. tooltip: {
  33511. trigger: 'item'
  33512. },
  33513. label: {
  33514. normal: {
  33515. show: true,
  33516. position: 'end'
  33517. },
  33518. emphasis: {
  33519. show: true
  33520. }
  33521. },
  33522. lineStyle: {
  33523. normal: {
  33524. type: 'dashed'
  33525. },
  33526. emphasis: {
  33527. width: 3
  33528. }
  33529. },
  33530. animationEasing: 'linear'
  33531. }
  33532. });
  33533. /**
  33534. * Line path for bezier and straight line draw
  33535. */
  33536. var straightLineProto = Line.prototype;
  33537. var bezierCurveProto = BezierCurve.prototype;
  33538. function isLine(shape) {
  33539. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  33540. }
  33541. var LinePath = extendShape({
  33542. type: 'ec-line',
  33543. style: {
  33544. stroke: '#000',
  33545. fill: null
  33546. },
  33547. shape: {
  33548. x1: 0,
  33549. y1: 0,
  33550. x2: 0,
  33551. y2: 0,
  33552. percent: 1,
  33553. cpx1: null,
  33554. cpy1: null
  33555. },
  33556. buildPath: function (ctx, shape) {
  33557. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  33558. },
  33559. pointAt: function (t) {
  33560. return isLine(this.shape)
  33561. ? straightLineProto.pointAt.call(this, t)
  33562. : bezierCurveProto.pointAt.call(this, t);
  33563. },
  33564. tangentAt: function (t) {
  33565. var shape = this.shape;
  33566. var p = isLine(shape)
  33567. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  33568. : bezierCurveProto.tangentAt.call(this, t);
  33569. return normalize(p, p);
  33570. }
  33571. });
  33572. /**
  33573. * @module echarts/chart/helper/Line
  33574. */
  33575. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  33576. function makeSymbolTypeKey(symbolCategory) {
  33577. return '_' + symbolCategory + 'Type';
  33578. }
  33579. /**
  33580. * @inner
  33581. */
  33582. function createSymbol$1(name, lineData, idx) {
  33583. var color = lineData.getItemVisual(idx, 'color');
  33584. var symbolType = lineData.getItemVisual(idx, name);
  33585. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  33586. if (!symbolType || symbolType === 'none') {
  33587. return;
  33588. }
  33589. if (!isArray(symbolSize)) {
  33590. symbolSize = [symbolSize, symbolSize];
  33591. }
  33592. var symbolPath = createSymbol(
  33593. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  33594. symbolSize[0], symbolSize[1], color
  33595. );
  33596. symbolPath.name = name;
  33597. return symbolPath;
  33598. }
  33599. function createLine(points) {
  33600. var line = new LinePath({
  33601. name: 'line'
  33602. });
  33603. setLinePoints(line.shape, points);
  33604. return line;
  33605. }
  33606. function setLinePoints(targetShape, points) {
  33607. var p1 = points[0];
  33608. var p2 = points[1];
  33609. var cp1 = points[2];
  33610. targetShape.x1 = p1[0];
  33611. targetShape.y1 = p1[1];
  33612. targetShape.x2 = p2[0];
  33613. targetShape.y2 = p2[1];
  33614. targetShape.percent = 1;
  33615. if (cp1) {
  33616. targetShape.cpx1 = cp1[0];
  33617. targetShape.cpy1 = cp1[1];
  33618. }
  33619. else {
  33620. targetShape.cpx1 = NaN;
  33621. targetShape.cpy1 = NaN;
  33622. }
  33623. }
  33624. function updateSymbolAndLabelBeforeLineUpdate () {
  33625. var lineGroup = this;
  33626. var symbolFrom = lineGroup.childOfName('fromSymbol');
  33627. var symbolTo = lineGroup.childOfName('toSymbol');
  33628. var label = lineGroup.childOfName('label');
  33629. // Quick reject
  33630. if (!symbolFrom && !symbolTo && label.ignore) {
  33631. return;
  33632. }
  33633. var invScale = 1;
  33634. var parentNode = this.parent;
  33635. while (parentNode) {
  33636. if (parentNode.scale) {
  33637. invScale /= parentNode.scale[0];
  33638. }
  33639. parentNode = parentNode.parent;
  33640. }
  33641. var line = lineGroup.childOfName('line');
  33642. // If line not changed
  33643. // FIXME Parent scale changed
  33644. if (!this.__dirty && !line.__dirty) {
  33645. return;
  33646. }
  33647. var percent = line.shape.percent;
  33648. var fromPos = line.pointAt(0);
  33649. var toPos = line.pointAt(percent);
  33650. var d = sub([], toPos, fromPos);
  33651. normalize(d, d);
  33652. if (symbolFrom) {
  33653. symbolFrom.attr('position', fromPos);
  33654. var tangent = line.tangentAt(0);
  33655. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  33656. tangent[1], tangent[0]
  33657. ));
  33658. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  33659. }
  33660. if (symbolTo) {
  33661. symbolTo.attr('position', toPos);
  33662. var tangent = line.tangentAt(1);
  33663. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  33664. tangent[1], tangent[0]
  33665. ));
  33666. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  33667. }
  33668. if (!label.ignore) {
  33669. label.attr('position', toPos);
  33670. var textPosition;
  33671. var textAlign;
  33672. var textVerticalAlign;
  33673. var distance$$1 = 5 * invScale;
  33674. // End
  33675. if (label.__position === 'end') {
  33676. textPosition = [d[0] * distance$$1 + toPos[0], d[1] * distance$$1 + toPos[1]];
  33677. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  33678. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  33679. }
  33680. // Middle
  33681. else if (label.__position === 'middle') {
  33682. var halfPercent = percent / 2;
  33683. var tangent = line.tangentAt(halfPercent);
  33684. var n = [tangent[1], -tangent[0]];
  33685. var cp = line.pointAt(halfPercent);
  33686. if (n[1] > 0) {
  33687. n[0] = -n[0];
  33688. n[1] = -n[1];
  33689. }
  33690. textPosition = [cp[0] + n[0] * distance$$1, cp[1] + n[1] * distance$$1];
  33691. textAlign = 'center';
  33692. textVerticalAlign = 'bottom';
  33693. var rotation = -Math.atan2(tangent[1], tangent[0]);
  33694. if (toPos[0] < fromPos[0]) {
  33695. rotation = Math.PI + rotation;
  33696. }
  33697. label.attr('rotation', rotation);
  33698. }
  33699. // Start
  33700. else {
  33701. textPosition = [-d[0] * distance$$1 + fromPos[0], -d[1] * distance$$1 + fromPos[1]];
  33702. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  33703. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  33704. }
  33705. label.attr({
  33706. style: {
  33707. // Use the user specified text align and baseline first
  33708. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  33709. textAlign: label.__textAlign || textAlign
  33710. },
  33711. position: textPosition,
  33712. scale: [invScale, invScale]
  33713. });
  33714. }
  33715. }
  33716. /**
  33717. * @constructor
  33718. * @extends {module:zrender/graphic/Group}
  33719. * @alias {module:echarts/chart/helper/Line}
  33720. */
  33721. function Line$1(lineData, idx, seriesScope) {
  33722. Group.call(this);
  33723. this._createLine(lineData, idx, seriesScope);
  33724. }
  33725. var lineProto = Line$1.prototype;
  33726. // Update symbol position and rotation
  33727. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  33728. lineProto._createLine = function (lineData, idx, seriesScope) {
  33729. var seriesModel = lineData.hostModel;
  33730. var linePoints = lineData.getItemLayout(idx);
  33731. var line = createLine(linePoints);
  33732. line.shape.percent = 0;
  33733. initProps(line, {
  33734. shape: {
  33735. percent: 1
  33736. }
  33737. }, seriesModel, idx);
  33738. this.add(line);
  33739. var label = new Text({
  33740. name: 'label'
  33741. });
  33742. this.add(label);
  33743. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  33744. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  33745. // symbols must added after line to make sure
  33746. // it will be updated after line#update.
  33747. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  33748. this.add(symbol);
  33749. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  33750. }, this);
  33751. this._updateCommonStl(lineData, idx, seriesScope);
  33752. };
  33753. lineProto.updateData = function (lineData, idx, seriesScope) {
  33754. var seriesModel = lineData.hostModel;
  33755. var line = this.childOfName('line');
  33756. var linePoints = lineData.getItemLayout(idx);
  33757. var target = {
  33758. shape: {}
  33759. };
  33760. setLinePoints(target.shape, linePoints);
  33761. updateProps(line, target, seriesModel, idx);
  33762. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  33763. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  33764. var key = makeSymbolTypeKey(symbolCategory);
  33765. // Symbol changed
  33766. if (this[key] !== symbolType) {
  33767. this.remove(this.childOfName(symbolCategory));
  33768. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  33769. this.add(symbol);
  33770. }
  33771. this[key] = symbolType;
  33772. }, this);
  33773. this._updateCommonStl(lineData, idx, seriesScope);
  33774. };
  33775. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  33776. var seriesModel = lineData.hostModel;
  33777. var line = this.childOfName('line');
  33778. var lineStyle = seriesScope && seriesScope.lineStyle;
  33779. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  33780. var labelModel = seriesScope && seriesScope.labelModel;
  33781. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  33782. // Optimization for large dataset
  33783. if (!seriesScope || lineData.hasItemOption) {
  33784. var itemModel = lineData.getItemModel(idx);
  33785. lineStyle = itemModel.getModel('lineStyle.normal').getLineStyle();
  33786. hoverLineStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  33787. labelModel = itemModel.getModel('label.normal');
  33788. hoverLabelModel = itemModel.getModel('label.emphasis');
  33789. }
  33790. var visualColor = lineData.getItemVisual(idx, 'color');
  33791. var visualOpacity = retrieve3(
  33792. lineData.getItemVisual(idx, 'opacity'),
  33793. lineStyle.opacity,
  33794. 1
  33795. );
  33796. line.useStyle(defaults(
  33797. {
  33798. strokeNoScale: true,
  33799. fill: 'none',
  33800. stroke: visualColor,
  33801. opacity: visualOpacity
  33802. },
  33803. lineStyle
  33804. ));
  33805. line.hoverStyle = hoverLineStyle;
  33806. // Update symbol
  33807. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  33808. var symbol = this.childOfName(symbolCategory);
  33809. if (symbol) {
  33810. symbol.setColor(visualColor);
  33811. symbol.setStyle({
  33812. opacity: visualOpacity
  33813. });
  33814. }
  33815. }, this);
  33816. var showLabel = labelModel.getShallow('show');
  33817. var hoverShowLabel = hoverLabelModel.getShallow('show');
  33818. var label = this.childOfName('label');
  33819. var defaultLabelColor;
  33820. var defaultText;
  33821. var normalText;
  33822. var emphasisText;
  33823. if (showLabel || hoverShowLabel) {
  33824. var rawVal = seriesModel.getRawValue(idx);
  33825. defaultText = rawVal == null
  33826. ? defaultText = lineData.getName(idx)
  33827. : isFinite(rawVal)
  33828. ? round(rawVal)
  33829. : rawVal;
  33830. defaultLabelColor = visualColor || '#000';
  33831. normalText = retrieve2(
  33832. seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType),
  33833. defaultText
  33834. );
  33835. emphasisText = retrieve2(
  33836. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  33837. normalText
  33838. );
  33839. }
  33840. // label.afterUpdate = lineAfterUpdate;
  33841. if (showLabel) {
  33842. var labelStyle = setTextStyle(label.style, labelModel, {
  33843. text: normalText
  33844. }, {
  33845. autoColor: defaultLabelColor
  33846. });
  33847. label.__textAlign = labelStyle.textAlign;
  33848. label.__verticalAlign = labelStyle.textVerticalAlign;
  33849. // 'start', 'middle', 'end'
  33850. label.__position = labelModel.get('position') || 'middle';
  33851. }
  33852. else {
  33853. label.setStyle('text', null);
  33854. }
  33855. if (hoverShowLabel) {
  33856. // Only these properties supported in this emphasis style here.
  33857. label.hoverStyle = {
  33858. text: emphasisText,
  33859. textFill: hoverLabelModel.getTextColor(true),
  33860. // For merging hover style to normal style, do not use
  33861. // `hoverLabelModel.getFont()` here.
  33862. fontStyle: hoverLabelModel.getShallow('fontStyle'),
  33863. fontWeight: hoverLabelModel.getShallow('fontWeight'),
  33864. fontSize: hoverLabelModel.getShallow('fontSize'),
  33865. fontFamily: hoverLabelModel.getShallow('fontFamily')
  33866. };
  33867. }
  33868. else {
  33869. label.hoverStyle = {
  33870. text: null
  33871. };
  33872. }
  33873. label.ignore = !showLabel && !hoverShowLabel;
  33874. setHoverStyle(this);
  33875. };
  33876. lineProto.highlight = function () {
  33877. this.trigger('emphasis');
  33878. };
  33879. lineProto.downplay = function () {
  33880. this.trigger('normal');
  33881. };
  33882. lineProto.updateLayout = function (lineData, idx) {
  33883. this.setLinePoints(lineData.getItemLayout(idx));
  33884. };
  33885. lineProto.setLinePoints = function (points) {
  33886. var linePath = this.childOfName('line');
  33887. setLinePoints(linePath.shape, points);
  33888. linePath.dirty();
  33889. };
  33890. inherits(Line$1, Group);
  33891. /**
  33892. * @module echarts/chart/helper/LineDraw
  33893. */
  33894. function isPointNaN(pt) {
  33895. return isNaN(pt[0]) || isNaN(pt[1]);
  33896. }
  33897. function lineNeedsDraw(pts) {
  33898. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  33899. }
  33900. /**
  33901. * @alias module:echarts/component/marker/LineDraw
  33902. * @constructor
  33903. */
  33904. function LineDraw(ctor) {
  33905. this._ctor = ctor || Line$1;
  33906. this.group = new Group();
  33907. }
  33908. var lineDrawProto = LineDraw.prototype;
  33909. /**
  33910. * @param {module:echarts/data/List} lineData
  33911. */
  33912. lineDrawProto.updateData = function (lineData) {
  33913. var oldLineData = this._lineData;
  33914. var group = this.group;
  33915. var LineCtor = this._ctor;
  33916. var hostModel = lineData.hostModel;
  33917. var seriesScope = {
  33918. lineStyle: hostModel.getModel('lineStyle.normal').getLineStyle(),
  33919. hoverLineStyle: hostModel.getModel('lineStyle.emphasis').getLineStyle(),
  33920. labelModel: hostModel.getModel('label.normal'),
  33921. hoverLabelModel: hostModel.getModel('label.emphasis')
  33922. };
  33923. lineData.diff(oldLineData)
  33924. .add(function (idx) {
  33925. if (!lineNeedsDraw(lineData.getItemLayout(idx))) {
  33926. return;
  33927. }
  33928. var lineGroup = new LineCtor(lineData, idx, seriesScope);
  33929. lineData.setItemGraphicEl(idx, lineGroup);
  33930. group.add(lineGroup);
  33931. })
  33932. .update(function (newIdx, oldIdx) {
  33933. var lineGroup = oldLineData.getItemGraphicEl(oldIdx);
  33934. if (!lineNeedsDraw(lineData.getItemLayout(newIdx))) {
  33935. group.remove(lineGroup);
  33936. return;
  33937. }
  33938. if (!lineGroup) {
  33939. lineGroup = new LineCtor(lineData, newIdx, seriesScope);
  33940. }
  33941. else {
  33942. lineGroup.updateData(lineData, newIdx, seriesScope);
  33943. }
  33944. lineData.setItemGraphicEl(newIdx, lineGroup);
  33945. group.add(lineGroup);
  33946. })
  33947. .remove(function (idx) {
  33948. group.remove(oldLineData.getItemGraphicEl(idx));
  33949. })
  33950. .execute();
  33951. this._lineData = lineData;
  33952. };
  33953. lineDrawProto.updateLayout = function () {
  33954. var lineData = this._lineData;
  33955. lineData.eachItemGraphicEl(function (el, idx) {
  33956. el.updateLayout(lineData, idx);
  33957. }, this);
  33958. };
  33959. lineDrawProto.remove = function () {
  33960. this.group.removeAll();
  33961. };
  33962. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  33963. var data = seriesModel.getData();
  33964. // Special type markLine like 'min', 'max', 'average'
  33965. var mlType = item.type;
  33966. if (!isArray(item)
  33967. && (
  33968. mlType === 'min' || mlType === 'max' || mlType === 'average'
  33969. // In case
  33970. // data: [{
  33971. // yAxis: 10
  33972. // }]
  33973. || (item.xAxis != null || item.yAxis != null)
  33974. )
  33975. ) {
  33976. var valueAxis;
  33977. var valueDataDim;
  33978. var value;
  33979. if (item.yAxis != null || item.xAxis != null) {
  33980. valueDataDim = item.yAxis != null ? 'y' : 'x';
  33981. valueAxis = coordSys.getAxis(valueDataDim);
  33982. value = retrieve(item.yAxis, item.xAxis);
  33983. }
  33984. else {
  33985. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  33986. valueDataDim = axisInfo.valueDataDim;
  33987. valueAxis = axisInfo.valueAxis;
  33988. value = numCalculate(data, valueDataDim, mlType);
  33989. }
  33990. var valueIndex = valueDataDim === 'x' ? 0 : 1;
  33991. var baseIndex = 1 - valueIndex;
  33992. var mlFrom = clone(item);
  33993. var mlTo = {};
  33994. mlFrom.type = null;
  33995. mlFrom.coord = [];
  33996. mlTo.coord = [];
  33997. mlFrom.coord[baseIndex] = -Infinity;
  33998. mlTo.coord[baseIndex] = Infinity;
  33999. var precision = mlModel.get('precision');
  34000. if (precision >= 0 && typeof value === 'number') {
  34001. value = +value.toFixed(Math.min(precision, 20));
  34002. }
  34003. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  34004. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  34005. type: mlType,
  34006. valueIndex: item.valueIndex,
  34007. // Force to use the value of calculated value.
  34008. value: value
  34009. }];
  34010. }
  34011. item = [
  34012. dataTransform(seriesModel, item[0]),
  34013. dataTransform(seriesModel, item[1]),
  34014. extend({}, item[2])
  34015. ];
  34016. // Avoid line data type is extended by from(to) data type
  34017. item[2].type = item[2].type || '';
  34018. // Merge from option and to option into line option
  34019. merge(item[2], item[0]);
  34020. merge(item[2], item[1]);
  34021. return item;
  34022. };
  34023. function isInifinity(val) {
  34024. return !isNaN(val) && !isFinite(val);
  34025. }
  34026. // If a markLine has one dim
  34027. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  34028. var otherDimIndex = 1 - dimIndex;
  34029. var dimName = coordSys.dimensions[dimIndex];
  34030. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  34031. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  34032. }
  34033. function markLineFilter(coordSys, item) {
  34034. if (coordSys.type === 'cartesian2d') {
  34035. var fromCoord = item[0].coord;
  34036. var toCoord = item[1].coord;
  34037. // In case
  34038. // {
  34039. // markLine: {
  34040. // data: [{ yAxis: 2 }]
  34041. // }
  34042. // }
  34043. if (
  34044. fromCoord && toCoord &&
  34045. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  34046. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  34047. ) {
  34048. return true;
  34049. }
  34050. }
  34051. return dataFilter$1(coordSys, item[0])
  34052. && dataFilter$1(coordSys, item[1]);
  34053. }
  34054. function updateSingleMarkerEndLayout(
  34055. data, idx, isFrom, seriesModel, api
  34056. ) {
  34057. var coordSys = seriesModel.coordinateSystem;
  34058. var itemModel = data.getItemModel(idx);
  34059. var point;
  34060. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  34061. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  34062. if (!isNaN(xPx) && !isNaN(yPx)) {
  34063. point = [xPx, yPx];
  34064. }
  34065. else {
  34066. // Chart like bar may have there own marker positioning logic
  34067. if (seriesModel.getMarkerPosition) {
  34068. // Use the getMarkerPoisition
  34069. point = seriesModel.getMarkerPosition(
  34070. data.getValues(data.dimensions, idx)
  34071. );
  34072. }
  34073. else {
  34074. var dims = coordSys.dimensions;
  34075. var x = data.get(dims[0], idx);
  34076. var y = data.get(dims[1], idx);
  34077. point = coordSys.dataToPoint([x, y]);
  34078. }
  34079. // Expand line to the edge of grid if value on one axis is Inifnity
  34080. // In case
  34081. // markLine: {
  34082. // data: [{
  34083. // yAxis: 2
  34084. // // or
  34085. // type: 'average'
  34086. // }]
  34087. // }
  34088. if (coordSys.type === 'cartesian2d') {
  34089. var xAxis = coordSys.getAxis('x');
  34090. var yAxis = coordSys.getAxis('y');
  34091. var dims = coordSys.dimensions;
  34092. if (isInifinity(data.get(dims[0], idx))) {
  34093. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  34094. }
  34095. else if (isInifinity(data.get(dims[1], idx))) {
  34096. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  34097. }
  34098. }
  34099. // Use x, y if has any
  34100. if (!isNaN(xPx)) {
  34101. point[0] = xPx;
  34102. }
  34103. if (!isNaN(yPx)) {
  34104. point[1] = yPx;
  34105. }
  34106. }
  34107. data.setItemLayout(idx, point);
  34108. }
  34109. MarkerView.extend({
  34110. type: 'markLine',
  34111. updateLayout: function (markLineModel, ecModel, api) {
  34112. ecModel.eachSeries(function (seriesModel) {
  34113. var mlModel = seriesModel.markLineModel;
  34114. if (mlModel) {
  34115. var mlData = mlModel.getData();
  34116. var fromData = mlModel.__from;
  34117. var toData = mlModel.__to;
  34118. // Update visual and layout of from symbol and to symbol
  34119. fromData.each(function (idx) {
  34120. updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  34121. updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  34122. });
  34123. // Update layout of line
  34124. mlData.each(function (idx) {
  34125. mlData.setItemLayout(idx, [
  34126. fromData.getItemLayout(idx),
  34127. toData.getItemLayout(idx)
  34128. ]);
  34129. });
  34130. this.markerGroupMap.get(seriesModel.id).updateLayout();
  34131. }
  34132. }, this);
  34133. },
  34134. renderSeries: function (seriesModel, mlModel, ecModel, api) {
  34135. var coordSys = seriesModel.coordinateSystem;
  34136. var seriesId = seriesModel.id;
  34137. var seriesData = seriesModel.getData();
  34138. var lineDrawMap = this.markerGroupMap;
  34139. var lineDraw = lineDrawMap.get(seriesId)
  34140. || lineDrawMap.set(seriesId, new LineDraw());
  34141. this.group.add(lineDraw.group);
  34142. var mlData = createList$2(coordSys, seriesModel, mlModel);
  34143. var fromData = mlData.from;
  34144. var toData = mlData.to;
  34145. var lineData = mlData.line;
  34146. mlModel.__from = fromData;
  34147. mlModel.__to = toData;
  34148. // Line data for tooltip and formatter
  34149. mlModel.setData(lineData);
  34150. var symbolType = mlModel.get('symbol');
  34151. var symbolSize = mlModel.get('symbolSize');
  34152. if (!isArray(symbolType)) {
  34153. symbolType = [symbolType, symbolType];
  34154. }
  34155. if (typeof symbolSize === 'number') {
  34156. symbolSize = [symbolSize, symbolSize];
  34157. }
  34158. // Update visual and layout of from symbol and to symbol
  34159. mlData.from.each(function (idx) {
  34160. updateDataVisualAndLayout(fromData, idx, true);
  34161. updateDataVisualAndLayout(toData, idx, false);
  34162. });
  34163. // Update visual and layout of line
  34164. lineData.each(function (idx) {
  34165. var lineColor = lineData.getItemModel(idx).get('lineStyle.normal.color');
  34166. lineData.setItemVisual(idx, {
  34167. color: lineColor || fromData.getItemVisual(idx, 'color')
  34168. });
  34169. lineData.setItemLayout(idx, [
  34170. fromData.getItemLayout(idx),
  34171. toData.getItemLayout(idx)
  34172. ]);
  34173. lineData.setItemVisual(idx, {
  34174. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  34175. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  34176. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  34177. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  34178. });
  34179. });
  34180. lineDraw.updateData(lineData);
  34181. // Set host model for tooltip
  34182. // FIXME
  34183. mlData.line.eachItemGraphicEl(function (el, idx) {
  34184. el.traverse(function (child) {
  34185. child.dataModel = mlModel;
  34186. });
  34187. });
  34188. function updateDataVisualAndLayout(data, idx, isFrom) {
  34189. var itemModel = data.getItemModel(idx);
  34190. updateSingleMarkerEndLayout(
  34191. data, idx, isFrom, seriesModel, api
  34192. );
  34193. data.setItemVisual(idx, {
  34194. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  34195. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  34196. color: itemModel.get('itemStyle.normal.color') || seriesData.getVisual('color')
  34197. });
  34198. }
  34199. lineDraw.__keep = true;
  34200. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  34201. }
  34202. });
  34203. /**
  34204. * @inner
  34205. * @param {module:echarts/coord/*} coordSys
  34206. * @param {module:echarts/model/Series} seriesModel
  34207. * @param {module:echarts/model/Model} mpModel
  34208. */
  34209. function createList$2(coordSys, seriesModel, mlModel) {
  34210. var coordDimsInfos;
  34211. if (coordSys) {
  34212. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  34213. var info = seriesModel.getData().getDimensionInfo(
  34214. seriesModel.coordDimToDataDim(coordDim)[0]
  34215. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  34216. info.name = coordDim;
  34217. return info;
  34218. });
  34219. }
  34220. else {
  34221. coordDimsInfos =[{
  34222. name: 'value',
  34223. type: 'float'
  34224. }];
  34225. }
  34226. var fromData = new List(coordDimsInfos, mlModel);
  34227. var toData = new List(coordDimsInfos, mlModel);
  34228. // No dimensions
  34229. var lineData = new List([], mlModel);
  34230. var optData = map(mlModel.get('data'), curry(
  34231. markLineTransform, seriesModel, coordSys, mlModel
  34232. ));
  34233. if (coordSys) {
  34234. optData = filter(
  34235. optData, curry(markLineFilter, coordSys)
  34236. );
  34237. }
  34238. var dimValueGetter$$1 = coordSys ? dimValueGetter : function (item) {
  34239. return item.value;
  34240. };
  34241. fromData.initData(
  34242. map(optData, function (item) { return item[0]; }),
  34243. null, dimValueGetter$$1
  34244. );
  34245. toData.initData(
  34246. map(optData, function (item) { return item[1]; }),
  34247. null, dimValueGetter$$1
  34248. );
  34249. lineData.initData(
  34250. map(optData, function (item) { return item[2]; })
  34251. );
  34252. lineData.hasItemOption = true;
  34253. return {
  34254. from: fromData,
  34255. to: toData,
  34256. line: lineData
  34257. };
  34258. }
  34259. registerPreprocessor(function (opt) {
  34260. // Make sure markLine component is enabled
  34261. opt.markLine = opt.markLine || {};
  34262. });
  34263. MarkerModel.extend({
  34264. type: 'markArea',
  34265. defaultOption: {
  34266. zlevel: 0,
  34267. // PENDING
  34268. z: 1,
  34269. tooltip: {
  34270. trigger: 'item'
  34271. },
  34272. // markArea should fixed on the coordinate system
  34273. animation: false,
  34274. label: {
  34275. normal: {
  34276. show: true,
  34277. position: 'top'
  34278. },
  34279. emphasis: {
  34280. show: true,
  34281. position: 'top'
  34282. }
  34283. },
  34284. itemStyle: {
  34285. normal: {
  34286. // color and borderColor default to use color from series
  34287. // color: 'auto'
  34288. // borderColor: 'auto'
  34289. borderWidth: 0
  34290. }
  34291. }
  34292. }
  34293. });
  34294. // TODO Better on polar
  34295. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  34296. var lt = dataTransform(seriesModel, item[0]);
  34297. var rb = dataTransform(seriesModel, item[1]);
  34298. var retrieve$$1 = retrieve;
  34299. // FIXME make sure lt is less than rb
  34300. var ltCoord = lt.coord;
  34301. var rbCoord = rb.coord;
  34302. ltCoord[0] = retrieve$$1(ltCoord[0], -Infinity);
  34303. ltCoord[1] = retrieve$$1(ltCoord[1], -Infinity);
  34304. rbCoord[0] = retrieve$$1(rbCoord[0], Infinity);
  34305. rbCoord[1] = retrieve$$1(rbCoord[1], Infinity);
  34306. // Merge option into one
  34307. var result = mergeAll([{}, lt, rb]);
  34308. result.coord = [
  34309. lt.coord, rb.coord
  34310. ];
  34311. result.x0 = lt.x;
  34312. result.y0 = lt.y;
  34313. result.x1 = rb.x;
  34314. result.y1 = rb.y;
  34315. return result;
  34316. };
  34317. function isInifinity$1(val) {
  34318. return !isNaN(val) && !isFinite(val);
  34319. }
  34320. // If a markArea has one dim
  34321. function ifMarkLineHasOnlyDim$1(dimIndex, fromCoord, toCoord, coordSys) {
  34322. var otherDimIndex = 1 - dimIndex;
  34323. return isInifinity$1(fromCoord[otherDimIndex]) && isInifinity$1(toCoord[otherDimIndex]);
  34324. }
  34325. function markAreaFilter(coordSys, item) {
  34326. var fromCoord = item.coord[0];
  34327. var toCoord = item.coord[1];
  34328. if (coordSys.type === 'cartesian2d') {
  34329. // In case
  34330. // {
  34331. // markArea: {
  34332. // data: [{ yAxis: 2 }]
  34333. // }
  34334. // }
  34335. if (
  34336. fromCoord && toCoord &&
  34337. (ifMarkLineHasOnlyDim$1(1, fromCoord, toCoord, coordSys)
  34338. || ifMarkLineHasOnlyDim$1(0, fromCoord, toCoord, coordSys))
  34339. ) {
  34340. return true;
  34341. }
  34342. }
  34343. return dataFilter$1(coordSys, {
  34344. coord: fromCoord,
  34345. x: item.x0,
  34346. y: item.y0
  34347. })
  34348. || dataFilter$1(coordSys, {
  34349. coord: toCoord,
  34350. x: item.x1,
  34351. y: item.y1
  34352. });
  34353. }
  34354. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  34355. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  34356. var coordSys = seriesModel.coordinateSystem;
  34357. var itemModel = data.getItemModel(idx);
  34358. var point;
  34359. var xPx = parsePercent$1(itemModel.get(dims[0]), api.getWidth());
  34360. var yPx = parsePercent$1(itemModel.get(dims[1]), api.getHeight());
  34361. if (!isNaN(xPx) && !isNaN(yPx)) {
  34362. point = [xPx, yPx];
  34363. }
  34364. else {
  34365. // Chart like bar may have there own marker positioning logic
  34366. if (seriesModel.getMarkerPosition) {
  34367. // Use the getMarkerPoisition
  34368. point = seriesModel.getMarkerPosition(
  34369. data.getValues(dims, idx)
  34370. );
  34371. }
  34372. else {
  34373. var x = data.get(dims[0], idx);
  34374. var y = data.get(dims[1], idx);
  34375. point = coordSys.dataToPoint([x, y], true);
  34376. }
  34377. if (coordSys.type === 'cartesian2d') {
  34378. var xAxis = coordSys.getAxis('x');
  34379. var yAxis = coordSys.getAxis('y');
  34380. var x = data.get(dims[0], idx);
  34381. var y = data.get(dims[1], idx);
  34382. if (isInifinity$1(x)) {
  34383. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  34384. }
  34385. else if (isInifinity$1(y)) {
  34386. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  34387. }
  34388. }
  34389. // Use x, y if has any
  34390. if (!isNaN(xPx)) {
  34391. point[0] = xPx;
  34392. }
  34393. if (!isNaN(yPx)) {
  34394. point[1] = yPx;
  34395. }
  34396. }
  34397. return point;
  34398. }
  34399. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  34400. MarkerView.extend({
  34401. type: 'markArea',
  34402. updateLayout: function (markAreaModel, ecModel, api) {
  34403. ecModel.eachSeries(function (seriesModel) {
  34404. var maModel = seriesModel.markAreaModel;
  34405. if (maModel) {
  34406. var areaData = maModel.getData();
  34407. areaData.each(function (idx) {
  34408. var points = map(dimPermutations, function (dim) {
  34409. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  34410. });
  34411. // Layout
  34412. areaData.setItemLayout(idx, points);
  34413. var el = areaData.getItemGraphicEl(idx);
  34414. el.setShape('points', points);
  34415. });
  34416. }
  34417. }, this);
  34418. },
  34419. renderSeries: function (seriesModel, maModel, ecModel, api) {
  34420. var coordSys = seriesModel.coordinateSystem;
  34421. var seriesName = seriesModel.name;
  34422. var seriesData = seriesModel.getData();
  34423. var areaGroupMap = this.markerGroupMap;
  34424. var polygonGroup = areaGroupMap.get(seriesName)
  34425. || areaGroupMap.set(seriesName, {group: new Group()});
  34426. this.group.add(polygonGroup.group);
  34427. polygonGroup.__keep = true;
  34428. var areaData = createList$3(coordSys, seriesModel, maModel);
  34429. // Line data for tooltip and formatter
  34430. maModel.setData(areaData);
  34431. // Update visual and layout of line
  34432. areaData.each(function (idx) {
  34433. // Layout
  34434. areaData.setItemLayout(idx, map(dimPermutations, function (dim) {
  34435. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  34436. }));
  34437. // Visual
  34438. areaData.setItemVisual(idx, {
  34439. color: seriesData.getVisual('color')
  34440. });
  34441. });
  34442. areaData.diff(polygonGroup.__data)
  34443. .add(function (idx) {
  34444. var polygon = new Polygon({
  34445. shape: {
  34446. points: areaData.getItemLayout(idx)
  34447. }
  34448. });
  34449. areaData.setItemGraphicEl(idx, polygon);
  34450. polygonGroup.group.add(polygon);
  34451. })
  34452. .update(function (newIdx, oldIdx) {
  34453. var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
  34454. updateProps(polygon, {
  34455. shape: {
  34456. points: areaData.getItemLayout(newIdx)
  34457. }
  34458. }, maModel, newIdx);
  34459. polygonGroup.group.add(polygon);
  34460. areaData.setItemGraphicEl(newIdx, polygon);
  34461. })
  34462. .remove(function (idx) {
  34463. var polygon = polygonGroup.__data.getItemGraphicEl(idx);
  34464. polygonGroup.group.remove(polygon);
  34465. })
  34466. .execute();
  34467. areaData.eachItemGraphicEl(function (polygon, idx) {
  34468. var itemModel = areaData.getItemModel(idx);
  34469. var labelModel = itemModel.getModel('label.normal');
  34470. var labelHoverModel = itemModel.getModel('label.emphasis');
  34471. var color = areaData.getItemVisual(idx, 'color');
  34472. polygon.useStyle(
  34473. defaults(
  34474. itemModel.getModel('itemStyle.normal').getItemStyle(),
  34475. {
  34476. fill: modifyAlpha(color, 0.4),
  34477. stroke: color
  34478. }
  34479. )
  34480. );
  34481. polygon.hoverStyle = itemModel.getModel('itemStyle.emphasis').getItemStyle();
  34482. setLabelStyle(
  34483. polygon.style, polygon.hoverStyle, labelModel, labelHoverModel,
  34484. {
  34485. labelFetcher: maModel,
  34486. labelDataIndex: idx,
  34487. defaultText: areaData.getName(idx) || '',
  34488. isRectText: true,
  34489. autoColor: color
  34490. }
  34491. );
  34492. setHoverStyle(polygon, {});
  34493. polygon.dataModel = maModel;
  34494. });
  34495. polygonGroup.__data = areaData;
  34496. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  34497. }
  34498. });
  34499. /**
  34500. * @inner
  34501. * @param {module:echarts/coord/*} coordSys
  34502. * @param {module:echarts/model/Series} seriesModel
  34503. * @param {module:echarts/model/Model} mpModel
  34504. */
  34505. function createList$3(coordSys, seriesModel, maModel) {
  34506. var coordDimsInfos;
  34507. var areaData;
  34508. var dims = ['x0', 'y0', 'x1', 'y1'];
  34509. if (coordSys) {
  34510. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  34511. var info = seriesModel.getData().getDimensionInfo(
  34512. seriesModel.coordDimToDataDim(coordDim)[0]
  34513. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  34514. info.name = coordDim;
  34515. return info;
  34516. });
  34517. areaData = new List(map(dims, function (dim, idx) {
  34518. return {
  34519. name: dim,
  34520. type: coordDimsInfos[idx % 2].type
  34521. };
  34522. }), maModel);
  34523. }
  34524. else {
  34525. coordDimsInfos =[{
  34526. name: 'value',
  34527. type: 'float'
  34528. }];
  34529. areaData = new List(coordDimsInfos, maModel);
  34530. }
  34531. var optData = map(maModel.get('data'), curry(
  34532. markAreaTransform, seriesModel, coordSys, maModel
  34533. ));
  34534. if (coordSys) {
  34535. optData = filter(
  34536. optData, curry(markAreaFilter, coordSys)
  34537. );
  34538. }
  34539. var dimValueGetter$$1 = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  34540. return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  34541. } : function (item) {
  34542. return item.value;
  34543. };
  34544. areaData.initData(optData, null, dimValueGetter$$1);
  34545. areaData.hasItemOption = true;
  34546. return areaData;
  34547. }
  34548. registerPreprocessor(function (opt) {
  34549. // Make sure markArea component is enabled
  34550. opt.markArea = opt.markArea || {};
  34551. });
  34552. ComponentModel.registerSubTypeDefaulter('dataZoom', function () {
  34553. // Default 'slider' when no type specified.
  34554. return 'slider';
  34555. });
  34556. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single'];
  34557. // Supported coords.
  34558. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  34559. /**
  34560. * @param {string} coordType
  34561. * @return {boolean}
  34562. */
  34563. function isCoordSupported(coordType) {
  34564. return indexOf(COORDS, coordType) >= 0;
  34565. }
  34566. /**
  34567. * Create "each" method to iterate names.
  34568. *
  34569. * @pubilc
  34570. * @param {Array.<string>} names
  34571. * @param {Array.<string>=} attrs
  34572. * @return {Function}
  34573. */
  34574. function createNameEach(names, attrs) {
  34575. names = names.slice();
  34576. var capitalNames = map(names, capitalFirst);
  34577. attrs = (attrs || []).slice();
  34578. var capitalAttrs = map(attrs, capitalFirst);
  34579. return function (callback, context) {
  34580. each$1(names, function (name, index) {
  34581. var nameObj = {name: name, capital: capitalNames[index]};
  34582. for (var j = 0; j < attrs.length; j++) {
  34583. nameObj[attrs[j]] = name + capitalAttrs[j];
  34584. }
  34585. callback.call(context, nameObj);
  34586. });
  34587. };
  34588. }
  34589. /**
  34590. * Iterate each dimension name.
  34591. *
  34592. * @public
  34593. * @param {Function} callback The parameter is like:
  34594. * {
  34595. * name: 'angle',
  34596. * capital: 'Angle',
  34597. * axis: 'angleAxis',
  34598. * axisIndex: 'angleAixs',
  34599. * index: 'angleIndex'
  34600. * }
  34601. * @param {Object} context
  34602. */
  34603. var eachAxisDim$1 = createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  34604. /**
  34605. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  34606. * dataZoomModels and 'links' make up one or more graphics.
  34607. * This function finds the graphic where the source dataZoomModel is in.
  34608. *
  34609. * @public
  34610. * @param {Function} forEachNode Node iterator.
  34611. * @param {Function} forEachEdgeType edgeType iterator
  34612. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  34613. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  34614. */
  34615. function createLinkedNodesFinder(forEachNode, forEachEdgeType, edgeIdGetter) {
  34616. return function (sourceNode) {
  34617. var result = {
  34618. nodes: [],
  34619. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  34620. };
  34621. forEachEdgeType(function (edgeType) {
  34622. result.records[edgeType.name] = {};
  34623. });
  34624. if (!sourceNode) {
  34625. return result;
  34626. }
  34627. absorb(sourceNode, result);
  34628. var existsLink;
  34629. do {
  34630. existsLink = false;
  34631. forEachNode(processSingleNode);
  34632. }
  34633. while (existsLink);
  34634. function processSingleNode(node) {
  34635. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  34636. absorb(node, result);
  34637. existsLink = true;
  34638. }
  34639. }
  34640. return result;
  34641. };
  34642. function isNodeAbsorded(node, result) {
  34643. return indexOf(result.nodes, node) >= 0;
  34644. }
  34645. function isLinked(node, result) {
  34646. var hasLink = false;
  34647. forEachEdgeType(function (edgeType) {
  34648. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  34649. result.records[edgeType.name][edgeId] && (hasLink = true);
  34650. });
  34651. });
  34652. return hasLink;
  34653. }
  34654. function absorb(node, result) {
  34655. result.nodes.push(node);
  34656. forEachEdgeType(function (edgeType) {
  34657. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  34658. result.records[edgeType.name][edgeId] = true;
  34659. });
  34660. });
  34661. }
  34662. }
  34663. var each$16 = each$1;
  34664. var asc$1 = asc;
  34665. /**
  34666. * Operate single axis.
  34667. * One axis can only operated by one axis operator.
  34668. * Different dataZoomModels may be defined to operate the same axis.
  34669. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  34670. * So dataZoomModels share one axisProxy in that case.
  34671. *
  34672. * @class
  34673. */
  34674. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  34675. /**
  34676. * @private
  34677. * @type {string}
  34678. */
  34679. this._dimName = dimName;
  34680. /**
  34681. * @private
  34682. */
  34683. this._axisIndex = axisIndex;
  34684. /**
  34685. * @private
  34686. * @type {Array.<number>}
  34687. */
  34688. this._valueWindow;
  34689. /**
  34690. * @private
  34691. * @type {Array.<number>}
  34692. */
  34693. this._percentWindow;
  34694. /**
  34695. * @private
  34696. * @type {Array.<number>}
  34697. */
  34698. this._dataExtent;
  34699. /**
  34700. * {minSpan, maxSpan, minValueSpan, maxValueSpan}
  34701. * @private
  34702. * @type {Object}
  34703. */
  34704. this._minMaxSpan;
  34705. /**
  34706. * @readOnly
  34707. * @type {module: echarts/model/Global}
  34708. */
  34709. this.ecModel = ecModel;
  34710. /**
  34711. * @private
  34712. * @type {module: echarts/component/dataZoom/DataZoomModel}
  34713. */
  34714. this._dataZoomModel = dataZoomModel;
  34715. };
  34716. AxisProxy.prototype = {
  34717. constructor: AxisProxy,
  34718. /**
  34719. * Whether the axisProxy is hosted by dataZoomModel.
  34720. *
  34721. * @public
  34722. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  34723. * @return {boolean}
  34724. */
  34725. hostedBy: function (dataZoomModel) {
  34726. return this._dataZoomModel === dataZoomModel;
  34727. },
  34728. /**
  34729. * @return {Array.<number>} Value can only be NaN or finite value.
  34730. */
  34731. getDataValueWindow: function () {
  34732. return this._valueWindow.slice();
  34733. },
  34734. /**
  34735. * @return {Array.<number>}
  34736. */
  34737. getDataPercentWindow: function () {
  34738. return this._percentWindow.slice();
  34739. },
  34740. /**
  34741. * @public
  34742. * @param {number} axisIndex
  34743. * @return {Array} seriesModels
  34744. */
  34745. getTargetSeriesModels: function () {
  34746. var seriesModels = [];
  34747. var ecModel = this.ecModel;
  34748. ecModel.eachSeries(function (seriesModel) {
  34749. if (isCoordSupported(seriesModel.get('coordinateSystem'))) {
  34750. var dimName = this._dimName;
  34751. var axisModel = ecModel.queryComponents({
  34752. mainType: dimName + 'Axis',
  34753. index: seriesModel.get(dimName + 'AxisIndex'),
  34754. id: seriesModel.get(dimName + 'AxisId')
  34755. })[0];
  34756. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  34757. seriesModels.push(seriesModel);
  34758. }
  34759. }
  34760. }, this);
  34761. return seriesModels;
  34762. },
  34763. getAxisModel: function () {
  34764. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  34765. },
  34766. getOtherAxisModel: function () {
  34767. var axisDim = this._dimName;
  34768. var ecModel = this.ecModel;
  34769. var axisModel = this.getAxisModel();
  34770. var isCartesian = axisDim === 'x' || axisDim === 'y';
  34771. var otherAxisDim;
  34772. var coordSysIndexName;
  34773. if (isCartesian) {
  34774. coordSysIndexName = 'gridIndex';
  34775. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  34776. }
  34777. else {
  34778. coordSysIndexName = 'polarIndex';
  34779. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  34780. }
  34781. var foundOtherAxisModel;
  34782. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  34783. if ((otherAxisModel.get(coordSysIndexName) || 0)
  34784. === (axisModel.get(coordSysIndexName) || 0)
  34785. ) {
  34786. foundOtherAxisModel = otherAxisModel;
  34787. }
  34788. });
  34789. return foundOtherAxisModel;
  34790. },
  34791. getMinMaxSpan: function () {
  34792. return clone(this._minMaxSpan);
  34793. },
  34794. /**
  34795. * Only calculate by given range and this._dataExtent, do not change anything.
  34796. *
  34797. * @param {Object} opt
  34798. * @param {number} [opt.start]
  34799. * @param {number} [opt.end]
  34800. * @param {number} [opt.startValue]
  34801. * @param {number} [opt.endValue]
  34802. */
  34803. calculateDataWindow: function (opt) {
  34804. var dataExtent = this._dataExtent;
  34805. var axisModel = this.getAxisModel();
  34806. var scale = axisModel.axis.scale;
  34807. var rangePropMode = this._dataZoomModel.getRangePropMode();
  34808. var percentExtent = [0, 100];
  34809. var percentWindow = [
  34810. opt.start,
  34811. opt.end
  34812. ];
  34813. var valueWindow = [];
  34814. each$16(['startValue', 'endValue'], function (prop) {
  34815. valueWindow.push(opt[prop] != null ? scale.parse(opt[prop]) : null);
  34816. });
  34817. // Normalize bound.
  34818. each$16([0, 1], function (idx) {
  34819. var boundValue = valueWindow[idx];
  34820. var boundPercent = percentWindow[idx];
  34821. // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  34822. // on `valueProp` ('startValue', 'endValue'). The former one is suitable
  34823. // for cases that a dataZoom component controls multiple axes with different
  34824. // unit or extent, and the latter one is suitable for accurate zoom by pixel
  34825. // (e.g., in dataZoomSelect). `valueProp` can be calculated from `percentProp`,
  34826. // but it is awkward that `percentProp` can not be obtained from `valueProp`
  34827. // accurately (because all of values that are overflow the `dataExtent` will
  34828. // be calculated to percent '100%'). So we have to use
  34829. // `dataZoom.getRangePropMode()` to mark which prop is used.
  34830. // `rangePropMode` is updated only when setOption or dispatchAction, otherwise
  34831. // it remains its original value.
  34832. if (rangePropMode[idx] === 'percent') {
  34833. if (boundPercent == null) {
  34834. boundPercent = percentExtent[idx];
  34835. }
  34836. // Use scale.parse to math round for category or time axis.
  34837. boundValue = scale.parse(linearMap(
  34838. boundPercent, percentExtent, dataExtent, true
  34839. ));
  34840. }
  34841. else {
  34842. // Calculating `percent` from `value` may be not accurate, because
  34843. // This calculation can not be inversed, because all of values that
  34844. // are overflow the `dataExtent` will be calculated to percent '100%'
  34845. boundPercent = linearMap(
  34846. boundValue, dataExtent, percentExtent, true
  34847. );
  34848. }
  34849. // valueWindow[idx] = round(boundValue);
  34850. // percentWindow[idx] = round(boundPercent);
  34851. valueWindow[idx] = boundValue;
  34852. percentWindow[idx] = boundPercent;
  34853. });
  34854. return {
  34855. valueWindow: asc$1(valueWindow),
  34856. percentWindow: asc$1(percentWindow)
  34857. };
  34858. },
  34859. /**
  34860. * Notice: reset should not be called before series.restoreData() called,
  34861. * so it is recommanded to be called in "process stage" but not "model init
  34862. * stage".
  34863. *
  34864. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  34865. */
  34866. reset: function (dataZoomModel) {
  34867. if (dataZoomModel !== this._dataZoomModel) {
  34868. return;
  34869. }
  34870. // Culculate data window and data extent, and record them.
  34871. this._dataExtent = calculateDataExtent(
  34872. this, this._dimName, this.getTargetSeriesModels()
  34873. );
  34874. var dataWindow = this.calculateDataWindow(dataZoomModel.option);
  34875. this._valueWindow = dataWindow.valueWindow;
  34876. this._percentWindow = dataWindow.percentWindow;
  34877. setMinMaxSpan(this);
  34878. // Update axis setting then.
  34879. setAxisModel(this);
  34880. },
  34881. /**
  34882. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  34883. */
  34884. restore: function (dataZoomModel) {
  34885. if (dataZoomModel !== this._dataZoomModel) {
  34886. return;
  34887. }
  34888. this._valueWindow = this._percentWindow = null;
  34889. setAxisModel(this, true);
  34890. },
  34891. /**
  34892. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  34893. */
  34894. filterData: function (dataZoomModel) {
  34895. if (dataZoomModel !== this._dataZoomModel) {
  34896. return;
  34897. }
  34898. var axisDim = this._dimName;
  34899. var seriesModels = this.getTargetSeriesModels();
  34900. var filterMode = dataZoomModel.get('filterMode');
  34901. var valueWindow = this._valueWindow;
  34902. if (filterMode === 'none') {
  34903. return;
  34904. }
  34905. // FIXME
  34906. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  34907. // with NaN data, NaN will be filtered and stack will be wrong.
  34908. // So we need to force the mode to be set empty.
  34909. // In fect, it is not a big deal that do not support filterMode-'filter'
  34910. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  34911. // selection" some day, which might need "adapt to data extent on the
  34912. // otherAxis", which is disabled by filterMode-'empty'.
  34913. var otherAxisModel = this.getOtherAxisModel();
  34914. if (dataZoomModel.get('$fromToolbox')
  34915. && otherAxisModel
  34916. && otherAxisModel.get('type') === 'category'
  34917. ) {
  34918. filterMode = 'empty';
  34919. }
  34920. // Process series data
  34921. each$16(seriesModels, function (seriesModel) {
  34922. var seriesData = seriesModel.getData();
  34923. var dataDims = seriesModel.coordDimToDataDim(axisDim);
  34924. if (filterMode === 'weakFilter') {
  34925. seriesData && seriesData.filterSelf(function (dataIndex) {
  34926. var leftOut;
  34927. var rightOut;
  34928. var hasValue;
  34929. for (var i = 0; i < dataDims.length; i++) {
  34930. var value = seriesData.get(dataDims[i], dataIndex);
  34931. var thisHasValue = !isNaN(value);
  34932. var thisLeftOut = value < valueWindow[0];
  34933. var thisRightOut = value > valueWindow[1];
  34934. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  34935. return true;
  34936. }
  34937. thisHasValue && (hasValue = true);
  34938. thisLeftOut && (leftOut = true);
  34939. thisRightOut && (rightOut = true);
  34940. }
  34941. // If both left out and right out, do not filter.
  34942. return hasValue && leftOut && rightOut;
  34943. });
  34944. }
  34945. else {
  34946. seriesData && each$16(dataDims, function (dim) {
  34947. if (filterMode === 'empty') {
  34948. seriesModel.setData(
  34949. seriesData.map(dim, function (value) {
  34950. return !isInWindow(value) ? NaN : value;
  34951. })
  34952. );
  34953. }
  34954. else {
  34955. seriesData.filterSelf(dim, isInWindow);
  34956. }
  34957. });
  34958. }
  34959. });
  34960. function isInWindow(value) {
  34961. return value >= valueWindow[0] && value <= valueWindow[1];
  34962. }
  34963. }
  34964. };
  34965. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  34966. var dataExtent = [Infinity, -Infinity];
  34967. each$16(seriesModels, function (seriesModel) {
  34968. var seriesData = seriesModel.getData();
  34969. if (seriesData) {
  34970. each$16(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  34971. var seriesExtent = seriesData.getDataExtent(dim);
  34972. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  34973. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  34974. });
  34975. }
  34976. });
  34977. if (dataExtent[1] < dataExtent[0]) {
  34978. dataExtent = [NaN, NaN];
  34979. }
  34980. // It is important to get "consistent" extent when more then one axes is
  34981. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  34982. // when zooming. But it is difficult to know what is "consistent", considering
  34983. // axes have different type or even different meanings (For example, two
  34984. // time axes are used to compare data of the same date in different years).
  34985. // So basically dataZoom just obtains extent by series.data (in category axis
  34986. // extent can be obtained from axis.data).
  34987. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  34988. // consistent.
  34989. fixExtentByAxis(axisProxy, dataExtent);
  34990. return dataExtent;
  34991. }
  34992. function fixExtentByAxis(axisProxy, dataExtent) {
  34993. var axisModel = axisProxy.getAxisModel();
  34994. var min = axisModel.getMin(true);
  34995. // For category axis, if min/max/scale are not set, extent is determined
  34996. // by axis.data by default.
  34997. var isCategoryAxis = axisModel.get('type') === 'category';
  34998. var axisDataLen = isCategoryAxis && (axisModel.get('data') || []).length;
  34999. if (min != null && min !== 'dataMin' && typeof min !== 'function') {
  35000. dataExtent[0] = min;
  35001. }
  35002. else if (isCategoryAxis) {
  35003. dataExtent[0] = axisDataLen > 0 ? 0 : NaN;
  35004. }
  35005. var max = axisModel.getMax(true);
  35006. if (max != null && max !== 'dataMax' && typeof max !== 'function') {
  35007. dataExtent[1] = max;
  35008. }
  35009. else if (isCategoryAxis) {
  35010. dataExtent[1] = axisDataLen > 0 ? axisDataLen - 1 : NaN;
  35011. }
  35012. if (!axisModel.get('scale', true)) {
  35013. dataExtent[0] > 0 && (dataExtent[0] = 0);
  35014. dataExtent[1] < 0 && (dataExtent[1] = 0);
  35015. }
  35016. // For value axis, if min/max/scale are not set, we just use the extent obtained
  35017. // by series data, which may be a little different from the extent calculated by
  35018. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  35019. // little when zooming. So it will not be fixed until some users require it strongly.
  35020. return dataExtent;
  35021. }
  35022. function setAxisModel(axisProxy, isRestore) {
  35023. var axisModel = axisProxy.getAxisModel();
  35024. var percentWindow = axisProxy._percentWindow;
  35025. var valueWindow = axisProxy._valueWindow;
  35026. if (!percentWindow) {
  35027. return;
  35028. }
  35029. // [0, 500]: arbitrary value, guess axis extent.
  35030. var precision = getPixelPrecision(valueWindow, [0, 500]);
  35031. precision = Math.min(precision, 20);
  35032. // isRestore or isFull
  35033. var useOrigin = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  35034. axisModel.setRange(
  35035. useOrigin ? null : +valueWindow[0].toFixed(precision),
  35036. useOrigin ? null : +valueWindow[1].toFixed(precision)
  35037. );
  35038. }
  35039. function setMinMaxSpan(axisProxy) {
  35040. var minMaxSpan = axisProxy._minMaxSpan = {};
  35041. var dataZoomModel = axisProxy._dataZoomModel;
  35042. each$16(['min', 'max'], function (minMax) {
  35043. minMaxSpan[minMax + 'Span'] = dataZoomModel.get(minMax + 'Span');
  35044. // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  35045. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  35046. if (valueSpan != null) {
  35047. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  35048. valueSpan = axisProxy.getAxisModel().axis.scale.parse(valueSpan);
  35049. if (valueSpan != null) {
  35050. var dataExtent = axisProxy._dataExtent;
  35051. minMaxSpan[minMax + 'Span'] = linearMap(
  35052. dataExtent[0] + valueSpan, dataExtent, [0, 100], true
  35053. );
  35054. }
  35055. }
  35056. });
  35057. }
  35058. var each$15 = each$1;
  35059. var eachAxisDim = eachAxisDim$1;
  35060. var DataZoomModel = extendComponentModel({
  35061. type: 'dataZoom',
  35062. dependencies: [
  35063. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'
  35064. ],
  35065. /**
  35066. * @protected
  35067. */
  35068. defaultOption: {
  35069. zlevel: 0,
  35070. z: 4, // Higher than normal component (z: 2).
  35071. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  35072. xAxisIndex: null, // Default the first horizontal category axis.
  35073. yAxisIndex: null, // Default the first vertical category axis.
  35074. filterMode: 'filter', // Possible values: 'filter' or 'empty' or 'weakFilter'.
  35075. // 'filter': data items which are out of window will be removed. This option is
  35076. // applicable when filtering outliers. For each data item, it will be
  35077. // filtered if one of the relevant dimensions is out of the window.
  35078. // 'weakFilter': data items which are out of window will be removed. This option
  35079. // is applicable when filtering outliers. For each data item, it will be
  35080. // filtered only if all of the relevant dimensions are out of the same
  35081. // side of the window.
  35082. // 'empty': data items which are out of window will be set to empty.
  35083. // This option is applicable when user should not neglect
  35084. // that there are some data items out of window.
  35085. // 'none': Do not filter.
  35086. // Taking line chart as an example, line will be broken in
  35087. // the filtered points when filterModel is set to 'empty', but
  35088. // be connected when set to 'filter'.
  35089. throttle: null, // Dispatch action by the fixed rate, avoid frequency.
  35090. // default 100. Do not throttle when use null/undefined.
  35091. // If animation === true and animationDurationUpdate > 0,
  35092. // default value is 100, otherwise 20.
  35093. start: 0, // Start percent. 0 ~ 100
  35094. end: 100, // End percent. 0 ~ 100
  35095. startValue: null, // Start value. If startValue specified, start is ignored.
  35096. endValue: null, // End value. If endValue specified, end is ignored.
  35097. minSpan: null, // 0 ~ 100
  35098. maxSpan: null, // 0 ~ 100
  35099. minValueSpan: null, // The range of dataZoom can not be smaller than that.
  35100. maxValueSpan: null, // The range of dataZoom can not be larger than that.
  35101. rangeMode: null // Array, can be 'value' or 'percent'.
  35102. },
  35103. /**
  35104. * @override
  35105. */
  35106. init: function (option, parentModel, ecModel) {
  35107. /**
  35108. * key like x_0, y_1
  35109. * @private
  35110. * @type {Object}
  35111. */
  35112. this._dataIntervalByAxis = {};
  35113. /**
  35114. * @private
  35115. */
  35116. this._dataInfo = {};
  35117. /**
  35118. * key like x_0, y_1
  35119. * @private
  35120. */
  35121. this._axisProxies = {};
  35122. /**
  35123. * @readOnly
  35124. */
  35125. this.textStyleModel;
  35126. /**
  35127. * @private
  35128. */
  35129. this._autoThrottle = true;
  35130. /**
  35131. * 'percent' or 'value'
  35132. * @private
  35133. */
  35134. this._rangePropMode = ['percent', 'percent'];
  35135. var rawOption = retrieveRaw(option);
  35136. this.mergeDefaultAndTheme(option, ecModel);
  35137. this.doInit(rawOption);
  35138. },
  35139. /**
  35140. * @override
  35141. */
  35142. mergeOption: function (newOption) {
  35143. var rawOption = retrieveRaw(newOption);
  35144. //FIX #2591
  35145. merge(this.option, newOption, true);
  35146. this.doInit(rawOption);
  35147. },
  35148. /**
  35149. * @protected
  35150. */
  35151. doInit: function (rawOption) {
  35152. var thisOption = this.option;
  35153. // Disable realtime view update if canvas is not supported.
  35154. if (!env$1.canvasSupported) {
  35155. thisOption.realtime = false;
  35156. }
  35157. this._setDefaultThrottle(rawOption);
  35158. updateRangeUse(this, rawOption);
  35159. each$15([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  35160. // start/end has higher priority over startValue/endValue if they
  35161. // both set, but we should make chart.setOption({endValue: 1000})
  35162. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  35163. if (this._rangePropMode[index] === 'value') {
  35164. thisOption[names[0]] = null;
  35165. }
  35166. // Otherwise do nothing and use the merge result.
  35167. }, this);
  35168. this.textStyleModel = this.getModel('textStyle');
  35169. this._resetTarget();
  35170. this._giveAxisProxies();
  35171. },
  35172. /**
  35173. * @private
  35174. */
  35175. _giveAxisProxies: function () {
  35176. var axisProxies = this._axisProxies;
  35177. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  35178. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  35179. // If exists, share axisProxy with other dataZoomModels.
  35180. var axisProxy = axisModel.__dzAxisProxy || (
  35181. // Use the first dataZoomModel as the main model of axisProxy.
  35182. axisModel.__dzAxisProxy = new AxisProxy(
  35183. dimNames.name, axisIndex, this, ecModel
  35184. )
  35185. );
  35186. // FIXME
  35187. // dispose __dzAxisProxy
  35188. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  35189. }, this);
  35190. },
  35191. /**
  35192. * @private
  35193. */
  35194. _resetTarget: function () {
  35195. var thisOption = this.option;
  35196. var autoMode = this._judgeAutoMode();
  35197. eachAxisDim(function (dimNames) {
  35198. var axisIndexName = dimNames.axisIndex;
  35199. thisOption[axisIndexName] = normalizeToArray(
  35200. thisOption[axisIndexName]
  35201. );
  35202. }, this);
  35203. if (autoMode === 'axisIndex') {
  35204. this._autoSetAxisIndex();
  35205. }
  35206. else if (autoMode === 'orient') {
  35207. this._autoSetOrient();
  35208. }
  35209. },
  35210. /**
  35211. * @private
  35212. */
  35213. _judgeAutoMode: function () {
  35214. // Auto set only works for setOption at the first time.
  35215. // The following is user's reponsibility. So using merged
  35216. // option is OK.
  35217. var thisOption = this.option;
  35218. var hasIndexSpecified = false;
  35219. eachAxisDim(function (dimNames) {
  35220. // When user set axisIndex as a empty array, we think that user specify axisIndex
  35221. // but do not want use auto mode. Because empty array may be encountered when
  35222. // some error occured.
  35223. if (thisOption[dimNames.axisIndex] != null) {
  35224. hasIndexSpecified = true;
  35225. }
  35226. }, this);
  35227. var orient = thisOption.orient;
  35228. if (orient == null && hasIndexSpecified) {
  35229. return 'orient';
  35230. }
  35231. else if (!hasIndexSpecified) {
  35232. if (orient == null) {
  35233. thisOption.orient = 'horizontal';
  35234. }
  35235. return 'axisIndex';
  35236. }
  35237. },
  35238. /**
  35239. * @private
  35240. */
  35241. _autoSetAxisIndex: function () {
  35242. var autoAxisIndex = true;
  35243. var orient = this.get('orient', true);
  35244. var thisOption = this.option;
  35245. var dependentModels = this.dependentModels;
  35246. if (autoAxisIndex) {
  35247. // Find axis that parallel to dataZoom as default.
  35248. var dimName = orient === 'vertical' ? 'y' : 'x';
  35249. if (dependentModels[dimName + 'Axis'].length) {
  35250. thisOption[dimName + 'AxisIndex'] = [0];
  35251. autoAxisIndex = false;
  35252. }
  35253. else {
  35254. each$15(dependentModels.singleAxis, function (singleAxisModel) {
  35255. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  35256. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  35257. autoAxisIndex = false;
  35258. }
  35259. });
  35260. }
  35261. }
  35262. if (autoAxisIndex) {
  35263. // Find the first category axis as default. (consider polar)
  35264. eachAxisDim(function (dimNames) {
  35265. if (!autoAxisIndex) {
  35266. return;
  35267. }
  35268. var axisIndices = [];
  35269. var axisModels = this.dependentModels[dimNames.axis];
  35270. if (axisModels.length && !axisIndices.length) {
  35271. for (var i = 0, len = axisModels.length; i < len; i++) {
  35272. if (axisModels[i].get('type') === 'category') {
  35273. axisIndices.push(i);
  35274. }
  35275. }
  35276. }
  35277. thisOption[dimNames.axisIndex] = axisIndices;
  35278. if (axisIndices.length) {
  35279. autoAxisIndex = false;
  35280. }
  35281. }, this);
  35282. }
  35283. if (autoAxisIndex) {
  35284. // FIXME
  35285. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  35286. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  35287. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  35288. // dataZoom component auto adopts series that reference to
  35289. // both xAxis and yAxis which type is 'value'.
  35290. this.ecModel.eachSeries(function (seriesModel) {
  35291. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  35292. eachAxisDim(function (dimNames) {
  35293. var axisIndices = thisOption[dimNames.axisIndex];
  35294. var axisIndex = seriesModel.get(dimNames.axisIndex);
  35295. var axisId = seriesModel.get(dimNames.axisId);
  35296. var axisModel = seriesModel.ecModel.queryComponents({
  35297. mainType: dimNames.axis,
  35298. index: axisIndex,
  35299. id: axisId
  35300. })[0];
  35301. if (__DEV__) {
  35302. if (!axisModel) {
  35303. throw new Error(
  35304. dimNames.axis + ' "' + retrieve(
  35305. axisIndex,
  35306. axisId,
  35307. 0
  35308. ) + '" not found'
  35309. );
  35310. }
  35311. }
  35312. axisIndex = axisModel.componentIndex;
  35313. if (indexOf(axisIndices, axisIndex) < 0) {
  35314. axisIndices.push(axisIndex);
  35315. }
  35316. });
  35317. }
  35318. }, this);
  35319. }
  35320. },
  35321. /**
  35322. * @private
  35323. */
  35324. _autoSetOrient: function () {
  35325. var dim;
  35326. // Find the first axis
  35327. this.eachTargetAxis(function (dimNames) {
  35328. !dim && (dim = dimNames.name);
  35329. }, this);
  35330. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  35331. },
  35332. /**
  35333. * @private
  35334. */
  35335. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  35336. // FIXME
  35337. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  35338. // 例如series.type === scatter时。
  35339. var is = true;
  35340. eachAxisDim(function (dimNames) {
  35341. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  35342. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  35343. if (!axisModel || axisModel.get('type') !== axisType) {
  35344. is = false;
  35345. }
  35346. }, this);
  35347. return is;
  35348. },
  35349. /**
  35350. * @private
  35351. */
  35352. _setDefaultThrottle: function (rawOption) {
  35353. // When first time user set throttle, auto throttle ends.
  35354. if (rawOption.hasOwnProperty('throttle')) {
  35355. this._autoThrottle = false;
  35356. }
  35357. if (this._autoThrottle) {
  35358. var globalOption = this.ecModel.option;
  35359. this.option.throttle =
  35360. (globalOption.animation && globalOption.animationDurationUpdate > 0)
  35361. ? 100 : 20;
  35362. }
  35363. },
  35364. /**
  35365. * @public
  35366. */
  35367. getFirstTargetAxisModel: function () {
  35368. var firstAxisModel;
  35369. eachAxisDim(function (dimNames) {
  35370. if (firstAxisModel == null) {
  35371. var indices = this.get(dimNames.axisIndex);
  35372. if (indices.length) {
  35373. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  35374. }
  35375. }
  35376. }, this);
  35377. return firstAxisModel;
  35378. },
  35379. /**
  35380. * @public
  35381. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  35382. */
  35383. eachTargetAxis: function (callback, context) {
  35384. var ecModel = this.ecModel;
  35385. eachAxisDim(function (dimNames) {
  35386. each$15(
  35387. this.get(dimNames.axisIndex),
  35388. function (axisIndex) {
  35389. callback.call(context, dimNames, axisIndex, this, ecModel);
  35390. },
  35391. this
  35392. );
  35393. }, this);
  35394. },
  35395. /**
  35396. * @param {string} dimName
  35397. * @param {number} axisIndex
  35398. * @return {module:echarts/component/dataZoom/AxisProxy} If not found, return null/undefined.
  35399. */
  35400. getAxisProxy: function (dimName, axisIndex) {
  35401. return this._axisProxies[dimName + '_' + axisIndex];
  35402. },
  35403. /**
  35404. * @param {string} dimName
  35405. * @param {number} axisIndex
  35406. * @return {module:echarts/model/Model} If not found, return null/undefined.
  35407. */
  35408. getAxisModel: function (dimName, axisIndex) {
  35409. var axisProxy = this.getAxisProxy(dimName, axisIndex);
  35410. return axisProxy && axisProxy.getAxisModel();
  35411. },
  35412. /**
  35413. * If not specified, set to undefined.
  35414. *
  35415. * @public
  35416. * @param {Object} opt
  35417. * @param {number} [opt.start]
  35418. * @param {number} [opt.end]
  35419. * @param {number} [opt.startValue]
  35420. * @param {number} [opt.endValue]
  35421. * @param {boolean} [ignoreUpdateRangeUsg=false]
  35422. */
  35423. setRawRange: function (opt, ignoreUpdateRangeUsg) {
  35424. var option = this.option;
  35425. each$15([['start', 'startValue'], ['end', 'endValue']], function (names) {
  35426. // If only one of 'start' and 'startValue' is not null/undefined, the other
  35427. // should be cleared, which enable clear the option.
  35428. // If both of them are not set, keep option with the original value, which
  35429. // enable use only set start but not set end when calling `dispatchAction`.
  35430. // The same as 'end' and 'endValue'.
  35431. if (opt[names[0]] != null || opt[names[1]] != null) {
  35432. option[names[0]] = opt[names[0]];
  35433. option[names[1]] = opt[names[1]];
  35434. }
  35435. }, this);
  35436. !ignoreUpdateRangeUsg && updateRangeUse(this, opt);
  35437. },
  35438. /**
  35439. * @public
  35440. * @return {Array.<number>} [startPercent, endPercent]
  35441. */
  35442. getPercentRange: function () {
  35443. var axisProxy = this.findRepresentativeAxisProxy();
  35444. if (axisProxy) {
  35445. return axisProxy.getDataPercentWindow();
  35446. }
  35447. },
  35448. /**
  35449. * @public
  35450. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  35451. *
  35452. * @param {string} [axisDimName]
  35453. * @param {number} [axisIndex]
  35454. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  35455. */
  35456. getValueRange: function (axisDimName, axisIndex) {
  35457. if (axisDimName == null && axisIndex == null) {
  35458. var axisProxy = this.findRepresentativeAxisProxy();
  35459. if (axisProxy) {
  35460. return axisProxy.getDataValueWindow();
  35461. }
  35462. }
  35463. else {
  35464. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  35465. }
  35466. },
  35467. /**
  35468. * @public
  35469. * @param {module:echarts/model/Model} [axisModel] If axisModel given, find axisProxy
  35470. * corresponding to the axisModel
  35471. * @return {module:echarts/component/dataZoom/AxisProxy}
  35472. */
  35473. findRepresentativeAxisProxy: function (axisModel) {
  35474. if (axisModel) {
  35475. return axisModel.__dzAxisProxy;
  35476. }
  35477. // Find the first hosted axisProxy
  35478. var axisProxies = this._axisProxies;
  35479. for (var key in axisProxies) {
  35480. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  35481. return axisProxies[key];
  35482. }
  35483. }
  35484. // If no hosted axis find not hosted axisProxy.
  35485. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  35486. // and the option.start or option.end settings are different. The percentRange
  35487. // should follow axisProxy.
  35488. // (We encounter this problem in toolbox data zoom.)
  35489. for (var key in axisProxies) {
  35490. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  35491. return axisProxies[key];
  35492. }
  35493. }
  35494. },
  35495. /**
  35496. * @return {Array.<string>}
  35497. */
  35498. getRangePropMode: function () {
  35499. return this._rangePropMode.slice();
  35500. }
  35501. });
  35502. function retrieveRaw(option) {
  35503. var ret = {};
  35504. each$15(
  35505. ['start', 'end', 'startValue', 'endValue', 'throttle'],
  35506. function (name) {
  35507. option.hasOwnProperty(name) && (ret[name] = option[name]);
  35508. }
  35509. );
  35510. return ret;
  35511. }
  35512. function updateRangeUse(dataZoomModel, rawOption) {
  35513. var rangePropMode = dataZoomModel._rangePropMode;
  35514. var rangeModeInOption = dataZoomModel.get('rangeMode');
  35515. each$15([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  35516. var percentSpecified = rawOption[names[0]] != null;
  35517. var valueSpecified = rawOption[names[1]] != null;
  35518. if (percentSpecified && !valueSpecified) {
  35519. rangePropMode[index] = 'percent';
  35520. }
  35521. else if (!percentSpecified && valueSpecified) {
  35522. rangePropMode[index] = 'value';
  35523. }
  35524. else if (rangeModeInOption) {
  35525. rangePropMode[index] = rangeModeInOption[index];
  35526. }
  35527. else if (percentSpecified) { // percentSpecified && valueSpecified
  35528. rangePropMode[index] = 'percent';
  35529. }
  35530. // else remain its original setting.
  35531. });
  35532. }
  35533. var DataZoomView = Component$1.extend({
  35534. type: 'dataZoom',
  35535. render: function (dataZoomModel, ecModel, api, payload) {
  35536. this.dataZoomModel = dataZoomModel;
  35537. this.ecModel = ecModel;
  35538. this.api = api;
  35539. },
  35540. /**
  35541. * Find the first target coordinate system.
  35542. *
  35543. * @protected
  35544. * @return {Object} {
  35545. * grid: [
  35546. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  35547. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  35548. * ...
  35549. * ], // cartesians must not be null/undefined.
  35550. * polar: [
  35551. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  35552. * ...
  35553. * ], // polars must not be null/undefined.
  35554. * singleAxis: [
  35555. * {model: coord0, axisModels: [], coordIndex: 0}
  35556. * ]
  35557. */
  35558. getTargetCoordInfo: function () {
  35559. var dataZoomModel = this.dataZoomModel;
  35560. var ecModel = this.ecModel;
  35561. var coordSysLists = {};
  35562. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  35563. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  35564. if (axisModel) {
  35565. var coordModel = axisModel.getCoordSysModel();
  35566. coordModel && save(
  35567. coordModel,
  35568. axisModel,
  35569. coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []),
  35570. coordModel.componentIndex
  35571. );
  35572. }
  35573. }, this);
  35574. function save(coordModel, axisModel, store, coordIndex) {
  35575. var item;
  35576. for (var i = 0; i < store.length; i++) {
  35577. if (store[i].model === coordModel) {
  35578. item = store[i];
  35579. break;
  35580. }
  35581. }
  35582. if (!item) {
  35583. store.push(item = {
  35584. model: coordModel, axisModels: [], coordIndex: coordIndex
  35585. });
  35586. }
  35587. item.axisModels.push(axisModel);
  35588. }
  35589. return coordSysLists;
  35590. }
  35591. });
  35592. var SliderZoomModel = DataZoomModel.extend({
  35593. type: 'dataZoom.slider',
  35594. layoutMode: 'box',
  35595. /**
  35596. * @protected
  35597. */
  35598. defaultOption: {
  35599. show: true,
  35600. // ph => placeholder. Using placehoder here because
  35601. // deault value can only be drived in view stage.
  35602. right: 'ph', // Default align to grid rect.
  35603. top: 'ph', // Default align to grid rect.
  35604. width: 'ph', // Default align to grid rect.
  35605. height: 'ph', // Default align to grid rect.
  35606. left: null, // Default align to grid rect.
  35607. bottom: null, // Default align to grid rect.
  35608. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  35609. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  35610. // highest priority, remain for compatibility of
  35611. // previous version, but not recommended any more.
  35612. dataBackground: {
  35613. lineStyle: {
  35614. color: '#2f4554',
  35615. width: 0.5,
  35616. opacity: 0.3
  35617. },
  35618. areaStyle: {
  35619. color: 'rgba(47,69,84,0.3)',
  35620. opacity: 0.3
  35621. }
  35622. },
  35623. borderColor: '#ddd', // border color of the box. For compatibility,
  35624. // if dataBackgroundColor is set, borderColor
  35625. // is ignored.
  35626. fillerColor: 'rgba(167,183,204,0.4)', // Color of selected area.
  35627. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  35628. // handleIcon: 'path://M4.9,17.8c0-1.4,4.5-10.5,5.5-12.4c0-0.1,0.6-1.1,0.9-1.1c0.4,0,0.9,1,0.9,1.1c1.1,2.2,5.4,11,5.4,12.4v17.8c0,1.5-0.6,2.1-1.3,2.1H6.1c-0.7,0-1.3-0.6-1.3-2.1V17.8z',
  35629. handleIcon: 'M8.2,13.6V3.9H6.3v9.7H3.1v14.9h3.3v9.7h1.8v-9.7h3.3V13.6H8.2z M9.7,24.4H4.8v-1.4h4.9V24.4z M9.7,19.1H4.8v-1.4h4.9V19.1z',
  35630. // Percent of the slider height
  35631. handleSize: '100%',
  35632. handleStyle: {
  35633. color: '#a7b7cc'
  35634. },
  35635. labelPrecision: null,
  35636. labelFormatter: null,
  35637. showDetail: true,
  35638. showDataShadow: 'auto', // Default auto decision.
  35639. realtime: true,
  35640. zoomLock: false, // Whether disable zoom.
  35641. textStyle: {
  35642. color: '#333'
  35643. }
  35644. }
  35645. });
  35646. /**
  35647. * Calculate slider move result.
  35648. * Usage:
  35649. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  35650. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  35651. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  35652. *
  35653. * @param {number} delta Move length.
  35654. * @param {Array.<number>} handleEnds handleEnds[0] can be bigger then handleEnds[1].
  35655. * handleEnds will be modified in this method.
  35656. * @param {Array.<number>} extent handleEnds is restricted by extent.
  35657. * extent[0] should less or equals than extent[1].
  35658. * @param {number|string} handleIndex Can be 'all', means that both move the two handleEnds,
  35659. * where the input minSpan and maxSpan will not work.
  35660. * @param {number} [minSpan] The range of dataZoom can not be smaller than that.
  35661. * If not set, handle0 and cross handle1. If set as a non-negative
  35662. * number (including `0`), handles will push each other when reaching
  35663. * the minSpan.
  35664. * @param {number} [maxSpan] The range of dataZoom can not be larger than that.
  35665. * @return {Array.<number>} The input handleEnds.
  35666. */
  35667. var sliderMove = function (delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  35668. // Normalize firstly.
  35669. handleEnds[0] = restrict(handleEnds[0], extent);
  35670. handleEnds[1] = restrict(handleEnds[1], extent);
  35671. delta = delta || 0;
  35672. var extentSpan = extent[1] - extent[0];
  35673. // Notice maxSpan and minSpan can be null/undefined.
  35674. if (minSpan != null) {
  35675. minSpan = restrict(minSpan, [0, extentSpan]);
  35676. }
  35677. if (maxSpan != null) {
  35678. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  35679. }
  35680. if (handleIndex === 'all') {
  35681. minSpan = maxSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  35682. handleIndex = 0;
  35683. }
  35684. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  35685. handleEnds[handleIndex] += delta;
  35686. // Restrict in extent.
  35687. var extentMinSpan = minSpan || 0;
  35688. var realExtent = extent.slice();
  35689. originalDistSign.sign < 0 ? (realExtent[0] += extentMinSpan) : (realExtent[1] -= extentMinSpan);
  35690. handleEnds[handleIndex] = restrict(handleEnds[handleIndex], realExtent);
  35691. // Expand span.
  35692. var currDistSign = getSpanSign(handleEnds, handleIndex);
  35693. if (minSpan != null && (
  35694. currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan
  35695. )) {
  35696. // If minSpan exists, 'cross' is forbinden.
  35697. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  35698. }
  35699. // Shrink span.
  35700. var currDistSign = getSpanSign(handleEnds, handleIndex);
  35701. if (maxSpan != null && currDistSign.span > maxSpan) {
  35702. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  35703. }
  35704. return handleEnds;
  35705. };
  35706. function getSpanSign(handleEnds, handleIndex) {
  35707. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex];
  35708. // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  35709. // is at left of handleEnds[1] for non-cross case.
  35710. return {span: Math.abs(dist), sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1};
  35711. }
  35712. function restrict(value, extend) {
  35713. return Math.min(extend[1], Math.max(extend[0], value));
  35714. }
  35715. var Rect$1 = Rect;
  35716. var linearMap$2 = linearMap;
  35717. var asc$2 = asc;
  35718. var bind$3 = bind;
  35719. var each$17 = each$1;
  35720. // Constants
  35721. var DEFAULT_LOCATION_EDGE_GAP = 7;
  35722. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  35723. var DEFAULT_FILLER_SIZE = 30;
  35724. var HORIZONTAL = 'horizontal';
  35725. var VERTICAL = 'vertical';
  35726. var LABEL_GAP = 5;
  35727. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  35728. var SliderZoomView = DataZoomView.extend({
  35729. type: 'dataZoom.slider',
  35730. init: function (ecModel, api) {
  35731. /**
  35732. * @private
  35733. * @type {Object}
  35734. */
  35735. this._displayables = {};
  35736. /**
  35737. * @private
  35738. * @type {string}
  35739. */
  35740. this._orient;
  35741. /**
  35742. * [0, 100]
  35743. * @private
  35744. */
  35745. this._range;
  35746. /**
  35747. * [coord of the first handle, coord of the second handle]
  35748. * @private
  35749. */
  35750. this._handleEnds;
  35751. /**
  35752. * [length, thick]
  35753. * @private
  35754. * @type {Array.<number>}
  35755. */
  35756. this._size;
  35757. /**
  35758. * @private
  35759. * @type {number}
  35760. */
  35761. this._handleWidth;
  35762. /**
  35763. * @private
  35764. * @type {number}
  35765. */
  35766. this._handleHeight;
  35767. /**
  35768. * @private
  35769. */
  35770. this._location;
  35771. /**
  35772. * @private
  35773. */
  35774. this._dragging;
  35775. /**
  35776. * @private
  35777. */
  35778. this._dataShadowInfo;
  35779. this.api = api;
  35780. },
  35781. /**
  35782. * @override
  35783. */
  35784. render: function (dataZoomModel, ecModel, api, payload) {
  35785. SliderZoomView.superApply(this, 'render', arguments);
  35786. createOrUpdate(
  35787. this,
  35788. '_dispatchZoomAction',
  35789. this.dataZoomModel.get('throttle'),
  35790. 'fixRate'
  35791. );
  35792. this._orient = dataZoomModel.get('orient');
  35793. if (this.dataZoomModel.get('show') === false) {
  35794. this.group.removeAll();
  35795. return;
  35796. }
  35797. // Notice: this._resetInterval() should not be executed when payload.type
  35798. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  35799. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  35800. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  35801. this._buildView();
  35802. }
  35803. this._updateView();
  35804. },
  35805. /**
  35806. * @override
  35807. */
  35808. remove: function () {
  35809. SliderZoomView.superApply(this, 'remove', arguments);
  35810. clear(this, '_dispatchZoomAction');
  35811. },
  35812. /**
  35813. * @override
  35814. */
  35815. dispose: function () {
  35816. SliderZoomView.superApply(this, 'dispose', arguments);
  35817. clear(this, '_dispatchZoomAction');
  35818. },
  35819. _buildView: function () {
  35820. var thisGroup = this.group;
  35821. thisGroup.removeAll();
  35822. this._resetLocation();
  35823. this._resetInterval();
  35824. var barGroup = this._displayables.barGroup = new Group();
  35825. this._renderBackground();
  35826. this._renderHandle();
  35827. this._renderDataShadow();
  35828. thisGroup.add(barGroup);
  35829. this._positionGroup();
  35830. },
  35831. /**
  35832. * @private
  35833. */
  35834. _resetLocation: function () {
  35835. var dataZoomModel = this.dataZoomModel;
  35836. var api = this.api;
  35837. // If some of x/y/width/height are not specified,
  35838. // auto-adapt according to target grid.
  35839. var coordRect = this._findCoordRect();
  35840. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  35841. // Default align by coordinate system rect.
  35842. var positionInfo = this._orient === HORIZONTAL
  35843. ? {
  35844. // Why using 'right', because right should be used in vertical,
  35845. // and it is better to be consistent for dealing with position param merge.
  35846. right: ecSize.width - coordRect.x - coordRect.width,
  35847. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  35848. width: coordRect.width,
  35849. height: DEFAULT_FILLER_SIZE
  35850. }
  35851. : { // vertical
  35852. right: DEFAULT_LOCATION_EDGE_GAP,
  35853. top: coordRect.y,
  35854. width: DEFAULT_FILLER_SIZE,
  35855. height: coordRect.height
  35856. };
  35857. // Do not write back to option and replace value 'ph', because
  35858. // the 'ph' value should be recalculated when resize.
  35859. var layoutParams = getLayoutParams(dataZoomModel.option);
  35860. // Replace the placeholder value.
  35861. each$1(['right', 'top', 'width', 'height'], function (name) {
  35862. if (layoutParams[name] === 'ph') {
  35863. layoutParams[name] = positionInfo[name];
  35864. }
  35865. });
  35866. var layoutRect = getLayoutRect(
  35867. layoutParams,
  35868. ecSize,
  35869. dataZoomModel.padding
  35870. );
  35871. this._location = {x: layoutRect.x, y: layoutRect.y};
  35872. this._size = [layoutRect.width, layoutRect.height];
  35873. this._orient === VERTICAL && this._size.reverse();
  35874. },
  35875. /**
  35876. * @private
  35877. */
  35878. _positionGroup: function () {
  35879. var thisGroup = this.group;
  35880. var location = this._location;
  35881. var orient = this._orient;
  35882. // Just use the first axis to determine mapping.
  35883. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  35884. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  35885. var barGroup = this._displayables.barGroup;
  35886. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  35887. // Transform barGroup.
  35888. barGroup.attr(
  35889. (orient === HORIZONTAL && !inverse)
  35890. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  35891. : (orient === HORIZONTAL && inverse)
  35892. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  35893. : (orient === VERTICAL && !inverse)
  35894. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  35895. // Dont use Math.PI, considering shadow direction.
  35896. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  35897. );
  35898. // Position barGroup
  35899. var rect = thisGroup.getBoundingRect([barGroup]);
  35900. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  35901. },
  35902. /**
  35903. * @private
  35904. */
  35905. _getViewExtent: function () {
  35906. return [0, this._size[0]];
  35907. },
  35908. _renderBackground: function () {
  35909. var dataZoomModel = this.dataZoomModel;
  35910. var size = this._size;
  35911. var barGroup = this._displayables.barGroup;
  35912. barGroup.add(new Rect$1({
  35913. silent: true,
  35914. shape: {
  35915. x: 0, y: 0, width: size[0], height: size[1]
  35916. },
  35917. style: {
  35918. fill: dataZoomModel.get('backgroundColor')
  35919. },
  35920. z2: -40
  35921. }));
  35922. // Click panel, over shadow, below handles.
  35923. barGroup.add(new Rect$1({
  35924. shape: {
  35925. x: 0, y: 0, width: size[0], height: size[1]
  35926. },
  35927. style: {
  35928. fill: 'transparent'
  35929. },
  35930. z2: 0,
  35931. onclick: bind(this._onClickPanelClick, this)
  35932. }));
  35933. },
  35934. _renderDataShadow: function () {
  35935. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  35936. if (!info) {
  35937. return;
  35938. }
  35939. var size = this._size;
  35940. var seriesModel = info.series;
  35941. var data = seriesModel.getRawData();
  35942. var otherDim = seriesModel.getShadowDim
  35943. ? seriesModel.getShadowDim() // @see candlestick
  35944. : info.otherDim;
  35945. if (otherDim == null) {
  35946. return;
  35947. }
  35948. var otherDataExtent = data.getDataExtent(otherDim);
  35949. // Nice extent.
  35950. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  35951. otherDataExtent = [
  35952. otherDataExtent[0] - otherOffset,
  35953. otherDataExtent[1] + otherOffset
  35954. ];
  35955. var otherShadowExtent = [0, size[1]];
  35956. var thisShadowExtent = [0, size[0]];
  35957. var areaPoints = [[size[0], 0], [0, 0]];
  35958. var linePoints = [];
  35959. var step = thisShadowExtent[1] / (data.count() - 1);
  35960. var thisCoord = 0;
  35961. // Optimize for large data shadow
  35962. var stride = Math.round(data.count() / size[0]);
  35963. var lastIsEmpty;
  35964. data.each([otherDim], function (value, index) {
  35965. if (stride > 0 && (index % stride)) {
  35966. thisCoord += step;
  35967. return;
  35968. }
  35969. // FIXME
  35970. // Should consider axis.min/axis.max when drawing dataShadow.
  35971. // FIXME
  35972. // 应该使用统一的空判断?还是在list里进行空判断?
  35973. var isEmpty = value == null || isNaN(value) || value === '';
  35974. // See #4235.
  35975. var otherCoord = isEmpty
  35976. ? 0 : linearMap$2(value, otherDataExtent, otherShadowExtent, true);
  35977. // Attempt to draw data shadow precisely when there are empty value.
  35978. if (isEmpty && !lastIsEmpty && index) {
  35979. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  35980. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  35981. }
  35982. else if (!isEmpty && lastIsEmpty) {
  35983. areaPoints.push([thisCoord, 0]);
  35984. linePoints.push([thisCoord, 0]);
  35985. }
  35986. areaPoints.push([thisCoord, otherCoord]);
  35987. linePoints.push([thisCoord, otherCoord]);
  35988. thisCoord += step;
  35989. lastIsEmpty = isEmpty;
  35990. });
  35991. var dataZoomModel = this.dataZoomModel;
  35992. // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  35993. this._displayables.barGroup.add(new Polygon({
  35994. shape: {points: areaPoints},
  35995. style: defaults(
  35996. {fill: dataZoomModel.get('dataBackgroundColor')},
  35997. dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()
  35998. ),
  35999. silent: true,
  36000. z2: -20
  36001. }));
  36002. this._displayables.barGroup.add(new Polyline({
  36003. shape: {points: linePoints},
  36004. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  36005. silent: true,
  36006. z2: -19
  36007. }));
  36008. },
  36009. _prepareDataShadowInfo: function () {
  36010. var dataZoomModel = this.dataZoomModel;
  36011. var showDataShadow = dataZoomModel.get('showDataShadow');
  36012. if (showDataShadow === false) {
  36013. return;
  36014. }
  36015. // Find a representative series.
  36016. var result;
  36017. var ecModel = this.ecModel;
  36018. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  36019. var seriesModels = dataZoomModel
  36020. .getAxisProxy(dimNames.name, axisIndex)
  36021. .getTargetSeriesModels();
  36022. each$1(seriesModels, function (seriesModel) {
  36023. if (result) {
  36024. return;
  36025. }
  36026. if (showDataShadow !== true && indexOf(
  36027. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  36028. ) < 0
  36029. ) {
  36030. return;
  36031. }
  36032. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  36033. var otherDim = getOtherDim(dimNames.name);
  36034. var otherAxisInverse;
  36035. var coordSys = seriesModel.coordinateSystem;
  36036. if (otherDim != null && coordSys.getOtherAxis) {
  36037. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  36038. }
  36039. result = {
  36040. thisAxis: thisAxis,
  36041. series: seriesModel,
  36042. thisDim: dimNames.name,
  36043. otherDim: otherDim,
  36044. otherAxisInverse: otherAxisInverse
  36045. };
  36046. }, this);
  36047. }, this);
  36048. return result;
  36049. },
  36050. _renderHandle: function () {
  36051. var displaybles = this._displayables;
  36052. var handles = displaybles.handles = [];
  36053. var handleLabels = displaybles.handleLabels = [];
  36054. var barGroup = this._displayables.barGroup;
  36055. var size = this._size;
  36056. var dataZoomModel = this.dataZoomModel;
  36057. barGroup.add(displaybles.filler = new Rect$1({
  36058. draggable: true,
  36059. cursor: getCursor(this._orient),
  36060. drift: bind$3(this._onDragMove, this, 'all'),
  36061. onmousemove: function (e) {
  36062. // Fot mobile devicem, prevent screen slider on the button.
  36063. stop(e.event);
  36064. },
  36065. ondragstart: bind$3(this._showDataInfo, this, true),
  36066. ondragend: bind$3(this._onDragEnd, this),
  36067. onmouseover: bind$3(this._showDataInfo, this, true),
  36068. onmouseout: bind$3(this._showDataInfo, this, false),
  36069. style: {
  36070. fill: dataZoomModel.get('fillerColor'),
  36071. textPosition : 'inside'
  36072. }
  36073. }));
  36074. // Frame border.
  36075. barGroup.add(new Rect$1(subPixelOptimizeRect({
  36076. silent: true,
  36077. shape: {
  36078. x: 0,
  36079. y: 0,
  36080. width: size[0],
  36081. height: size[1]
  36082. },
  36083. style: {
  36084. stroke: dataZoomModel.get('dataBackgroundColor')
  36085. || dataZoomModel.get('borderColor'),
  36086. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  36087. fill: 'rgba(0,0,0,0)'
  36088. }
  36089. })));
  36090. each$17([0, 1], function (handleIndex) {
  36091. var path = createIcon(
  36092. dataZoomModel.get('handleIcon'),
  36093. {
  36094. cursor: getCursor(this._orient),
  36095. draggable: true,
  36096. drift: bind$3(this._onDragMove, this, handleIndex),
  36097. onmousemove: function (e) {
  36098. // Fot mobile devicem, prevent screen slider on the button.
  36099. stop(e.event);
  36100. },
  36101. ondragend: bind$3(this._onDragEnd, this),
  36102. onmouseover: bind$3(this._showDataInfo, this, true),
  36103. onmouseout: bind$3(this._showDataInfo, this, false)
  36104. },
  36105. {x: -1, y: 0, width: 2, height: 2}
  36106. );
  36107. var bRect = path.getBoundingRect();
  36108. this._handleHeight = parsePercent$1(dataZoomModel.get('handleSize'), this._size[1]);
  36109. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  36110. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  36111. var handleColor = dataZoomModel.get('handleColor');
  36112. // Compatitable with previous version
  36113. if (handleColor != null) {
  36114. path.style.fill = handleColor;
  36115. }
  36116. barGroup.add(handles[handleIndex] = path);
  36117. var textStyleModel = dataZoomModel.textStyleModel;
  36118. this.group.add(
  36119. handleLabels[handleIndex] = new Text({
  36120. silent: true,
  36121. invisible: true,
  36122. style: {
  36123. x: 0, y: 0, text: '',
  36124. textVerticalAlign: 'middle',
  36125. textAlign: 'center',
  36126. textFill: textStyleModel.getTextColor(),
  36127. textFont: textStyleModel.getFont()
  36128. },
  36129. z2: 10
  36130. }));
  36131. }, this);
  36132. },
  36133. /**
  36134. * @private
  36135. */
  36136. _resetInterval: function () {
  36137. var range = this._range = this.dataZoomModel.getPercentRange();
  36138. var viewExtent = this._getViewExtent();
  36139. this._handleEnds = [
  36140. linearMap$2(range[0], [0, 100], viewExtent, true),
  36141. linearMap$2(range[1], [0, 100], viewExtent, true)
  36142. ];
  36143. },
  36144. /**
  36145. * @private
  36146. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  36147. * @param {number} delta
  36148. */
  36149. _updateInterval: function (handleIndex, delta) {
  36150. var dataZoomModel = this.dataZoomModel;
  36151. var handleEnds = this._handleEnds;
  36152. var viewExtend = this._getViewExtent();
  36153. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  36154. var percentExtent = [0, 100];
  36155. sliderMove(
  36156. delta,
  36157. handleEnds,
  36158. viewExtend,
  36159. dataZoomModel.get('zoomLock') ? 'all' : handleIndex,
  36160. minMaxSpan.minSpan != null
  36161. ? linearMap$2(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null,
  36162. minMaxSpan.maxSpan != null
  36163. ? linearMap$2(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null
  36164. );
  36165. this._range = asc$2([
  36166. linearMap$2(handleEnds[0], viewExtend, percentExtent, true),
  36167. linearMap$2(handleEnds[1], viewExtend, percentExtent, true)
  36168. ]);
  36169. },
  36170. /**
  36171. * @private
  36172. */
  36173. _updateView: function (nonRealtime) {
  36174. var displaybles = this._displayables;
  36175. var handleEnds = this._handleEnds;
  36176. var handleInterval = asc$2(handleEnds.slice());
  36177. var size = this._size;
  36178. each$17([0, 1], function (handleIndex) {
  36179. // Handles
  36180. var handle = displaybles.handles[handleIndex];
  36181. var handleHeight = this._handleHeight;
  36182. handle.attr({
  36183. scale: [handleHeight / 2, handleHeight / 2],
  36184. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  36185. });
  36186. }, this);
  36187. // Filler
  36188. displaybles.filler.setShape({
  36189. x: handleInterval[0],
  36190. y: 0,
  36191. width: handleInterval[1] - handleInterval[0],
  36192. height: size[1]
  36193. });
  36194. this._updateDataInfo(nonRealtime);
  36195. },
  36196. /**
  36197. * @private
  36198. */
  36199. _updateDataInfo: function (nonRealtime) {
  36200. var dataZoomModel = this.dataZoomModel;
  36201. var displaybles = this._displayables;
  36202. var handleLabels = displaybles.handleLabels;
  36203. var orient = this._orient;
  36204. var labelTexts = ['', ''];
  36205. // FIXME
  36206. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  36207. if (dataZoomModel.get('showDetail')) {
  36208. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  36209. if (axisProxy) {
  36210. var axis = axisProxy.getAxisModel().axis;
  36211. var range = this._range;
  36212. var dataInterval = nonRealtime
  36213. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  36214. ? axisProxy.calculateDataWindow({
  36215. start: range[0], end: range[1]
  36216. }).valueWindow
  36217. : axisProxy.getDataValueWindow();
  36218. labelTexts = [
  36219. this._formatLabel(dataInterval[0], axis),
  36220. this._formatLabel(dataInterval[1], axis)
  36221. ];
  36222. }
  36223. }
  36224. var orderedHandleEnds = asc$2(this._handleEnds.slice());
  36225. setLabel.call(this, 0);
  36226. setLabel.call(this, 1);
  36227. function setLabel(handleIndex) {
  36228. // Label
  36229. // Text should not transform by barGroup.
  36230. // Ignore handlers transform
  36231. var barTransform = getTransform(
  36232. displaybles.handles[handleIndex].parent, this.group
  36233. );
  36234. var direction = transformDirection(
  36235. handleIndex === 0 ? 'right' : 'left', barTransform
  36236. );
  36237. var offset = this._handleWidth / 2 + LABEL_GAP;
  36238. var textPoint = applyTransform$1(
  36239. [
  36240. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  36241. this._size[1] / 2
  36242. ],
  36243. barTransform
  36244. );
  36245. handleLabels[handleIndex].setStyle({
  36246. x: textPoint[0],
  36247. y: textPoint[1],
  36248. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  36249. textAlign: orient === HORIZONTAL ? direction : 'center',
  36250. text: labelTexts[handleIndex]
  36251. });
  36252. }
  36253. },
  36254. /**
  36255. * @private
  36256. */
  36257. _formatLabel: function (value, axis) {
  36258. var dataZoomModel = this.dataZoomModel;
  36259. var labelFormatter = dataZoomModel.get('labelFormatter');
  36260. var labelPrecision = dataZoomModel.get('labelPrecision');
  36261. if (labelPrecision == null || labelPrecision === 'auto') {
  36262. labelPrecision = axis.getPixelPrecision();
  36263. }
  36264. var valueStr = (value == null || isNaN(value))
  36265. ? ''
  36266. // FIXME Glue code
  36267. : (axis.type === 'category' || axis.type === 'time')
  36268. ? axis.scale.getLabel(Math.round(value))
  36269. // param of toFixed should less then 20.
  36270. : value.toFixed(Math.min(labelPrecision, 20));
  36271. return isFunction(labelFormatter)
  36272. ? labelFormatter(value, valueStr)
  36273. : isString(labelFormatter)
  36274. ? labelFormatter.replace('{value}', valueStr)
  36275. : valueStr;
  36276. },
  36277. /**
  36278. * @private
  36279. * @param {boolean} showOrHide true: show, false: hide
  36280. */
  36281. _showDataInfo: function (showOrHide) {
  36282. // Always show when drgging.
  36283. showOrHide = this._dragging || showOrHide;
  36284. var handleLabels = this._displayables.handleLabels;
  36285. handleLabels[0].attr('invisible', !showOrHide);
  36286. handleLabels[1].attr('invisible', !showOrHide);
  36287. },
  36288. _onDragMove: function (handleIndex, dx, dy) {
  36289. this._dragging = true;
  36290. // Transform dx, dy to bar coordination.
  36291. var barTransform = this._displayables.barGroup.getLocalTransform();
  36292. var vertex = applyTransform$1([dx, dy], barTransform, true);
  36293. this._updateInterval(handleIndex, vertex[0]);
  36294. var realtime = this.dataZoomModel.get('realtime');
  36295. this._updateView(!realtime);
  36296. if (realtime) {
  36297. realtime && this._dispatchZoomAction();
  36298. }
  36299. },
  36300. _onDragEnd: function () {
  36301. this._dragging = false;
  36302. this._showDataInfo(false);
  36303. this._dispatchZoomAction();
  36304. },
  36305. _onClickPanelClick: function (e) {
  36306. var size = this._size;
  36307. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  36308. if (localPoint[0] < 0 || localPoint[0] > size[0]
  36309. || localPoint[1] < 0 || localPoint[1] > size[1]
  36310. ) {
  36311. return;
  36312. }
  36313. var handleEnds = this._handleEnds;
  36314. var center = (handleEnds[0] + handleEnds[1]) / 2;
  36315. this._updateInterval('all', localPoint[0] - center);
  36316. this._updateView();
  36317. this._dispatchZoomAction();
  36318. },
  36319. /**
  36320. * This action will be throttled.
  36321. * @private
  36322. */
  36323. _dispatchZoomAction: function () {
  36324. var range = this._range;
  36325. this.api.dispatchAction({
  36326. type: 'dataZoom',
  36327. from: this.uid,
  36328. dataZoomId: this.dataZoomModel.id,
  36329. start: range[0],
  36330. end: range[1]
  36331. });
  36332. },
  36333. /**
  36334. * @private
  36335. */
  36336. _findCoordRect: function () {
  36337. // Find the grid coresponding to the first axis referred by dataZoom.
  36338. var rect;
  36339. each$17(this.getTargetCoordInfo(), function (coordInfoList) {
  36340. if (!rect && coordInfoList.length) {
  36341. var coordSys = coordInfoList[0].model.coordinateSystem;
  36342. rect = coordSys.getRect && coordSys.getRect();
  36343. }
  36344. });
  36345. if (!rect) {
  36346. var width = this.api.getWidth();
  36347. var height = this.api.getHeight();
  36348. rect = {
  36349. x: width * 0.2,
  36350. y: height * 0.2,
  36351. width: width * 0.6,
  36352. height: height * 0.6
  36353. };
  36354. }
  36355. return rect;
  36356. }
  36357. });
  36358. function getOtherDim(thisDim) {
  36359. // FIXME
  36360. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  36361. var map$$1 = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
  36362. return map$$1[thisDim];
  36363. }
  36364. function getCursor(orient) {
  36365. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  36366. }
  36367. DataZoomModel.extend({
  36368. type: 'dataZoom.inside',
  36369. /**
  36370. * @protected
  36371. */
  36372. defaultOption: {
  36373. disabled: false, // Whether disable this inside zoom.
  36374. zoomLock: false, // Whether disable zoom but only pan.
  36375. zoomOnMouseWheel: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  36376. moveOnMouseMove: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  36377. preventDefaultMouseMove: true
  36378. }
  36379. });
  36380. var ATTR$1 = '\0_ec_interaction_mutex';
  36381. function take(zr, resourceKey, userKey) {
  36382. var store = getStore(zr);
  36383. store[resourceKey] = userKey;
  36384. }
  36385. function release(zr, resourceKey, userKey) {
  36386. var store = getStore(zr);
  36387. var uKey = store[resourceKey];
  36388. if (uKey === userKey) {
  36389. store[resourceKey] = null;
  36390. }
  36391. }
  36392. function isTaken(zr, resourceKey) {
  36393. return !!getStore(zr)[resourceKey];
  36394. }
  36395. function getStore(zr) {
  36396. return zr[ATTR$1] || (zr[ATTR$1] = {});
  36397. }
  36398. /**
  36399. * payload: {
  36400. * type: 'takeGlobalCursor',
  36401. * key: 'dataZoomSelect', or 'brush', or ...,
  36402. * If no userKey, release global cursor.
  36403. * }
  36404. */
  36405. registerAction(
  36406. {type: 'takeGlobalCursor', event: 'globalCursorTaken', update: 'update'},
  36407. function () {}
  36408. );
  36409. /**
  36410. * @alias module:echarts/component/helper/RoamController
  36411. * @constructor
  36412. * @mixin {module:zrender/mixin/Eventful}
  36413. *
  36414. * @param {module:zrender/zrender~ZRender} zr
  36415. */
  36416. function RoamController(zr) {
  36417. /**
  36418. * @type {Function}
  36419. */
  36420. this.pointerChecker;
  36421. /**
  36422. * @type {module:zrender}
  36423. */
  36424. this._zr = zr;
  36425. /**
  36426. * @type {Object}
  36427. */
  36428. this._opt = {};
  36429. // Avoid two roamController bind the same handler
  36430. var bind$$1 = bind;
  36431. var mousedownHandler = bind$$1(mousedown, this);
  36432. var mousemoveHandler = bind$$1(mousemove, this);
  36433. var mouseupHandler = bind$$1(mouseup, this);
  36434. var mousewheelHandler = bind$$1(mousewheel, this);
  36435. var pinchHandler = bind$$1(pinch, this);
  36436. Eventful.call(this);
  36437. /**
  36438. * @param {Function} pointerChecker
  36439. * input: x, y
  36440. * output: boolean
  36441. */
  36442. this.setPointerChecker = function (pointerChecker) {
  36443. this.pointerChecker = pointerChecker;
  36444. };
  36445. /**
  36446. * Notice: only enable needed types. For example, if 'zoom'
  36447. * is not needed, 'zoom' should not be enabled, otherwise
  36448. * default mousewheel behaviour (scroll page) will be disabled.
  36449. *
  36450. * @param {boolean|string} [controlType=true] Specify the control type,
  36451. * which can be null/undefined or true/false
  36452. * or 'pan/move' or 'zoom'/'scale'
  36453. * @param {Object} [opt]
  36454. * @param {Object} [opt.zoomOnMouseWheel=true]
  36455. * @param {Object} [opt.moveOnMouseMove=true]
  36456. * @param {Object} [opt.preventDefaultMouseMove=true] When pan.
  36457. */
  36458. this.enable = function (controlType, opt) {
  36459. // Disable previous first
  36460. this.disable();
  36461. this._opt = defaults(clone(opt) || {}, {
  36462. zoomOnMouseWheel: true,
  36463. moveOnMouseMove: true,
  36464. preventDefaultMouseMove: true
  36465. });
  36466. if (controlType == null) {
  36467. controlType = true;
  36468. }
  36469. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  36470. zr.on('mousedown', mousedownHandler);
  36471. zr.on('mousemove', mousemoveHandler);
  36472. zr.on('mouseup', mouseupHandler);
  36473. }
  36474. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  36475. zr.on('mousewheel', mousewheelHandler);
  36476. zr.on('pinch', pinchHandler);
  36477. }
  36478. };
  36479. this.disable = function () {
  36480. zr.off('mousedown', mousedownHandler);
  36481. zr.off('mousemove', mousemoveHandler);
  36482. zr.off('mouseup', mouseupHandler);
  36483. zr.off('mousewheel', mousewheelHandler);
  36484. zr.off('pinch', pinchHandler);
  36485. };
  36486. this.dispose = this.disable;
  36487. this.isDragging = function () {
  36488. return this._dragging;
  36489. };
  36490. this.isPinching = function () {
  36491. return this._pinching;
  36492. };
  36493. }
  36494. mixin(RoamController, Eventful);
  36495. function mousedown(e) {
  36496. if (notLeftMouse(e)
  36497. || (e.target && e.target.draggable)
  36498. ) {
  36499. return;
  36500. }
  36501. var x = e.offsetX;
  36502. var y = e.offsetY;
  36503. // Only check on mosedown, but not mousemove.
  36504. // Mouse can be out of target when mouse moving.
  36505. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  36506. this._x = x;
  36507. this._y = y;
  36508. this._dragging = true;
  36509. }
  36510. }
  36511. function mousemove(e) {
  36512. if (notLeftMouse(e)
  36513. || !checkKeyBinding(this, 'moveOnMouseMove', e)
  36514. || !this._dragging
  36515. || e.gestureEvent === 'pinch'
  36516. || isTaken(this._zr, 'globalPan')
  36517. ) {
  36518. return;
  36519. }
  36520. var x = e.offsetX;
  36521. var y = e.offsetY;
  36522. var oldX = this._x;
  36523. var oldY = this._y;
  36524. var dx = x - oldX;
  36525. var dy = y - oldY;
  36526. this._x = x;
  36527. this._y = y;
  36528. this._opt.preventDefaultMouseMove && stop(e.event);
  36529. this.trigger('pan', dx, dy, oldX, oldY, x, y);
  36530. }
  36531. function mouseup(e) {
  36532. if (!notLeftMouse(e)) {
  36533. this._dragging = false;
  36534. }
  36535. }
  36536. function mousewheel(e) {
  36537. // wheelDelta maybe -0 in chrome mac.
  36538. if (!checkKeyBinding(this, 'zoomOnMouseWheel', e) || e.wheelDelta === 0) {
  36539. return;
  36540. }
  36541. // Convenience:
  36542. // Mac and VM Windows on Mac: scroll up: zoom out.
  36543. // Windows: scroll up: zoom in.
  36544. var zoomDelta = e.wheelDelta > 0 ? 1.1 : 1 / 1.1;
  36545. zoom.call(this, e, zoomDelta, e.offsetX, e.offsetY);
  36546. }
  36547. function pinch(e) {
  36548. if (isTaken(this._zr, 'globalPan')) {
  36549. return;
  36550. }
  36551. var zoomDelta = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  36552. zoom.call(this, e, zoomDelta, e.pinchX, e.pinchY);
  36553. }
  36554. function zoom(e, zoomDelta, zoomX, zoomY) {
  36555. if (this.pointerChecker && this.pointerChecker(e, zoomX, zoomY)) {
  36556. // When mouse is out of roamController rect,
  36557. // default befavoius should not be be disabled, otherwise
  36558. // page sliding is disabled, contrary to expectation.
  36559. stop(e.event);
  36560. this.trigger('zoom', zoomDelta, zoomX, zoomY);
  36561. }
  36562. }
  36563. function checkKeyBinding(roamController, prop, e) {
  36564. var setting = roamController._opt[prop];
  36565. return setting
  36566. && (!isString(setting) || e.event[setting + 'Key']);
  36567. }
  36568. // Only create one roam controller for each coordinate system.
  36569. // one roam controller might be refered by two inside data zoom
  36570. // components (for example, one for x and one for y). When user
  36571. // pan or zoom, only dispatch one action for those data zoom
  36572. // components.
  36573. var curry$5 = curry;
  36574. var ATTR = '\0_ec_dataZoom_roams';
  36575. /**
  36576. * @public
  36577. * @param {module:echarts/ExtensionAPI} api
  36578. * @param {Object} dataZoomInfo
  36579. * @param {string} dataZoomInfo.coordId
  36580. * @param {Function} dataZoomInfo.containsPoint
  36581. * @param {Array.<string>} dataZoomInfo.allCoordIds
  36582. * @param {string} dataZoomInfo.dataZoomId
  36583. * @param {number} dataZoomInfo.throttleRate
  36584. * @param {Function} dataZoomInfo.panGetRange
  36585. * @param {Function} dataZoomInfo.zoomGetRange
  36586. * @param {boolean} [dataZoomInfo.zoomLock]
  36587. * @param {boolean} [dataZoomInfo.disabled]
  36588. */
  36589. function register$1(api, dataZoomInfo) {
  36590. var store = giveStore(api);
  36591. var theDataZoomId = dataZoomInfo.dataZoomId;
  36592. var theCoordId = dataZoomInfo.coordId;
  36593. // Do clean when a dataZoom changes its target coordnate system.
  36594. // Avoid memory leak, dispose all not-used-registered.
  36595. each$1(store, function (record, coordId) {
  36596. var dataZoomInfos = record.dataZoomInfos;
  36597. if (dataZoomInfos[theDataZoomId]
  36598. && indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  36599. ) {
  36600. delete dataZoomInfos[theDataZoomId];
  36601. record.count--;
  36602. }
  36603. });
  36604. cleanStore(store);
  36605. var record = store[theCoordId];
  36606. // Create if needed.
  36607. if (!record) {
  36608. record = store[theCoordId] = {
  36609. coordId: theCoordId,
  36610. dataZoomInfos: {},
  36611. count: 0
  36612. };
  36613. record.controller = createController(api, record);
  36614. record.dispatchAction = curry(dispatchAction, api);
  36615. }
  36616. // Update reference of dataZoom.
  36617. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  36618. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  36619. var controllerParams = mergeControllerParams(record.dataZoomInfos);
  36620. record.controller.enable(controllerParams.controlType, controllerParams.opt);
  36621. // Consider resize, area should be always updated.
  36622. record.controller.setPointerChecker(dataZoomInfo.containsPoint);
  36623. // Update throttle.
  36624. createOrUpdate(
  36625. record,
  36626. 'dispatchAction',
  36627. dataZoomInfo.throttleRate,
  36628. 'fixRate'
  36629. );
  36630. }
  36631. /**
  36632. * @public
  36633. * @param {module:echarts/ExtensionAPI} api
  36634. * @param {string} dataZoomId
  36635. */
  36636. function unregister$1(api, dataZoomId) {
  36637. var store = giveStore(api);
  36638. each$1(store, function (record) {
  36639. record.controller.dispose();
  36640. var dataZoomInfos = record.dataZoomInfos;
  36641. if (dataZoomInfos[dataZoomId]) {
  36642. delete dataZoomInfos[dataZoomId];
  36643. record.count--;
  36644. }
  36645. });
  36646. cleanStore(store);
  36647. }
  36648. /**
  36649. * @public
  36650. */
  36651. function shouldRecordRange(payload, dataZoomId) {
  36652. if (payload && payload.type === 'dataZoom' && payload.batch) {
  36653. for (var i = 0, len = payload.batch.length; i < len; i++) {
  36654. if (payload.batch[i].dataZoomId === dataZoomId) {
  36655. return false;
  36656. }
  36657. }
  36658. }
  36659. return true;
  36660. }
  36661. /**
  36662. * @public
  36663. */
  36664. function generateCoordId(coordModel) {
  36665. return coordModel.type + '\0_' + coordModel.id;
  36666. }
  36667. /**
  36668. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  36669. * @type {Array.<Object>}
  36670. */
  36671. function giveStore(api) {
  36672. // Mount store on zrender instance, so that we do not
  36673. // need to worry about dispose.
  36674. var zr = api.getZr();
  36675. return zr[ATTR] || (zr[ATTR] = {});
  36676. }
  36677. function createController(api, newRecord) {
  36678. var controller = new RoamController(api.getZr());
  36679. controller.on('pan', curry$5(onPan, newRecord));
  36680. controller.on('zoom', curry$5(onZoom, newRecord));
  36681. return controller;
  36682. }
  36683. function cleanStore(store) {
  36684. each$1(store, function (record, coordId) {
  36685. if (!record.count) {
  36686. record.controller.dispose();
  36687. delete store[coordId];
  36688. }
  36689. });
  36690. }
  36691. function onPan(record, dx, dy, oldX, oldY, newX, newY) {
  36692. wrapAndDispatch(record, function (info) {
  36693. return info.panGetRange(record.controller, dx, dy, oldX, oldY, newX, newY);
  36694. });
  36695. }
  36696. function onZoom(record, scale, mouseX, mouseY) {
  36697. wrapAndDispatch(record, function (info) {
  36698. return info.zoomGetRange(record.controller, scale, mouseX, mouseY);
  36699. });
  36700. }
  36701. function wrapAndDispatch(record, getRange) {
  36702. var batch = [];
  36703. each$1(record.dataZoomInfos, function (info) {
  36704. var range = getRange(info);
  36705. !info.disabled && range && batch.push({
  36706. dataZoomId: info.dataZoomId,
  36707. start: range[0],
  36708. end: range[1]
  36709. });
  36710. });
  36711. record.dispatchAction(batch);
  36712. }
  36713. /**
  36714. * This action will be throttled.
  36715. */
  36716. function dispatchAction(api, batch) {
  36717. api.dispatchAction({
  36718. type: 'dataZoom',
  36719. batch: batch
  36720. });
  36721. }
  36722. /**
  36723. * Merge roamController settings when multiple dataZooms share one roamController.
  36724. */
  36725. function mergeControllerParams(dataZoomInfos) {
  36726. var controlType;
  36727. var opt = {};
  36728. var typePriority = {
  36729. 'true': 2,
  36730. 'move': 1,
  36731. 'false': 0,
  36732. 'undefined': -1
  36733. };
  36734. each$1(dataZoomInfos, function (dataZoomInfo) {
  36735. var oneType = dataZoomInfo.disabled ? false : dataZoomInfo.zoomLock ? 'move' : true;
  36736. typePriority[oneType] > typePriority[controlType] && (controlType = oneType);
  36737. // Do not support that different 'shift'/'ctrl'/'alt' setting used in one coord sys.
  36738. extend(opt, dataZoomInfo.roamControllerOpt);
  36739. });
  36740. return {
  36741. controlType: controlType,
  36742. opt: opt
  36743. };
  36744. }
  36745. var bind$4 = bind;
  36746. var InsideZoomView = DataZoomView.extend({
  36747. type: 'dataZoom.inside',
  36748. /**
  36749. * @override
  36750. */
  36751. init: function (ecModel, api) {
  36752. /**
  36753. * 'throttle' is used in this.dispatchAction, so we save range
  36754. * to avoid missing some 'pan' info.
  36755. * @private
  36756. * @type {Array.<number>}
  36757. */
  36758. this._range;
  36759. },
  36760. /**
  36761. * @override
  36762. */
  36763. render: function (dataZoomModel, ecModel, api, payload) {
  36764. InsideZoomView.superApply(this, 'render', arguments);
  36765. // Notice: origin this._range should be maintained, and should not be re-fetched
  36766. // from dataZoomModel when payload.type is 'dataZoom', otherwise 'pan' or 'zoom'
  36767. // info will be missed because of 'throttle' of this.dispatchAction.
  36768. if (shouldRecordRange(payload, dataZoomModel.id)) {
  36769. this._range = dataZoomModel.getPercentRange();
  36770. }
  36771. // Reset controllers.
  36772. each$1(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  36773. var allCoordIds = map(coordInfoList, function (coordInfo) {
  36774. return generateCoordId(coordInfo.model);
  36775. });
  36776. each$1(coordInfoList, function (coordInfo) {
  36777. var coordModel = coordInfo.model;
  36778. var dataZoomOption = dataZoomModel.option;
  36779. register$1(
  36780. api,
  36781. {
  36782. coordId: generateCoordId(coordModel),
  36783. allCoordIds: allCoordIds,
  36784. containsPoint: function (e, x, y) {
  36785. return coordModel.coordinateSystem.containPoint([x, y]);
  36786. },
  36787. dataZoomId: dataZoomModel.id,
  36788. throttleRate: dataZoomModel.get('throttle', true),
  36789. panGetRange: bind$4(this._onPan, this, coordInfo, coordSysName),
  36790. zoomGetRange: bind$4(this._onZoom, this, coordInfo, coordSysName),
  36791. zoomLock: dataZoomOption.zoomLock,
  36792. disabled: dataZoomOption.disabled,
  36793. roamControllerOpt: {
  36794. zoomOnMouseWheel: dataZoomOption.zoomOnMouseWheel,
  36795. moveOnMouseMove: dataZoomOption.moveOnMouseMove,
  36796. preventDefaultMouseMove: dataZoomOption.preventDefaultMouseMove
  36797. }
  36798. }
  36799. );
  36800. }, this);
  36801. }, this);
  36802. },
  36803. /**
  36804. * @override
  36805. */
  36806. dispose: function () {
  36807. unregister$1(this.api, this.dataZoomModel.id);
  36808. InsideZoomView.superApply(this, 'dispose', arguments);
  36809. this._range = null;
  36810. },
  36811. /**
  36812. * @private
  36813. */
  36814. _onPan: function (coordInfo, coordSysName, controller, dx, dy, oldX, oldY, newX, newY) {
  36815. var range = this._range.slice();
  36816. // Calculate transform by the first axis.
  36817. var axisModel = coordInfo.axisModels[0];
  36818. if (!axisModel) {
  36819. return;
  36820. }
  36821. var directionInfo = getDirectionInfo[coordSysName](
  36822. [oldX, oldY], [newX, newY], axisModel, controller, coordInfo
  36823. );
  36824. var percentDelta = directionInfo.signal
  36825. * (range[1] - range[0])
  36826. * directionInfo.pixel / directionInfo.pixelLength;
  36827. sliderMove(percentDelta, range, [0, 100], 'all');
  36828. return (this._range = range);
  36829. },
  36830. /**
  36831. * @private
  36832. */
  36833. _onZoom: function (coordInfo, coordSysName, controller, scale, mouseX, mouseY) {
  36834. var range = this._range.slice();
  36835. // Calculate transform by the first axis.
  36836. var axisModel = coordInfo.axisModels[0];
  36837. if (!axisModel) {
  36838. return;
  36839. }
  36840. var directionInfo = getDirectionInfo[coordSysName](
  36841. null, [mouseX, mouseY], axisModel, controller, coordInfo
  36842. );
  36843. var percentPoint = (
  36844. directionInfo.signal > 0
  36845. ? (directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel)
  36846. : (directionInfo.pixel - directionInfo.pixelStart)
  36847. ) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  36848. scale = Math.max(1 / scale, 0);
  36849. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  36850. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  36851. // Restrict range.
  36852. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  36853. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  36854. return (this._range = range);
  36855. }
  36856. });
  36857. var getDirectionInfo = {
  36858. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  36859. var axis = axisModel.axis;
  36860. var ret = {};
  36861. var rect = coordInfo.model.coordinateSystem.getRect();
  36862. oldPoint = oldPoint || [0, 0];
  36863. if (axis.dim === 'x') {
  36864. ret.pixel = newPoint[0] - oldPoint[0];
  36865. ret.pixelLength = rect.width;
  36866. ret.pixelStart = rect.x;
  36867. ret.signal = axis.inverse ? 1 : -1;
  36868. }
  36869. else { // axis.dim === 'y'
  36870. ret.pixel = newPoint[1] - oldPoint[1];
  36871. ret.pixelLength = rect.height;
  36872. ret.pixelStart = rect.y;
  36873. ret.signal = axis.inverse ? -1 : 1;
  36874. }
  36875. return ret;
  36876. },
  36877. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  36878. var axis = axisModel.axis;
  36879. var ret = {};
  36880. var polar = coordInfo.model.coordinateSystem;
  36881. var radiusExtent = polar.getRadiusAxis().getExtent();
  36882. var angleExtent = polar.getAngleAxis().getExtent();
  36883. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  36884. newPoint = polar.pointToCoord(newPoint);
  36885. if (axisModel.mainType === 'radiusAxis') {
  36886. ret.pixel = newPoint[0] - oldPoint[0];
  36887. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  36888. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  36889. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  36890. ret.pixelStart = radiusExtent[0];
  36891. ret.signal = axis.inverse ? 1 : -1;
  36892. }
  36893. else { // 'angleAxis'
  36894. ret.pixel = newPoint[1] - oldPoint[1];
  36895. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  36896. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  36897. ret.pixelLength = angleExtent[1] - angleExtent[0];
  36898. ret.pixelStart = angleExtent[0];
  36899. ret.signal = axis.inverse ? -1 : 1;
  36900. }
  36901. return ret;
  36902. },
  36903. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  36904. var axis = axisModel.axis;
  36905. var rect = coordInfo.model.coordinateSystem.getRect();
  36906. var ret = {};
  36907. oldPoint = oldPoint || [0, 0];
  36908. if (axis.orient === 'horizontal') {
  36909. ret.pixel = newPoint[0] - oldPoint[0];
  36910. ret.pixelLength = rect.width;
  36911. ret.pixelStart = rect.x;
  36912. ret.signal = axis.inverse ? 1 : -1;
  36913. }
  36914. else { // 'vertical'
  36915. ret.pixel = newPoint[1] - oldPoint[1];
  36916. ret.pixelLength = rect.height;
  36917. ret.pixelStart = rect.y;
  36918. ret.signal = axis.inverse ? -1 : 1;
  36919. }
  36920. return ret;
  36921. }
  36922. };
  36923. registerProcessor(function (ecModel, api) {
  36924. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  36925. // We calculate window and reset axis here but not in model
  36926. // init stage and not after action dispatch handler, because
  36927. // reset should be called after seriesData.restoreData.
  36928. dataZoomModel.eachTargetAxis(resetSingleAxis);
  36929. // Caution: data zoom filtering is order sensitive when using
  36930. // percent range and no min/max/scale set on axis.
  36931. // For example, we have dataZoom definition:
  36932. // [
  36933. // {xAxisIndex: 0, start: 30, end: 70},
  36934. // {yAxisIndex: 0, start: 20, end: 80}
  36935. // ]
  36936. // In this case, [20, 80] of y-dataZoom should be based on data
  36937. // that have filtered by x-dataZoom using range of [30, 70],
  36938. // but should not be based on full raw data. Thus sliding
  36939. // x-dataZoom will change both ranges of xAxis and yAxis,
  36940. // while sliding y-dataZoom will only change the range of yAxis.
  36941. // So we should filter x-axis after reset x-axis immediately,
  36942. // and then reset y-axis and filter y-axis.
  36943. dataZoomModel.eachTargetAxis(filterSingleAxis);
  36944. });
  36945. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  36946. // Fullfill all of the range props so that user
  36947. // is able to get them from chart.getOption().
  36948. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  36949. var percentRange = axisProxy.getDataPercentWindow();
  36950. var valueRange = axisProxy.getDataValueWindow();
  36951. dataZoomModel.setRawRange({
  36952. start: percentRange[0],
  36953. end: percentRange[1],
  36954. startValue: valueRange[0],
  36955. endValue: valueRange[1]
  36956. }, true);
  36957. });
  36958. });
  36959. function resetSingleAxis(dimNames, axisIndex, dataZoomModel) {
  36960. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel);
  36961. }
  36962. function filterSingleAxis(dimNames, axisIndex, dataZoomModel) {
  36963. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel);
  36964. }
  36965. registerAction('dataZoom', function (payload, ecModel) {
  36966. var linkedNodesFinder = createLinkedNodesFinder(
  36967. bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  36968. eachAxisDim$1,
  36969. function (model, dimNames) {
  36970. return model.get(dimNames.axisIndex);
  36971. }
  36972. );
  36973. var effectedModels = [];
  36974. ecModel.eachComponent(
  36975. {mainType: 'dataZoom', query: payload},
  36976. function (model, index) {
  36977. effectedModels.push.apply(
  36978. effectedModels, linkedNodesFinder(model).nodes
  36979. );
  36980. }
  36981. );
  36982. each$1(effectedModels, function (dataZoomModel, index) {
  36983. dataZoomModel.setRawRange({
  36984. start: payload.start,
  36985. end: payload.end,
  36986. startValue: payload.startValue,
  36987. endValue: payload.endValue
  36988. });
  36989. });
  36990. });
  36991. /**
  36992. * DataZoom component entry
  36993. */
  36994. var features = {};
  36995. function register$2(name, ctor) {
  36996. features[name] = ctor;
  36997. }
  36998. function get$5(name) {
  36999. return features[name];
  37000. }
  37001. var ToolboxModel = extendComponentModel({
  37002. type: 'toolbox',
  37003. layoutMode: {
  37004. type: 'box',
  37005. ignoreSize: true
  37006. },
  37007. mergeDefaultAndTheme: function (option) {
  37008. ToolboxModel.superApply(this, 'mergeDefaultAndTheme', arguments);
  37009. each$1(this.option.feature, function (featureOpt, featureName) {
  37010. var Feature = get$5(featureName);
  37011. Feature && merge(featureOpt, Feature.defaultOption);
  37012. });
  37013. },
  37014. defaultOption: {
  37015. show: true,
  37016. z: 6,
  37017. zlevel: 0,
  37018. orient: 'horizontal',
  37019. left: 'right',
  37020. top: 'top',
  37021. // right
  37022. // bottom
  37023. backgroundColor: 'transparent',
  37024. borderColor: '#ccc',
  37025. borderRadius: 0,
  37026. borderWidth: 0,
  37027. padding: 5,
  37028. itemSize: 15,
  37029. itemGap: 8,
  37030. showTitle: true,
  37031. iconStyle: {
  37032. normal: {
  37033. borderColor: '#666',
  37034. color: 'none'
  37035. },
  37036. emphasis: {
  37037. borderColor: '#3E98C5'
  37038. }
  37039. }
  37040. // textStyle: {},
  37041. // feature
  37042. }
  37043. });
  37044. extendComponentView({
  37045. type: 'toolbox',
  37046. render: function (toolboxModel, ecModel, api, payload) {
  37047. var group = this.group;
  37048. group.removeAll();
  37049. if (!toolboxModel.get('show')) {
  37050. return;
  37051. }
  37052. var itemSize = +toolboxModel.get('itemSize');
  37053. var featureOpts = toolboxModel.get('feature') || {};
  37054. var features = this._features || (this._features = {});
  37055. var featureNames = [];
  37056. each$1(featureOpts, function (opt, name) {
  37057. featureNames.push(name);
  37058. });
  37059. (new DataDiffer(this._featureNames || [], featureNames))
  37060. .add(processFeature)
  37061. .update(processFeature)
  37062. .remove(curry(processFeature, null))
  37063. .execute();
  37064. // Keep for diff.
  37065. this._featureNames = featureNames;
  37066. function processFeature(newIndex, oldIndex) {
  37067. var featureName = featureNames[newIndex];
  37068. var oldName = featureNames[oldIndex];
  37069. var featureOpt = featureOpts[featureName];
  37070. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  37071. var feature;
  37072. if (featureName && !oldName) { // Create
  37073. if (isUserFeatureName(featureName)) {
  37074. feature = {
  37075. model: featureModel,
  37076. onclick: featureModel.option.onclick,
  37077. featureName: featureName
  37078. };
  37079. }
  37080. else {
  37081. var Feature = get$5(featureName);
  37082. if (!Feature) {
  37083. return;
  37084. }
  37085. feature = new Feature(featureModel, ecModel, api);
  37086. }
  37087. features[featureName] = feature;
  37088. }
  37089. else {
  37090. feature = features[oldName];
  37091. // If feature does not exsit.
  37092. if (!feature) {
  37093. return;
  37094. }
  37095. feature.model = featureModel;
  37096. feature.ecModel = ecModel;
  37097. feature.api = api;
  37098. }
  37099. if (!featureName && oldName) {
  37100. feature.dispose && feature.dispose(ecModel, api);
  37101. return;
  37102. }
  37103. if (!featureModel.get('show') || feature.unusable) {
  37104. feature.remove && feature.remove(ecModel, api);
  37105. return;
  37106. }
  37107. createIconPaths(featureModel, feature, featureName);
  37108. featureModel.setIconStatus = function (iconName, status) {
  37109. var option = this.option;
  37110. var iconPaths = this.iconPaths;
  37111. option.iconStatus = option.iconStatus || {};
  37112. option.iconStatus[iconName] = status;
  37113. // FIXME
  37114. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  37115. };
  37116. if (feature.render) {
  37117. feature.render(featureModel, ecModel, api, payload);
  37118. }
  37119. }
  37120. function createIconPaths(featureModel, feature, featureName) {
  37121. var iconStyleModel = featureModel.getModel('iconStyle');
  37122. // If one feature has mutiple icon. they are orginaized as
  37123. // {
  37124. // icon: {
  37125. // foo: '',
  37126. // bar: ''
  37127. // },
  37128. // title: {
  37129. // foo: '',
  37130. // bar: ''
  37131. // }
  37132. // }
  37133. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  37134. var titles = featureModel.get('title') || {};
  37135. if (typeof icons === 'string') {
  37136. var icon = icons;
  37137. var title = titles;
  37138. icons = {};
  37139. titles = {};
  37140. icons[featureName] = icon;
  37141. titles[featureName] = title;
  37142. }
  37143. var iconPaths = featureModel.iconPaths = {};
  37144. each$1(icons, function (iconStr, iconName) {
  37145. var path = createIcon(
  37146. iconStr,
  37147. {},
  37148. {
  37149. x: -itemSize / 2,
  37150. y: -itemSize / 2,
  37151. width: itemSize,
  37152. height: itemSize
  37153. }
  37154. );
  37155. path.setStyle(iconStyleModel.getModel('normal').getItemStyle());
  37156. path.hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  37157. setHoverStyle(path);
  37158. if (toolboxModel.get('showTitle')) {
  37159. path.__title = titles[iconName];
  37160. path.on('mouseover', function () {
  37161. // Should not reuse above hoverStyle, which might be modified.
  37162. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  37163. path.setStyle({
  37164. text: titles[iconName],
  37165. textPosition: hoverStyle.textPosition || 'bottom',
  37166. textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
  37167. textAlign: hoverStyle.textAlign || 'center'
  37168. });
  37169. })
  37170. .on('mouseout', function () {
  37171. path.setStyle({
  37172. textFill: null
  37173. });
  37174. });
  37175. }
  37176. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  37177. group.add(path);
  37178. path.on('click', bind(
  37179. feature.onclick, feature, ecModel, api, iconName
  37180. ));
  37181. iconPaths[iconName] = path;
  37182. });
  37183. }
  37184. layout$1(group, toolboxModel, api);
  37185. // Render background after group is layout
  37186. // FIXME
  37187. group.add(makeBackground(group.getBoundingRect(), toolboxModel));
  37188. // Adjust icon title positions to avoid them out of screen
  37189. group.eachChild(function (icon) {
  37190. var titleText = icon.__title;
  37191. var hoverStyle = icon.hoverStyle;
  37192. // May be background element
  37193. if (hoverStyle && titleText) {
  37194. var rect = getBoundingRect(
  37195. titleText, makeFont(hoverStyle)
  37196. );
  37197. var offsetX = icon.position[0] + group.position[0];
  37198. var offsetY = icon.position[1] + group.position[1] + itemSize;
  37199. var needPutOnTop = false;
  37200. if (offsetY + rect.height > api.getHeight()) {
  37201. hoverStyle.textPosition = 'top';
  37202. needPutOnTop = true;
  37203. }
  37204. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  37205. if (offsetX + rect.width / 2 > api.getWidth()) {
  37206. hoverStyle.textPosition = ['100%', topOffset];
  37207. hoverStyle.textAlign = 'right';
  37208. }
  37209. else if (offsetX - rect.width / 2 < 0) {
  37210. hoverStyle.textPosition = [0, topOffset];
  37211. hoverStyle.textAlign = 'left';
  37212. }
  37213. }
  37214. });
  37215. },
  37216. updateView: function (toolboxModel, ecModel, api, payload) {
  37217. each$1(this._features, function (feature) {
  37218. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  37219. });
  37220. },
  37221. updateLayout: function (toolboxModel, ecModel, api, payload) {
  37222. each$1(this._features, function (feature) {
  37223. feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  37224. });
  37225. },
  37226. remove: function (ecModel, api) {
  37227. each$1(this._features, function (feature) {
  37228. feature.remove && feature.remove(ecModel, api);
  37229. });
  37230. this.group.removeAll();
  37231. },
  37232. dispose: function (ecModel, api) {
  37233. each$1(this._features, function (feature) {
  37234. feature.dispose && feature.dispose(ecModel, api);
  37235. });
  37236. }
  37237. });
  37238. function isUserFeatureName(featureName) {
  37239. return featureName.indexOf('my') === 0;
  37240. }
  37241. var lang = {
  37242. toolbox: {
  37243. brush: {
  37244. title: {
  37245. rect: 'Box Select',
  37246. polygon: 'Lasso Select',
  37247. lineX: 'Horizontally Select',
  37248. lineY: 'Vertically Select',
  37249. keep: 'Keep Selections',
  37250. clear: 'Clear Selections'
  37251. }
  37252. },
  37253. dataView: {
  37254. title: 'Data View',
  37255. lang: ['Data View', 'Close', 'Refresh']
  37256. },
  37257. dataZoom: {
  37258. title: {
  37259. zoom: 'Zoom',
  37260. back: 'Zoom Reset'
  37261. }
  37262. },
  37263. magicType: {
  37264. title: {
  37265. line: 'Switch to Line Chart',
  37266. bar: 'Switch to Bar Chart',
  37267. stack: 'Stack',
  37268. tiled: 'Tile'
  37269. }
  37270. },
  37271. restore: {
  37272. title: 'Restore'
  37273. },
  37274. saveAsImage: {
  37275. title: 'Save as Image',
  37276. lang: ['Right Click to Save Image']
  37277. }
  37278. }
  37279. };
  37280. var saveAsImageLang = lang.toolbox.saveAsImage;
  37281. function SaveAsImage(model) {
  37282. this.model = model;
  37283. }
  37284. SaveAsImage.defaultOption = {
  37285. show: true,
  37286. 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',
  37287. title: saveAsImageLang.title,
  37288. type: 'png',
  37289. // Default use option.backgroundColor
  37290. // backgroundColor: '#fff',
  37291. name: '',
  37292. excludeComponents: ['toolbox'],
  37293. pixelRatio: 1,
  37294. lang: saveAsImageLang.lang.slice()
  37295. };
  37296. SaveAsImage.prototype.unusable = !env$1.canvasSupported;
  37297. var proto = SaveAsImage.prototype;
  37298. proto.onclick = function (ecModel, api) {
  37299. var model = this.model;
  37300. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  37301. var $a = document.createElement('a');
  37302. var type = model.get('type', true) || 'png';
  37303. $a.download = title + '.' + type;
  37304. $a.target = '_blank';
  37305. var url = api.getConnectedDataURL({
  37306. type: type,
  37307. backgroundColor: model.get('backgroundColor', true)
  37308. || ecModel.get('backgroundColor') || '#fff',
  37309. excludeComponents: model.get('excludeComponents'),
  37310. pixelRatio: model.get('pixelRatio')
  37311. });
  37312. $a.href = url;
  37313. // Chrome and Firefox
  37314. if (typeof MouseEvent === 'function' && !env$1.browser.ie && !env$1.browser.edge) {
  37315. var evt = new MouseEvent('click', {
  37316. view: window,
  37317. bubbles: true,
  37318. cancelable: false
  37319. });
  37320. $a.dispatchEvent(evt);
  37321. }
  37322. // IE
  37323. else {
  37324. if (window.navigator.msSaveOrOpenBlob) {
  37325. var bstr = atob(url.split(',')[1]);
  37326. var n = bstr.length;
  37327. var u8arr = new Uint8Array(n);
  37328. while(n--) {
  37329. u8arr[n] = bstr.charCodeAt(n);
  37330. }
  37331. var blob = new Blob([u8arr]);
  37332. window.navigator.msSaveOrOpenBlob(blob, title + '.' + type);
  37333. }
  37334. else {
  37335. var lang$$1 = model.get('lang');
  37336. var html = '' +
  37337. '<body style="margin:0;">' +
  37338. '<img src="' + url + '" style="max-width:100%;" title="' + ((lang$$1 && lang$$1[0]) || '') + '" />' +
  37339. '</body>';
  37340. var tab = window.open();
  37341. tab.document.write(html);
  37342. }
  37343. }
  37344. };
  37345. register$2(
  37346. 'saveAsImage', SaveAsImage
  37347. );
  37348. var magicTypeLang = lang.toolbox.magicType;
  37349. function MagicType(model) {
  37350. this.model = model;
  37351. }
  37352. MagicType.defaultOption = {
  37353. show: true,
  37354. type: [],
  37355. // Icon group
  37356. icon: {
  37357. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  37358. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  37359. 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
  37360. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  37361. },
  37362. // `line`, `bar`, `stack`, `tiled`
  37363. title: clone(magicTypeLang.title),
  37364. option: {},
  37365. seriesIndex: {}
  37366. };
  37367. var proto$1 = MagicType.prototype;
  37368. proto$1.getIcons = function () {
  37369. var model = this.model;
  37370. var availableIcons = model.get('icon');
  37371. var icons = {};
  37372. each$1(model.get('type'), function (type) {
  37373. if (availableIcons[type]) {
  37374. icons[type] = availableIcons[type];
  37375. }
  37376. });
  37377. return icons;
  37378. };
  37379. var seriesOptGenreator = {
  37380. 'line': function (seriesType, seriesId, seriesModel, model) {
  37381. if (seriesType === 'bar') {
  37382. return merge({
  37383. id: seriesId,
  37384. type: 'line',
  37385. // Preserve data related option
  37386. data: seriesModel.get('data'),
  37387. stack: seriesModel.get('stack'),
  37388. markPoint: seriesModel.get('markPoint'),
  37389. markLine: seriesModel.get('markLine')
  37390. }, model.get('option.line') || {}, true);
  37391. }
  37392. },
  37393. 'bar': function (seriesType, seriesId, seriesModel, model) {
  37394. if (seriesType === 'line') {
  37395. return merge({
  37396. id: seriesId,
  37397. type: 'bar',
  37398. // Preserve data related option
  37399. data: seriesModel.get('data'),
  37400. stack: seriesModel.get('stack'),
  37401. markPoint: seriesModel.get('markPoint'),
  37402. markLine: seriesModel.get('markLine')
  37403. }, model.get('option.bar') || {}, true);
  37404. }
  37405. },
  37406. 'stack': function (seriesType, seriesId, seriesModel, model) {
  37407. if (seriesType === 'line' || seriesType === 'bar') {
  37408. return merge({
  37409. id: seriesId,
  37410. stack: '__ec_magicType_stack__'
  37411. }, model.get('option.stack') || {}, true);
  37412. }
  37413. },
  37414. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  37415. if (seriesType === 'line' || seriesType === 'bar') {
  37416. return merge({
  37417. id: seriesId,
  37418. stack: ''
  37419. }, model.get('option.tiled') || {}, true);
  37420. }
  37421. }
  37422. };
  37423. var radioTypes = [
  37424. ['line', 'bar'],
  37425. ['stack', 'tiled']
  37426. ];
  37427. proto$1.onclick = function (ecModel, api, type) {
  37428. var model = this.model;
  37429. var seriesIndex = model.get('seriesIndex.' + type);
  37430. // Not supported magicType
  37431. if (!seriesOptGenreator[type]) {
  37432. return;
  37433. }
  37434. var newOption = {
  37435. series: []
  37436. };
  37437. var generateNewSeriesTypes = function (seriesModel) {
  37438. var seriesType = seriesModel.subType;
  37439. var seriesId = seriesModel.id;
  37440. var newSeriesOpt = seriesOptGenreator[type](
  37441. seriesType, seriesId, seriesModel, model
  37442. );
  37443. if (newSeriesOpt) {
  37444. // PENDING If merge original option?
  37445. defaults(newSeriesOpt, seriesModel.option);
  37446. newOption.series.push(newSeriesOpt);
  37447. }
  37448. // Modify boundaryGap
  37449. var coordSys = seriesModel.coordinateSystem;
  37450. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  37451. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  37452. if (categoryAxis) {
  37453. var axisDim = categoryAxis.dim;
  37454. var axisType = axisDim + 'Axis';
  37455. var axisModel = ecModel.queryComponents({
  37456. mainType: axisType,
  37457. index: seriesModel.get(name + 'Index'),
  37458. id: seriesModel.get(name + 'Id')
  37459. })[0];
  37460. var axisIndex = axisModel.componentIndex;
  37461. newOption[axisType] = newOption[axisType] || [];
  37462. for (var i = 0; i <= axisIndex; i++) {
  37463. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  37464. }
  37465. newOption[axisType][axisIndex].boundaryGap = type === 'bar' ? true : false;
  37466. }
  37467. }
  37468. };
  37469. each$1(radioTypes, function (radio) {
  37470. if (indexOf(radio, type) >= 0) {
  37471. each$1(radio, function (item) {
  37472. model.setIconStatus(item, 'normal');
  37473. });
  37474. }
  37475. });
  37476. model.setIconStatus(type, 'emphasis');
  37477. ecModel.eachComponent(
  37478. {
  37479. mainType: 'series',
  37480. query: seriesIndex == null ? null : {
  37481. seriesIndex: seriesIndex
  37482. }
  37483. }, generateNewSeriesTypes
  37484. );
  37485. api.dispatchAction({
  37486. type: 'changeMagicType',
  37487. currentType: type,
  37488. newOption: newOption
  37489. });
  37490. };
  37491. registerAction({
  37492. type: 'changeMagicType',
  37493. event: 'magicTypeChanged',
  37494. update: 'prepareAndUpdate'
  37495. }, function (payload, ecModel) {
  37496. ecModel.mergeOption(payload.newOption);
  37497. });
  37498. register$2('magicType', MagicType);
  37499. var dataViewLang = lang.toolbox.dataView;
  37500. var BLOCK_SPLITER = new Array(60).join('-');
  37501. var ITEM_SPLITER = '\t';
  37502. /**
  37503. * Group series into two types
  37504. * 1. on category axis, like line, bar
  37505. * 2. others, like scatter, pie
  37506. * @param {module:echarts/model/Global} ecModel
  37507. * @return {Object}
  37508. * @inner
  37509. */
  37510. function groupSeries(ecModel) {
  37511. var seriesGroupByCategoryAxis = {};
  37512. var otherSeries = [];
  37513. var meta = [];
  37514. ecModel.eachRawSeries(function (seriesModel) {
  37515. var coordSys = seriesModel.coordinateSystem;
  37516. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  37517. var baseAxis = coordSys.getBaseAxis();
  37518. if (baseAxis.type === 'category') {
  37519. var key = baseAxis.dim + '_' + baseAxis.index;
  37520. if (!seriesGroupByCategoryAxis[key]) {
  37521. seriesGroupByCategoryAxis[key] = {
  37522. categoryAxis: baseAxis,
  37523. valueAxis: coordSys.getOtherAxis(baseAxis),
  37524. series: []
  37525. };
  37526. meta.push({
  37527. axisDim: baseAxis.dim,
  37528. axisIndex: baseAxis.index
  37529. });
  37530. }
  37531. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  37532. }
  37533. else {
  37534. otherSeries.push(seriesModel);
  37535. }
  37536. }
  37537. else {
  37538. otherSeries.push(seriesModel);
  37539. }
  37540. });
  37541. return {
  37542. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  37543. other: otherSeries,
  37544. meta: meta
  37545. };
  37546. }
  37547. /**
  37548. * Assemble content of series on cateogory axis
  37549. * @param {Array.<module:echarts/model/Series>} series
  37550. * @return {string}
  37551. * @inner
  37552. */
  37553. function assembleSeriesWithCategoryAxis(series) {
  37554. var tables = [];
  37555. each$1(series, function (group, key) {
  37556. var categoryAxis = group.categoryAxis;
  37557. var valueAxis = group.valueAxis;
  37558. var valueAxisDim = valueAxis.dim;
  37559. var headers = [' '].concat(map(group.series, function (series) {
  37560. return series.name;
  37561. }));
  37562. var columns = [categoryAxis.model.getCategories()];
  37563. each$1(group.series, function (series) {
  37564. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  37565. return val;
  37566. }));
  37567. });
  37568. // Assemble table content
  37569. var lines = [headers.join(ITEM_SPLITER)];
  37570. for (var i = 0; i < columns[0].length; i++) {
  37571. var items = [];
  37572. for (var j = 0; j < columns.length; j++) {
  37573. items.push(columns[j][i]);
  37574. }
  37575. lines.push(items.join(ITEM_SPLITER));
  37576. }
  37577. tables.push(lines.join('\n'));
  37578. });
  37579. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  37580. }
  37581. /**
  37582. * Assemble content of other series
  37583. * @param {Array.<module:echarts/model/Series>} series
  37584. * @return {string}
  37585. * @inner
  37586. */
  37587. function assembleOtherSeries(series) {
  37588. return map(series, function (series) {
  37589. var data = series.getRawData();
  37590. var lines = [series.name];
  37591. var vals = [];
  37592. data.each(data.dimensions, function () {
  37593. var argLen = arguments.length;
  37594. var dataIndex = arguments[argLen - 1];
  37595. var name = data.getName(dataIndex);
  37596. for (var i = 0; i < argLen - 1; i++) {
  37597. vals[i] = arguments[i];
  37598. }
  37599. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  37600. });
  37601. return lines.join('\n');
  37602. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  37603. }
  37604. /**
  37605. * @param {module:echarts/model/Global}
  37606. * @return {Object}
  37607. * @inner
  37608. */
  37609. function getContentFromModel(ecModel) {
  37610. var result = groupSeries(ecModel);
  37611. return {
  37612. value: filter([
  37613. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  37614. assembleOtherSeries(result.other)
  37615. ], function (str) {
  37616. return str.replace(/[\n\t\s]/g, '');
  37617. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  37618. meta: result.meta
  37619. };
  37620. }
  37621. function trim(str) {
  37622. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  37623. }
  37624. /**
  37625. * If a block is tsv format
  37626. */
  37627. function isTSVFormat(block) {
  37628. // Simple method to find out if a block is tsv format
  37629. var firstLine = block.slice(0, block.indexOf('\n'));
  37630. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  37631. return true;
  37632. }
  37633. }
  37634. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  37635. /**
  37636. * @param {string} tsv
  37637. * @return {Object}
  37638. */
  37639. function parseTSVContents(tsv) {
  37640. var tsvLines = tsv.split(/\n+/g);
  37641. var headers = trim(tsvLines.shift()).split(itemSplitRegex);
  37642. var categories = [];
  37643. var series = map(headers, function (header) {
  37644. return {
  37645. name: header,
  37646. data: []
  37647. };
  37648. });
  37649. for (var i = 0; i < tsvLines.length; i++) {
  37650. var items = trim(tsvLines[i]).split(itemSplitRegex);
  37651. categories.push(items.shift());
  37652. for (var j = 0; j < items.length; j++) {
  37653. series[j] && (series[j].data[i] = items[j]);
  37654. }
  37655. }
  37656. return {
  37657. series: series,
  37658. categories: categories
  37659. };
  37660. }
  37661. /**
  37662. * @param {string} str
  37663. * @return {Array.<Object>}
  37664. * @inner
  37665. */
  37666. function parseListContents(str) {
  37667. var lines = str.split(/\n+/g);
  37668. var seriesName = trim(lines.shift());
  37669. var data = [];
  37670. for (var i = 0; i < lines.length; i++) {
  37671. var items = trim(lines[i]).split(itemSplitRegex);
  37672. var name = '';
  37673. var value;
  37674. var hasName = false;
  37675. if (isNaN(items[0])) { // First item is name
  37676. hasName = true;
  37677. name = items[0];
  37678. items = items.slice(1);
  37679. data[i] = {
  37680. name: name,
  37681. value: []
  37682. };
  37683. value = data[i].value;
  37684. }
  37685. else {
  37686. value = data[i] = [];
  37687. }
  37688. for (var j = 0; j < items.length; j++) {
  37689. value.push(+items[j]);
  37690. }
  37691. if (value.length === 1) {
  37692. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  37693. }
  37694. }
  37695. return {
  37696. name: seriesName,
  37697. data: data
  37698. };
  37699. }
  37700. /**
  37701. * @param {string} str
  37702. * @param {Array.<Object>} blockMetaList
  37703. * @return {Object}
  37704. * @inner
  37705. */
  37706. function parseContents(str, blockMetaList) {
  37707. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  37708. var newOption = {
  37709. series: []
  37710. };
  37711. each$1(blocks, function (block, idx) {
  37712. if (isTSVFormat(block)) {
  37713. var result = parseTSVContents(block);
  37714. var blockMeta = blockMetaList[idx];
  37715. var axisKey = blockMeta.axisDim + 'Axis';
  37716. if (blockMeta) {
  37717. newOption[axisKey] = newOption[axisKey] || [];
  37718. newOption[axisKey][blockMeta.axisIndex] = {
  37719. data: result.categories
  37720. };
  37721. newOption.series = newOption.series.concat(result.series);
  37722. }
  37723. }
  37724. else {
  37725. var result = parseListContents(block);
  37726. newOption.series.push(result);
  37727. }
  37728. });
  37729. return newOption;
  37730. }
  37731. /**
  37732. * @alias {module:echarts/component/toolbox/feature/DataView}
  37733. * @constructor
  37734. * @param {module:echarts/model/Model} model
  37735. */
  37736. function DataView(model) {
  37737. this._dom = null;
  37738. this.model = model;
  37739. }
  37740. DataView.defaultOption = {
  37741. show: true,
  37742. readOnly: false,
  37743. optionToContent: null,
  37744. contentToOption: null,
  37745. 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',
  37746. title: clone(dataViewLang.title),
  37747. lang: clone(dataViewLang.lang),
  37748. backgroundColor: '#fff',
  37749. textColor: '#000',
  37750. textareaColor: '#fff',
  37751. textareaBorderColor: '#333',
  37752. buttonColor: '#c23531',
  37753. buttonTextColor: '#fff'
  37754. };
  37755. DataView.prototype.onclick = function (ecModel, api) {
  37756. var container = api.getDom();
  37757. var model = this.model;
  37758. if (this._dom) {
  37759. container.removeChild(this._dom);
  37760. }
  37761. var root = document.createElement('div');
  37762. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  37763. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  37764. // Create elements
  37765. var header = document.createElement('h4');
  37766. var lang$$1 = model.get('lang') || [];
  37767. header.innerHTML = lang$$1[0] || model.get('title');
  37768. header.style.cssText = 'margin: 10px 20px;';
  37769. header.style.color = model.get('textColor');
  37770. var viewMain = document.createElement('div');
  37771. var textarea = document.createElement('textarea');
  37772. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  37773. var optionToContent = model.get('optionToContent');
  37774. var contentToOption = model.get('contentToOption');
  37775. var result = getContentFromModel(ecModel);
  37776. if (typeof optionToContent === 'function') {
  37777. var htmlOrDom = optionToContent(api.getOption());
  37778. if (typeof htmlOrDom === 'string') {
  37779. viewMain.innerHTML = htmlOrDom;
  37780. }
  37781. else if (isDom(htmlOrDom)) {
  37782. viewMain.appendChild(htmlOrDom);
  37783. }
  37784. }
  37785. else {
  37786. // Use default textarea
  37787. viewMain.appendChild(textarea);
  37788. textarea.readOnly = model.get('readOnly');
  37789. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  37790. textarea.style.color = model.get('textColor');
  37791. textarea.style.borderColor = model.get('textareaBorderColor');
  37792. textarea.style.backgroundColor = model.get('textareaColor');
  37793. textarea.value = result.value;
  37794. }
  37795. var blockMetaList = result.meta;
  37796. var buttonContainer = document.createElement('div');
  37797. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  37798. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  37799. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  37800. var closeButton = document.createElement('div');
  37801. var refreshButton = document.createElement('div');
  37802. buttonStyle += ';background-color:' + model.get('buttonColor');
  37803. buttonStyle += ';color:' + model.get('buttonTextColor');
  37804. var self = this;
  37805. function close() {
  37806. container.removeChild(root);
  37807. self._dom = null;
  37808. }
  37809. addEventListener(closeButton, 'click', close);
  37810. addEventListener(refreshButton, 'click', function () {
  37811. var newOption;
  37812. try {
  37813. if (typeof contentToOption === 'function') {
  37814. newOption = contentToOption(viewMain, api.getOption());
  37815. }
  37816. else {
  37817. newOption = parseContents(textarea.value, blockMetaList);
  37818. }
  37819. }
  37820. catch (e) {
  37821. close();
  37822. throw new Error('Data view format error ' + e);
  37823. }
  37824. if (newOption) {
  37825. api.dispatchAction({
  37826. type: 'changeDataView',
  37827. newOption: newOption
  37828. });
  37829. }
  37830. close();
  37831. });
  37832. closeButton.innerHTML = lang$$1[1];
  37833. refreshButton.innerHTML = lang$$1[2];
  37834. refreshButton.style.cssText = buttonStyle;
  37835. closeButton.style.cssText = buttonStyle;
  37836. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  37837. buttonContainer.appendChild(closeButton);
  37838. // http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
  37839. addEventListener(textarea, 'keydown', function (e) {
  37840. if ((e.keyCode || e.which) === 9) {
  37841. // get caret position/selection
  37842. var val = this.value;
  37843. var start = this.selectionStart;
  37844. var end = this.selectionEnd;
  37845. // set textarea value to: text before caret + tab + text after caret
  37846. this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
  37847. // put caret at right position again
  37848. this.selectionStart = this.selectionEnd = start + 1;
  37849. // prevent the focus lose
  37850. stop(e);
  37851. }
  37852. });
  37853. root.appendChild(header);
  37854. root.appendChild(viewMain);
  37855. root.appendChild(buttonContainer);
  37856. viewMain.style.height = (container.clientHeight - 80) + 'px';
  37857. container.appendChild(root);
  37858. this._dom = root;
  37859. };
  37860. DataView.prototype.remove = function (ecModel, api) {
  37861. this._dom && api.getDom().removeChild(this._dom);
  37862. };
  37863. DataView.prototype.dispose = function (ecModel, api) {
  37864. this.remove(ecModel, api);
  37865. };
  37866. /**
  37867. * @inner
  37868. */
  37869. function tryMergeDataOption(newData, originalData) {
  37870. return map(newData, function (newVal, idx) {
  37871. var original = originalData && originalData[idx];
  37872. if (isObject(original) && !isArray(original)) {
  37873. if (isObject(newVal) && !isArray(newVal)) {
  37874. newVal = newVal.value;
  37875. }
  37876. // Original data has option
  37877. return defaults({
  37878. value: newVal
  37879. }, original);
  37880. }
  37881. else {
  37882. return newVal;
  37883. }
  37884. });
  37885. }
  37886. register$2('dataView', DataView);
  37887. registerAction({
  37888. type: 'changeDataView',
  37889. event: 'dataViewChanged',
  37890. update: 'prepareAndUpdate'
  37891. }, function (payload, ecModel) {
  37892. var newSeriesOptList = [];
  37893. each$1(payload.newOption.series, function (seriesOpt) {
  37894. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  37895. if (!seriesModel) {
  37896. // New created series
  37897. // Geuss the series type
  37898. newSeriesOptList.push(extend({
  37899. // Default is scatter
  37900. type: 'scatter'
  37901. }, seriesOpt));
  37902. }
  37903. else {
  37904. var originalData = seriesModel.get('data');
  37905. newSeriesOptList.push({
  37906. name: seriesOpt.name,
  37907. data: tryMergeDataOption(seriesOpt.data, originalData)
  37908. });
  37909. }
  37910. });
  37911. ecModel.mergeOption(defaults({
  37912. series: newSeriesOptList
  37913. }, payload.newOption));
  37914. });
  37915. var curry$6 = curry;
  37916. var each$19 = each$1;
  37917. var map$3 = map;
  37918. var mathMin$4 = Math.min;
  37919. var mathMax$4 = Math.max;
  37920. var mathPow$2 = Math.pow;
  37921. var COVER_Z = 10000;
  37922. var UNSELECT_THRESHOLD = 6;
  37923. var MIN_RESIZE_LINE_WIDTH = 6;
  37924. var MUTEX_RESOURCE_KEY = 'globalPan';
  37925. var DIRECTION_MAP = {
  37926. w: [0, 0],
  37927. e: [0, 1],
  37928. n: [1, 0],
  37929. s: [1, 1]
  37930. };
  37931. var CURSOR_MAP = {
  37932. w: 'ew',
  37933. e: 'ew',
  37934. n: 'ns',
  37935. s: 'ns',
  37936. ne: 'nesw',
  37937. sw: 'nesw',
  37938. nw: 'nwse',
  37939. se: 'nwse'
  37940. };
  37941. var DEFAULT_BRUSH_OPT = {
  37942. brushStyle: {
  37943. lineWidth: 2,
  37944. stroke: 'rgba(0,0,0,0.3)',
  37945. fill: 'rgba(0,0,0,0.1)'
  37946. },
  37947. transformable: true,
  37948. brushMode: 'single',
  37949. removeOnClick: false
  37950. };
  37951. var baseUID = 0;
  37952. /**
  37953. * @alias module:echarts/component/helper/BrushController
  37954. * @constructor
  37955. * @mixin {module:zrender/mixin/Eventful}
  37956. * @event module:echarts/component/helper/BrushController#brush
  37957. * params:
  37958. * areas: Array.<Array>, coord relates to container group,
  37959. * If no container specified, to global.
  37960. * opt {
  37961. * isEnd: boolean,
  37962. * removeOnClick: boolean
  37963. * }
  37964. *
  37965. * @param {module:zrender/zrender~ZRender} zr
  37966. */
  37967. function BrushController(zr) {
  37968. if (__DEV__) {
  37969. assert(zr);
  37970. }
  37971. Eventful.call(this);
  37972. /**
  37973. * @type {module:zrender/zrender~ZRender}
  37974. * @private
  37975. */
  37976. this._zr = zr;
  37977. /**
  37978. * @type {module:zrender/container/Group}
  37979. * @readOnly
  37980. */
  37981. this.group = new Group();
  37982. /**
  37983. * Only for drawing (after enabledBrush).
  37984. * 'line', 'rect', 'polygon' or false
  37985. * If passing false/null/undefined, disable brush.
  37986. * If passing 'auto', determined by panel.defaultBrushType
  37987. * @private
  37988. * @type {string}
  37989. */
  37990. this._brushType;
  37991. /**
  37992. * Only for drawing (after enabledBrush).
  37993. *
  37994. * @private
  37995. * @type {Object}
  37996. */
  37997. this._brushOption;
  37998. /**
  37999. * @private
  38000. * @type {Object}
  38001. */
  38002. this._panels;
  38003. /**
  38004. * @private
  38005. * @type {Array.<nubmer>}
  38006. */
  38007. this._track = [];
  38008. /**
  38009. * @private
  38010. * @type {boolean}
  38011. */
  38012. this._dragging;
  38013. /**
  38014. * @private
  38015. * @type {Array}
  38016. */
  38017. this._covers = [];
  38018. /**
  38019. * @private
  38020. * @type {moudule:zrender/container/Group}
  38021. */
  38022. this._creatingCover;
  38023. /**
  38024. * `true` means global panel
  38025. * @private
  38026. * @type {module:zrender/container/Group|boolean}
  38027. */
  38028. this._creatingPanel;
  38029. /**
  38030. * @private
  38031. * @type {boolean}
  38032. */
  38033. this._enableGlobalPan;
  38034. /**
  38035. * @private
  38036. * @type {boolean}
  38037. */
  38038. if (__DEV__) {
  38039. this._mounted;
  38040. }
  38041. /**
  38042. * @private
  38043. * @type {string}
  38044. */
  38045. this._uid = 'brushController_' + baseUID++;
  38046. /**
  38047. * @private
  38048. * @type {Object}
  38049. */
  38050. this._handlers = {};
  38051. each$19(mouseHandlers, function (handler, eventName) {
  38052. this._handlers[eventName] = bind(handler, this);
  38053. }, this);
  38054. }
  38055. BrushController.prototype = {
  38056. constructor: BrushController,
  38057. /**
  38058. * If set to null/undefined/false, select disabled.
  38059. * @param {Object} brushOption
  38060. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  38061. * If passing false/null/undefined, disable brush.
  38062. * If passing 'auto', determined by panel.defaultBrushType.
  38063. * ('auto' can not be used in global panel)
  38064. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  38065. * @param {boolean} [brushOption.transformable=true]
  38066. * @param {boolean} [brushOption.removeOnClick=false]
  38067. * @param {Object} [brushOption.brushStyle]
  38068. * @param {number} [brushOption.brushStyle.width]
  38069. * @param {number} [brushOption.brushStyle.lineWidth]
  38070. * @param {string} [brushOption.brushStyle.stroke]
  38071. * @param {string} [brushOption.brushStyle.fill]
  38072. * @param {number} [brushOption.z]
  38073. */
  38074. enableBrush: function (brushOption) {
  38075. if (__DEV__) {
  38076. assert(this._mounted);
  38077. }
  38078. this._brushType && doDisableBrush(this);
  38079. brushOption.brushType && doEnableBrush(this, brushOption);
  38080. return this;
  38081. },
  38082. /**
  38083. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  38084. * Each items: {
  38085. * panelId, // mandatory.
  38086. * clipPath, // mandatory. function.
  38087. * isTargetByCursor, // mandatory. function.
  38088. * defaultBrushType, // optional, only used when brushType is 'auto'.
  38089. * getLinearBrushOtherExtent, // optional. function.
  38090. * }
  38091. */
  38092. setPanels: function (panelOpts) {
  38093. if (panelOpts && panelOpts.length) {
  38094. var panels = this._panels = {};
  38095. each$1(panelOpts, function (panelOpts) {
  38096. panels[panelOpts.panelId] = clone(panelOpts);
  38097. });
  38098. }
  38099. else {
  38100. this._panels = null;
  38101. }
  38102. return this;
  38103. },
  38104. /**
  38105. * @param {Object} [opt]
  38106. * @return {boolean} [opt.enableGlobalPan=false]
  38107. */
  38108. mount: function (opt) {
  38109. opt = opt || {};
  38110. if (__DEV__) {
  38111. this._mounted = true; // should be at first.
  38112. }
  38113. this._enableGlobalPan = opt.enableGlobalPan;
  38114. var thisGroup = this.group;
  38115. this._zr.add(thisGroup);
  38116. thisGroup.attr({
  38117. position: opt.position || [0, 0],
  38118. rotation: opt.rotation || 0,
  38119. scale: opt.scale || [1, 1]
  38120. });
  38121. this._transform = thisGroup.getLocalTransform();
  38122. return this;
  38123. },
  38124. eachCover: function (cb, context) {
  38125. each$19(this._covers, cb, context);
  38126. },
  38127. /**
  38128. * Update covers.
  38129. * @param {Array.<Object>} brushOptionList Like:
  38130. * [
  38131. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  38132. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  38133. * ...
  38134. * ]
  38135. * `brushType` is required in each cover info. (can not be 'auto')
  38136. * `id` is not mandatory.
  38137. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  38138. * If brushOptionList is null/undefined, all covers removed.
  38139. */
  38140. updateCovers: function (brushOptionList) {
  38141. if (__DEV__) {
  38142. assert(this._mounted);
  38143. }
  38144. brushOptionList = map(brushOptionList, function (brushOption) {
  38145. return merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  38146. });
  38147. var tmpIdPrefix = '\0-brush-index-';
  38148. var oldCovers = this._covers;
  38149. var newCovers = this._covers = [];
  38150. var controller = this;
  38151. var creatingCover = this._creatingCover;
  38152. (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
  38153. .add(addOrUpdate)
  38154. .update(addOrUpdate)
  38155. .remove(remove)
  38156. .execute();
  38157. return this;
  38158. function getKey(brushOption, index) {
  38159. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
  38160. + '-' + brushOption.brushType;
  38161. }
  38162. function oldGetKey(cover, index) {
  38163. return getKey(cover.__brushOption, index);
  38164. }
  38165. function addOrUpdate(newIndex, oldIndex) {
  38166. var newBrushOption = brushOptionList[newIndex];
  38167. // Consider setOption in event listener of brushSelect,
  38168. // where updating cover when creating should be forbiden.
  38169. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  38170. newCovers[newIndex] = oldCovers[oldIndex];
  38171. }
  38172. else {
  38173. var cover = newCovers[newIndex] = oldIndex != null
  38174. ? (
  38175. oldCovers[oldIndex].__brushOption = newBrushOption,
  38176. oldCovers[oldIndex]
  38177. )
  38178. : endCreating(controller, createCover(controller, newBrushOption));
  38179. updateCoverAfterCreation(controller, cover);
  38180. }
  38181. }
  38182. function remove(oldIndex) {
  38183. if (oldCovers[oldIndex] !== creatingCover) {
  38184. controller.group.remove(oldCovers[oldIndex]);
  38185. }
  38186. }
  38187. },
  38188. unmount: function () {
  38189. if (__DEV__) {
  38190. if (!this._mounted) {
  38191. return;
  38192. }
  38193. }
  38194. this.enableBrush(false);
  38195. // container may 'removeAll' outside.
  38196. clearCovers(this);
  38197. this._zr.remove(this.group);
  38198. if (__DEV__) {
  38199. this._mounted = false; // should be at last.
  38200. }
  38201. return this;
  38202. },
  38203. dispose: function () {
  38204. this.unmount();
  38205. this.off();
  38206. }
  38207. };
  38208. mixin(BrushController, Eventful);
  38209. function doEnableBrush(controller, brushOption) {
  38210. var zr = controller._zr;
  38211. // Consider roam, which takes globalPan too.
  38212. if (!controller._enableGlobalPan) {
  38213. take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  38214. }
  38215. each$19(controller._handlers, function (handler, eventName) {
  38216. zr.on(eventName, handler);
  38217. });
  38218. controller._brushType = brushOption.brushType;
  38219. controller._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  38220. }
  38221. function doDisableBrush(controller) {
  38222. var zr = controller._zr;
  38223. release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  38224. each$19(controller._handlers, function (handler, eventName) {
  38225. zr.off(eventName, handler);
  38226. });
  38227. controller._brushType = controller._brushOption = null;
  38228. }
  38229. function createCover(controller, brushOption) {
  38230. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  38231. cover.__brushOption = brushOption;
  38232. updateZ$1(cover, brushOption);
  38233. controller.group.add(cover);
  38234. return cover;
  38235. }
  38236. function endCreating(controller, creatingCover) {
  38237. var coverRenderer = getCoverRenderer(creatingCover);
  38238. if (coverRenderer.endCreating) {
  38239. coverRenderer.endCreating(controller, creatingCover);
  38240. updateZ$1(creatingCover, creatingCover.__brushOption);
  38241. }
  38242. return creatingCover;
  38243. }
  38244. function updateCoverShape(controller, cover) {
  38245. var brushOption = cover.__brushOption;
  38246. getCoverRenderer(cover).updateCoverShape(
  38247. controller, cover, brushOption.range, brushOption
  38248. );
  38249. }
  38250. function updateZ$1(cover, brushOption) {
  38251. var z = brushOption.z;
  38252. z == null && (z = COVER_Z);
  38253. cover.traverse(function (el) {
  38254. el.z = z;
  38255. el.z2 = z; // Consider in given container.
  38256. });
  38257. }
  38258. function updateCoverAfterCreation(controller, cover) {
  38259. getCoverRenderer(cover).updateCommon(controller, cover);
  38260. updateCoverShape(controller, cover);
  38261. }
  38262. function getCoverRenderer(cover) {
  38263. return coverRenderers[cover.__brushOption.brushType];
  38264. }
  38265. // return target panel or `true` (means global panel)
  38266. function getPanelByPoint(controller, e, localCursorPoint) {
  38267. var panels = controller._panels;
  38268. if (!panels) {
  38269. return true; // Global panel
  38270. }
  38271. var panel;
  38272. var transform = controller._transform;
  38273. each$19(panels, function (pn) {
  38274. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  38275. });
  38276. return panel;
  38277. }
  38278. // Return a panel or true
  38279. function getPanelByCover(controller, cover) {
  38280. var panels = controller._panels;
  38281. if (!panels) {
  38282. return true; // Global panel
  38283. }
  38284. var panelId = cover.__brushOption.panelId;
  38285. // User may give cover without coord sys info,
  38286. // which is then treated as global panel.
  38287. return panelId != null ? panels[panelId] : true;
  38288. }
  38289. function clearCovers(controller) {
  38290. var covers = controller._covers;
  38291. var originalLength = covers.length;
  38292. each$19(covers, function (cover) {
  38293. controller.group.remove(cover);
  38294. }, controller);
  38295. covers.length = 0;
  38296. return !!originalLength;
  38297. }
  38298. function trigger(controller, opt) {
  38299. var areas = map$3(controller._covers, function (cover) {
  38300. var brushOption = cover.__brushOption;
  38301. var range = clone(brushOption.range);
  38302. return {
  38303. brushType: brushOption.brushType,
  38304. panelId: brushOption.panelId,
  38305. range: range
  38306. };
  38307. });
  38308. controller.trigger('brush', areas, {
  38309. isEnd: !!opt.isEnd,
  38310. removeOnClick: !!opt.removeOnClick
  38311. });
  38312. }
  38313. function shouldShowCover(controller) {
  38314. var track = controller._track;
  38315. if (!track.length) {
  38316. return false;
  38317. }
  38318. var p2 = track[track.length - 1];
  38319. var p1 = track[0];
  38320. var dx = p2[0] - p1[0];
  38321. var dy = p2[1] - p1[1];
  38322. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  38323. return dist > UNSELECT_THRESHOLD;
  38324. }
  38325. function getTrackEnds(track) {
  38326. var tail = track.length - 1;
  38327. tail < 0 && (tail = 0);
  38328. return [track[0], track[tail]];
  38329. }
  38330. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  38331. var cover = new Group();
  38332. cover.add(new Rect({
  38333. name: 'main',
  38334. style: makeStyle(brushOption),
  38335. silent: true,
  38336. draggable: true,
  38337. cursor: 'move',
  38338. drift: curry$6(doDrift, controller, cover, 'nswe'),
  38339. ondragend: curry$6(trigger, controller, {isEnd: true})
  38340. }));
  38341. each$19(
  38342. edgeNames,
  38343. function (name) {
  38344. cover.add(new Rect({
  38345. name: name,
  38346. style: {opacity: 0},
  38347. draggable: true,
  38348. silent: true,
  38349. invisible: true,
  38350. drift: curry$6(doDrift, controller, cover, name),
  38351. ondragend: curry$6(trigger, controller, {isEnd: true})
  38352. }));
  38353. }
  38354. );
  38355. return cover;
  38356. }
  38357. function updateBaseRect(controller, cover, localRange, brushOption) {
  38358. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  38359. var handleSize = mathMax$4(lineWidth, MIN_RESIZE_LINE_WIDTH);
  38360. var x = localRange[0][0];
  38361. var y = localRange[1][0];
  38362. var xa = x - lineWidth / 2;
  38363. var ya = y - lineWidth / 2;
  38364. var x2 = localRange[0][1];
  38365. var y2 = localRange[1][1];
  38366. var x2a = x2 - handleSize + lineWidth / 2;
  38367. var y2a = y2 - handleSize + lineWidth / 2;
  38368. var width = x2 - x;
  38369. var height = y2 - y;
  38370. var widtha = width + lineWidth;
  38371. var heighta = height + lineWidth;
  38372. updateRectShape(controller, cover, 'main', x, y, width, height);
  38373. if (brushOption.transformable) {
  38374. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  38375. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  38376. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  38377. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  38378. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  38379. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  38380. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  38381. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  38382. }
  38383. }
  38384. function updateCommon(controller, cover) {
  38385. var brushOption = cover.__brushOption;
  38386. var transformable = brushOption.transformable;
  38387. var mainEl = cover.childAt(0);
  38388. mainEl.useStyle(makeStyle(brushOption));
  38389. mainEl.attr({
  38390. silent: !transformable,
  38391. cursor: transformable ? 'move' : 'default'
  38392. });
  38393. each$19(
  38394. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'],
  38395. function (name) {
  38396. var el = cover.childOfName(name);
  38397. var globalDir = getGlobalDirection(controller, name);
  38398. el && el.attr({
  38399. silent: !transformable,
  38400. invisible: !transformable,
  38401. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  38402. });
  38403. }
  38404. );
  38405. }
  38406. function updateRectShape(controller, cover, name, x, y, w, h) {
  38407. var el = cover.childOfName(name);
  38408. el && el.setShape(pointsToRect(
  38409. clipByPanel(controller, cover, [[x, y], [x + w, y + h]])
  38410. ));
  38411. }
  38412. function makeStyle(brushOption) {
  38413. return defaults({strokeNoScale: true}, brushOption.brushStyle);
  38414. }
  38415. function formatRectRange(x, y, x2, y2) {
  38416. var min = [mathMin$4(x, x2), mathMin$4(y, y2)];
  38417. var max = [mathMax$4(x, x2), mathMax$4(y, y2)];
  38418. return [
  38419. [min[0], max[0]], // x range
  38420. [min[1], max[1]] // y range
  38421. ];
  38422. }
  38423. function getTransform$1(controller) {
  38424. return getTransform(controller.group);
  38425. }
  38426. function getGlobalDirection(controller, localDirection) {
  38427. if (localDirection.length > 1) {
  38428. localDirection = localDirection.split('');
  38429. var globalDir = [
  38430. getGlobalDirection(controller, localDirection[0]),
  38431. getGlobalDirection(controller, localDirection[1])
  38432. ];
  38433. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  38434. return globalDir.join('');
  38435. }
  38436. else {
  38437. var map$$1 = {w: 'left', e: 'right', n: 'top', s: 'bottom'};
  38438. var inverseMap = {left: 'w', right: 'e', top: 'n', bottom: 's'};
  38439. var globalDir = transformDirection(
  38440. map$$1[localDirection], getTransform$1(controller)
  38441. );
  38442. return inverseMap[globalDir];
  38443. }
  38444. }
  38445. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  38446. var brushOption = cover.__brushOption;
  38447. var rectRange = toRectRange(brushOption.range);
  38448. var localDelta = toLocalDelta(controller, dx, dy);
  38449. each$19(name.split(''), function (namePart) {
  38450. var ind = DIRECTION_MAP[namePart];
  38451. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  38452. });
  38453. brushOption.range = fromRectRange(formatRectRange(
  38454. rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]
  38455. ));
  38456. updateCoverAfterCreation(controller, cover);
  38457. trigger(controller, {isEnd: false});
  38458. }
  38459. function driftPolygon(controller, cover, dx, dy, e) {
  38460. var range = cover.__brushOption.range;
  38461. var localDelta = toLocalDelta(controller, dx, dy);
  38462. each$19(range, function (point) {
  38463. point[0] += localDelta[0];
  38464. point[1] += localDelta[1];
  38465. });
  38466. updateCoverAfterCreation(controller, cover);
  38467. trigger(controller, {isEnd: false});
  38468. }
  38469. function toLocalDelta(controller, dx, dy) {
  38470. var thisGroup = controller.group;
  38471. var localD = thisGroup.transformCoordToLocal(dx, dy);
  38472. var localZero = thisGroup.transformCoordToLocal(0, 0);
  38473. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  38474. }
  38475. function clipByPanel(controller, cover, data) {
  38476. var panel = getPanelByCover(controller, cover);
  38477. return (panel && panel !== true)
  38478. ? panel.clipPath(data, controller._transform)
  38479. : clone(data);
  38480. }
  38481. function pointsToRect(points) {
  38482. var xmin = mathMin$4(points[0][0], points[1][0]);
  38483. var ymin = mathMin$4(points[0][1], points[1][1]);
  38484. var xmax = mathMax$4(points[0][0], points[1][0]);
  38485. var ymax = mathMax$4(points[0][1], points[1][1]);
  38486. return {
  38487. x: xmin,
  38488. y: ymin,
  38489. width: xmax - xmin,
  38490. height: ymax - ymin
  38491. };
  38492. }
  38493. function resetCursor(controller, e, localCursorPoint) {
  38494. // Check active
  38495. if (!controller._brushType) {
  38496. return;
  38497. }
  38498. var zr = controller._zr;
  38499. var covers = controller._covers;
  38500. var currPanel = getPanelByPoint(controller, e, localCursorPoint);
  38501. // Check whether in covers.
  38502. if (!controller._dragging) {
  38503. for (var i = 0; i < covers.length; i++) {
  38504. var brushOption = covers[i].__brushOption;
  38505. if (currPanel
  38506. && (currPanel === true || brushOption.panelId === currPanel.panelId)
  38507. && coverRenderers[brushOption.brushType].contain(
  38508. covers[i], localCursorPoint[0], localCursorPoint[1]
  38509. )
  38510. ) {
  38511. // Use cursor style set on cover.
  38512. return;
  38513. }
  38514. }
  38515. }
  38516. currPanel && zr.setCursorStyle('crosshair');
  38517. }
  38518. function preventDefault(e) {
  38519. var rawE = e.event;
  38520. rawE.preventDefault && rawE.preventDefault();
  38521. }
  38522. function mainShapeContain(cover, x, y) {
  38523. return cover.childOfName('main').contain(x, y);
  38524. }
  38525. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  38526. var creatingCover = controller._creatingCover;
  38527. var panel = controller._creatingPanel;
  38528. var thisBrushOption = controller._brushOption;
  38529. var eventParams;
  38530. controller._track.push(localCursorPoint.slice());
  38531. if (shouldShowCover(controller) || creatingCover) {
  38532. if (panel && !creatingCover) {
  38533. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  38534. var brushOption = clone(thisBrushOption);
  38535. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  38536. brushOption.panelId = panel === true ? null : panel.panelId;
  38537. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  38538. controller._covers.push(creatingCover);
  38539. }
  38540. if (creatingCover) {
  38541. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  38542. var coverBrushOption = creatingCover.__brushOption;
  38543. coverBrushOption.range = coverRenderer.getCreatingRange(
  38544. clipByPanel(controller, creatingCover, controller._track)
  38545. );
  38546. if (isEnd) {
  38547. endCreating(controller, creatingCover);
  38548. coverRenderer.updateCommon(controller, creatingCover);
  38549. }
  38550. updateCoverShape(controller, creatingCover);
  38551. eventParams = {isEnd: isEnd};
  38552. }
  38553. }
  38554. else if (
  38555. isEnd
  38556. && thisBrushOption.brushMode === 'single'
  38557. && thisBrushOption.removeOnClick
  38558. ) {
  38559. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  38560. // But a single click do not clear covers, because user may have casual
  38561. // clicks (for example, click on other component and do not expect covers
  38562. // disappear).
  38563. // Only some cover removed, trigger action, but not every click trigger action.
  38564. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  38565. eventParams = {isEnd: isEnd, removeOnClick: true};
  38566. }
  38567. }
  38568. return eventParams;
  38569. }
  38570. function determineBrushType(brushType, panel) {
  38571. if (brushType === 'auto') {
  38572. if (__DEV__) {
  38573. assert(
  38574. panel && panel.defaultBrushType,
  38575. 'MUST have defaultBrushType when brushType is "atuo"'
  38576. );
  38577. }
  38578. return panel.defaultBrushType;
  38579. }
  38580. return brushType;
  38581. }
  38582. var mouseHandlers = {
  38583. mousedown: function (e) {
  38584. if (this._dragging) {
  38585. // In case some browser do not support globalOut,
  38586. // and release mose out side the browser.
  38587. handleDragEnd.call(this, e);
  38588. }
  38589. else if (!e.target || !e.target.draggable) {
  38590. preventDefault(e);
  38591. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  38592. this._creatingCover = null;
  38593. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  38594. if (panel) {
  38595. this._dragging = true;
  38596. this._track = [localCursorPoint.slice()];
  38597. }
  38598. }
  38599. },
  38600. mousemove: function (e) {
  38601. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  38602. resetCursor(this, e, localCursorPoint);
  38603. if (this._dragging) {
  38604. preventDefault(e);
  38605. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  38606. eventParams && trigger(this, eventParams);
  38607. }
  38608. },
  38609. mouseup: handleDragEnd //,
  38610. // FIXME
  38611. // in tooltip, globalout should not be triggered.
  38612. // globalout: handleDragEnd
  38613. };
  38614. function handleDragEnd(e) {
  38615. if (this._dragging) {
  38616. preventDefault(e);
  38617. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  38618. var eventParams = updateCoverByMouse(this, e, localCursorPoint, true);
  38619. this._dragging = false;
  38620. this._track = [];
  38621. this._creatingCover = null;
  38622. // trigger event shoule be at final, after procedure will be nested.
  38623. eventParams && trigger(this, eventParams);
  38624. }
  38625. }
  38626. /**
  38627. * key: brushType
  38628. * @type {Object}
  38629. */
  38630. var coverRenderers = {
  38631. lineX: getLineRenderer(0),
  38632. lineY: getLineRenderer(1),
  38633. rect: {
  38634. createCover: function (controller, brushOption) {
  38635. return createBaseRectCover(
  38636. curry$6(
  38637. driftRect,
  38638. function (range) {
  38639. return range;
  38640. },
  38641. function (range) {
  38642. return range;
  38643. }
  38644. ),
  38645. controller,
  38646. brushOption,
  38647. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']
  38648. );
  38649. },
  38650. getCreatingRange: function (localTrack) {
  38651. var ends = getTrackEnds(localTrack);
  38652. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  38653. },
  38654. updateCoverShape: function (controller, cover, localRange, brushOption) {
  38655. updateBaseRect(controller, cover, localRange, brushOption);
  38656. },
  38657. updateCommon: updateCommon,
  38658. contain: mainShapeContain
  38659. },
  38660. polygon: {
  38661. createCover: function (controller, brushOption) {
  38662. var cover = new Group();
  38663. // Do not use graphic.Polygon because graphic.Polyline do not close the
  38664. // border of the shape when drawing, which is a better experience for user.
  38665. cover.add(new Polyline({
  38666. name: 'main',
  38667. style: makeStyle(brushOption),
  38668. silent: true
  38669. }));
  38670. return cover;
  38671. },
  38672. getCreatingRange: function (localTrack) {
  38673. return localTrack;
  38674. },
  38675. endCreating: function (controller, cover) {
  38676. cover.remove(cover.childAt(0));
  38677. // Use graphic.Polygon close the shape.
  38678. cover.add(new Polygon({
  38679. name: 'main',
  38680. draggable: true,
  38681. drift: curry$6(driftPolygon, controller, cover),
  38682. ondragend: curry$6(trigger, controller, {isEnd: true})
  38683. }));
  38684. },
  38685. updateCoverShape: function (controller, cover, localRange, brushOption) {
  38686. cover.childAt(0).setShape({
  38687. points: clipByPanel(controller, cover, localRange)
  38688. });
  38689. },
  38690. updateCommon: updateCommon,
  38691. contain: mainShapeContain
  38692. }
  38693. };
  38694. function getLineRenderer(xyIndex) {
  38695. return {
  38696. createCover: function (controller, brushOption) {
  38697. return createBaseRectCover(
  38698. curry$6(
  38699. driftRect,
  38700. function (range) {
  38701. var rectRange = [range, [0, 100]];
  38702. xyIndex && rectRange.reverse();
  38703. return rectRange;
  38704. },
  38705. function (rectRange) {
  38706. return rectRange[xyIndex];
  38707. }
  38708. ),
  38709. controller,
  38710. brushOption,
  38711. [['w', 'e'], ['n', 's']][xyIndex]
  38712. );
  38713. },
  38714. getCreatingRange: function (localTrack) {
  38715. var ends = getTrackEnds(localTrack);
  38716. var min = mathMin$4(ends[0][xyIndex], ends[1][xyIndex]);
  38717. var max = mathMax$4(ends[0][xyIndex], ends[1][xyIndex]);
  38718. return [min, max];
  38719. },
  38720. updateCoverShape: function (controller, cover, localRange, brushOption) {
  38721. var otherExtent;
  38722. // If brushWidth not specified, fit the panel.
  38723. var panel = getPanelByCover(controller, cover);
  38724. if (panel !== true && panel.getLinearBrushOtherExtent) {
  38725. otherExtent = panel.getLinearBrushOtherExtent(
  38726. xyIndex, controller._transform
  38727. );
  38728. }
  38729. else {
  38730. var zr = controller._zr;
  38731. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  38732. }
  38733. var rectRange = [localRange, otherExtent];
  38734. xyIndex && rectRange.reverse();
  38735. updateBaseRect(controller, cover, rectRange, brushOption);
  38736. },
  38737. updateCommon: updateCommon,
  38738. contain: mainShapeContain
  38739. };
  38740. }
  38741. var IRRELEVANT_EXCLUDES = {'axisPointer': 1, 'tooltip': 1, 'brush': 1};
  38742. /**
  38743. * Avoid that: mouse click on a elements that is over geo or graph,
  38744. * but roam is triggered.
  38745. */
  38746. function onIrrelevantElement(e, api, targetCoordSysModel) {
  38747. var model = api.getComponentByElement(e.topTarget);
  38748. // If model is axisModel, it works only if it is injected with coordinateSystem.
  38749. var coordSys = model && model.coordinateSystem;
  38750. return model
  38751. && model !== targetCoordSysModel
  38752. && !IRRELEVANT_EXCLUDES[model.mainType]
  38753. && (coordSys && coordSys.model !== targetCoordSysModel);
  38754. }
  38755. function makeRectPanelClipPath(rect) {
  38756. rect = normalizeRect(rect);
  38757. return function (localPoints, transform) {
  38758. return clipPointsByRect(localPoints, rect);
  38759. };
  38760. }
  38761. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  38762. rect = normalizeRect(rect);
  38763. return function (xyIndex) {
  38764. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  38765. var brushWidth = idx ? rect.width : rect.height;
  38766. var base = idx ? rect.x : rect.y;
  38767. return [base, base + (brushWidth || 0)];
  38768. };
  38769. }
  38770. function makeRectIsTargetByCursor(rect, api, targetModel) {
  38771. rect = normalizeRect(rect);
  38772. return function (e, localCursorPoint, transform) {
  38773. return rect.contain(localCursorPoint[0], localCursorPoint[1])
  38774. && !onIrrelevantElement(e, api, targetModel);
  38775. };
  38776. }
  38777. // Consider width/height is negative.
  38778. function normalizeRect(rect) {
  38779. return BoundingRect.create(rect);
  38780. }
  38781. var each$20 = each$1;
  38782. var indexOf$3 = indexOf;
  38783. var curry$7 = curry;
  38784. var COORD_CONVERTS = ['dataToPoint', 'pointToData'];
  38785. // FIXME
  38786. // how to genarialize to more coordinate systems.
  38787. var INCLUDE_FINDER_MAIN_TYPES = [
  38788. 'grid', 'xAxis', 'yAxis', 'geo', 'graph',
  38789. 'polar', 'radiusAxis', 'angleAxis', 'bmap'
  38790. ];
  38791. /**
  38792. * [option in constructor]:
  38793. * {
  38794. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  38795. * }
  38796. *
  38797. *
  38798. * [targetInfo]:
  38799. *
  38800. * There can be multiple axes in a single targetInfo. Consider the case
  38801. * of `grid` component, a targetInfo represents a grid which contains one or more
  38802. * cartesian and one or more axes. And consider the case of parallel system,
  38803. * which has multiple axes in a coordinate system.
  38804. * Can be {
  38805. * panelId: ...,
  38806. * coordSys: <a representitive cartesian in grid (first cartesian by default)>,
  38807. * coordSyses: all cartesians.
  38808. * gridModel: <grid component>
  38809. * xAxes: correspond to coordSyses on index
  38810. * yAxes: correspond to coordSyses on index
  38811. * }
  38812. * or {
  38813. * panelId: ...,
  38814. * coordSys: <geo coord sys>
  38815. * coordSyses: [<geo coord sys>]
  38816. * geoModel: <geo component>
  38817. * }
  38818. *
  38819. *
  38820. * [panelOpt]:
  38821. *
  38822. * Make from targetInfo. Input to BrushController.
  38823. * {
  38824. * panelId: ...,
  38825. * rect: ...
  38826. * }
  38827. *
  38828. *
  38829. * [area]:
  38830. *
  38831. * Generated by BrushController or user input.
  38832. * {
  38833. * panelId: Used to locate coordInfo directly. If user inpput, no panelId.
  38834. * brushType: determine how to convert to/from coord('rect' or 'polygon' or 'lineX/Y').
  38835. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  38836. * range: pixel range.
  38837. * coordRange: representitive coord range (the first one of coordRanges).
  38838. * coordRanges: <Array> coord ranges, used in multiple cartesian in one grid.
  38839. * }
  38840. */
  38841. /**
  38842. * @param {Object} option contains Index/Id/Name of xAxis/yAxis/geo/grid
  38843. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  38844. * @param {module:echarts/model/Global} ecModel
  38845. * @param {Object} [opt]
  38846. * @param {Array.<string>} [opt.include] include coordinate system types.
  38847. */
  38848. function BrushTargetManager(option, ecModel, opt) {
  38849. /**
  38850. * @private
  38851. * @type {Array.<Object>}
  38852. */
  38853. var targetInfoList = this._targetInfoList = [];
  38854. var info = {};
  38855. var foundCpts = parseFinder$1(ecModel, option);
  38856. each$20(targetInfoBuilders, function (builder, type) {
  38857. if (!opt || !opt.include || indexOf$3(opt.include, type) >= 0) {
  38858. builder(foundCpts, targetInfoList, info);
  38859. }
  38860. });
  38861. }
  38862. var proto$3 = BrushTargetManager.prototype;
  38863. proto$3.setOutputRanges = function (areas, ecModel) {
  38864. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  38865. (area.coordRanges || (area.coordRanges = [])).push(coordRange);
  38866. // area.coordRange is the first of area.coordRanges
  38867. if (!area.coordRange) {
  38868. area.coordRange = coordRange;
  38869. // In 'category' axis, coord to pixel is not reversible, so we can not
  38870. // rebuild range by coordRange accrately, which may bring trouble when
  38871. // brushing only one item. So we use __rangeOffset to rebuilding range
  38872. // by coordRange. And this it only used in brush component so it is no
  38873. // need to be adapted to coordRanges.
  38874. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  38875. area.__rangeOffset = {
  38876. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  38877. xyMinMax: result.xyMinMax
  38878. };
  38879. }
  38880. });
  38881. };
  38882. proto$3.matchOutputRanges = function (areas, ecModel, cb) {
  38883. each$20(areas, function (area) {
  38884. var targetInfo = this.findTargetInfo(area, ecModel);
  38885. if (targetInfo && targetInfo !== true) {
  38886. each$1(
  38887. targetInfo.coordSyses,
  38888. function (coordSys) {
  38889. var result = coordConvert[area.brushType](1, coordSys, area.range);
  38890. cb(area, result.values, coordSys, ecModel);
  38891. }
  38892. );
  38893. }
  38894. }, this);
  38895. };
  38896. proto$3.setInputRanges = function (areas, ecModel) {
  38897. each$20(areas, function (area) {
  38898. var targetInfo = this.findTargetInfo(area, ecModel);
  38899. if (__DEV__) {
  38900. assert(
  38901. !targetInfo || targetInfo === true || area.coordRange,
  38902. 'coordRange must be specified when coord index specified.'
  38903. );
  38904. assert(
  38905. !targetInfo || targetInfo !== true || area.range,
  38906. 'range must be specified in global brush.'
  38907. );
  38908. }
  38909. area.range = area.range || [];
  38910. // convert coordRange to global range and set panelId.
  38911. if (targetInfo && targetInfo !== true) {
  38912. area.panelId = targetInfo.panelId;
  38913. // (1) area.range shoule always be calculate from coordRange but does
  38914. // not keep its original value, for the sake of the dataZoom scenario,
  38915. // where area.coordRange remains unchanged but area.range may be changed.
  38916. // (2) Only support converting one coordRange to pixel range in brush
  38917. // component. So do not consider `coordRanges`.
  38918. // (3) About __rangeOffset, see comment above.
  38919. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  38920. var rangeOffset = area.__rangeOffset;
  38921. area.range = rangeOffset
  38922. ? diffProcessor[area.brushType](
  38923. result.values,
  38924. rangeOffset.offset,
  38925. getScales(result.xyMinMax, rangeOffset.xyMinMax)
  38926. )
  38927. : result.values;
  38928. }
  38929. }, this);
  38930. };
  38931. proto$3.makePanelOpts = function (api, getDefaultBrushType) {
  38932. return map(this._targetInfoList, function (targetInfo) {
  38933. var rect = targetInfo.getPanelRect();
  38934. return {
  38935. panelId: targetInfo.panelId,
  38936. defaultBrushType: getDefaultBrushType && getDefaultBrushType(targetInfo),
  38937. clipPath: makeRectPanelClipPath(rect),
  38938. isTargetByCursor: makeRectIsTargetByCursor(
  38939. rect, api, targetInfo.coordSysModel
  38940. ),
  38941. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  38942. };
  38943. });
  38944. };
  38945. proto$3.controlSeries = function (area, seriesModel, ecModel) {
  38946. // Check whether area is bound in coord, and series do not belong to that coord.
  38947. // If do not do this check, some brush (like lineX) will controll all axes.
  38948. var targetInfo = this.findTargetInfo(area, ecModel);
  38949. return targetInfo === true || (
  38950. targetInfo && indexOf$3(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0
  38951. );
  38952. };
  38953. /**
  38954. * If return Object, a coord found.
  38955. * If reutrn true, global found.
  38956. * Otherwise nothing found.
  38957. *
  38958. * @param {Object} area
  38959. * @param {Array} targetInfoList
  38960. * @return {Object|boolean}
  38961. */
  38962. proto$3.findTargetInfo = function (area, ecModel) {
  38963. var targetInfoList = this._targetInfoList;
  38964. var foundCpts = parseFinder$1(ecModel, area);
  38965. for (var i = 0; i < targetInfoList.length; i++) {
  38966. var targetInfo = targetInfoList[i];
  38967. var areaPanelId = area.panelId;
  38968. if (areaPanelId) {
  38969. if (targetInfo.panelId === areaPanelId) {
  38970. return targetInfo;
  38971. }
  38972. }
  38973. else {
  38974. for (var i = 0; i < targetInfoMatchers.length; i++) {
  38975. if (targetInfoMatchers[i](foundCpts, targetInfo)) {
  38976. return targetInfo;
  38977. }
  38978. }
  38979. }
  38980. }
  38981. return true;
  38982. };
  38983. function formatMinMax(minMax) {
  38984. minMax[0] > minMax[1] && minMax.reverse();
  38985. return minMax;
  38986. }
  38987. function parseFinder$1(ecModel, option) {
  38988. return parseFinder(
  38989. ecModel, option, {includeMainTypes: INCLUDE_FINDER_MAIN_TYPES}
  38990. );
  38991. }
  38992. var targetInfoBuilders = {
  38993. grid: function (foundCpts, targetInfoList) {
  38994. var xAxisModels = foundCpts.xAxisModels;
  38995. var yAxisModels = foundCpts.yAxisModels;
  38996. var gridModels = foundCpts.gridModels;
  38997. // Remove duplicated.
  38998. var gridModelMap = createHashMap();
  38999. var xAxesHas = {};
  39000. var yAxesHas = {};
  39001. if (!xAxisModels && !yAxisModels && !gridModels) {
  39002. return;
  39003. }
  39004. each$20(xAxisModels, function (axisModel) {
  39005. var gridModel = axisModel.axis.grid.model;
  39006. gridModelMap.set(gridModel.id, gridModel);
  39007. xAxesHas[gridModel.id] = true;
  39008. });
  39009. each$20(yAxisModels, function (axisModel) {
  39010. var gridModel = axisModel.axis.grid.model;
  39011. gridModelMap.set(gridModel.id, gridModel);
  39012. yAxesHas[gridModel.id] = true;
  39013. });
  39014. each$20(gridModels, function (gridModel) {
  39015. gridModelMap.set(gridModel.id, gridModel);
  39016. xAxesHas[gridModel.id] = true;
  39017. yAxesHas[gridModel.id] = true;
  39018. });
  39019. gridModelMap.each(function (gridModel) {
  39020. var grid = gridModel.coordinateSystem;
  39021. var cartesians = [];
  39022. each$20(grid.getCartesians(), function (cartesian, index) {
  39023. if (indexOf$3(xAxisModels, cartesian.getAxis('x').model) >= 0
  39024. || indexOf$3(yAxisModels, cartesian.getAxis('y').model) >= 0
  39025. ) {
  39026. cartesians.push(cartesian);
  39027. }
  39028. });
  39029. targetInfoList.push({
  39030. panelId: 'grid--' + gridModel.id,
  39031. gridModel: gridModel,
  39032. coordSysModel: gridModel,
  39033. // Use the first one as the representitive coordSys.
  39034. coordSys: cartesians[0],
  39035. coordSyses: cartesians,
  39036. getPanelRect: panelRectBuilder.grid,
  39037. xAxisDeclared: xAxesHas[gridModel.id],
  39038. yAxisDeclared: yAxesHas[gridModel.id]
  39039. });
  39040. });
  39041. },
  39042. geo: function (foundCpts, targetInfoList) {
  39043. each$20(foundCpts.geoModels, function (geoModel) {
  39044. var coordSys = geoModel.coordinateSystem;
  39045. targetInfoList.push({
  39046. panelId: 'geo--' + geoModel.id,
  39047. geoModel: geoModel,
  39048. coordSysModel: geoModel,
  39049. coordSys: coordSys,
  39050. coordSyses: [coordSys],
  39051. getPanelRect: panelRectBuilder.geo
  39052. });
  39053. });
  39054. }
  39055. };
  39056. var targetInfoMatchers = [
  39057. // grid
  39058. function (foundCpts, targetInfo) {
  39059. var xAxisModel = foundCpts.xAxisModel;
  39060. var yAxisModel = foundCpts.yAxisModel;
  39061. var gridModel = foundCpts.gridModel;
  39062. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  39063. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  39064. return gridModel && gridModel === targetInfo.gridModel;
  39065. },
  39066. // geo
  39067. function (foundCpts, targetInfo) {
  39068. var geoModel = foundCpts.geoModel;
  39069. return geoModel && geoModel === targetInfo.geoModel;
  39070. }
  39071. ];
  39072. var panelRectBuilder = {
  39073. grid: function () {
  39074. // grid is not Transformable.
  39075. return this.coordSys.grid.getRect().clone();
  39076. },
  39077. geo: function () {
  39078. var coordSys = this.coordSys;
  39079. var rect = coordSys.getBoundingRect().clone();
  39080. // geo roam and zoom transform
  39081. rect.applyTransform(getTransform(coordSys));
  39082. return rect;
  39083. }
  39084. };
  39085. var coordConvert = {
  39086. lineX: curry$7(axisConvert, 0),
  39087. lineY: curry$7(axisConvert, 1),
  39088. rect: function (to, coordSys, rangeOrCoordRange) {
  39089. var xminymin = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]]);
  39090. var xmaxymax = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]]);
  39091. var values = [
  39092. formatMinMax([xminymin[0], xmaxymax[0]]),
  39093. formatMinMax([xminymin[1], xmaxymax[1]])
  39094. ];
  39095. return {values: values, xyMinMax: values};
  39096. },
  39097. polygon: function (to, coordSys, rangeOrCoordRange) {
  39098. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  39099. var values = map(rangeOrCoordRange, function (item) {
  39100. var p = coordSys[COORD_CONVERTS[to]](item);
  39101. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  39102. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  39103. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  39104. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  39105. return p;
  39106. });
  39107. return {values: values, xyMinMax: xyMinMax};
  39108. }
  39109. };
  39110. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  39111. if (__DEV__) {
  39112. assert(
  39113. coordSys.type === 'cartesian2d',
  39114. 'lineX/lineY brush is available only in cartesian2d.'
  39115. );
  39116. }
  39117. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  39118. var values = formatMinMax(map([0, 1], function (i) {
  39119. return to
  39120. ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]))
  39121. : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  39122. }));
  39123. var xyMinMax = [];
  39124. xyMinMax[axisNameIndex] = values;
  39125. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  39126. return {values: values, xyMinMax: xyMinMax};
  39127. }
  39128. var diffProcessor = {
  39129. lineX: curry$7(axisDiffProcessor, 0),
  39130. lineY: curry$7(axisDiffProcessor, 1),
  39131. rect: function (values, refer, scales) {
  39132. return [
  39133. [values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]],
  39134. [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]
  39135. ];
  39136. },
  39137. polygon: function (values, refer, scales) {
  39138. return map(values, function (item, idx) {
  39139. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  39140. });
  39141. }
  39142. };
  39143. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  39144. return [
  39145. values[0] - scales[axisNameIndex] * refer[0],
  39146. values[1] - scales[axisNameIndex] * refer[1]
  39147. ];
  39148. }
  39149. // We have to process scale caused by dataZoom manually,
  39150. // although it might be not accurate.
  39151. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  39152. var sizeCurr = getSize(xyMinMaxCurr);
  39153. var sizeOrigin = getSize(xyMinMaxOrigin);
  39154. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  39155. isNaN(scales[0]) && (scales[0] = 1);
  39156. isNaN(scales[1]) && (scales[1] = 1);
  39157. return scales;
  39158. }
  39159. function getSize(xyMinMax) {
  39160. return xyMinMax
  39161. ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]]
  39162. : [NaN, NaN];
  39163. }
  39164. var each$21 = each$1;
  39165. var ATTR$2 = '\0_ec_hist_store';
  39166. /**
  39167. * @param {module:echarts/model/Global} ecModel
  39168. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  39169. */
  39170. function push(ecModel, newSnapshot) {
  39171. var store = giveStore$1(ecModel);
  39172. // If previous dataZoom can not be found,
  39173. // complete an range with current range.
  39174. each$21(newSnapshot, function (batchItem, dataZoomId) {
  39175. var i = store.length - 1;
  39176. for (; i >= 0; i--) {
  39177. var snapshot = store[i];
  39178. if (snapshot[dataZoomId]) {
  39179. break;
  39180. }
  39181. }
  39182. if (i < 0) {
  39183. // No origin range set, create one by current range.
  39184. var dataZoomModel = ecModel.queryComponents(
  39185. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  39186. )[0];
  39187. if (dataZoomModel) {
  39188. var percentRange = dataZoomModel.getPercentRange();
  39189. store[0][dataZoomId] = {
  39190. dataZoomId: dataZoomId,
  39191. start: percentRange[0],
  39192. end: percentRange[1]
  39193. };
  39194. }
  39195. }
  39196. });
  39197. store.push(newSnapshot);
  39198. }
  39199. /**
  39200. * @param {module:echarts/model/Global} ecModel
  39201. * @return {Object} snapshot
  39202. */
  39203. function pop(ecModel) {
  39204. var store = giveStore$1(ecModel);
  39205. var head = store[store.length - 1];
  39206. store.length > 1 && store.pop();
  39207. // Find top for all dataZoom.
  39208. var snapshot = {};
  39209. each$21(head, function (batchItem, dataZoomId) {
  39210. for (var i = store.length - 1; i >= 0; i--) {
  39211. var batchItem = store[i][dataZoomId];
  39212. if (batchItem) {
  39213. snapshot[dataZoomId] = batchItem;
  39214. break;
  39215. }
  39216. }
  39217. });
  39218. return snapshot;
  39219. }
  39220. /**
  39221. * @param {module:echarts/model/Global} ecModel
  39222. */
  39223. function clear$1(ecModel) {
  39224. ecModel[ATTR$2] = null;
  39225. }
  39226. /**
  39227. * @param {module:echarts/model/Global} ecModel
  39228. * @return {number} records. always >= 1.
  39229. */
  39230. function count(ecModel) {
  39231. return giveStore$1(ecModel).length;
  39232. }
  39233. /**
  39234. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  39235. * History length of each dataZoom may be different.
  39236. * this._history[0] is used to store origin range.
  39237. * @type {Array.<Object>}
  39238. */
  39239. function giveStore$1(ecModel) {
  39240. var store = ecModel[ATTR$2];
  39241. if (!store) {
  39242. store = ecModel[ATTR$2] = [{}];
  39243. }
  39244. return store;
  39245. }
  39246. DataZoomModel.extend({
  39247. type: 'dataZoom.select'
  39248. });
  39249. DataZoomView.extend({
  39250. type: 'dataZoom.select'
  39251. });
  39252. /**
  39253. * DataZoom component entry
  39254. */
  39255. // Use dataZoomSelect
  39256. var dataZoomLang = lang.toolbox.dataZoom;
  39257. var each$18 = each$1;
  39258. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  39259. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  39260. function DataZoom(model, ecModel, api) {
  39261. /**
  39262. * @private
  39263. * @type {module:echarts/component/helper/BrushController}
  39264. */
  39265. (this._brushController = new BrushController(api.getZr()))
  39266. .on('brush', bind(this._onBrush, this))
  39267. .mount();
  39268. /**
  39269. * @private
  39270. * @type {boolean}
  39271. */
  39272. this._isZoomActive;
  39273. }
  39274. DataZoom.defaultOption = {
  39275. show: true,
  39276. // Icon group
  39277. icon: {
  39278. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  39279. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  39280. },
  39281. // `zoom`, `back`
  39282. title: clone(dataZoomLang.title)
  39283. };
  39284. var proto$2 = DataZoom.prototype;
  39285. proto$2.render = function (featureModel, ecModel, api, payload) {
  39286. this.model = featureModel;
  39287. this.ecModel = ecModel;
  39288. this.api = api;
  39289. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  39290. updateBackBtnStatus(featureModel, ecModel);
  39291. };
  39292. proto$2.onclick = function (ecModel, api, type) {
  39293. handlers[type].call(this);
  39294. };
  39295. proto$2.remove = function (ecModel, api) {
  39296. this._brushController.unmount();
  39297. };
  39298. proto$2.dispose = function (ecModel, api) {
  39299. this._brushController.dispose();
  39300. };
  39301. /**
  39302. * @private
  39303. */
  39304. var handlers = {
  39305. zoom: function () {
  39306. var nextActive = !this._isZoomActive;
  39307. this.api.dispatchAction({
  39308. type: 'takeGlobalCursor',
  39309. key: 'dataZoomSelect',
  39310. dataZoomSelectActive: nextActive
  39311. });
  39312. },
  39313. back: function () {
  39314. this._dispatchZoomAction(pop(this.ecModel));
  39315. }
  39316. };
  39317. /**
  39318. * @private
  39319. */
  39320. proto$2._onBrush = function (areas, opt) {
  39321. if (!opt.isEnd || !areas.length) {
  39322. return;
  39323. }
  39324. var snapshot = {};
  39325. var ecModel = this.ecModel;
  39326. this._brushController.updateCovers([]); // remove cover
  39327. var brushTargetManager = new BrushTargetManager(
  39328. retrieveAxisSetting(this.model.option), ecModel, {include: ['grid']}
  39329. );
  39330. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  39331. if (coordSys.type !== 'cartesian2d') {
  39332. return;
  39333. }
  39334. var brushType = area.brushType;
  39335. if (brushType === 'rect') {
  39336. setBatch('x', coordSys, coordRange[0]);
  39337. setBatch('y', coordSys, coordRange[1]);
  39338. }
  39339. else {
  39340. setBatch(({lineX: 'x', lineY: 'y'})[brushType], coordSys, coordRange);
  39341. }
  39342. });
  39343. push(ecModel, snapshot);
  39344. this._dispatchZoomAction(snapshot);
  39345. function setBatch(dimName, coordSys, minMax) {
  39346. var axis = coordSys.getAxis(dimName);
  39347. var axisModel = axis.model;
  39348. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel);
  39349. // Restrict range.
  39350. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  39351. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  39352. minMax = sliderMove(
  39353. 0, minMax.slice(), axis.scale.getExtent(), 0,
  39354. minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan
  39355. );
  39356. }
  39357. dataZoomModel && (snapshot[dataZoomModel.id] = {
  39358. dataZoomId: dataZoomModel.id,
  39359. startValue: minMax[0],
  39360. endValue: minMax[1]
  39361. });
  39362. }
  39363. function findDataZoom(dimName, axisModel, ecModel) {
  39364. var found;
  39365. ecModel.eachComponent({mainType: 'dataZoom', subType: 'select'}, function (dzModel) {
  39366. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  39367. has && (found = dzModel);
  39368. });
  39369. return found;
  39370. }
  39371. };
  39372. /**
  39373. * @private
  39374. */
  39375. proto$2._dispatchZoomAction = function (snapshot) {
  39376. var batch = [];
  39377. // Convert from hash map to array.
  39378. each$18(snapshot, function (batchItem, dataZoomId) {
  39379. batch.push(clone(batchItem));
  39380. });
  39381. batch.length && this.api.dispatchAction({
  39382. type: 'dataZoom',
  39383. from: this.uid,
  39384. batch: batch
  39385. });
  39386. };
  39387. function retrieveAxisSetting(option) {
  39388. var setting = {};
  39389. // Compatible with previous setting: null => all axis, false => no axis.
  39390. each$1(['xAxisIndex', 'yAxisIndex'], function (name) {
  39391. setting[name] = option[name];
  39392. setting[name] == null && (setting[name] = 'all');
  39393. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  39394. });
  39395. return setting;
  39396. }
  39397. function updateBackBtnStatus(featureModel, ecModel) {
  39398. featureModel.setIconStatus(
  39399. 'back',
  39400. count(ecModel) > 1 ? 'emphasis' : 'normal'
  39401. );
  39402. }
  39403. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  39404. var zoomActive = view._isZoomActive;
  39405. if (payload && payload.type === 'takeGlobalCursor') {
  39406. zoomActive = payload.key === 'dataZoomSelect'
  39407. ? payload.dataZoomSelectActive : false;
  39408. }
  39409. view._isZoomActive = zoomActive;
  39410. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  39411. var brushTargetManager = new BrushTargetManager(
  39412. retrieveAxisSetting(featureModel.option), ecModel, {include: ['grid']}
  39413. );
  39414. view._brushController
  39415. .setPanels(brushTargetManager.makePanelOpts(api, function (targetInfo) {
  39416. return (targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared)
  39417. ? 'lineX'
  39418. : (!targetInfo.xAxisDeclared && targetInfo.yAxisDeclared)
  39419. ? 'lineY'
  39420. : 'rect';
  39421. }))
  39422. .enableBrush(
  39423. zoomActive
  39424. ? {
  39425. brushType: 'auto',
  39426. brushStyle: {
  39427. // FIXME user customized?
  39428. lineWidth: 0,
  39429. fill: 'rgba(0,0,0,0.2)'
  39430. }
  39431. }
  39432. : false
  39433. );
  39434. }
  39435. register$2('dataZoom', DataZoom);
  39436. // Create special dataZoom option for select
  39437. registerPreprocessor(function (option) {
  39438. if (!option) {
  39439. return;
  39440. }
  39441. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  39442. if (!isArray(dataZoomOpts)) {
  39443. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  39444. }
  39445. var toolboxOpt = option.toolbox;
  39446. if (toolboxOpt) {
  39447. // Assume there is only one toolbox
  39448. if (isArray(toolboxOpt)) {
  39449. toolboxOpt = toolboxOpt[0];
  39450. }
  39451. if (toolboxOpt && toolboxOpt.feature) {
  39452. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  39453. addForAxis('xAxis', dataZoomOpt);
  39454. addForAxis('yAxis', dataZoomOpt);
  39455. }
  39456. }
  39457. function addForAxis(axisName, dataZoomOpt) {
  39458. if (!dataZoomOpt) {
  39459. return;
  39460. }
  39461. // Try not to modify model, because it is not merged yet.
  39462. var axisIndicesName = axisName + 'Index';
  39463. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  39464. if (givenAxisIndices != null
  39465. && givenAxisIndices != 'all'
  39466. && !isArray(givenAxisIndices)
  39467. ) {
  39468. givenAxisIndices = (givenAxisIndices === false || givenAxisIndices === 'none') ? [] : [givenAxisIndices];
  39469. }
  39470. forEachComponent(axisName, function (axisOpt, axisIndex) {
  39471. if (givenAxisIndices != null
  39472. && givenAxisIndices != 'all'
  39473. && indexOf(givenAxisIndices, axisIndex) === -1
  39474. ) {
  39475. return;
  39476. }
  39477. var newOpt = {
  39478. type: 'select',
  39479. $fromToolbox: true,
  39480. // Id for merge mapping.
  39481. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  39482. };
  39483. // FIXME
  39484. // Only support one axis now.
  39485. newOpt[axisIndicesName] = axisIndex;
  39486. dataZoomOpts.push(newOpt);
  39487. });
  39488. }
  39489. function forEachComponent(mainType, cb) {
  39490. var opts = option[mainType];
  39491. if (!isArray(opts)) {
  39492. opts = opts ? [opts] : [];
  39493. }
  39494. each$18(opts, cb);
  39495. }
  39496. });
  39497. var restoreLang = lang.toolbox.restore;
  39498. function Restore(model) {
  39499. this.model = model;
  39500. }
  39501. Restore.defaultOption = {
  39502. show: true,
  39503. 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',
  39504. title: restoreLang.title
  39505. };
  39506. var proto$4 = Restore.prototype;
  39507. proto$4.onclick = function (ecModel, api, type) {
  39508. clear$1(ecModel);
  39509. api.dispatchAction({
  39510. type: 'restore',
  39511. from: this.uid
  39512. });
  39513. };
  39514. register$2('restore', Restore);
  39515. registerAction(
  39516. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  39517. function (payload, ecModel) {
  39518. ecModel.resetOption('recreate');
  39519. }
  39520. );
  39521. var urn = 'urn:schemas-microsoft-com:vml';
  39522. var win = typeof window === 'undefined' ? null : window;
  39523. var vmlInited = false;
  39524. var doc = win && win.document;
  39525. function createNode(tagName) {
  39526. return doCreateNode(tagName);
  39527. }
  39528. // Avoid assign to an exported variable, for transforming to cjs.
  39529. var doCreateNode;
  39530. if (doc && !env$1.canvasSupported) {
  39531. try {
  39532. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  39533. doCreateNode = function (tagName) {
  39534. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  39535. };
  39536. }
  39537. catch (e) {
  39538. doCreateNode = function (tagName) {
  39539. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  39540. };
  39541. }
  39542. }
  39543. // From raphael
  39544. function initVML() {
  39545. if (vmlInited || !doc) {
  39546. return;
  39547. }
  39548. vmlInited = true;
  39549. var styleSheets = doc.styleSheets;
  39550. if (styleSheets.length < 31) {
  39551. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  39552. }
  39553. else {
  39554. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  39555. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  39556. }
  39557. }
  39558. // http://www.w3.org/TR/NOTE-VML
  39559. // TODO Use proxy like svg instead of overwrite brush methods
  39560. var CMD$3 = PathProxy.CMD;
  39561. var round$2 = Math.round;
  39562. var sqrt = Math.sqrt;
  39563. var abs$1 = Math.abs;
  39564. var cos = Math.cos;
  39565. var sin = Math.sin;
  39566. var mathMax$5 = Math.max;
  39567. if (!env$1.canvasSupported) {
  39568. var comma = ',';
  39569. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  39570. var Z = 21600;
  39571. var Z2 = Z / 2;
  39572. var ZLEVEL_BASE = 100000;
  39573. var Z_BASE = 1000;
  39574. var initRootElStyle = function (el) {
  39575. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  39576. el.coordsize = Z + ',' + Z;
  39577. el.coordorigin = '0,0';
  39578. };
  39579. var encodeHtmlAttribute = function (s) {
  39580. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  39581. };
  39582. var rgb2Str = function (r, g, b) {
  39583. return 'rgb(' + [r, g, b].join(',') + ')';
  39584. };
  39585. var append = function (parent, child) {
  39586. if (child && parent && child.parentNode !== parent) {
  39587. parent.appendChild(child);
  39588. }
  39589. };
  39590. var remove = function (parent, child) {
  39591. if (child && parent && child.parentNode === parent) {
  39592. parent.removeChild(child);
  39593. }
  39594. };
  39595. var getZIndex = function (zlevel, z, z2) {
  39596. // z 的取值范围为 [0, 1000]
  39597. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE + z2;
  39598. };
  39599. var parsePercent$3 = function (value, maxValue) {
  39600. if (typeof value === 'string') {
  39601. if (value.lastIndexOf('%') >= 0) {
  39602. return parseFloat(value) / 100 * maxValue;
  39603. }
  39604. return parseFloat(value);
  39605. }
  39606. return value;
  39607. };
  39608. /***************************************************
  39609. * PATH
  39610. **************************************************/
  39611. var setColorAndOpacity = function (el, color, opacity) {
  39612. var colorArr = parse(color);
  39613. opacity = +opacity;
  39614. if (isNaN(opacity)) {
  39615. opacity = 1;
  39616. }
  39617. if (colorArr) {
  39618. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  39619. el.opacity = opacity * colorArr[3];
  39620. }
  39621. };
  39622. var getColorAndAlpha = function (color) {
  39623. var colorArr = parse(color);
  39624. return [
  39625. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  39626. colorArr[3]
  39627. ];
  39628. };
  39629. var updateFillNode = function (el, style, zrEl) {
  39630. // TODO pattern
  39631. var fill = style.fill;
  39632. if (fill != null) {
  39633. // Modified from excanvas
  39634. if (fill instanceof Gradient) {
  39635. var gradientType;
  39636. var angle = 0;
  39637. var focus = [0, 0];
  39638. // additional offset
  39639. var shift = 0;
  39640. // scale factor for offset
  39641. var expansion = 1;
  39642. var rect = zrEl.getBoundingRect();
  39643. var rectWidth = rect.width;
  39644. var rectHeight = rect.height;
  39645. if (fill.type === 'linear') {
  39646. gradientType = 'gradient';
  39647. var transform = zrEl.transform;
  39648. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  39649. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  39650. if (transform) {
  39651. applyTransform(p0, p0, transform);
  39652. applyTransform(p1, p1, transform);
  39653. }
  39654. var dx = p1[0] - p0[0];
  39655. var dy = p1[1] - p0[1];
  39656. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  39657. // The angle should be a non-negative number.
  39658. if (angle < 0) {
  39659. angle += 360;
  39660. }
  39661. // Very small angles produce an unexpected result because they are
  39662. // converted to a scientific notation string.
  39663. if (angle < 1e-6) {
  39664. angle = 0;
  39665. }
  39666. }
  39667. else {
  39668. gradientType = 'gradientradial';
  39669. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  39670. var transform = zrEl.transform;
  39671. var scale$$1 = zrEl.scale;
  39672. var width = rectWidth;
  39673. var height = rectHeight;
  39674. focus = [
  39675. // Percent in bounding rect
  39676. (p0[0] - rect.x) / width,
  39677. (p0[1] - rect.y) / height
  39678. ];
  39679. if (transform) {
  39680. applyTransform(p0, p0, transform);
  39681. }
  39682. width /= scale$$1[0] * Z;
  39683. height /= scale$$1[1] * Z;
  39684. var dimension = mathMax$5(width, height);
  39685. shift = 2 * 0 / dimension;
  39686. expansion = 2 * fill.r / dimension - shift;
  39687. }
  39688. // We need to sort the color stops in ascending order by offset,
  39689. // otherwise IE won't interpret it correctly.
  39690. var stops = fill.colorStops.slice();
  39691. stops.sort(function(cs1, cs2) {
  39692. return cs1.offset - cs2.offset;
  39693. });
  39694. var length$$1 = stops.length;
  39695. // Color and alpha list of first and last stop
  39696. var colorAndAlphaList = [];
  39697. var colors = [];
  39698. for (var i = 0; i < length$$1; i++) {
  39699. var stop = stops[i];
  39700. var colorAndAlpha = getColorAndAlpha(stop.color);
  39701. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  39702. if (i === 0 || i === length$$1 - 1) {
  39703. colorAndAlphaList.push(colorAndAlpha);
  39704. }
  39705. }
  39706. if (length$$1 >= 2) {
  39707. var color1 = colorAndAlphaList[0][0];
  39708. var color2 = colorAndAlphaList[1][0];
  39709. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  39710. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  39711. el.type = gradientType;
  39712. el.method = 'none';
  39713. el.focus = '100%';
  39714. el.angle = angle;
  39715. el.color = color1;
  39716. el.color2 = color2;
  39717. el.colors = colors.join(',');
  39718. // When colors attribute is used, the meanings of opacity and o:opacity2
  39719. // are reversed.
  39720. el.opacity = opacity2;
  39721. // FIXME g_o_:opacity ?
  39722. el.opacity2 = opacity1;
  39723. }
  39724. if (gradientType === 'radial') {
  39725. el.focusposition = focus.join(',');
  39726. }
  39727. }
  39728. else {
  39729. // FIXME Change from Gradient fill to color fill
  39730. setColorAndOpacity(el, fill, style.opacity);
  39731. }
  39732. }
  39733. };
  39734. var updateStrokeNode = function (el, style) {
  39735. // if (style.lineJoin != null) {
  39736. // el.joinstyle = style.lineJoin;
  39737. // }
  39738. // if (style.miterLimit != null) {
  39739. // el.miterlimit = style.miterLimit * Z;
  39740. // }
  39741. // if (style.lineCap != null) {
  39742. // el.endcap = style.lineCap;
  39743. // }
  39744. if (style.lineDash != null) {
  39745. el.dashstyle = style.lineDash.join(' ');
  39746. }
  39747. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  39748. setColorAndOpacity(el, style.stroke, style.opacity);
  39749. }
  39750. };
  39751. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  39752. var isFill = type == 'fill';
  39753. var el = vmlEl.getElementsByTagName(type)[0];
  39754. // Stroke must have lineWidth
  39755. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  39756. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  39757. // FIXME Remove before updating, or set `colors` will throw error
  39758. if (style[type] instanceof Gradient) {
  39759. remove(vmlEl, el);
  39760. }
  39761. if (!el) {
  39762. el = createNode(type);
  39763. }
  39764. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  39765. append(vmlEl, el);
  39766. }
  39767. else {
  39768. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  39769. remove(vmlEl, el);
  39770. }
  39771. };
  39772. var points$1 = [[], [], []];
  39773. var pathDataToString = function (path, m) {
  39774. var M = CMD$3.M;
  39775. var C = CMD$3.C;
  39776. var L = CMD$3.L;
  39777. var A = CMD$3.A;
  39778. var Q = CMD$3.Q;
  39779. var str = [];
  39780. var nPoint;
  39781. var cmdStr;
  39782. var cmd;
  39783. var i;
  39784. var xi;
  39785. var yi;
  39786. var data = path.data;
  39787. var dataLength = path.len();
  39788. for (i = 0; i < dataLength;) {
  39789. cmd = data[i++];
  39790. cmdStr = '';
  39791. nPoint = 0;
  39792. switch (cmd) {
  39793. case M:
  39794. cmdStr = ' m ';
  39795. nPoint = 1;
  39796. xi = data[i++];
  39797. yi = data[i++];
  39798. points$1[0][0] = xi;
  39799. points$1[0][1] = yi;
  39800. break;
  39801. case L:
  39802. cmdStr = ' l ';
  39803. nPoint = 1;
  39804. xi = data[i++];
  39805. yi = data[i++];
  39806. points$1[0][0] = xi;
  39807. points$1[0][1] = yi;
  39808. break;
  39809. case Q:
  39810. case C:
  39811. cmdStr = ' c ';
  39812. nPoint = 3;
  39813. var x1 = data[i++];
  39814. var y1 = data[i++];
  39815. var x2 = data[i++];
  39816. var y2 = data[i++];
  39817. var x3;
  39818. var y3;
  39819. if (cmd === Q) {
  39820. // Convert quadratic to cubic using degree elevation
  39821. x3 = x2;
  39822. y3 = y2;
  39823. x2 = (x2 + 2 * x1) / 3;
  39824. y2 = (y2 + 2 * y1) / 3;
  39825. x1 = (xi + 2 * x1) / 3;
  39826. y1 = (yi + 2 * y1) / 3;
  39827. }
  39828. else {
  39829. x3 = data[i++];
  39830. y3 = data[i++];
  39831. }
  39832. points$1[0][0] = x1;
  39833. points$1[0][1] = y1;
  39834. points$1[1][0] = x2;
  39835. points$1[1][1] = y2;
  39836. points$1[2][0] = x3;
  39837. points$1[2][1] = y3;
  39838. xi = x3;
  39839. yi = y3;
  39840. break;
  39841. case A:
  39842. var x = 0;
  39843. var y = 0;
  39844. var sx = 1;
  39845. var sy = 1;
  39846. var angle = 0;
  39847. if (m) {
  39848. // Extract SRT from matrix
  39849. x = m[4];
  39850. y = m[5];
  39851. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  39852. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  39853. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  39854. }
  39855. var cx = data[i++];
  39856. var cy = data[i++];
  39857. var rx = data[i++];
  39858. var ry = data[i++];
  39859. var startAngle = data[i++] + angle;
  39860. var endAngle = data[i++] + startAngle + angle;
  39861. // FIXME
  39862. // var psi = data[i++];
  39863. i++;
  39864. var clockwise = data[i++];
  39865. var x0 = cx + cos(startAngle) * rx;
  39866. var y0 = cy + sin(startAngle) * ry;
  39867. var x1 = cx + cos(endAngle) * rx;
  39868. var y1 = cy + sin(endAngle) * ry;
  39869. var type = clockwise ? ' wa ' : ' at ';
  39870. if (Math.abs(x0 - x1) < 1e-4) {
  39871. // IE won't render arches drawn counter clockwise if x0 == x1.
  39872. if (Math.abs(endAngle - startAngle) > 1e-2) {
  39873. // Offset x0 by 1/80 of a pixel. Use something
  39874. // that can be represented in binary
  39875. if (clockwise) {
  39876. x0 += 270 / Z;
  39877. }
  39878. }
  39879. else {
  39880. // Avoid case draw full circle
  39881. if (Math.abs(y0 - cy) < 1e-4) {
  39882. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  39883. y1 -= 270 / Z;
  39884. }
  39885. else {
  39886. y1 += 270 / Z;
  39887. }
  39888. }
  39889. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  39890. x1 += 270 / Z;
  39891. }
  39892. else {
  39893. x1 -= 270 / Z;
  39894. }
  39895. }
  39896. }
  39897. str.push(
  39898. type,
  39899. round$2(((cx - rx) * sx + x) * Z - Z2), comma,
  39900. round$2(((cy - ry) * sy + y) * Z - Z2), comma,
  39901. round$2(((cx + rx) * sx + x) * Z - Z2), comma,
  39902. round$2(((cy + ry) * sy + y) * Z - Z2), comma,
  39903. round$2((x0 * sx + x) * Z - Z2), comma,
  39904. round$2((y0 * sy + y) * Z - Z2), comma,
  39905. round$2((x1 * sx + x) * Z - Z2), comma,
  39906. round$2((y1 * sy + y) * Z - Z2)
  39907. );
  39908. xi = x1;
  39909. yi = y1;
  39910. break;
  39911. case CMD$3.R:
  39912. var p0 = points$1[0];
  39913. var p1 = points$1[1];
  39914. // x0, y0
  39915. p0[0] = data[i++];
  39916. p0[1] = data[i++];
  39917. // x1, y1
  39918. p1[0] = p0[0] + data[i++];
  39919. p1[1] = p0[1] + data[i++];
  39920. if (m) {
  39921. applyTransform(p0, p0, m);
  39922. applyTransform(p1, p1, m);
  39923. }
  39924. p0[0] = round$2(p0[0] * Z - Z2);
  39925. p1[0] = round$2(p1[0] * Z - Z2);
  39926. p0[1] = round$2(p0[1] * Z - Z2);
  39927. p1[1] = round$2(p1[1] * Z - Z2);
  39928. str.push(
  39929. // x0, y0
  39930. ' m ', p0[0], comma, p0[1],
  39931. // x1, y0
  39932. ' l ', p1[0], comma, p0[1],
  39933. // x1, y1
  39934. ' l ', p1[0], comma, p1[1],
  39935. // x0, y1
  39936. ' l ', p0[0], comma, p1[1]
  39937. );
  39938. break;
  39939. case CMD$3.Z:
  39940. // FIXME Update xi, yi
  39941. str.push(' x ');
  39942. }
  39943. if (nPoint > 0) {
  39944. str.push(cmdStr);
  39945. for (var k = 0; k < nPoint; k++) {
  39946. var p = points$1[k];
  39947. m && applyTransform(p, p, m);
  39948. // 不 round 会非常慢
  39949. str.push(
  39950. round$2(p[0] * Z - Z2), comma, round$2(p[1] * Z - Z2),
  39951. k < nPoint - 1 ? comma : ''
  39952. );
  39953. }
  39954. }
  39955. }
  39956. return str.join('');
  39957. };
  39958. // Rewrite the original path method
  39959. Path.prototype.brushVML = function (vmlRoot) {
  39960. var style = this.style;
  39961. var vmlEl = this._vmlEl;
  39962. if (!vmlEl) {
  39963. vmlEl = createNode('shape');
  39964. initRootElStyle(vmlEl);
  39965. this._vmlEl = vmlEl;
  39966. }
  39967. updateFillAndStroke(vmlEl, 'fill', style, this);
  39968. updateFillAndStroke(vmlEl, 'stroke', style, this);
  39969. var m = this.transform;
  39970. var needTransform = m != null;
  39971. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  39972. if (strokeEl) {
  39973. var lineWidth = style.lineWidth;
  39974. // Get the line scale.
  39975. // Determinant of this.m_ means how much the area is enlarged by the
  39976. // transformation. So its square root can be used as a scale factor
  39977. // for width.
  39978. if (needTransform && !style.strokeNoScale) {
  39979. var det = m[0] * m[3] - m[1] * m[2];
  39980. lineWidth *= sqrt(abs$1(det));
  39981. }
  39982. strokeEl.weight = lineWidth + 'px';
  39983. }
  39984. var path = this.path || (this.path = new PathProxy());
  39985. if (this.__dirtyPath) {
  39986. path.beginPath();
  39987. this.buildPath(path, this.shape);
  39988. path.toStatic();
  39989. this.__dirtyPath = false;
  39990. }
  39991. vmlEl.path = pathDataToString(path, this.transform);
  39992. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  39993. // Append to root
  39994. append(vmlRoot, vmlEl);
  39995. // Text
  39996. if (style.text != null) {
  39997. this.drawRectText(vmlRoot, this.getBoundingRect());
  39998. }
  39999. else {
  40000. this.removeRectText(vmlRoot);
  40001. }
  40002. };
  40003. Path.prototype.onRemove = function (vmlRoot) {
  40004. remove(vmlRoot, this._vmlEl);
  40005. this.removeRectText(vmlRoot);
  40006. };
  40007. Path.prototype.onAdd = function (vmlRoot) {
  40008. append(vmlRoot, this._vmlEl);
  40009. this.appendRectText(vmlRoot);
  40010. };
  40011. /***************************************************
  40012. * IMAGE
  40013. **************************************************/
  40014. var isImage = function (img) {
  40015. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  40016. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  40017. // return img instanceof Image;
  40018. };
  40019. // Rewrite the original path method
  40020. ZImage.prototype.brushVML = function (vmlRoot) {
  40021. var style = this.style;
  40022. var image = style.image;
  40023. // Image original width, height
  40024. var ow;
  40025. var oh;
  40026. if (isImage(image)) {
  40027. var src = image.src;
  40028. if (src === this._imageSrc) {
  40029. ow = this._imageWidth;
  40030. oh = this._imageHeight;
  40031. }
  40032. else {
  40033. var imageRuntimeStyle = image.runtimeStyle;
  40034. var oldRuntimeWidth = imageRuntimeStyle.width;
  40035. var oldRuntimeHeight = imageRuntimeStyle.height;
  40036. imageRuntimeStyle.width = 'auto';
  40037. imageRuntimeStyle.height = 'auto';
  40038. // get the original size
  40039. ow = image.width;
  40040. oh = image.height;
  40041. // and remove overides
  40042. imageRuntimeStyle.width = oldRuntimeWidth;
  40043. imageRuntimeStyle.height = oldRuntimeHeight;
  40044. // Caching image original width, height and src
  40045. this._imageSrc = src;
  40046. this._imageWidth = ow;
  40047. this._imageHeight = oh;
  40048. }
  40049. image = src;
  40050. }
  40051. else {
  40052. if (image === this._imageSrc) {
  40053. ow = this._imageWidth;
  40054. oh = this._imageHeight;
  40055. }
  40056. }
  40057. if (!image) {
  40058. return;
  40059. }
  40060. var x = style.x || 0;
  40061. var y = style.y || 0;
  40062. var dw = style.width;
  40063. var dh = style.height;
  40064. var sw = style.sWidth;
  40065. var sh = style.sHeight;
  40066. var sx = style.sx || 0;
  40067. var sy = style.sy || 0;
  40068. var hasCrop = sw && sh;
  40069. var vmlEl = this._vmlEl;
  40070. if (!vmlEl) {
  40071. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  40072. // vmlEl = vmlCore.createNode('group');
  40073. vmlEl = doc.createElement('div');
  40074. initRootElStyle(vmlEl);
  40075. this._vmlEl = vmlEl;
  40076. }
  40077. var vmlElStyle = vmlEl.style;
  40078. var hasRotation = false;
  40079. var m;
  40080. var scaleX = 1;
  40081. var scaleY = 1;
  40082. if (this.transform) {
  40083. m = this.transform;
  40084. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  40085. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  40086. hasRotation = m[1] || m[2];
  40087. }
  40088. if (hasRotation) {
  40089. // If filters are necessary (rotation exists), create them
  40090. // filters are bog-slow, so only create them if abbsolutely necessary
  40091. // The following check doesn't account for skews (which don't exist
  40092. // in the canvas spec (yet) anyway.
  40093. // From excanvas
  40094. var p0 = [x, y];
  40095. var p1 = [x + dw, y];
  40096. var p2 = [x, y + dh];
  40097. var p3 = [x + dw, y + dh];
  40098. applyTransform(p0, p0, m);
  40099. applyTransform(p1, p1, m);
  40100. applyTransform(p2, p2, m);
  40101. applyTransform(p3, p3, m);
  40102. var maxX = mathMax$5(p0[0], p1[0], p2[0], p3[0]);
  40103. var maxY = mathMax$5(p0[1], p1[1], p2[1], p3[1]);
  40104. var transformFilter = [];
  40105. transformFilter.push('M11=', m[0] / scaleX, comma,
  40106. 'M12=', m[2] / scaleY, comma,
  40107. 'M21=', m[1] / scaleX, comma,
  40108. 'M22=', m[3] / scaleY, comma,
  40109. 'Dx=', round$2(x * scaleX + m[4]), comma,
  40110. 'Dy=', round$2(y * scaleY + m[5]));
  40111. vmlElStyle.padding = '0 ' + round$2(maxX) + 'px ' + round$2(maxY) + 'px 0';
  40112. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  40113. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  40114. + transformFilter.join('') + ', SizingMethod=clip)';
  40115. }
  40116. else {
  40117. if (m) {
  40118. x = x * scaleX + m[4];
  40119. y = y * scaleY + m[5];
  40120. }
  40121. vmlElStyle.filter = '';
  40122. vmlElStyle.left = round$2(x) + 'px';
  40123. vmlElStyle.top = round$2(y) + 'px';
  40124. }
  40125. var imageEl = this._imageEl;
  40126. var cropEl = this._cropEl;
  40127. if (!imageEl) {
  40128. imageEl = doc.createElement('div');
  40129. this._imageEl = imageEl;
  40130. }
  40131. var imageELStyle = imageEl.style;
  40132. if (hasCrop) {
  40133. // Needs know image original width and height
  40134. if (! (ow && oh)) {
  40135. var tmpImage = new Image();
  40136. var self = this;
  40137. tmpImage.onload = function () {
  40138. tmpImage.onload = null;
  40139. ow = tmpImage.width;
  40140. oh = tmpImage.height;
  40141. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  40142. imageELStyle.width = round$2(scaleX * ow * dw / sw) + 'px';
  40143. imageELStyle.height = round$2(scaleY * oh * dh / sh) + 'px';
  40144. // Caching image original width, height and src
  40145. self._imageWidth = ow;
  40146. self._imageHeight = oh;
  40147. self._imageSrc = image;
  40148. };
  40149. tmpImage.src = image;
  40150. }
  40151. else {
  40152. imageELStyle.width = round$2(scaleX * ow * dw / sw) + 'px';
  40153. imageELStyle.height = round$2(scaleY * oh * dh / sh) + 'px';
  40154. }
  40155. if (! cropEl) {
  40156. cropEl = doc.createElement('div');
  40157. cropEl.style.overflow = 'hidden';
  40158. this._cropEl = cropEl;
  40159. }
  40160. var cropElStyle = cropEl.style;
  40161. cropElStyle.width = round$2((dw + sx * dw / sw) * scaleX);
  40162. cropElStyle.height = round$2((dh + sy * dh / sh) * scaleY);
  40163. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  40164. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  40165. if (! cropEl.parentNode) {
  40166. vmlEl.appendChild(cropEl);
  40167. }
  40168. if (imageEl.parentNode != cropEl) {
  40169. cropEl.appendChild(imageEl);
  40170. }
  40171. }
  40172. else {
  40173. imageELStyle.width = round$2(scaleX * dw) + 'px';
  40174. imageELStyle.height = round$2(scaleY * dh) + 'px';
  40175. vmlEl.appendChild(imageEl);
  40176. if (cropEl && cropEl.parentNode) {
  40177. vmlEl.removeChild(cropEl);
  40178. this._cropEl = null;
  40179. }
  40180. }
  40181. var filterStr = '';
  40182. var alpha = style.opacity;
  40183. if (alpha < 1) {
  40184. filterStr += '.Alpha(opacity=' + round$2(alpha * 100) + ') ';
  40185. }
  40186. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  40187. imageELStyle.filter = filterStr;
  40188. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  40189. // Append to root
  40190. append(vmlRoot, vmlEl);
  40191. // Text
  40192. if (style.text != null) {
  40193. this.drawRectText(vmlRoot, this.getBoundingRect());
  40194. }
  40195. };
  40196. ZImage.prototype.onRemove = function (vmlRoot) {
  40197. remove(vmlRoot, this._vmlEl);
  40198. this._vmlEl = null;
  40199. this._cropEl = null;
  40200. this._imageEl = null;
  40201. this.removeRectText(vmlRoot);
  40202. };
  40203. ZImage.prototype.onAdd = function (vmlRoot) {
  40204. append(vmlRoot, this._vmlEl);
  40205. this.appendRectText(vmlRoot);
  40206. };
  40207. /***************************************************
  40208. * TEXT
  40209. **************************************************/
  40210. var DEFAULT_STYLE_NORMAL = 'normal';
  40211. var fontStyleCache = {};
  40212. var fontStyleCacheCount = 0;
  40213. var MAX_FONT_CACHE_SIZE = 100;
  40214. var fontEl = document.createElement('div');
  40215. var getFontStyle = function (fontString) {
  40216. var fontStyle = fontStyleCache[fontString];
  40217. if (!fontStyle) {
  40218. // Clear cache
  40219. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  40220. fontStyleCacheCount = 0;
  40221. fontStyleCache = {};
  40222. }
  40223. var style = fontEl.style;
  40224. var fontFamily;
  40225. try {
  40226. style.font = fontString;
  40227. fontFamily = style.fontFamily.split(',')[0];
  40228. }
  40229. catch (e) {
  40230. }
  40231. fontStyle = {
  40232. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  40233. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  40234. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  40235. size: parseFloat(style.fontSize || 12) | 0,
  40236. family: fontFamily || 'Microsoft YaHei'
  40237. };
  40238. fontStyleCache[fontString] = fontStyle;
  40239. fontStyleCacheCount++;
  40240. }
  40241. return fontStyle;
  40242. };
  40243. var textMeasureEl;
  40244. // Overwrite measure text method
  40245. $override$1('measureText', function (text, textFont) {
  40246. var doc$$1 = doc;
  40247. if (!textMeasureEl) {
  40248. textMeasureEl = doc$$1.createElement('div');
  40249. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  40250. + 'padding:0;margin:0;border:none;white-space:pre;';
  40251. doc.body.appendChild(textMeasureEl);
  40252. }
  40253. try {
  40254. textMeasureEl.style.font = textFont;
  40255. } catch (ex) {
  40256. // Ignore failures to set to invalid font.
  40257. }
  40258. textMeasureEl.innerHTML = '';
  40259. // Don't use innerHTML or innerText because they allow markup/whitespace.
  40260. textMeasureEl.appendChild(doc$$1.createTextNode(text));
  40261. return {
  40262. width: textMeasureEl.offsetWidth
  40263. };
  40264. });
  40265. var tmpRect$2 = new BoundingRect();
  40266. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  40267. var style = this.style;
  40268. // Optimize, avoid normalize every time.
  40269. this.__dirty && normalizeTextStyle(style, true);
  40270. var text = style.text;
  40271. // Convert to string
  40272. text != null && (text += '');
  40273. if (!text) {
  40274. return;
  40275. }
  40276. // Convert rich text to plain text. Rich text is not supported in
  40277. // IE8-, but tags in rich text template will be removed.
  40278. if (style.rich) {
  40279. var contentBlock = parseRichText(text, style);
  40280. text = [];
  40281. for (var i = 0; i < contentBlock.lines.length; i++) {
  40282. var tokens = contentBlock.lines[i].tokens;
  40283. var textLine = [];
  40284. for (var j = 0; j < tokens.length; j++) {
  40285. textLine.push(tokens[j].text);
  40286. }
  40287. text.push(textLine.join(''));
  40288. }
  40289. text = text.join('\n');
  40290. }
  40291. var x;
  40292. var y;
  40293. var align = style.textAlign;
  40294. var verticalAlign = style.textVerticalAlign;
  40295. var fontStyle = getFontStyle(style.font);
  40296. // FIXME encodeHtmlAttribute ?
  40297. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  40298. + fontStyle.size + 'px "' + fontStyle.family + '"';
  40299. textRect = textRect || getBoundingRect(text, font, align, verticalAlign);
  40300. // Transform rect to view space
  40301. var m = this.transform;
  40302. // Ignore transform for text in other element
  40303. if (m && !fromTextEl) {
  40304. tmpRect$2.copy(rect);
  40305. tmpRect$2.applyTransform(m);
  40306. rect = tmpRect$2;
  40307. }
  40308. if (!fromTextEl) {
  40309. var textPosition = style.textPosition;
  40310. var distance$$1 = style.textDistance;
  40311. // Text position represented by coord
  40312. if (textPosition instanceof Array) {
  40313. x = rect.x + parsePercent$3(textPosition[0], rect.width);
  40314. y = rect.y + parsePercent$3(textPosition[1], rect.height);
  40315. align = align || 'left';
  40316. }
  40317. else {
  40318. var res = adjustTextPositionOnRect(
  40319. textPosition, rect, distance$$1
  40320. );
  40321. x = res.x;
  40322. y = res.y;
  40323. // Default align and baseline when has textPosition
  40324. align = align || res.textAlign;
  40325. verticalAlign = verticalAlign || res.textVerticalAlign;
  40326. }
  40327. }
  40328. else {
  40329. x = rect.x;
  40330. y = rect.y;
  40331. }
  40332. x = adjustTextX(x, textRect.width, align);
  40333. y = adjustTextY(y, textRect.height, verticalAlign);
  40334. // Force baseline 'middle'
  40335. y += textRect.height / 2;
  40336. // var fontSize = fontStyle.size;
  40337. // 1.75 is an arbitrary number, as there is no info about the text baseline
  40338. // switch (baseline) {
  40339. // case 'hanging':
  40340. // case 'top':
  40341. // y += fontSize / 1.75;
  40342. // break;
  40343. // case 'middle':
  40344. // break;
  40345. // default:
  40346. // // case null:
  40347. // // case 'alphabetic':
  40348. // // case 'ideographic':
  40349. // // case 'bottom':
  40350. // y -= fontSize / 2.25;
  40351. // break;
  40352. // }
  40353. // switch (align) {
  40354. // case 'left':
  40355. // break;
  40356. // case 'center':
  40357. // x -= textRect.width / 2;
  40358. // break;
  40359. // case 'right':
  40360. // x -= textRect.width;
  40361. // break;
  40362. // case 'end':
  40363. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  40364. // break;
  40365. // case 'start':
  40366. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  40367. // break;
  40368. // default:
  40369. // align = 'left';
  40370. // }
  40371. var createNode$$1 = createNode;
  40372. var textVmlEl = this._textVmlEl;
  40373. var pathEl;
  40374. var textPathEl;
  40375. var skewEl;
  40376. if (!textVmlEl) {
  40377. textVmlEl = createNode$$1('line');
  40378. pathEl = createNode$$1('path');
  40379. textPathEl = createNode$$1('textpath');
  40380. skewEl = createNode$$1('skew');
  40381. // FIXME Why here is not cammel case
  40382. // Align 'center' seems wrong
  40383. textPathEl.style['v-text-align'] = 'left';
  40384. initRootElStyle(textVmlEl);
  40385. pathEl.textpathok = true;
  40386. textPathEl.on = true;
  40387. textVmlEl.from = '0 0';
  40388. textVmlEl.to = '1000 0.05';
  40389. append(textVmlEl, skewEl);
  40390. append(textVmlEl, pathEl);
  40391. append(textVmlEl, textPathEl);
  40392. this._textVmlEl = textVmlEl;
  40393. }
  40394. else {
  40395. // 这里是在前面 appendChild 保证顺序的前提下
  40396. skewEl = textVmlEl.firstChild;
  40397. pathEl = skewEl.nextSibling;
  40398. textPathEl = pathEl.nextSibling;
  40399. }
  40400. var coords = [x, y];
  40401. var textVmlElStyle = textVmlEl.style;
  40402. // Ignore transform for text in other element
  40403. if (m && fromTextEl) {
  40404. applyTransform(coords, coords, m);
  40405. skewEl.on = true;
  40406. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma +
  40407. m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  40408. // Text position
  40409. skewEl.offset = (round$2(coords[0]) || 0) + ',' + (round$2(coords[1]) || 0);
  40410. // Left top point as origin
  40411. skewEl.origin = '0 0';
  40412. textVmlElStyle.left = '0px';
  40413. textVmlElStyle.top = '0px';
  40414. }
  40415. else {
  40416. skewEl.on = false;
  40417. textVmlElStyle.left = round$2(x) + 'px';
  40418. textVmlElStyle.top = round$2(y) + 'px';
  40419. }
  40420. textPathEl.string = encodeHtmlAttribute(text);
  40421. // TODO
  40422. try {
  40423. textPathEl.style.font = font;
  40424. }
  40425. // Error font format
  40426. catch (e) {}
  40427. updateFillAndStroke(textVmlEl, 'fill', {
  40428. fill: style.textFill,
  40429. opacity: style.opacity
  40430. }, this);
  40431. updateFillAndStroke(textVmlEl, 'stroke', {
  40432. stroke: style.textStroke,
  40433. opacity: style.opacity,
  40434. lineDash: style.lineDash
  40435. }, this);
  40436. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  40437. // Attached to root
  40438. append(vmlRoot, textVmlEl);
  40439. };
  40440. var removeRectText = function (vmlRoot) {
  40441. remove(vmlRoot, this._textVmlEl);
  40442. this._textVmlEl = null;
  40443. };
  40444. var appendRectText = function (vmlRoot) {
  40445. append(vmlRoot, this._textVmlEl);
  40446. };
  40447. var list = [RectText, Displayable, ZImage, Path, Text];
  40448. // In case Displayable has been mixed in RectText
  40449. for (var i$1 = 0; i$1 < list.length; i$1++) {
  40450. var proto$5 = list[i$1].prototype;
  40451. proto$5.drawRectText = drawRectText;
  40452. proto$5.removeRectText = removeRectText;
  40453. proto$5.appendRectText = appendRectText;
  40454. }
  40455. Text.prototype.brushVML = function (vmlRoot) {
  40456. var style = this.style;
  40457. if (style.text != null) {
  40458. this.drawRectText(vmlRoot, {
  40459. x: style.x || 0, y: style.y || 0,
  40460. width: 0, height: 0
  40461. }, this.getBoundingRect(), true);
  40462. }
  40463. else {
  40464. this.removeRectText(vmlRoot);
  40465. }
  40466. };
  40467. Text.prototype.onRemove = function (vmlRoot) {
  40468. this.removeRectText(vmlRoot);
  40469. };
  40470. Text.prototype.onAdd = function (vmlRoot) {
  40471. this.appendRectText(vmlRoot);
  40472. };
  40473. }
  40474. /**
  40475. * VML Painter.
  40476. *
  40477. * @module zrender/vml/Painter
  40478. */
  40479. function parseInt10$1(val) {
  40480. return parseInt(val, 10);
  40481. }
  40482. /**
  40483. * @alias module:zrender/vml/Painter
  40484. */
  40485. function VMLPainter(root, storage) {
  40486. initVML();
  40487. this.root = root;
  40488. this.storage = storage;
  40489. var vmlViewport = document.createElement('div');
  40490. var vmlRoot = document.createElement('div');
  40491. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  40492. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  40493. root.appendChild(vmlViewport);
  40494. this._vmlRoot = vmlRoot;
  40495. this._vmlViewport = vmlViewport;
  40496. this.resize();
  40497. // Modify storage
  40498. var oldDelFromStorage = storage.delFromStorage;
  40499. var oldAddToStorage = storage.addToStorage;
  40500. storage.delFromStorage = function (el) {
  40501. oldDelFromStorage.call(storage, el);
  40502. if (el) {
  40503. el.onRemove && el.onRemove(vmlRoot);
  40504. }
  40505. };
  40506. storage.addToStorage = function (el) {
  40507. // Displayable already has a vml node
  40508. el.onAdd && el.onAdd(vmlRoot);
  40509. oldAddToStorage.call(storage, el);
  40510. };
  40511. this._firstPaint = true;
  40512. }
  40513. VMLPainter.prototype = {
  40514. constructor: VMLPainter,
  40515. getType: function () {
  40516. return 'vml';
  40517. },
  40518. /**
  40519. * @return {HTMLDivElement}
  40520. */
  40521. getViewportRoot: function () {
  40522. return this._vmlViewport;
  40523. },
  40524. getViewportRootOffset: function () {
  40525. var viewportRoot = this.getViewportRoot();
  40526. if (viewportRoot) {
  40527. return {
  40528. offsetLeft: viewportRoot.offsetLeft || 0,
  40529. offsetTop: viewportRoot.offsetTop || 0
  40530. };
  40531. }
  40532. },
  40533. /**
  40534. * 刷新
  40535. */
  40536. refresh: function () {
  40537. var list = this.storage.getDisplayList(true, true);
  40538. this._paintList(list);
  40539. },
  40540. _paintList: function (list) {
  40541. var vmlRoot = this._vmlRoot;
  40542. for (var i = 0; i < list.length; i++) {
  40543. var el = list[i];
  40544. if (el.invisible || el.ignore) {
  40545. if (!el.__alreadyNotVisible) {
  40546. el.onRemove(vmlRoot);
  40547. }
  40548. // Set as already invisible
  40549. el.__alreadyNotVisible = true;
  40550. }
  40551. else {
  40552. if (el.__alreadyNotVisible) {
  40553. el.onAdd(vmlRoot);
  40554. }
  40555. el.__alreadyNotVisible = false;
  40556. if (el.__dirty) {
  40557. el.beforeBrush && el.beforeBrush();
  40558. (el.brushVML || el.brush).call(el, vmlRoot);
  40559. el.afterBrush && el.afterBrush();
  40560. }
  40561. }
  40562. el.__dirty = false;
  40563. }
  40564. if (this._firstPaint) {
  40565. // Detached from document at first time
  40566. // to avoid page refreshing too many times
  40567. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  40568. this._vmlViewport.appendChild(vmlRoot);
  40569. this._firstPaint = false;
  40570. }
  40571. },
  40572. resize: function (width, height) {
  40573. var width = width == null ? this._getWidth() : width;
  40574. var height = height == null ? this._getHeight() : height;
  40575. if (this._width != width || this._height != height) {
  40576. this._width = width;
  40577. this._height = height;
  40578. var vmlViewportStyle = this._vmlViewport.style;
  40579. vmlViewportStyle.width = width + 'px';
  40580. vmlViewportStyle.height = height + 'px';
  40581. }
  40582. },
  40583. dispose: function () {
  40584. this.root.innerHTML = '';
  40585. this._vmlRoot =
  40586. this._vmlViewport =
  40587. this.storage = null;
  40588. },
  40589. getWidth: function () {
  40590. return this._width;
  40591. },
  40592. getHeight: function () {
  40593. return this._height;
  40594. },
  40595. clear: function () {
  40596. if (this._vmlViewport) {
  40597. this.root.removeChild(this._vmlViewport);
  40598. }
  40599. },
  40600. _getWidth: function () {
  40601. var root = this.root;
  40602. var stl = root.currentStyle;
  40603. return ((root.clientWidth || parseInt10$1(stl.width))
  40604. - parseInt10$1(stl.paddingLeft)
  40605. - parseInt10$1(stl.paddingRight)) | 0;
  40606. },
  40607. _getHeight: function () {
  40608. var root = this.root;
  40609. var stl = root.currentStyle;
  40610. return ((root.clientHeight || parseInt10$1(stl.height))
  40611. - parseInt10$1(stl.paddingTop)
  40612. - parseInt10$1(stl.paddingBottom)) | 0;
  40613. }
  40614. };
  40615. // Not supported methods
  40616. function createMethodNotSupport(method) {
  40617. return function () {
  40618. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  40619. };
  40620. }
  40621. // Unsupported methods
  40622. each$1([
  40623. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer', 'eachOtherLayer', 'getLayers',
  40624. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  40625. ], function (name) {
  40626. VMLPainter.prototype[name] = createMethodNotSupport(name);
  40627. });
  40628. registerPainter('vml', VMLPainter);
  40629. var svgURI = 'http://www.w3.org/2000/svg';
  40630. function createElement(name) {
  40631. return document.createElementNS(svgURI, name);
  40632. }
  40633. // TODO
  40634. // 1. shadow
  40635. // 2. Image: sx, sy, sw, sh
  40636. var CMD$4 = PathProxy.CMD;
  40637. var arrayJoin = Array.prototype.join;
  40638. var NONE = 'none';
  40639. var mathRound = Math.round;
  40640. var mathSin$3 = Math.sin;
  40641. var mathCos$3 = Math.cos;
  40642. var PI$3 = Math.PI;
  40643. var PI2$5 = Math.PI * 2;
  40644. var degree = 180 / PI$3;
  40645. var EPSILON$4 = 1e-4;
  40646. function round4(val) {
  40647. return mathRound(val * 1e4) / 1e4;
  40648. }
  40649. function isAroundZero$1(val) {
  40650. return val < EPSILON$4 && val > -EPSILON$4;
  40651. }
  40652. function pathHasFill(style, isText) {
  40653. var fill = isText ? style.textFill : style.fill;
  40654. return fill != null && fill !== NONE;
  40655. }
  40656. function pathHasStroke(style, isText) {
  40657. var stroke = isText ? style.textStroke : style.stroke;
  40658. return stroke != null && stroke !== NONE;
  40659. }
  40660. function setTransform(svgEl, m) {
  40661. if (m) {
  40662. attr(svgEl, 'transform', 'matrix(' + arrayJoin.call(m, ',') + ')');
  40663. }
  40664. }
  40665. function attr(el, key, val) {
  40666. if (!val || val.type !== 'linear' && val.type !== 'radial') {
  40667. // Don't set attribute for gradient, since it need new dom nodes
  40668. el.setAttribute(key, val);
  40669. }
  40670. }
  40671. function attrXLink(el, key, val) {
  40672. el.setAttributeNS('http://www.w3.org/1999/xlink', key, val);
  40673. }
  40674. function bindStyle(svgEl, style, isText) {
  40675. if (pathHasFill(style, isText)) {
  40676. var fill = isText ? style.textFill : style.fill;
  40677. fill = fill === 'transparent' ? NONE : fill;
  40678. /**
  40679. * FIXME:
  40680. * This is a temporary fix for Chrome's clipping bug
  40681. * that happens when a clip-path is referring another one.
  40682. * This fix should be used before Chrome's bug is fixed.
  40683. * For an element that has clip-path, and fill is none,
  40684. * set it to be "rgba(0, 0, 0, 0.002)" will hide the element.
  40685. * Otherwise, it will show black fill color.
  40686. * 0.002 is used because this won't work for alpha values smaller
  40687. * than 0.002.
  40688. *
  40689. * See
  40690. * https://bugs.chromium.org/p/chromium/issues/detail?id=659790
  40691. * for more information.
  40692. */
  40693. if (svgEl.getAttribute('clip-path') !== 'none' && fill === NONE) {
  40694. fill = 'rgba(0, 0, 0, 0.002)';
  40695. }
  40696. attr(svgEl, 'fill', fill);
  40697. attr(svgEl, 'fill-opacity', style.opacity);
  40698. }
  40699. else {
  40700. attr(svgEl, 'fill', NONE);
  40701. }
  40702. if (pathHasStroke(style, isText)) {
  40703. var stroke = isText ? style.textStroke : style.stroke;
  40704. stroke = stroke === 'transparent' ? NONE : stroke;
  40705. attr(svgEl, 'stroke', stroke);
  40706. var strokeWidth = isText
  40707. ? style.textStrokeWidth
  40708. : style.lineWidth;
  40709. var strokeScale = style.strokeNoScale
  40710. ? style.host.getLineScale()
  40711. : 1;
  40712. attr(svgEl, 'stroke-width', strokeWidth / strokeScale);
  40713. attr(svgEl, 'paint-order', 'stroke');
  40714. attr(svgEl, 'stroke-opacity', style.opacity);
  40715. var lineDash = style.lineDash;
  40716. if (lineDash) {
  40717. attr(svgEl, 'stroke-dasharray', style.lineDash.join(','));
  40718. attr(svgEl, 'stroke-dashoffset', mathRound(style.lineDashOffset || 0));
  40719. }
  40720. else {
  40721. attr(svgEl, 'stroke-dasharray', '');
  40722. }
  40723. // PENDING
  40724. style.lineCap && attr(svgEl, 'stroke-linecap', style.lineCap);
  40725. style.lineJoin && attr(svgEl, 'stroke-linejoin', style.lineJoin);
  40726. style.miterLimit && attr(svgEl, 'stroke-miterlimit', style.miterLimit);
  40727. }
  40728. else {
  40729. attr(svgEl, 'stroke', NONE);
  40730. }
  40731. }
  40732. /***************************************************
  40733. * PATH
  40734. **************************************************/
  40735. function pathDataToString$1(path) {
  40736. var str = [];
  40737. var data = path.data;
  40738. var dataLength = path.len();
  40739. for (var i = 0; i < dataLength;) {
  40740. var cmd = data[i++];
  40741. var cmdStr = '';
  40742. var nData = 0;
  40743. switch (cmd) {
  40744. case CMD$4.M:
  40745. cmdStr = 'M';
  40746. nData = 2;
  40747. break;
  40748. case CMD$4.L:
  40749. cmdStr = 'L';
  40750. nData = 2;
  40751. break;
  40752. case CMD$4.Q:
  40753. cmdStr = 'Q';
  40754. nData = 4;
  40755. break;
  40756. case CMD$4.C:
  40757. cmdStr = 'C';
  40758. nData = 6;
  40759. break;
  40760. case CMD$4.A:
  40761. var cx = data[i++];
  40762. var cy = data[i++];
  40763. var rx = data[i++];
  40764. var ry = data[i++];
  40765. var theta = data[i++];
  40766. var dTheta = data[i++];
  40767. var psi = data[i++];
  40768. var clockwise = data[i++];
  40769. var dThetaPositive = Math.abs(dTheta);
  40770. var isCircle = isAroundZero$1(dThetaPositive % PI2$5)
  40771. && !isAroundZero$1(dThetaPositive);
  40772. var large = false;
  40773. if (dThetaPositive >= PI2$5) {
  40774. large = true;
  40775. }
  40776. else if (isAroundZero$1(dThetaPositive)) {
  40777. large = false;
  40778. }
  40779. else {
  40780. large = (dTheta > -PI$3 && dTheta < 0 || dTheta > PI$3)
  40781. === !!clockwise;
  40782. }
  40783. var x0 = round4(cx + rx * mathCos$3(theta));
  40784. var y0 = round4(cy + ry * mathSin$3(theta));
  40785. // It will not draw if start point and end point are exactly the same
  40786. // We need to shift the end point with a small value
  40787. // FIXME A better way to draw circle ?
  40788. if (isCircle) {
  40789. if (clockwise) {
  40790. dTheta = PI2$5 - 1e-4;
  40791. }
  40792. else {
  40793. dTheta = -PI2$5 + 1e-4;
  40794. }
  40795. large = true;
  40796. if (i === 9) {
  40797. // Move to (x0, y0) only when CMD.A comes at the
  40798. // first position of a shape.
  40799. // For instance, when drawing a ring, CMD.A comes
  40800. // after CMD.M, so it's unnecessary to move to
  40801. // (x0, y0).
  40802. str.push('M', x0, y0);
  40803. }
  40804. }
  40805. var x = round4(cx + rx * mathCos$3(theta + dTheta));
  40806. var y = round4(cy + ry * mathSin$3(theta + dTheta));
  40807. // FIXME Ellipse
  40808. str.push('A', round4(rx), round4(ry),
  40809. mathRound(psi * degree), +large, +clockwise, x, y);
  40810. break;
  40811. case CMD$4.Z:
  40812. cmdStr = 'Z';
  40813. break;
  40814. case CMD$4.R:
  40815. var x = round4(data[i++]);
  40816. var y = round4(data[i++]);
  40817. var w = round4(data[i++]);
  40818. var h = round4(data[i++]);
  40819. str.push(
  40820. 'M', x, y,
  40821. 'L', x + w, y,
  40822. 'L', x + w, y + h,
  40823. 'L', x, y + h,
  40824. 'L', x, y
  40825. );
  40826. break;
  40827. }
  40828. cmdStr && str.push(cmdStr);
  40829. for (var j = 0; j < nData; j++) {
  40830. // PENDING With scale
  40831. str.push(round4(data[i++]));
  40832. }
  40833. }
  40834. return str.join(' ');
  40835. }
  40836. var svgPath = {};
  40837. svgPath.brush = function (el) {
  40838. var style = el.style;
  40839. var svgEl = el.__svgEl;
  40840. if (!svgEl) {
  40841. svgEl = createElement('path');
  40842. el.__svgEl = svgEl;
  40843. }
  40844. if (!el.path) {
  40845. el.createPathProxy();
  40846. }
  40847. var path = el.path;
  40848. if (el.__dirtyPath) {
  40849. path.beginPath();
  40850. el.buildPath(path, el.shape);
  40851. el.__dirtyPath = false;
  40852. var pathStr = pathDataToString$1(path);
  40853. if (pathStr.indexOf('NaN') < 0) {
  40854. // Ignore illegal path, which may happen such in out-of-range
  40855. // data in Calendar series.
  40856. attr(svgEl, 'd', pathStr);
  40857. }
  40858. }
  40859. bindStyle(svgEl, style);
  40860. setTransform(svgEl, el.transform);
  40861. if (style.text != null) {
  40862. svgTextDrawRectText(el, el.getBoundingRect());
  40863. }
  40864. };
  40865. /***************************************************
  40866. * IMAGE
  40867. **************************************************/
  40868. var svgImage = {};
  40869. svgImage.brush = function (el) {
  40870. var style = el.style;
  40871. var image = style.image;
  40872. if (image instanceof HTMLImageElement) {
  40873. var src = image.src;
  40874. image = src;
  40875. }
  40876. if (! image) {
  40877. return;
  40878. }
  40879. var x = style.x || 0;
  40880. var y = style.y || 0;
  40881. var dw = style.width;
  40882. var dh = style.height;
  40883. var svgEl = el.__svgEl;
  40884. if (! svgEl) {
  40885. svgEl = createElement('image');
  40886. el.__svgEl = svgEl;
  40887. }
  40888. if (image !== el.__imageSrc) {
  40889. attrXLink(svgEl, 'href', image);
  40890. // Caching image src
  40891. el.__imageSrc = image;
  40892. }
  40893. attr(svgEl, 'width', dw);
  40894. attr(svgEl, 'height', dh);
  40895. attr(svgEl, 'x', x);
  40896. attr(svgEl, 'y', y);
  40897. setTransform(svgEl, el.transform);
  40898. if (style.text != null) {
  40899. svgTextDrawRectText(el, el.getBoundingRect());
  40900. }
  40901. };
  40902. /***************************************************
  40903. * TEXT
  40904. **************************************************/
  40905. var svgText = {};
  40906. var tmpRect$3 = new BoundingRect();
  40907. var svgTextDrawRectText = function (el, rect, textRect) {
  40908. var style = el.style;
  40909. el.__dirty && normalizeTextStyle(style, true);
  40910. var text = style.text;
  40911. // Convert to string
  40912. if (text == null) {
  40913. // Draw no text only when text is set to null, but not ''
  40914. return;
  40915. }
  40916. else {
  40917. text += '';
  40918. }
  40919. var textSvgEl = el.__textSvgEl;
  40920. if (! textSvgEl) {
  40921. textSvgEl = createElement('text');
  40922. el.__textSvgEl = textSvgEl;
  40923. }
  40924. bindStyle(textSvgEl, style, true);
  40925. if (el instanceof Text || el.style.transformText) {
  40926. // Transform text with element
  40927. setTransform(textSvgEl, el.transform);
  40928. }
  40929. else {
  40930. if (el.transform) {
  40931. tmpRect$3.copy(rect);
  40932. tmpRect$3.applyTransform(el.transform);
  40933. rect = tmpRect$3;
  40934. }
  40935. else {
  40936. var pos = el.transformCoordToGlobal(rect.x, rect.y);
  40937. rect.x = pos[0];
  40938. rect.y = pos[1];
  40939. }
  40940. }
  40941. var x;
  40942. var y;
  40943. var textPosition = style.textPosition;
  40944. var distance = style.textDistance;
  40945. var align = style.textAlign || 'left';
  40946. if (typeof style.fontSize === 'number') {
  40947. style.fontSize += 'px';
  40948. }
  40949. var font = style.font
  40950. || [
  40951. style.fontStyle || '',
  40952. style.fontWeight || '',
  40953. style.fontSize || '',
  40954. style.fontFamily || ''
  40955. ].join(' ')
  40956. || DEFAULT_FONT;
  40957. var verticalAlign = getVerticalAlignForSvg(style.textVerticalAlign);
  40958. textRect = getBoundingRect(text, font, align,
  40959. verticalAlign);
  40960. var lineHeight = textRect.lineHeight;
  40961. // Text position represented by coord
  40962. if (textPosition instanceof Array) {
  40963. x = rect.x + textPosition[0];
  40964. y = rect.y + textPosition[1];
  40965. }
  40966. else {
  40967. var newPos = adjustTextPositionOnRect(
  40968. textPosition, rect, distance
  40969. );
  40970. x = newPos.x;
  40971. y = newPos.y;
  40972. verticalAlign = getVerticalAlignForSvg(newPos.textVerticalAlign);
  40973. align = newPos.textAlign;
  40974. }
  40975. attr(textSvgEl, 'alignment-baseline', verticalAlign);
  40976. if (font) {
  40977. textSvgEl.style.font = font;
  40978. }
  40979. var textPadding = style.textPadding;
  40980. // Make baseline top
  40981. attr(textSvgEl, 'x', x);
  40982. attr(textSvgEl, 'y', y);
  40983. var textLines = text.split('\n');
  40984. var nTextLines = textLines.length;
  40985. var textAnchor = align;
  40986. // PENDING
  40987. if (textAnchor === 'left') {
  40988. textAnchor = 'start';
  40989. textPadding && (x += textPadding[3]);
  40990. }
  40991. else if (textAnchor === 'right') {
  40992. textAnchor = 'end';
  40993. textPadding && (x -= textPadding[1]);
  40994. }
  40995. else if (textAnchor === 'center') {
  40996. textAnchor = 'middle';
  40997. textPadding && (x += (textPadding[3] - textPadding[1]) / 2);
  40998. }
  40999. var dy = 0;
  41000. if (verticalAlign === 'baseline') {
  41001. dy = -textRect.height + lineHeight;
  41002. textPadding && (dy -= textPadding[2]);
  41003. }
  41004. else if (verticalAlign === 'middle') {
  41005. dy = (-textRect.height + lineHeight) / 2;
  41006. textPadding && (y += (textPadding[0] - textPadding[2]) / 2);
  41007. }
  41008. else {
  41009. textPadding && (dy += textPadding[0]);
  41010. }
  41011. // Font may affect position of each tspan elements
  41012. if (el.__text !== text || el.__textFont !== font) {
  41013. var tspanList = el.__tspanList || [];
  41014. el.__tspanList = tspanList;
  41015. for (var i = 0; i < nTextLines; i++) {
  41016. // Using cached tspan elements
  41017. var tspan = tspanList[i];
  41018. if (! tspan) {
  41019. tspan = tspanList[i] = createElement('tspan');
  41020. textSvgEl.appendChild(tspan);
  41021. attr(tspan, 'alignment-baseline', verticalAlign);
  41022. attr(tspan, 'text-anchor', textAnchor);
  41023. }
  41024. else {
  41025. tspan.innerHTML = '';
  41026. }
  41027. attr(tspan, 'x', x);
  41028. attr(tspan, 'y', y + i * lineHeight + dy);
  41029. tspan.appendChild(document.createTextNode(textLines[i]));
  41030. }
  41031. // Remove unsed tspan elements
  41032. for (; i < tspanList.length; i++) {
  41033. textSvgEl.removeChild(tspanList[i]);
  41034. }
  41035. tspanList.length = nTextLines;
  41036. el.__text = text;
  41037. el.__textFont = font;
  41038. }
  41039. else if (el.__tspanList.length) {
  41040. // Update span x and y
  41041. var len = el.__tspanList.length;
  41042. for (var i = 0; i < len; ++i) {
  41043. var tspan = el.__tspanList[i];
  41044. if (tspan) {
  41045. attr(tspan, 'x', x);
  41046. attr(tspan, 'y', y + i * lineHeight + dy);
  41047. }
  41048. }
  41049. }
  41050. };
  41051. function getVerticalAlignForSvg(verticalAlign) {
  41052. if (verticalAlign === 'middle') {
  41053. return 'middle';
  41054. }
  41055. else if (verticalAlign === 'bottom') {
  41056. return 'baseline';
  41057. }
  41058. else {
  41059. return 'hanging';
  41060. }
  41061. }
  41062. svgText.drawRectText = svgTextDrawRectText;
  41063. svgText.brush = function (el) {
  41064. var style = el.style;
  41065. if (style.text != null) {
  41066. // 强制设置 textPosition
  41067. style.textPosition = [0, 0];
  41068. svgTextDrawRectText(el, {
  41069. x: style.x || 0, y: style.y || 0,
  41070. width: 0, height: 0
  41071. }, el.getBoundingRect());
  41072. }
  41073. };
  41074. // Myers' Diff Algorithm
  41075. // Modified from https://github.com/kpdecker/jsdiff/blob/master/src/diff/base.js
  41076. function Diff() {}
  41077. Diff.prototype = {
  41078. diff: function (oldArr, newArr, equals) {
  41079. if (!equals) {
  41080. equals = function (a, b) {
  41081. return a === b;
  41082. };
  41083. }
  41084. this.equals = equals;
  41085. var self = this;
  41086. oldArr = oldArr.slice();
  41087. newArr = newArr.slice();
  41088. // Allow subclasses to massage the input prior to running
  41089. var newLen = newArr.length;
  41090. var oldLen = oldArr.length;
  41091. var editLength = 1;
  41092. var maxEditLength = newLen + oldLen;
  41093. var bestPath = [{ newPos: -1, components: [] }];
  41094. // Seed editLength = 0, i.e. the content starts with the same values
  41095. var oldPos = this.extractCommon(bestPath[0], newArr, oldArr, 0);
  41096. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  41097. var indices = [];
  41098. for (var i = 0; i < newArr.length; i++) {
  41099. indices.push(i);
  41100. }
  41101. // Identity per the equality and tokenizer
  41102. return [{
  41103. indices: indices, count: newArr.length
  41104. }];
  41105. }
  41106. // Main worker method. checks all permutations of a given edit length for acceptance.
  41107. function execEditLength() {
  41108. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  41109. var basePath;
  41110. var addPath = bestPath[diagonalPath - 1];
  41111. var removePath = bestPath[diagonalPath + 1];
  41112. var oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  41113. if (addPath) {
  41114. // No one else is going to attempt to use this value, clear it
  41115. bestPath[diagonalPath - 1] = undefined;
  41116. }
  41117. var canAdd = addPath && addPath.newPos + 1 < newLen;
  41118. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  41119. if (!canAdd && !canRemove) {
  41120. // If this path is a terminal then prune
  41121. bestPath[diagonalPath] = undefined;
  41122. continue;
  41123. }
  41124. // Select the diagonal that we want to branch from. We select the prior
  41125. // path whose position in the new string is the farthest from the origin
  41126. // and does not pass the bounds of the diff graph
  41127. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  41128. basePath = clonePath(removePath);
  41129. self.pushComponent(basePath.components, undefined, true);
  41130. }
  41131. else {
  41132. basePath = addPath; // No need to clone, we've pulled it from the list
  41133. basePath.newPos++;
  41134. self.pushComponent(basePath.components, true, undefined);
  41135. }
  41136. oldPos = self.extractCommon(basePath, newArr, oldArr, diagonalPath);
  41137. // If we have hit the end of both strings, then we are done
  41138. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  41139. return buildValues(self, basePath.components, newArr, oldArr);
  41140. }
  41141. else {
  41142. // Otherwise track this path as a potential candidate and continue.
  41143. bestPath[diagonalPath] = basePath;
  41144. }
  41145. }
  41146. editLength++;
  41147. }
  41148. while (editLength <= maxEditLength) {
  41149. var ret = execEditLength();
  41150. if (ret) {
  41151. return ret;
  41152. }
  41153. }
  41154. },
  41155. pushComponent: function (components, added, removed) {
  41156. var last = components[components.length - 1];
  41157. if (last && last.added === added && last.removed === removed) {
  41158. // We need to clone here as the component clone operation is just
  41159. // as shallow array clone
  41160. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  41161. }
  41162. else {
  41163. components.push({count: 1, added: added, removed: removed });
  41164. }
  41165. },
  41166. extractCommon: function (basePath, newArr, oldArr, diagonalPath) {
  41167. var newLen = newArr.length;
  41168. var oldLen = oldArr.length;
  41169. var newPos = basePath.newPos;
  41170. var oldPos = newPos - diagonalPath;
  41171. var commonCount = 0;
  41172. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newArr[newPos + 1], oldArr[oldPos + 1])) {
  41173. newPos++;
  41174. oldPos++;
  41175. commonCount++;
  41176. }
  41177. if (commonCount) {
  41178. basePath.components.push({count: commonCount});
  41179. }
  41180. basePath.newPos = newPos;
  41181. return oldPos;
  41182. },
  41183. tokenize: function (value) {
  41184. return value.slice();
  41185. },
  41186. join: function (value) {
  41187. return value.slice();
  41188. }
  41189. };
  41190. function buildValues(diff, components, newArr, oldArr) {
  41191. var componentPos = 0;
  41192. var componentLen = components.length;
  41193. var newPos = 0;
  41194. var oldPos = 0;
  41195. for (; componentPos < componentLen; componentPos++) {
  41196. var component = components[componentPos];
  41197. if (!component.removed) {
  41198. var indices = [];
  41199. for (var i = newPos; i < newPos + component.count; i++) {
  41200. indices.push(i);
  41201. }
  41202. component.indices = indices;
  41203. newPos += component.count;
  41204. // Common case
  41205. if (!component.added) {
  41206. oldPos += component.count;
  41207. }
  41208. }
  41209. else {
  41210. var indices = [];
  41211. for (var i = oldPos; i < oldPos + component.count; i++) {
  41212. indices.push(i);
  41213. }
  41214. component.indices = indices;
  41215. oldPos += component.count;
  41216. }
  41217. }
  41218. return components;
  41219. }
  41220. function clonePath(path) {
  41221. return { newPos: path.newPos, components: path.components.slice(0) };
  41222. }
  41223. var arrayDiff = new Diff();
  41224. var arrayDiff$1 = function (oldArr, newArr, callback) {
  41225. return arrayDiff.diff(oldArr, newArr, callback);
  41226. };
  41227. /**
  41228. * @file Manages elements that can be defined in <defs> in SVG,
  41229. * e.g., gradients, clip path, etc.
  41230. * @author Zhang Wenli
  41231. */
  41232. var MARK_UNUSED = '0';
  41233. var MARK_USED = '1';
  41234. /**
  41235. * Manages elements that can be defined in <defs> in SVG,
  41236. * e.g., gradients, clip path, etc.
  41237. *
  41238. * @class
  41239. * @param {SVGElement} svgRoot root of SVG document
  41240. * @param {string|string[]} tagNames possible tag names
  41241. * @param {string} markLabel label name to make if the element
  41242. * is used
  41243. */
  41244. function Definable(
  41245. svgRoot,
  41246. tagNames,
  41247. markLabel
  41248. ) {
  41249. this._svgRoot = svgRoot;
  41250. this._tagNames = typeof tagNames === 'string' ? [tagNames] : tagNames;
  41251. this._markLabel = markLabel;
  41252. this.nextId = 0;
  41253. }
  41254. Definable.prototype.createElement = createElement;
  41255. /**
  41256. * Get the <defs> tag for svgRoot; optionally creates one if not exists.
  41257. *
  41258. * @param {boolean} isForceCreating if need to create when not exists
  41259. * @return {SVGDefsElement} SVG <defs> element, null if it doesn't
  41260. * exist and isForceCreating is false
  41261. */
  41262. Definable.prototype.getDefs = function (isForceCreating) {
  41263. var svgRoot = this._svgRoot;
  41264. var defs = this._svgRoot.getElementsByTagName('defs');
  41265. if (defs.length === 0) {
  41266. // Not exist
  41267. if (isForceCreating) {
  41268. defs = svgRoot.insertBefore(
  41269. this.createElement('defs'), // Create new tag
  41270. svgRoot.firstChild // Insert in the front of svg
  41271. );
  41272. if (!defs.contains) {
  41273. // IE doesn't support contains method
  41274. defs.contains = function (el) {
  41275. var children = defs.children;
  41276. if (!children) {
  41277. return false;
  41278. }
  41279. for (var i = children.length - 1; i >= 0; --i) {
  41280. if (children[i] === el) {
  41281. return true;
  41282. }
  41283. }
  41284. return false;
  41285. };
  41286. }
  41287. return defs;
  41288. }
  41289. else {
  41290. return null;
  41291. }
  41292. }
  41293. else {
  41294. return defs[0];
  41295. }
  41296. };
  41297. /**
  41298. * Update DOM element if necessary.
  41299. *
  41300. * @param {Object|string} element style element. e.g., for gradient,
  41301. * it may be '#ccc' or {type: 'linear', ...}
  41302. * @param {Function|undefined} onUpdate update callback
  41303. */
  41304. Definable.prototype.update = function (element, onUpdate) {
  41305. if (!element) {
  41306. return;
  41307. }
  41308. var defs = this.getDefs(false);
  41309. if (element._dom && defs.contains(element._dom)) {
  41310. // Update DOM
  41311. if (typeof onUpdate === 'function') {
  41312. onUpdate();
  41313. }
  41314. }
  41315. else {
  41316. // No previous dom, create new
  41317. var dom = this.add(element);
  41318. if (dom) {
  41319. element._dom = dom;
  41320. }
  41321. }
  41322. };
  41323. /**
  41324. * Add gradient dom to defs
  41325. *
  41326. * @param {SVGElement} dom DOM to be added to <defs>
  41327. */
  41328. Definable.prototype.addDom = function (dom) {
  41329. var defs = this.getDefs(true);
  41330. defs.appendChild(dom);
  41331. };
  41332. /**
  41333. * Remove DOM of a given element.
  41334. *
  41335. * @param {SVGElement} element element to remove dom
  41336. */
  41337. Definable.prototype.removeDom = function (element) {
  41338. var defs = this.getDefs(false);
  41339. defs.removeChild(element._dom);
  41340. };
  41341. /**
  41342. * Get DOMs of this element.
  41343. *
  41344. * @return {HTMLDomElement} doms of this defineable elements in <defs>
  41345. */
  41346. Definable.prototype.getDoms = function () {
  41347. var defs = this.getDefs(false);
  41348. if (!defs) {
  41349. // No dom when defs is not defined
  41350. return [];
  41351. }
  41352. var doms = [];
  41353. each$1(this._tagNames, function (tagName) {
  41354. var tags = defs.getElementsByTagName(tagName);
  41355. // Note that tags is HTMLCollection, which is array-like
  41356. // rather than real array.
  41357. // So `doms.concat(tags)` add tags as one object.
  41358. doms = doms.concat([].slice.call(tags));
  41359. });
  41360. return doms;
  41361. };
  41362. /**
  41363. * Mark DOMs to be unused before painting, and clear unused ones at the end
  41364. * of the painting.
  41365. */
  41366. Definable.prototype.markAllUnused = function () {
  41367. var doms = this.getDoms();
  41368. var that = this;
  41369. each$1(doms, function (dom) {
  41370. dom[that._markLabel] = MARK_UNUSED;
  41371. });
  41372. };
  41373. /**
  41374. * Mark a single DOM to be used.
  41375. *
  41376. * @param {SVGElement} dom DOM to mark
  41377. */
  41378. Definable.prototype.markUsed = function (dom) {
  41379. if (dom) {
  41380. dom[this._markLabel] = MARK_USED;
  41381. }
  41382. };
  41383. /**
  41384. * Remove unused DOMs defined in <defs>
  41385. */
  41386. Definable.prototype.removeUnused = function () {
  41387. var defs = this.getDefs(false);
  41388. if (!defs) {
  41389. // Nothing to remove
  41390. return;
  41391. }
  41392. var doms = this.getDoms();
  41393. var that = this;
  41394. each$1(doms, function (dom) {
  41395. if (dom[that._markLabel] !== MARK_USED) {
  41396. // Remove gradient
  41397. defs.removeChild(dom);
  41398. }
  41399. });
  41400. };
  41401. /**
  41402. * Get SVG proxy.
  41403. *
  41404. * @param {Displayable} displayable displayable element
  41405. * @return {Path|Image|Text} svg proxy of given element
  41406. */
  41407. Definable.prototype.getSvgProxy = function (displayable) {
  41408. if (displayable instanceof Path) {
  41409. return svgPath;
  41410. }
  41411. else if (displayable instanceof ZImage) {
  41412. return svgImage;
  41413. }
  41414. else if (displayable instanceof Text) {
  41415. return svgText;
  41416. }
  41417. else {
  41418. return svgPath;
  41419. }
  41420. };
  41421. /**
  41422. * Get text SVG element.
  41423. *
  41424. * @param {Displayable} displayable displayable element
  41425. * @return {SVGElement} SVG element of text
  41426. */
  41427. Definable.prototype.getTextSvgElement = function (displayable) {
  41428. return displayable.__textSvgEl;
  41429. };
  41430. /**
  41431. * Get SVG element.
  41432. *
  41433. * @param {Displayable} displayable displayable element
  41434. * @return {SVGElement} SVG element
  41435. */
  41436. Definable.prototype.getSvgElement = function (displayable) {
  41437. return displayable.__svgEl;
  41438. };
  41439. /**
  41440. * @file Manages SVG gradient elements.
  41441. * @author Zhang Wenli
  41442. */
  41443. /**
  41444. * Manages SVG gradient elements.
  41445. *
  41446. * @class
  41447. * @extends Definable
  41448. * @param {SVGElement} svgRoot root of SVG document
  41449. */
  41450. function GradientManager(svgRoot) {
  41451. Definable.call(
  41452. this,
  41453. svgRoot,
  41454. ['linearGradient', 'radialGradient'],
  41455. '__gradient_in_use__'
  41456. );
  41457. }
  41458. inherits(GradientManager, Definable);
  41459. /**
  41460. * Create new gradient DOM for fill or stroke if not exist,
  41461. * but will not update gradient if exists.
  41462. *
  41463. * @param {SvgElement} svgElement SVG element to paint
  41464. * @param {Displayable} displayable zrender displayable element
  41465. */
  41466. GradientManager.prototype.addWithoutUpdate = function (
  41467. svgElement,
  41468. displayable
  41469. ) {
  41470. if (displayable && displayable.style) {
  41471. var that = this;
  41472. each$1(['fill', 'stroke'], function (fillOrStroke) {
  41473. if (displayable.style[fillOrStroke]
  41474. && (displayable.style[fillOrStroke].type === 'linear'
  41475. || displayable.style[fillOrStroke].type === 'radial')
  41476. ) {
  41477. var gradient = displayable.style[fillOrStroke];
  41478. var defs = that.getDefs(true);
  41479. // Create dom in <defs> if not exists
  41480. var dom;
  41481. if (gradient._dom) {
  41482. // Gradient exists
  41483. dom = gradient._dom;
  41484. if (!defs.contains(gradient._dom)) {
  41485. // _dom is no longer in defs, recreate
  41486. that.addDom(dom);
  41487. }
  41488. }
  41489. else {
  41490. // New dom
  41491. dom = that.add(gradient);
  41492. }
  41493. that.markUsed(displayable);
  41494. var id = dom.getAttribute('id');
  41495. svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
  41496. }
  41497. });
  41498. }
  41499. };
  41500. /**
  41501. * Add a new gradient tag in <defs>
  41502. *
  41503. * @param {Gradient} gradient zr gradient instance
  41504. * @return {SVGLinearGradientElement | SVGRadialGradientElement}
  41505. * created DOM
  41506. */
  41507. GradientManager.prototype.add = function (gradient) {
  41508. var dom;
  41509. if (gradient.type === 'linear') {
  41510. dom = this.createElement('linearGradient');
  41511. }
  41512. else if (gradient.type === 'radial') {
  41513. dom = this.createElement('radialGradient');
  41514. }
  41515. else {
  41516. zrLog('Illegal gradient type.');
  41517. return null;
  41518. }
  41519. // Set dom id with gradient id, since each gradient instance
  41520. // will have no more than one dom element.
  41521. // id may exists before for those dirty elements, in which case
  41522. // id should remain the same, and other attributes should be
  41523. // updated.
  41524. gradient.id = gradient.id || this.nextId++;
  41525. dom.setAttribute('id', 'zr-gradient-' + gradient.id);
  41526. this.updateDom(gradient, dom);
  41527. this.addDom(dom);
  41528. return dom;
  41529. };
  41530. /**
  41531. * Update gradient.
  41532. *
  41533. * @param {Gradient} gradient zr gradient instance
  41534. */
  41535. GradientManager.prototype.update = function (gradient) {
  41536. var that = this;
  41537. Definable.prototype.update.call(this, gradient, function () {
  41538. var type = gradient.type;
  41539. var tagName = gradient._dom.tagName;
  41540. if (type === 'linear' && tagName === 'linearGradient'
  41541. || type === 'radial' && tagName === 'radialGradient'
  41542. ) {
  41543. // Gradient type is not changed, update gradient
  41544. that.updateDom(gradient, gradient._dom);
  41545. }
  41546. else {
  41547. // Remove and re-create if type is changed
  41548. that.removeDom(gradient);
  41549. that.add(gradient);
  41550. }
  41551. });
  41552. };
  41553. /**
  41554. * Update gradient dom
  41555. *
  41556. * @param {Gradient} gradient zr gradient instance
  41557. * @param {SVGLinearGradientElement | SVGRadialGradientElement} dom
  41558. * DOM to update
  41559. */
  41560. GradientManager.prototype.updateDom = function (gradient, dom) {
  41561. if (gradient.type === 'linear') {
  41562. dom.setAttribute('x1', gradient.x);
  41563. dom.setAttribute('y1', gradient.y);
  41564. dom.setAttribute('x2', gradient.x2);
  41565. dom.setAttribute('y2', gradient.y2);
  41566. }
  41567. else if (gradient.type === 'radial') {
  41568. dom.setAttribute('cx', gradient.x);
  41569. dom.setAttribute('cy', gradient.y);
  41570. dom.setAttribute('r', gradient.r);
  41571. }
  41572. else {
  41573. zrLog('Illegal gradient type.');
  41574. return;
  41575. }
  41576. if (gradient.global) {
  41577. // x1, x2, y1, y2 in range of 0 to canvas width or height
  41578. dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  41579. }
  41580. else {
  41581. // x1, x2, y1, y2 in range of 0 to 1
  41582. dom.setAttribute('gradientUnits', 'objectBoundingBox');
  41583. }
  41584. // Remove color stops if exists
  41585. dom.innerHTML = '';
  41586. // Add color stops
  41587. var colors = gradient.colorStops;
  41588. for (var i = 0, len = colors.length; i < len; ++i) {
  41589. var stop = this.createElement('stop');
  41590. stop.setAttribute('offset', colors[i].offset * 100 + '%');
  41591. stop.setAttribute('stop-color', colors[i].color);
  41592. dom.appendChild(stop);
  41593. }
  41594. // Store dom element in gradient, to avoid creating multiple
  41595. // dom instances for the same gradient element
  41596. gradient._dom = dom;
  41597. };
  41598. /**
  41599. * Mark a single gradient to be used
  41600. *
  41601. * @param {Displayable} displayable displayable element
  41602. */
  41603. GradientManager.prototype.markUsed = function (displayable) {
  41604. if (displayable.style) {
  41605. var gradient = displayable.style.fill;
  41606. if (gradient && gradient._dom) {
  41607. Definable.prototype.markUsed.call(this, gradient._dom);
  41608. }
  41609. gradient = displayable.style.stroke;
  41610. if (gradient && gradient._dom) {
  41611. Definable.prototype.markUsed.call(this, gradient._dom);
  41612. }
  41613. }
  41614. };
  41615. /**
  41616. * @file Manages SVG clipPath elements.
  41617. * @author Zhang Wenli
  41618. */
  41619. /**
  41620. * Manages SVG clipPath elements.
  41621. *
  41622. * @class
  41623. * @extends Definable
  41624. * @param {SVGElement} svgRoot root of SVG document
  41625. */
  41626. function ClippathManager(svgRoot) {
  41627. Definable.call(this, svgRoot, 'clipPath', '__clippath_in_use__');
  41628. }
  41629. inherits(ClippathManager, Definable);
  41630. /**
  41631. * Update clipPath.
  41632. *
  41633. * @param {Displayable} displayable displayable element
  41634. */
  41635. ClippathManager.prototype.update = function (displayable) {
  41636. var svgEl = this.getSvgElement(displayable);
  41637. if (svgEl) {
  41638. this.updateDom(svgEl, displayable.__clipPaths, false);
  41639. }
  41640. var textEl = this.getTextSvgElement(displayable);
  41641. if (textEl) {
  41642. // Make another clipPath for text, since it's transform
  41643. // matrix is not the same with svgElement
  41644. this.updateDom(textEl, displayable.__clipPaths, true);
  41645. }
  41646. this.markUsed(displayable);
  41647. };
  41648. /**
  41649. * Create an SVGElement of displayable and create a <clipPath> of its
  41650. * clipPath
  41651. *
  41652. * @param {Displayable} parentEl parent element
  41653. * @param {ClipPath[]} clipPaths clipPaths of parent element
  41654. * @param {boolean} isText if parent element is Text
  41655. */
  41656. ClippathManager.prototype.updateDom = function (
  41657. parentEl,
  41658. clipPaths,
  41659. isText
  41660. ) {
  41661. if (clipPaths && clipPaths.length > 0) {
  41662. // Has clipPath, create <clipPath> with the first clipPath
  41663. var defs = this.getDefs(true);
  41664. var clipPath = clipPaths[0];
  41665. var clipPathEl;
  41666. var id;
  41667. var dom = isText ? '_textDom' : '_dom';
  41668. if (clipPath[dom]) {
  41669. // Use a dom that is already in <defs>
  41670. id = clipPath[dom].getAttribute('id');
  41671. clipPathEl = clipPath[dom];
  41672. // Use a dom that is already in <defs>
  41673. if (!defs.contains(clipPathEl)) {
  41674. // This happens when set old clipPath that has
  41675. // been previously removed
  41676. defs.appendChild(clipPathEl);
  41677. }
  41678. }
  41679. else {
  41680. // New <clipPath>
  41681. id = 'zr-clip-' + this.nextId;
  41682. ++this.nextId;
  41683. clipPathEl = this.createElement('clipPath');
  41684. clipPathEl.setAttribute('id', id);
  41685. defs.appendChild(clipPathEl);
  41686. clipPath[dom] = clipPathEl;
  41687. }
  41688. // Build path and add to <clipPath>
  41689. var svgProxy = this.getSvgProxy(clipPath);
  41690. if (clipPath.transform
  41691. && clipPath.parent.invTransform
  41692. && !isText
  41693. ) {
  41694. /**
  41695. * If a clipPath has a parent with transform, the transform
  41696. * of parent should not be considered when setting transform
  41697. * of clipPath. So we need to transform back from parent's
  41698. * transform, which is done by multiplying parent's inverse
  41699. * transform.
  41700. */
  41701. // Store old transform
  41702. var transform = Array.prototype.slice.call(
  41703. clipPath.transform
  41704. );
  41705. // Transform back from parent, and brush path
  41706. mul$1(
  41707. clipPath.transform,
  41708. clipPath.parent.invTransform,
  41709. clipPath.transform
  41710. );
  41711. svgProxy.brush(clipPath);
  41712. // Set back transform of clipPath
  41713. clipPath.transform = transform;
  41714. }
  41715. else {
  41716. svgProxy.brush(clipPath);
  41717. }
  41718. var pathEl = this.getSvgElement(clipPath);
  41719. /**
  41720. * Use `cloneNode()` here to appendChild to multiple parents,
  41721. * which may happend when Text and other shapes are using the same
  41722. * clipPath. Since Text will create an extra clipPath DOM due to
  41723. * different transform rules.
  41724. */
  41725. clipPathEl.appendChild(pathEl.cloneNode());
  41726. parentEl.setAttribute('clip-path', 'url(#' + id + ')');
  41727. if (clipPaths.length > 1) {
  41728. // Make the other clipPaths recursively
  41729. this.updateDom(clipPathEl, clipPaths.slice(1), isText);
  41730. }
  41731. }
  41732. else {
  41733. // No clipPath
  41734. if (parentEl) {
  41735. parentEl.setAttribute('clip-path', 'none');
  41736. }
  41737. }
  41738. };
  41739. /**
  41740. * Mark a single clipPath to be used
  41741. *
  41742. * @param {Displayable} displayable displayable element
  41743. */
  41744. ClippathManager.prototype.markUsed = function (displayable) {
  41745. var that = this;
  41746. if (displayable.__clipPaths && displayable.__clipPaths.length > 0) {
  41747. each$1(displayable.__clipPaths, function (clipPath) {
  41748. if (clipPath._dom) {
  41749. Definable.prototype.markUsed.call(that, clipPath._dom);
  41750. }
  41751. if (clipPath._textDom) {
  41752. Definable.prototype.markUsed.call(that, clipPath._textDom);
  41753. }
  41754. });
  41755. }
  41756. };
  41757. /**
  41758. * SVG Painter
  41759. * @module zrender/svg/Painter
  41760. */
  41761. function parseInt10$2(val) {
  41762. return parseInt(val, 10);
  41763. }
  41764. function getSvgProxy(el) {
  41765. if (el instanceof Path) {
  41766. return svgPath;
  41767. }
  41768. else if (el instanceof ZImage) {
  41769. return svgImage;
  41770. }
  41771. else if (el instanceof Text) {
  41772. return svgText;
  41773. }
  41774. else {
  41775. return svgPath;
  41776. }
  41777. }
  41778. function checkParentAvailable(parent, child) {
  41779. return child && parent && child.parentNode !== parent;
  41780. }
  41781. function insertAfter(parent, child, prevSibling) {
  41782. if (checkParentAvailable(parent, child) && prevSibling) {
  41783. var nextSibling = prevSibling.nextSibling;
  41784. nextSibling ? parent.insertBefore(child, nextSibling)
  41785. : parent.appendChild(child);
  41786. }
  41787. }
  41788. function prepend(parent, child) {
  41789. if (checkParentAvailable(parent, child)) {
  41790. var firstChild = parent.firstChild;
  41791. firstChild ? parent.insertBefore(child, firstChild)
  41792. : parent.appendChild(child);
  41793. }
  41794. }
  41795. function remove$1(parent, child) {
  41796. if (child && parent && child.parentNode === parent) {
  41797. parent.removeChild(child);
  41798. }
  41799. }
  41800. function getTextSvgElement(displayable) {
  41801. return displayable.__textSvgEl;
  41802. }
  41803. function getSvgElement(displayable) {
  41804. return displayable.__svgEl;
  41805. }
  41806. /**
  41807. * @alias module:zrender/svg/Painter
  41808. * @constructor
  41809. * @param {HTMLElement} root 绘图容器
  41810. * @param {module:zrender/Storage} storage
  41811. * @param {Object} opts
  41812. */
  41813. var SVGPainter = function (root, storage, opts) {
  41814. this.root = root;
  41815. this.storage = storage;
  41816. this._opts = opts = extend({}, opts || {});
  41817. var svgRoot = createElement('svg');
  41818. svgRoot.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  41819. svgRoot.setAttribute('version', '1.1');
  41820. svgRoot.setAttribute('baseProfile', 'full');
  41821. svgRoot.style['user-select'] = 'none';
  41822. svgRoot.style.cssText = 'position:absolute;left:0;top:0;';
  41823. this.gradientManager = new GradientManager(svgRoot);
  41824. this.clipPathManager = new ClippathManager(svgRoot);
  41825. var viewport = document.createElement('div');
  41826. viewport.style.cssText = 'overflow:hidden;position:relative';
  41827. this._svgRoot = svgRoot;
  41828. this._viewport = viewport;
  41829. root.appendChild(viewport);
  41830. viewport.appendChild(svgRoot);
  41831. this.resize(opts.width, opts.height);
  41832. this._visibleList = [];
  41833. };
  41834. SVGPainter.prototype = {
  41835. constructor: SVGPainter,
  41836. getType: function () {
  41837. return 'svg';
  41838. },
  41839. getViewportRoot: function () {
  41840. return this._viewport;
  41841. },
  41842. getViewportRootOffset: function () {
  41843. var viewportRoot = this.getViewportRoot();
  41844. if (viewportRoot) {
  41845. return {
  41846. offsetLeft: viewportRoot.offsetLeft || 0,
  41847. offsetTop: viewportRoot.offsetTop || 0
  41848. };
  41849. }
  41850. },
  41851. refresh: function () {
  41852. var list = this.storage.getDisplayList(true);
  41853. this._paintList(list);
  41854. },
  41855. _paintList: function (list) {
  41856. this.gradientManager.markAllUnused();
  41857. this.clipPathManager.markAllUnused();
  41858. var svgRoot = this._svgRoot;
  41859. var visibleList = this._visibleList;
  41860. var listLen = list.length;
  41861. var newVisibleList = [];
  41862. var i;
  41863. for (i = 0; i < listLen; i++) {
  41864. var displayable = list[i];
  41865. var svgProxy = getSvgProxy(displayable);
  41866. if (!displayable.invisible) {
  41867. if (displayable.__dirty) {
  41868. svgProxy && svgProxy.brush(displayable);
  41869. // Update clipPath
  41870. this.clipPathManager.update(displayable);
  41871. // Update gradient
  41872. if (displayable.style) {
  41873. this.gradientManager
  41874. .update(displayable.style.fill);
  41875. this.gradientManager
  41876. .update(displayable.style.stroke);
  41877. }
  41878. displayable.__dirty = false;
  41879. }
  41880. newVisibleList.push(displayable);
  41881. }
  41882. }
  41883. var diff = arrayDiff$1(visibleList, newVisibleList);
  41884. var prevSvgElement;
  41885. // First do remove, in case element moved to the head and do remove
  41886. // after add
  41887. for (i = 0; i < diff.length; i++) {
  41888. var item = diff[i];
  41889. if (item.removed) {
  41890. for (var k = 0; k < item.count; k++) {
  41891. var displayable = visibleList[item.indices[k]];
  41892. var svgElement = getSvgElement(displayable);
  41893. var textSvgElement = getTextSvgElement(displayable);
  41894. remove$1(svgRoot, svgElement);
  41895. remove$1(svgRoot, textSvgElement);
  41896. }
  41897. }
  41898. }
  41899. for (i = 0; i < diff.length; i++) {
  41900. var item = diff[i];
  41901. if (item.added) {
  41902. for (var k = 0; k < item.count; k++) {
  41903. var displayable = newVisibleList[item.indices[k]];
  41904. var svgElement = getSvgElement(displayable);
  41905. var textSvgElement = getTextSvgElement(displayable);
  41906. prevSvgElement
  41907. ? insertAfter(svgRoot, svgElement, prevSvgElement)
  41908. : prepend(svgRoot, svgElement);
  41909. if (svgElement) {
  41910. insertAfter(svgRoot, textSvgElement, svgElement);
  41911. }
  41912. else if (prevSvgElement) {
  41913. insertAfter(
  41914. svgRoot, textSvgElement, prevSvgElement
  41915. );
  41916. }
  41917. else {
  41918. prepend(svgRoot, textSvgElement);
  41919. }
  41920. // Insert text
  41921. insertAfter(svgRoot, textSvgElement, svgElement);
  41922. prevSvgElement = textSvgElement || svgElement
  41923. || prevSvgElement;
  41924. this.gradientManager
  41925. .addWithoutUpdate(svgElement, displayable);
  41926. this.clipPathManager.markUsed(displayable);
  41927. }
  41928. }
  41929. else if (!item.removed) {
  41930. for (var k = 0; k < item.count; k++) {
  41931. var displayable = newVisibleList[item.indices[k]];
  41932. prevSvgElement
  41933. = svgElement
  41934. = getTextSvgElement(displayable)
  41935. || getSvgElement(displayable)
  41936. || prevSvgElement;
  41937. this.gradientManager.markUsed(displayable);
  41938. this.gradientManager
  41939. .addWithoutUpdate(svgElement, displayable);
  41940. this.clipPathManager.markUsed(displayable);
  41941. }
  41942. }
  41943. }
  41944. this.gradientManager.removeUnused();
  41945. this.clipPathManager.removeUnused();
  41946. this._visibleList = newVisibleList;
  41947. },
  41948. _getDefs: function (isForceCreating) {
  41949. var svgRoot = this._svgRoot;
  41950. var defs = this._svgRoot.getElementsByTagName('defs');
  41951. if (defs.length === 0) {
  41952. // Not exist
  41953. if (isForceCreating) {
  41954. var defs = svgRoot.insertBefore(
  41955. createElement('defs'), // Create new tag
  41956. svgRoot.firstChild // Insert in the front of svg
  41957. );
  41958. if (!defs.contains) {
  41959. // IE doesn't support contains method
  41960. defs.contains = function (el) {
  41961. var children = defs.children;
  41962. if (!children) {
  41963. return false;
  41964. }
  41965. for (var i = children.length - 1; i >= 0; --i) {
  41966. if (children[i] === el) {
  41967. return true;
  41968. }
  41969. }
  41970. return false;
  41971. };
  41972. }
  41973. return defs;
  41974. }
  41975. else {
  41976. return null;
  41977. }
  41978. }
  41979. else {
  41980. return defs[0];
  41981. }
  41982. },
  41983. resize: function (width, height) {
  41984. var viewport = this._viewport;
  41985. // FIXME Why ?
  41986. viewport.style.display = 'none';
  41987. // Save input w/h
  41988. var opts = this._opts;
  41989. width != null && (opts.width = width);
  41990. height != null && (opts.height = height);
  41991. width = this._getSize(0);
  41992. height = this._getSize(1);
  41993. viewport.style.display = '';
  41994. if (this._width !== width && this._height !== height) {
  41995. this._width = width;
  41996. this._height = height;
  41997. var viewportStyle = viewport.style;
  41998. viewportStyle.width = width + 'px';
  41999. viewportStyle.height = height + 'px';
  42000. var svgRoot = this._svgRoot;
  42001. // Set width by 'svgRoot.width = width' is invalid
  42002. svgRoot.setAttribute('width', width);
  42003. svgRoot.setAttribute('height', height);
  42004. }
  42005. },
  42006. /**
  42007. * 获取绘图区域宽度
  42008. */
  42009. getWidth: function () {
  42010. return this._width;
  42011. },
  42012. /**
  42013. * 获取绘图区域高度
  42014. */
  42015. getHeight: function () {
  42016. return this._height;
  42017. },
  42018. _getSize: function (whIdx) {
  42019. var opts = this._opts;
  42020. var wh = ['width', 'height'][whIdx];
  42021. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  42022. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  42023. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  42024. if (opts[wh] != null && opts[wh] !== 'auto') {
  42025. return parseFloat(opts[wh]);
  42026. }
  42027. var root = this.root;
  42028. // IE8 does not support getComputedStyle, but it use VML.
  42029. var stl = document.defaultView.getComputedStyle(root);
  42030. return (
  42031. (root[cwh] || parseInt10$2(stl[wh]) || parseInt10$2(root.style[wh]))
  42032. - (parseInt10$2(stl[plt]) || 0)
  42033. - (parseInt10$2(stl[prb]) || 0)
  42034. ) | 0;
  42035. },
  42036. dispose: function () {
  42037. this.root.innerHTML = '';
  42038. this._svgRoot
  42039. = this._viewport
  42040. = this.storage
  42041. = null;
  42042. },
  42043. clear: function () {
  42044. if (this._viewport) {
  42045. this.root.removeChild(this._viewport);
  42046. }
  42047. },
  42048. pathToSvg: function () {
  42049. this.refresh();
  42050. var html = this._svgRoot.outerHTML;
  42051. return 'data:img/svg+xml;utf-8,' + unescape(html);
  42052. }
  42053. };
  42054. // Not supported methods
  42055. function createMethodNotSupport$1(method) {
  42056. return function () {
  42057. zrLog('In SVG mode painter not support method "' + method + '"');
  42058. };
  42059. }
  42060. // Unsuppoted methods
  42061. each$1([
  42062. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer',
  42063. 'eachOtherLayer', 'getLayers', 'modLayer', 'delLayer', 'clearLayer',
  42064. 'toDataURL', 'pathToImage'
  42065. ], function (name) {
  42066. SVGPainter.prototype[name] = createMethodNotSupport$1(name);
  42067. });
  42068. registerPainter('svg', SVGPainter);
  42069. exports.version = version;
  42070. exports.dependencies = dependencies;
  42071. exports.PRIORITY = PRIORITY;
  42072. exports.init = init;
  42073. exports.connect = connect;
  42074. exports.disConnect = disConnect;
  42075. exports.disconnect = disconnect;
  42076. exports.dispose = dispose;
  42077. exports.getInstanceByDom = getInstanceByDom;
  42078. exports.getInstanceById = getInstanceById;
  42079. exports.registerTheme = registerTheme;
  42080. exports.registerPreprocessor = registerPreprocessor;
  42081. exports.registerProcessor = registerProcessor;
  42082. exports.registerPostUpdate = registerPostUpdate;
  42083. exports.registerAction = registerAction;
  42084. exports.registerCoordinateSystem = registerCoordinateSystem;
  42085. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  42086. exports.registerLayout = registerLayout;
  42087. exports.registerVisual = registerVisual;
  42088. exports.registerLoading = registerLoading;
  42089. exports.extendComponentModel = extendComponentModel;
  42090. exports.extendComponentView = extendComponentView;
  42091. exports.extendSeriesModel = extendSeriesModel;
  42092. exports.extendChartView = extendChartView;
  42093. exports.setCanvasCreator = setCanvasCreator;
  42094. exports.registerMap = registerMap;
  42095. exports.getMap = getMap;
  42096. exports.dataTool = dataTool;
  42097. exports.zrender = zrender;
  42098. exports.graphic = graphic;
  42099. exports.number = number;
  42100. exports.format = format;
  42101. exports.throttle = throttle;
  42102. exports.helper = helper;
  42103. exports.matrix = matrix;
  42104. exports.vector = vector;
  42105. exports.color = color;
  42106. exports.util = ecUtil;
  42107. exports.List = List;
  42108. exports.Model = Model;
  42109. exports.Axis = Axis;
  42110. exports.env = env$1;
  42111. exports.parseGeoJson = parseGeoJson;
  42112. })));